mirror of
https://github.com/Docile-Alligator/Infinity-For-Reddit.git
synced 2026-02-04 22:25:27 +00:00
Fix issues when deleting the oldest read posts for users. No more app hangs.
This commit is contained in:
@ -3112,7 +3112,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
}
|
||||
if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) {
|
||||
((MarkPostAsReadInterface) mActivity).markPostAsRead(post);
|
||||
mFragment.markPostAsRead(post);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4140,7 +4139,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
}
|
||||
if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) {
|
||||
((MarkPostAsReadInterface) mActivity).markPostAsRead(post);
|
||||
mFragment.markPostAsRead(post);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4383,7 +4381,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
}
|
||||
if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) {
|
||||
((MarkPostAsReadInterface) mActivity).markPostAsRead(post);
|
||||
mFragment.markPostAsRead(post);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4580,7 +4577,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
}
|
||||
if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) {
|
||||
((MarkPostAsReadInterface) mActivity).markPostAsRead(post);
|
||||
mFragment.markPostAsRead(post);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,10 +67,8 @@ import ml.docilealligator.infinityforreddit.post.PostPagingSource;
|
||||
import ml.docilealligator.infinityforreddit.post.PostViewModel;
|
||||
import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
|
||||
import ml.docilealligator.infinityforreddit.postfilter.PostFilterUsage;
|
||||
import ml.docilealligator.infinityforreddit.readpost.InsertReadPost;
|
||||
import ml.docilealligator.infinityforreddit.readpost.ReadPostsList;
|
||||
import ml.docilealligator.infinityforreddit.readpost.ReadPostsListInterface;
|
||||
import ml.docilealligator.infinityforreddit.readpost.ReadPostsUtils;
|
||||
import ml.docilealligator.infinityforreddit.thing.SortType;
|
||||
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||
import ml.docilealligator.infinityforreddit.utils.Utils;
|
||||
@ -1252,12 +1250,6 @@ public class PostFragment extends PostFragmentBase implements FragmentCommunicat
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markPostAsRead(Post post) {
|
||||
int readPostsLimit = ReadPostsUtils.GetReadPostsLimit(activity.accountName, mPostHistorySharedPreferences);
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, activity.accountName, post.getId(), readPostsLimit);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onChangeDefaultPostLayoutEvent(ChangeDefaultPostLayoutEvent changeDefaultPostLayoutEvent) {
|
||||
Bundle bundle = getArguments();
|
||||
|
||||
@ -568,10 +568,6 @@ public abstract class PostFragmentBase extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
public void markPostAsRead(Post post) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
protected abstract boolean scrollPostsByCount(int count);
|
||||
|
||||
protected final void initializeSwipeActionDrawable() {
|
||||
|
||||
@ -9,7 +9,7 @@ public class InsertReadPost {
|
||||
String username, String postId, int readPostsLimit) {
|
||||
executor.execute(() -> {
|
||||
ReadPostDao readPostDao = redditDataRoomDatabase.readPostDao();
|
||||
int limit = Math.max(readPostsLimit, 500);
|
||||
int limit = Math.max(readPostsLimit, 100);
|
||||
boolean isReadPostLimit = readPostsLimit != -1;
|
||||
while (readPostDao.getReadPostsCount(username) > limit && isReadPostLimit) {
|
||||
readPostDao.deleteOldestReadPosts(username);
|
||||
|
||||
@ -26,7 +26,7 @@ public interface ReadPostDao {
|
||||
@Query("SELECT COUNT(id) FROM read_posts WHERE username = :username")
|
||||
int getReadPostsCount(String username);
|
||||
|
||||
@Query("DELETE FROM read_posts WHERE rowid IN (SELECT rowid FROM read_posts ORDER BY time ASC LIMIT 100) AND username = :username")
|
||||
@Query("DELETE FROM read_posts WHERE rowid IN (SELECT rowid FROM read_posts WHERE username = :username ORDER BY time ASC LIMIT 100)")
|
||||
void deleteOldestReadPosts(String username);
|
||||
|
||||
@Query("DELETE FROM read_posts")
|
||||
|
||||
Reference in New Issue
Block a user