11package org .schabi .newpipe .settings ;
22
33import android .content .Context ;
4+ import android .content .Intent ;
5+ import android .net .Uri ;
6+ import android .os .Build ;
47import android .os .Bundle ;
8+ import android .provider .Settings ;
59import android .util .Log ;
610import android .widget .Toast ;
711
12+ import androidx .appcompat .app .AppCompatDelegate ;
813import androidx .preference .Preference ;
914
1015import org .schabi .newpipe .DownloaderImpl ;
1520import org .schabi .newpipe .util .image .ImageStrategy ;
1621import org .schabi .newpipe .util .image .PreferredImageQuality ;
1722
23+ import java .util .Locale ;
24+
1825import coil3 .SingletonImageLoader ;
1926
2027public class ContentSettingsFragment extends BasePreferenceFragment {
2128 private String youtubeRestrictedModeEnabledKey ;
2229
23- private Localization initialSelectedLocalization ;
24- private ContentCountry initialSelectedContentCountry ;
2530 private String initialLanguage ;
2631
2732 @ Override
@@ -30,12 +35,28 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
3035
3136 addPreferencesFromResourceRegistry ();
3237
33- initialSelectedLocalization = org .schabi .newpipe .util .Localization
34- .getPreferredLocalization (requireContext ());
35- initialSelectedContentCountry = org .schabi .newpipe .util .Localization
36- .getPreferredContentCountry (requireContext ());
3738 initialLanguage = defaultPreferences .getString (getString (R .string .app_language_key ), "en" );
3839
40+ if (Build .VERSION .SDK_INT >= 33 ) {
41+ requirePreference (R .string .app_language_key ).setVisible (false );
42+ final Preference newAppLanguagePref =
43+ requirePreference (R .string .app_language_android_13_and_up_key );
44+ newAppLanguagePref .setSummaryProvider (preference -> {
45+ final Locale customLocale = AppCompatDelegate .getApplicationLocales ().get (0 );
46+ if (customLocale != null ) {
47+ return customLocale .getDisplayName ();
48+ }
49+ return getString (R .string .systems_language );
50+ });
51+ newAppLanguagePref .setOnPreferenceClickListener (preference -> {
52+ final Intent intent = new Intent (Settings .ACTION_APP_LOCALE_SETTINGS )
53+ .setData (Uri .fromParts ("package" , requireContext ().getPackageName (), null ));
54+ startActivity (intent );
55+ return true ;
56+ });
57+ newAppLanguagePref .setVisible (true );
58+ }
59+
3960 final Preference imageQualityPreference = requirePreference (R .string .image_quality_key );
4061 imageQualityPreference .setOnPreferenceChangeListener (
4162 (preference , newValue ) -> {
@@ -70,19 +91,21 @@ public boolean onPreferenceTreeClick(final Preference preference) {
7091 public void onDestroy () {
7192 super .onDestroy ();
7293
73- final Localization selectedLocalization = org .schabi .newpipe .util .Localization
74- .getPreferredLocalization (requireContext ());
75- final ContentCountry selectedContentCountry = org .schabi .newpipe .util .Localization
76- .getPreferredContentCountry (requireContext ());
7794 final String selectedLanguage =
7895 defaultPreferences .getString (getString (R .string .app_language_key ), "en" );
7996
80- if (!selectedLocalization .equals (initialSelectedLocalization )
81- || !selectedContentCountry .equals (initialSelectedContentCountry )
82- || !selectedLanguage .equals (initialLanguage )) {
83- Toast .makeText (requireContext (), R .string .localization_changes_requires_app_restart ,
84- Toast .LENGTH_LONG ).show ();
85-
97+ if (!selectedLanguage .equals (initialLanguage )) {
98+ if (Build .VERSION .SDK_INT < 33 ) {
99+ Toast .makeText (
100+ requireContext (),
101+ R .string .localization_changes_requires_app_restart ,
102+ Toast .LENGTH_LONG
103+ ).show ();
104+ }
105+ final Localization selectedLocalization = org .schabi .newpipe .util .Localization
106+ .getPreferredLocalization (requireContext ());
107+ final ContentCountry selectedContentCountry = org .schabi .newpipe .util .Localization
108+ .getPreferredContentCountry (requireContext ());
86109 NewPipe .setupLocalization (selectedLocalization , selectedContentCountry );
87110 }
88111 }
0 commit comments