From 29fa93e829ca7f9c3a28c58f3de146bc2bd15aad Mon Sep 17 00:00:00 2001 From: Andreas Date: Sun, 25 Sep 2022 16:07:06 +0200 Subject: [PATCH] Split the rest of the preferences in PreferencesHelper (#8074) * Split the reset of the preferences in PreferencesHelper * Capitalize ThemeMode --- app/build.gradle.kts | 2 +- .../eu/kanade/domain/base/BasePreferences.kt | 26 ++++++++ .../library/service/LibraryPreferences.kt | 2 + .../eu/kanade/domain/manga/model/Manga.kt | 4 +- .../java/eu/kanade/domain/ui/UiPreferences.kt | 45 +++++++++++++ .../eu/kanade/domain/ui/model/AppTheme.kt | 22 +++++++ .../eu/kanade/domain/ui/model/TabletUiMode.kt | 10 +++ .../eu/kanade/domain/ui/model/ThemeMode.kt | 7 ++ .../history/components/HistoryContent.kt | 6 +- app/src/main/java/eu/kanade/tachiyomi/App.kt | 20 +++--- .../java/eu/kanade/tachiyomi/AppModule.kt | 11 ++-- .../java/eu/kanade/tachiyomi/Migrations.kt | 25 ++++++-- .../data/preference/PreferenceKeys.kt | 9 --- .../data/preference/PreferenceValues.kt | 39 ----------- .../data/preference/PreferencesHelper.kt | 64 ------------------- .../tachiyomi/data/track/TrackService.kt | 4 +- .../data/updater/AppUpdateChecker.kt | 12 ++-- .../tachiyomi/extension/ExtensionUpdateJob.kt | 4 +- .../extension/api/ExtensionGithubApi.kt | 12 ++-- .../extension/util/ExtensionInstaller.kt | 6 +- .../ui/base/activity/BaseActivity.kt | 4 +- .../ui/base/activity/BaseRxActivity.kt | 4 +- .../base/delegate/SecureActivityDelegate.kt | 4 +- .../ui/base/delegate/ThemingDelegate.kt | 30 ++++----- .../tachiyomi/ui/browse/BrowsePresenter.kt | 4 +- .../migration/search/SearchController.kt | 9 +-- .../migration/search/SearchPresenter.kt | 9 ++- .../ui/browse/source/SourcesPresenter.kt | 4 +- .../source/browse/BrowseSourcePresenter.kt | 6 +- .../globalsearch/GlobalSearchController.kt | 4 +- .../globalsearch/GlobalSearchPresenter.kt | 4 +- .../tachiyomi/ui/library/LibraryPresenter.kt | 4 +- .../ui/library/LibrarySettingsSheet.kt | 4 +- .../kanade/tachiyomi/ui/main/MainActivity.kt | 10 ++- .../tachiyomi/ui/manga/MangaPresenter.kt | 14 ++-- .../tachiyomi/ui/manga/track/TrackHolder.kt | 6 +- .../tachiyomi/ui/more/AboutController.kt | 6 +- .../kanade/tachiyomi/ui/more/MorePresenter.kt | 5 +- .../tachiyomi/ui/reader/ReaderPresenter.kt | 4 +- .../ui/recent/history/HistoryPresenter.kt | 4 +- .../ui/recent/updates/UpdatesPresenter.kt | 15 +++-- .../ui/setting/SettingsAdvancedController.kt | 13 ++-- .../setting/SettingsAppearanceController.kt | 39 +++++------ .../ui/setting/SettingsController.kt | 4 +- .../setting/search/SettingsSearchPresenter.kt | 4 +- .../util/system/ContextExtensions.kt | 16 ++--- .../tachiyomi/widget/TachiyomiSearchView.kt | 6 +- .../widget/TachiyomiTextInputEditText.kt | 8 +-- .../preference/LoginDialogPreference.kt | 4 +- .../widget/preference/ThemesPreference.kt | 4 +- .../preference/ThemesPreferenceAdapter.kt | 12 ++-- 51 files changed, 319 insertions(+), 275 deletions(-) create mode 100644 app/src/main/java/eu/kanade/domain/base/BasePreferences.kt create mode 100644 app/src/main/java/eu/kanade/domain/ui/UiPreferences.kt create mode 100644 app/src/main/java/eu/kanade/domain/ui/model/AppTheme.kt create mode 100644 app/src/main/java/eu/kanade/domain/ui/model/TabletUiMode.kt create mode 100644 app/src/main/java/eu/kanade/domain/ui/model/ThemeMode.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index f1353765bd..8cd7de781b 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -27,7 +27,7 @@ android { applicationId = "eu.kanade.tachiyomi" minSdk = AndroidConfig.minSdk targetSdk = AndroidConfig.targetSdk - versionCode = 85 + versionCode = 86 versionName = "0.13.6" buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"") diff --git a/app/src/main/java/eu/kanade/domain/base/BasePreferences.kt b/app/src/main/java/eu/kanade/domain/base/BasePreferences.kt new file mode 100644 index 0000000000..5bcc2cbbad --- /dev/null +++ b/app/src/main/java/eu/kanade/domain/base/BasePreferences.kt @@ -0,0 +1,26 @@ +package eu.kanade.domain.base + +import android.content.Context +import eu.kanade.tachiyomi.core.preference.PreferenceStore +import eu.kanade.tachiyomi.core.preference.getEnum +import eu.kanade.tachiyomi.data.preference.PreferenceValues +import eu.kanade.tachiyomi.util.system.DeviceUtil + +class BasePreferences( + val context: Context, + private val preferenceStore: PreferenceStore, +) { + + fun confirmExit() = preferenceStore.getBoolean("pref_confirm_exit", false) + + fun downloadedOnly() = preferenceStore.getBoolean("pref_downloaded_only", false) + + fun incognitoMode() = preferenceStore.getBoolean("incognito_mode", false) + + fun automaticExtUpdates() = preferenceStore.getBoolean("automatic_ext_updates", true) + + fun extensionInstaller() = preferenceStore.getEnum( + "extension_installer", + if (DeviceUtil.isMiui) PreferenceValues.ExtensionInstaller.LEGACY else PreferenceValues.ExtensionInstaller.PACKAGEINSTALLER, + ) +} diff --git a/app/src/main/java/eu/kanade/domain/library/service/LibraryPreferences.kt b/app/src/main/java/eu/kanade/domain/library/service/LibraryPreferences.kt index 7132d2357a..e13f273638 100644 --- a/app/src/main/java/eu/kanade/domain/library/service/LibraryPreferences.kt +++ b/app/src/main/java/eu/kanade/domain/library/service/LibraryPreferences.kt @@ -103,5 +103,7 @@ class LibraryPreferences( sortChapterByAscendingOrDescending().set(if (manga.sortDescending()) Manga.CHAPTER_SORT_DESC else Manga.CHAPTER_SORT_ASC) } + fun autoClearChapterCache() = preferenceStore.getBoolean("auto_clear_chapter_cache", false) + // endregion } diff --git a/app/src/main/java/eu/kanade/domain/manga/model/Manga.kt b/app/src/main/java/eu/kanade/domain/manga/model/Manga.kt index aba7e14b7a..10044044fd 100644 --- a/app/src/main/java/eu/kanade/domain/manga/model/Manga.kt +++ b/app/src/main/java/eu/kanade/domain/manga/model/Manga.kt @@ -1,9 +1,9 @@ package eu.kanade.domain.manga.model import eu.kanade.data.listOfStringsAdapter +import eu.kanade.domain.base.BasePreferences import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.database.models.MangaImpl -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.widget.ExtendedNavigationView @@ -78,7 +78,7 @@ data class Manga( } fun forceDownloaded(): Boolean { - return favorite && Injekt.get().downloadedOnly().get() + return favorite && Injekt.get().downloadedOnly().get() } fun sortDescending(): Boolean { diff --git a/app/src/main/java/eu/kanade/domain/ui/UiPreferences.kt b/app/src/main/java/eu/kanade/domain/ui/UiPreferences.kt new file mode 100644 index 0000000000..69868bb13e --- /dev/null +++ b/app/src/main/java/eu/kanade/domain/ui/UiPreferences.kt @@ -0,0 +1,45 @@ +package eu.kanade.domain.ui + +import android.os.Build +import eu.kanade.domain.ui.model.AppTheme +import eu.kanade.domain.ui.model.TabletUiMode +import eu.kanade.domain.ui.model.ThemeMode +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 + +class UiPreferences( + private val preferenceStore: PreferenceStore, +) { + + 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) { ThemeMode.SYSTEM } else { ThemeMode.LIGHT }, + ) + + fun appTheme() = preferenceStore.getEnum( + "pref_app_theme", + if (DeviceUtil.isDynamicColorAvailable) { AppTheme.MONET } else { AppTheme.DEFAULT }, + ) + + fun themeDarkAmoled() = preferenceStore.getBoolean("pref_theme_dark_amoled_key", false) + + fun relativeTime() = preferenceStore.getInt("relative_time", 7) + + fun dateFormat() = preferenceStore.getString("app_date_format", "") + + fun tabletUiMode() = preferenceStore.getEnum("tablet_ui_mode", TabletUiMode.AUTOMATIC) + + companion object { + fun dateFormat(format: String): DateFormat = when (format) { + "" -> DateFormat.getDateInstance(DateFormat.SHORT) + else -> SimpleDateFormat(format, Locale.getDefault()) + } + } +} diff --git a/app/src/main/java/eu/kanade/domain/ui/model/AppTheme.kt b/app/src/main/java/eu/kanade/domain/ui/model/AppTheme.kt new file mode 100644 index 0000000000..250188535f --- /dev/null +++ b/app/src/main/java/eu/kanade/domain/ui/model/AppTheme.kt @@ -0,0 +1,22 @@ +package eu.kanade.domain.ui.model + +import eu.kanade.tachiyomi.R + +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), +} diff --git a/app/src/main/java/eu/kanade/domain/ui/model/TabletUiMode.kt b/app/src/main/java/eu/kanade/domain/ui/model/TabletUiMode.kt new file mode 100644 index 0000000000..71cee1264c --- /dev/null +++ b/app/src/main/java/eu/kanade/domain/ui/model/TabletUiMode.kt @@ -0,0 +1,10 @@ +package eu.kanade.domain.ui.model + +import eu.kanade.tachiyomi.R + +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), +} diff --git a/app/src/main/java/eu/kanade/domain/ui/model/ThemeMode.kt b/app/src/main/java/eu/kanade/domain/ui/model/ThemeMode.kt new file mode 100644 index 0000000000..5f0a74be93 --- /dev/null +++ b/app/src/main/java/eu/kanade/domain/ui/model/ThemeMode.kt @@ -0,0 +1,7 @@ +package eu.kanade.domain.ui.model + +enum class ThemeMode { + LIGHT, + DARK, + SYSTEM, +} diff --git a/app/src/main/java/eu/kanade/presentation/history/components/HistoryContent.kt b/app/src/main/java/eu/kanade/presentation/history/components/HistoryContent.kt index 4e7e750de1..8ab80f8a89 100644 --- a/app/src/main/java/eu/kanade/presentation/history/components/HistoryContent.kt +++ b/app/src/main/java/eu/kanade/presentation/history/components/HistoryContent.kt @@ -15,6 +15,7 @@ import androidx.compose.ui.graphics.Brush import androidx.paging.compose.LazyPagingItems import androidx.paging.compose.items import eu.kanade.domain.history.model.HistoryWithRelations +import eu.kanade.domain.ui.UiPreferences import eu.kanade.presentation.components.RelativeDateHeader import eu.kanade.presentation.components.ScrollbarLazyColumn import eu.kanade.presentation.history.HistoryUiModel @@ -22,7 +23,6 @@ import eu.kanade.presentation.util.bottomNavPaddingValues import eu.kanade.presentation.util.plus import eu.kanade.presentation.util.shimmerGradient import eu.kanade.presentation.util.topPaddingValues -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.text.DateFormat @@ -34,10 +34,10 @@ fun HistoryContent( onClickCover: (HistoryWithRelations) -> Unit, onClickResume: (HistoryWithRelations) -> Unit, onClickDelete: (HistoryWithRelations) -> Unit, - preferences: PreferencesHelper = Injekt.get(), + preferences: UiPreferences = Injekt.get(), ) { val relativeTime: Int = remember { preferences.relativeTime().get() } - val dateFormat: DateFormat = remember { preferences.dateFormat() } + val dateFormat: DateFormat = remember { UiPreferences.dateFormat(preferences.dateFormat().get()) } ScrollbarLazyColumn( contentPadding = contentPadding + bottomNavPaddingValues + topPaddingValues, diff --git a/app/src/main/java/eu/kanade/tachiyomi/App.kt b/app/src/main/java/eu/kanade/tachiyomi/App.kt index 94b7117fe0..4bd6bda2a4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/App.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/App.kt @@ -27,14 +27,15 @@ import coil.disk.DiskCache import coil.util.DebugLogger import eu.kanade.data.DatabaseHandler import eu.kanade.domain.DomainModule +import eu.kanade.domain.base.BasePreferences +import eu.kanade.domain.ui.UiPreferences +import eu.kanade.domain.ui.model.ThemeMode import eu.kanade.tachiyomi.data.coil.DomainMangaKeyer import eu.kanade.tachiyomi.data.coil.MangaCoverFetcher import eu.kanade.tachiyomi.data.coil.MangaCoverKeyer import eu.kanade.tachiyomi.data.coil.MangaKeyer import eu.kanade.tachiyomi.data.coil.TachiyomiImageDecoder import eu.kanade.tachiyomi.data.notification.Notifications -import eu.kanade.tachiyomi.data.preference.PreferenceValues -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.glance.UpdatesGridGlanceWidget import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.network.NetworkPreferences @@ -63,7 +64,8 @@ import java.security.Security class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory { - private val preferences: PreferencesHelper by injectLazy() + private val basePreferences: BasePreferences by injectLazy() + private val uiPreferences: UiPreferences by injectLazy() private val networkPreferences: NetworkPreferences by injectLazy() private val disableIncognitoReceiver = DisableIncognitoReceiver() @@ -93,7 +95,7 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory { ProcessLifecycleOwner.get().lifecycle.addObserver(this) // Show notification to disable Incognito Mode when it's enabled - preferences.incognitoMode().changes() + basePreferences.incognitoMode().changes() .onEach { enabled -> val notificationManager = NotificationManagerCompat.from(this) if (enabled) { @@ -120,13 +122,13 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory { } .launchIn(ProcessLifecycleOwner.get().lifecycleScope) - preferences.themeMode() + uiPreferences.themeMode() .asHotFlow { AppCompatDelegate.setDefaultNightMode( when (it) { - PreferenceValues.ThemeMode.light -> AppCompatDelegate.MODE_NIGHT_NO - PreferenceValues.ThemeMode.dark -> AppCompatDelegate.MODE_NIGHT_YES - PreferenceValues.ThemeMode.system -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM + ThemeMode.LIGHT -> AppCompatDelegate.MODE_NIGHT_NO + ThemeMode.DARK -> AppCompatDelegate.MODE_NIGHT_YES + ThemeMode.SYSTEM -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM }, ) }.launchIn(ProcessLifecycleOwner.get().lifecycleScope) @@ -230,7 +232,7 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory { private var registered = false override fun onReceive(context: Context, intent: Intent) { - preferences.incognitoMode().set(false) + basePreferences.incognitoMode().set(false) } fun register() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt b/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt index e518605837..f12b85783f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt @@ -14,10 +14,12 @@ import eu.kanade.data.DatabaseHandler import eu.kanade.data.dateAdapter import eu.kanade.data.listOfStringsAdapter import eu.kanade.domain.backup.service.BackupPreferences +import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.download.service.DownloadPreferences import eu.kanade.domain.library.service.LibraryPreferences import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.domain.track.service.TrackPreferences +import eu.kanade.domain.ui.UiPreferences import eu.kanade.tachiyomi.core.preference.AndroidPreferenceStore import eu.kanade.tachiyomi.core.preference.PreferenceStore import eu.kanade.tachiyomi.core.provider.AndroidBackupFolderProvider @@ -26,7 +28,6 @@ import eu.kanade.tachiyomi.core.security.SecurityPreferences import eu.kanade.tachiyomi.data.cache.ChapterCache import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.download.DownloadManager -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.saver.ImageSaver import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.job.DelayedTrackingStore @@ -182,10 +183,10 @@ class PreferenceModule(val application: Application) : InjektModule { ) } addSingletonFactory { - PreferencesHelper( - context = application, - preferenceStore = get(), - ) + UiPreferences(get()) + } + addSingletonFactory { + BasePreferences(application, get()) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt index 365bb14ee4..f934d78813 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt @@ -5,14 +5,16 @@ import android.os.Build import androidx.core.content.edit import androidx.preference.PreferenceManager import eu.kanade.domain.backup.service.BackupPreferences +import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.library.service.LibraryPreferences import eu.kanade.domain.source.service.SourcePreferences +import eu.kanade.domain.ui.UiPreferences +import eu.kanade.tachiyomi.core.preference.PreferenceStore import eu.kanade.tachiyomi.core.security.SecurityPreferences import eu.kanade.tachiyomi.data.backup.BackupCreatorJob import eu.kanade.tachiyomi.data.library.LibraryUpdateJob import eu.kanade.tachiyomi.data.preference.MANGA_NON_COMPLETED import eu.kanade.tachiyomi.data.preference.PreferenceValues -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.updater.AppUpdateJob import eu.kanade.tachiyomi.extension.ExtensionUpdateJob @@ -39,7 +41,9 @@ object Migrations { */ fun upgrade( context: Context, - preferences: PreferencesHelper, + preferenceStore: PreferenceStore, + basePreferences: BasePreferences, + uiPreferences: UiPreferences, networkPreferences: NetworkPreferences, sourcePreferences: SourcePreferences, securityPreferences: SecurityPreferences, @@ -47,9 +51,10 @@ object Migrations { readerPreferences: ReaderPreferences, backupPreferences: BackupPreferences, ): Boolean { - val oldVersion = preferences.lastVersionCode().get() + val lastVersionCode = preferenceStore.getInt("last_version_code", 0) + val oldVersion = lastVersionCode.get() if (oldVersion < BuildConfig.VERSION_CODE) { - preferences.lastVersionCode().set(BuildConfig.VERSION_CODE) + lastVersionCode.set(BuildConfig.VERSION_CODE) // Always set up background tasks to ensure they're running if (BuildConfig.INCLUDE_UPDATER) { @@ -263,8 +268,8 @@ object Migrations { if (oldSecureScreen) { securityPreferences.secureScreen().set(SecurityPreferences.SecureScreenMode.ALWAYS) } - if (DeviceUtil.isMiui && preferences.extensionInstaller().get() == PreferenceValues.ExtensionInstaller.PACKAGEINSTALLER) { - preferences.extensionInstaller().set(PreferenceValues.ExtensionInstaller.LEGACY) + if (DeviceUtil.isMiui && basePreferences.extensionInstaller().get() == PreferenceValues.ExtensionInstaller.PACKAGEINSTALLER) { + basePreferences.extensionInstaller().set(PreferenceValues.ExtensionInstaller.LEGACY) } } if (oldVersion < 76) { @@ -326,6 +331,14 @@ object Migrations { } } } + if (oldVersion < 86) { + if (uiPreferences.themeMode().isSet()) { + prefs.edit { + val themeMode = prefs.getString(uiPreferences.themeMode().key(), null) ?: return@edit + putString(uiPreferences.themeMode().key(), themeMode.uppercase()) + } + } + } return true } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt deleted file mode 100644 index 1325b44d67..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ /dev/null @@ -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" -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt index ee46723dcf..d451bd7f85 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt @@ -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), diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt deleted file mode 100644 index 24d942850f..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ /dev/null @@ -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) -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt index 42d405d0f2..b853da5e0f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt @@ -4,9 +4,9 @@ import androidx.annotation.CallSuper import androidx.annotation.ColorInt import androidx.annotation.DrawableRes import androidx.annotation.StringRes +import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.track.service.TrackPreferences import eu.kanade.tachiyomi.data.database.models.Track -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.network.NetworkHelper import okhttp3.OkHttpClient @@ -14,7 +14,7 @@ import uy.kohesive.injekt.injectLazy abstract class TrackService(val id: Long) { - val preferences: PreferencesHelper by injectLazy() + val preferences: BasePreferences by injectLazy() val trackPreferences: TrackPreferences by injectLazy() val networkService: NetworkHelper by injectLazy() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt index 3688d302fd..6839000f63 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateChecker.kt @@ -2,7 +2,8 @@ package eu.kanade.tachiyomi.data.updater import android.content.Context import eu.kanade.tachiyomi.BuildConfig -import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.core.preference.Preference +import eu.kanade.tachiyomi.core.preference.PreferenceStore import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.network.await @@ -16,11 +17,14 @@ import java.util.concurrent.TimeUnit class AppUpdateChecker { private val networkService: NetworkHelper by injectLazy() - private val preferences: PreferencesHelper by injectLazy() + private val preferenceStore: PreferenceStore by injectLazy() + private val lastAppCheck: Preference by lazy { + preferenceStore.getLong("last_app_check", 0) + } suspend fun checkForUpdate(context: Context, isUserPrompt: Boolean = false): AppUpdateResult { // Limit checks to once a day at most - if (isUserPrompt.not() && Date().time < preferences.lastAppCheck().get() + TimeUnit.DAYS.toMillis(1)) { + if (isUserPrompt.not() && Date().time < lastAppCheck.get() + TimeUnit.DAYS.toMillis(1)) { return AppUpdateResult.NoNewUpdate } @@ -30,7 +34,7 @@ class AppUpdateChecker { .await() .parseAs() .let { - preferences.lastAppCheck().set(Date().time) + lastAppCheck.set(Date().time) // Check if latest version is different from current version if (isNewVersion(it.version)) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt index 0f70dba75c..a07a75b678 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt @@ -10,10 +10,10 @@ import androidx.work.NetworkType import androidx.work.PeriodicWorkRequestBuilder import androidx.work.WorkManager import androidx.work.WorkerParameters +import eu.kanade.domain.base.BasePreferences import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.notification.Notifications -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi import eu.kanade.tachiyomi.util.system.logcat import eu.kanade.tachiyomi.util.system.notification @@ -68,7 +68,7 @@ class ExtensionUpdateJob(private val context: Context, workerParams: WorkerParam private const val TAG = "ExtensionUpdate" fun setupTask(context: Context, forceAutoUpdateJob: Boolean? = null) { - val preferences = Injekt.get() + val preferences = Injekt.get() val autoUpdateJob = forceAutoUpdateJob ?: preferences.automaticExtUpdates().get() if (autoUpdateJob) { val constraints = Constraints.Builder() diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt index 29e834f05c..d4d708eaba 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt @@ -1,7 +1,8 @@ package eu.kanade.tachiyomi.extension.api import android.content.Context -import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.core.preference.Preference +import eu.kanade.tachiyomi.core.preference.PreferenceStore import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.extension.model.AvailableSources import eu.kanade.tachiyomi.extension.model.Extension @@ -22,7 +23,10 @@ import java.util.concurrent.TimeUnit internal class ExtensionGithubApi { private val networkService: NetworkHelper by injectLazy() - private val preferences: PreferencesHelper by injectLazy() + private val preferenceStore: PreferenceStore by injectLazy() + private val lastExtCheck: Preference by lazy { + preferenceStore.getLong("last_ext_check", 0) + } private val extensionManager: ExtensionManager by injectLazy() private var requiresFallbackSource = false @@ -65,14 +69,14 @@ internal class ExtensionGithubApi { suspend fun checkForUpdates(context: Context, fromAvailableExtensionList: Boolean = false): List? { // Limit checks to once a day at most - if (fromAvailableExtensionList.not() && Date().time < preferences.lastExtCheck().get() + TimeUnit.DAYS.toMillis(1)) { + if (fromAvailableExtensionList.not() && Date().time < lastExtCheck.get() + TimeUnit.DAYS.toMillis(1)) { return null } val extensions = if (fromAvailableExtensionList) { extensionManager.availableExtensions } else { - findExtensions().also { preferences.lastExtCheck().set(Date().time) } + findExtensions().also { lastExtCheck.set(Date().time) } } val installedExtensions = ExtensionLoader.loadExtensions(context) diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstaller.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstaller.kt index 9f387b5007..0e7bb0c37f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstaller.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstaller.kt @@ -11,8 +11,8 @@ import androidx.core.content.ContextCompat import androidx.core.content.getSystemService import androidx.core.net.toUri import com.jakewharton.rxrelay.PublishRelay +import eu.kanade.domain.base.BasePreferences import eu.kanade.tachiyomi.data.preference.PreferenceValues -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.extension.installer.Installer import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.extension.model.InstallStep @@ -54,7 +54,7 @@ internal class ExtensionInstaller(private val context: Context) { */ private val downloadsRelay = PublishRelay.create>() - private val installerPref = Injekt.get().extensionInstaller() + private val extensionInstaller = Injekt.get().extensionInstaller() /** * Adds the given extension to the downloads queue and returns an observable containing its @@ -133,7 +133,7 @@ internal class ExtensionInstaller(private val context: Context) { * @param uri The uri of the extension to install. */ fun installApk(downloadId: Long, uri: Uri) { - when (val installer = installerPref.get()) { + when (val installer = extensionInstaller.get()) { PreferenceValues.ExtensionInstaller.LEGACY -> { val intent = Intent(context, ExtensionInstallActivity::class.java) .setDataAndType(uri, APK_MIME) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt index 7312d1236d..6c02fd3f6e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt @@ -3,7 +3,7 @@ package eu.kanade.tachiyomi.ui.base.activity import android.content.Context import android.os.Bundle import androidx.appcompat.app.AppCompatActivity -import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.domain.base.BasePreferences import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegate import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegateImpl import eu.kanade.tachiyomi.ui.base.delegate.ThemingDelegate @@ -16,7 +16,7 @@ open class BaseActivity : SecureActivityDelegate by SecureActivityDelegateImpl(), ThemingDelegate by ThemingDelegateImpl() { - protected val preferences: PreferencesHelper by injectLazy() + protected val preferences: BasePreferences by injectLazy() override fun attachBaseContext(newBase: Context) { super.attachBaseContext(newBase.prepareTabletUiContext()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt index 8b22dd2eef..8c35bf5b26 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt @@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.ui.base.activity import android.content.Context import android.os.Bundle -import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.domain.base.BasePreferences import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegate import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegateImpl import eu.kanade.tachiyomi.ui.base.delegate.ThemingDelegate @@ -17,7 +17,7 @@ open class BaseRxActivity

> : SecureActivityDelegate by SecureActivityDelegateImpl(), ThemingDelegate by ThemingDelegateImpl() { - protected val preferences: PreferencesHelper by injectLazy() + protected val preferences: BasePreferences by injectLazy() override fun attachBaseContext(newBase: Context) { super.attachBaseContext(newBase.prepareTabletUiContext()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/SecureActivityDelegate.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/SecureActivityDelegate.kt index 3d36d2f97a..7b5d3f6540 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/SecureActivityDelegate.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/SecureActivityDelegate.kt @@ -5,8 +5,8 @@ import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.lifecycleScope +import eu.kanade.domain.base.BasePreferences import eu.kanade.tachiyomi.core.security.SecurityPreferences -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.ui.security.UnlockActivity import eu.kanade.tachiyomi.util.system.AuthenticatorUtil import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.isAuthenticationSupported @@ -70,7 +70,7 @@ class SecureActivityDelegateImpl : SecureActivityDelegate, DefaultLifecycleObser private lateinit var activity: AppCompatActivity - private val preferences: PreferencesHelper by injectLazy() + private val preferences: BasePreferences by injectLazy() private val securityPreferences: SecurityPreferences by injectLazy() override fun registerSecureActivity(activity: AppCompatActivity) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/ThemingDelegate.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/ThemingDelegate.kt index 177e507ce2..4ad7474fe3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/ThemingDelegate.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/ThemingDelegate.kt @@ -1,9 +1,9 @@ package eu.kanade.tachiyomi.ui.base.delegate import android.app.Activity +import eu.kanade.domain.ui.UiPreferences +import eu.kanade.domain.ui.model.AppTheme import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferenceValues -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -11,37 +11,37 @@ interface ThemingDelegate { fun applyAppTheme(activity: Activity) companion object { - fun getThemeResIds(appTheme: PreferenceValues.AppTheme, isAmoled: Boolean): List { + fun getThemeResIds(appTheme: AppTheme, isAmoled: Boolean): List { val resIds = mutableListOf() when (appTheme) { - PreferenceValues.AppTheme.MONET -> { + AppTheme.MONET -> { resIds += R.style.Theme_Tachiyomi_Monet } - PreferenceValues.AppTheme.GREEN_APPLE -> { + AppTheme.GREEN_APPLE -> { resIds += R.style.Theme_Tachiyomi_GreenApple } - PreferenceValues.AppTheme.LAVENDER -> { + AppTheme.LAVENDER -> { resIds += R.style.Theme_Tachiyomi_Lavender } - PreferenceValues.AppTheme.MIDNIGHT_DUSK -> { + AppTheme.MIDNIGHT_DUSK -> { resIds += R.style.Theme_Tachiyomi_MidnightDusk } - PreferenceValues.AppTheme.STRAWBERRY_DAIQUIRI -> { + AppTheme.STRAWBERRY_DAIQUIRI -> { resIds += R.style.Theme_Tachiyomi_StrawberryDaiquiri } - PreferenceValues.AppTheme.TAKO -> { + AppTheme.TAKO -> { resIds += R.style.Theme_Tachiyomi_Tako } - PreferenceValues.AppTheme.TEALTURQUOISE -> { + AppTheme.TEALTURQUOISE -> { resIds += R.style.Theme_Tachiyomi_TealTurquoise } - PreferenceValues.AppTheme.YINYANG -> { + AppTheme.YINYANG -> { resIds += R.style.Theme_Tachiyomi_YinYang } - PreferenceValues.AppTheme.YOTSUBA -> { + AppTheme.YOTSUBA -> { resIds += R.style.Theme_Tachiyomi_Yotsuba } - PreferenceValues.AppTheme.TIDAL_WAVE -> { + AppTheme.TIDAL_WAVE -> { resIds += R.style.Theme_Tachiyomi_TidalWave } else -> { @@ -60,8 +60,8 @@ interface ThemingDelegate { class ThemingDelegateImpl : ThemingDelegate { override fun applyAppTheme(activity: Activity) { - val preferences = Injekt.get() - ThemingDelegate.getThemeResIds(preferences.appTheme().get(), preferences.themeDarkAmoled().get()) + val uiPreferences = Injekt.get() + ThemingDelegate.getThemeResIds(uiPreferences.appTheme().get(), uiPreferences.themeDarkAmoled().get()) .forEach { activity.setTheme(it) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowsePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowsePresenter.kt index 194e7ddeb4..5447bc12c4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowsePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowsePresenter.kt @@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.ui.browse import android.os.Bundle import androidx.compose.runtime.getValue -import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.domain.base.BasePreferences import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.ui.browse.extension.ExtensionsPresenter import eu.kanade.tachiyomi.ui.browse.migration.sources.MigrationSourcesPresenter @@ -11,7 +11,7 @@ import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get class BrowsePresenter( - preferences: PreferencesHelper = Injekt.get(), + preferences: BasePreferences = Injekt.get(), ) : BasePresenter() { val isDownloadOnly: Boolean by preferences.downloadedOnly().asState() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt index c6263daaaa..551a66d55f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt @@ -9,7 +9,6 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder import eu.kanade.domain.manga.interactor.GetManga import eu.kanade.domain.manga.model.Manga import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.pushController @@ -21,7 +20,6 @@ import eu.kanade.tachiyomi.util.system.getSerializableCompat import kotlinx.coroutines.runBlocking import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -import uy.kohesive.injekt.injectLazy class SearchController( private var manga: Manga? = null, @@ -101,11 +99,10 @@ class SearchController( class MigrationDialog(private val manga: Manga? = null, private val newManga: Manga? = null, private val callingController: Controller? = null) : DialogController() { - private val preferences: PreferencesHelper by injectLazy() - @Suppress("DEPRECATION") override fun onCreateDialog(savedViewState: Bundle?): Dialog { - val prefValue = preferences.migrateFlags().get() + val migrateFlags = ((targetController as SearchController).presenter as SearchPresenter).migrateFlags + val prefValue = migrateFlags.get() val enabledFlagsPositions = MigrationFlags.getEnabledFlagsPositions(prefValue) val items = MigrationFlags.titles(manga) .map { resources?.getString(it) } @@ -124,7 +121,7 @@ class SearchController( val selectedIndices = mutableListOf() selected.forEachIndexed { i, b -> if (b) selectedIndices.add(i) } val newValue = MigrationFlags.getFlagsFromPositions(selectedIndices.toTypedArray()) - preferences.migrateFlags().set(newValue) + migrateFlags.set(newValue) if (callingController != null) { if (callingController.javaClass == SourceSearchController::class.java) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt index b1e8bec3f2..97ae7bc244 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt @@ -15,6 +15,8 @@ import eu.kanade.domain.manga.model.hasCustomCover import eu.kanade.domain.manga.model.toDbManga import eu.kanade.domain.track.interactor.GetTracks import eu.kanade.domain.track.interactor.InsertTrack +import eu.kanade.tachiyomi.core.preference.Preference +import eu.kanade.tachiyomi.core.preference.PreferenceStore import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.track.EnhancedTrackService import eu.kanade.tachiyomi.data.track.TrackManager @@ -45,12 +47,17 @@ class SearchPresenter( private val getTracks: GetTracks = Injekt.get(), private val insertTrack: InsertTrack = Injekt.get(), private val setMangaCategories: SetMangaCategories = Injekt.get(), + preferenceStore: PreferenceStore = Injekt.get(), ) : GlobalSearchPresenter(initialQuery) { private val replacingMangaRelay = BehaviorRelay.create>() private val coverCache: CoverCache by injectLazy() private val enhancedServices by lazy { Injekt.get().services.filterIsInstance() } + val migrateFlags: Preference by lazy { + preferenceStore.getInt("migrate_flags", Int.MAX_VALUE) + } + override fun onCreate(savedState: Bundle?) { super.onCreate(savedState) @@ -106,7 +113,7 @@ class SearchPresenter( manga: Manga, replace: Boolean, ) { - val flags = preferences.migrateFlags().get() + val flags = migrateFlags.get() val migrateChapters = MigrationFlags.hasChapters(flags) val migrateCategories = MigrationFlags.hasCategories(flags) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesPresenter.kt index 7a0d66e498..f51aa9d5b3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourcesPresenter.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.ui.browse.source +import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.source.interactor.GetEnabledSources import eu.kanade.domain.source.interactor.ToggleSource import eu.kanade.domain.source.interactor.ToggleSourcePin @@ -9,7 +10,6 @@ import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.presentation.browse.SourceUiModel import eu.kanade.presentation.browse.SourcesState import eu.kanade.presentation.browse.SourcesStateImpl -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.system.logcat import kotlinx.coroutines.CoroutineScope @@ -25,7 +25,7 @@ import java.util.TreeMap class SourcesPresenter( private val presenterScope: CoroutineScope, private val state: SourcesStateImpl = SourcesState() as SourcesStateImpl, - private val preferences: PreferencesHelper = Injekt.get(), + private val preferences: BasePreferences = Injekt.get(), private val sourcePreferences: SourcePreferences = Injekt.get(), private val getEnabledSources: GetEnabledSources = Injekt.get(), private val toggleSource: ToggleSource = Injekt.get(), diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt index 7f348d347c..51e2915781 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourcePresenter.kt @@ -19,6 +19,7 @@ import androidx.paging.map import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.core.prefs.CheckboxState import eu.kanade.core.prefs.mapAsCheckboxState +import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.category.interactor.GetCategories import eu.kanade.domain.category.interactor.SetMangaCategories import eu.kanade.domain.chapter.interactor.GetChapterByMangaId @@ -40,7 +41,6 @@ import eu.kanade.presentation.browse.BrowseSourceStateImpl import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.toDomainManga -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.track.EnhancedTrackService import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackService @@ -87,8 +87,8 @@ open class BrowseSourcePresenter( searchQuery: String? = null, private val state: BrowseSourceStateImpl = BrowseSourceState(searchQuery) as BrowseSourceStateImpl, private val sourceManager: SourceManager = Injekt.get(), - private val preferences: PreferencesHelper = Injekt.get(), - private val sourcePreferences: SourcePreferences = Injekt.get(), + preferences: BasePreferences = Injekt.get(), + sourcePreferences: SourcePreferences = Injekt.get(), private val libraryPreferences: LibraryPreferences = Injekt.get(), private val coverCache: CoverCache = Injekt.get(), private val getRemoteManga: GetRemoteManga = Injekt.get(), diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt index b892f30b6e..02d8a9d9d1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt @@ -10,10 +10,10 @@ import androidx.appcompat.widget.SearchView import androidx.core.view.isVisible import androidx.recyclerview.widget.LinearLayoutManager import dev.chrisbanes.insetter.applyInsetter +import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.manga.model.Manga import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.databinding.GlobalSearchControllerBinding import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.ui.base.controller.SearchableNucleusController @@ -34,7 +34,7 @@ open class GlobalSearchController( GlobalSearchCardAdapter.OnMangaClickListener, GlobalSearchAdapter.OnTitleClickListener { - private val preferences: PreferencesHelper by injectLazy() + private val preferences: BasePreferences by injectLazy() private val sourcePreferences: SourcePreferences by injectLazy() /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt index ecab326d4b..0e8c10e037 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.ui.browse.source.globalsearch import android.os.Bundle +import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.manga.interactor.GetManga import eu.kanade.domain.manga.interactor.InsertManga import eu.kanade.domain.manga.interactor.UpdateManga @@ -9,7 +10,6 @@ import eu.kanade.domain.manga.model.toMangaUpdate import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.toDomainManga -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.Source @@ -35,7 +35,7 @@ open class GlobalSearchPresenter( private val initialQuery: String? = "", private val initialExtensionFilter: String? = null, val sourceManager: SourceManager = Injekt.get(), - val preferences: PreferencesHelper = Injekt.get(), + val preferences: BasePreferences = Injekt.get(), val sourcePreferences: SourcePreferences = Injekt.get(), private val getManga: GetManga = Injekt.get(), private val insertManga: InsertManga = Injekt.get(), diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 1300cbdb33..958e15ad9f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -16,6 +16,7 @@ import eu.kanade.core.prefs.PreferenceMutableState import eu.kanade.core.util.asFlow import eu.kanade.core.util.asObservable import eu.kanade.data.DatabaseHandler +import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.category.interactor.GetCategories import eu.kanade.domain.category.interactor.SetMangaCategories import eu.kanade.domain.category.model.Category @@ -40,7 +41,6 @@ import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.data.database.models.toDomainManga import eu.kanade.tachiyomi.data.download.DownloadManager -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.SManga @@ -90,7 +90,7 @@ class LibraryPresenter( private val setReadStatus: SetReadStatus = Injekt.get(), private val updateManga: UpdateManga = Injekt.get(), private val setMangaCategories: SetMangaCategories = Injekt.get(), - private val preferences: PreferencesHelper = Injekt.get(), + private val preferences: BasePreferences = Injekt.get(), private val libraryPreferences: LibraryPreferences = Injekt.get(), private val coverCache: CoverCache = Injekt.get(), private val sourceManager: SourceManager = Injekt.get(), diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt index 65b4c32a44..2e5062e48b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt @@ -4,6 +4,7 @@ import android.content.Context import android.util.AttributeSet import android.view.View import com.bluelinelabs.conductor.Router +import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.category.interactor.SetDisplayModeForCategory import eu.kanade.domain.category.interactor.SetSortModeForCategory import eu.kanade.domain.category.model.Category @@ -13,7 +14,6 @@ import eu.kanade.domain.library.model.display import eu.kanade.domain.library.model.sort import eu.kanade.domain.library.service.LibraryPreferences import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.util.lang.launchIO @@ -410,7 +410,7 @@ class LibrarySettingsSheet( open inner class Settings(context: Context, attrs: AttributeSet?) : ExtendedNavigationView(context, attrs) { - val preferences: PreferencesHelper by injectLazy() + val preferences: BasePreferences by injectLazy() val libraryPreferences: LibraryPreferences by injectLazy() lateinit var adapter: Adapter diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index d0645b5285..6d2a3a7f9d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -33,6 +33,7 @@ import com.google.android.material.transition.platform.MaterialContainerTransfor import dev.chrisbanes.insetter.applyInsetter import eu.kanade.domain.library.service.LibraryPreferences import eu.kanade.domain.source.service.SourcePreferences +import eu.kanade.domain.ui.UiPreferences import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.Migrations import eu.kanade.tachiyomi.R @@ -82,6 +83,7 @@ class MainActivity : BaseActivity() { private val sourcePreferences: SourcePreferences by injectLazy() private val libraryPreferences: LibraryPreferences by injectLazy() + private val uiPreferences: UiPreferences by injectLazy() lateinit var binding: MainActivityBinding @@ -115,7 +117,9 @@ class MainActivity : BaseActivity() { val didMigration = if (savedInstanceState == null) { Migrations.upgrade( context = applicationContext, - preferences = preferences, + basePreferences = preferences, + uiPreferences = uiPreferences, + preferenceStore = Injekt.get(), networkPreferences = Injekt.get(), sourcePreferences = sourcePreferences, securityPreferences = Injekt.get(), @@ -154,7 +158,7 @@ class MainActivity : BaseActivity() { setSplashScreenExitAnimation(splashScreen) if (binding.sideNav != null) { - preferences.sideNavIconAlignment() + uiPreferences.sideNavIconAlignment() .asHotFlow { binding.sideNav?.menuGravity = when (it) { 1 -> Gravity.CENTER @@ -510,7 +514,7 @@ class MainActivity : BaseActivity() { lifecycleScope.launchUI { resetExitConfirmation() } } else if (backstackSize == 1 || !router.handleBack()) { // Regular back (i.e. closing the app) - if (preferences.autoClearChapterCache().get()) { + if (libraryPreferences.autoClearChapterCache().get()) { chapterCache.clear() } super.onBackPressed() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt index 3eed4df0ed..c25611509a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt @@ -6,6 +6,7 @@ import android.os.Bundle import androidx.compose.runtime.Immutable import eu.kanade.core.prefs.CheckboxState import eu.kanade.core.prefs.mapAsCheckboxState +import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.category.interactor.GetCategories import eu.kanade.domain.category.interactor.SetMangaCategories import eu.kanade.domain.category.model.Category @@ -30,11 +31,11 @@ import eu.kanade.domain.track.interactor.GetTracks import eu.kanade.domain.track.interactor.InsertTrack import eu.kanade.domain.track.model.toDbTrack import eu.kanade.domain.track.model.toDomainTrack +import eu.kanade.domain.ui.UiPreferences import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.model.Download -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.track.EnhancedTrackService import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackService @@ -82,7 +83,8 @@ import eu.kanade.domain.manga.model.Manga as DomainManga class MangaPresenter( val mangaId: Long, val isFromSource: Boolean, - private val preferences: PreferencesHelper = Injekt.get(), + private val basePreferences: BasePreferences = Injekt.get(), + private val uiPreferences: UiPreferences = Injekt.get(), private val downloadPreferences: DownloadPreferences = Injekt.get(), private val libraryPreferences: LibraryPreferences = Injekt.get(), private val trackManager: TrackManager = Injekt.get(), @@ -189,8 +191,8 @@ class MangaPresenter( val chapterItems = chapters.toChapterItems( context = view?.activity ?: Injekt.get(), manga = manga, - dateRelativeTime = preferences.relativeTime().get(), - dateFormat = preferences.dateFormat(), + dateRelativeTime = uiPreferences.relativeTime().get(), + dateFormat = UiPreferences.dateFormat(uiPreferences.dateFormat().get()), ) updateSuccessState { it.copy( @@ -213,11 +215,11 @@ class MangaPresenter( } } - preferences.incognitoMode() + basePreferences.incognitoMode() .asHotFlow { incognitoMode = it } .launchIn(presenterScope) - preferences.downloadedOnly() + basePreferences.downloadedOnly() .asHotFlow { downloadedOnlyMode = it } .launchIn(presenterScope) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackHolder.kt index 8400ed4058..d417a88c94 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackHolder.kt @@ -3,8 +3,8 @@ package eu.kanade.tachiyomi.ui.manga.track import android.annotation.SuppressLint import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView +import eu.kanade.domain.ui.UiPreferences import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.databinding.TrackItemBinding import eu.kanade.tachiyomi.util.view.popupMenu import uy.kohesive.injekt.injectLazy @@ -12,10 +12,10 @@ import java.text.DateFormat class TrackHolder(private val binding: TrackItemBinding, adapter: TrackAdapter) : RecyclerView.ViewHolder(binding.root) { - private val preferences: PreferencesHelper by injectLazy() + private val preferences: UiPreferences by injectLazy() private val dateFormat: DateFormat by lazy { - preferences.dateFormat() + UiPreferences.dateFormat(preferences.dateFormat().get()) } private val listener = adapter.rowClickListener diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt index 1d32451869..e2108310dd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt @@ -1,10 +1,10 @@ package eu.kanade.tachiyomi.ui.more import androidx.compose.runtime.Composable +import eu.kanade.domain.ui.UiPreferences import eu.kanade.presentation.more.about.AboutScreen import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.updater.AppUpdateChecker import eu.kanade.tachiyomi.data.updater.AppUpdateResult import eu.kanade.tachiyomi.ui.base.controller.BasicFullComposeController @@ -23,7 +23,7 @@ import java.util.TimeZone class AboutController : BasicFullComposeController() { - private val preferences: PreferencesHelper by injectLazy() + private val preferences: UiPreferences by injectLazy() private val updateChecker by lazy { AppUpdateChecker() } @Composable @@ -78,7 +78,7 @@ class AboutController : BasicFullComposeController() { ) outputDf.timeZone = TimeZone.getDefault() - buildTime!!.toDateTimestampString(preferences.dateFormat()) + buildTime!!.toDateTimestampString(UiPreferences.dateFormat(preferences.dateFormat().get())) } catch (e: Exception) { BuildConfig.BUILD_TIME } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MorePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MorePresenter.kt index e9cc3f4906..8ea2ed57ab 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MorePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MorePresenter.kt @@ -1,9 +1,9 @@ package eu.kanade.tachiyomi.ui.more import android.os.Bundle +import eu.kanade.domain.base.BasePreferences import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadService -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.util.lang.launchIO import kotlinx.coroutines.flow.MutableStateFlow @@ -18,7 +18,8 @@ import uy.kohesive.injekt.api.get class MorePresenter( private val downloadManager: DownloadManager = Injekt.get(), - preferences: PreferencesHelper = Injekt.get(), + preferences: BasePreferences = Injekt.get(), + ) : BasePresenter() { val downloadedOnly = preferences.downloadedOnly().asState() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index 5d7fbfa753..5b1bcfc738 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -5,6 +5,7 @@ import android.content.Context import android.net.Uri import android.os.Bundle import com.jakewharton.rxrelay.BehaviorRelay +import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.chapter.interactor.GetChapterByMangaId import eu.kanade.domain.chapter.interactor.UpdateChapter import eu.kanade.domain.chapter.model.ChapterUpdate @@ -25,7 +26,6 @@ import eu.kanade.tachiyomi.data.database.models.toDomainChapter import eu.kanade.tachiyomi.data.database.models.toDomainManga import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.model.Download -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.saver.Image import eu.kanade.tachiyomi.data.saver.ImageSaver import eu.kanade.tachiyomi.data.saver.Location @@ -80,7 +80,7 @@ import eu.kanade.tachiyomi.data.database.models.Chapter as DbChapter class ReaderPresenter( private val sourceManager: SourceManager = Injekt.get(), private val downloadManager: DownloadManager = Injekt.get(), - private val preferences: PreferencesHelper = Injekt.get(), + preferences: BasePreferences = Injekt.get(), private val downloadPreferences: DownloadPreferences = Injekt.get(), private val readerPreferences: ReaderPreferences = Injekt.get(), private val trackPreferences: TrackPreferences = Injekt.get(), diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt index 8904a314e0..a01fbd8975 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryPresenter.kt @@ -13,6 +13,7 @@ import androidx.paging.compose.LazyPagingItems import androidx.paging.compose.collectAsLazyPagingItems import androidx.paging.insertSeparators import androidx.paging.map +import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.chapter.model.Chapter import eu.kanade.domain.history.interactor.DeleteHistoryTable import eu.kanade.domain.history.interactor.GetHistory @@ -22,7 +23,6 @@ import eu.kanade.domain.history.interactor.RemoveHistoryByMangaId import eu.kanade.domain.history.model.HistoryWithRelations import eu.kanade.presentation.history.HistoryUiModel import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.toDateKey @@ -46,7 +46,7 @@ class HistoryPresenter( private val deleteHistoryTable: DeleteHistoryTable = Injekt.get(), private val removeHistoryById: RemoveHistoryById = Injekt.get(), private val removeHistoryByMangaId: RemoveHistoryByMangaId = Injekt.get(), - preferences: PreferencesHelper = Injekt.get(), + preferences: BasePreferences = Injekt.get(), ) : BasePresenter(), HistoryState by state { private val _events: Channel = Channel(Int.MAX_VALUE) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt index d800076112..3712f99218 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesPresenter.kt @@ -4,6 +4,7 @@ import android.os.Bundle import androidx.compose.runtime.Immutable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf +import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.chapter.interactor.GetChapter import eu.kanade.domain.chapter.interactor.SetReadStatus import eu.kanade.domain.chapter.interactor.UpdateChapter @@ -11,6 +12,7 @@ import eu.kanade.domain.chapter.model.ChapterUpdate import eu.kanade.domain.chapter.model.toDbChapter import eu.kanade.domain.library.service.LibraryPreferences import eu.kanade.domain.manga.interactor.GetManga +import eu.kanade.domain.ui.UiPreferences import eu.kanade.domain.updates.interactor.GetUpdates import eu.kanade.domain.updates.model.UpdatesWithRelations import eu.kanade.presentation.components.ChapterDownloadAction @@ -19,7 +21,6 @@ import eu.kanade.presentation.updates.UpdatesStateImpl import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadService import eu.kanade.tachiyomi.data.download.model.Download -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.util.lang.launchIO @@ -32,6 +33,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.distinctUntilChanged +import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.launch import logcat.LogPriority @@ -50,17 +52,18 @@ class UpdatesPresenter( private val sourceManager: SourceManager = Injekt.get(), private val downloadManager: DownloadManager = Injekt.get(), private val getChapter: GetChapter = Injekt.get(), - preferences: PreferencesHelper = Injekt.get(), + basePreferences: BasePreferences = Injekt.get(), + uiPreferences: UiPreferences = Injekt.get(), libraryPreferences: LibraryPreferences = Injekt.get(), ) : BasePresenter(), UpdatesState by state { - val isDownloadOnly: Boolean by preferences.downloadedOnly().asState() - val isIncognitoMode: Boolean by preferences.incognitoMode().asState() + val isDownloadOnly: Boolean by basePreferences.downloadedOnly().asState() + val isIncognitoMode: Boolean by basePreferences.incognitoMode().asState() val lastUpdated by libraryPreferences.libraryUpdateLastTimestamp().asState() - val relativeTime: Int by preferences.relativeTime().asState() - val dateFormat: DateFormat by mutableStateOf(preferences.dateFormat()) + val relativeTime: Int by uiPreferences.relativeTime().asState() + val dateFormat: DateFormat by mutableStateOf(UiPreferences.dateFormat(uiPreferences.dateFormat().get())) private val _events: Channel = Channel(Int.MAX_VALUE) val events: Flow = _events.receiveAsFlow() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt index 4c3d72b4b5..778592899e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt @@ -9,7 +9,10 @@ import android.webkit.WebView import androidx.core.net.toUri import androidx.preference.PreferenceScreen import com.google.android.material.dialog.MaterialAlertDialogBuilder +import eu.kanade.domain.library.service.LibraryPreferences import eu.kanade.domain.manga.repository.MangaRepository +import eu.kanade.domain.ui.UiPreferences +import eu.kanade.domain.ui.model.TabletUiMode import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.cache.ChapterCache import eu.kanade.tachiyomi.data.library.LibraryUpdateService @@ -70,6 +73,8 @@ class SettingsAdvancedController( private val chapterCache: ChapterCache by injectLazy() private val trackManager: TrackManager by injectLazy() private val networkPreferences: NetworkPreferences by injectLazy() + private val libraryPreferences: LibraryPreferences by injectLazy() + private val uiPreferences: UiPreferences by injectLazy() @SuppressLint("BatteryLife") override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { @@ -156,7 +161,7 @@ class SettingsAdvancedController( onClick { clearChapterCache() } } switchPreference { - bindTo(preferences.autoClearChapterCache()) + bindTo(libraryPreferences.autoClearChapterCache()) titleRes = R.string.pref_auto_clear_chapter_cache } preference { @@ -327,11 +332,11 @@ class SettingsAdvancedController( titleRes = R.string.pref_category_display listPreference { - bindTo(preferences.tabletUiMode()) + bindTo(uiPreferences.tabletUiMode()) titleRes = R.string.pref_tablet_ui_mode summary = "%s" - entriesRes = PreferenceValues.TabletUiMode.values().map { it.titleResId }.toTypedArray() - entryValues = PreferenceValues.TabletUiMode.values().map { it.name }.toTypedArray() + entriesRes = TabletUiMode.values().map { it.titleResId }.toTypedArray() + entryValues = TabletUiMode.values().map { it.name }.toTypedArray() onChange { activity?.toast(R.string.requires_app_restart) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAppearanceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAppearanceController.kt index 8f2ee0c30e..9de77183c2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAppearanceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAppearanceController.kt @@ -5,9 +5,11 @@ import android.os.Bundle import android.view.View import androidx.core.app.ActivityCompat import androidx.preference.PreferenceScreen +import eu.kanade.domain.ui.UiPreferences +import eu.kanade.domain.ui.model.AppTheme +import eu.kanade.domain.ui.model.ThemeMode import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.preference.bindTo -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 @@ -20,13 +22,13 @@ import eu.kanade.tachiyomi.util.system.DeviceUtil import eu.kanade.tachiyomi.util.system.isDynamicColorAvailable import eu.kanade.tachiyomi.util.system.isTablet import eu.kanade.tachiyomi.widget.preference.ThemesPreference +import uy.kohesive.injekt.injectLazy 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() { private var themesPreference: ThemesPreference? = null + private val uiPreferences: UiPreferences by injectLazy() override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { titleRes = R.string.pref_category_appearance @@ -35,7 +37,7 @@ class SettingsAppearanceController : SettingsController() { titleRes = R.string.pref_category_theme listPreference { - bindTo(preferences.themeMode()) + bindTo(uiPreferences.themeMode()) titleRes = R.string.pref_theme_mode if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { @@ -45,9 +47,9 @@ class SettingsAppearanceController : SettingsController() { R.string.theme_dark, ) entryValues = arrayOf( - Values.ThemeMode.system.name, - Values.ThemeMode.light.name, - Values.ThemeMode.dark.name, + ThemeMode.SYSTEM.name, + ThemeMode.LIGHT.name, + ThemeMode.DARK.name, ) } else { entriesRes = arrayOf( @@ -55,19 +57,19 @@ class SettingsAppearanceController : SettingsController() { R.string.theme_dark, ) entryValues = arrayOf( - Values.ThemeMode.light.name, - Values.ThemeMode.dark.name, + ThemeMode.LIGHT.name, + ThemeMode.DARK.name, ) } summary = "%s" } themesPreference = initThenAdd(ThemesPreference(context)) { - bindTo(preferences.appTheme()) + bindTo(uiPreferences.appTheme()) titleRes = R.string.pref_app_theme - val appThemes = Values.AppTheme.values().filter { - val monetFilter = if (it == Values.AppTheme.MONET) { + val appThemes = AppTheme.values().filter { + val monetFilter = if (it == AppTheme.MONET) { DeviceUtil.isDynamicColorAvailable } else { true @@ -82,10 +84,10 @@ class SettingsAppearanceController : SettingsController() { } } switchPreference { - bindTo(preferences.themeDarkAmoled()) + bindTo(uiPreferences.themeDarkAmoled()) titleRes = R.string.pref_dark_theme_pure_black - visibleIf(preferences.themeMode()) { it != Values.ThemeMode.light } + visibleIf(uiPreferences.themeMode()) { it != ThemeMode.LIGHT } onChange { activity?.let { ActivityCompat.recreate(it) } @@ -99,7 +101,7 @@ class SettingsAppearanceController : SettingsController() { titleRes = R.string.pref_category_navigation intListPreference { - bindTo(preferences.sideNavIconAlignment()) + bindTo(uiPreferences.sideNavIconAlignment()) titleRes = R.string.pref_side_nav_icon_alignment entriesRes = arrayOf( R.string.alignment_top, @@ -116,7 +118,7 @@ class SettingsAppearanceController : SettingsController() { titleRes = R.string.pref_category_timestamps intListPreference { - bindTo(preferences.relativeTime()) + bindTo(uiPreferences.relativeTime()) titleRes = R.string.pref_relative_format val values = arrayOf("0", "2", "7") entryValues = values @@ -131,13 +133,13 @@ class SettingsAppearanceController : SettingsController() { } listPreference { - key = Keys.dateFormat + bindTo(uiPreferences.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) + val formattedDate = UiPreferences.dateFormat(value.toString()).format(now) if (value == "") { "${context.getString(R.string.label_default)} ($formattedDate)" } else { @@ -145,7 +147,6 @@ class SettingsAppearanceController : SettingsController() { } }.toTypedArray() - defaultValue = "" summary = "%s" } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt index 79445818f6..ecef08a430 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt @@ -19,8 +19,8 @@ import androidx.preference.PreferenceScreen import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeType import dev.chrisbanes.insetter.applyInsetter +import eu.kanade.domain.base.BasePreferences import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.util.preference.asHotFlow import eu.kanade.tachiyomi.util.system.getResourceColor import kotlinx.coroutines.CoroutineScope @@ -33,7 +33,7 @@ import uy.kohesive.injekt.api.get abstract class SettingsController : PreferenceController() { var preferenceKey: String? = null - val preferences: PreferencesHelper = Injekt.get() + val preferences: BasePreferences = Injekt.get() val viewScope: CoroutineScope = MainScope() private var themedContext: Context? = null diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/search/SettingsSearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/search/SettingsSearchPresenter.kt index e30574b5d5..8b41612703 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/search/SettingsSearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/search/SettingsSearchPresenter.kt @@ -1,7 +1,7 @@ package eu.kanade.tachiyomi.ui.setting.search import android.os.Bundle -import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.domain.base.BasePreferences import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -10,7 +10,7 @@ import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get class SettingsSearchPresenter( - private val preferences: PreferencesHelper = Injekt.get(), + private val preferences: BasePreferences = Injekt.get(), ) : BasePresenter() { private val _state: MutableStateFlow> = diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt index bedbc5a279..075859c065 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt @@ -36,9 +36,9 @@ import androidx.core.graphics.green import androidx.core.graphics.red import androidx.core.net.toUri import com.hippo.unifile.UniFile +import eu.kanade.domain.ui.UiPreferences +import eu.kanade.domain.ui.model.TabletUiMode import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferenceValues -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.ui.base.delegate.ThemingDelegate import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences import eu.kanade.tachiyomi.util.lang.truncateCenter @@ -262,11 +262,11 @@ fun Context.isTablet(): Boolean { fun Context.prepareTabletUiContext(): Context { val configuration = resources.configuration - val expected = when (Injekt.get().tabletUiMode().get()) { - PreferenceValues.TabletUiMode.AUTOMATIC -> isTablet() - PreferenceValues.TabletUiMode.ALWAYS -> true - PreferenceValues.TabletUiMode.LANDSCAPE -> configuration.orientation == Configuration.ORIENTATION_LANDSCAPE - PreferenceValues.TabletUiMode.NEVER -> false + val expected = when (Injekt.get().tabletUiMode().get()) { + TabletUiMode.AUTOMATIC -> isTablet() + TabletUiMode.ALWAYS -> true + TabletUiMode.LANDSCAPE -> configuration.orientation == Configuration.ORIENTATION_LANDSCAPE + TabletUiMode.NEVER -> false } if (configuration.smallestScreenWidthDp >= TABLET_UI_MIN_SCREEN_WIDTH_DP != expected) { val overrideConf = Configuration() @@ -295,7 +295,7 @@ fun Context.isNightMode(): Boolean { * https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:appcompat/appcompat/src/main/java/androidx/appcompat/app/AppCompatDelegateImpl.java;l=348;drc=e28752c96fc3fb4d3354781469a1af3dbded4898 */ fun Context.createReaderThemeContext(): Context { - val preferences = Injekt.get() + val preferences = Injekt.get() val readerPreferences = Injekt.get() val isDarkBackground = when (readerPreferences.readerTheme().get()) { 1, 2 -> true // Black, Gray diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/TachiyomiSearchView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/TachiyomiSearchView.kt index 5c77eca76a..5cf3d2c4c4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/TachiyomiSearchView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/TachiyomiSearchView.kt @@ -5,8 +5,8 @@ import android.util.AttributeSet import android.view.inputmethod.EditorInfo import androidx.appcompat.widget.SearchView import androidx.core.view.inputmethod.EditorInfoCompat +import eu.kanade.domain.base.BasePreferences import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.util.preference.asHotFlow import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -18,7 +18,7 @@ import uy.kohesive.injekt.api.get /** * A custom [SearchView] that sets [EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING] to imeOptions - * if [PreferencesHelper.incognitoMode] is true. Some IMEs may not respect this flag. + * if [BasePreferences.incognitoMode] is true. Some IMEs may not respect this flag. */ class TachiyomiSearchView @JvmOverloads constructor( context: Context, @@ -31,7 +31,7 @@ class TachiyomiSearchView @JvmOverloads constructor( override fun onAttachedToWindow() { super.onAttachedToWindow() scope = CoroutineScope(SupervisorJob() + Dispatchers.Main) - Injekt.get().incognitoMode() + Injekt.get().incognitoMode() .asHotFlow { imeOptions = if (it) { imeOptions or EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/TachiyomiTextInputEditText.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/TachiyomiTextInputEditText.kt index 4c227efd01..bf77d38fdf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/TachiyomiTextInputEditText.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/TachiyomiTextInputEditText.kt @@ -5,8 +5,8 @@ import android.util.AttributeSet import android.widget.EditText import androidx.core.view.inputmethod.EditorInfoCompat import com.google.android.material.textfield.TextInputEditText +import eu.kanade.domain.base.BasePreferences import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.util.preference.asHotFlow import eu.kanade.tachiyomi.widget.TachiyomiTextInputEditText.Companion.setIncognito import kotlinx.coroutines.CoroutineScope @@ -19,7 +19,7 @@ import uy.kohesive.injekt.api.get /** * A custom [TextInputEditText] that sets [EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING] to imeOptions - * if [PreferencesHelper.incognitoMode] is true. Some IMEs may not respect this flag. + * if [BasePreferences.incognitoMode] is true. Some IMEs may not respect this flag. * * @see setIncognito */ @@ -46,10 +46,10 @@ class TachiyomiTextInputEditText @JvmOverloads constructor( companion object { /** * Sets Flow to this [EditText] that sets [EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING] to imeOptions - * if [PreferencesHelper.incognitoMode] is true. Some IMEs may not respect this flag. + * if [BasePreferences.incognitoMode] is true. Some IMEs may not respect this flag. */ fun EditText.setIncognito(viewScope: CoroutineScope) { - Injekt.get().incognitoMode() + Injekt.get().incognitoMode() .asHotFlow { imeOptions = if (it) { imeOptions or EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt index 6d46885cdc..4374c6da2d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/LoginDialogPreference.kt @@ -9,8 +9,8 @@ import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeType import com.dd.processbutton.iml.ActionProcessButton import com.google.android.material.dialog.MaterialAlertDialogBuilder +import eu.kanade.domain.base.BasePreferences import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.databinding.PrefAccountLoginBinding import eu.kanade.tachiyomi.ui.base.controller.DialogController import uy.kohesive.injekt.injectLazy @@ -23,7 +23,7 @@ abstract class LoginDialogPreference( var binding: PrefAccountLoginBinding? = null private set - val preferences: PreferencesHelper by injectLazy() + val preferences: BasePreferences by injectLazy() override fun onCreateDialog(savedViewState: Bundle?): Dialog { binding = PrefAccountLoginBinding.inflate(LayoutInflater.from(activity!!)) diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ThemesPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ThemesPreference.kt index 576859fe6b..10bcb688db 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ThemesPreference.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ThemesPreference.kt @@ -6,8 +6,8 @@ import androidx.preference.ListPreference import androidx.preference.PreferenceViewHolder import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView +import eu.kanade.domain.ui.model.AppTheme import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferenceValues import eu.kanade.tachiyomi.util.system.dpToPx class ThemesPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : @@ -19,7 +19,7 @@ class ThemesPreference @JvmOverloads constructor(context: Context, attrs: Attrib var lastScrollPosition: Int? = null - var entries: List = emptyList() + var entries: List = emptyList() set(value) { field = value adapter.setItems(value) diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ThemesPreferenceAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ThemesPreferenceAdapter.kt index 4c5bd324d7..f4169257f4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ThemesPreferenceAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ThemesPreferenceAdapter.kt @@ -5,9 +5,9 @@ import android.view.View import android.view.ViewGroup import androidx.appcompat.view.ContextThemeWrapper import androidx.recyclerview.widget.RecyclerView +import eu.kanade.domain.ui.UiPreferences +import eu.kanade.domain.ui.model.AppTheme import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferenceValues -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.databinding.PrefThemeItemBinding import eu.kanade.tachiyomi.ui.base.delegate.ThemingDelegate import eu.kanade.tachiyomi.util.system.getResourceColor @@ -16,9 +16,9 @@ import uy.kohesive.injekt.injectLazy class ThemesPreferenceAdapter(private val clickListener: OnItemClickListener) : RecyclerView.Adapter() { - private val preferences: PreferencesHelper by injectLazy() + private val preferences: UiPreferences by injectLazy() - private var themes = emptyList() + private var themes = emptyList() private lateinit var binding: PrefThemeItemBinding @@ -41,7 +41,7 @@ class ThemesPreferenceAdapter(private val clickListener: OnItemClickListener) : holder.bind(themes[position]) } - fun setItems(themes: List) { + fun setItems(themes: List) { this.themes = themes notifyDataSetChanged() } @@ -51,7 +51,7 @@ class ThemesPreferenceAdapter(private val clickListener: OnItemClickListener) : private val selectedColor = view.context.getResourceColor(R.attr.colorAccent) private val unselectedColor = view.context.getResourceColor(android.R.attr.divider) - fun bind(appTheme: PreferenceValues.AppTheme) { + fun bind(appTheme: AppTheme) { binding.name.text = view.context.getString(appTheme.titleResId!!) // For rounded corners