UI changes, Add more settings

This commit is contained in:
MrLetsplay 2023-09-25 13:57:48 +02:00
parent 831a1a9c20
commit eabafe0e25
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
15 changed files with 145 additions and 30 deletions

View File

@ -1,5 +1,6 @@
package com.cringe_studios.cringe_authenticator; package com.cringe_studios.cringe_authenticator;
import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.WindowManager; 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.SettingsUtil;
import com.cringe_studios.cringe_authenticator.util.ThemeUtil; import com.cringe_studios.cringe_authenticator.util.ThemeUtil;
import java.util.Locale;
public class BaseActivity extends AppCompatActivity { public class BaseActivity extends AppCompatActivity {
private ActivityResultLauncher<Void> startUnlockActivity; private ActivityResultLauncher<Void> startUnlockActivity;
@ -28,6 +31,7 @@ public class BaseActivity extends AppCompatActivity {
} }
ThemeUtil.loadTheme(this); ThemeUtil.loadTheme(this);
setLocale(SettingsUtil.getLocale(this));
} }
private void registerCallbacks() { private void registerCallbacks() {
@ -43,4 +47,11 @@ public class BaseActivity extends AppCompatActivity {
startUnlockActivity.launch(null); startUnlockActivity.launch(null);
} }
public void setLocale(Locale locale) {
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getResources().updateConfiguration(config, getResources().getDisplayMetrics());
}
} }

View File

@ -67,8 +67,6 @@ public class MainActivity extends BaseActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setLocale(SettingsUtil.getLocale(this));
qrScanner = new QRScanner(); qrScanner = new QRScanner();
startQRCodeScan = registerForActivityResult(new QRScannerContract(), obj -> { startQRCodeScan = registerForActivityResult(new QRScannerContract(), obj -> {
@ -149,13 +147,6 @@ public class MainActivity extends BaseActivity {
qrScanner.close(); 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() { private void launchApp() {
fullyLaunched = true; fullyLaunched = true;
lockOnPause = true; lockOnPause = true;

View File

@ -1,5 +1,6 @@
package com.cringe_studios.cringe_authenticator.fragment; package com.cringe_studios.cringe_authenticator.fragment;
import android.app.AlertDialog;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
@ -68,7 +69,7 @@ public class SettingsFragment extends NamedFragment {
if(locale.equals(SettingsUtil.getLocale(requireContext()))) return; if(locale.equals(SettingsUtil.getLocale(requireContext()))) return;
SettingsUtil.setLocale(requireContext(), locale); SettingsUtil.setLocale(requireContext(), locale);
((MainActivity) requireActivity()).setLocale(locale); //((MainActivity) requireActivity()).setLocale(locale);
requireActivity().recreate(); requireActivity().recreate();
} }
@ -144,9 +145,6 @@ public class SettingsFragment extends NamedFragment {
// TODO: inform user // 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.setChecked(SettingsUtil.isScreenSecurity(requireContext()));
binding.settingsScreenSecurity.setOnCheckedChangeListener((view, checked) -> { binding.settingsScreenSecurity.setOnCheckedChangeListener((view, checked) -> {
SettingsUtil.setScreenSecurity(requireContext(), checked); SettingsUtil.setScreenSecurity(requireContext(), checked);
@ -161,6 +159,15 @@ public class SettingsFragment extends NamedFragment {
themeNames[i] = getResources().getString(Theme.values()[i].getName()); 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.setAdapter(new ArrayAdapter<>(requireContext(), android.R.layout.simple_list_item_1, themeNames));
binding.settingsTheme.setSelection(SettingsUtil.getTheme(requireContext()).ordinal()); binding.settingsTheme.setSelection(SettingsUtil.getTheme(requireContext()).ordinal());
binding.settingsTheme.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { binding.settingsTheme.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@ -177,6 +184,12 @@ public class SettingsFragment extends NamedFragment {
public void onNothingSelected(AdapterView<?> parent) {} 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]; String[] appearanceNames = new String[Appearance.values().length];
for(int i = 0; i < Appearance.values().length; i++) { for(int i = 0; i < Appearance.values().length; i++) {
appearanceNames[i] = getResources().getString(Appearance.values()[i].getName()); appearanceNames[i] = getResources().getString(Appearance.values()[i].getName());
@ -200,6 +213,7 @@ public class SettingsFragment extends NamedFragment {
binding.settingsCreateBackup.setOnClickListener(view -> { binding.settingsCreateBackup.setOnClickListener(view -> {
new StyledDialogBuilder(requireContext()) new StyledDialogBuilder(requireContext())
.setTitle(R.string.create_backup)
.setItems(R.array.backup_create, (d, which) -> { .setItems(R.array.backup_create, (d, which) -> {
switch(which) { switch(which) {
case 0: case 0:

View File

@ -156,6 +156,24 @@ public class SettingsUtil {
return ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE).getBoolean("enableIntroVideo", true); 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) { public static void setScreenSecurity(Context ctx, boolean screenSecurity) {
SharedPreferences prefs = ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE); SharedPreferences prefs = ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE);
prefs.edit().putBoolean("screenSecurity", screenSecurity).apply(); prefs.edit().putBoolean("screenSecurity", screenSecurity).apply();

View File

@ -2,6 +2,8 @@ package com.cringe_studios.cringe_authenticator.util;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray;
import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
@ -22,7 +24,17 @@ public class StyledDialogBuilder extends AlertDialog.Builder {
@Override @Override
public AlertDialog create() { public AlertDialog create() {
AlertDialog dialog = super.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; return dialog;
} }

View File

@ -15,10 +15,16 @@ public class ThemeUtil {
Theme theme = SettingsUtil.getTheme(activity); Theme theme = SettingsUtil.getTheme(activity);
activity.setTheme(theme.getStyle()); activity.setTheme(theme.getStyle());
if(SettingsUtil.isMinimalistThemeEnabled(activity)) {
activity.getTheme().applyStyle(R.style.Theme_CringeAuthenticator_Minimalist, true);
}
AppCompatDelegate.setDefaultNightMode(SettingsUtil.getAppearance(activity).getValue()); AppCompatDelegate.setDefaultNightMode(SettingsUtil.getAppearance(activity).getValue());
} }
public static void loadBackground(AppCompatActivity activity) { public static void loadBackground(AppCompatActivity activity) {
if(!SettingsUtil.isThemedBackgroundEnabled(activity)) return;
Theme theme = SettingsUtil.getTheme(activity); Theme theme = SettingsUtil.getTheme(activity);
Appearance appearance = SettingsUtil.getAppearance(activity); Appearance appearance = SettingsUtil.getAppearance(activity);

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="0dp"
android:color="#FFFFFF" />
<solid android:color="?attr/colorOnBackground" />
<corners
android:bottomLeftRadius="20dp"
android:bottomRightRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp" />
</shape>
</item>
</layer-list>

View File

@ -43,7 +43,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:background="@drawable/button_themed" android:background="?attr/buttonBackground"
android:text="@string/unlock" android:text="@string/unlock"
android:textAllCaps="false" android:textAllCaps="false"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
@ -55,7 +55,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:background="@drawable/button_themed" android:background="?attr/buttonBackground"
android:text="@string/unlock_using_biometrics" android:text="@string/unlock_using_biometrics"
android:textAllCaps="false" android:textAllCaps="false"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"

View File

@ -23,6 +23,12 @@
android:paddingTop="10dp" android:paddingTop="10dp"
android:paddingBottom="10dp" /> android:paddingBottom="10dp" />
<View
android:layout_width="match_parent"
android:background="@color/background_light_grey"
android:layout_height="1dp"
android:layout_marginVertical="10dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/settings_enable_encryption" android:id="@+id/settings_enable_encryption"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -35,12 +41,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/settings_biometric_lock" /> android:text="@string/settings_biometric_lock" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/settings_enable_intro_video"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/settings_enable_intro_video" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/settings_screen_security" android:id="@+id/settings_screen_security"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -53,6 +53,24 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/hide_codes" /> android:text="@string/hide_codes" />
<View
android:layout_width="match_parent"
android:background="@color/background_light_grey"
android:layout_height="1dp"
android:layout_marginVertical="10dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/settings_enable_intro_video"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/settings_enable_intro_video" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/settings_enable_themed_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Use themed background" />
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -65,6 +83,12 @@
android:paddingTop="10dp" android:paddingTop="10dp"
android:paddingBottom="10dp" /> android:paddingBottom="10dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/settings_enable_minimalist_theme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Use minimalist theme" />
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -77,17 +101,23 @@
android:paddingTop="10dp" android:paddingTop="10dp"
android:paddingBottom="10dp" /> android:paddingBottom="10dp" />
<View
android:layout_width="match_parent"
android:background="@color/background_light_grey"
android:layout_height="1dp"
android:layout_marginVertical="10dp" />
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Backups" /> android:text="@string/backups" />
<androidx.appcompat.widget.AppCompatButton <androidx.appcompat.widget.AppCompatButton
android:id="@+id/settings_create_backup" android:id="@+id/settings_create_backup"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/button_themed" android:background="?attr/buttonBackground"
android:text="Create backup" android:text="@string/create_backup"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:textAllCaps="false" /> android:textAllCaps="false" />
@ -95,8 +125,8 @@
android:id="@+id/settings_load_backup" android:id="@+id/settings_load_backup"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/button_themed" android:background="?attr/buttonBackground"
android:text="Load backup" android:text="@string/load_backup"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:textAllCaps="false" /> android:textAllCaps="false" />

View File

@ -13,7 +13,7 @@
android:id="@+id/button" android:id="@+id/button"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/button_themed" android:background="?attr/buttonBackground"
android:paddingTop="20dp" android:paddingTop="20dp"
android:paddingBottom="20dp" android:paddingBottom="20dp"
android:textAllCaps="false" android:textAllCaps="false"

View File

@ -16,7 +16,7 @@
android:orientation="horizontal" android:orientation="horizontal"
android:paddingTop="5dp" android:paddingTop="5dp"
android:paddingBottom="5dp" android:paddingBottom="5dp"
android:background="@drawable/button_themed"> android:background="?attr/buttonBackground">
<ImageView <ImageView
android:id="@+id/imageView5" android:id="@+id/imageView5"

View File

@ -90,4 +90,7 @@
<item>Mit neuem Passwort erstellen</item> <item>Mit neuem Passwort erstellen</item>
</string-array> </string-array>
<string name="backup_load_title">Backup laden</string> <string name="backup_load_title">Backup laden</string>
<string name="backups">Backups</string>
<string name="create_backup">Backup erstellen</string>
<string name="load_backup">Backup laden</string>
</resources> </resources>

View File

@ -2,4 +2,7 @@
<resources> <resources>
<attr name="colorTheme1" format="color" /> <attr name="colorTheme1" format="color" />
<attr name="colorTheme2" format="color" /> <attr name="colorTheme2" format="color" />
<attr name="dialogBackground" format="reference|color" />
<attr name="menuBackground" format="reference|color" />
<attr name="buttonBackground" format="reference|color" />
</resources> </resources>

View File

@ -91,4 +91,7 @@
<item>Create with new password</item> <item>Create with new password</item>
</string-array> </string-array>
<string name="backup_load_title">Load backup</string> <string name="backup_load_title">Load backup</string>
<string name="backups">Backups</string>
<string name="create_backup">Create backup</string>
<string name="load_backup">Load backup</string>
</resources> </resources>

View File

@ -11,6 +11,9 @@
<item name="android:textColor">@color/black</item> <item name="android:textColor">@color/black</item>
<item name="colorOnBackground">@color/background_light_grey</item> <item name="colorOnBackground">@color/background_light_grey</item>
<item name="actionOverflowMenuStyle">@style/ActionPopupMenuStyle</item> <item name="actionOverflowMenuStyle">@style/ActionPopupMenuStyle</item>
<item name="dialogBackground">@drawable/dialog_themed</item>
<item name="menuBackground">@drawable/menu_themed</item>
<item name="buttonBackground">@drawable/button_themed</item>
</style> </style>
<style name="Theme.CringeAuthenticator" parent="Base.Theme.CringeAuthenticator" /> <style name="Theme.CringeAuthenticator" parent="Base.Theme.CringeAuthenticator" />
@ -41,8 +44,13 @@
<item name="colorTheme1">@color/color_orange</item> <item name="colorTheme1">@color/color_orange</item>
<item name="colorTheme2">@color/color_turquoise</item> <item name="colorTheme2">@color/color_turquoise</item>
</style> </style>
<style name="Theme.CringeAuthenticator.Minimalist" parent="">
<item name="dialogBackground">?android:attr/colorBackground</item>
<item name="menuBackground">?android:attr/colorBackground</item>
<item name="buttonBackground">@drawable/button_simple</item>
</style>
<style name="ActionPopupMenuStyle" parent="Widget.AppCompat.PopupMenu"> <style name="ActionPopupMenuStyle" parent="Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">@drawable/menu_themed</item> <item name="android:popupBackground">?attr/menuBackground</item>
</style> </style>
</resources> </resources>