Upate locale setting, Update version
This commit is contained in:
parent
0307043843
commit
09a76c29fe
@ -11,8 +11,8 @@ android {
|
||||
applicationId "com.cringe_studios.code_guard"
|
||||
minSdk 21
|
||||
targetSdk 34
|
||||
versionCode 4
|
||||
versionName "1.0.0_alpha3"
|
||||
versionCode 5
|
||||
versionName "1.0.0_beta1"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.cringe_studios.code_guard.unlock.UnlockContract;
|
||||
import com.cringe_studios.code_guard.util.AppLocale;
|
||||
import com.cringe_studios.code_guard.util.SettingsUtil;
|
||||
import com.cringe_studios.code_guard.util.ThemeUtil;
|
||||
|
||||
@ -46,10 +47,9 @@ public class BaseActivity extends AppCompatActivity {
|
||||
startUnlockActivity.launch(null);
|
||||
}
|
||||
|
||||
public void setLocale(Locale locale) {
|
||||
Locale.setDefault(locale);
|
||||
public void setLocale(AppLocale locale) {
|
||||
Configuration config = new Configuration();
|
||||
config.setLocale(locale);
|
||||
config.setLocale(locale == AppLocale.SYSTEM_DEFAULT ? Locale.getDefault() : locale.getLocale());
|
||||
getResources().updateConfiguration(config, getResources().getDisplayMetrics());
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ import com.cringe_studios.code_guard.databinding.FragmentSettingsBinding;
|
||||
import com.cringe_studios.code_guard.icon.IconPack;
|
||||
import com.cringe_studios.code_guard.icon.IconPackListAdapter;
|
||||
import com.cringe_studios.code_guard.icon.IconUtil;
|
||||
import com.cringe_studios.code_guard.util.AppLocale;
|
||||
import com.cringe_studios.code_guard.util.Appearance;
|
||||
import com.cringe_studios.code_guard.util.BackupException;
|
||||
import com.cringe_studios.code_guard.util.BiometricUtil;
|
||||
@ -40,7 +41,6 @@ import com.cringe_studios.code_guard.util.Theme;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
|
||||
@ -58,19 +58,18 @@ public class SettingsFragment extends NamedFragment {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = FragmentSettingsBinding.inflate(inflater);
|
||||
|
||||
Locale[] locales = new Locale[] {Locale.ENGLISH, Locale.GERMAN};
|
||||
|
||||
String[] localeNames = new String[locales.length];
|
||||
for(int i = 0; i < locales.length; i++) {
|
||||
localeNames[i] = locales[i].getDisplayName(locales[i]);
|
||||
String[] localeNames = new String[AppLocale.values().length];
|
||||
for(int i = 0; i < localeNames.length; i++) {
|
||||
localeNames[i] = AppLocale.values()[i].getName(requireContext());
|
||||
}
|
||||
|
||||
binding.settingsLanguage.setAdapter(new ArrayAdapter<>(requireContext(), android.R.layout.simple_list_item_1, localeNames));
|
||||
binding.settingsLanguage.setSelection(Arrays.asList(locales).indexOf(SettingsUtil.getLocale(requireContext())));
|
||||
binding.settingsLanguage.setSelection(Arrays.asList(AppLocale.values()).indexOf(SettingsUtil.getLocale(requireContext())));
|
||||
binding.settingsLanguage.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
Locale locale = locales[position];
|
||||
AppLocale locale = AppLocale.values()[position];
|
||||
if(locale.equals(SettingsUtil.getLocale(requireContext()))) return;
|
||||
|
||||
SettingsUtil.setLocale(requireContext(), locale);
|
||||
|
@ -0,0 +1,41 @@
|
||||
package com.cringe_studios.code_guard.util;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import com.cringe_studios.code_guard.R;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public enum AppLocale {
|
||||
|
||||
SYSTEM_DEFAULT(R.string.locale_system_default),
|
||||
ENGLISH(Locale.ENGLISH),
|
||||
GERMAN(Locale.GERMAN),
|
||||
;
|
||||
|
||||
@StringRes
|
||||
private final int name;
|
||||
|
||||
private final Locale locale;
|
||||
|
||||
AppLocale(@StringRes int name) {
|
||||
this.name = name;
|
||||
this.locale = null;
|
||||
}
|
||||
|
||||
AppLocale(Locale locale) {
|
||||
this.name = 0;
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
public String getName(Context context) {
|
||||
return locale == null ? context.getString(name) : locale.getDisplayName(locale);
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
}
|
@ -11,7 +11,6 @@ import com.google.gson.Gson;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class SettingsUtil {
|
||||
|
||||
@ -222,13 +221,18 @@ public class SettingsUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setLocale(Context ctx, Locale locale) {
|
||||
public static void setLocale(Context ctx, AppLocale locale) {
|
||||
SharedPreferences prefs = ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE);
|
||||
prefs.edit().putString("locale", locale.getLanguage()).apply();
|
||||
prefs.edit().putString("locale", locale.name()).apply();
|
||||
}
|
||||
|
||||
public static Locale getLocale(Context ctx) {
|
||||
return new Locale(ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE).getString("locale", Locale.ENGLISH.getLanguage()));
|
||||
public static AppLocale getLocale(Context ctx) {
|
||||
String lang = ctx.getSharedPreferences(GENERAL_PREFS_NAME, Context.MODE_PRIVATE).getString("locale", AppLocale.ENGLISH.name());
|
||||
try {
|
||||
return AppLocale.valueOf(lang);
|
||||
}catch(IllegalArgumentException e) {
|
||||
return AppLocale.SYSTEM_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
public static void enableSuperSecretHamburgers(Context ctx) {
|
||||
|
@ -12,7 +12,7 @@
|
||||
android:orderInCategory="100"
|
||||
android:icon="@drawable/baseline_add_24"
|
||||
android:title="@string/action_new_group"
|
||||
app:showAsAction="ifRoom">
|
||||
app:showAsAction="always">
|
||||
<menu>
|
||||
<item
|
||||
android:id="@+id/action_otp_input"
|
||||
|
@ -166,4 +166,5 @@
|
||||
<string name="error_duplicate_otp_message">Ein OTP mit dem Namen des OTPs, das du hinzufügen willst, existiert bereits.\n\nWillst du das neue OTP umbenennen lassen, um sie voneinander zu unterscheiden?</string>
|
||||
<string name="error_duplicate_otp_title">Doppeltes OTP</string>
|
||||
<string name="biometric_encryption_unavailable">Biometrische Authentifizierung ist deaktiviert, da sie auf deinem Gerät nicht eingerichtet oder nicht verfügbar ist</string>
|
||||
<string name="locale_system_default">Systemstandard</string>
|
||||
</resources>
|
@ -85,6 +85,7 @@
|
||||
<string name="appearance_dark">Dark</string>
|
||||
<string name="appearance_light">Light</string>
|
||||
<string name="appearance_follow_system">System default</string>
|
||||
<string name="locale_system_default">System default</string>
|
||||
<string name="backup_create_title">Create backup</string>
|
||||
<string-array name="backup_create">
|
||||
<item>Create with current password</item>
|
||||
|
Loading…
Reference in New Issue
Block a user