From 412b78912b9fae089d4a5f18a391eeb1b679d142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wieland=20Sch=C3=B6bl?= Date: Tue, 2 Nov 2021 15:13:54 +0100 Subject: feat: re-enable manual material you for older platforms --- .../infinityforreddit/utils/MaterialYouUtils.java | 79 +++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/ml/docilealligator') 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()); + }); + } } }); } -- cgit v1.2.3