parent
22b2f52f8c
commit
a85e8a29ff
|
@ -1,6 +1,5 @@
|
|||
package org.schabi.newpipe.settings;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
|
@ -19,57 +18,43 @@ public class AppearanceSettingsFragment extends BasePreferenceFragment {
|
|||
private static final boolean CAPTIONING_SETTINGS_ACCESSIBLE =
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
||||
|
||||
/**
|
||||
* Theme that was applied when the settings was opened (or recreated after a theme change).
|
||||
*/
|
||||
private String startThemeKey;
|
||||
private final Preference.OnPreferenceChangeListener themePreferenceChange
|
||||
= new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(final Preference preference, final Object newValue) {
|
||||
defaultPreferences.edit().putBoolean(Constants.KEY_THEME_CHANGE, true).apply();
|
||||
defaultPreferences.edit()
|
||||
.putString(getString(R.string.theme_key), newValue.toString()).apply();
|
||||
|
||||
if (!newValue.equals(startThemeKey) && getActivity() != null) {
|
||||
// If it's not the current theme
|
||||
ActivityCompat.recreate(requireActivity());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
private final Preference.OnPreferenceChangeListener deviceThemePreferenceChange
|
||||
= new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(final Preference preference, final Object newValue) {
|
||||
defaultPreferences.edit().putBoolean(Constants.KEY_THEME_CHANGE, true).apply();
|
||||
|
||||
final Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
activity.recreate();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
private String captionSettingsKey;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
final String themeKey = getString(R.string.theme_key);
|
||||
startThemeKey = defaultPreferences
|
||||
.getString(themeKey, getString(R.string.default_theme_value));
|
||||
findPreference(themeKey).setOnPreferenceChangeListener(themePreferenceChange);
|
||||
|
||||
findPreference(getString(R.string.use_device_theme_key))
|
||||
.setOnPreferenceChangeListener(deviceThemePreferenceChange);
|
||||
final String themeKey = getString(R.string.theme_key);
|
||||
// the key of the active theme when settings were opened (or recreated after theme change)
|
||||
final String startThemeKey = defaultPreferences
|
||||
.getString(themeKey, getString(R.string.default_theme_value));
|
||||
final String autoDeviceThemeKey = getString(R.string.auto_device_theme_key);
|
||||
findPreference(themeKey).setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
if (newValue.toString().equals(autoDeviceThemeKey)) {
|
||||
Toast.makeText(getContext(), getString(R.string.select_night_theme_toast),
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
applyThemeChange(startThemeKey, themeKey, newValue);
|
||||
return false;
|
||||
});
|
||||
|
||||
final String nightThemeKey = getString(R.string.night_theme_key);
|
||||
if (startThemeKey.equals(autoDeviceThemeKey)) {
|
||||
final String startNightThemeKey = defaultPreferences
|
||||
.getString(nightThemeKey, getString(R.string.default_night_theme_value));
|
||||
|
||||
findPreference(nightThemeKey).setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
applyThemeChange(startNightThemeKey, nightThemeKey, newValue);
|
||||
return false;
|
||||
});
|
||||
} else {
|
||||
removePreference(nightThemeKey);
|
||||
}
|
||||
|
||||
captionSettingsKey = getString(R.string.caption_settings_key);
|
||||
if (!CAPTIONING_SETTINGS_ACCESSIBLE) {
|
||||
final Preference captionSettings = findPreference(captionSettingsKey);
|
||||
getPreferenceScreen().removePreference(captionSettings);
|
||||
removePreference(captionSettingsKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,4 +75,23 @@ public class AppearanceSettingsFragment extends BasePreferenceFragment {
|
|||
|
||||
return super.onPreferenceTreeClick(preference);
|
||||
}
|
||||
|
||||
private void removePreference(final String preferenceKey) {
|
||||
final Preference preference = findPreference(preferenceKey);
|
||||
if (preference != null) {
|
||||
getPreferenceScreen().removePreference(preference);
|
||||
}
|
||||
}
|
||||
|
||||
private void applyThemeChange(final String beginningThemeKey,
|
||||
final String themeKey,
|
||||
final Object newValue) {
|
||||
defaultPreferences.edit().putBoolean(Constants.KEY_THEME_CHANGE, true).apply();
|
||||
defaultPreferences.edit().putString(themeKey, newValue.toString()).apply();
|
||||
|
||||
if (!newValue.equals(beginningThemeKey) && getActivity() != null) {
|
||||
// if it's not the current theme
|
||||
ActivityCompat.recreate(getActivity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,8 @@ public final class ThemeHelper {
|
|||
final Resources res = context.getResources();
|
||||
|
||||
return selectedThemeString.equals(res.getString(R.string.light_theme_key))
|
||||
|| (shouldFollowDeviceTheme(context) && !isDeviceDarkThemeEnabled(context));
|
||||
|| (selectedThemeString.equals(res.getString(R.string.auto_device_theme_key))
|
||||
&& !isDeviceDarkThemeEnabled(context));
|
||||
}
|
||||
|
||||
|
||||
|
@ -140,6 +141,7 @@ public final class ThemeHelper {
|
|||
final String lightTheme = res.getString(R.string.light_theme_key);
|
||||
final String darkTheme = res.getString(R.string.dark_theme_key);
|
||||
final String blackTheme = res.getString(R.string.black_theme_key);
|
||||
final String automaticDeviceTheme = res.getString(R.string.auto_device_theme_key);
|
||||
|
||||
final String selectedTheme = getSelectedThemeString(context);
|
||||
|
||||
|
@ -147,11 +149,20 @@ public final class ThemeHelper {
|
|||
if (selectedTheme.equals(lightTheme)) {
|
||||
defaultTheme = R.style.LightTheme;
|
||||
} else if (selectedTheme.equals(blackTheme)) {
|
||||
defaultTheme = shouldFollowDeviceTheme(context) && !isDeviceDarkThemeEnabled(context)
|
||||
? R.style.LightTheme : R.style.BlackTheme;
|
||||
} else if (selectedTheme.equals(darkTheme)) {
|
||||
defaultTheme = shouldFollowDeviceTheme(context) && !isDeviceDarkThemeEnabled(context)
|
||||
? R.style.LightTheme : R.style.DarkTheme;
|
||||
defaultTheme = R.style.BlackTheme;
|
||||
} else if (selectedTheme.equals(automaticDeviceTheme)) {
|
||||
|
||||
if (isDeviceDarkThemeEnabled(context)) {
|
||||
final String selectedNightTheme = getSelectedNightThemeString(context);
|
||||
if (selectedNightTheme.equals(blackTheme)) {
|
||||
defaultTheme = R.style.BlackTheme;
|
||||
} else {
|
||||
defaultTheme = R.style.DarkTheme;
|
||||
}
|
||||
} else {
|
||||
// there is only one day theme
|
||||
defaultTheme = R.style.LightTheme;
|
||||
}
|
||||
}
|
||||
|
||||
if (serviceId <= -1) {
|
||||
|
@ -190,17 +201,29 @@ public final class ThemeHelper {
|
|||
final String lightTheme = res.getString(R.string.light_theme_key);
|
||||
final String darkTheme = res.getString(R.string.dark_theme_key);
|
||||
final String blackTheme = res.getString(R.string.black_theme_key);
|
||||
final String automaticDeviceTheme = res.getString(R.string.auto_device_theme_key);
|
||||
|
||||
|
||||
final String selectedTheme = getSelectedThemeString(context);
|
||||
|
||||
if (selectedTheme.equals(lightTheme)) {
|
||||
return R.style.LightSettingsTheme;
|
||||
} else if (selectedTheme.equals(blackTheme)) {
|
||||
return shouldFollowDeviceTheme(context) && !isDeviceDarkThemeEnabled(context)
|
||||
? R.style.LightSettingsTheme : R.style.BlackSettingsTheme;
|
||||
return R.style.BlackSettingsTheme;
|
||||
} else if (selectedTheme.equals(darkTheme)) {
|
||||
return shouldFollowDeviceTheme(context) && !isDeviceDarkThemeEnabled(context)
|
||||
? R.style.LightSettingsTheme : R.style.DarkSettingsTheme;
|
||||
return R.style.DarkSettingsTheme;
|
||||
} else if (selectedTheme.equals(automaticDeviceTheme)) {
|
||||
if (isDeviceDarkThemeEnabled(context)) {
|
||||
final String selectedNightTheme = getSelectedNightThemeString(context);
|
||||
if (selectedNightTheme.equals(blackTheme)) {
|
||||
return R.style.BlackSettingsTheme;
|
||||
} else {
|
||||
return R.style.DarkSettingsTheme;
|
||||
}
|
||||
} else {
|
||||
// there is only one day theme
|
||||
return R.style.LightSettingsTheme;
|
||||
}
|
||||
} else {
|
||||
// Fallback
|
||||
return R.style.DarkSettingsTheme;
|
||||
|
@ -246,6 +269,14 @@ public final class ThemeHelper {
|
|||
.getString(themeKey, defaultTheme);
|
||||
}
|
||||
|
||||
private static String getSelectedNightThemeString(final Context context) {
|
||||
final String nightThemeKey = context.getString(R.string.night_theme_key);
|
||||
final String defaultNightTheme = context.getResources()
|
||||
.getString(R.string.default_night_theme_value);
|
||||
return PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getString(nightThemeKey, defaultNightTheme);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the title to the activity, if the activity is an {@link AppCompatActivity} and has an
|
||||
* action bar.
|
||||
|
@ -286,15 +317,4 @@ public final class ThemeHelper {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells if the user wants the theme to follow the device theme.
|
||||
*
|
||||
* @param context the context to use
|
||||
* @return whether the user wants the theme to follow the device's theme
|
||||
*/
|
||||
public static boolean shouldFollowDeviceTheme(final Context context) {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getBoolean(context.getString(R.string.use_device_theme_key), false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -579,6 +579,4 @@
|
|||
<string name="artists">Artistoj</string>
|
||||
<string name="albums">Albumoj</string>
|
||||
<string name="songs">Kantoj</string>
|
||||
<string name="follow_device_theme_title">Sekvi la etoson de la aparato</string>
|
||||
<string name="follow_device_theme_summary">La apo sekvos la etoson de la aparato. Ĝi povus malfunkcii se via Android versiono malsupras Android 10.</string>
|
||||
</resources>
|
|
@ -41,6 +41,7 @@
|
|||
<string name="use_tor_title">Utiliser Tor</string>
|
||||
<string name="use_tor_summary">(Expérimental) Forcer la redirection du trafic de téléchargement via Tor pour plus de confidentialité (les flux vidéos ne sont pas encore pris en charge).</string>
|
||||
<string name="theme_title">Thème</string>
|
||||
<string name="night_theme_title">Thème nuit</string>
|
||||
<string name="dark_theme_title">Sombre</string>
|
||||
<string name="light_theme_title">Clair</string>
|
||||
<string name="black_theme_title">Noir</string>
|
||||
|
@ -669,6 +670,7 @@
|
|||
<string name="paid_content">Ce contenu n\'est disponible que pour les abonnés, il ne peut donc pas être diffusé en continu ni téléchargé par NewPipe.</string>
|
||||
<string name="youtube_music_premium_content">Cette vidéo n\'est disponible que pour les membres de YouTube Music Premium, elle ne peut donc pas être diffusée en continu ni téléchargée par NewPipe.</string>
|
||||
<string name="private_content">Ce contenu est privé, il ne peut donc pas être diffusé en continu ni téléchargé par NewPipe.</string>
|
||||
<string name="follow_device_theme_title">Suivre le thème de l\'appareil</string>
|
||||
<string name="follow_device_theme_summary">L\'application suivera le thème de votre appareil. Il se peut que ça ne marche pas si vous utiliser une version d\'Android inférieure à 10.</string>
|
||||
<string name="auto_device_theme_title">Automatique (thème de l\'appareil)</string>
|
||||
<string name="night_theme_summary">Choisissez votre thème nuit favori — %s</string>
|
||||
<string name="select_night_theme_toast">Vous pouvez chosir votre thème nuit favori</string>
|
||||
</resources>
|
|
@ -176,21 +176,33 @@
|
|||
|
||||
<!-- THEMES -->
|
||||
<string name="theme_key" translatable="false">theme</string>
|
||||
<string name="night_theme_key" translatable="false">night_theme</string>
|
||||
<string name="light_theme_key" translatable="false">light_theme</string>
|
||||
<string name="dark_theme_key" translatable="false">dark_theme</string>
|
||||
<string name="black_theme_key" translatable="false">black_theme</string>
|
||||
<string name="auto_device_theme_key" translatable="false">auto_device_theme</string>
|
||||
<string name="default_theme_value" translatable="false">@string/dark_theme_key</string>
|
||||
<string name="default_night_theme_value" translatable="false">@string/dark_theme_key</string>
|
||||
<string-array name="theme_values_list" translatable="false">
|
||||
<item>@string/light_theme_key</item>
|
||||
<item>@string/dark_theme_key</item>
|
||||
<item>@string/black_theme_key</item>
|
||||
<item>@string/auto_device_theme_key</item>
|
||||
</string-array>
|
||||
<string-array name="theme_description_list" translatable="false">
|
||||
<item>@string/light_theme_title</item>
|
||||
<item>@string/dark_theme_title</item>
|
||||
<item>@string/black_theme_title</item>
|
||||
<item>@string/auto_device_theme_title</item>
|
||||
</string-array>
|
||||
<string-array name="night_theme_values_list" translatable="false">
|
||||
<item>@string/dark_theme_key</item>
|
||||
<item>@string/black_theme_key</item>
|
||||
</string-array>
|
||||
<string-array name="night_theme_description_list" translatable="false">
|
||||
<item>@string/dark_theme_title</item>
|
||||
<item>@string/black_theme_title</item>
|
||||
</string-array>
|
||||
<string name="use_device_theme_key" translatable="false">use_device_theme_key</string>
|
||||
|
||||
<!-- Caption Size -->
|
||||
<string name="caption_settings_key" translatable="false">caption_settings_key</string>
|
||||
|
|
|
@ -79,11 +79,10 @@
|
|||
<string name="default_audio_format_title">Default audio format</string>
|
||||
<string name="default_video_format_title">Default video format</string>
|
||||
<string name="theme_title">Theme</string>
|
||||
<string name="night_theme_title">Night Theme</string>
|
||||
<string name="light_theme_title">Light</string>
|
||||
<string name="dark_theme_title">Dark</string>
|
||||
<string name="black_theme_title">Black</string>
|
||||
<string name="device_dark_theme_title">Device theme (Dark)</string>
|
||||
<string name="device_black_theme_title">Device theme (Black)</string>
|
||||
<string name="popup_remember_size_pos_title">Remember popup properties</string>
|
||||
<string name="popup_remember_size_pos_summary">Remember last size and position of popup</string>
|
||||
<string name="use_inexact_seek_title">Use fast inexact seek</string>
|
||||
|
@ -711,6 +710,7 @@
|
|||
<string name="paid_content">This content is only available to users who have paid, so it cannot be streamed or downloaded by NewPipe.</string>
|
||||
<string name="featured">Featured</string>
|
||||
<string name="radio">Radio</string>
|
||||
<string name="follow_device_theme_title">Follow device theme</string>
|
||||
<string name="follow_device_theme_summary">The app theme will follow your device theme. It may not work for devices below Android 10.</string>
|
||||
<string name="auto_device_theme_title">Automatic (device theme)</string>
|
||||
<string name="night_theme_summary">Select your favorite night theme — %s</string>
|
||||
<string name="select_night_theme_toast">You can select your favorite night theme below</string>
|
||||
</resources>
|
||||
|
|
|
@ -12,11 +12,13 @@
|
|||
android:title="@string/theme_title"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:key="@string/use_device_theme_key"
|
||||
android:summary="@string/follow_device_theme_summary"
|
||||
android:title="@string/follow_device_theme_title"
|
||||
<ListPreference
|
||||
android:defaultValue="@string/default_night_theme_value"
|
||||
android:entries="@array/night_theme_description_list"
|
||||
android:entryValues="@array/night_theme_values_list"
|
||||
android:key="@string/night_theme_key"
|
||||
android:summary="@string/night_theme_summary"
|
||||
android:title="@string/night_theme_title"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
|
|
Loading…
Reference in New Issue