Cleaned up some code related to app language

* Use build constants when possible
* Inline variables
* Don't use var for normal-sized types (that way it's easier to review)
* Split code into methods
This commit is contained in:
litetex 2025-07-20 21:52:07 +02:00
parent 99003bab07
commit f48e73eb2a
No known key found for this signature in database
GPG key ID: 525B43E6039B3689
2 changed files with 42 additions and 32 deletions

View file

@ -448,8 +448,8 @@ public final class Localization {
final String appLanguageKey = context.getString(R.string.app_language_key);
final String appLanguageValue = sp.getString(appLanguageKey, null);
if (appLanguageValue != null) {
// The app language key is used on Android versions < Tiramisu; for more info, see
// ContentSettingsFragment.
// The app language key is used on Android versions < 33
// for more info, see ContentSettingsFragment
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
sp.edit().remove(appLanguageKey).apply();
}
@ -457,8 +457,8 @@ public final class Localization {
context.getString(R.string.default_localization_key);
if (!appLanguageValue.equals(appLanguageDefaultValue)) {
try {
final var locales = LocaleListCompat.forLanguageTags(appLanguageValue);
AppCompatDelegate.setApplicationLocales(locales);
AppCompatDelegate.setApplicationLocales(
LocaleListCompat.forLanguageTags(appLanguageValue));
} catch (final RuntimeException e) {
Log.e(TAG, "Failed to migrate previous custom app language "
+ "setting to public per-app language APIs"