From 8e05bac93615fc86405541a6bab8378ca267debc Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 7 Dec 2020 19:38:58 +0800 Subject: Mark posts as read. --- .../infinityforreddit/MarkPostAsReadInterface.java | 7 ++ .../infinityforreddit/RedditDataRoomDatabase.java | 4 +- .../activities/AccountSavedThingActivity.java | 18 +++-- .../activities/FilteredThingActivity.java | 21 +++-- .../infinityforreddit/activities/MainActivity.java | 29 ++++--- .../activities/ViewMultiRedditDetailActivity.java | 22 +++-- .../activities/ViewSubredditDetailActivity.java | 22 +++-- .../activities/ViewUserDetailActivity.java | 24 ++++-- .../adapters/PostRecyclerViewAdapter.java | 59 ++++++++++++-- .../infinityforreddit/fragments/PostFragment.java | 40 +++++----- .../infinityforreddit/post/ParsePost.java | 22 +++-- .../infinityforreddit/post/Post.java | 13 +++ .../infinityforreddit/post/PostDataSource.java | 40 ++++++---- .../post/PostDataSourceFactory.java | 29 ++++--- .../infinityforreddit/post/PostViewModel.java | 52 +++++++----- .../infinityforreddit/readpost/FetchReadPosts.java | 53 ++++++++++++ .../infinityforreddit/readpost/InsertReadPost.java | 34 ++++++++ .../infinityforreddit/readpost/ReadPost.java | 93 ++++++++++++++++++++++ .../infinityforreddit/readpost/ReadPostDao.java | 23 ++++++ .../readposts/FetchReadPosts.java | 53 ------------ .../infinityforreddit/readposts/ReadPost.java | 74 ----------------- .../infinityforreddit/readposts/ReadPostDao.java | 20 ----- 22 files changed, 482 insertions(+), 270 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/MarkPostAsReadInterface.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/readpost/FetchReadPosts.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/readpost/InsertReadPost.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/readpost/ReadPost.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/readpost/ReadPostDao.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/readposts/FetchReadPosts.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/readposts/ReadPost.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/readposts/ReadPostDao.java (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MarkPostAsReadInterface.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MarkPostAsReadInterface.java new file mode 100644 index 00000000..d14c1c09 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MarkPostAsReadInterface.java @@ -0,0 +1,7 @@ +package ml.docilealligator.infinityforreddit; + +import ml.docilealligator.infinityforreddit.post.Post; + +public interface MarkPostAsReadInterface { + void markPostAsRead(Post post); +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java index 73138eae..f7cd0e5b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java @@ -16,8 +16,8 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomTheme; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeDao; import ml.docilealligator.infinityforreddit.multireddit.MultiReddit; import ml.docilealligator.infinityforreddit.multireddit.MultiRedditDao; -import ml.docilealligator.infinityforreddit.readposts.ReadPost; -import ml.docilealligator.infinityforreddit.readposts.ReadPostDao; +import ml.docilealligator.infinityforreddit.readpost.ReadPost; +import ml.docilealligator.infinityforreddit.readpost.ReadPostDao; import ml.docilealligator.infinityforreddit.recentsearchquery.RecentSearchQuery; import ml.docilealligator.infinityforreddit.recentsearchquery.RecentSearchQueryDao; import ml.docilealligator.infinityforreddit.subreddit.SubredditDao; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java index 46b474fc..9be885d1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java @@ -36,6 +36,11 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; +import ml.docilealligator.infinityforreddit.FragmentCommunicator; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; @@ -43,16 +48,14 @@ import ml.docilealligator.infinityforreddit.events.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.fragments.CommentsListingFragment; import ml.docilealligator.infinityforreddit.fragments.PostFragment; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; -import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.post.PostDataSource; -import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.readpost.InsertReadPost; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import retrofit2.Retrofit; public class AccountSavedThingActivity extends BaseActivity implements ActivityToolbarInterface, - PostLayoutBottomSheetFragment.PostLayoutSelectionCallback { + PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, MarkPostAsReadInterface { private static final String NULL_ACCESS_TOKEN_STATE = "NATS"; private static final String ACCESS_TOKEN_STATE = "ATS"; @@ -335,6 +338,11 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT } } + @Override + public void markPostAsRead(Post post) { + InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mAccountName, post.getId()); + } + private class SectionsPagerAdapter extends FragmentStateAdapter { SectionsPagerAdapter(FragmentManager fm, Lifecycle lifecycle) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredThingActivity.java index d2bfc20f..279a8346 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredThingActivity.java @@ -28,6 +28,13 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; +import ml.docilealligator.infinityforreddit.FragmentCommunicator; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.SearchPostSortTypeBottomSheetFragment; @@ -37,18 +44,13 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.UserThingSortTy import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.fragments.PostFragment; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; -import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.post.PostDataSource; -import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.readpost.InsertReadPost; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; public class FilteredThingActivity extends BaseActivity implements SortTypeSelectionCallback, - PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface { + PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface, MarkPostAsReadInterface { public static final String EXTRA_NAME = "ESN"; public static final String EXTRA_QUERY = "EQ"; @@ -457,4 +459,9 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec ((PostFragment) mFragment).goBackToTop(); } } + + @Override + public void markPostAsRead(Post post) { + InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mAccountName, post.getId()); + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index ed20aaf3..c963cf84 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -64,8 +64,17 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.account.AccountViewModel; import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; +import ml.docilealligator.infinityforreddit.FetchMyInfo; +import ml.docilealligator.infinityforreddit.FetchSubscribedThing; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; +import ml.docilealligator.infinityforreddit.PullNotificationWorker; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.account.AccountViewModel; import ml.docilealligator.infinityforreddit.adapters.NavigationDrawerRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThingsAsyncTask; @@ -85,17 +94,11 @@ import ml.docilealligator.infinityforreddit.events.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.events.ChangeRequireAuthToAccountSectionEvent; import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; -import ml.docilealligator.infinityforreddit.FetchMyInfo; -import ml.docilealligator.infinityforreddit.FetchSubscribedThing; import ml.docilealligator.infinityforreddit.fragments.PostFragment; -import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.message.ReadMessage; +import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.post.PostDataSource; -import ml.docilealligator.infinityforreddit.PullNotificationWorker; -import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.readpost.InsertReadPost; import ml.docilealligator.infinityforreddit.subreddit.SubredditData; import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData; import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditViewModel; @@ -110,7 +113,8 @@ import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; public class MainActivity extends BaseActivity implements SortTypeSelectionCallback, PostTypeBottomSheetFragment.PostTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, - ActivityToolbarInterface, FABMoreOptionsBottomSheetFragment.FABOptionSelectionCallback, RandomBottomSheetFragment.RandomOptionSelectionCallback { + ActivityToolbarInterface, FABMoreOptionsBottomSheetFragment.FABOptionSelectionCallback, + RandomBottomSheetFragment.RandomOptionSelectionCallback, MarkPostAsReadInterface { static final String EXTRA_MESSSAGE_FULLNAME = "ENF"; static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN"; @@ -1269,6 +1273,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb startActivity(intent); } + @Override + public void markPostAsRead(Post post) { + InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mAccountName, post.getId()); + } + private class SectionsPagerAdapter extends FragmentStateAdapter { int tabCount; boolean showFavoriteSubscribedSubreddits; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java index 2caec58b..b0032263 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java @@ -29,6 +29,13 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; +import ml.docilealligator.infinityforreddit.FragmentCommunicator; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.SortTimeBottomSheetFragment; @@ -36,21 +43,17 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.SortTypeBottomS import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.events.RefreshMultiRedditsEvent; import ml.docilealligator.infinityforreddit.fragments.PostFragment; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; -import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.multireddit.DeleteMultiReddit; import ml.docilealligator.infinityforreddit.multireddit.MultiReddit; +import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.post.PostDataSource; -import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.readpost.InsertReadPost; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Retrofit; public class ViewMultiRedditDetailActivity extends BaseActivity implements SortTypeSelectionCallback, - PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface { + PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface, MarkPostAsReadInterface { public static final String EXTRA_MULTIREDDIT_DATA = "EMD"; public static final String EXTRA_MULTIREDDIT_PATH = "EMP"; @@ -361,4 +364,9 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT Utils.displaySortTypeInToolbar(sortType, toolbar); } } + + @Override + public void markPostAsRead(Post post) { + InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mAccountName, post.getId()); + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java index c62d4ae2..9363a9d8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -63,6 +63,13 @@ import butterknife.ButterKnife; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; +import ml.docilealligator.infinityforreddit.FragmentCommunicator; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.asynctasks.CheckIsSubscribedToSubredditAsyncTask; import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.asynctasks.InsertSubredditDataAsyncTask; @@ -79,14 +86,10 @@ import ml.docilealligator.infinityforreddit.events.GoBackToMainPageEvent; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.fragments.PostFragment; import ml.docilealligator.infinityforreddit.fragments.SidebarFragment; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; -import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.message.ReadMessage; +import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.post.PostDataSource; -import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.readpost.InsertReadPost; import ml.docilealligator.infinityforreddit.subreddit.FetchSubredditData; import ml.docilealligator.infinityforreddit.subreddit.SubredditData; import ml.docilealligator.infinityforreddit.subreddit.SubredditSubscription; @@ -99,7 +102,7 @@ import retrofit2.Retrofit; public class ViewSubredditDetailActivity extends BaseActivity implements SortTypeSelectionCallback, PostTypeBottomSheetFragment.PostTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface, FABMoreOptionsBottomSheetFragment.FABOptionSelectionCallback, - RandomBottomSheetFragment.RandomOptionSelectionCallback { + RandomBottomSheetFragment.RandomOptionSelectionCallback, MarkPostAsReadInterface { public static final String EXTRA_SUBREDDIT_NAME_KEY = "ESN"; public static final String EXTRA_MESSAGE_FULLNAME = "ENF"; @@ -1196,6 +1199,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp startActivity(intent); } + @Override + public void markPostAsRead(Post post) { + InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mAccountName, post.getId()); + } + private class SectionsPagerAdapter extends FragmentStateAdapter { SectionsPagerAdapter(FragmentManager fm, Lifecycle lifecycle) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java index 6b118b07..298cfc51 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java @@ -56,6 +56,14 @@ import butterknife.ButterKnife; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; +import ml.docilealligator.infinityforreddit.DeleteThing; +import ml.docilealligator.infinityforreddit.FragmentCommunicator; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.asynctasks.CheckIsFollowingUserAsyncTask; import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccountAsyncTask; @@ -63,19 +71,14 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBotto import ml.docilealligator.infinityforreddit.bottomsheetfragments.SortTimeBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.UserThingSortTypeBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; -import ml.docilealligator.infinityforreddit.DeleteThing; import ml.docilealligator.infinityforreddit.events.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.fragments.CommentsListingFragment; import ml.docilealligator.infinityforreddit.fragments.PostFragment; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; -import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.message.ReadMessage; +import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.post.PostDataSource; -import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.readpost.InsertReadPost; import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserDao; import ml.docilealligator.infinityforreddit.user.BlockUser; import ml.docilealligator.infinityforreddit.user.FetchUserData; @@ -89,7 +92,7 @@ import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; public class ViewUserDetailActivity extends BaseActivity implements SortTypeSelectionCallback, - PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface { + PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface, MarkPostAsReadInterface { public static final String EXTRA_USER_NAME_KEY = "EUNK"; public static final String EXTRA_MESSAGE_FULLNAME = "ENF"; @@ -835,6 +838,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele } } + @Override + public void markPostAsRead(Post post) { + InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mAccountName, post.getId()); + } + private static class InsertUserDataAsyncTask extends AsyncTask { private UserDao userDao; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index 285419a2..a77e3ad2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -70,6 +70,7 @@ import im.ene.toro.widget.Container; import jp.wasabeef.glide.transformations.BlurTransformation; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.FetchGfycatOrRedgifsVideoLinks; +import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; @@ -141,10 +142,13 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { int position = getAdapterPosition(); if (position >= 0 && canStartActivity) { - canStartActivity = false; + Post post = getItem(position); + if (post != null) { + markPostRead(post); + canStartActivity = false; - Intent intent = new Intent(mActivity, ViewPostDetailActivity.class); - intent.putExtra(ViewPostDetailActivity.EXTRA_POST_DATA, getItem(position)); - intent.putExtra(ViewPostDetailActivity.EXTRA_POST_LIST_POSITION, getAdapterPosition()); - mActivity.startActivity(intent); + Intent intent = new Intent(mActivity, ViewPostDetailActivity.class); + intent.putExtra(ViewPostDetailActivity.EXTRA_POST_DATA, post); + intent.putExtra(ViewPostDetailActivity.EXTRA_POST_LIST_POSITION, getAdapterPosition()); + mActivity.startActivity(intent); + } } }); @@ -1827,6 +1854,18 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) { subredditFilterList = subredditFilters; mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, accountName, locale, mSharedPreferences, - postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, filter, nsfw, subredditFilterList)).get(PostViewModel.class); + postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, filter, nsfw, readPosts, subredditFilterList)).get(PostViewModel.class); bindPostViewModel(); } @@ -843,20 +843,20 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } else { mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, accountName, locale, mSharedPreferences, - postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, filter, nsfw)).get(PostViewModel.class); + postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, filter, nsfw, readPosts)).get(PostViewModel.class); } } else if (postType == PostDataSource.TYPE_MULTI_REDDIT) { mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, accountName, locale, mSharedPreferences, - postFeedScrolledPositionSharedPreferences, multiRedditPath, postType, sortType, filter, nsfw)).get(PostViewModel.class); + postFeedScrolledPositionSharedPreferences, multiRedditPath, postType, sortType, filter, nsfw, readPosts)).get(PostViewModel.class); } else if (postType == PostDataSource.TYPE_USER) { mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, accountName, locale, mSharedPreferences, - postFeedScrolledPositionSharedPreferences, username, postType, sortType, where, filter, nsfw)).get(PostViewModel.class); + postFeedScrolledPositionSharedPreferences, username, postType, sortType, where, filter, nsfw, readPosts)).get(PostViewModel.class); } else { mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mOauthRetrofit, accessToken, accountName, locale, mSharedPreferences, postFeedScrolledPositionSharedPreferences, - postType, sortType, filter, nsfw)).get(PostViewModel.class); + postType, sortType, filter, nsfw, readPosts)).get(PostViewModel.class); } if (mPostViewModel != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java index 708f4e75..abf046af 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java @@ -9,10 +9,12 @@ import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import ml.docilealligator.infinityforreddit.fragments.PostFragment; +import ml.docilealligator.infinityforreddit.readpost.ReadPost; import ml.docilealligator.infinityforreddit.subredditfilter.SubredditFilter; import ml.docilealligator.infinityforreddit.utils.JSONUtils; import ml.docilealligator.infinityforreddit.utils.Utils; @@ -22,14 +24,14 @@ import ml.docilealligator.infinityforreddit.utils.Utils; */ public class ParsePost { - public static void parsePosts(String response, int nPosts, int filter, boolean nsfw, + public static void parsePosts(String response, int nPosts, int filter, boolean nsfw, List readPostList, ParsePostsListingListener parsePostsListingListener) { - new ParsePostDataAsyncTask(response, nPosts, filter, nsfw, parsePostsListingListener).execute(); + new ParsePostDataAsyncTask(response, nPosts, filter, nsfw, readPostList, parsePostsListingListener).execute(); } - public static void parsePosts(String response, int nPosts, int filter, boolean nsfw, + public static void parsePosts(String response, int nPosts, int filter, boolean nsfw, List readPostList, List subredditFilterList, ParsePostsListingListener parsePostsListingListener) { - new ParsePostDataAsyncTask(response, nPosts, filter, nsfw, subredditFilterList, parsePostsListingListener).execute(); + new ParsePostDataAsyncTask(response, nPosts, filter, nsfw, readPostList, subredditFilterList, parsePostsListingListener).execute(); } public static void parsePost(String response, ParsePostListener parsePostListener) { @@ -490,6 +492,7 @@ public class ParsePost { private int nPosts; private int filter; private boolean nsfw; + private List readPostList; private List subredditFilterList; private ParsePostsListingListener parsePostsListingListener; private ParsePostListener parsePostListener; @@ -498,7 +501,7 @@ public class ParsePost { private String lastItem; private boolean parseFailed; - ParsePostDataAsyncTask(String response, int nPosts, int filter, boolean nsfw, + ParsePostDataAsyncTask(String response, int nPosts, int filter, boolean nsfw, List readPostList, ParsePostsListingListener parsePostsListingListener) { this.parsePostsListingListener = parsePostsListingListener; try { @@ -508,6 +511,7 @@ public class ParsePost { this.nPosts = nPosts; this.filter = filter; this.nsfw = nsfw; + this.readPostList = readPostList; newPosts = new LinkedHashSet<>(); parseFailed = false; } catch (JSONException e) { @@ -516,9 +520,9 @@ public class ParsePost { } } - ParsePostDataAsyncTask(String response, int nPosts, int filter, boolean nsfw, + ParsePostDataAsyncTask(String response, int nPosts, int filter, boolean nsfw, List readPostList, List subredditFilterList, ParsePostsListingListener parsePostsListingListener) { - this(response, nPosts, filter, nsfw, parsePostsListingListener); + this(response, nPosts, filter, nsfw, readPostList, parsePostsListingListener); this.subredditFilterList = subredditFilterList; } @@ -564,12 +568,16 @@ public class ParsePost { size = nPosts; } + HashSet readPostHashSet = new HashSet<>(readPostList); for (int i = 0; i < size; i++) { try { if (allData.getJSONObject(i).getString(JSONUtils.KIND_KEY).equals("t3")) { JSONObject data = allData.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY); Post post = parseBasicData(data); boolean availablePost = true; + if (readPostHashSet.contains(ReadPost.convertPost(post))) { + post.markAsRead(); + } if (subredditFilterList != null) { for (SubredditFilter subredditFilter : subredditFilterList) { if (subredditFilter.getSubredditName().equals(post.getSubredditName())) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java index 1e220487..582c398d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java @@ -71,6 +71,7 @@ public class Post implements Parcelable { private boolean locked; private boolean saved; private boolean isCrosspost; + private boolean isRead; private String crosspostParentId; private ArrayList previews = new ArrayList<>(); private ArrayList gallery = new ArrayList<>(); @@ -107,6 +108,7 @@ public class Post implements Parcelable { this.locked = locked; this.saved = saved; this.isCrosspost = isCrosspost; + isRead = false; } public Post(String id, String fullName, String subredditName, String subredditNamePrefixed, @@ -142,6 +144,7 @@ public class Post implements Parcelable { this.locked = locked; this.saved = saved; this.isCrosspost = isCrosspost; + isRead = false; } protected Post(Parcel in) { @@ -183,6 +186,7 @@ public class Post implements Parcelable { locked = in.readByte() != 0; saved = in.readByte() != 0; isCrosspost = in.readByte() != 0; + isRead = in.readByte() != 0; crosspostParentId = in.readString(); in.readTypedList(previews, Preview.CREATOR); in.readTypedList(gallery, Gallery.CREATOR); @@ -446,6 +450,14 @@ public class Post implements Parcelable { return isCrosspost; } + public void markAsRead() { + isRead = true; + } + + public boolean isRead() { + return isRead; + } + public String getCrosspostParentId() { return crosspostParentId; } @@ -510,6 +522,7 @@ public class Post implements Parcelable { parcel.writeByte((byte) (locked ? 1 : 0)); parcel.writeByte((byte) (saved ? 1 : 0)); parcel.writeByte((byte) (isCrosspost ? 1 : 0)); + parcel.writeByte((byte) (isRead ? 1 : 0)); parcel.writeString(crosspostParentId); parcel.writeTypedList(previews); parcel.writeTypedList(gallery); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSource.java index 20e43fce..e17a9a1c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSource.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSource.java @@ -11,9 +11,10 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; -import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.apis.RedditAPI; +import ml.docilealligator.infinityforreddit.readpost.ReadPost; import ml.docilealligator.infinityforreddit.subredditfilter.SubredditFilter; import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; @@ -48,6 +49,7 @@ public class PostDataSource extends PageKeyedDataSource { private SortType sortType; private boolean nsfw; private int filter; + private List readPostList; private List subredditFilterList; private String userWhere; private String multiRedditPath; @@ -62,7 +64,7 @@ public class PostDataSource extends PageKeyedDataSource { PostDataSource(Retrofit retrofit, String accessToken, String accountName, Locale locale, SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, int postType, - SortType sortType, int filter, boolean nsfw) { + SortType sortType, int filter, boolean nsfw, List readPostList) { this.retrofit = retrofit; this.accessToken = accessToken; this.accountName = accountName; @@ -76,12 +78,14 @@ public class PostDataSource extends PageKeyedDataSource { this.sortType = sortType == null ? new SortType(SortType.Type.BEST) : sortType; this.filter = filter; this.nsfw = nsfw; + this.readPostList = readPostList; postLinkedHashSet = new LinkedHashSet<>(); } PostDataSource(Retrofit retrofit, String accessToken, String accountName, Locale locale, SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, - String path, int postType, SortType sortType, int filter, boolean nsfw, List subredditFilterList) { + String path, int postType, SortType sortType, int filter, boolean nsfw, List readPostList, + List subredditFilterList) { this.retrofit = retrofit; this.accessToken = accessToken; this.accountName = accountName; @@ -116,13 +120,14 @@ public class PostDataSource extends PageKeyedDataSource { } this.filter = filter; this.nsfw = nsfw; + this.readPostList = readPostList; this.subredditFilterList = subredditFilterList; postLinkedHashSet = new LinkedHashSet<>(); } PostDataSource(Retrofit retrofit, String accessToken, String accountName, Locale locale, SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, String subredditOrUserName, - int postType, SortType sortType, String where, int filter, boolean nsfw) { + int postType, SortType sortType, String where, int filter, boolean nsfw, List readPostList) { this.retrofit = retrofit; this.accessToken = accessToken; this.accountName = accountName; @@ -138,12 +143,14 @@ public class PostDataSource extends PageKeyedDataSource { userWhere = where; this.filter = filter; this.nsfw = nsfw; + this.readPostList = readPostList; postLinkedHashSet = new LinkedHashSet<>(); } PostDataSource(Retrofit retrofit, String accessToken, String accountName, Locale locale, - SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, String subredditOrUserName, - String query, int postType, SortType sortType, int filter, boolean nsfw) { + SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, + String subredditOrUserName, String query, int postType, SortType sortType, int filter, + boolean nsfw, List readPostList) { this.retrofit = retrofit; this.accessToken = accessToken; this.accountName = accountName; @@ -160,6 +167,7 @@ public class PostDataSource extends PageKeyedDataSource { this.filter = filter; this.nsfw = nsfw; postLinkedHashSet = new LinkedHashSet<>(); + this.readPostList = readPostList; } MutableLiveData getPaginationNetworkStateLiveData() { @@ -250,7 +258,7 @@ public class PostDataSource extends PageKeyedDataSource { @Override public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { if (response.isSuccessful()) { - ParsePost.parsePosts(response.body(), -1, filter, nsfw, + ParsePost.parsePosts(response.body(), -1, filter, nsfw, readPostList, new ParsePost.ParsePostsListingListener() { @Override public void onParsePostsListingSuccess(LinkedHashSet newPosts, String lastItem) { @@ -313,7 +321,7 @@ public class PostDataSource extends PageKeyedDataSource { @Override public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { if (response.isSuccessful()) { - ParsePost.parsePosts(response.body(), -1, filter, nsfw, + ParsePost.parsePosts(response.body(), -1, filter, nsfw, readPostList, new ParsePost.ParsePostsListingListener() { @Override public void onParsePostsListingSuccess(LinkedHashSet newPosts, String lastItem) { @@ -373,7 +381,7 @@ public class PostDataSource extends PageKeyedDataSource { @Override public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { if (response.isSuccessful()) { - ParsePost.parsePosts(response.body(), -1, filter, nsfw, subredditFilterList, + ParsePost.parsePosts(response.body(), -1, filter, nsfw, readPostList, subredditFilterList, new ParsePost.ParsePostsListingListener() { @Override public void onParsePostsListingSuccess(LinkedHashSet newPosts, String lastItem) { @@ -447,7 +455,7 @@ public class PostDataSource extends PageKeyedDataSource { @Override public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { if (response.isSuccessful()) { - ParsePost.parsePosts(response.body(), -1, filter, nsfw, subredditFilterList, + ParsePost.parsePosts(response.body(), -1, filter, nsfw, readPostList, subredditFilterList, new ParsePost.ParsePostsListingListener() { @Override public void onParsePostsListingSuccess(LinkedHashSet newPosts, String lastItem) { @@ -508,7 +516,7 @@ public class PostDataSource extends PageKeyedDataSource { @Override public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { if (response.isSuccessful()) { - ParsePost.parsePosts(response.body(), -1, filter, nsfw, + ParsePost.parsePosts(response.body(), -1, filter, nsfw, readPostList, new ParsePost.ParsePostsListingListener() { @Override public void onParsePostsListingSuccess(LinkedHashSet newPosts, String lastItem) { @@ -579,7 +587,7 @@ public class PostDataSource extends PageKeyedDataSource { @Override public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { if (response.isSuccessful()) { - ParsePost.parsePosts(response.body(), -1, filter, nsfw, + ParsePost.parsePosts(response.body(), -1, filter, nsfw, readPostList, new ParsePost.ParsePostsListingListener() { @Override public void onParsePostsListingSuccess(LinkedHashSet newPosts, String lastItem) { @@ -662,7 +670,7 @@ public class PostDataSource extends PageKeyedDataSource { @Override public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { if (response.isSuccessful()) { - ParsePost.parsePosts(response.body(), -1, filter, nsfw, + ParsePost.parsePosts(response.body(), -1, filter, nsfw, readPostList, new ParsePost.ParsePostsListingListener() { @Override public void onParsePostsListingSuccess(LinkedHashSet newPosts, String lastItem) { @@ -753,7 +761,7 @@ public class PostDataSource extends PageKeyedDataSource { @Override public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { if (response.isSuccessful()) { - ParsePost.parsePosts(response.body(), -1, filter, nsfw, + ParsePost.parsePosts(response.body(), -1, filter, nsfw, readPostList, new ParsePost.ParsePostsListingListener() { @Override public void onParsePostsListingSuccess(LinkedHashSet newPosts, String lastItem) { @@ -813,7 +821,7 @@ public class PostDataSource extends PageKeyedDataSource { @Override public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { if (response.isSuccessful()) { - ParsePost.parsePosts(response.body(), -1, filter, nsfw, + ParsePost.parsePosts(response.body(), -1, filter, nsfw, readPostList, new ParsePost.ParsePostsListingListener() { @Override public void onParsePostsListingSuccess(LinkedHashSet newPosts, String lastItem) { @@ -884,7 +892,7 @@ public class PostDataSource extends PageKeyedDataSource { @Override public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { if (response.isSuccessful()) { - ParsePost.parsePosts(response.body(), -1, filter, nsfw, + ParsePost.parsePosts(response.body(), -1, filter, nsfw, readPostList, new ParsePost.ParsePostsListingListener() { @Override public void onParsePostsListingSuccess(LinkedHashSet newPosts, String lastItem) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSourceFactory.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSourceFactory.java index 5973e009..6d49e4d3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSourceFactory.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSourceFactory.java @@ -10,6 +10,7 @@ import java.util.List; import java.util.Locale; import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.readpost.ReadPost; import ml.docilealligator.infinityforreddit.subredditfilter.SubredditFilter; import retrofit2.Retrofit; @@ -27,14 +28,16 @@ class PostDataSourceFactory extends DataSource.Factory { private String userWhere; private int filter; private boolean nsfw; + private List readPostList; private List subredditFilterList; private PostDataSource postDataSource; private MutableLiveData postDataSourceLiveData; PostDataSourceFactory(Retrofit retrofit, String accessToken, String accountName, Locale locale, - SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, - int postType, SortType sortType, int filter, boolean nsfw) { + SharedPreferences sharedPreferences, + SharedPreferences postFeedScrolledPositionSharedPreferences, int postType, + SortType sortType, int filter, boolean nsfw, List readPostList) { this.retrofit = retrofit; this.accessToken = accessToken; this.accountName = accountName; @@ -46,12 +49,13 @@ class PostDataSourceFactory extends DataSource.Factory { this.sortType = sortType; this.filter = filter; this.nsfw = nsfw; + this.readPostList = readPostList; } PostDataSourceFactory(Retrofit retrofit, String accessToken, String accountName, Locale locale, SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, String subredditName, int postType, SortType sortType, int filter, boolean nsfw, - List subredditFilterList) { + List readPostList, List subredditFilterList) { this.retrofit = retrofit; this.accessToken = accessToken; this.accountName = accountName; @@ -64,13 +68,14 @@ class PostDataSourceFactory extends DataSource.Factory { this.sortType = sortType; this.filter = filter; this.nsfw = nsfw; + this.readPostList = readPostList; this.subredditFilterList = subredditFilterList; } PostDataSourceFactory(Retrofit retrofit, String accessToken, String accountName, Locale locale, SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, String subredditName, int postType, SortType sortType, String where, int filter, - boolean nsfw) { + boolean nsfw, List readPostList) { this.retrofit = retrofit; this.accessToken = accessToken; this.accountName = accountName; @@ -84,12 +89,13 @@ class PostDataSourceFactory extends DataSource.Factory { userWhere = where; this.filter = filter; this.nsfw = nsfw; + this.readPostList = readPostList; } PostDataSourceFactory(Retrofit retrofit, String accessToken, String accountName, Locale locale, SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, String subredditName, String query, int postType, SortType sortType, int filter, - boolean nsfw) { + boolean nsfw, List readPostList) { this.retrofit = retrofit; this.accessToken = accessToken; this.accountName = accountName; @@ -103,6 +109,7 @@ class PostDataSourceFactory extends DataSource.Factory { this.sortType = sortType; this.filter = filter; this.nsfw = nsfw; + this.readPostList = readPostList; } @NonNull @@ -110,16 +117,20 @@ class PostDataSourceFactory extends DataSource.Factory { public DataSource create() { if (postType == PostDataSource.TYPE_FRONT_PAGE) { postDataSource = new PostDataSource(retrofit, accessToken, accountName, locale, - sharedPreferences, postFeedScrolledPositionSharedPreferences, postType, sortType, filter, nsfw); + sharedPreferences, postFeedScrolledPositionSharedPreferences, postType, sortType, filter, + nsfw, readPostList); } else if (postType == PostDataSource.TYPE_SEARCH) { postDataSource = new PostDataSource(retrofit, accessToken, accountName, locale, - sharedPreferences, postFeedScrolledPositionSharedPreferences, subredditName, query, postType, sortType, filter, nsfw); + sharedPreferences, postFeedScrolledPositionSharedPreferences, subredditName, query, + postType, sortType, filter, nsfw, readPostList); } else if (postType == PostDataSource.TYPE_SUBREDDIT || postType == PostDataSource.TYPE_MULTI_REDDIT) { postDataSource = new PostDataSource(retrofit, accessToken, accountName, locale, - sharedPreferences, postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, filter, nsfw, subredditFilterList); + sharedPreferences, postFeedScrolledPositionSharedPreferences, subredditName, postType, + sortType, filter, nsfw, readPostList, subredditFilterList); } else { postDataSource = new PostDataSource(retrofit, accessToken, accountName, locale, - sharedPreferences, postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, userWhere, filter, nsfw); + sharedPreferences, postFeedScrolledPositionSharedPreferences, subredditName, postType, + sortType, userWhere, filter, nsfw, readPostList); } postDataSourceLiveData.postValue(postDataSource); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java index 114c68ee..c9193429 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java @@ -18,6 +18,7 @@ import java.util.Locale; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.readpost.ReadPost; import ml.docilealligator.infinityforreddit.subredditfilter.SubredditFilter; import retrofit2.Retrofit; @@ -33,9 +34,9 @@ public class PostViewModel extends ViewModel { public PostViewModel(Retrofit retrofit, String accessToken, String accountName, Locale locale, SharedPreferences sharedPreferences, SharedPreferences cache, int postType, - SortType sortType, int filter, boolean nsfw) { + SortType sortType, int filter, boolean nsfw, List readPostList) { postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, accountName, locale, - sharedPreferences, cache, postType, sortType, filter, nsfw); + sharedPreferences, cache, postType, sortType, filter, nsfw, readPostList); initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(), PostDataSource::getInitialLoadStateLiveData); @@ -65,9 +66,11 @@ public class PostViewModel extends ViewModel { public PostViewModel(Retrofit retrofit, String accessToken, String accountName, Locale locale, SharedPreferences sharedPreferences, SharedPreferences cache, String subredditName, - int postType, SortType sortType, int filter, boolean nsfw, List subredditFilterList) { + int postType, SortType sortType, int filter, boolean nsfw, List readPostList, + List subredditFilterList) { postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, accountName, locale, - sharedPreferences, cache, subredditName, postType, sortType, filter, nsfw, subredditFilterList); + sharedPreferences, cache, subredditName, postType, sortType, filter, nsfw, readPostList, + subredditFilterList); initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(), PostDataSource::getInitialLoadStateLiveData); @@ -97,10 +100,10 @@ public class PostViewModel extends ViewModel { public PostViewModel(Retrofit retrofit, String accessToken, String accountName, Locale locale, SharedPreferences sharedPreferences, SharedPreferences cache, String subredditName, - int postType, SortType sortType, String where, int filter, - boolean nsfw) { + int postType, SortType sortType, String where, int filter, boolean nsfw, + List readPostList) { postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, accountName, locale, - sharedPreferences, cache, subredditName, postType, sortType, where, filter, nsfw); + sharedPreferences, cache, subredditName, postType, sortType, where, filter, nsfw, readPostList); initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(), PostDataSource::getInitialLoadStateLiveData); @@ -130,10 +133,10 @@ public class PostViewModel extends ViewModel { public PostViewModel(Retrofit retrofit, String accessToken, String accountName, Locale locale, SharedPreferences sharedPreferences, SharedPreferences cache, String subredditName, - String query, int postType, SortType sortType, int filter, - boolean nsfw) { + String query, int postType, SortType sortType, int filter, boolean nsfw, + List readPostList) { postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, accountName, locale, - sharedPreferences, cache, subredditName, query, postType, sortType, filter, nsfw); + sharedPreferences, cache, subredditName, query, postType, sortType, filter, nsfw, readPostList); initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(), PostDataSource::getInitialLoadStateLiveData); @@ -207,11 +210,12 @@ public class PostViewModel extends ViewModel { private String userWhere; private int filter; private boolean nsfw; + private List readPostList; private List subredditFilterList; public Factory(Retrofit retrofit, String accessToken, String accountName, Locale locale, SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, - int postType, SortType sortType, int filter, boolean nsfw) { + int postType, SortType sortType, int filter, boolean nsfw, List readPostList) { this.retrofit = retrofit; this.accessToken = accessToken; this.accountName = accountName; @@ -222,11 +226,12 @@ public class PostViewModel extends ViewModel { this.sortType = sortType; this.filter = filter; this.nsfw = nsfw; + this.readPostList = readPostList; } public Factory(Retrofit retrofit, String accessToken, String accountName, Locale locale, SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, String subredditName, - int postType, SortType sortType, int filter, boolean nsfw) { + int postType, SortType sortType, int filter, boolean nsfw, List readPostList) { this.retrofit = retrofit; this.accessToken = accessToken; this.accountName = accountName; @@ -238,12 +243,14 @@ public class PostViewModel extends ViewModel { this.sortType = sortType; this.filter = filter; this.nsfw = nsfw; + this.readPostList = readPostList; } //With subreddit filter public Factory(Retrofit retrofit, String accessToken, String accountName, Locale locale, SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, String subredditName, - int postType, SortType sortType, int filter, boolean nsfw, List subredditFilterList) { + int postType, SortType sortType, int filter, boolean nsfw, List readPostList, + List subredditFilterList) { this.retrofit = retrofit; this.accessToken = accessToken; this.accountName = accountName; @@ -255,14 +262,14 @@ public class PostViewModel extends ViewModel { this.sortType = sortType; this.filter = filter; this.nsfw = nsfw; + this.readPostList = readPostList; this.subredditFilterList = subredditFilterList; } //User posts public Factory(Retrofit retrofit, String accessToken, String accountName, Locale locale, SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, String subredditName, - int postType, SortType sortType, String where, int filter, - boolean nsfw) { + int postType, SortType sortType, String where, int filter, boolean nsfw, List readPostList) { this.retrofit = retrofit; this.accessToken = accessToken; this.accountName = accountName; @@ -275,11 +282,12 @@ public class PostViewModel extends ViewModel { userWhere = where; this.filter = filter; this.nsfw = nsfw; + this.readPostList = readPostList; } public Factory(Retrofit retrofit, String accessToken, String accountName, Locale locale, SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, String subredditName, - String query, int postType, SortType sortType, int filter, boolean nsfw) { + String query, int postType, SortType sortType, int filter, boolean nsfw, List readPostList) { this.retrofit = retrofit; this.accessToken = accessToken; this.accountName = accountName; @@ -292,6 +300,7 @@ public class PostViewModel extends ViewModel { this.sortType = sortType; this.filter = filter; this.nsfw = nsfw; + this.readPostList = readPostList; } @NonNull @@ -299,16 +308,19 @@ public class PostViewModel extends ViewModel { public T create(@NonNull Class modelClass) { if (postType == PostDataSource.TYPE_FRONT_PAGE) { return (T) new PostViewModel(retrofit, accessToken, accountName, locale, sharedPreferences, - postFeedScrolledPositionSharedPreferences, postType, sortType, filter, nsfw); + postFeedScrolledPositionSharedPreferences, postType, sortType, filter, nsfw, readPostList); } else if (postType == PostDataSource.TYPE_SEARCH) { return (T) new PostViewModel(retrofit, accessToken, accountName, locale, sharedPreferences, - postFeedScrolledPositionSharedPreferences, subredditName, query, postType, sortType, filter, nsfw); + postFeedScrolledPositionSharedPreferences, subredditName, query, postType, sortType, + filter, nsfw, readPostList); } else if (postType == PostDataSource.TYPE_SUBREDDIT || postType == PostDataSource.TYPE_MULTI_REDDIT) { return (T) new PostViewModel(retrofit, accessToken, accountName, locale, sharedPreferences, - postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, filter, nsfw, subredditFilterList); + postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, + filter, nsfw, readPostList, subredditFilterList); } else { return (T) new PostViewModel(retrofit, accessToken, accountName, locale, sharedPreferences, - postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, userWhere, filter, nsfw); + postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, + userWhere, filter, nsfw, readPostList); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/FetchReadPosts.java b/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/FetchReadPosts.java new file mode 100644 index 00000000..33ade1f3 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/FetchReadPosts.java @@ -0,0 +1,53 @@ +package ml.docilealligator.infinityforreddit.readpost; + +import android.os.AsyncTask; + +import java.util.ArrayList; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.subredditfilter.SubredditFilter; + +public class FetchReadPosts { + + public interface FetchReadPostsListener { + void success(ArrayList readPosts, ArrayList subredditFilters); + } + + public static void fetchReadPosts(RedditDataRoomDatabase redditDataRoomDatabase, String username, + boolean fetchSubredditFilter, FetchReadPostsListener fetchReadPostsListener) { + new FetchAllReadPostsAsyncTask(redditDataRoomDatabase, username, fetchSubredditFilter, fetchReadPostsListener).execute(); + } + + private static class FetchAllReadPostsAsyncTask extends AsyncTask { + + private RedditDataRoomDatabase redditDataRoomDatabase; + private String username; + private boolean fetchSubredditFilter; + private FetchReadPostsListener fetchReadPostsListener; + private ArrayList readPosts; + private ArrayList subredditFilters; + + private FetchAllReadPostsAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, String username, + boolean fetchSubredditFilter, FetchReadPostsListener fetchReadPostsListener) { + this.redditDataRoomDatabase = redditDataRoomDatabase; + this.username = username; + this.fetchSubredditFilter = fetchSubredditFilter; + this.fetchReadPostsListener = fetchReadPostsListener; + } + + @Override + protected Void doInBackground(Void... voids) { + readPosts = (ArrayList) redditDataRoomDatabase.readPostDao().getAllReadPosts(username); + if (fetchSubredditFilter) { + subredditFilters = (ArrayList) redditDataRoomDatabase.subredditFilterDao().getAllSubredditFilters(); + } + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + super.onPostExecute(aVoid); + fetchReadPostsListener.success(readPosts, subredditFilters); + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/InsertReadPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/InsertReadPost.java new file mode 100644 index 00000000..b5d34c6f --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/InsertReadPost.java @@ -0,0 +1,34 @@ +package ml.docilealligator.infinityforreddit.readpost; + +import android.os.AsyncTask; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; + +public class InsertReadPost { + public static void insertReadPost(RedditDataRoomDatabase redditDataRoomDatabase, String username, String postId) { + new InsertReadPostAsyncTask(redditDataRoomDatabase, username, postId).execute(); + } + + private static class InsertReadPostAsyncTask extends AsyncTask { + + private RedditDataRoomDatabase redditDataRoomDatabase; + private String username; + private String postId; + + public InsertReadPostAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, String username, String postId) { + this.redditDataRoomDatabase = redditDataRoomDatabase; + this.username = username; + this.postId = postId; + } + + @Override + protected Void doInBackground(Void... voids) { + ReadPostDao readPostDao = redditDataRoomDatabase.readPostDao(); + if (readPostDao.getReadPostsCount() > 500) { + readPostDao.deleteOldestReadPosts(username); + } + readPostDao.insert(new ReadPost(username, postId)); + return null; + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/ReadPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/ReadPost.java new file mode 100644 index 00000000..df704f3d --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/ReadPost.java @@ -0,0 +1,93 @@ +package ml.docilealligator.infinityforreddit.readpost; + +import android.os.Parcel; +import android.os.Parcelable; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.room.ColumnInfo; +import androidx.room.Entity; +import androidx.room.ForeignKey; + +import ml.docilealligator.infinityforreddit.account.Account; +import ml.docilealligator.infinityforreddit.post.Post; + +@Entity(tableName = "read_posts", primaryKeys = {"username", "id"}, + foreignKeys = @ForeignKey(entity = Account.class, parentColumns = "username", + childColumns = "username", onDelete = ForeignKey.CASCADE)) +public class ReadPost implements Parcelable { + @NonNull + @ColumnInfo(name = "username") + private String username; + @NonNull + @ColumnInfo(name = "id") + private String id; + + public static ReadPost convertPost(Post post) { + return new ReadPost("temp", post.getId()); + } + + public ReadPost(@NonNull String username, @NonNull String id) { + this.username = username; + this.id = id; + } + + protected ReadPost(Parcel in) { + username = in.readString(); + id = in.readString(); + } + + public static final Creator CREATOR = new Creator() { + @Override + public ReadPost createFromParcel(Parcel in) { + return new ReadPost(in); + } + + @Override + public ReadPost[] newArray(int size) { + return new ReadPost[size]; + } + }; + + @NonNull + public String getUsername() { + return username; + } + + public void setUsername(@NonNull String username) { + this.username = username; + } + + @NonNull + public String getId() { + return id; + } + + public void setId(@NonNull String id) { + this.id = id; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeString(username); + parcel.writeString(id); + } + + @Override + public boolean equals(@Nullable Object obj) { + if (obj instanceof ReadPost) { + return ((ReadPost) obj).id.equals(id); + } + return false; + } + + @Override + public int hashCode() { + return id.hashCode(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/ReadPostDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/ReadPostDao.java new file mode 100644 index 00000000..d129e109 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/ReadPostDao.java @@ -0,0 +1,23 @@ +package ml.docilealligator.infinityforreddit.readpost; + +import androidx.room.Dao; +import androidx.room.Insert; +import androidx.room.OnConflictStrategy; +import androidx.room.Query; + +import java.util.List; + +@Dao +public interface ReadPostDao { + @Insert(onConflict = OnConflictStrategy.REPLACE) + void insert(ReadPost readPost); + + @Query("SELECT * FROM read_posts WHERE username = :username") + List getAllReadPosts(String username); + + @Query("SELECT COUNT(id) FROM read_posts") + int getReadPostsCount(); + + @Query("DELETE FROM read_posts WHERE rowid IN (SELECT rowid FROM read_posts LIMIT 100) AND username = :username") + void deleteOldestReadPosts(String username); +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/readposts/FetchReadPosts.java b/app/src/main/java/ml/docilealligator/infinityforreddit/readposts/FetchReadPosts.java deleted file mode 100644 index cfb70789..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/readposts/FetchReadPosts.java +++ /dev/null @@ -1,53 +0,0 @@ -package ml.docilealligator.infinityforreddit.readposts; - -import android.os.AsyncTask; - -import java.util.ArrayList; - -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.subredditfilter.SubredditFilter; - -public class FetchReadPosts { - - public interface FetchReadPostsListener { - void success(ArrayList readPosts, ArrayList subredditFilters); - } - - public static void fetchReadPosts(RedditDataRoomDatabase redditDataRoomDatabase, String username, - boolean fetchSubredditFilter, FetchReadPostsListener fetchReadPostsListener) { - new FetchAllReadPostsAsyncTask(redditDataRoomDatabase, username, fetchSubredditFilter, fetchReadPostsListener).execute(); - } - - private static class FetchAllReadPostsAsyncTask extends AsyncTask { - - private RedditDataRoomDatabase redditDataRoomDatabase; - private String username; - private boolean fetchSubredditFilter; - private FetchReadPostsListener fetchReadPostsListener; - private ArrayList readPosts; - private ArrayList subredditFilters; - - private FetchAllReadPostsAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, String username, - boolean fetchSubredditFilter, FetchReadPostsListener fetchReadPostsListener) { - this.redditDataRoomDatabase = redditDataRoomDatabase; - this.username = username; - this.fetchSubredditFilter = fetchSubredditFilter; - this.fetchReadPostsListener = fetchReadPostsListener; - } - - @Override - protected Void doInBackground(Void... voids) { - readPosts = (ArrayList) redditDataRoomDatabase.readPostDao().getAllReadPosts(username); - if (fetchSubredditFilter) { - subredditFilters = (ArrayList) redditDataRoomDatabase.subredditFilterDao().getAllSubredditFilters(); - } - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - fetchReadPostsListener.success(readPosts, subredditFilters); - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/readposts/ReadPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/readposts/ReadPost.java deleted file mode 100644 index 27a76b85..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/readposts/ReadPost.java +++ /dev/null @@ -1,74 +0,0 @@ -package ml.docilealligator.infinityforreddit.readposts; - -import android.os.Parcel; -import android.os.Parcelable; - -import androidx.annotation.NonNull; -import androidx.room.ColumnInfo; -import androidx.room.Entity; -import androidx.room.ForeignKey; - -import ml.docilealligator.infinityforreddit.account.Account; - -@Entity(tableName = "read_posts", primaryKeys = {"username", "id"}, - foreignKeys = @ForeignKey(entity = Account.class, parentColumns = "username", - childColumns = "username", onDelete = ForeignKey.CASCADE)) -public class ReadPost implements Parcelable { - @NonNull - @ColumnInfo(name = "username") - private String username; - @NonNull - @ColumnInfo(name = "id") - private String id; - - public ReadPost(@NonNull String username, @NonNull String id) { - this.username = username; - this.id = id; - } - - protected ReadPost(Parcel in) { - username = in.readString(); - id = in.readString(); - } - - public static final Creator CREATOR = new Creator() { - @Override - public ReadPost createFromParcel(Parcel in) { - return new ReadPost(in); - } - - @Override - public ReadPost[] newArray(int size) { - return new ReadPost[size]; - } - }; - - @NonNull - public String getUsername() { - return username; - } - - public void setUsername(@NonNull String username) { - this.username = username; - } - - @NonNull - public String getId() { - return id; - } - - public void setId(@NonNull String id) { - this.id = id; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - parcel.writeString(username); - parcel.writeString(id); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/readposts/ReadPostDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/readposts/ReadPostDao.java deleted file mode 100644 index 1363f14b..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/readposts/ReadPostDao.java +++ /dev/null @@ -1,20 +0,0 @@ -package ml.docilealligator.infinityforreddit.readposts; - -import androidx.room.Dao; -import androidx.room.Insert; -import androidx.room.OnConflictStrategy; -import androidx.room.Query; - -import java.util.List; - -@Dao -public interface ReadPostDao { - @Insert(onConflict = OnConflictStrategy.REPLACE) - void insert(ReadPost readPost); - - @Query("SELECT * FROM read_posts WHERE username = :username") - List getAllReadPosts(String username); - - @Query("DELETE FROM read_posts WHERE rowid IN (SELECT rowid FROM read_posts LIMIT 100) AND username = :username") - void deleteOldestReadPosts(String username); -} -- cgit v1.2.3