Split out appearance settings from general section

This commit is contained in:
arkon 2021-08-23 12:24:30 -04:00
parent 6240fe1dfc
commit 0493e77cff
6 changed files with 200 additions and 141 deletions

View File

@ -0,0 +1,160 @@
package eu.kanade.tachiyomi.ui.setting
import android.os.Build
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
import eu.kanade.tachiyomi.util.preference.defaultValue
import eu.kanade.tachiyomi.util.preference.entriesRes
import eu.kanade.tachiyomi.util.preference.initThenAdd
import eu.kanade.tachiyomi.util.preference.intListPreference
import eu.kanade.tachiyomi.util.preference.listPreference
import eu.kanade.tachiyomi.util.preference.onChange
import eu.kanade.tachiyomi.util.preference.preferenceCategory
import eu.kanade.tachiyomi.util.preference.switchPreference
import eu.kanade.tachiyomi.util.preference.titleRes
import eu.kanade.tachiyomi.util.system.isTablet
import eu.kanade.tachiyomi.widget.preference.ThemesPreference
import kotlinx.coroutines.flow.launchIn
import java.util.Date
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values
class SettingsAppearanceController : SettingsController() {
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
titleRes = R.string.pref_category_appearance
preferenceCategory {
titleRes = R.string.pref_category_theme
listPreference {
key = Keys.themeMode
titleRes = R.string.pref_theme_mode
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
entriesRes = arrayOf(
R.string.theme_system,
R.string.theme_light,
R.string.theme_dark
)
entryValues = arrayOf(
Values.ThemeMode.system.name,
Values.ThemeMode.light.name,
Values.ThemeMode.dark.name
)
defaultValue = Values.ThemeMode.system.name
} else {
entriesRes = arrayOf(
R.string.theme_light,
R.string.theme_dark
)
entryValues = arrayOf(
Values.ThemeMode.light.name,
Values.ThemeMode.dark.name
)
defaultValue = Values.ThemeMode.light.name
}
summary = "%s"
}
initThenAdd(ThemesPreference(context)) {
key = Keys.appTheme
titleRes = R.string.pref_app_theme
val appThemes = Values.AppTheme.values().filter {
val monetFilter = if (it == Values.AppTheme.MONET) {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
} else {
true
}
it.titleResId != null && monetFilter
}
entries = appThemes
defaultValue = appThemes[0].name
onChange {
activity?.recreate()
true
}
}
switchPreference {
key = Keys.themeDarkAmoled
titleRes = R.string.pref_dark_theme_pure_black
defaultValue = false
preferences.themeMode().asImmediateFlow { isVisible = it != Values.ThemeMode.light }
.launchIn(viewScope)
onChange {
activity?.recreate()
true
}
}
}
preferenceCategory {
titleRes = R.string.pref_category_layout
if (context.isTablet()) {
intListPreference {
key = Keys.sideNavIconAlignment
titleRes = R.string.pref_side_nav_icon_alignment
entriesRes = arrayOf(
R.string.alignment_top,
R.string.alignment_center,
R.string.alignment_bottom,
)
entryValues = arrayOf("0", "1", "2")
defaultValue = "0"
summary = "%s"
}
} else {
switchPreference {
key = Keys.hideBottomBarOnScroll
titleRes = R.string.pref_hide_bottom_bar_on_scroll
defaultValue = true
}
}
}
preferenceCategory {
titleRes = R.string.pref_category_timestamps
intListPreference {
key = Keys.relativeTime
titleRes = R.string.pref_relative_format
val values = arrayOf("0", "2", "7")
entryValues = values
entries = values.map {
when (it) {
"0" -> context.getString(R.string.off)
"2" -> context.getString(R.string.pref_relative_time_short)
else -> context.getString(R.string.pref_relative_time_long)
}
}.toTypedArray()
defaultValue = "7"
summary = "%s"
}
listPreference {
key = Keys.dateFormat
titleRes = R.string.pref_date_format
entryValues = arrayOf("", "MM/dd/yy", "dd/MM/yy", "yyyy-MM-dd", "dd MMM yyyy", "MMM dd, yyyy")
val now = Date().time
entries = entryValues.map { value ->
val formattedDate = preferences.dateFormat(value.toString()).format(now)
if (value == "") {
"${context.getString(R.string.label_default)} ($formattedDate)"
} else {
"$value ($formattedDate)"
}
}.toTypedArray()
defaultValue = ""
summary = "%s"
}
}
}
}

View File

@ -5,24 +5,14 @@ import android.os.Build
import android.provider.Settings import android.provider.Settings
import androidx.preference.PreferenceScreen import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
import eu.kanade.tachiyomi.util.preference.defaultValue import eu.kanade.tachiyomi.util.preference.defaultValue
import eu.kanade.tachiyomi.util.preference.entriesRes import eu.kanade.tachiyomi.util.preference.entriesRes
import eu.kanade.tachiyomi.util.preference.initThenAdd
import eu.kanade.tachiyomi.util.preference.intListPreference import eu.kanade.tachiyomi.util.preference.intListPreference
import eu.kanade.tachiyomi.util.preference.listPreference
import eu.kanade.tachiyomi.util.preference.onChange
import eu.kanade.tachiyomi.util.preference.onClick import eu.kanade.tachiyomi.util.preference.onClick
import eu.kanade.tachiyomi.util.preference.preference import eu.kanade.tachiyomi.util.preference.preference
import eu.kanade.tachiyomi.util.preference.preferenceCategory
import eu.kanade.tachiyomi.util.preference.switchPreference import eu.kanade.tachiyomi.util.preference.switchPreference
import eu.kanade.tachiyomi.util.preference.titleRes import eu.kanade.tachiyomi.util.preference.titleRes
import eu.kanade.tachiyomi.util.system.isTablet
import eu.kanade.tachiyomi.widget.preference.ThemesPreference
import kotlinx.coroutines.flow.launchIn
import java.util.Date
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values
class SettingsGeneralController : SettingsController() { class SettingsGeneralController : SettingsController() {
@ -47,27 +37,6 @@ class SettingsGeneralController : SettingsController() {
titleRes = R.string.pref_confirm_exit titleRes = R.string.pref_confirm_exit
defaultValue = false defaultValue = false
} }
if (context.isTablet()) {
intListPreference {
key = Keys.sideNavIconAlignment
titleRes = R.string.pref_side_nav_icon_alignment
entriesRes = arrayOf(
R.string.alignment_top,
R.string.alignment_center,
R.string.alignment_bottom,
)
entryValues = arrayOf("0", "1", "2")
defaultValue = "0"
summary = "%s"
}
} else {
switchPreference {
key = Keys.hideBottomBarOnScroll
titleRes = R.string.pref_hide_bottom_bar_on_scroll
defaultValue = true
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
preference { preference {
key = "pref_manage_notifications" key = "pref_manage_notifications"
@ -80,107 +49,5 @@ class SettingsGeneralController : SettingsController() {
} }
} }
} }
intListPreference {
key = Keys.relativeTime
titleRes = R.string.pref_relative_format
val values = arrayOf("0", "2", "7")
entryValues = values
entries = values.map {
when (it) {
"0" -> context.getString(R.string.off)
"2" -> context.getString(R.string.pref_relative_time_short)
else -> context.getString(R.string.pref_relative_time_long)
}
}.toTypedArray()
defaultValue = "7"
summary = "%s"
}
listPreference {
key = Keys.dateFormat
titleRes = R.string.pref_date_format
entryValues = arrayOf("", "MM/dd/yy", "dd/MM/yy", "yyyy-MM-dd", "dd MMM yyyy", "MMM dd, yyyy")
val now = Date().time
entries = entryValues.map { value ->
val formattedDate = preferences.dateFormat(value.toString()).format(now)
if (value == "") {
"${context.getString(R.string.label_default)} ($formattedDate)"
} else {
"$value ($formattedDate)"
}
}.toTypedArray()
defaultValue = ""
summary = "%s"
}
preferenceCategory {
titleRes = R.string.pref_category_theme
listPreference {
key = Keys.themeMode
titleRes = R.string.pref_theme_mode
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
entriesRes = arrayOf(
R.string.theme_system,
R.string.theme_light,
R.string.theme_dark
)
entryValues = arrayOf(
Values.ThemeMode.system.name,
Values.ThemeMode.light.name,
Values.ThemeMode.dark.name
)
defaultValue = Values.ThemeMode.system.name
} else {
entriesRes = arrayOf(
R.string.theme_light,
R.string.theme_dark
)
entryValues = arrayOf(
Values.ThemeMode.light.name,
Values.ThemeMode.dark.name
)
defaultValue = Values.ThemeMode.light.name
}
summary = "%s"
}
initThenAdd(ThemesPreference(context)) {
key = Keys.appTheme
titleRes = R.string.pref_app_theme
val appThemes = Values.AppTheme.values().filter {
val monetFilter = if (it == Values.AppTheme.MONET) {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
} else {
true
}
it.titleResId != null && monetFilter
}
entries = appThemes
defaultValue = appThemes[0].name
onChange {
activity?.recreate()
true
}
}
switchPreference {
key = Keys.themeDarkAmoled
titleRes = R.string.pref_dark_theme_pure_black
defaultValue = false
preferences.themeMode().asImmediateFlow { isVisible = it != Values.ThemeMode.light }
.launchIn(viewScope)
onChange {
activity?.recreate()
true
}
}
}
} }
} }

View File

@ -28,6 +28,12 @@ class SettingsMainController : SettingsController() {
titleRes = R.string.pref_category_general titleRes = R.string.pref_category_general
onClick { navigateTo(SettingsGeneralController()) } onClick { navigateTo(SettingsGeneralController()) }
} }
preference {
iconRes = R.drawable.ic_palette_24dp
iconTint = tintColor
titleRes = R.string.pref_category_appearance
onClick { navigateTo(SettingsAppearanceController()) }
}
preference { preference {
iconRes = R.drawable.ic_library_outline_24dp iconRes = R.drawable.ic_library_outline_24dp
iconTint = tintColor iconTint = tintColor

View File

@ -23,7 +23,8 @@ class ThemesPreferenceAdapter(private val clickListener: OnItemClickListener) :
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ThemeViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ThemeViewHolder {
val themeResIds = BaseThemedActivity.getThemeResIds(themes[viewType], preferences.themeDarkAmoled().get()) val themeResIds = BaseThemedActivity.getThemeResIds(themes[viewType], preferences.themeDarkAmoled().get())
val themedContext = themeResIds.fold(parent.context) { val themedContext = themeResIds.fold(parent.context) {
context, themeResId -> ContextThemeWrapper(context, themeResId) context, themeResId ->
ContextThemeWrapper(context, themeResId)
} }
binding = PrefThemeItemBinding.inflate(LayoutInflater.from(themedContext), parent, false) binding = PrefThemeItemBinding.inflate(LayoutInflater.from(themedContext), parent, false)

View File

@ -0,0 +1,21 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/black"
android:pathData="M12,22C6.49,22 2,17.51 2,12S6.49,2 12,2s10,4.04 10,9c0,3.31 -2.69,6 -6,6h-1.77c-0.28,0 -0.5,0.22 -0.5,0.5 0,0.12 0.05,0.23 0.13,0.33 0.41,0.47 0.64,1.06 0.64,1.67 0,1.38 -1.12,2.5 -2.5,2.5zM12,4c-4.41,0 -8,3.59 -8,8s3.59,8 8,8c0.28,0 0.5,-0.22 0.5,-0.5 0,-0.16 -0.08,-0.28 -0.14,-0.35 -0.41,-0.46 -0.63,-1.05 -0.63,-1.65 0,-1.38 1.12,-2.5 2.5,-2.5L16,15c2.21,0 4,-1.79 4,-4 0,-3.86 -3.59,-7 -8,-7z"/>
<path
android:fillColor="@android:color/black"
android:pathData="M6.5,11.5m-1.5,0a1.5,1.5 0,1 1,3 0a1.5,1.5 0,1 1,-3 0"/>
<path
android:fillColor="@android:color/black"
android:pathData="M9.5,7.5m-1.5,0a1.5,1.5 0,1 1,3 0a1.5,1.5 0,1 1,-3 0"/>
<path
android:fillColor="@android:color/black"
android:pathData="M14.5,7.5m-1.5,0a1.5,1.5 0,1 1,3 0a1.5,1.5 0,1 1,-3 0"/>
<path
android:fillColor="@android:color/black"
android:pathData="M17.5,11.5m-1.5,0a1.5,1.5 0,1 1,3 0a1.5,1.5 0,1 1,-3 0"/>
</vector>

View File

@ -134,6 +134,7 @@
<!-- Preferences --> <!-- Preferences -->
<!-- Subsections --> <!-- Subsections -->
<string name="pref_category_general">General</string> <string name="pref_category_general">General</string>
<string name="pref_category_appearance">Appearance</string>
<string name="pref_category_library">Library</string> <string name="pref_category_library">Library</string>
<string name="pref_category_reader">Reader</string> <string name="pref_category_reader">Reader</string>
<string name="pref_category_downloads">Downloads</string> <string name="pref_category_downloads">Downloads</string>
@ -158,14 +159,20 @@
<string name="theme_yinyang">Yin &amp; Yang</string> <string name="theme_yinyang">Yin &amp; Yang</string>
<string name="theme_yotsuba">Yotsuba</string> <string name="theme_yotsuba">Yotsuba</string>
<string name="pref_dark_theme_pure_black">Pure black dark mode</string> <string name="pref_dark_theme_pure_black">Pure black dark mode</string>
<string name="pref_start_screen">Start screen</string> <string name="pref_category_layout">Layout</string>
<string name="pref_date_format">Date format</string>
<string name="pref_confirm_exit">Confirm exit</string>
<string name="pref_hide_bottom_bar_on_scroll">Hide bottom bar on scroll</string>
<string name="pref_side_nav_icon_alignment">Side navigation icon alignment</string> <string name="pref_side_nav_icon_alignment">Side navigation icon alignment</string>
<string name="alignment_top">Top</string> <string name="alignment_top">Top</string>
<string name="alignment_center">Center</string> <string name="alignment_center">Center</string>
<string name="alignment_bottom">Bottom</string> <string name="alignment_bottom">Bottom</string>
<string name="pref_hide_bottom_bar_on_scroll">Hide bottom bar on scroll</string>
<string name="pref_category_timestamps">Timestamps</string>
<string name="pref_relative_format">Relative timestamps</string>
<string name="pref_relative_time_short">Short (Today, Yesterday)</string>
<string name="pref_relative_time_long">Long (Short+, n days ago)</string>
<string name="pref_date_format">Date format</string>
<string name="pref_start_screen">Start screen</string>
<string name="pref_confirm_exit">Confirm exit</string>
<string name="pref_manage_notifications">Manage notifications</string> <string name="pref_manage_notifications">Manage notifications</string>
<string name="pref_category_security">Security</string> <string name="pref_category_security">Security</string>
@ -193,9 +200,6 @@
<item quantity="one">Yesterday</item> <item quantity="one">Yesterday</item>
<item quantity="other">%1$d days ago</item> <item quantity="other">%1$d days ago</item>
</plurals> </plurals>
<string name="pref_relative_format">Relative timestamps</string>
<string name="pref_relative_time_short">Short (Today, Yesterday)</string>
<string name="pref_relative_time_long">Long (Short+, n days ago)</string>
<!-- Library section --> <!-- Library section -->
<string name="pref_category_display">Display</string> <string name="pref_category_display">Display</string>