Implement appearance setting, Remove background image for testing
This commit is contained in:
parent
1389afa353
commit
85f7140e14
@ -24,6 +24,7 @@ import com.cringe_studios.cringe_authenticator.crypto.Crypto;
|
||||
import com.cringe_studios.cringe_authenticator.crypto.CryptoException;
|
||||
import com.cringe_studios.cringe_authenticator.crypto.CryptoParameters;
|
||||
import com.cringe_studios.cringe_authenticator.databinding.FragmentSettingsBinding;
|
||||
import com.cringe_studios.cringe_authenticator.util.Appearance;
|
||||
import com.cringe_studios.cringe_authenticator.util.BiometricUtil;
|
||||
import com.cringe_studios.cringe_authenticator.util.DialogUtil;
|
||||
import com.cringe_studios.cringe_authenticator.util.FabUtil;
|
||||
@ -177,6 +178,27 @@ public class SettingsFragment extends NamedFragment {
|
||||
public void onNothingSelected(AdapterView<?> parent) {}
|
||||
});
|
||||
|
||||
String[] appearanceNames = new String[Appearance.values().length];
|
||||
for(int i = 0; i < Appearance.values().length; i++) {
|
||||
appearanceNames[i] = getResources().getString(Appearance.values()[i].getName());
|
||||
}
|
||||
|
||||
binding.settingsAppearance.setAdapter(new ArrayAdapter<>(requireContext(), android.R.layout.simple_list_item_1, appearanceNames));
|
||||
binding.settingsAppearance.setSelection(SettingsUtil.getAppearance(requireContext()).ordinal());
|
||||
binding.settingsAppearance.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
Appearance appearance = Appearance.values()[position];
|
||||
if(appearance == SettingsUtil.getAppearance(requireContext())) return;
|
||||
|
||||
SettingsUtil.setAppearance(requireContext(), appearance);
|
||||
requireActivity().recreate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {}
|
||||
});
|
||||
|
||||
FabUtil.hideFabs(requireActivity());
|
||||
|
||||
return binding.getRoot();
|
||||
|
@ -0,0 +1,35 @@
|
||||
package com.cringe_studios.cringe_authenticator.util;
|
||||
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
|
||||
import com.cringe_studios.cringe_authenticator.R;
|
||||
|
||||
public enum Appearance {
|
||||
|
||||
FOLLOW_SYSTEM(R.string.appearance_follow_system, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM),
|
||||
LIGHT(R.string.appearance_light, AppCompatDelegate.MODE_NIGHT_NO),
|
||||
DARK(R.string.appearance_dark, AppCompatDelegate.MODE_NIGHT_YES),
|
||||
;
|
||||
|
||||
@StringRes
|
||||
private int name;
|
||||
|
||||
@AppCompatDelegate.NightMode
|
||||
private int value;
|
||||
|
||||
Appearance(@StringRes int name, @AppCompatDelegate.NightMode int value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@StringRes
|
||||
public int getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@AppCompatDelegate.NightMode
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
@ -188,6 +188,20 @@ public class SettingsUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setAppearance(Context ctx, Appearance appearance) {
|
||||
SharedPreferences prefs = ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE);
|
||||
prefs.edit().putString("appearance", appearance.name()).apply();
|
||||
}
|
||||
|
||||
public static Appearance getAppearance(Context ctx) {
|
||||
String themeId = ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE).getString("appearance", Appearance.FOLLOW_SYSTEM.name());
|
||||
try {
|
||||
return Appearance.valueOf(themeId);
|
||||
}catch(IllegalArgumentException e) {
|
||||
return Appearance.FOLLOW_SYSTEM;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setLocale(Context ctx, Locale locale) {
|
||||
SharedPreferences prefs = ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE);
|
||||
prefs.edit().putString("locale", locale.getLanguage()).apply();
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.cringe_studios.cringe_authenticator.util;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
|
||||
@ -11,8 +13,7 @@ public class ThemeUtil {
|
||||
Theme theme = SettingsUtil.getTheme(activity);
|
||||
activity.setTheme(theme.getStyle());
|
||||
|
||||
// TODO: use settings
|
||||
//AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
|
||||
AppCompatDelegate.setDefaultNightMode(SettingsUtil.getAppearance(activity).getValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:background="@drawable/background_blue_green"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
|
@ -80,4 +80,7 @@
|
||||
<string name="theme_blue_yellow">Blau/Gelb</string>
|
||||
<string name="theme_green_yellow">Grün/Gelb</string>
|
||||
<string name="theme_orange_turquoise">Orange/Türkis</string>
|
||||
<string name="appearance_follow_system">System folgen</string>
|
||||
<string name="appearance_light">Hell</string>
|
||||
<string name="appearance_dark">Dunkel</string>
|
||||
</resources>
|
@ -82,4 +82,7 @@
|
||||
<string name="theme_blue_yellow">Blue/Yellow</string>
|
||||
<string name="theme_green_yellow">Green/Yellow</string>
|
||||
<string name="theme_orange_turquoise">Orange/Turquoise</string>
|
||||
<string name="appearance_dark">Dark</string>
|
||||
<string name="appearance_light">Light</string>
|
||||
<string name="appearance_follow_system">Follow system</string>
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user