diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-03-18 05:33:55 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-03-18 05:33:55 +0000 |
commit | 71e22b3e364c75400ef380df1d53a83f9dbd3a1b (patch) | |
tree | 7f2a1d5100e1a1dc3f3b2289d3118a49baa0559a | |
parent | 21c47eaa4c3cffe0965447e2d7fb7d1cb964b720 (diff) | |
download | infinity-for-reddit-71e22b3e364c75400ef380df1d53a83f9dbd3a1b.tar infinity-for-reddit-71e22b3e364c75400ef380df1d53a83f9dbd3a1b.tar.gz infinity-for-reddit-71e22b3e364c75400ef380df1d53a83f9dbd3a1b.tar.bz2 infinity-for-reddit-71e22b3e364c75400ef380df1d53a83f9dbd3a1b.tar.lz infinity-for-reddit-71e22b3e364c75400ef380df1d53a83f9dbd3a1b.tar.xz infinity-for-reddit-71e22b3e364c75400ef380df1d53a83f9dbd3a1b.tar.zst infinity-for-reddit-71e22b3e364c75400ef380df1d53a83f9dbd3a1b.zip |
Immersive Interface is now available on Android 8.0. Add ThemePreferenceFragment. Fix theme database.
17 files changed, 348 insertions, 229 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java index 60abf067..3849e5f0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java @@ -65,13 +65,13 @@ public abstract class BaseActivity extends AppCompatActivity { case 0: AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); getTheme().applyStyle(R.style.Theme_Normal, true); - customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.NORMAL); + customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.LIGHT); break; case 1: AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { getTheme().applyStyle(R.style.Theme_Normal_AmoledDark, true); - customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.AMOLED_DARK); + customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.AMOLED); } else { getTheme().applyStyle(R.style.Theme_Normal_NormalDark, true); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.DARK); @@ -85,11 +85,11 @@ public abstract class BaseActivity extends AppCompatActivity { } if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) { getTheme().applyStyle(R.style.Theme_Normal, true); - customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.NORMAL); + customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.LIGHT); } else { if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { getTheme().applyStyle(R.style.Theme_Normal_AmoledDark, true); - customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.AMOLED_DARK); + customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.AMOLED); } else { getTheme().applyStyle(R.style.Theme_Normal_NormalDark, true); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.DARK); @@ -120,8 +120,8 @@ public abstract class BaseActivity extends AppCompatActivity { window.setStatusBarColor(customThemeWrapper.getColorPrimaryDark()); } boolean isLightStatusbar = customThemeWrapper.isLightStatusBar(); - boolean isLightNavBar = customThemeWrapper.isLightNavBar(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + boolean isLightNavBar = customThemeWrapper.isLightNavBar(); if (isLightStatusbar) { if (isLightNavBar) { systemVisibilityToolbarExpanded = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index 9bc49a1a..b65fc134 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -495,13 +495,13 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb case R.string.light_theme: mSharedPreferences.edit().putString(SharedPreferencesUtils.THEME_KEY, "0").apply(); AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - mCustomThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.NORMAL); + mCustomThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.LIGHT); break; case R.string.dark_theme: mSharedPreferences.edit().putString(SharedPreferencesUtils.THEME_KEY, "1").apply(); AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); if (mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { - mCustomThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.AMOLED_DARK); + mCustomThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.AMOLED); } else { mCustomThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.DARK); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 15f81b12..c5c68959 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -23,8 +23,8 @@ import ml.docilealligator.infinityforreddit.Activity.SearchActivity; import ml.docilealligator.infinityforreddit.Activity.SearchResultActivity; import ml.docilealligator.infinityforreddit.Activity.SearchSubredditsResultActivity; import ml.docilealligator.infinityforreddit.Activity.SettingsActivity; -import ml.docilealligator.infinityforreddit.Activity.SubredditSelectionActivity; import ml.docilealligator.infinityforreddit.Activity.SubredditMultiselectionActivity; +import ml.docilealligator.infinityforreddit.Activity.SubredditSelectionActivity; import ml.docilealligator.infinityforreddit.Activity.SubscribedThingListingActivity; import ml.docilealligator.infinityforreddit.Activity.ViewGIFActivity; import ml.docilealligator.infinityforreddit.Activity.ViewImageActivity; @@ -44,9 +44,9 @@ import ml.docilealligator.infinityforreddit.Fragment.SubscribedSubredditsListing import ml.docilealligator.infinityforreddit.Fragment.UserListingFragment; import ml.docilealligator.infinityforreddit.Service.SubmitPostService; import ml.docilealligator.infinityforreddit.Settings.GesturesAndButtonsPreferenceFragment; -import ml.docilealligator.infinityforreddit.Settings.InterfacePreferenceFragment; import ml.docilealligator.infinityforreddit.Settings.MainPreferenceFragment; import ml.docilealligator.infinityforreddit.Settings.NotificationPreferenceFragment; +import ml.docilealligator.infinityforreddit.Settings.ThemePreferenceFragment; @Singleton @Component(modules = AppModule.class) @@ -139,5 +139,5 @@ public interface AppComponent { void inject(SubredditMultiselectionActivity subredditMultiselectionActivity); - void inject(InterfacePreferenceFragment interfacePreferenceFragment); + void inject(ThemePreferenceFragment themePreferenceFragment); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java index d28821b7..70567266 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java @@ -107,15 +107,31 @@ class AppModule { } @Provides - @Named("theme") + @Named("light_theme") @Singleton - SharedPreferences provideThemeSharedPreferences() { - return mApplication.getSharedPreferences(CustomThemeSharedPreferencesUtils.THEME_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE); + SharedPreferences provideLightThemeSharedPreferences() { + return mApplication.getSharedPreferences(CustomThemeSharedPreferencesUtils.LIGHT_THEME_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE); } @Provides + @Named("dark_theme") @Singleton - CustomThemeWrapper provideCustomThemeWrapper(@Named("theme") SharedPreferences themeSharedPreferences) { - return new CustomThemeWrapper(themeSharedPreferences); + SharedPreferences provideDarkThemeSharedPreferences() { + return mApplication.getSharedPreferences(CustomThemeSharedPreferencesUtils.DARK_THEME_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE); + } + + @Provides + @Named("amoled_theme") + @Singleton + SharedPreferences provideAmoledThemeSharedPreferences() { + return mApplication.getSharedPreferences(CustomThemeSharedPreferencesUtils.AMOLED_THEME_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE); + } + + @Provides + @Singleton + CustomThemeWrapper provideCustomThemeWrapper(@Named("light_theme") SharedPreferences lightThemeSharedPreferences, + @Named("dark_theme") SharedPreferences darkThemeSharedPreferences, + @Named("amoled_theme") SharedPreferences amoledThemeSharedPreferences) { + return new CustomThemeWrapper(lightThemeSharedPreferences, darkThemeSharedPreferences, amoledThemeSharedPreferences); } } 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 799e530d..94f4bac9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomTheme.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomTheme.java @@ -11,6 +11,12 @@ public class CustomTheme { @NonNull @ColumnInfo(name = "name") public String name; + @ColumnInfo(name = "is_light_theme") + public boolean isLightTheme; + @ColumnInfo(name = "is_dark_theme") + public boolean isDarkTheme; + @ColumnInfo(name = "is_amoled_theme") + public boolean isAmoledTheme; @ColumnInfo(name = "color_primary") public int colorPrimary; @ColumnInfo(name = "color_primary_dark") @@ -23,12 +29,26 @@ public class CustomTheme { public int primaryTextColor; @ColumnInfo(name = "secondary_text_color") public int secondaryTextColor; + @ColumnInfo(name = "post_title_color") + public int postTitleColor; + @ColumnInfo(name = "post_content_color") + public int postContentColor; + @ColumnInfo(name = "comment_color") + public int commentColor; + @ColumnInfo(name = "button_text_color") + public int buttonTextColor; @ColumnInfo(name = "background_color") public int backgroundColor; - @ColumnInfo(name = "rounded_bottom_sheet_primary_background") - public int roundedBottomSheetPrimaryBackground; @ColumnInfo(name = "card_view_background_color") public int cardViewBackgroundColor; + @ColumnInfo(name = "comment_background_color") + public int commentBackgroundColor; + @ColumnInfo(name = "bottom_app_bar_background_color") + public int bottomAppBarBackgroundColor; + @ColumnInfo(name = "primary_icon_color") + public int primaryIconColor; + @ColumnInfo(name = "comment_icon_and_info_color") + public int commentIconAndInfoColor; @ColumnInfo(name = "toolbar_primary_text_and_icon_color") public int toolbarPrimaryTextAndIconColor; @ColumnInfo(name = "toolbar_and_tab_background_color") @@ -53,22 +73,30 @@ public class CustomTheme { public int upvoted; @ColumnInfo(name = "downvoted") public int downvoted; - @ColumnInfo(name = "post_type") - public int postType; - @ColumnInfo(name = "spoiler_color") - public int spoilerColor; - @ColumnInfo(name = "nsfw_color") - public int nsfwColor; - @ColumnInfo(name = "flair_color") - public int flairColor; + @ColumnInfo(name = "post_type_background_color") + public int postTypeBackgroundColor; + @ColumnInfo(name = "post_type_text_color") + public int postTypeTextColor; + @ColumnInfo(name = "spoiler_background_color") + public int spoilerBackgroundColor; + @ColumnInfo(name = "spoiler_text_color") + public int spoilerTextColor; + @ColumnInfo(name = "nsfw_background_color") + public int nsfwBackgroundColor; + @ColumnInfo(name = "nsfw_text_color") + public int nsfwTextColor; + @ColumnInfo(name = "flair_background_color") + public int flairBackgroundColor; + @ColumnInfo(name = "flair_text_color") + public int flairTextColor; @ColumnInfo(name = "archived_tint") public int archivedTint; @ColumnInfo(name = "locked_icon_tint") public int lockedIconTint; - @ColumnInfo(name = "crosspost") - public int crosspost; - @ColumnInfo(name = "stickied_post") - public int stickiedPost; + @ColumnInfo(name = "crosspost_icon_tint") + public int crosspostIconTint; + @ColumnInfo(name = "stickied_post_icon_tint") + public int stickiedPostIconTint; @ColumnInfo(name = "subscribed") public int subscribed; @ColumnInfo(name = "unsubscribed") @@ -83,8 +111,6 @@ public class CustomTheme { public int submitter; @ColumnInfo(name = "moderator") public int moderator; - @ColumnInfo(name = "notification_icon_color") - public int notificationIconColor; @ColumnInfo(name = "single_comment_thread_background_color") public int singleCommentThreadBackgroundColor; @ColumnInfo(name = "unread_message_background_color") @@ -109,6 +135,16 @@ public class CustomTheme { public int commentVerticalBarColor6; @ColumnInfo(name = "comment_vertical_bar_color_7") public int commentVerticalBarColor7; + @ColumnInfo(name = "fab_icon_color") + public int fabIconColor; + @ColumnInfo(name = "chip_text_color") + public int chipTextColor; + @ColumnInfo(name = "is_light_status_bar") + public int isLightStatusBar; + @ColumnInfo(name = "is_light_nav_bar") + public int isLightNavBar; + @ColumnInfo(name = "is_change_status_bar_icon_color_after_toolbar_collapsed_in_immersive_interface") + public int isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface; public CustomTheme(@NonNull String name) { this.name = name; 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 7c0e5bd5..bcb46f7e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeWrapper.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeWrapper.java @@ -5,22 +5,39 @@ import android.graphics.Color; import ml.docilealligator.infinityforreddit.Utils.CustomThemeSharedPreferencesUtils; -import static ml.docilealligator.infinityforreddit.Utils.CustomThemeSharedPreferencesUtils.AMOLED_DARK; +import static ml.docilealligator.infinityforreddit.Utils.CustomThemeSharedPreferencesUtils.AMOLED; import static ml.docilealligator.infinityforreddit.Utils.CustomThemeSharedPreferencesUtils.DARK; public class CustomThemeWrapper { - private SharedPreferences themeSharedPreferences; + private SharedPreferences lightThemeSharedPreferences; + private SharedPreferences darkThemeSharedPreferences; + private SharedPreferences amoledThemeSharedPreferences; private int themeType; - public CustomThemeWrapper(SharedPreferences themeSharedPreferences) { - this.themeSharedPreferences = themeSharedPreferences; + public CustomThemeWrapper(SharedPreferences lightThemeSharedPreferences, + SharedPreferences darkThemeSharedPreferences, + SharedPreferences amoledThemeSharedPreferences) { + this.lightThemeSharedPreferences = lightThemeSharedPreferences; + this.darkThemeSharedPreferences = darkThemeSharedPreferences; + this.amoledThemeSharedPreferences = amoledThemeSharedPreferences; + } + + private SharedPreferences getThemeSharedPreferences() { + switch (themeType) { + case DARK: + return darkThemeSharedPreferences; + case AMOLED: + return amoledThemeSharedPreferences; + default: + return lightThemeSharedPreferences; + } } private int getDefaultColor(String normalHex, String darkHex, String amoledDarkHex) { switch (themeType) { case DARK: return Color.parseColor(darkHex); - case AMOLED_DARK: + case AMOLED: return Color.parseColor(amoledDarkHex); default: return Color.parseColor(normalHex); @@ -31,327 +48,326 @@ public class CustomThemeWrapper { this.themeType = themeType; } - public boolean isLightStatusBar() { - return themeSharedPreferences.getBoolean(CustomThemeSharedPreferencesUtils.LIGHT_STATUS_BAR, false); - } - - public boolean isLightNavBar() { - return themeSharedPreferences.getBoolean(CustomThemeSharedPreferencesUtils.LIGHT_NAV_BAR, false); - } - - public boolean isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface() { - return themeSharedPreferences.getBoolean( - CustomThemeSharedPreferencesUtils.CHANGE_STATUS_BAR_ICON_COLOR_AFTER_TOOLBAR_COLLAPSED_IN_IMMERSIVE_INTERFACE, - true); - } - public int getColorPrimary() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.COLOR_PRIMARY, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COLOR_PRIMARY, getDefaultColor("#1565C0", "#242424", "#000000")); } public int getColorPrimaryDark() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.COLOR_PRIMARY_DARK, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COLOR_PRIMARY_DARK, getDefaultColor("#0D47A1", "#121212", "#000000")); } public int getColorAccent() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.COLOR_ACCENT, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COLOR_ACCENT, getDefaultColor("#FF4081", "#FF4081", "#FF4081")); } public int getColorPrimaryLightTheme() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.COLOR_PRIMARY_LIGHT_THEME, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COLOR_PRIMARY_LIGHT_THEME, getDefaultColor("#1565C0", "#1565C0", "#1565C0")); } - public int getPostTitleColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.POST_TITLE_COLOR, + public int getPrimaryTextColor() { + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.PRIMARY_TEXT_COLOR, getDefaultColor("#000000", "#FFFFFF", "#FFFFFF")); } - public int getPostContentColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.POST_CONTENT_COLOR, + public int getSecondaryTextColor() { + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.SECONDARY_TEXT_COLOR, getDefaultColor("#8A000000", "#B3FFFFFF", "#B3FFFFFF")); } - public int getCommentColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.COMMENT_COLOR, + public int getPostTitleColor() { + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.POST_TITLE_COLOR, getDefaultColor("#000000", "#FFFFFF", "#FFFFFF")); } - public int getPrimaryTextColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.PRIMARY_TEXT_COLOR, - getDefaultColor("#000000", "#FFFFFF", "#FFFFFF")); + public int getPostContentColor() { + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.POST_CONTENT_COLOR, + getDefaultColor("#8A000000", "#B3FFFFFF", "#B3FFFFFF")); } - public int getSecondaryTextColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.SECONDARY_TEXT_COLOR, - getDefaultColor("#8A000000", "#B3FFFFFF", "#B3FFFFFF")); + public int getCommentColor() { + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COMMENT_COLOR, + getDefaultColor("#000000", "#FFFFFF", "#FFFFFF")); } public int getButtonTextColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.BUTTON_TEXT_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.BUTTON_TEXT_COLOR, getDefaultColor("#FFFFFF", "#FFFFFF", "#FFFFFF")); } public int getBackgroundColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.BACKGROUND_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.BACKGROUND_COLOR, getDefaultColor("#FFFFFF", "#121212", "#000000")); } public int getCardViewBackgroundColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.CARD_VIEW_BACKGROUND_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.CARD_VIEW_BACKGROUND_COLOR, getDefaultColor("#FFFFFF", "#242424", "#000000")); } public int getCommentBackgroundColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.COMMENT_BACKGROUND_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COMMENT_BACKGROUND_COLOR, getDefaultColor("#FFFFFF", "#242424", "#000000")); } public int getBottomAppBarBackgroundColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.BOTTOM_APP_BAR_BACKGROUND_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.BOTTOM_APP_BAR_BACKGROUND_COLOR, getDefaultColor("#FFFFFF", "#121212", "#000000")); } public int getPrimaryIconColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.PRIMARY_ICON_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.PRIMARY_ICON_COLOR, getDefaultColor("#000000", "#FFFFFF", "#FFFFFF")); } public int getPostIconAndInfoColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.POST_ICON_AND_INFO_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.POST_ICON_AND_INFO_COLOR, getDefaultColor("#8A000000", "#B3FFFFFF", "#B3FFFFFF")); } public int getCommentIconAndInfoColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.COMMENT_ICON_AND_INFO_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COMMENT_ICON_AND_INFO_COLOR, getDefaultColor("#8A000000", "#B3FFFFFF", "#B3FFFFFF")); } public int getToolbarPrimaryTextAndIconColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.TOOLBAR_PRIMARY_TEXT_AND_ICON_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.TOOLBAR_PRIMARY_TEXT_AND_ICON_COLOR, getDefaultColor("#FFFFFF", "#FFFFFF", "#FFFFFF")); } public int getToolbarAndTabBackgroundColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.TOOLBAR_AND_TAB_BACKGROUND_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.TOOLBAR_AND_TAB_BACKGROUND_COLOR, getDefaultColor("#1565C0", "#282828", "#000000")); } public int getCircularProgressBarBackground() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.CIRCULAR_PROGRESS_BAR_BACKGROUND, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.CIRCULAR_PROGRESS_BAR_BACKGROUND, getDefaultColor("#FFFFFF", "#242424", "#000000")); } public int getTabLayoutWithExpandedCollapsingToolbarTabBackground() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.TAB_LAYOUT_WITH_EXPANDED_COLLAPSING_TOOLBAR_TAB_BACKGROUND, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.TAB_LAYOUT_WITH_EXPANDED_COLLAPSING_TOOLBAR_TAB_BACKGROUND, getDefaultColor("#FFFFFF", "#242424", "#000000")); } public int getTabLayoutWithExpandedCollapsingToolbarTextColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.TAB_LAYOUT_WITH_EXPANDED_COLLAPSING_TOOLBAR_TEXT_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.TAB_LAYOUT_WITH_EXPANDED_COLLAPSING_TOOLBAR_TEXT_COLOR, getDefaultColor("#1565C0", "#FFFFFF", "#FFFFFF")); } public int getTabLayoutWithExpandedCollapsingToolbarTabIndicator() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.TAB_LAYOUT_WITH_EXPANDED_COLLAPSING_TOOLBAR_TAB_INDICATOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.TAB_LAYOUT_WITH_EXPANDED_COLLAPSING_TOOLBAR_TAB_INDICATOR, getDefaultColor("#1565C0", "#FFFFFF", "#FFFFFF")); } public int getTabLayoutWithCollapsedCollapsingToolbarTabBackground() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.TAB_LAYOUT_WITH_COLLAPSED_COLLAPSING_TOOLBAR_TAB_BACKGROUND, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.TAB_LAYOUT_WITH_COLLAPSED_COLLAPSING_TOOLBAR_TAB_BACKGROUND, getDefaultColor("#1565C0", "#242424", "#000000")); } public int getTabLayoutWithCollapsedCollapsingToolbarTextColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.TAB_LAYOUT_WITH_COLLAPSED_COLLAPSING_TOOLBAR_TEXT_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.TAB_LAYOUT_WITH_COLLAPSED_COLLAPSING_TOOLBAR_TEXT_COLOR, getDefaultColor("#FFFFFF", "#FFFFFF", "#FFFFFF")); } public int getTabLayoutWithCollapsedCollapsingToolbarTabIndicator() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.TAB_LAYOUT_WITH_COLLAPSED_COLLAPSING_TOOLBAR_TAB_INDICATOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.TAB_LAYOUT_WITH_COLLAPSED_COLLAPSING_TOOLBAR_TAB_INDICATOR, getDefaultColor("#FFFFFF", "#FFFFFF", "#FFFFFF")); } public int getNavBarColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.NAV_BAR_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.NAV_BAR_COLOR, getDefaultColor("#FFFFFF", "#121212", "#000000")); } public int getUpvoted() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.UPVOTED, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.UPVOTED, getDefaultColor("#E91E63", "#E91E63", "#E91E63")); } public int getDownvoted() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.DOWNVOTED, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.DOWNVOTED, getDefaultColor("#007DDE", "#007DDE", "#007DDE")); } public int getPostTypeBackgroundColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.POST_TYPE_BACKGROUND_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.POST_TYPE_BACKGROUND_COLOR, getDefaultColor("#0D47A1", "#1565C0", "#1565C0")); } public int getPostTypeTextColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.POST_TYPE_TEXT_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.POST_TYPE_TEXT_COLOR, getDefaultColor("#FFFFFF", "#FFFFFF", "#FFFFFF")); } public int getSpoilerBackgroundColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.SPOILER_BACKGROUND_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.SPOILER_BACKGROUND_COLOR, getDefaultColor("#EE02EB", "#EE02EB", "#EE02EB")); } public int getSpoilerTextColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.SPOILER_TEXT_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.SPOILER_TEXT_COLOR, getDefaultColor("#FFFFFF", "#FFFFFF", "#FFFFFF")); } public int getNsfwBackgroundColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.NSFW_BACKGROUND_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.NSFW_BACKGROUND_COLOR, getDefaultColor("#FF4081", "#FF4081", "#FF4081")); } public int getNsfwTextColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.NSFW_TEXT_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.NSFW_TEXT_COLOR, getDefaultColor("#FFFFFF", "#FFFFFF", "#FFFFFF")); } public int getFlairBackgroundColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.FLAIR_BACKGROUND_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.FLAIR_BACKGROUND_COLOR, getDefaultColor("#00AA8C", "#00AA8C", "#00AA8C")); } public int getFlairTextColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.FLAIR_TEXT_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.FLAIR_TEXT_COLOR, getDefaultColor("#FFFFFF", "#FFFFFF", "#FFFFFF")); } public int getArchivedTint() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.ARCHIVED_TINT, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.ARCHIVED_TINT, getDefaultColor("#B4009F", "#B4009F", "#B4009F")); } public int getLockedIconTint() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.LOCKED_ICON_TINT, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.LOCKED_ICON_TINT, getDefaultColor("#EE7302", "#EE7302", "#EE7302")); } public int getCrosspostIconTint() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.CROSSPOST_ICON_TINT, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.CROSSPOST_ICON_TINT, getDefaultColor("#FF4081", "#FF4081", "#FF4081")); } public int getStickiedPostIconTint() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.STICKIED_POST_ICON_TINT, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.STICKIED_POST_ICON_TINT, getDefaultColor("#0D47A1", "#1565C0", "#1565C0")); } public int getSubscribed() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.SUBSCRIBED, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.SUBSCRIBED, getDefaultColor("#FF4081", "#FF4081", "#FF4081")); } public int getUnsubscribed() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.UNSUBSCRIBED, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.UNSUBSCRIBED, getDefaultColor("#0D47A1", "#1565C0", "#1565C0")); } public int getUsername() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.USERNAME, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.USERNAME, getDefaultColor("#0D47A1", "#1E88E5", "#1E88E5")); } public int getSubreddit() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.SUBREDDIT, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.SUBREDDIT, getDefaultColor("#E91E63", "#E91E63", "#E91E63")); } public int getAuthorFlairTextColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.AUTHOR_FLAIR_TEXT_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.AUTHOR_FLAIR_TEXT_COLOR, getDefaultColor("#EE02C4", "#EE02C4", "#EE02C4")); } public int getSubmitter() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.SUBMITTER, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.SUBMITTER, getDefaultColor("#EE8A02", "#EE8A02", "#EE8A02")); } public int getModerator() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.MODERATOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.MODERATOR, getDefaultColor("#00BA81", "#00BA81", "#00BA81")); } public int getSingleCommentThreadBackgroundColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.SINGLE_COMMENT_THREAD_BACKGROUND, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.SINGLE_COMMENT_THREAD_BACKGROUND, getDefaultColor("#B3E5F9", "#123E77", "#123E77")); } public int getUnreadMessageBackgroundColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.UNREAD_MESSAGE_BACKGROUND_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.UNREAD_MESSAGE_BACKGROUND_COLOR, getDefaultColor("#B3E5F9", "#123E77", "#123E77")); } public int getDividerColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.DIVIDER_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.DIVIDER_COLOR, getDefaultColor("#E0E0E0", "#69666C", "#69666C")); } public int getNoPreviewLinkBackgroundColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.NO_PREVIEW_LINK_BACKGROUND_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.NO_PREVIEW_LINK_BACKGROUND_COLOR, getDefaultColor("#E0E0E0", "#424242", "#424242")); } public int getVoteAndReplyUnavailableVoteButtonColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.VOTE_AND_REPLY_UNAVAILABLE_VOTE_BUTTON_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.VOTE_AND_REPLY_UNAVAILABLE_VOTE_BUTTON_COLOR, getDefaultColor("#F0F0F0", "#3C3C3C", "#3C3C3C")); } public int getCommentVerticalBarColor1() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.COMMENT_VERTICAL_BAR_COLOR_1, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COMMENT_VERTICAL_BAR_COLOR_1, getDefaultColor("#1565C0", "#1565C0", "#1565C0")); } public int getCommentVerticalBarColor2() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.COMMENT_VERTICAL_BAR_COLOR_2, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COMMENT_VERTICAL_BAR_COLOR_2, getDefaultColor("#EE02BE", "#C300B3", "#C300B3")); } public int getCommentVerticalBarColor3() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.COMMENT_VERTICAL_BAR_COLOR_3, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COMMENT_VERTICAL_BAR_COLOR_3, getDefaultColor("#02DFEE", "#00B8DA", "#00B8DA")); } public int getCommentVerticalBarColor4() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.COMMENT_VERTICAL_BAR_COLOR_4, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COMMENT_VERTICAL_BAR_COLOR_4, getDefaultColor("#EED502", "#EDCA00", "#EDCA00")); } public int getCommentVerticalBarColor5() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.COMMENT_VERTICAL_BAR_COLOR_5, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COMMENT_VERTICAL_BAR_COLOR_5, getDefaultColor("#EE0220", "#EE0219", "#EE0219")); } public int getCommentVerticalBarColor6() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.COMMENT_VERTICAL_BAR_COLOR_6, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COMMENT_VERTICAL_BAR_COLOR_6, getDefaultColor("#02EE6E", "#00B925", "#00B925")); } public int getCommentVerticalBarColor7() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.COMMENT_VERTICAL_BAR_COLOR_7, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COMMENT_VERTICAL_BAR_COLOR_7, getDefaultColor("#EE4602", "#EE4602", "#EE4602")); } public int getFABIconColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.FAB_ICON_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.FAB_ICON_COLOR, getDefaultColor("#1565C0", "#1565C0", "#1565C0")); } public int getChipTextColor() { - return themeSharedPreferences.getInt(CustomThemeSharedPreferencesUtils.CHIP_TEXT_COLOR, + return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.CHIP_TEXT_COLOR, getDefaultColor("#FFFFFF", "#FFFFFF", "#FFFFFF")); } + + public boolean isLightStatusBar() { + return getThemeSharedPreferences().getBoolean(CustomThemeSharedPreferencesUtils.LIGHT_STATUS_BAR, false); + } + + public boolean isLightNavBar() { + return getThemeSharedPreferences().getBoolean(CustomThemeSharedPreferencesUtils.LIGHT_NAV_BAR, true); + } + + public boolean isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface() { + return getThemeSharedPreferences().getBoolean( + CustomThemeSharedPreferencesUtils.CHANGE_STATUS_BAR_ICON_COLOR_AFTER_TOOLBAR_COLLAPSED_IN_IMMERSIVE_INTERFACE, true); + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java index a0d6edb0..e6d31728 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java @@ -116,12 +116,16 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase { @Override public void migrate(@NonNull SupportSQLiteDatabase database) { database.execSQL("CREATE TABLE custom_themes" + - "(name TEXT NOT NULL PRIMARY KEY, color_primary INTEGER NOT NULL," + + "(name TEXT NOT NULL PRIMARY KEY, is_light_theme INTEGER NOT NULL," + + "is_dark_theme INTEGER NOT NULL, is_amoled_theme INTEGER NOT NULL, color_primary INTEGER NOT NULL," + "color_primary_dark INTEGER NOT NULL, color_accent INTEGER NOT NULL," + "color_primary_light_theme INTEGER NOT NULL, primary_text_color INTEGER NOT NULL," + - "secondary_text_color INTEGER NOT NULL, background_color INTEGER NOT NULL," + - "rounded_bottom_sheet_primary_background INTEGER NOT NULL," + - "card_view_background_color INTEGER NOT NULL, toolbar_primary_text_and_icon_color INTEGER NOT NULL," + + "secondary_text_color INTEGER NOT NULL, post_title_color INTEGER NOT NULL," + + "post_content_color INTEGER NOT NULL, comment_color INTEGER NOT NULL," + + "button_text_color INTEGER NOT NULL, background_color INTEGER NOT NULL," + + "card_view_background_color INTEGER NOT NULL, comment_background_color INTEGER NOT NULL," + + "bottom_app_bar_background_color INTEGER NOT NULL, primary_icon_color INTEGER NOT NULL," + + "comment_icon_and_info_color INTEGER NOT NULL, toolbar_primary_text_and_icon_color INTEGER NOT NULL," + "toolbar_and_tab_background_color INTEGER NOT NULL, circular_progress_bar_background INTEGER NOT NULL," + "tab_layout_with_expanded_collapsing_toolbar_tab_background INTEGER NOT NULL," + "tab_layout_with_expanded_collapsing_toolbar_text_color INTEGER NOT NULL," + @@ -130,9 +134,12 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase { "tab_layout_with_collapsed_collapsing_toolbar_text_color INTEGER NOT NULL," + "tab_layout_with_collapsed_collapsing_toolbar_tab_indicator INTEGER NOT NULL," + "nav_bar_color INTEGER NOT NULL, upvoted INTEGER NOT NULL, downvoted INTEGER NOT NULL," + - "post_type INTEGER NOT NULL, spoiler_color INTEGER NOT NULL, nsfw_color INTEGER NOT NULL," + - "flair_color INTEGER NOT NULL, archived_tint INTEGER NOT NULL, locked_icon_tint INTEGER NOT NULL," + - "crosspost INTEGER NOT NULL, stickied_post INTEGER NOT NULL, subscribed INTEGER NOT NULL," + + "post_type_background_color INTEGER NOT NULL, post_type_text_color INTEGER NOT NULL," + + "spoiler_background_color INTEGER NOT NULL, spoiler_text_color INTEGER NOT NULL," + + "nsfw_background_color INTEGER NOT NULL, nsfw_text_color INTEGER NOT NULL," + + "flair_background_color INTEGER NOT NULL, flair_text_color INTEGER NOT NULL," + + "archived_tint INTEGER NOT NULL, locked_icon_tint INTEGER NOT NULL," + + "crosspost_icon_tint INTEGER NOT NULL, stickied_post_icon_tint INTEGER NOT NULL, subscribed INTEGER NOT NULL," + "unsubscribed INTEGER NOT NULL, username INTEGER NOT NULL, subreddit INTEGER NOT NULL," + "author_flair_text_color INTEGER NOT NULL, submitter INTEGER NOT NULL," + "moderator INTEGER NOT NULL, notification_icon_color INTEGER NOT NULL," + @@ -143,7 +150,10 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase { "comment_vertical_bar_color_1 INTEGER NOT NULL, comment_vertical_bar_color_2 INTEGER NOT NULL," + "comment_vertical_bar_color_3 INTEGER NOT NULL, comment_vertical_bar_color_4 INTEGER NOT NULL," + "comment_vertical_bar_color_5 INTEGER NOT NULL, comment_vertical_bar_color_6 INTEGER NOT NULL," + - "comment_vertical_bar_color_7 INTEGER NOT NULL)"); + "comment_vertical_bar_color_7 INTEGER NOT NULL, fab_icon_color INTEGER NOT NULL," + + "chip_text_color INTEGER NOT NULL, is_light_status_bar INTEGER NOT NULL," + + "is_light_nav_bar INTEGER NOT NULL," + + "is_change_status_bar_icon_color_after_toolbar_collapsed_in_immersive_interface INTEGER NOT NULL)"); } }; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java index 5a4d0b4f..56c65426 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java @@ -1,14 +1,9 @@ package ml.docilealligator.infinityforreddit.Settings; -import android.app.Activity; -import android.content.Context; -import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatDelegate; import androidx.fragment.app.Fragment; import androidx.preference.ListPreference; import androidx.preference.PreferenceFragmentCompat; @@ -16,42 +11,24 @@ import androidx.preference.SwitchPreference; import org.greenrobot.eventbus.EventBus; -import javax.inject.Inject; - -import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.Event.ChangeDefaultPostLayoutEvent; import ml.docilealligator.infinityforreddit.Event.ChangeShowAbsoluteNumberOfVotesEvent; import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent; import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent; import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.Event.ShowDividerInCompactLayoutPreferenceEvent; -import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.Utils.CustomThemeSharedPreferencesUtils; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - /** * A simple {@link Fragment} subclass. */ public class InterfacePreferenceFragment extends PreferenceFragmentCompat { - private Activity activity; - @Inject - CustomThemeWrapper customThemeWrapper; - @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.interface_preference, rootKey); - ((Infinity) activity.getApplication()).getAppComponent().inject(this); - - ListPreference themePreference = findPreference(SharedPreferencesUtils.THEME_KEY); - SwitchPreference amoledDarkSwitch = findPreference(SharedPreferencesUtils.AMOLED_DARK_KEY); SwitchPreference immersiveInterfaceSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY); SwitchPreference bottomAppBarSwitch = findPreference(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY); SwitchPreference voteButtonsOnTheRightSwitch = findPreference(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY); @@ -60,63 +37,8 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat { SwitchPreference showDividerInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT); SwitchPreference showAbsoluteNumberOfVotes = findPreference(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES); - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - - if (themePreference != null && amoledDarkSwitch != null) { - if (systemDefault) { - themePreference.setEntries(R.array.settings_theme_q); - } else { - themePreference.setEntries(R.array.settings_theme); - } - - themePreference.setOnPreferenceChangeListener((preference, newValue) -> { - int option = Integer.parseInt((String) newValue); - switch (option) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.NORMAL); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - if (amoledDarkSwitch.isChecked()) { - customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.AMOLED_DARK); - } else { - customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.DARK); - } - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) { - customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.NORMAL); - } else { - if (amoledDarkSwitch.isChecked()) { - customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.AMOLED_DARK); - } else { - customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.DARK); - } - } - } - return true; - }); - } - - if (amoledDarkSwitch != null) { - amoledDarkSwitch.setOnPreferenceChangeListener((preference, newValue) -> { - if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_NO) { - EventBus.getDefault().post(new RecreateActivityEvent()); - activity.recreate(); - } - return true; - }); - } - if (immersiveInterfaceSwitch != null) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { immersiveInterfaceSwitch.setVisible(true); immersiveInterfaceSwitch.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new RecreateActivityEvent()); @@ -169,10 +91,4 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat { }); } } - - @Override - public void onAttach(@NonNull Context context) { - super.onAttach(context); - activity = (Activity) context; - } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/ThemePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/ThemePreferenceFragment.java new file mode 100644 index 00000000..516e3c93 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/ThemePreferenceFragment.java @@ -0,0 +1,110 @@ +package ml.docilealligator.infinityforreddit.Settings; + +import android.app.Activity; +import android.content.Context; +import android.content.res.Configuration; +import android.os.Build; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatDelegate; +import androidx.fragment.app.Fragment; +import androidx.preference.ListPreference; +import androidx.preference.PreferenceFragmentCompat; +import androidx.preference.SwitchPreference; + +import org.greenrobot.eventbus.EventBus; + +import javax.inject.Inject; + +import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.Utils.CustomThemeSharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; + +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + +/** + * A simple {@link Fragment} subclass. + */ +public class ThemePreferenceFragment extends PreferenceFragmentCompat { + + private Activity activity; + @Inject + CustomThemeWrapper customThemeWrapper; + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + setPreferencesFromResource(R.xml.theme_preferences, rootKey); + + ((Infinity) activity.getApplication()).getAppComponent().inject(this); + + ListPreference themePreference = findPreference(SharedPreferencesUtils.THEME_KEY); + SwitchPreference amoledDarkSwitch = findPreference(SharedPreferencesUtils.AMOLED_DARK_KEY); + + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + if (themePreference != null && amoledDarkSwitch != null) { + if (systemDefault) { + themePreference.setEntries(R.array.settings_theme_q); + } else { + themePreference.setEntries(R.array.settings_theme); + } + + themePreference.setOnPreferenceChangeListener((preference, newValue) -> { + int option = Integer.parseInt((String) newValue); + switch (option) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.LIGHT); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + if (amoledDarkSwitch.isChecked()) { + customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.AMOLED); + } else { + customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.DARK); + } + break; + case 2: + if (systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + + if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) { + customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.LIGHT); + } else { + if (amoledDarkSwitch.isChecked()) { + customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.AMOLED); + } else { + customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.DARK); + } + } + } + return true; + }); + } + + if (amoledDarkSwitch != null) { + amoledDarkSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_NO) { + EventBus.getDefault().post(new RecreateActivityEvent()); + activity.recreate(); + } + return true; + }); + } + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + activity = (Activity) context; + } +} 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 92d1a984..44559721 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/CustomThemeSharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/CustomThemeSharedPreferencesUtils.java @@ -1,10 +1,12 @@ package ml.docilealligator.infinityforreddit.Utils; public class CustomThemeSharedPreferencesUtils { - public static final int NORMAL = 0; + public static final int LIGHT = 0; public static final int DARK = 1; - public static final int AMOLED_DARK = 2; - public static final String THEME_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.theme"; + public static final int AMOLED = 2; + public static final String LIGHT_THEME_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.light_theme"; + public static final String DARK_THEME_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.dark_theme"; + public static final String AMOLED_THEME_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.amoled_theme"; public static final String LIGHT_STATUS_BAR = "lightStatusBar"; public static final String LIGHT_NAV_BAR = "lightNavBar"; public static final String CHANGE_STATUS_BAR_ICON_COLOR_AFTER_TOOLBAR_COLLAPSED_IN_IMMERSIVE_INTERFACE = "changeStatusBarIconColorImmersive"; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java index 552f8515..fea670d0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java @@ -44,7 +44,7 @@ public class Utils { return context.getString(R.string.elapsed_time_a_minute_ago); } else if (diff < 50 * MINUTE_MILLIS) { return context.getString(R.string.elapsed_time_minutes_ago, diff / MINUTE_MILLIS); - } else if (diff < 90 * MINUTE_MILLIS) { + } else if (diff < 120 * MINUTE_MILLIS) { return context.getString(R.string.elapsed_time_an_hour_ago); } else if (diff < 24 * HOUR_MILLIS) { return context.getString(R.string.elapsed_time_hours_ago, diff / HOUR_MILLIS); diff --git a/app/src/main/res/drawable-night/ic_outline_color_lens_24px.xml b/app/src/main/res/drawable-night/ic_outline_color_lens_24dp.xml index 6fa0d26f..6fa0d26f 100644 --- a/app/src/main/res/drawable-night/ic_outline_color_lens_24px.xml +++ b/app/src/main/res/drawable-night/ic_outline_color_lens_24dp.xml diff --git a/app/src/main/res/drawable/ic_outline_color_lens_24px.xml b/app/src/main/res/drawable/ic_outline_color_lens_24dp.xml index d1bc2624..d1bc2624 100644 --- a/app/src/main/res/drawable/ic_outline_color_lens_24px.xml +++ b/app/src/main/res/drawable/ic_outline_color_lens_24dp.xml diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index eb88ae16..45f7b7e5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -459,4 +459,7 @@ <string name="cannot_get_storage">Cannot access the app storage</string> <string name="save_image_before_sharing">Saving the image. Please wait.</string> <string name="save_gif_before_sharing">Saving the gif. Please wait.</string> + + <!-- TODO: Remove or change this placeholder text --> + <string name="hello_blank_fragment">Hello blank fragment</string> </resources> diff --git a/app/src/main/res/xml/interface_preference.xml b/app/src/main/res/xml/interface_preference.xml index c62ecbac..7b21020e 100644 --- a/app/src/main/res/xml/interface_preference.xml +++ b/app/src/main/res/xml/interface_preference.xml @@ -2,19 +2,6 @@ <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> - <ListPreference - app:defaultValue="2" - app:entryValues="@array/settings_theme_values" - app:key="theme" - app:icon="@drawable/ic_outline_color_lens_24px" - app:title="@string/settings_theme_title" - app:useSimpleSummaryProvider="true" /> - - <SwitchPreference - app:defaultValue="false" - app:key="amoled_dark" - app:title="@string/settings_amoled_dark_title" /> - <Preference app:title="@string/settings_font_size_title" app:icon="@drawable/ic_font_size_24dp" diff --git a/app/src/main/res/xml/main_preferences.xml b/app/src/main/res/xml/main_preferences.xml index d95e675f..3afc2f8b 100644 --- a/app/src/main/res/xml/main_preferences.xml +++ b/app/src/main/res/xml/main_preferences.xml @@ -13,6 +13,11 @@ app:fragment="ml.docilealligator.infinityforreddit.Settings.InterfacePreferenceFragment" /> <Preference + app:title="@string/settings_theme_title" + app:icon="@drawable/ic_outline_color_lens_24dp" + app:fragment="ml.docilealligator.infinityforreddit.Settings.ThemePreferenceFragment" /> + + <Preference app:icon="@drawable/ic_gesture_24dp" app:title="@string/settings_gestures_and_buttons_title" app:fragment="ml.docilealligator.infinityforreddit.Settings.GesturesAndButtonsPreferenceFragment" /> diff --git a/app/src/main/res/xml/theme_preferences.xml b/app/src/main/res/xml/theme_preferences.xml new file mode 100644 index 00000000..038485e0 --- /dev/null +++ b/app/src/main/res/xml/theme_preferences.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="utf-8"?> +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto"> + + <ListPreference + app:defaultValue="2" + app:entryValues="@array/settings_theme_values" + app:key="theme" + app:icon="@drawable/ic_outline_color_lens_24dp" + app:title="@string/settings_theme_title" + app:useSimpleSummaryProvider="true" /> + + <SwitchPreference + app:defaultValue="false" + app:key="amoled_dark" + app:title="@string/settings_amoled_dark_title" /> + +</PreferenceScreen>
\ No newline at end of file |