mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
commit
f1f2c21938
@ -18,7 +18,7 @@ class AppearanceSettings : PreferenceFragmentCompat() {
|
||||
val settingsActivity = activity as SettingsActivity
|
||||
settingsActivity.changeTopBarText(getString(R.string.appearance))
|
||||
|
||||
val themeToggle = findPreference<ListPreference>("theme_togglee")
|
||||
val themeToggle = findPreference<ListPreference>("theme_toggle")
|
||||
themeToggle?.setOnPreferenceChangeListener { _, _ ->
|
||||
val restartDialog = RequireRestartDialog()
|
||||
restartDialog.show(childFragmentManager, "RequireRestartDialog")
|
||||
|
@ -17,11 +17,17 @@ import com.google.android.material.color.DynamicColors
|
||||
object ThemeHelper {
|
||||
|
||||
fun updateTheme(activity: AppCompatActivity) {
|
||||
updateAccentColor(activity)
|
||||
updateThemeMode(activity)
|
||||
val themeMode = PreferenceHelper.getString(activity, "theme_toggle", "A")!!
|
||||
val blackModeEnabled = themeMode == "O"
|
||||
|
||||
updateAccentColor(activity, blackModeEnabled)
|
||||
updateThemeMode(themeMode)
|
||||
}
|
||||
|
||||
private fun updateAccentColor(activity: AppCompatActivity) {
|
||||
private fun updateAccentColor(
|
||||
activity: AppCompatActivity,
|
||||
blackThemeEnabled: Boolean
|
||||
) {
|
||||
val theme = when (
|
||||
PreferenceHelper.getString(
|
||||
activity,
|
||||
@ -31,14 +37,15 @@ object ThemeHelper {
|
||||
) {
|
||||
"my" -> {
|
||||
applyDynamicColors(activity)
|
||||
R.style.MaterialYou
|
||||
if (blackThemeEnabled) R.style.MaterialYou_Black
|
||||
else R.style.MaterialYou
|
||||
}
|
||||
"red" -> R.style.Theme_Red
|
||||
"blue" -> R.style.Theme_Blue
|
||||
"yellow" -> R.style.Theme_Yellow
|
||||
"green" -> R.style.Theme_Green
|
||||
"purple" -> R.style.Theme_Purple
|
||||
else -> R.style.Theme_Purple
|
||||
"red" -> if (blackThemeEnabled) R.style.Theme_Red_Black else R.style.Theme_Red
|
||||
"blue" -> if (blackThemeEnabled) R.style.Theme_Blue_Black else R.style.Theme_Blue
|
||||
"yellow" -> if (blackThemeEnabled) R.style.Theme_Yellow_Black else R.style.Theme_Yellow
|
||||
"green" -> if (blackThemeEnabled) R.style.Theme_Green_Black else R.style.Theme_Green
|
||||
"purple" -> if (blackThemeEnabled) R.style.Theme_Purple_Black else R.style.Theme_Purple
|
||||
else -> if (blackThemeEnabled) R.style.Theme_Purple_Black else R.style.Theme_Purple
|
||||
}
|
||||
activity.setTheme(theme)
|
||||
}
|
||||
@ -50,16 +57,15 @@ object ThemeHelper {
|
||||
DynamicColors.applyToActivityIfAvailable(activity)
|
||||
}
|
||||
|
||||
private fun updateThemeMode(context: Context) {
|
||||
when (PreferenceHelper.getString(context, "theme_togglee", "A")) {
|
||||
"A" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||
"L" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||
"D" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||
"O" -> {
|
||||
context.setTheme(R.style.Black)
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||
}
|
||||
private fun updateThemeMode(themeMode: String) {
|
||||
val mode = when (themeMode) {
|
||||
"A" -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
"L" -> AppCompatDelegate.MODE_NIGHT_NO
|
||||
"D" -> AppCompatDelegate.MODE_NIGHT_YES
|
||||
"O" -> AppCompatDelegate.MODE_NIGHT_YES
|
||||
else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
}
|
||||
AppCompatDelegate.setDefaultNightMode(mode)
|
||||
}
|
||||
|
||||
fun changeIcon(context: Context, newLogoActivityAlias: String) {
|
||||
|
@ -8,6 +8,13 @@
|
||||
|
||||
</style>
|
||||
|
||||
<style name="MaterialYou.Black" parent="MaterialYou">
|
||||
|
||||
<item name="android:colorBackground">@android:color/black</item>
|
||||
<item name="colorSurface">@android:color/black</item>
|
||||
|
||||
</style>
|
||||
|
||||
<style name="Theme.Red" parent="Theme.Material3.Dark.NoActionBar">
|
||||
|
||||
<item name="colorPrimary">@color/red_dark_accentLight</item>
|
||||
@ -26,6 +33,13 @@
|
||||
|
||||
</style>
|
||||
|
||||
<style name="Theme.Red.Black" parent="Theme.Red">
|
||||
|
||||
<item name="android:colorBackground">@android:color/black</item>
|
||||
<item name="colorSurface">@android:color/black</item>
|
||||
|
||||
</style>
|
||||
|
||||
<style name="Theme.Blue" parent="Theme.Material3.Dark.NoActionBar">
|
||||
|
||||
<item name="colorPrimary">@color/blue_dark_accentLight</item>
|
||||
@ -44,6 +58,13 @@
|
||||
|
||||
</style>
|
||||
|
||||
<style name="Theme.Blue.Black" parent="Theme.Blue">
|
||||
|
||||
<item name="android:colorBackground">@android:color/black</item>
|
||||
<item name="colorSurface">@android:color/black</item>
|
||||
|
||||
</style>
|
||||
|
||||
<style name="Theme.Yellow" parent="Theme.Material3.Dark.NoActionBar">
|
||||
|
||||
<item name="colorPrimary">@color/yellow_dark_accentLight</item>
|
||||
@ -62,6 +83,13 @@
|
||||
|
||||
</style>
|
||||
|
||||
<style name="Theme.Yellow.Black" parent="Theme.Yellow">
|
||||
|
||||
<item name="android:colorBackground">@android:color/black</item>
|
||||
<item name="colorSurface">@android:color/black</item>
|
||||
|
||||
</style>
|
||||
|
||||
<style name="Theme.Green" parent="Theme.Material3.Dark.NoActionBar">
|
||||
|
||||
<item name="colorPrimary">@color/green_dark_accentLight</item>
|
||||
@ -80,6 +108,13 @@
|
||||
|
||||
</style>
|
||||
|
||||
<style name="Theme.Green.Black" parent="Theme.Green">
|
||||
|
||||
<item name="android:colorBackground">@android:color/black</item>
|
||||
<item name="colorSurface">@android:color/black</item>
|
||||
|
||||
</style>
|
||||
|
||||
<style name="Theme.Purple" parent="Theme.Material3.Dark.NoActionBar">
|
||||
|
||||
<item name="colorPrimary">@color/purple_dark_accentLight</item>
|
||||
@ -98,4 +133,11 @@
|
||||
|
||||
</style>
|
||||
|
||||
<style name="Theme.Purple.Black" parent="Theme.Purple">
|
||||
|
||||
<item name="android:colorBackground">@android:color/black</item>
|
||||
<item name="colorSurface">@android:color/black</item>
|
||||
|
||||
</style>
|
||||
|
||||
</resources>
|
@ -15,16 +15,6 @@
|
||||
|
||||
</style>
|
||||
|
||||
<style name="Black">
|
||||
|
||||
<item name="android:colorBackground">@android:color/black</item>
|
||||
<item name="colorSurface">@android:color/black</item>
|
||||
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||
|
||||
</style>
|
||||
|
||||
<style name="MaterialAlertDialog">
|
||||
|
||||
<item name="alertDialogTheme">@style/ThemeOverlay.Material3.MaterialAlertDialog</item>
|
||||
|
@ -9,7 +9,7 @@
|
||||
app:defaultValue="A"
|
||||
app:entries="@array/themes"
|
||||
app:entryValues="@array/themesValue"
|
||||
app:key="theme_togglee"
|
||||
app:key="theme_toggle"
|
||||
app:title="@string/app_theme"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user