Merge pull request #787 from Bnyro/master

introduce pure theme
This commit is contained in:
Bnyro 2022-07-14 22:33:11 +02:00 committed by GitHub
commit 929899ec08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 95 additions and 30 deletions

View File

@ -3,7 +3,7 @@ package com.github.libretube.preferences
import android.os.Bundle import android.os.Bundle
import androidx.preference.ListPreference import androidx.preference.ListPreference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference import androidx.preference.SwitchPreferenceCompat
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.activities.SettingsActivity import com.github.libretube.activities.SettingsActivity
import com.github.libretube.dialogs.RequireRestartDialog import com.github.libretube.dialogs.RequireRestartDialog
@ -25,6 +25,13 @@ class AppearanceSettings : PreferenceFragmentCompat() {
true true
} }
val pureTheme = findPreference<SwitchPreferenceCompat>("pure_theme")
pureTheme?.setOnPreferenceChangeListener { _, _ ->
val restartDialog = RequireRestartDialog()
restartDialog.show(childFragmentManager, "RequireRestartDialog")
true
}
val accentColor = findPreference<ListPreference>("accent_color") val accentColor = findPreference<ListPreference>("accent_color")
updateAccentColorValues(accentColor!!) updateAccentColorValues(accentColor!!)
accentColor.setOnPreferenceChangeListener { _, _ -> accentColor.setOnPreferenceChangeListener { _, _ ->
@ -46,7 +53,7 @@ class AppearanceSettings : PreferenceFragmentCompat() {
true true
} }
val hideTrending = findPreference<SwitchPreference>("hide_trending_page") val hideTrending = findPreference<SwitchPreferenceCompat>("hide_trending_page")
hideTrending?.setOnPreferenceChangeListener { _, _ -> hideTrending?.setOnPreferenceChangeListener { _, _ ->
val restartDialog = RequireRestartDialog() val restartDialog = RequireRestartDialog()
restartDialog.show(childFragmentManager, "RequireRestartDialog") restartDialog.show(childFragmentManager, "RequireRestartDialog")

View File

@ -18,7 +18,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.preference.ListPreference import androidx.preference.ListPreference
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference import androidx.preference.SwitchPreferenceCompat
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.activities.SettingsActivity import com.github.libretube.activities.SettingsActivity
import com.github.libretube.dialogs.CustomInstanceDialog import com.github.libretube.dialogs.CustomInstanceDialog
@ -146,7 +146,7 @@ class InstanceSettings : PreferenceFragmentCompat() {
true true
} }
val authInstanceToggle = findPreference<SwitchPreference>("auth_instance_toggle") val authInstanceToggle = findPreference<SwitchPreferenceCompat>("auth_instance_toggle")
authInstanceToggle?.setOnPreferenceChangeListener { _, newValue -> authInstanceToggle?.setOnPreferenceChangeListener { _, newValue ->
authInstance.isVisible = newValue == true authInstance.isVisible = newValue == true
logout() logout()

View File

@ -18,15 +18,15 @@ object ThemeHelper {
fun updateTheme(activity: AppCompatActivity) { fun updateTheme(activity: AppCompatActivity) {
val themeMode = PreferenceHelper.getString(activity, "theme_toggle", "A")!! val themeMode = PreferenceHelper.getString(activity, "theme_toggle", "A")!!
val blackModeEnabled = themeMode == "O" val pureThemeEnabled = PreferenceHelper.getBoolean(activity, "pure_theme", false)
updateAccentColor(activity, blackModeEnabled) updateAccentColor(activity, pureThemeEnabled)
updateThemeMode(themeMode) updateThemeMode(themeMode)
} }
private fun updateAccentColor( private fun updateAccentColor(
activity: AppCompatActivity, activity: AppCompatActivity,
blackThemeEnabled: Boolean pureThemeEnabled: Boolean
) { ) {
val theme = when ( val theme = when (
PreferenceHelper.getString( PreferenceHelper.getString(
@ -37,15 +37,16 @@ object ThemeHelper {
) { ) {
"my" -> { "my" -> {
applyDynamicColors(activity) applyDynamicColors(activity)
if (blackThemeEnabled) R.style.MaterialYou_Black if (pureThemeEnabled) R.style.MaterialYou_Pure
else R.style.MaterialYou else R.style.MaterialYou
} }
"red" -> if (blackThemeEnabled) R.style.Theme_Red_Black else R.style.Theme_Red // set the theme, use the pure theme if enabled
"blue" -> if (blackThemeEnabled) R.style.Theme_Blue_Black else R.style.Theme_Blue "red" -> if (pureThemeEnabled) R.style.Theme_Red_Pure else R.style.Theme_Red
"yellow" -> if (blackThemeEnabled) R.style.Theme_Yellow_Black else R.style.Theme_Yellow "blue" -> if (pureThemeEnabled) R.style.Theme_Blue_Pure else R.style.Theme_Blue
"green" -> if (blackThemeEnabled) R.style.Theme_Green_Black else R.style.Theme_Green "yellow" -> if (pureThemeEnabled) R.style.Theme_Yellow_Pure else R.style.Theme_Yellow
"purple" -> if (blackThemeEnabled) R.style.Theme_Purple_Black else R.style.Theme_Purple "green" -> if (pureThemeEnabled) R.style.Theme_Green_Pure else R.style.Theme_Green
else -> if (blackThemeEnabled) R.style.Theme_Purple_Black else R.style.Theme_Purple "purple" -> if (pureThemeEnabled) R.style.Theme_Purple_Pure else R.style.Theme_Purple
else -> if (pureThemeEnabled) R.style.Theme_Purple_Pure else R.style.Theme_Purple
} }
activity.setTheme(theme) activity.setTheme(theme)
} }
@ -62,7 +63,6 @@ object ThemeHelper {
"A" -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM "A" -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
"L" -> AppCompatDelegate.MODE_NIGHT_NO "L" -> AppCompatDelegate.MODE_NIGHT_NO
"D" -> AppCompatDelegate.MODE_NIGHT_YES "D" -> AppCompatDelegate.MODE_NIGHT_YES
"O" -> AppCompatDelegate.MODE_NIGHT_YES
else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
} }
AppCompatDelegate.setDefaultNightMode(mode) AppCompatDelegate.setDefaultNightMode(mode)

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?android:attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M12,4.81L12,19c-3.31,0 -6,-2.63 -6,-5.87c0,-1.56 0.62,-3.03 1.75,-4.14L12,4.81M6.35,7.56L6.35,7.56C4.9,8.99 4,10.96 4,13.13C4,17.48 7.58,21 12,21c4.42,0 8,-3.52 8,-7.87c0,-2.17 -0.9,-4.14 -2.35,-5.57l0,0L12,2L6.35,7.56z"
android:fillColor="#000000"/>
</vector>

View File

@ -8,7 +8,7 @@
</style> </style>
<style name="MaterialYou.Black" parent="MaterialYou"> <style name="MaterialYou.Pure" parent="MaterialYou">
<item name="android:colorBackground">@android:color/black</item> <item name="android:colorBackground">@android:color/black</item>
<item name="colorSurface">@android:color/black</item> <item name="colorSurface">@android:color/black</item>
@ -33,7 +33,7 @@
</style> </style>
<style name="Theme.Red.Black" parent="Theme.Red"> <style name="Theme.Red.Pure" parent="Theme.Red">
<item name="android:colorBackground">@android:color/black</item> <item name="android:colorBackground">@android:color/black</item>
<item name="colorSurface">@android:color/black</item> <item name="colorSurface">@android:color/black</item>
@ -58,7 +58,7 @@
</style> </style>
<style name="Theme.Blue.Black" parent="Theme.Blue"> <style name="Theme.Blue.Pure" parent="Theme.Blue">
<item name="android:colorBackground">@android:color/black</item> <item name="android:colorBackground">@android:color/black</item>
<item name="colorSurface">@android:color/black</item> <item name="colorSurface">@android:color/black</item>
@ -83,7 +83,7 @@
</style> </style>
<style name="Theme.Yellow.Black" parent="Theme.Yellow"> <style name="Theme.Yellow.Pure" parent="Theme.Yellow">
<item name="android:colorBackground">@android:color/black</item> <item name="android:colorBackground">@android:color/black</item>
<item name="colorSurface">@android:color/black</item> <item name="colorSurface">@android:color/black</item>
@ -108,7 +108,7 @@
</style> </style>
<style name="Theme.Green.Black" parent="Theme.Green"> <style name="Theme.Green.Pure" parent="Theme.Green">
<item name="android:colorBackground">@android:color/black</item> <item name="android:colorBackground">@android:color/black</item>
<item name="colorSurface">@android:color/black</item> <item name="colorSurface">@android:color/black</item>
@ -133,7 +133,7 @@
</style> </style>
<style name="Theme.Purple.Black" parent="Theme.Purple"> <style name="Theme.Purple.Pure" parent="Theme.Purple">
<item name="android:colorBackground">@android:color/black</item> <item name="android:colorBackground">@android:color/black</item>
<item name="colorSurface">@android:color/black</item> <item name="colorSurface">@android:color/black</item>

View File

@ -533,14 +533,12 @@
<item>@string/systemDefault</item> <item>@string/systemDefault</item>
<item>@string/lightTheme</item> <item>@string/lightTheme</item>
<item>@string/darkTheme</item> <item>@string/darkTheme</item>
<item>@string/oledTheme</item>
</string-array> </string-array>
<string-array name="themesValue"> <string-array name="themesValue">
<item>A</item> <item>A</item>
<item>L</item> <item>L</item>
<item>D</item> <item>D</item>
<item>O</item>
</string-array> </string-array>
<string-array name="accents"> <string-array name="accents">

View File

@ -239,4 +239,6 @@
<string name="never">Never</string> <string name="never">Never</string>
<string name="autoRotatePlayer">Auto fullscreen</string> <string name="autoRotatePlayer">Auto fullscreen</string>
<string name="autoRotatePlayer_summary">Automatically switch to player fullscreen when the device gets turned.</string> <string name="autoRotatePlayer_summary">Automatically switch to player fullscreen when the device gets turned.</string>
<string name="pure_theme">Pure theme</string>
<string name="pure_theme_summary">Pure white/black theme</string>
</resources> </resources>

View File

@ -126,5 +126,4 @@
</style> </style>
</resources> </resources>

View File

@ -8,6 +8,13 @@
</style> </style>
<style name="Theme.MaterialYou.Pure" parent="MaterialYou">
<item name="android:colorBackground">@android:color/white</item>
<item name="colorSurface">@android:color/white</item>
</style>
<style name="Theme.Red" parent="Theme.Material3.Light.NoActionBar"> <style name="Theme.Red" parent="Theme.Material3.Light.NoActionBar">
<item name="colorPrimary">@color/red_light_accentLight</item> <item name="colorPrimary">@color/red_light_accentLight</item>
@ -27,6 +34,13 @@
</style> </style>
<style name="Theme.Red.Pure" parent="Theme.Red">
<item name="android:colorBackground">@android:color/white</item>
<item name="colorSurface">@android:color/white</item>
</style>
<style name="Theme.Blue" parent="Theme.Material3.Light.NoActionBar"> <style name="Theme.Blue" parent="Theme.Material3.Light.NoActionBar">
<item name="colorPrimary">@color/blue_light_accentLight</item> <item name="colorPrimary">@color/blue_light_accentLight</item>
@ -46,6 +60,13 @@
</style> </style>
<style name="Theme.Blue.Pure" parent="Theme.Blue">
<item name="android:colorBackground">@android:color/white</item>
<item name="colorSurface">@android:color/white</item>
</style>
<style name="Theme.Yellow" parent="Theme.Material3.Light.NoActionBar"> <style name="Theme.Yellow" parent="Theme.Material3.Light.NoActionBar">
<item name="colorPrimary">@color/yellow_light_accentLight</item> <item name="colorPrimary">@color/yellow_light_accentLight</item>
@ -65,6 +86,13 @@
</style> </style>
<style name="Theme.Yellow.Pure" parent="Theme.Yellow">
<item name="android:colorBackground">@android:color/white</item>
<item name="colorSurface">@android:color/white</item>
</style>
<style name="Theme.Green" parent="Theme.Material3.Light.NoActionBar"> <style name="Theme.Green" parent="Theme.Material3.Light.NoActionBar">
<item name="colorPrimary">@color/green_light_accentLight</item> <item name="colorPrimary">@color/green_light_accentLight</item>
@ -84,6 +112,13 @@
</style> </style>
<style name="Theme.Green.Pure" parent="Theme.Green">
<item name="android:colorBackground">@android:color/white</item>
<item name="colorSurface">@android:color/white</item>
</style>
<style name="Theme.Purple" parent="Theme.Material3.Light.NoActionBar"> <style name="Theme.Purple" parent="Theme.Material3.Light.NoActionBar">
<item name="colorPrimary">@color/purple_light_accentLight</item> <item name="colorPrimary">@color/purple_light_accentLight</item>
@ -103,4 +138,11 @@
</style> </style>
<style name="Theme.Purple.Pure" parent="Theme.Purple">
<item name="android:colorBackground">@android:color/white</item>
<item name="colorSurface">@android:color/white</item>
</style>
</resources> </resources>

View File

@ -33,7 +33,7 @@
<PreferenceCategory app:title="@string/search_history"> <PreferenceCategory app:title="@string/search_history">
<SwitchPreference <SwitchPreferenceCompat
android:defaultValue="true" android:defaultValue="true"
android:icon="@drawable/ic_history_filled" android:icon="@drawable/ic_history_filled"
app:key="search_history_toggle" app:key="search_history_toggle"
@ -48,13 +48,13 @@
<PreferenceCategory app:title="@string/watch_history"> <PreferenceCategory app:title="@string/watch_history">
<SwitchPreference <SwitchPreferenceCompat
android:defaultValue="true" android:defaultValue="true"
android:icon="@drawable/ic_time_outlined" android:icon="@drawable/ic_time_outlined"
app:key="watch_history_toggle" app:key="watch_history_toggle"
app:title="@string/watch_history" /> app:title="@string/watch_history" />
<SwitchPreference <SwitchPreferenceCompat
android:defaultValue="true" android:defaultValue="true"
android:icon="@drawable/ic_play_filled" android:icon="@drawable/ic_play_filled"
app:key="watch_position_toggle" app:key="watch_position_toggle"

View File

@ -13,6 +13,13 @@
app:title="@string/app_theme" app:title="@string/app_theme"
app:useSimpleSummaryProvider="true" /> app:useSimpleSummaryProvider="true" />
<SwitchPreferenceCompat
android:icon="@drawable/ic_invert_colors"
android:summary="@string/pure_theme_summary"
app:defaultValue="false"
app:key="pure_theme"
app:title="@string/pure_theme" />
<ListPreference <ListPreference
android:icon="@drawable/ic_color" android:icon="@drawable/ic_color"
app:defaultValue="purple" app:defaultValue="purple"
@ -44,7 +51,7 @@
app:title="@string/defaultTab" app:title="@string/defaultTab"
app:useSimpleSummaryProvider="true" /> app:useSimpleSummaryProvider="true" />
<SwitchPreference <SwitchPreferenceCompat
android:icon="@drawable/ic_trending" android:icon="@drawable/ic_trending"
app:defaultValue="false" app:defaultValue="false"
app:key="hide_trending_page" app:key="hide_trending_page"
@ -73,7 +80,7 @@
<PreferenceCategory> <PreferenceCategory>
<SwitchPreference <SwitchPreferenceCompat
android:defaultValue="true" android:defaultValue="true"
android:icon="@drawable/ic_list" android:icon="@drawable/ic_list"
app:key="related_streams_toggle" app:key="related_streams_toggle"

View File

@ -23,7 +23,7 @@
app:key="clearCustomInstances" app:key="clearCustomInstances"
app:title="@string/clear_customInstances" /> app:title="@string/clear_customInstances" />
<SwitchPreference <SwitchPreferenceCompat
android:defaultValue="false" android:defaultValue="false"
android:icon="@drawable/ic_auth" android:icon="@drawable/ic_auth"
app:key="auth_instance_toggle" app:key="auth_instance_toggle"