feat: re-enable manual material you for older platforms

This commit is contained in:
Wieland Schöbl 2021-11-02 15:13:54 +01:00
parent 7fcc1890fe
commit 412b78912b

View File

@ -82,7 +82,7 @@ public class MaterialYouUtils {
lightTheme.circularProgressBarBackground = context.getColor(android.R.color.system_accent1_10); lightTheme.circularProgressBarBackground = context.getColor(android.R.color.system_accent1_10);
lightTheme.dividerColor = context.getColor(android.R.color.system_neutral1_100); lightTheme.dividerColor = context.getColor(android.R.color.system_neutral1_100);
lightTheme.isLightStatusBar = false; lightTheme.isLightStatusBar = false;
lightTheme.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface = false; lightTheme.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface = true;
lightTheme.name = "Material You"; lightTheme.name = "Material You";
darkTheme.colorPrimary = context.getColor(android.R.color.system_accent1_100); darkTheme.colorPrimary = context.getColor(android.R.color.system_accent1_100);
@ -136,6 +136,83 @@ public class MaterialYouUtils {
} }
EventBus.getDefault().post(new RecreateActivityEvent()); 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());
});
}
} }
}); });
} }