diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/BaseActivity.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/BaseActivity.java index 7f73d5e..38b85f4 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/BaseActivity.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/BaseActivity.java @@ -1,5 +1,6 @@ package com.cringe_studios.cringe_authenticator; +import android.content.res.Configuration; import android.os.Bundle; import android.util.Log; import android.view.WindowManager; @@ -12,6 +13,8 @@ import com.cringe_studios.cringe_authenticator.unlock.UnlockContract; import com.cringe_studios.cringe_authenticator.util.SettingsUtil; import com.cringe_studios.cringe_authenticator.util.ThemeUtil; +import java.util.Locale; + public class BaseActivity extends AppCompatActivity { private ActivityResultLauncher startUnlockActivity; @@ -28,6 +31,7 @@ public class BaseActivity extends AppCompatActivity { } ThemeUtil.loadTheme(this); + setLocale(SettingsUtil.getLocale(this)); } private void registerCallbacks() { @@ -43,4 +47,11 @@ public class BaseActivity extends AppCompatActivity { startUnlockActivity.launch(null); } + public void setLocale(Locale locale) { + Locale.setDefault(locale); + Configuration config = new Configuration(); + config.locale = locale; + getResources().updateConfiguration(config, getResources().getDisplayMetrics()); + } + } diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/MainActivity.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/MainActivity.java index 62d5ace..c26803b 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/MainActivity.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/MainActivity.java @@ -67,8 +67,6 @@ public class MainActivity extends BaseActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setLocale(SettingsUtil.getLocale(this)); - qrScanner = new QRScanner(); startQRCodeScan = registerForActivityResult(new QRScannerContract(), obj -> { @@ -149,13 +147,6 @@ public class MainActivity extends BaseActivity { qrScanner.close(); } - public void setLocale(Locale locale) { - Locale.setDefault(locale); - Configuration config = new Configuration(); - config.locale = locale; - getResources().updateConfiguration(config, getResources().getDisplayMetrics()); - } - private void launchApp() { fullyLaunched = true; lockOnPause = true; diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/fragment/SettingsFragment.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/fragment/SettingsFragment.java index 2575674..9cbaacd 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/fragment/SettingsFragment.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/fragment/SettingsFragment.java @@ -1,5 +1,6 @@ package com.cringe_studios.cringe_authenticator.fragment; +import android.app.AlertDialog; import android.net.Uri; import android.os.Bundle; import android.util.Log; @@ -68,7 +69,7 @@ public class SettingsFragment extends NamedFragment { if(locale.equals(SettingsUtil.getLocale(requireContext()))) return; SettingsUtil.setLocale(requireContext(), locale); - ((MainActivity) requireActivity()).setLocale(locale); + //((MainActivity) requireActivity()).setLocale(locale); requireActivity().recreate(); } @@ -144,9 +145,6 @@ public class SettingsFragment extends NamedFragment { // TODO: inform user } - binding.settingsEnableIntroVideo.setChecked(SettingsUtil.isIntroVideoEnabled(requireContext())); - binding.settingsEnableIntroVideo.setOnCheckedChangeListener((view, checked) -> SettingsUtil.setEnableIntroVideo(requireContext(), checked)); - binding.settingsScreenSecurity.setChecked(SettingsUtil.isScreenSecurity(requireContext())); binding.settingsScreenSecurity.setOnCheckedChangeListener((view, checked) -> { SettingsUtil.setScreenSecurity(requireContext(), checked); @@ -161,6 +159,15 @@ public class SettingsFragment extends NamedFragment { themeNames[i] = getResources().getString(Theme.values()[i].getName()); } + binding.settingsEnableIntroVideo.setChecked(SettingsUtil.isIntroVideoEnabled(requireContext())); + binding.settingsEnableIntroVideo.setOnCheckedChangeListener((view, checked) -> SettingsUtil.setEnableIntroVideo(requireContext(), checked)); + + binding.settingsEnableThemedBackground.setChecked(SettingsUtil.isThemedBackgroundEnabled(requireContext())); + binding.settingsEnableThemedBackground.setOnCheckedChangeListener((view, checked) -> { + SettingsUtil.setEnableThemedBackground(requireContext(), checked); + requireActivity().recreate(); + }); + binding.settingsTheme.setAdapter(new ArrayAdapter<>(requireContext(), android.R.layout.simple_list_item_1, themeNames)); binding.settingsTheme.setSelection(SettingsUtil.getTheme(requireContext()).ordinal()); binding.settingsTheme.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @@ -177,6 +184,12 @@ public class SettingsFragment extends NamedFragment { public void onNothingSelected(AdapterView parent) {} }); + binding.settingsEnableMinimalistTheme.setChecked(SettingsUtil.isMinimalistThemeEnabled(requireContext())); + binding.settingsEnableMinimalistTheme.setOnCheckedChangeListener((view, checked) -> { + SettingsUtil.setEnableMinimalistTheme(requireContext(), checked); + requireActivity().recreate(); + }); + String[] appearanceNames = new String[Appearance.values().length]; for(int i = 0; i < Appearance.values().length; i++) { appearanceNames[i] = getResources().getString(Appearance.values()[i].getName()); @@ -200,6 +213,7 @@ public class SettingsFragment extends NamedFragment { binding.settingsCreateBackup.setOnClickListener(view -> { new StyledDialogBuilder(requireContext()) + .setTitle(R.string.create_backup) .setItems(R.array.backup_create, (d, which) -> { switch(which) { case 0: diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/util/SettingsUtil.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/util/SettingsUtil.java index f96819d..b944e31 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/util/SettingsUtil.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/util/SettingsUtil.java @@ -156,6 +156,24 @@ public class SettingsUtil { return ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE).getBoolean("enableIntroVideo", true); } + public static void setEnableThemedBackground(Context ctx, boolean enableThemedBackground) { + SharedPreferences prefs = ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE); + prefs.edit().putBoolean("enableThemedBackground", enableThemedBackground).apply(); + } + + public static boolean isThemedBackgroundEnabled(Context ctx) { + return ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE).getBoolean("enableThemedBackground", true); + } + + public static void setEnableMinimalistTheme(Context ctx, boolean enableMinimalistTheme) { + SharedPreferences prefs = ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE); + prefs.edit().putBoolean("enableMinimalistTheme", enableMinimalistTheme).apply(); + } + + public static boolean isMinimalistThemeEnabled(Context ctx) { + return ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE).getBoolean("enableMinimalistTheme", false); + } + public static void setScreenSecurity(Context ctx, boolean screenSecurity) { SharedPreferences prefs = ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE); prefs.edit().putBoolean("screenSecurity", screenSecurity).apply(); diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/util/StyledDialogBuilder.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/util/StyledDialogBuilder.java index 429caef..06c5ce0 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/util/StyledDialogBuilder.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/util/StyledDialogBuilder.java @@ -2,6 +2,8 @@ package com.cringe_studios.cringe_authenticator.util; import android.content.Context; +import android.content.res.TypedArray; +import android.util.Log; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; @@ -22,7 +24,17 @@ public class StyledDialogBuilder extends AlertDialog.Builder { @Override public AlertDialog create() { AlertDialog dialog = super.create(); - dialog.getWindow().setBackgroundDrawableResource(R.drawable.dialog_themed); + + TypedArray arr = dialog.getContext().obtainStyledAttributes(new int[] {R.attr.dialogBackground}); + try { + Log.d("WINDOW", dialog.getWindow().getClass().toString()); + dialog.getWindow().setBackgroundDrawable(arr.getDrawable(0)); + //dialog.getWindow().getContext().getResources().obtainAttributes().getDrawable() + //R.attr.dialogBackground; + }finally { + arr.close(); + } + return dialog; } diff --git a/app/src/main/java/com/cringe_studios/cringe_authenticator/util/ThemeUtil.java b/app/src/main/java/com/cringe_studios/cringe_authenticator/util/ThemeUtil.java index 427dc4a..4a54c83 100644 --- a/app/src/main/java/com/cringe_studios/cringe_authenticator/util/ThemeUtil.java +++ b/app/src/main/java/com/cringe_studios/cringe_authenticator/util/ThemeUtil.java @@ -15,10 +15,16 @@ public class ThemeUtil { Theme theme = SettingsUtil.getTheme(activity); activity.setTheme(theme.getStyle()); + if(SettingsUtil.isMinimalistThemeEnabled(activity)) { + activity.getTheme().applyStyle(R.style.Theme_CringeAuthenticator_Minimalist, true); + } + AppCompatDelegate.setDefaultNightMode(SettingsUtil.getAppearance(activity).getValue()); } public static void loadBackground(AppCompatActivity activity) { + if(!SettingsUtil.isThemedBackgroundEnabled(activity)) return; + Theme theme = SettingsUtil.getTheme(activity); Appearance appearance = SettingsUtil.getAppearance(activity); diff --git a/app/src/main/res/drawable/button_simple.xml b/app/src/main/res/drawable/button_simple.xml new file mode 100644 index 0000000..358c00b --- /dev/null +++ b/app/src/main/res/drawable/button_simple.xml @@ -0,0 +1,16 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_unlock.xml b/app/src/main/res/layout/activity_unlock.xml index 5f7e419..8e16db5 100644 --- a/app/src/main/res/layout/activity_unlock.xml +++ b/app/src/main/res/layout/activity_unlock.xml @@ -43,7 +43,7 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginTop="10dp" - android:background="@drawable/button_themed" + android:background="?attr/buttonBackground" android:text="@string/unlock" android:textAllCaps="false" app:layout_constraintEnd_toEndOf="parent" @@ -55,7 +55,7 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginTop="10dp" - android:background="@drawable/button_themed" + android:background="?attr/buttonBackground" android:text="@string/unlock_using_biometrics" android:textAllCaps="false" app:layout_constraintEnd_toEndOf="parent" diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml index b340076..52e960b 100644 --- a/app/src/main/res/layout/fragment_settings.xml +++ b/app/src/main/res/layout/fragment_settings.xml @@ -23,6 +23,12 @@ android:paddingTop="10dp" android:paddingBottom="10dp" /> + + - - + + + + + + + + + + + android:text="@string/backups" /> @@ -95,8 +125,8 @@ android:id="@+id/settings_load_backup" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="@drawable/button_themed" - android:text="Load backup" + android:background="?attr/buttonBackground" + android:text="@string/load_backup" android:layout_marginTop="10dp" android:textAllCaps="false" /> diff --git a/app/src/main/res/layout/menu_item.xml b/app/src/main/res/layout/menu_item.xml index 3fc0411..4c521a3 100644 --- a/app/src/main/res/layout/menu_item.xml +++ b/app/src/main/res/layout/menu_item.xml @@ -13,7 +13,7 @@ android:id="@+id/button" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="@drawable/button_themed" + android:background="?attr/buttonBackground" android:paddingTop="20dp" android:paddingBottom="20dp" android:textAllCaps="false" diff --git a/app/src/main/res/layout/otp_code.xml b/app/src/main/res/layout/otp_code.xml index e1d1c9f..26622da 100644 --- a/app/src/main/res/layout/otp_code.xml +++ b/app/src/main/res/layout/otp_code.xml @@ -16,7 +16,7 @@ android:orientation="horizontal" android:paddingTop="5dp" android:paddingBottom="5dp" - android:background="@drawable/button_themed"> + android:background="?attr/buttonBackground"> Mit neuem Passwort erstellen Backup laden + Backups + Backup erstellen + Backup laden \ No newline at end of file diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 4622598..a60897b 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -2,4 +2,7 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3d7f57b..2ae8055 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -91,4 +91,7 @@ Create with new password Load backup + Backups + Create backup + Load backup \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 70c1ed7..5bb362c 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -11,6 +11,9 @@ @color/black @color/background_light_grey @style/ActionPopupMenuStyle + @drawable/dialog_themed + @drawable/menu_themed + @drawable/button_themed + \ No newline at end of file