mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-22 19:12:45 +01:00
Migrate to DayNight Theme
This commit is contained in:
parent
464d0e50b0
commit
b3e2418b93
@ -133,6 +133,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
|
||||
TLSSocketFactoryCompat.setAsDefault();
|
||||
}
|
||||
|
||||
ThemeHelper.setDayNightMode(this);
|
||||
ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this));
|
||||
|
||||
assureCorrectAppLanguage(this);
|
||||
|
@ -13,6 +13,7 @@ import androidx.preference.Preference;
|
||||
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.util.Constants;
|
||||
import org.schabi.newpipe.util.ThemeHelper;
|
||||
|
||||
public class AppearanceSettingsFragment extends BasePreferenceFragment {
|
||||
private static final boolean CAPTIONING_SETTINGS_ACCESSIBLE =
|
||||
@ -89,6 +90,8 @@ public class AppearanceSettingsFragment extends BasePreferenceFragment {
|
||||
defaultPreferences.edit().putBoolean(Constants.KEY_THEME_CHANGE, true).apply();
|
||||
defaultPreferences.edit().putString(themeKey, newValue.toString()).apply();
|
||||
|
||||
ThemeHelper.setDayNightMode(getContext(), newValue.toString());
|
||||
|
||||
if (!newValue.equals(beginningThemeKey) && getActivity() != null) {
|
||||
// if it's not the current theme
|
||||
ActivityCompat.recreate(getActivity());
|
||||
|
@ -31,6 +31,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StyleRes;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
@ -120,6 +121,7 @@ public final class ThemeHelper {
|
||||
|
||||
final String selectedThemeKey = getSelectedThemeKey(context);
|
||||
|
||||
|
||||
int baseTheme = R.style.DarkTheme; // default to dark theme
|
||||
if (selectedThemeKey.equals(lightThemeKey)) {
|
||||
baseTheme = R.style.LightTheme;
|
||||
@ -288,4 +290,21 @@ public final class ThemeHelper {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setDayNightMode(final Context context) {
|
||||
setDayNightMode(context, ThemeHelper.getSelectedThemeKey(context));
|
||||
}
|
||||
|
||||
public static void setDayNightMode(final Context context, final String selectedThemeKey) {
|
||||
final Resources res = context.getResources();
|
||||
|
||||
if (selectedThemeKey.equals(res.getString(R.string.light_theme_key))) {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
|
||||
} else if (selectedThemeKey.equals(res.getString(R.string.dark_theme_key))
|
||||
|| selectedThemeKey.equals(res.getString(R.string.black_theme_key))) {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
|
||||
} else {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,8 @@
|
||||
android:id="@+id/appbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.ActionBar">
|
||||
android:theme="@style/ThemeOverlay.AppCompat.DayNight.ActionBar"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.DayNight.ActionBar">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
|
@ -13,8 +13,8 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/appbar_padding_top"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.ActionBar">
|
||||
android:theme="@style/ThemeOverlay.AppCompat.DayNight.ActionBar"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.DayNight.ActionBar">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
|
@ -12,8 +12,8 @@
|
||||
android:id="@+id/appbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.ActionBar">
|
||||
android:theme="@style/ThemeOverlay.AppCompat.DayNight.ActionBar"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.DayNight.ActionBar">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
|
@ -12,8 +12,8 @@
|
||||
android:background="?attr/colorPrimary"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.ActionBar"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.DayNight.ActionBar"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.DayNight.ActionBar"
|
||||
app:titleTextAppearance="@style/Toolbar.Title" />
|
||||
|
||||
<WebView
|
||||
|
@ -109,8 +109,8 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:gravity="center_vertical"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.ActionBar"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.DayNight.ActionBar"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.DayNight.ActionBar"
|
||||
app:titleTextAppearance="@style/Toolbar.Title">
|
||||
|
||||
<LinearLayout
|
||||
|
@ -14,8 +14,8 @@
|
||||
android:background="?attr/colorPrimary"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.ActionBar"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.DayNight.ActionBar"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.DayNight.ActionBar"
|
||||
app:titleTextAppearance="@style/Toolbar.Title">
|
||||
|
||||
<include
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<style name="Base.V29.LightTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<style name="Base.V29.LightTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
|
||||
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||
<item name="android:enforceNavigationBarContrast">false</item>
|
||||
</style>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<resources>
|
||||
|
||||
<style name="OpeningTheme" parent="Theme.AppCompat.NoActionBar">
|
||||
<style name="OpeningTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
|
||||
<item name="colorPrimary">@android:color/transparent</item>
|
||||
<item name="colorPrimaryDark">@android:color/transparent</item>
|
||||
<item name="colorAccent">@android:color/transparent</item>
|
||||
@ -9,7 +9,7 @@
|
||||
</style>
|
||||
|
||||
<!-- Base themes -->
|
||||
<style name="Base.LightTheme" parent="Theme.AppCompat.Light.NoActionBar" />
|
||||
<style name="Base.LightTheme" parent="Theme.AppCompat.DayNight.DarkActionBar" />
|
||||
|
||||
<style name="LightTheme" parent="Base.LightTheme">
|
||||
<item name="colorPrimary">@color/light_youtube_primary_color</item>
|
||||
@ -117,7 +117,7 @@
|
||||
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
|
||||
</style>
|
||||
|
||||
<style name="Base.V7.DarkTheme" parent="Theme.AppCompat.NoActionBar" />
|
||||
<style name="Base.V7.DarkTheme" parent="Theme.AppCompat.DayNight.NoActionBar" />
|
||||
|
||||
<style name="Base.DarkTheme" parent="Base.V7.DarkTheme" />
|
||||
|
||||
@ -245,7 +245,7 @@
|
||||
</style>
|
||||
|
||||
<!-- Dialogs -->
|
||||
<style name="LightDialogTheme" parent="Theme.AppCompat.Light.Dialog">
|
||||
<style name="LightDialogTheme" parent="Theme.AppCompat.DayNight.Dialog">
|
||||
<item name="colorPrimary">@color/light_youtube_primary_color</item>
|
||||
<item name="colorPrimaryDark">@color/light_youtube_primary_color</item>
|
||||
<item name="colorAccent">@color/light_youtube_accent_color</item>
|
||||
@ -253,7 +253,7 @@
|
||||
<item name="windowBackground">@color/light_dialog_background_color</item>
|
||||
</style>
|
||||
|
||||
<style name="DarkDialogTheme" parent="Theme.AppCompat.Dialog">
|
||||
<style name="DarkDialogTheme" parent="Theme.AppCompat.DayNight.Dialog">
|
||||
<item name="colorPrimary">@color/dark_youtube_primary_color</item>
|
||||
<item name="colorPrimaryDark">@color/dark_youtube_primary_color</item>
|
||||
<item name="colorAccent">@color/dark_youtube_accent_color</item>
|
||||
@ -261,7 +261,7 @@
|
||||
<item name="windowBackground">@color/dark_dialog_background_color</item>
|
||||
</style>
|
||||
|
||||
<style name="LightDialogMinWidthTheme" parent="Theme.AppCompat.Light.Dialog.MinWidth">
|
||||
<style name="LightDialogMinWidthTheme" parent="Theme.AppCompat.DayNight.Dialog.MinWidth">
|
||||
<item name="colorPrimary">@color/light_youtube_primary_color</item>
|
||||
<item name="colorPrimaryDark">@color/light_youtube_primary_color</item>
|
||||
<item name="colorAccent">@color/light_youtube_accent_color</item>
|
||||
@ -269,7 +269,7 @@
|
||||
<item name="windowBackground">@color/light_dialog_background_color</item>
|
||||
</style>
|
||||
|
||||
<style name="DarkDialogMinWidthTheme" parent="Theme.AppCompat.Dialog.MinWidth">
|
||||
<style name="DarkDialogMinWidthTheme" parent="Theme.AppCompat.DayNight.Dialog.MinWidth">
|
||||
<item name="colorPrimary">@color/dark_youtube_primary_color</item>
|
||||
<item name="colorPrimaryDark">@color/dark_youtube_primary_color</item>
|
||||
<item name="colorAccent">@color/dark_youtube_accent_color</item>
|
||||
@ -294,7 +294,7 @@
|
||||
<item name="android:textSize">18sp</item>
|
||||
</style>
|
||||
|
||||
<style name="OldVideoPlayerTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<style name="OldVideoPlayerTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
|
||||
<item name="colorPrimary">@color/light_youtube_primary_color</item>
|
||||
<item name="colorPrimaryDark">@color/light_youtube_primary_color</item>
|
||||
<item name="colorAccent">@color/light_youtube_accent_color</item>
|
||||
|
@ -20,7 +20,7 @@
|
||||
<item name="alertDialogTheme">@style/FilePickerAlertDialogThemeLight</item>
|
||||
</style>
|
||||
|
||||
<style name="FilePickerAlertDialogThemeLight" parent="Theme.AppCompat.Dialog.Alert">
|
||||
<style name="FilePickerAlertDialogThemeLight" parent="Theme.AppCompat.DayNight.Dialog.Alert">
|
||||
<item name="colorPrimary">@color/light_youtube_primary_color</item>
|
||||
<item name="colorPrimaryDark">@color/light_youtube_dark_color</item>
|
||||
<item name="colorAccent">@color/light_settings_accent_color</item>
|
||||
@ -36,7 +36,7 @@
|
||||
<item name="alertDialogTheme">@style/FilePickerAlertDialogThemeDark</item>
|
||||
</style>
|
||||
|
||||
<style name="FilePickerAlertDialogThemeDark" parent="Theme.AppCompat.Dialog.Alert">
|
||||
<style name="FilePickerAlertDialogThemeDark" parent="Theme.AppCompat.DayNight.Dialog.Alert">
|
||||
<item name="colorPrimary">@color/dark_youtube_primary_color</item>
|
||||
<item name="colorPrimaryDark">@color/dark_youtube_dark_color</item>
|
||||
<item name="colorAccent">@color/dark_settings_accent_color</item>
|
||||
|
Loading…
Reference in New Issue
Block a user