Make app background follow theme and appearance

This commit is contained in:
MrLetsplay 2023-09-24 12:46:47 +02:00
parent 2b18b591e3
commit 1f6d3d94ed
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
6 changed files with 42 additions and 8 deletions

View File

@ -32,6 +32,7 @@ import com.cringe_studios.cringe_authenticator.util.NavigationUtil;
import com.cringe_studios.cringe_authenticator.util.OTPDatabase; import com.cringe_studios.cringe_authenticator.util.OTPDatabase;
import com.cringe_studios.cringe_authenticator.util.SettingsUtil; import com.cringe_studios.cringe_authenticator.util.SettingsUtil;
import com.cringe_studios.cringe_authenticator.util.StyledDialogBuilder; import com.cringe_studios.cringe_authenticator.util.StyledDialogBuilder;
import com.cringe_studios.cringe_authenticator.util.ThemeUtil;
import com.cringe_studios.cringe_authenticator_library.OTPType; import com.cringe_studios.cringe_authenticator_library.OTPType;
import com.google.mlkit.vision.common.InputImage; import com.google.mlkit.vision.common.InputImage;
@ -136,6 +137,7 @@ public class MainActivity extends BaseActivity {
binding = ActivityMainBinding.inflate(getLayoutInflater()); binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot()); setContentView(binding.getRoot());
ThemeUtil.loadBackground(this);
setSupportActionBar(binding.toolbar); setSupportActionBar(binding.toolbar);

View File

@ -60,6 +60,7 @@ public class UnlockActivity extends BaseActivity {
binding = ActivityUnlockBinding.inflate(getLayoutInflater()); binding = ActivityUnlockBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot()); setContentView(binding.getRoot());
ThemeUtil.loadBackground(this);
if(SettingsUtil.isBiometricEncryption(this) && BiometricUtil.isSupported(this)) { if(SettingsUtil.isBiometricEncryption(this) && BiometricUtil.isSupported(this)) {
Runnable onSuccess = () -> { Runnable onSuccess = () -> {

View File

@ -1,5 +1,6 @@
package com.cringe_studios.cringe_authenticator.util; package com.cringe_studios.cringe_authenticator.util;
import androidx.annotation.DrawableRes;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import androidx.annotation.StyleRes; import androidx.annotation.StyleRes;
@ -7,12 +8,12 @@ import com.cringe_studios.cringe_authenticator.R;
public enum Theme { public enum Theme {
BLUE_GREEN(R.string.theme_blue_green, R.style.Theme_CringeAuthenticator_Blue_Green), BLUE_GREEN(R.string.theme_blue_green, R.style.Theme_CringeAuthenticator_Blue_Green, R.drawable.background_blue_green_light, R.drawable.background_blue_green),
RED_BLUE(R.string.theme_red_blue, R.style.Theme_CringeAuthenticator_Red_Blue), RED_BLUE(R.string.theme_red_blue, R.style.Theme_CringeAuthenticator_Red_Blue, R.drawable.background_red_blue_light, R.drawable.background_red_blue),
PINK_GREEN(R.string.theme_pink_green, R.style.Theme_CringeAuthenticator_Pink_Green), PINK_GREEN(R.string.theme_pink_green, R.style.Theme_CringeAuthenticator_Pink_Green, R.drawable.background_pink_green_light, R.drawable.background_pink_green),
BLUE_YELLOW(R.string.theme_blue_yellow, R.style.Theme_CringeAuthenticator_Blue_Yellow), BLUE_YELLOW(R.string.theme_blue_yellow, R.style.Theme_CringeAuthenticator_Blue_Yellow, R.drawable.background_blue_yellow_light, R.drawable.background_blue_yellow),
GREEN_YELLOW(R.string.theme_green_yellow, R.style.Theme_CringeAuthenticator_Green_Yellow), GREEN_YELLOW(R.string.theme_green_yellow, R.style.Theme_CringeAuthenticator_Green_Yellow, R.drawable.background_green_yellow_light, R.drawable.background_green_yellow),
ORANGE_TURQUOISE(R.string.theme_orange_turquoise, R.style.Theme_CringeAuthenticator_Orange_Turquoise), ORANGE_TURQUOISE(R.string.theme_orange_turquoise, R.style.Theme_CringeAuthenticator_Orange_Turquoise, R.drawable.background_orange_turquoise_light, R.drawable.background_orange_turquoise),
; ;
@StringRes @StringRes
@ -21,9 +22,17 @@ public enum Theme {
@StyleRes @StyleRes
private final int style; private final int style;
Theme(@StringRes int name, @StyleRes int style) { @DrawableRes
private final int lightBackground;
@DrawableRes
private final int darkBackground;
Theme(@StringRes int name, @StyleRes int style, @DrawableRes int lightBackground, @DrawableRes int darkBackground) {
this.name = name; this.name = name;
this.style = style; this.style = style;
this.lightBackground = lightBackground;
this.darkBackground = darkBackground;
} }
@StringRes @StringRes
@ -36,4 +45,13 @@ public enum Theme {
return style; return style;
} }
@DrawableRes
public int getLightBackground() {
return lightBackground;
}
@DrawableRes
public int getDarkBackground() {
return darkBackground;
}
} }

View File

@ -1,6 +1,8 @@
package com.cringe_studios.cringe_authenticator.util; package com.cringe_studios.cringe_authenticator.util;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.util.Log;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.app.AppCompatDelegate;
@ -16,4 +18,14 @@ public class ThemeUtil {
AppCompatDelegate.setDefaultNightMode(SettingsUtil.getAppearance(activity).getValue()); AppCompatDelegate.setDefaultNightMode(SettingsUtil.getAppearance(activity).getValue());
} }
public static void loadBackground(AppCompatActivity activity) {
Theme theme = SettingsUtil.getTheme(activity);
Appearance appearance = SettingsUtil.getAppearance(activity);
View v = activity.findViewById(R.id.app_background);
if(v != null) {
v.setBackgroundResource(appearance == Appearance.LIGHT ? theme.getLightBackground() : theme.getDarkBackground());
}
}
} }

View File

@ -5,6 +5,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="true" android:fitsSystemWindows="true"
android:id="@+id/app_background"
tools:context=".MainActivity"> tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout

View File

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/background_blue_green" android:id="@+id/app_background"
android:padding="16dp"> android:padding="16dp">
<TextView <TextView