UI changes, Add more settings
This commit is contained in:
parent
831a1a9c20
commit
eabafe0e25
@ -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<Void> 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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:
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
16
app/src/main/res/drawable/button_simple.xml
Normal file
16
app/src/main/res/drawable/button_simple.xml
Normal 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>
|
@ -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"
|
||||
|
@ -23,6 +23,12 @@
|
||||
android:paddingTop="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
|
||||
android:id="@+id/settings_enable_encryption"
|
||||
android:layout_width="match_parent"
|
||||
@ -35,12 +41,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
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
|
||||
android:id="@+id/settings_screen_security"
|
||||
android:layout_width="match_parent"
|
||||
@ -53,6 +53,24 @@
|
||||
android:layout_height="wrap_content"
|
||||
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
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@ -65,6 +83,12 @@
|
||||
android:paddingTop="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
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@ -77,17 +101,23 @@
|
||||
android:paddingTop="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
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Backups" />
|
||||
android:text="@string/backups" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/settings_create_backup"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/button_themed"
|
||||
android:text="Create backup"
|
||||
android:background="?attr/buttonBackground"
|
||||
android:text="@string/create_backup"
|
||||
android:layout_marginTop="10dp"
|
||||
android:textAllCaps="false" />
|
||||
|
||||
@ -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" />
|
||||
|
||||
|
@ -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"
|
||||
|
@ -16,7 +16,7 @@
|
||||
android:orientation="horizontal"
|
||||
android:paddingTop="5dp"
|
||||
android:paddingBottom="5dp"
|
||||
android:background="@drawable/button_themed">
|
||||
android:background="?attr/buttonBackground">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView5"
|
||||
|
@ -90,4 +90,7 @@
|
||||
<item>Mit neuem Passwort erstellen</item>
|
||||
</string-array>
|
||||
<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>
|
@ -2,4 +2,7 @@
|
||||
<resources>
|
||||
<attr name="colorTheme1" 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>
|
@ -91,4 +91,7 @@
|
||||
<item>Create with new password</item>
|
||||
</string-array>
|
||||
<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>
|
@ -11,6 +11,9 @@
|
||||
<item name="android:textColor">@color/black</item>
|
||||
<item name="colorOnBackground">@color/background_light_grey</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 name="Theme.CringeAuthenticator" parent="Base.Theme.CringeAuthenticator" />
|
||||
@ -41,8 +44,13 @@
|
||||
<item name="colorTheme1">@color/color_orange</item>
|
||||
<item name="colorTheme2">@color/color_turquoise</item>
|
||||
</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">
|
||||
<item name="android:popupBackground">@drawable/menu_themed</item>
|
||||
<item name="android:popupBackground">?attr/menuBackground</item>
|
||||
</style>
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user