mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-30 21:07:11 +01:00
feat: "real" Material You implementation
This commit is contained in:
parent
efd5f61889
commit
7fcc1890fe
@ -1,7 +1,7 @@
|
|||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 30
|
compileSdkVersion 31
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "ml.docilealligator.infinityforreddit"
|
applicationId "ml.docilealligator.infinityforreddit"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
|
@ -15,6 +15,7 @@ import org.greenrobot.eventbus.EventBus;
|
|||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomTheme;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomTheme;
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
@ -23,6 +24,7 @@ import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent;
|
|||||||
public class MaterialYouUtils {
|
public class MaterialYouUtils {
|
||||||
public interface CheckThemeNameListener {
|
public interface CheckThemeNameListener {
|
||||||
void themeNotExists();
|
void themeNotExists();
|
||||||
|
|
||||||
void themeExists();
|
void themeExists();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,62 +50,72 @@ public class MaterialYouUtils {
|
|||||||
SharedPreferences amoledThemeSharedPreferences,
|
SharedPreferences amoledThemeSharedPreferences,
|
||||||
@Nullable MaterialYouListener materialYouListener) {
|
@Nullable MaterialYouListener materialYouListener) {
|
||||||
executor.execute(() -> {
|
executor.execute(() -> {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
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 lightTheme = CustomThemeWrapper.getIndigo(context);
|
||||||
CustomTheme darkTheme = CustomThemeWrapper.getIndigoDark(context);
|
CustomTheme darkTheme = CustomThemeWrapper.getIndigoDark(context);
|
||||||
CustomTheme amoledTheme = CustomThemeWrapper.getIndigoAmoled(context);
|
CustomTheme amoledTheme = CustomThemeWrapper.getIndigoAmoled(context);
|
||||||
|
|
||||||
lightTheme.colorPrimary = colorPrimaryInt;
|
|
||||||
lightTheme.colorPrimaryDark = colorPrimaryDarkInt;
|
lightTheme.colorPrimary = context.getColor(android.R.color.system_accent1_300);
|
||||||
lightTheme.colorAccent = colorAccentInt;
|
lightTheme.colorPrimaryDark = context.getColor(android.R.color.system_accent1_500);
|
||||||
lightTheme.colorPrimaryLightTheme = colorPrimaryInt;
|
lightTheme.colorAccent = context.getColor(android.R.color.system_accent3_300);
|
||||||
lightTheme.backgroundColor = backgroundColor;
|
lightTheme.colorPrimaryLightTheme = context.getColor(android.R.color.system_accent1_200);
|
||||||
lightTheme.cardViewBackgroundColor = cardViewBackgroundColor;
|
lightTheme.backgroundColor = context.getColor(android.R.color.system_neutral1_10);
|
||||||
lightTheme.commentBackgroundColor = cardViewBackgroundColor;
|
lightTheme.cardViewBackgroundColor = context.getColor(android.R.color.system_neutral2_50);
|
||||||
lightTheme.awardedCommentBackgroundColor = cardViewBackgroundColor;
|
lightTheme.commentBackgroundColor = context.getColor(android.R.color.system_neutral2_50);
|
||||||
lightTheme.bottomAppBarBackgroundColor = colorPrimaryInt;
|
lightTheme.awardedCommentBackgroundColor = context.getColor(android.R.color.system_neutral2_100);
|
||||||
lightTheme.navBarColor = colorPrimaryInt;
|
lightTheme.bottomAppBarBackgroundColor = context.getColor(android.R.color.system_accent2_100);
|
||||||
lightTheme.primaryTextColor = backgroundColorAppropriateTextColor;
|
lightTheme.navBarColor = context.getColor(android.R.color.system_neutral2_100);
|
||||||
lightTheme.secondaryTextColor = backgroundColorAppropriateTextColor == Color.BLACK ? Color.parseColor("#8A000000") : Color.parseColor("#B3FFFFFF");
|
lightTheme.primaryTextColor = context.getColor(android.R.color.system_neutral1_900);
|
||||||
lightTheme.bottomAppBarIconColor = colorPrimaryAppropriateTextColor;
|
lightTheme.secondaryTextColor = context.getColor(android.R.color.system_neutral1_900);
|
||||||
lightTheme.primaryIconColor = backgroundColorAppropriateTextColor;
|
lightTheme.bottomAppBarIconColor = context.getColor(android.R.color.system_accent1_400);;
|
||||||
lightTheme.fabIconColor = colorPrimaryAppropriateTextColor;
|
lightTheme.primaryIconColor = context.getColor(android.R.color.system_accent1_400);
|
||||||
lightTheme.toolbarPrimaryTextAndIconColor = colorPrimaryAppropriateTextColor;
|
lightTheme.fabIconColor = context.getColor(android.R.color.system_neutral1_10);
|
||||||
lightTheme.toolbarSecondaryTextColor = colorPrimaryAppropriateTextColor;
|
lightTheme.toolbarPrimaryTextAndIconColor = context.getColor(android.R.color.system_accent1_50);
|
||||||
lightTheme.tabLayoutWithCollapsedCollapsingToolbarTabIndicator = colorPrimaryAppropriateTextColor;
|
lightTheme.toolbarSecondaryTextColor = context.getColor(android.R.color.system_accent3_50);
|
||||||
lightTheme.tabLayoutWithCollapsedCollapsingToolbarTextColor = colorPrimaryAppropriateTextColor;
|
lightTheme.tabLayoutWithCollapsedCollapsingToolbarTabIndicator = context.getColor(android.R.color.system_accent1_50);
|
||||||
lightTheme.tabLayoutWithCollapsedCollapsingToolbarTabBackground = colorPrimaryInt;
|
lightTheme.tabLayoutWithCollapsedCollapsingToolbarTextColor = context.getColor(android.R.color.system_accent1_50);
|
||||||
lightTheme.tabLayoutWithExpandedCollapsingToolbarTabBackground = colorPrimaryInt;
|
lightTheme.tabLayoutWithCollapsedCollapsingToolbarTabBackground = context.getColor(android.R.color.system_accent1_50);
|
||||||
lightTheme.tabLayoutWithExpandedCollapsingToolbarTabIndicator = colorPrimaryAppropriateTextColor;
|
lightTheme.tabLayoutWithExpandedCollapsingToolbarTabBackground = context.getColor(android.R.color.system_accent1_50);
|
||||||
lightTheme.tabLayoutWithExpandedCollapsingToolbarTextColor = colorPrimaryAppropriateTextColor;
|
lightTheme.tabLayoutWithExpandedCollapsingToolbarTabIndicator = context.getColor(android.R.color.system_accent1_50);
|
||||||
lightTheme.circularProgressBarBackground = colorPrimaryInt;
|
lightTheme.tabLayoutWithExpandedCollapsingToolbarTextColor = context.getColor(android.R.color.system_accent1_50);
|
||||||
lightTheme.dividerColor = backgroundColorAppropriateTextColor == Color.BLACK ? Color.parseColor("#E0E0E0") : Color.parseColor("69666C");
|
lightTheme.circularProgressBarBackground = context.getColor(android.R.color.system_accent1_10);
|
||||||
lightTheme.isLightStatusBar = colorPrimaryAppropriateTextColor == Color.BLACK;
|
lightTheme.dividerColor = context.getColor(android.R.color.system_neutral1_100);
|
||||||
lightTheme.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface =
|
lightTheme.isLightStatusBar = false;
|
||||||
(lightTheme.isLightStatusBar && getAppropriateTextColor(cardViewBackgroundColor) == Color.WHITE)
|
lightTheme.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface = false;
|
||||||
|| (!lightTheme.isLightStatusBar && getAppropriateTextColor(cardViewBackgroundColor) == Color.BLACK);
|
|
||||||
lightTheme.name = "Material You";
|
lightTheme.name = "Material You";
|
||||||
|
|
||||||
darkTheme.colorAccent = colorPrimaryInt;
|
darkTheme.colorPrimary = context.getColor(android.R.color.system_accent1_100);
|
||||||
darkTheme.colorPrimaryLightTheme = colorPrimaryInt;
|
darkTheme.colorPrimaryDark = context.getColor(android.R.color.system_accent1_300);
|
||||||
|
darkTheme.colorAccent = context.getColor(android.R.color.system_accent3_100);
|
||||||
|
darkTheme.colorPrimaryLightTheme = context.getColor(android.R.color.system_accent1_100);
|
||||||
|
darkTheme.backgroundColor = context.getColor(android.R.color.system_neutral1_900);
|
||||||
|
darkTheme.cardViewBackgroundColor = context.getColor(android.R.color.system_neutral2_800);
|
||||||
|
darkTheme.commentBackgroundColor = context.getColor(android.R.color.system_neutral2_800);
|
||||||
|
darkTheme.awardedCommentBackgroundColor = context.getColor(android.R.color.system_neutral2_800);
|
||||||
|
darkTheme.bottomAppBarBackgroundColor = context.getColor(android.R.color.system_accent2_800);
|
||||||
|
darkTheme.navBarColor = context.getColor(android.R.color.system_neutral2_800);
|
||||||
|
darkTheme.primaryTextColor = context.getColor(android.R.color.system_neutral1_10);
|
||||||
|
darkTheme.secondaryTextColor = context.getColor(android.R.color.system_neutral1_10);
|
||||||
|
darkTheme.bottomAppBarIconColor = context.getColor(android.R.color.system_accent1_100);;
|
||||||
|
darkTheme.primaryIconColor = context.getColor(android.R.color.system_accent1_100);
|
||||||
|
darkTheme.fabIconColor = context.getColor(android.R.color.system_neutral1_900);
|
||||||
|
darkTheme.toolbarPrimaryTextAndIconColor = context.getColor(android.R.color.system_accent1_900);
|
||||||
|
darkTheme.toolbarSecondaryTextColor = context.getColor(android.R.color.system_accent3_900);
|
||||||
|
darkTheme.tabLayoutWithCollapsedCollapsingToolbarTabIndicator = context.getColor(android.R.color.system_accent1_800);
|
||||||
|
darkTheme.tabLayoutWithCollapsedCollapsingToolbarTextColor = context.getColor(android.R.color.system_accent1_800);
|
||||||
|
darkTheme.tabLayoutWithCollapsedCollapsingToolbarTabBackground = context.getColor(android.R.color.system_accent1_800);
|
||||||
|
darkTheme.tabLayoutWithExpandedCollapsingToolbarTabBackground = context.getColor(android.R.color.system_accent1_800);
|
||||||
|
darkTheme.tabLayoutWithExpandedCollapsingToolbarTabIndicator = context.getColor(android.R.color.system_accent1_800);
|
||||||
|
darkTheme.tabLayoutWithExpandedCollapsingToolbarTextColor = context.getColor(android.R.color.system_accent1_800);
|
||||||
|
darkTheme.circularProgressBarBackground = context.getColor(android.R.color.system_accent1_900);
|
||||||
|
darkTheme.dividerColor = context.getColor(android.R.color.system_neutral1_600);
|
||||||
|
darkTheme.isLightStatusBar = true;
|
||||||
|
darkTheme.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface = true;
|
||||||
darkTheme.name = "Material You Dark";
|
darkTheme.name = "Material You Dark";
|
||||||
|
|
||||||
amoledTheme.colorAccent = colorPrimaryInt;
|
amoledTheme.colorAccent = context.getColor(android.R.color.system_accent1_100);
|
||||||
amoledTheme.colorPrimaryLightTheme = colorPrimaryInt;
|
amoledTheme.colorPrimaryLightTheme = context.getColor(android.R.color.system_accent3_100);
|
||||||
amoledTheme.name = "Material You Amoled";
|
amoledTheme.name = "Material You Amoled";
|
||||||
|
|
||||||
redditDataRoomDatabase.customThemeDao().unsetLightTheme();
|
redditDataRoomDatabase.customThemeDao().unsetLightTheme();
|
||||||
@ -125,7 +137,6 @@ public class MaterialYouUtils {
|
|||||||
EventBus.getDefault().post(new RecreateActivityEvent());
|
EventBus.getDefault().post(new RecreateActivityEvent());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user