|
3 | 3 | import android.app.Application; |
4 | 4 | import android.content.Context; |
5 | 5 | import android.content.SharedPreferences; |
| 6 | +import android.os.Build; |
6 | 7 | import android.util.Log; |
7 | 8 |
|
8 | 9 | import androidx.annotation.NonNull; |
| 10 | +import androidx.appcompat.app.AppCompatDelegate; |
9 | 11 | import androidx.core.app.NotificationChannelCompat; |
10 | 12 | import androidx.core.app.NotificationManagerCompat; |
| 13 | +import androidx.core.os.LocaleListCompat; |
11 | 14 | import androidx.preference.PreferenceManager; |
12 | 15 |
|
13 | 16 | import com.jakewharton.processphoenix.ProcessPhoenix; |
@@ -122,6 +125,22 @@ public void onCreate() { |
122 | 125 | configureRxJavaErrorHandler(); |
123 | 126 |
|
124 | 127 | YoutubeStreamExtractor.setPoTokenProvider(PoTokenProviderImpl.INSTANCE); |
| 128 | + |
| 129 | + if (Build.VERSION.SDK_INT >= 33) { |
| 130 | + final String appLanguageKey = getString(R.string.app_language_key); |
| 131 | + if (prefs.contains(appLanguageKey)) { |
| 132 | + // Migrate to Android per-app language settings |
| 133 | + final String languageCode = prefs.getString(appLanguageKey, null); |
| 134 | + prefs.edit().remove(appLanguageKey).apply(); |
| 135 | + try { |
| 136 | + AppCompatDelegate.setApplicationLocales( |
| 137 | + LocaleListCompat.forLanguageTags(languageCode) |
| 138 | + ); |
| 139 | + } catch (final RuntimeException e) { |
| 140 | + Log.e(TAG, "Error migrating to Android 13+ per-app language settings"); |
| 141 | + } |
| 142 | + } |
| 143 | + } |
125 | 144 | } |
126 | 145 |
|
127 | 146 | @Override |
|
0 commit comments