Split the rest of the preferences in PreferencesHelper (#8074)

* Split the reset of the preferences in PreferencesHelper

* Capitalize ThemeMode
This commit is contained in:
Andreas
2022-09-25 16:07:06 +02:00
committed by GitHub
parent 0fabe4bd01
commit 29fa93e829
51 changed files with 319 additions and 275 deletions
@@ -1,9 +0,0 @@
package eu.kanade.tachiyomi.data.preference
/**
* This class stores the keys for the preferences in the application.
*/
object PreferenceKeys {
const val dateFormat = "app_date_format"
}
@@ -16,38 +16,6 @@ const val MANGA_NON_READ = "manga_started"
*/
object PreferenceValues {
/* ktlint-disable experimental:enum-entry-name-case */
// Keys are lowercase to match legacy string values
/* ktlint-disable enum-entry-name-case */
enum class ThemeMode {
light,
dark,
system,
}
/* ktlint-enable enum-entry-name-case */
/* ktlint-enable experimental:enum-entry-name-case */
enum class AppTheme(val titleResId: Int?) {
DEFAULT(R.string.label_default),
MONET(R.string.theme_monet),
GREEN_APPLE(R.string.theme_greenapple),
LAVENDER(R.string.theme_lavender),
MIDNIGHT_DUSK(R.string.theme_midnightdusk),
STRAWBERRY_DAIQUIRI(R.string.theme_strawberrydaiquiri),
TAKO(R.string.theme_tako),
TEALTURQUOISE(R.string.theme_tealturquoise),
TIDAL_WAVE(R.string.theme_tidalwave),
YINYANG(R.string.theme_yinyang),
YOTSUBA(R.string.theme_yotsuba),
// Deprecated
DARK_BLUE(null),
HOT_PINK(null),
BLUE(null),
}
enum class TappingInvertMode(val shouldInvertHorizontal: Boolean = false, val shouldInvertVertical: Boolean = false) {
NONE,
HORIZONTAL(shouldInvertHorizontal = true),
@@ -62,13 +30,6 @@ object PreferenceValues {
LOWEST(47),
}
enum class TabletUiMode(val titleResId: Int) {
AUTOMATIC(R.string.automatic_background),
ALWAYS(R.string.lock_always),
LANDSCAPE(R.string.landscape),
NEVER(R.string.lock_never),
}
enum class ExtensionInstaller(val titleResId: Int) {
LEGACY(R.string.ext_installer_legacy),
PACKAGEINSTALLER(R.string.ext_installer_packageinstaller),
@@ -1,64 +0,0 @@
package eu.kanade.tachiyomi.data.preference
import android.content.Context
import android.os.Build
import eu.kanade.tachiyomi.core.preference.PreferenceStore
import eu.kanade.tachiyomi.core.preference.getEnum
import eu.kanade.tachiyomi.util.system.DeviceUtil
import eu.kanade.tachiyomi.util.system.isDynamicColorAvailable
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.Locale
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values
class PreferencesHelper(
val context: Context,
private val preferenceStore: PreferenceStore,
) {
fun confirmExit() = preferenceStore.getBoolean("pref_confirm_exit", false)
fun sideNavIconAlignment() = preferenceStore.getInt("pref_side_nav_icon_alignment", 0)
fun themeMode() = preferenceStore.getEnum(
"pref_theme_mode_key",
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Values.ThemeMode.system } else { Values.ThemeMode.light },
)
fun appTheme() = preferenceStore.getEnum(
"pref_app_theme",
if (DeviceUtil.isDynamicColorAvailable) { Values.AppTheme.MONET } else { Values.AppTheme.DEFAULT },
)
fun themeDarkAmoled() = preferenceStore.getBoolean("pref_theme_dark_amoled_key", false)
fun lastVersionCode() = preferenceStore.getInt("last_version_code", 0)
fun relativeTime() = preferenceStore.getInt("relative_time", 7)
fun dateFormat(format: String = preferenceStore.getString(Keys.dateFormat, "").get()): DateFormat = when (format) {
"" -> DateFormat.getDateInstance(DateFormat.SHORT)
else -> SimpleDateFormat(format, Locale.getDefault())
}
fun downloadedOnly() = preferenceStore.getBoolean("pref_downloaded_only", false)
fun automaticExtUpdates() = preferenceStore.getBoolean("automatic_ext_updates", true)
fun lastAppCheck() = preferenceStore.getLong("last_app_check", 0)
fun lastExtCheck() = preferenceStore.getLong("last_ext_check", 0)
fun migrateFlags() = preferenceStore.getInt("migrate_flags", Int.MAX_VALUE)
fun incognitoMode() = preferenceStore.getBoolean("incognito_mode", false)
fun tabletUiMode() = preferenceStore.getEnum("tablet_ui_mode", Values.TabletUiMode.AUTOMATIC)
fun extensionInstaller() = preferenceStore.getEnum(
"extension_installer",
if (DeviceUtil.isMiui) Values.ExtensionInstaller.LEGACY else Values.ExtensionInstaller.PACKAGEINSTALLER,
)
fun autoClearChapterCache() = preferenceStore.getBoolean("auto_clear_chapter_cache", false)
}