mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-04-20 17:53:15 +00:00
Redirect to per-app language settings on Android 13+
This commit is contained in:
parent
b888dc72cf
commit
87693a2ad1
@ -1,10 +1,15 @@
|
||||
package org.schabi.newpipe.settings;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import org.schabi.newpipe.DownloaderImpl;
|
||||
@ -17,6 +22,7 @@ import org.schabi.newpipe.util.image.PicassoHelper;
|
||||
import org.schabi.newpipe.util.image.PreferredImageQuality;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||
private String youtubeRestrictedModeEnabledKey;
|
||||
@ -37,6 +43,26 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||
.getPreferredContentCountry(requireContext());
|
||||
initialLanguage = defaultPreferences.getString(getString(R.string.app_language_key), "en");
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 33) {
|
||||
requirePreference(R.string.app_language_key).setVisible(false);
|
||||
final Preference newAppLanguagePref =
|
||||
requirePreference(R.string.app_language_android_13_and_up_key);
|
||||
newAppLanguagePref.setSummaryProvider(preference -> {
|
||||
final Locale customLocale = AppCompatDelegate.getApplicationLocales().get(0);
|
||||
if (customLocale != null) {
|
||||
return customLocale.getDisplayName();
|
||||
}
|
||||
return getString(R.string.systems_language);
|
||||
});
|
||||
newAppLanguagePref.setOnPreferenceClickListener(preference -> {
|
||||
final Intent intent = new Intent(Settings.ACTION_APP_LOCALE_SETTINGS)
|
||||
.setData(Uri.fromParts("package", requireContext().getPackageName(), null));
|
||||
startActivity(intent);
|
||||
return true;
|
||||
});
|
||||
newAppLanguagePref.setVisible(true);
|
||||
}
|
||||
|
||||
final Preference imageQualityPreference = requirePreference(R.string.image_quality_key);
|
||||
imageQualityPreference.setOnPreferenceChangeListener(
|
||||
(preference, newValue) -> {
|
||||
|
@ -17,6 +17,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.PluralsRes;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.core.math.MathUtils;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
@ -39,6 +40,7 @@ import java.time.format.FormatStyle;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@ -101,6 +103,10 @@ public final class Localization {
|
||||
}
|
||||
|
||||
public static Locale getAppLocale(@NonNull final Context context) {
|
||||
if (Build.VERSION.SDK_INT >= 33) {
|
||||
final Locale customLocale = AppCompatDelegate.getApplicationLocales().get(0);
|
||||
return Objects.requireNonNullElseGet(customLocale, Locale::getDefault);
|
||||
}
|
||||
return getLocaleFromPrefs(context, R.string.app_language_key);
|
||||
}
|
||||
|
||||
|
@ -353,6 +353,7 @@
|
||||
<string name="playback_skip_silence_key">playback_skip_silence_key</string>
|
||||
|
||||
<string name="app_language_key">app_language_key</string>
|
||||
<string name="app_language_android_13_and_up_key">app_language_android_13_and_up_key</string>
|
||||
|
||||
<string name="feed_update_threshold_key">feed_update_threshold_key</string>
|
||||
<string name="feed_update_threshold_default_value">300</string>
|
||||
|
@ -13,6 +13,13 @@
|
||||
app:iconSpaceReserved="false"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
<Preference
|
||||
android:key="@string/app_language_android_13_and_up_key"
|
||||
android:title="@string/app_language_title"
|
||||
app:isPreferenceVisible="false"
|
||||
app:singleLineTitle="false"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="@string/default_localization_key"
|
||||
android:entries="@array/language_names"
|
||||
|
Loading…
x
Reference in New Issue
Block a user