diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-12-07 07:34:51 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-12-07 07:34:51 +0000 |
commit | ca932090e31eaba3c622d0aa5f3f8f8ab0902c69 (patch) | |
tree | 0817092d765b74e6b24b46763449fe0e766085b8 /app/src/main | |
parent | e33bc02481187ca2246c9da241d94779b1d6a34f (diff) | |
download | infinity-for-reddit-ca932090e31eaba3c622d0aa5f3f8f8ab0902c69.tar infinity-for-reddit-ca932090e31eaba3c622d0aa5f3f8f8ab0902c69.tar.gz infinity-for-reddit-ca932090e31eaba3c622d0aa5f3f8f8ab0902c69.tar.bz2 infinity-for-reddit-ca932090e31eaba3c622d0aa5f3f8f8ab0902c69.tar.lz infinity-for-reddit-ca932090e31eaba3c622d0aa5f3f8f8ab0902c69.tar.xz infinity-for-reddit-ca932090e31eaba3c622d0aa5f3f8f8ab0902c69.tar.zst infinity-for-reddit-ca932090e31eaba3c622d0aa5f3f8f8ab0902c69.zip |
Prepare to add a new feature: hide read posts.
Diffstat (limited to '')
8 files changed, 410 insertions, 120 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java index 6c376569..73138eae 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java @@ -16,6 +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.recentsearchquery.RecentSearchQuery; import ml.docilealligator.infinityforreddit.recentsearchquery.RecentSearchQueryDao; import ml.docilealligator.infinityforreddit.subreddit.SubredditDao; @@ -30,7 +32,8 @@ import ml.docilealligator.infinityforreddit.user.UserDao; import ml.docilealligator.infinityforreddit.user.UserData; @Database(entities = {Account.class, SubredditData.class, SubscribedSubredditData.class, UserData.class, - SubscribedUserData.class, MultiReddit.class, CustomTheme.class, RecentSearchQuery.class, SubredditFilter.class}, version = 13) + SubscribedUserData.class, MultiReddit.class, CustomTheme.class, RecentSearchQuery.class, + SubredditFilter.class, ReadPost.class}, version = 14) public abstract class RedditDataRoomDatabase extends RoomDatabase { private static RedditDataRoomDatabase INSTANCE; @@ -68,6 +71,8 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase { public abstract SubredditFilterDao subredditFilterDao(); + public abstract ReadPostDao readPostDao(); + private static final Migration MIGRATION_1_2 = new Migration(1, 2) { @Override public void migrate(SupportSQLiteDatabase database) { @@ -263,4 +268,16 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase { + " ADD COLUMN no_preview_post_type_icon_tint INTEGER DEFAULT " + Color.parseColor("#808080") + " NOT NULL"); } }; + + private static final Migration MIGRATION_13_14 = new Migration(13, 14) { + @Override + public void migrate(@NonNull SupportSQLiteDatabase database) { + database.execSQL("CREATE TABLE read_posts" + + "(username TEXT NOT NULL, id TEXT NOT NULL, PRIMARY KEY(username, id), " + + "FOREIGN KEY(username) REFERENCES accounts(username) ON DELETE CASCADE)"); + database.execSQL("ALTER TABLE custom_themes ADD COLUMN read_post_title_color INTEGER DEFAULT " + Color.parseColor("#9D9D9D") + " NOT NULL"); + database.execSQL("ALTER TABLE custom_themes ADD COLUMN read_post_content_color INTEGER DEFAULT " + Color.parseColor("#9D9D9D") + " NOT NULL"); + database.execSQL("ALTER TABLE custom_themes ADD COLUMN read_post_card_view_background_color INTEGER DEFAULT " + Color.parseColor("#F5F5F5") + " NOT NULL"); + } + }; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customtheme/CustomTheme.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customtheme/CustomTheme.java index fb9bda02..c428efb9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customtheme/CustomTheme.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customtheme/CustomTheme.java @@ -37,6 +37,10 @@ public class CustomTheme { public int postTitleColor; @ColumnInfo(name = "post_content_color") public int postContentColor; + @ColumnInfo(name = "read_post_title_color") + public int readPostTitleColor; + @ColumnInfo(name = "read_post_content_color") + public int readPostContentColor; @ColumnInfo(name = "comment_color") public int commentColor; @ColumnInfo(name = "button_text_color") @@ -45,6 +49,8 @@ public class CustomTheme { public int backgroundColor; @ColumnInfo(name = "card_view_background_color") public int cardViewBackgroundColor; + @ColumnInfo(name = "read_post_card_view_background_color") + public int readPostCardViewBackgroundColor; @ColumnInfo(name = "comment_background_color") public int commentBackgroundColor; @ColumnInfo(name = "bottom_app_bar_background_color") @@ -205,75 +211,78 @@ public class CustomTheme { customTheme.secondaryTextColor = customThemeSettingsItems.get(8).colorValue; customTheme.postTitleColor = customThemeSettingsItems.get(9).colorValue; customTheme.postContentColor = customThemeSettingsItems.get(10).colorValue; - customTheme.commentColor = customThemeSettingsItems.get(11).colorValue; - customTheme.buttonTextColor = customThemeSettingsItems.get(12).colorValue; - customTheme.chipTextColor = customThemeSettingsItems.get(13).colorValue; - customTheme.linkColor = customThemeSettingsItems.get(14).colorValue; - customTheme.receivedMessageTextColor = customThemeSettingsItems.get(15).colorValue; - customTheme.sentMessageTextColor = customThemeSettingsItems.get(16).colorValue; - customTheme.backgroundColor = customThemeSettingsItems.get(17).colorValue; - customTheme.cardViewBackgroundColor = customThemeSettingsItems.get(18).colorValue; - customTheme.commentBackgroundColor = customThemeSettingsItems.get(19).colorValue; - customTheme.fullyCollapsedCommentBackgroundColor = customThemeSettingsItems.get(20).colorValue; - customTheme.awardedCommentBackgroundColor = customThemeSettingsItems.get(21).colorValue; - customTheme.receivedMessageBackgroundColor = customThemeSettingsItems.get(22).colorValue; - customTheme.sentMessageBackgroundColor = customThemeSettingsItems.get(23).colorValue; - customTheme.bottomAppBarBackgroundColor = customThemeSettingsItems.get(24).colorValue; - customTheme.primaryIconColor = customThemeSettingsItems.get(25).colorValue; - customTheme.bottomAppBarIconColor = customThemeSettingsItems.get(26).colorValue; - customTheme.postIconAndInfoColor = customThemeSettingsItems.get(27).colorValue; - customTheme.commentIconAndInfoColor = customThemeSettingsItems.get(28).colorValue; - customTheme.fabIconColor = customThemeSettingsItems.get(29).colorValue; - customTheme.sendMessageIconColor = customThemeSettingsItems.get(30).colorValue; - customTheme.toolbarPrimaryTextAndIconColor = customThemeSettingsItems.get(31).colorValue; - customTheme.toolbarSecondaryTextColor = customThemeSettingsItems.get(32).colorValue; - customTheme.circularProgressBarBackground = customThemeSettingsItems.get(33).colorValue; - customTheme.tabLayoutWithExpandedCollapsingToolbarTabBackground = customThemeSettingsItems.get(34).colorValue; - customTheme.tabLayoutWithExpandedCollapsingToolbarTextColor = customThemeSettingsItems.get(35).colorValue; - customTheme.tabLayoutWithExpandedCollapsingToolbarTabIndicator = customThemeSettingsItems.get(36).colorValue; - customTheme.tabLayoutWithCollapsedCollapsingToolbarTabBackground = customThemeSettingsItems.get(37).colorValue; - customTheme.tabLayoutWithCollapsedCollapsingToolbarTextColor = customThemeSettingsItems.get(38).colorValue; - customTheme.tabLayoutWithCollapsedCollapsingToolbarTabIndicator = customThemeSettingsItems.get(39).colorValue; - customTheme.upvoted = customThemeSettingsItems.get(40).colorValue; - customTheme.downvoted = customThemeSettingsItems.get(41).colorValue; - customTheme.postTypeBackgroundColor = customThemeSettingsItems.get(42).colorValue; - customTheme.postTypeTextColor = customThemeSettingsItems.get(43).colorValue; - customTheme.spoilerBackgroundColor = customThemeSettingsItems.get(44).colorValue; - customTheme.spoilerTextColor = customThemeSettingsItems.get(45).colorValue; - customTheme.nsfwBackgroundColor = customThemeSettingsItems.get(46).colorValue; - customTheme.nsfwTextColor = customThemeSettingsItems.get(47).colorValue; - customTheme.flairBackgroundColor = customThemeSettingsItems.get(48).colorValue; - customTheme.flairTextColor = customThemeSettingsItems.get(49).colorValue; - customTheme.awardsBackgroundColor = customThemeSettingsItems.get(50).colorValue; - customTheme.awardsTextColor = customThemeSettingsItems.get(51).colorValue; - customTheme.archivedTint = customThemeSettingsItems.get(52).colorValue; - customTheme.lockedIconTint = customThemeSettingsItems.get(53).colorValue; - customTheme.crosspostIconTint = customThemeSettingsItems.get(54).colorValue; - customTheme.stickiedPostIconTint = customThemeSettingsItems.get(55).colorValue; - customTheme.noPreviewPostTypeIconTint = customThemeSettingsItems.get(56).colorValue; - customTheme.subscribed = customThemeSettingsItems.get(57).colorValue; - customTheme.unsubscribed = customThemeSettingsItems.get(58).colorValue; - customTheme.username = customThemeSettingsItems.get(59).colorValue; - customTheme.subreddit = customThemeSettingsItems.get(60).colorValue; - customTheme.authorFlairTextColor = customThemeSettingsItems.get(61).colorValue; - customTheme.submitter = customThemeSettingsItems.get(62).colorValue; - customTheme.moderator = customThemeSettingsItems.get(63).colorValue; - customTheme.singleCommentThreadBackgroundColor = customThemeSettingsItems.get(64).colorValue; - customTheme.unreadMessageBackgroundColor = customThemeSettingsItems.get(65).colorValue; - customTheme.dividerColor = customThemeSettingsItems.get(66).colorValue; - customTheme.noPreviewPostTypeBackgroundColor = customThemeSettingsItems.get(67).colorValue; - customTheme.voteAndReplyUnavailableButtonColor = customThemeSettingsItems.get(68).colorValue; - customTheme.commentVerticalBarColor1 = customThemeSettingsItems.get(69).colorValue; - customTheme.commentVerticalBarColor2 = customThemeSettingsItems.get(70).colorValue; - customTheme.commentVerticalBarColor3 = customThemeSettingsItems.get(71).colorValue; - customTheme.commentVerticalBarColor4 = customThemeSettingsItems.get(72).colorValue; - customTheme.commentVerticalBarColor5 = customThemeSettingsItems.get(73).colorValue; - customTheme.commentVerticalBarColor6 = customThemeSettingsItems.get(74).colorValue; - customTheme.commentVerticalBarColor7 = customThemeSettingsItems.get(75).colorValue; - customTheme.navBarColor = customThemeSettingsItems.get(76).colorValue; - customTheme.isLightStatusBar = customThemeSettingsItems.get(77).isEnabled; - customTheme.isLightNavBar = customThemeSettingsItems.get(78).isEnabled; - customTheme.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface = customThemeSettingsItems.get(79).isEnabled; + customTheme.readPostTitleColor = customThemeSettingsItems.get(11).colorValue; + customTheme.readPostContentColor = customThemeSettingsItems.get(12).colorValue; + customTheme.commentColor = customThemeSettingsItems.get(13).colorValue; + customTheme.buttonTextColor = customThemeSettingsItems.get(14).colorValue; + customTheme.chipTextColor = customThemeSettingsItems.get(15).colorValue; + customTheme.linkColor = customThemeSettingsItems.get(16).colorValue; + customTheme.receivedMessageTextColor = customThemeSettingsItems.get(17).colorValue; + customTheme.sentMessageTextColor = customThemeSettingsItems.get(18).colorValue; + customTheme.backgroundColor = customThemeSettingsItems.get(19).colorValue; + customTheme.cardViewBackgroundColor = customThemeSettingsItems.get(20).colorValue; + customTheme.readPostCardViewBackgroundColor = customThemeSettingsItems.get(21).colorValue; + customTheme.commentBackgroundColor = customThemeSettingsItems.get(22).colorValue; + customTheme.fullyCollapsedCommentBackgroundColor = customThemeSettingsItems.get(23).colorValue; + customTheme.awardedCommentBackgroundColor = customThemeSettingsItems.get(24).colorValue; + customTheme.receivedMessageBackgroundColor = customThemeSettingsItems.get(25).colorValue; + customTheme.sentMessageBackgroundColor = customThemeSettingsItems.get(26).colorValue; + customTheme.bottomAppBarBackgroundColor = customThemeSettingsItems.get(27).colorValue; + customTheme.primaryIconColor = customThemeSettingsItems.get(28).colorValue; + customTheme.bottomAppBarIconColor = customThemeSettingsItems.get(29).colorValue; + customTheme.postIconAndInfoColor = customThemeSettingsItems.get(30).colorValue; + customTheme.commentIconAndInfoColor = customThemeSettingsItems.get(31).colorValue; + customTheme.fabIconColor = customThemeSettingsItems.get(32).colorValue; + customTheme.sendMessageIconColor = customThemeSettingsItems.get(33).colorValue; + customTheme.toolbarPrimaryTextAndIconColor = customThemeSettingsItems.get(34).colorValue; + customTheme.toolbarSecondaryTextColor = customThemeSettingsItems.get(35).colorValue; + customTheme.circularProgressBarBackground = customThemeSettingsItems.get(36).colorValue; + customTheme.tabLayoutWithExpandedCollapsingToolbarTabBackground = customThemeSettingsItems.get(37).colorValue; + customTheme.tabLayoutWithExpandedCollapsingToolbarTextColor = customThemeSettingsItems.get(38).colorValue; + customTheme.tabLayoutWithExpandedCollapsingToolbarTabIndicator = customThemeSettingsItems.get(39).colorValue; + customTheme.tabLayoutWithCollapsedCollapsingToolbarTabBackground = customThemeSettingsItems.get(40).colorValue; + customTheme.tabLayoutWithCollapsedCollapsingToolbarTextColor = customThemeSettingsItems.get(41).colorValue; + customTheme.tabLayoutWithCollapsedCollapsingToolbarTabIndicator = customThemeSettingsItems.get(42).colorValue; + customTheme.upvoted = customThemeSettingsItems.get(43).colorValue; + customTheme.downvoted = customThemeSettingsItems.get(44).colorValue; + customTheme.postTypeBackgroundColor = customThemeSettingsItems.get(45).colorValue; + customTheme.postTypeTextColor = customThemeSettingsItems.get(46).colorValue; + customTheme.spoilerBackgroundColor = customThemeSettingsItems.get(47).colorValue; + customTheme.spoilerTextColor = customThemeSettingsItems.get(48).colorValue; + customTheme.nsfwBackgroundColor = customThemeSettingsItems.get(49).colorValue; + customTheme.nsfwTextColor = customThemeSettingsItems.get(50).colorValue; + customTheme.flairBackgroundColor = customThemeSettingsItems.get(51).colorValue; + customTheme.flairTextColor = customThemeSettingsItems.get(52).colorValue; + customTheme.awardsBackgroundColor = customThemeSettingsItems.get(53).colorValue; + customTheme.awardsTextColor = customThemeSettingsItems.get(54).colorValue; + customTheme.archivedTint = customThemeSettingsItems.get(55).colorValue; + customTheme.lockedIconTint = customThemeSettingsItems.get(56).colorValue; + customTheme.crosspostIconTint = customThemeSettingsItems.get(57).colorValue; + customTheme.stickiedPostIconTint = customThemeSettingsItems.get(58).colorValue; + customTheme.noPreviewPostTypeIconTint = customThemeSettingsItems.get(59).colorValue; + customTheme.subscribed = customThemeSettingsItems.get(60).colorValue; + customTheme.unsubscribed = customThemeSettingsItems.get(61).colorValue; + customTheme.username = customThemeSettingsItems.get(62).colorValue; + customTheme.subreddit = customThemeSettingsItems.get(63).colorValue; + customTheme.authorFlairTextColor = customThemeSettingsItems.get(64).colorValue; + customTheme.submitter = customThemeSettingsItems.get(65).colorValue; + customTheme.moderator = customThemeSettingsItems.get(66).colorValue; + customTheme.singleCommentThreadBackgroundColor = customThemeSettingsItems.get(67).colorValue; + customTheme.unreadMessageBackgroundColor = customThemeSettingsItems.get(68).colorValue; + customTheme.dividerColor = customThemeSettingsItems.get(69).colorValue; + customTheme.noPreviewPostTypeBackgroundColor = customThemeSettingsItems.get(70).colorValue; + customTheme.voteAndReplyUnavailableButtonColor = customThemeSettingsItems.get(71).colorValue; + customTheme.commentVerticalBarColor1 = customThemeSettingsItems.get(72).colorValue; + customTheme.commentVerticalBarColor2 = customThemeSettingsItems.get(73).colorValue; + customTheme.commentVerticalBarColor3 = customThemeSettingsItems.get(74).colorValue; + customTheme.commentVerticalBarColor4 = customThemeSettingsItems.get(75).colorValue; + customTheme.commentVerticalBarColor5 = customThemeSettingsItems.get(76).colorValue; + customTheme.commentVerticalBarColor6 = customThemeSettingsItems.get(77).colorValue; + customTheme.commentVerticalBarColor7 = customThemeSettingsItems.get(78).colorValue; + customTheme.navBarColor = customThemeSettingsItems.get(79).colorValue; + customTheme.isLightStatusBar = customThemeSettingsItems.get(80).isEnabled; + customTheme.isLightNavBar = customThemeSettingsItems.get(81).isEnabled; + customTheme.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface = customThemeSettingsItems.get(82).isEnabled; return customTheme; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customtheme/CustomThemeWrapper.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customtheme/CustomThemeWrapper.java index 8621559f..f0a8c0b7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customtheme/CustomThemeWrapper.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customtheme/CustomThemeWrapper.java @@ -92,6 +92,16 @@ public class CustomThemeWrapper { getDefaultColor("#8A000000", "#B3FFFFFF", "#B3FFFFFF")); } + public int getReadPostTitleColor() { + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.READ_POST_TITLE_COLOR, + getDefaultColor("#9D9D9D", "#979797", "#979797")); + } + + public int getReadPostContentColor() { + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.READ_POST_CONTENT_COLOR, + getDefaultColor("#9D9D9D", "#979797", "#979797")); + } + public int getCommentColor() { return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COMMENT_COLOR, getDefaultColor("#000000", "#FFFFFF", "#FFFFFF")); @@ -112,6 +122,11 @@ public class CustomThemeWrapper { getDefaultColor("#FFFFFF", "#242424", "#000000")); } + public int getReadPostCardViewBackgroundColor() { + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.READ_POST_CARD_VIEW_BACKGROUND_COLOR, + getDefaultColor("#F5F5F5", "#101010", "#000000")); + } + public int getCommentBackgroundColor() { return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COMMENT_BACKGROUND_COLOR, getDefaultColor("#FFFFFF", "#242424", "#000000")); @@ -492,10 +507,13 @@ public class CustomThemeWrapper { customTheme.secondaryTextColor = Color.parseColor("#8A000000"); customTheme.postTitleColor = Color.parseColor("#000000"); customTheme.postContentColor = Color.parseColor("#8A000000"); + customTheme.readPostTitleColor = Color.parseColor("#9D9D9D"); + customTheme.readPostContentColor = Color.parseColor("#9D9D9D"); customTheme.commentColor = Color.parseColor("#000000"); customTheme.buttonTextColor = Color.parseColor("#FFFFFF"); customTheme.backgroundColor = Color.parseColor("#FFFFFF"); customTheme.cardViewBackgroundColor = Color.parseColor("#FFFFFF"); + customTheme.readPostCardViewBackgroundColor = Color.parseColor("#F5F5F5"); customTheme.commentBackgroundColor = Color.parseColor("#FFFFFF"); customTheme.bottomAppBarBackgroundColor = Color.parseColor("#FFFFFF"); customTheme.primaryIconColor = Color.parseColor("#000000"); @@ -578,10 +596,13 @@ public class CustomThemeWrapper { customTheme.secondaryTextColor = Color.parseColor("#B3FFFFFF"); customTheme.postTitleColor = Color.parseColor("#FFFFFF"); customTheme.postContentColor = Color.parseColor("#B3FFFFFF"); + customTheme.readPostTitleColor = Color.parseColor("#979797"); + customTheme.readPostContentColor = Color.parseColor("#979797"); customTheme.commentColor = Color.parseColor("#FFFFFF"); customTheme.buttonTextColor = Color.parseColor("#FFFFFF"); customTheme.backgroundColor = Color.parseColor("#121212"); customTheme.cardViewBackgroundColor = Color.parseColor("#242424"); + customTheme.readPostCardViewBackgroundColor = Color.parseColor("#101010"); customTheme.commentBackgroundColor = Color.parseColor("#242424"); customTheme.bottomAppBarBackgroundColor = Color.parseColor("#121212"); customTheme.primaryIconColor = Color.parseColor("#FFFFFF"); @@ -664,10 +685,13 @@ public class CustomThemeWrapper { customTheme.secondaryTextColor = Color.parseColor("#B3FFFFFF"); customTheme.postTitleColor = Color.parseColor("#FFFFFF"); customTheme.postContentColor = Color.parseColor("#B3FFFFFF"); + customTheme.readPostTitleColor = Color.parseColor("#979797"); + customTheme.readPostContentColor = Color.parseColor("#979797"); customTheme.commentColor = Color.parseColor("#FFFFFF"); customTheme.buttonTextColor = Color.parseColor("#FFFFFF"); customTheme.backgroundColor = Color.parseColor("#000000"); customTheme.cardViewBackgroundColor = Color.parseColor("#000000"); + customTheme.readPostCardViewBackgroundColor = Color.parseColor("#000000"); customTheme.commentBackgroundColor = Color.parseColor("#000000"); customTheme.bottomAppBarBackgroundColor = Color.parseColor("#000000"); customTheme.primaryIconColor = Color.parseColor("#FFFFFF"); @@ -750,10 +774,13 @@ public class CustomThemeWrapper { customTheme.secondaryTextColor = Color.parseColor("#8A000000"); customTheme.postTitleColor = Color.parseColor("#000000"); customTheme.postContentColor = Color.parseColor("#8A000000"); + customTheme.readPostTitleColor = Color.parseColor("#9D9D9D"); + customTheme.readPostContentColor = Color.parseColor("#9D9D9D"); customTheme.commentColor = Color.parseColor("#000000"); customTheme.buttonTextColor = Color.parseColor("#000000"); customTheme.backgroundColor = Color.parseColor("#FFFFFF"); customTheme.cardViewBackgroundColor = Color.parseColor("#FFFFFF"); + customTheme.readPostCardViewBackgroundColor = Color.parseColor("#F5F5F5"); customTheme.commentBackgroundColor = Color.parseColor("#FFFFFF"); customTheme.bottomAppBarBackgroundColor = Color.parseColor("#FFFFFF"); customTheme.primaryIconColor = Color.parseColor("#000000"); @@ -836,10 +863,13 @@ public class CustomThemeWrapper { customTheme.secondaryTextColor = Color.parseColor("#B3FFFFFF"); customTheme.postTitleColor = Color.parseColor("#FFFFFF"); customTheme.postContentColor = Color.parseColor("#B3FFFFFF"); + customTheme.readPostTitleColor = Color.parseColor("#979797"); + customTheme.readPostContentColor = Color.parseColor("#979797"); customTheme.commentColor = Color.parseColor("#FFFFFF"); customTheme.buttonTextColor = Color.parseColor("#FFFFFF"); customTheme.backgroundColor = Color.parseColor("#121212"); customTheme.cardViewBackgroundColor = Color.parseColor("#242424"); + customTheme.readPostCardViewBackgroundColor = Color.parseColor("#101010"); customTheme.commentBackgroundColor = Color.parseColor("#242424"); customTheme.bottomAppBarBackgroundColor = Color.parseColor("#121212"); customTheme.primaryIconColor = Color.parseColor("#FFFFFF"); @@ -922,10 +952,13 @@ public class CustomThemeWrapper { customTheme.secondaryTextColor = Color.parseColor("#B3FFFFFF"); customTheme.postTitleColor = Color.parseColor("#FFFFFF"); customTheme.postContentColor = Color.parseColor("#B3FFFFFF"); + customTheme.readPostTitleColor = Color.parseColor("#979797"); + customTheme.readPostContentColor = Color.parseColor("#979797"); customTheme.commentColor = Color.parseColor("#FFFFFF"); customTheme.buttonTextColor = Color.parseColor("#FFFFFF"); customTheme.backgroundColor = Color.parseColor("#000000"); customTheme.cardViewBackgroundColor = Color.parseColor("#000000"); + customTheme.readPostCardViewBackgroundColor = Color.parseColor("#000000"); customTheme.commentBackgroundColor = Color.parseColor("#000000"); customTheme.bottomAppBarBackgroundColor = Color.parseColor("#000000"); customTheme.primaryIconColor = Color.parseColor("#FFFFFF"); @@ -1008,10 +1041,13 @@ public class CustomThemeWrapper { customTheme.secondaryTextColor = Color.parseColor("#8A000000"); customTheme.postTitleColor = Color.parseColor("#000000"); customTheme.postContentColor = Color.parseColor("#8A000000"); + customTheme.readPostTitleColor = Color.parseColor("#9D9D9D"); + customTheme.readPostContentColor = Color.parseColor("#9D9D9D"); customTheme.commentColor = Color.parseColor("#000000"); customTheme.buttonTextColor = Color.parseColor("#FFFFFF"); customTheme.backgroundColor = Color.parseColor("#FFFFFF"); customTheme.cardViewBackgroundColor = Color.parseColor("#FFFFFF"); + customTheme.readPostCardViewBackgroundColor = Color.parseColor("#F5F5F5"); customTheme.commentBackgroundColor = Color.parseColor("#FFFFFF"); customTheme.bottomAppBarBackgroundColor = Color.parseColor("#FFFFFF"); customTheme.primaryIconColor = Color.parseColor("#000000"); @@ -1094,10 +1130,13 @@ public class CustomThemeWrapper { customTheme.secondaryTextColor = Color.parseColor("#B3FFFFFF"); customTheme.postTitleColor = Color.parseColor("#FFFFFF"); customTheme.postContentColor = Color.parseColor("#B3FFFFFF"); + customTheme.readPostTitleColor = Color.parseColor("#979797"); + customTheme.readPostContentColor = Color.parseColor("#979797"); customTheme.commentColor = Color.parseColor("#FFFFFF"); customTheme.buttonTextColor = Color.parseColor("#FFFFFF"); customTheme.backgroundColor = Color.parseColor("#121212"); customTheme.cardViewBackgroundColor = Color.parseColor("#242424"); + customTheme.readPostCardViewBackgroundColor = Color.parseColor("#101010"); customTheme.commentBackgroundColor = Color.parseColor("#242424"); customTheme.bottomAppBarBackgroundColor = Color.parseColor("#121212"); customTheme.primaryIconColor = Color.parseColor("#FFFFFF"); @@ -1180,10 +1219,13 @@ public class CustomThemeWrapper { customTheme.secondaryTextColor = Color.parseColor("#B3FFFFFF"); customTheme.postTitleColor = Color.parseColor("#FFFFFF"); customTheme.postContentColor = Color.parseColor("#B3FFFFFF"); + customTheme.readPostTitleColor = Color.parseColor("#979797"); + customTheme.readPostContentColor = Color.parseColor("#979797"); customTheme.commentColor = Color.parseColor("#FFFFFF"); customTheme.buttonTextColor = Color.parseColor("#FFFFFF"); customTheme.backgroundColor = Color.parseColor("#000000"); customTheme.cardViewBackgroundColor = Color.parseColor("#000000"); + customTheme.readPostCardViewBackgroundColor = Color.parseColor("#000000"); customTheme.commentBackgroundColor = Color.parseColor("#000000"); customTheme.bottomAppBarBackgroundColor = Color.parseColor("#000000"); customTheme.primaryIconColor = Color.parseColor("#FFFFFF"); @@ -1266,10 +1308,13 @@ public class CustomThemeWrapper { customTheme.secondaryTextColor = Color.parseColor("#B3FFFFFF"); customTheme.postTitleColor = Color.parseColor("#FFFFFF"); customTheme.postContentColor = Color.parseColor("#B3FFFFFF"); + customTheme.readPostTitleColor = Color.parseColor("#9D9D9D"); + customTheme.readPostContentColor = Color.parseColor("#9D9D9D"); customTheme.commentColor = Color.parseColor("#FFFFFF"); customTheme.buttonTextColor = Color.parseColor("#FFFFFF"); customTheme.backgroundColor = Color.parseColor("#282A36"); customTheme.cardViewBackgroundColor = Color.parseColor("#393A59"); + customTheme.readPostCardViewBackgroundColor = Color.parseColor("#1C1F3D"); customTheme.commentBackgroundColor = Color.parseColor("#393A59"); customTheme.bottomAppBarBackgroundColor = Color.parseColor("#393A59"); customTheme.primaryIconColor = Color.parseColor("#FFFFFF"); @@ -1352,10 +1397,13 @@ public class CustomThemeWrapper { customTheme.secondaryTextColor = Color.parseColor("#8A000000"); customTheme.postTitleColor = Color.parseColor("#000000"); customTheme.postContentColor = Color.parseColor("#8A000000"); + customTheme.readPostTitleColor = Color.parseColor("#979797"); + customTheme.readPostContentColor = Color.parseColor("#979797"); customTheme.commentColor = Color.parseColor("#000000"); customTheme.buttonTextColor = Color.parseColor("#FFFFFF"); customTheme.backgroundColor = Color.parseColor("#DAD0DE"); customTheme.cardViewBackgroundColor = Color.parseColor("#C0F0F4"); + customTheme.readPostCardViewBackgroundColor = Color.parseColor("#D2E7EA"); customTheme.commentBackgroundColor = Color.parseColor("#C0F0F4"); customTheme.bottomAppBarBackgroundColor = Color.parseColor("#D48AE0"); customTheme.primaryIconColor = Color.parseColor("#000000"); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java index fbc7d0cb..de0d2c0f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -61,11 +61,17 @@ import butterknife.ButterKnife; import im.ene.toro.exoplayer.ExoCreator; import im.ene.toro.media.PlaybackInfo; import im.ene.toro.media.VolumeInfo; +import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; +import ml.docilealligator.infinityforreddit.FragmentCommunicator; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.NetworkState; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.FilteredThingActivity; import ml.docilealligator.infinityforreddit.activities.MainActivity; import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.adapters.PostRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.CustomToroContainer; @@ -95,15 +101,11 @@ import ml.docilealligator.infinityforreddit.events.ChangeVoteButtonsPositionEven import ml.docilealligator.infinityforreddit.events.PostUpdateEventToPostList; import ml.docilealligator.infinityforreddit.events.ShowDividerInCompactLayoutPreferenceEvent; import ml.docilealligator.infinityforreddit.events.ShowThumbnailOnTheRightInCompactLayoutEvent; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; -import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.post.PostDataSource; import ml.docilealligator.infinityforreddit.post.PostViewModel; -import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.readposts.FetchReadPosts; +import ml.docilealligator.infinityforreddit.readposts.ReadPost; import ml.docilealligator.infinityforreddit.subredditfilter.FetchSubredditFilters; import ml.docilealligator.infinityforreddit.subredditfilter.SubredditFilter; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; @@ -131,6 +133,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { private static final String IS_IN_LAZY_MODE_STATE = "IILMS"; private static final String RECYCLER_VIEW_POSITION_STATE = "RVPS"; + private static final String READ_POST_LIST_STATE = "RPLS"; private static final String SUBREDDIT_FILTER_LIST_STATE = "SFLS"; @BindView(R.id.swipe_refresh_layout_post_fragment) @@ -197,6 +200,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator { private String accountName; private String subredditName; private String username; + private String query; + private String where; private String multiRedditPath; private int maxPosition = -1; private int postLayout; @@ -211,6 +216,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { private float swipeActionThreshold; private ItemTouchHelper touchHelper; private ArrayList<SubredditFilter> subredditFilterList; + private ArrayList<ReadPost> readPosts; public PostFragment() { // Required empty public constructor @@ -371,6 +377,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE); + readPosts = savedInstanceState.getParcelableArrayList(READ_POST_LIST_STATE); subredditFilterList = savedInstanceState.getParcelableArrayList(SUBREDDIT_FILTER_LIST_STATE); } @@ -419,7 +426,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { if (postType == PostDataSource.TYPE_SEARCH) { subredditName = getArguments().getString(EXTRA_NAME); - String query = getArguments().getString(EXTRA_QUERY); + query = getArguments().getString(EXTRA_QUERY); String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, SortType.Type.RELEVANCE.name()); String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, SortType.Time.ALL.name()); @@ -457,10 +464,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator { TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition()); } }); - - mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, - accountName, locale, mSharedPreferences, - postFeedScrolledPositionSharedPreferences, subredditName, query, postType, sortType, filter, nsfw)).get(PostViewModel.class); } else if (postType == PostDataSource.TYPE_SUBREDDIT) { subredditName = getArguments().getString(EXTRA_NAME); String sort; @@ -509,29 +512,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator { TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition()); } }); - - if (subredditName.equals("all") || subredditName.equals("popular")) { - if (subredditFilterList != null) { - mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, - accountName, locale, mSharedPreferences, - postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, filter, nsfw, subredditFilterList)).get(PostViewModel.class); - } else { - FetchSubredditFilters.fetchSubredditFilters(mRedditDataRoomDatabase, subredditFilters -> { - 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, subredditFilters)).get(PostViewModel.class); - - bindPostViewModel(); - } - }); - } - } else { - mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, - accountName, locale, mSharedPreferences, - postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, filter, nsfw)).get(PostViewModel.class); - } } else if(postType == PostDataSource.TYPE_MULTI_REDDIT) { multiRedditPath = getArguments().getString(EXTRA_NAME); String sort; @@ -582,13 +562,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator { TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition()); } }); - - mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, - accountName, locale, mSharedPreferences, - postFeedScrolledPositionSharedPreferences, multiRedditPath, postType, sortType, filter, nsfw)).get(PostViewModel.class); } else if (postType == PostDataSource.TYPE_USER) { username = getArguments().getString(EXTRA_USER_NAME); - String where = getArguments().getString(EXTRA_USER_WHERE); + where = getArguments().getString(EXTRA_USER_WHERE); if (where != null && where.equals(PostDataSource.USER_WHERE_SUBMITTED)) { CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mFetchPostInfoLinearLayout.getLayoutParams(); params.height = ViewGroup.LayoutParams.WRAP_CONTENT; @@ -635,10 +611,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator { TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition()); } }); - - mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, - accountName, locale, mSharedPreferences, - postFeedScrolledPositionSharedPreferences, username, postType, sortType, where, filter, nsfw)).get(PostViewModel.class); } else { String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, SortType.Type.BEST.name()); if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) { @@ -679,16 +651,30 @@ public class PostFragment extends Fragment implements FragmentCommunicator { TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition()); } }); - - mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mOauthRetrofit, accessToken, - accountName, locale, mSharedPreferences, postFeedScrolledPositionSharedPreferences, - postType, sortType, filter, nsfw)).get(PostViewModel.class); } if (activity instanceof ActivityToolbarInterface) { ((ActivityToolbarInterface) activity).displaySortType(); } + if (accountName != null && !accountName.equals("")) { + if (readPosts == null) { + FetchReadPosts.fetchReadPosts(mRedditDataRoomDatabase, accountName, + postType == PostDataSource.TYPE_SUBREDDIT && subredditName != null && (subredditName.equals("all") || subredditName.equals("popular")), + (readPosts, subredditFilters) -> { + if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) { + this.readPosts = readPosts; + this.subredditFilterList = subredditFilters; + initializeAndPostViewModel(accessToken, locale, filter, nsfw); + } + }); + } else { + initializeAndPostViewModel(accessToken, locale, filter, nsfw); + } + } else { + initializeAndPostViewModelForAnonymous(accessToken, locale, filter, nsfw); + } + vibrateWhenActionTriggered = mSharedPreferences.getBoolean(SharedPreferencesUtils.VIBRATE_WHEN_ACTION_TRIGGERED, true); swipeActionThreshold = Float.parseFloat(mSharedPreferences.getString(SharedPreferencesUtils.SWIPE_ACTION_THRESHOLD, "0.3")); swipeRightAction = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.SWIPE_RIGHT_ACTION, "1")); @@ -795,11 +781,87 @@ public class PostFragment extends Fragment implements FragmentCommunicator { return new PlaybackInfo(INDEX_UNSET, TIME_UNSET, volumeInfo); }); + return rootView; + } + + private void initializeAndPostViewModel(String accessToken, Locale locale, int filter, boolean nsfw) { + if (postType == PostDataSource.TYPE_SEARCH) { + mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, + accountName, locale, mSharedPreferences, + postFeedScrolledPositionSharedPreferences, subredditName, query, postType, sortType, filter, nsfw)).get(PostViewModel.class); + } else if (postType == PostDataSource.TYPE_SUBREDDIT) { + if (subredditName.equals("all") || subredditName.equals("popular")) { + 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); + } 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); + } + } 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); + } 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); + } else { + mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mOauthRetrofit, accessToken, + accountName, locale, mSharedPreferences, postFeedScrolledPositionSharedPreferences, + postType, sortType, filter, nsfw)).get(PostViewModel.class); + } + + bindPostViewModel(); + } + + private void initializeAndPostViewModelForAnonymous(String accessToken, Locale locale, int filter, boolean nsfw) { + //For anonymous user + if (postType == PostDataSource.TYPE_SEARCH) { + mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, + accountName, locale, mSharedPreferences, + postFeedScrolledPositionSharedPreferences, subredditName, query, postType, sortType, filter, nsfw)).get(PostViewModel.class); + } else if (postType == PostDataSource.TYPE_SUBREDDIT) { + if (subredditName.equals("all") || subredditName.equals("popular")) { + if (subredditFilterList != null) { + mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, + accountName, locale, mSharedPreferences, + postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, filter, nsfw, subredditFilterList)).get(PostViewModel.class); + } else { + FetchSubredditFilters.fetchSubredditFilters(mRedditDataRoomDatabase, subredditFilters -> { + 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); + + bindPostViewModel(); + } + }); + } + } 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); + } + } 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); + } 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); + } else { + mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mOauthRetrofit, accessToken, + accountName, locale, mSharedPreferences, postFeedScrolledPositionSharedPreferences, + postType, sortType, filter, nsfw)).get(PostViewModel.class); + } + if (mPostViewModel != null) { bindPostViewModel(); } - - return rootView; } private void bindPostViewModel() { @@ -912,6 +974,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { public void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode); + outState.putParcelableArrayList(READ_POST_LIST_STATE, readPosts); outState.putParcelableArrayList(SUBREDDIT_FILTER_LIST_STATE, subredditFilterList); if (mLinearLayoutManager != null) { outState.putInt(RECYCLER_VIEW_POSITION_STATE, mLinearLayoutManager.findFirstVisibleItemPosition()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/readposts/FetchReadPosts.java b/app/src/main/java/ml/docilealligator/infinityforreddit/readposts/FetchReadPosts.java new file mode 100644 index 00000000..cfb70789 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/readposts/FetchReadPosts.java @@ -0,0 +1,53 @@ +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<ReadPost> readPosts, ArrayList<SubredditFilter> 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<Void, Void, Void> { + + private RedditDataRoomDatabase redditDataRoomDatabase; + private String username; + private boolean fetchSubredditFilter; + private FetchReadPostsListener fetchReadPostsListener; + private ArrayList<ReadPost> readPosts; + private ArrayList<SubredditFilter> 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<ReadPost>) redditDataRoomDatabase.readPostDao().getAllReadPosts(username); + if (fetchSubredditFilter) { + subredditFilters = (ArrayList<SubredditFilter>) 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 new file mode 100644 index 00000000..27a76b85 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/readposts/ReadPost.java @@ -0,0 +1,74 @@ +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<ReadPost> CREATOR = new Creator<ReadPost>() { + @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 new file mode 100644 index 00000000..1363f14b --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/readposts/ReadPostDao.java @@ -0,0 +1,20 @@ +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<ReadPost> 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); +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/CustomThemeSharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/CustomThemeSharedPreferencesUtils.java index 0f3e991c..db7520d7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/CustomThemeSharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/CustomThemeSharedPreferencesUtils.java @@ -20,12 +20,15 @@ public class CustomThemeSharedPreferencesUtils { public static final String COLOR_PRIMARY_LIGHT_THEME = "colorPrimaryLightTheme"; public static final String POST_TITLE_COLOR = "postTitleColor"; public static final String POST_CONTENT_COLOR = "postContentColor"; + public static final String READ_POST_TITLE_COLOR = "readPostTitleColor"; + public static final String READ_POST_CONTENT_COLOR = "readPostContentColor"; public static final String COMMENT_COLOR = "commentColor"; public static final String PRIMARY_TEXT_COLOR = "primaryTextColor"; public static final String SECONDARY_TEXT_COLOR = "secondaryTextColor"; public static final String BUTTON_TEXT_COLOR = "buttonTextColor"; public static final String BACKGROUND_COLOR = "backgroundColor"; public static final String CARD_VIEW_BACKGROUND_COLOR = "cardViewBackgroundColor"; + public static final String READ_POST_CARD_VIEW_BACKGROUND_COLOR = "readPostCardViewBackgroundColor"; public static final String COMMENT_BACKGROUND_COLOR = "commentBackgroundColor"; public static final String BOTTOM_APP_BAR_BACKGROUND_COLOR = "bottomAppBarBackgroundColor"; public static final String PRIMARY_ICON_COLOR = "primaryIconColor"; @@ -99,10 +102,13 @@ public class CustomThemeSharedPreferencesUtils { editor.putInt(SECONDARY_TEXT_COLOR, customTheme.secondaryTextColor); editor.putInt(POST_TITLE_COLOR, customTheme.postTitleColor); editor.putInt(POST_CONTENT_COLOR, customTheme.postContentColor); + editor.putInt(READ_POST_TITLE_COLOR, customTheme.readPostTitleColor); + editor.putInt(READ_POST_CONTENT_COLOR, customTheme.readPostContentColor); editor.putInt(COMMENT_COLOR, customTheme.commentColor); editor.putInt(BUTTON_TEXT_COLOR, customTheme.buttonTextColor); editor.putInt(BACKGROUND_COLOR, customTheme.backgroundColor); editor.putInt(CARD_VIEW_BACKGROUND_COLOR, customTheme.cardViewBackgroundColor); + editor.putInt(READ_POST_CARD_VIEW_BACKGROUND_COLOR, customTheme.readPostCardViewBackgroundColor); editor.putInt(COMMENT_BACKGROUND_COLOR, customTheme.commentBackgroundColor); editor.putInt(BOTTOM_APP_BAR_BACKGROUND_COLOR, customTheme.bottomAppBarBackgroundColor); editor.putInt(PRIMARY_ICON_COLOR, customTheme.primaryIconColor); |