1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-04-20 17:53:15 +00:00

Migrate from pre-Android 13 app language pref

This commit is contained in:
Miles Krell 2025-03-15 22:13:01 -04:00
parent 87693a2ad1
commit 3532ac96b4

View File

@ -3,11 +3,14 @@ package org.schabi.newpipe;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.app.NotificationChannelCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.os.LocaleListCompat;
import androidx.preference.PreferenceManager;
import com.jakewharton.processphoenix.ProcessPhoenix;
@ -122,6 +125,22 @@ public class App extends Application {
configureRxJavaErrorHandler();
YoutubeStreamExtractor.setPoTokenProvider(PoTokenProviderImpl.INSTANCE);
if (Build.VERSION.SDK_INT >= 33) {
final String appLanguageKey = getString(R.string.app_language_key);
if (prefs.contains(appLanguageKey)) {
// Migrate to Android per-app language settings
final String languageCode = prefs.getString(appLanguageKey, null);
prefs.edit().remove(appLanguageKey).apply();
try {
AppCompatDelegate.setApplicationLocales(
LocaleListCompat.forLanguageTags(languageCode)
);
} catch (final RuntimeException e) {
Log.e(TAG, "Error migrating to Android 13+ per-app language settings");
}
}
}
}
@Override