Skip to content

Commit 980a35a

Browse files
committed
Move migration to separate method
1 parent da106e2 commit 980a35a

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

  • app/src/main/java/org/schabi/newpipe

app/src/main/java/org/schabi/newpipe/App.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,24 @@ public void onCreate() {
127127
YoutubeStreamExtractor.setPoTokenProvider(PoTokenProviderImpl.INSTANCE);
128128

129129
if (Build.VERSION.SDK_INT >= 33) {
130-
final String appLanguageDefaultValue = getString(R.string.default_localization_key);
131-
final String appLanguageKey = getString(R.string.app_language_key);
132-
final String appLanguageCurrentValue = prefs.getString(appLanguageKey, null);
133-
if (appLanguageCurrentValue != null) {
134-
// Migrate to Android per-app language settings
135-
prefs.edit().remove(appLanguageKey).apply();
136-
if (!appLanguageCurrentValue.equals(appLanguageDefaultValue)) {
137-
try {
138-
AppCompatDelegate.setApplicationLocales(
139-
LocaleListCompat.forLanguageTags(appLanguageCurrentValue)
140-
);
141-
} catch (final RuntimeException e) {
142-
Log.e(TAG, "Error migrating to Android 13+ per-app language settings");
143-
}
130+
ensureAppLanguagePreferenceIsMigrated(prefs);
131+
}
132+
}
133+
134+
private void ensureAppLanguagePreferenceIsMigrated(final SharedPreferences prefs) {
135+
final String appLanguageDefaultValue = getString(R.string.default_localization_key);
136+
final String appLanguageKey = getString(R.string.app_language_key);
137+
final String appLanguageCurrentValue = prefs.getString(appLanguageKey, null);
138+
if (appLanguageCurrentValue != null) {
139+
// Migrate to Android per-app language settings
140+
prefs.edit().remove(appLanguageKey).apply();
141+
if (!appLanguageCurrentValue.equals(appLanguageDefaultValue)) {
142+
try {
143+
AppCompatDelegate.setApplicationLocales(
144+
LocaleListCompat.forLanguageTags(appLanguageCurrentValue)
145+
);
146+
} catch (final RuntimeException e) {
147+
Log.e(TAG, "Error migrating to Android 13+ per-app language settings");
144148
}
145149
}
146150
}

0 commit comments

Comments
 (0)