diff options
author | Wieland Schöbl <wulkanat@gmail.com> | 2021-11-02 14:13:54 +0000 |
---|---|---|
committer | Wieland Schöbl <wulkanat@gmail.com> | 2021-11-02 14:13:54 +0000 |
commit | 412b78912b9fae089d4a5f18a391eeb1b679d142 (patch) | |
tree | e4f3e6fa0d8f1da3b23c73769fa3116f93e5d810 | |
parent | 7fcc1890fe017128b4c5019386a1b2b34ac0ba9e (diff) | |
download | infinity-for-reddit-412b78912b9fae089d4a5f18a391eeb1b679d142.tar infinity-for-reddit-412b78912b9fae089d4a5f18a391eeb1b679d142.tar.gz infinity-for-reddit-412b78912b9fae089d4a5f18a391eeb1b679d142.tar.bz2 infinity-for-reddit-412b78912b9fae089d4a5f18a391eeb1b679d142.tar.lz infinity-for-reddit-412b78912b9fae089d4a5f18a391eeb1b679d142.tar.xz infinity-for-reddit-412b78912b9fae089d4a5f18a391eeb1b679d142.tar.zst infinity-for-reddit-412b78912b9fae089d4a5f18a391eeb1b679d142.zip |
feat: re-enable manual material you for older platforms
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/utils/MaterialYouUtils.java | 79 |
1 files changed, 78 insertions, 1 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/MaterialYouUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/MaterialYouUtils.java index ab2c7364..ab044a53 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/MaterialYouUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/MaterialYouUtils.java @@ -82,7 +82,7 @@ public class MaterialYouUtils { lightTheme.circularProgressBarBackground = context.getColor(android.R.color.system_accent1_10); lightTheme.dividerColor = context.getColor(android.R.color.system_neutral1_100); lightTheme.isLightStatusBar = false; - lightTheme.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface = false; + lightTheme.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface = true; lightTheme.name = "Material You"; darkTheme.colorPrimary = context.getColor(android.R.color.system_accent1_100); @@ -136,6 +136,83 @@ public class MaterialYouUtils { } EventBus.getDefault().post(new RecreateActivityEvent()); }); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { + WallpaperManager wallpaperManager = WallpaperManager.getInstance(context); + WallpaperColors wallpaperColors = wallpaperManager.getWallpaperColors(WallpaperManager.FLAG_SYSTEM); + + if (wallpaperColors != null) { + int colorPrimaryInt = lightenColor(wallpaperColors.getPrimaryColor().toArgb(), 0.4); + int colorPrimaryDarkInt = darkenColor(colorPrimaryInt, 0.3); + int backgroundColor = lightenColor(colorPrimaryInt, 0.2); + int cardViewBackgroundColor = lightenColor(colorPrimaryInt, 0.6); + Color colorAccent = wallpaperColors.getSecondaryColor(); + int colorAccentInt = lightenColor(colorAccent == null ? customThemeWrapper.getColorAccent() : colorAccent.toArgb(), 0.4); + + int colorPrimaryAppropriateTextColor = getAppropriateTextColor(colorPrimaryInt); + int backgroundColorAppropriateTextColor = getAppropriateTextColor(backgroundColor); + + CustomTheme lightTheme = CustomThemeWrapper.getIndigo(context); + CustomTheme darkTheme = CustomThemeWrapper.getIndigoDark(context); + CustomTheme amoledTheme = CustomThemeWrapper.getIndigoAmoled(context); + + lightTheme.colorPrimary = colorPrimaryInt; + lightTheme.colorPrimaryDark = colorPrimaryDarkInt; + lightTheme.colorAccent = colorAccentInt; + lightTheme.colorPrimaryLightTheme = colorPrimaryInt; + lightTheme.backgroundColor = backgroundColor; + lightTheme.cardViewBackgroundColor = cardViewBackgroundColor; + lightTheme.commentBackgroundColor = cardViewBackgroundColor; + lightTheme.awardedCommentBackgroundColor = cardViewBackgroundColor; + lightTheme.bottomAppBarBackgroundColor = colorPrimaryInt; + lightTheme.navBarColor = colorPrimaryInt; + lightTheme.primaryTextColor = backgroundColorAppropriateTextColor; + lightTheme.secondaryTextColor = backgroundColorAppropriateTextColor == Color.BLACK ? Color.parseColor("#8A000000") : Color.parseColor("#B3FFFFFF"); + lightTheme.bottomAppBarIconColor = colorPrimaryAppropriateTextColor; + lightTheme.primaryIconColor = backgroundColorAppropriateTextColor; + lightTheme.fabIconColor = colorPrimaryAppropriateTextColor; + lightTheme.toolbarPrimaryTextAndIconColor = colorPrimaryAppropriateTextColor; + lightTheme.toolbarSecondaryTextColor = colorPrimaryAppropriateTextColor; + lightTheme.tabLayoutWithCollapsedCollapsingToolbarTabIndicator = colorPrimaryAppropriateTextColor; + lightTheme.tabLayoutWithCollapsedCollapsingToolbarTextColor = colorPrimaryAppropriateTextColor; + lightTheme.tabLayoutWithCollapsedCollapsingToolbarTabBackground = colorPrimaryInt; + lightTheme.tabLayoutWithExpandedCollapsingToolbarTabBackground = colorPrimaryInt; + lightTheme.tabLayoutWithExpandedCollapsingToolbarTabIndicator = colorPrimaryAppropriateTextColor; + lightTheme.tabLayoutWithExpandedCollapsingToolbarTextColor = colorPrimaryAppropriateTextColor; + lightTheme.circularProgressBarBackground = colorPrimaryInt; + lightTheme.dividerColor = backgroundColorAppropriateTextColor == Color.BLACK ? Color.parseColor("#E0E0E0") : Color.parseColor("69666C"); + lightTheme.isLightStatusBar = colorPrimaryAppropriateTextColor == Color.BLACK; + lightTheme.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface = + (lightTheme.isLightStatusBar && getAppropriateTextColor(cardViewBackgroundColor) == Color.WHITE) + || (!lightTheme.isLightStatusBar && getAppropriateTextColor(cardViewBackgroundColor) == Color.BLACK); + lightTheme.name = "Material You"; + + darkTheme.colorAccent = colorPrimaryInt; + darkTheme.colorPrimaryLightTheme = colorPrimaryInt; + darkTheme.name = "Material You Dark"; + + amoledTheme.colorAccent = colorPrimaryInt; + amoledTheme.colorPrimaryLightTheme = colorPrimaryInt; + amoledTheme.name = "Material You Amoled"; + + redditDataRoomDatabase.customThemeDao().unsetLightTheme(); + redditDataRoomDatabase.customThemeDao().unsetDarkTheme(); + redditDataRoomDatabase.customThemeDao().unsetAmoledTheme(); + + redditDataRoomDatabase.customThemeDao().insert(lightTheme); + redditDataRoomDatabase.customThemeDao().insert(darkTheme); + redditDataRoomDatabase.customThemeDao().insert(amoledTheme); + + CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(lightTheme, lightThemeSharedPreferences); + CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(darkTheme, darkThemeSharedPreferences); + CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(amoledTheme, amoledThemeSharedPreferences); + + handler.post(() -> { + if (materialYouListener != null) { + materialYouListener.applied(); + } + EventBus.getDefault().post(new RecreateActivityEvent()); + }); + } } }); } |