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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
51 changed files with 319 additions and 275 deletions

View File

@ -27,7 +27,7 @@ android {
applicationId = "eu.kanade.tachiyomi" applicationId = "eu.kanade.tachiyomi"
minSdk = AndroidConfig.minSdk minSdk = AndroidConfig.minSdk
targetSdk = AndroidConfig.targetSdk targetSdk = AndroidConfig.targetSdk
versionCode = 85 versionCode = 86
versionName = "0.13.6" versionName = "0.13.6"
buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"") buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"")

View File

@ -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,
)
}

View File

@ -103,5 +103,7 @@ class LibraryPreferences(
sortChapterByAscendingOrDescending().set(if (manga.sortDescending()) Manga.CHAPTER_SORT_DESC else Manga.CHAPTER_SORT_ASC) sortChapterByAscendingOrDescending().set(if (manga.sortDescending()) Manga.CHAPTER_SORT_DESC else Manga.CHAPTER_SORT_ASC)
} }
fun autoClearChapterCache() = preferenceStore.getBoolean("auto_clear_chapter_cache", false)
// endregion // endregion
} }

View File

@ -1,9 +1,9 @@
package eu.kanade.domain.manga.model package eu.kanade.domain.manga.model
import eu.kanade.data.listOfStringsAdapter import eu.kanade.data.listOfStringsAdapter
import eu.kanade.domain.base.BasePreferences
import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.cache.CoverCache
import eu.kanade.tachiyomi.data.database.models.MangaImpl 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.LocalSource
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.widget.ExtendedNavigationView import eu.kanade.tachiyomi.widget.ExtendedNavigationView
@ -78,7 +78,7 @@ data class Manga(
} }
fun forceDownloaded(): Boolean { fun forceDownloaded(): Boolean {
return favorite && Injekt.get<PreferencesHelper>().downloadedOnly().get() return favorite && Injekt.get<BasePreferences>().downloadedOnly().get()
} }
fun sortDescending(): Boolean { fun sortDescending(): Boolean {

View File

@ -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())
}
}
}

View File

@ -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),
}

View File

@ -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),
}

View File

@ -0,0 +1,7 @@
package eu.kanade.domain.ui.model
enum class ThemeMode {
LIGHT,
DARK,
SYSTEM,
}

View File

@ -15,6 +15,7 @@ import androidx.compose.ui.graphics.Brush
import androidx.paging.compose.LazyPagingItems import androidx.paging.compose.LazyPagingItems
import androidx.paging.compose.items import androidx.paging.compose.items
import eu.kanade.domain.history.model.HistoryWithRelations import eu.kanade.domain.history.model.HistoryWithRelations
import eu.kanade.domain.ui.UiPreferences
import eu.kanade.presentation.components.RelativeDateHeader import eu.kanade.presentation.components.RelativeDateHeader
import eu.kanade.presentation.components.ScrollbarLazyColumn import eu.kanade.presentation.components.ScrollbarLazyColumn
import eu.kanade.presentation.history.HistoryUiModel 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.plus
import eu.kanade.presentation.util.shimmerGradient import eu.kanade.presentation.util.shimmerGradient
import eu.kanade.presentation.util.topPaddingValues import eu.kanade.presentation.util.topPaddingValues
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.text.DateFormat import java.text.DateFormat
@ -34,10 +34,10 @@ fun HistoryContent(
onClickCover: (HistoryWithRelations) -> Unit, onClickCover: (HistoryWithRelations) -> Unit,
onClickResume: (HistoryWithRelations) -> Unit, onClickResume: (HistoryWithRelations) -> Unit,
onClickDelete: (HistoryWithRelations) -> Unit, onClickDelete: (HistoryWithRelations) -> Unit,
preferences: PreferencesHelper = Injekt.get(), preferences: UiPreferences = Injekt.get(),
) { ) {
val relativeTime: Int = remember { preferences.relativeTime().get() } val relativeTime: Int = remember { preferences.relativeTime().get() }
val dateFormat: DateFormat = remember { preferences.dateFormat() } val dateFormat: DateFormat = remember { UiPreferences.dateFormat(preferences.dateFormat().get()) }
ScrollbarLazyColumn( ScrollbarLazyColumn(
contentPadding = contentPadding + bottomNavPaddingValues + topPaddingValues, contentPadding = contentPadding + bottomNavPaddingValues + topPaddingValues,

View File

@ -27,14 +27,15 @@ import coil.disk.DiskCache
import coil.util.DebugLogger import coil.util.DebugLogger
import eu.kanade.data.DatabaseHandler import eu.kanade.data.DatabaseHandler
import eu.kanade.domain.DomainModule 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.DomainMangaKeyer
import eu.kanade.tachiyomi.data.coil.MangaCoverFetcher import eu.kanade.tachiyomi.data.coil.MangaCoverFetcher
import eu.kanade.tachiyomi.data.coil.MangaCoverKeyer import eu.kanade.tachiyomi.data.coil.MangaCoverKeyer
import eu.kanade.tachiyomi.data.coil.MangaKeyer import eu.kanade.tachiyomi.data.coil.MangaKeyer
import eu.kanade.tachiyomi.data.coil.TachiyomiImageDecoder import eu.kanade.tachiyomi.data.coil.TachiyomiImageDecoder
import eu.kanade.tachiyomi.data.notification.Notifications 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.glance.UpdatesGridGlanceWidget
import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.network.NetworkHelper
import eu.kanade.tachiyomi.network.NetworkPreferences import eu.kanade.tachiyomi.network.NetworkPreferences
@ -63,7 +64,8 @@ import java.security.Security
class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory { 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 networkPreferences: NetworkPreferences by injectLazy()
private val disableIncognitoReceiver = DisableIncognitoReceiver() private val disableIncognitoReceiver = DisableIncognitoReceiver()
@ -93,7 +95,7 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
ProcessLifecycleOwner.get().lifecycle.addObserver(this) ProcessLifecycleOwner.get().lifecycle.addObserver(this)
// Show notification to disable Incognito Mode when it's enabled // Show notification to disable Incognito Mode when it's enabled
preferences.incognitoMode().changes() basePreferences.incognitoMode().changes()
.onEach { enabled -> .onEach { enabled ->
val notificationManager = NotificationManagerCompat.from(this) val notificationManager = NotificationManagerCompat.from(this)
if (enabled) { if (enabled) {
@ -120,13 +122,13 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
} }
.launchIn(ProcessLifecycleOwner.get().lifecycleScope) .launchIn(ProcessLifecycleOwner.get().lifecycleScope)
preferences.themeMode() uiPreferences.themeMode()
.asHotFlow { .asHotFlow {
AppCompatDelegate.setDefaultNightMode( AppCompatDelegate.setDefaultNightMode(
when (it) { when (it) {
PreferenceValues.ThemeMode.light -> AppCompatDelegate.MODE_NIGHT_NO ThemeMode.LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
PreferenceValues.ThemeMode.dark -> AppCompatDelegate.MODE_NIGHT_YES ThemeMode.DARK -> AppCompatDelegate.MODE_NIGHT_YES
PreferenceValues.ThemeMode.system -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM ThemeMode.SYSTEM -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}, },
) )
}.launchIn(ProcessLifecycleOwner.get().lifecycleScope) }.launchIn(ProcessLifecycleOwner.get().lifecycleScope)
@ -230,7 +232,7 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
private var registered = false private var registered = false
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
preferences.incognitoMode().set(false) basePreferences.incognitoMode().set(false)
} }
fun register() { fun register() {

View File

@ -14,10 +14,12 @@ import eu.kanade.data.DatabaseHandler
import eu.kanade.data.dateAdapter import eu.kanade.data.dateAdapter
import eu.kanade.data.listOfStringsAdapter import eu.kanade.data.listOfStringsAdapter
import eu.kanade.domain.backup.service.BackupPreferences import eu.kanade.domain.backup.service.BackupPreferences
import eu.kanade.domain.base.BasePreferences
import eu.kanade.domain.download.service.DownloadPreferences import eu.kanade.domain.download.service.DownloadPreferences
import eu.kanade.domain.library.service.LibraryPreferences import eu.kanade.domain.library.service.LibraryPreferences
import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.domain.source.service.SourcePreferences
import eu.kanade.domain.track.service.TrackPreferences 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.AndroidPreferenceStore
import eu.kanade.tachiyomi.core.preference.PreferenceStore import eu.kanade.tachiyomi.core.preference.PreferenceStore
import eu.kanade.tachiyomi.core.provider.AndroidBackupFolderProvider 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.ChapterCache
import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.cache.CoverCache
import eu.kanade.tachiyomi.data.download.DownloadManager 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.saver.ImageSaver
import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.data.track.job.DelayedTrackingStore import eu.kanade.tachiyomi.data.track.job.DelayedTrackingStore
@ -182,10 +183,10 @@ class PreferenceModule(val application: Application) : InjektModule {
) )
} }
addSingletonFactory { addSingletonFactory {
PreferencesHelper( UiPreferences(get())
context = application, }
preferenceStore = get(), addSingletonFactory {
) BasePreferences(application, get())
} }
} }
} }

View File

@ -5,14 +5,16 @@ import android.os.Build
import androidx.core.content.edit import androidx.core.content.edit
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import eu.kanade.domain.backup.service.BackupPreferences import eu.kanade.domain.backup.service.BackupPreferences
import eu.kanade.domain.base.BasePreferences
import eu.kanade.domain.library.service.LibraryPreferences import eu.kanade.domain.library.service.LibraryPreferences
import eu.kanade.domain.source.service.SourcePreferences 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.core.security.SecurityPreferences
import eu.kanade.tachiyomi.data.backup.BackupCreatorJob import eu.kanade.tachiyomi.data.backup.BackupCreatorJob
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
import eu.kanade.tachiyomi.data.preference.MANGA_NON_COMPLETED import eu.kanade.tachiyomi.data.preference.MANGA_NON_COMPLETED
import eu.kanade.tachiyomi.data.preference.PreferenceValues 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.track.TrackManager
import eu.kanade.tachiyomi.data.updater.AppUpdateJob import eu.kanade.tachiyomi.data.updater.AppUpdateJob
import eu.kanade.tachiyomi.extension.ExtensionUpdateJob import eu.kanade.tachiyomi.extension.ExtensionUpdateJob
@ -39,7 +41,9 @@ object Migrations {
*/ */
fun upgrade( fun upgrade(
context: Context, context: Context,
preferences: PreferencesHelper, preferenceStore: PreferenceStore,
basePreferences: BasePreferences,
uiPreferences: UiPreferences,
networkPreferences: NetworkPreferences, networkPreferences: NetworkPreferences,
sourcePreferences: SourcePreferences, sourcePreferences: SourcePreferences,
securityPreferences: SecurityPreferences, securityPreferences: SecurityPreferences,
@ -47,9 +51,10 @@ object Migrations {
readerPreferences: ReaderPreferences, readerPreferences: ReaderPreferences,
backupPreferences: BackupPreferences, backupPreferences: BackupPreferences,
): Boolean { ): Boolean {
val oldVersion = preferences.lastVersionCode().get() val lastVersionCode = preferenceStore.getInt("last_version_code", 0)
val oldVersion = lastVersionCode.get()
if (oldVersion < BuildConfig.VERSION_CODE) { 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 // Always set up background tasks to ensure they're running
if (BuildConfig.INCLUDE_UPDATER) { if (BuildConfig.INCLUDE_UPDATER) {
@ -263,8 +268,8 @@ object Migrations {
if (oldSecureScreen) { if (oldSecureScreen) {
securityPreferences.secureScreen().set(SecurityPreferences.SecureScreenMode.ALWAYS) securityPreferences.secureScreen().set(SecurityPreferences.SecureScreenMode.ALWAYS)
} }
if (DeviceUtil.isMiui && preferences.extensionInstaller().get() == PreferenceValues.ExtensionInstaller.PACKAGEINSTALLER) { if (DeviceUtil.isMiui && basePreferences.extensionInstaller().get() == PreferenceValues.ExtensionInstaller.PACKAGEINSTALLER) {
preferences.extensionInstaller().set(PreferenceValues.ExtensionInstaller.LEGACY) basePreferences.extensionInstaller().set(PreferenceValues.ExtensionInstaller.LEGACY)
} }
} }
if (oldVersion < 76) { 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 return true
} }

View File

@ -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"
}

View File

@ -16,38 +16,6 @@ const val MANGA_NON_READ = "manga_started"
*/ */
object PreferenceValues { 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) { enum class TappingInvertMode(val shouldInvertHorizontal: Boolean = false, val shouldInvertVertical: Boolean = false) {
NONE, NONE,
HORIZONTAL(shouldInvertHorizontal = true), HORIZONTAL(shouldInvertHorizontal = true),
@ -62,13 +30,6 @@ object PreferenceValues {
LOWEST(47), 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) { enum class ExtensionInstaller(val titleResId: Int) {
LEGACY(R.string.ext_installer_legacy), LEGACY(R.string.ext_installer_legacy),
PACKAGEINSTALLER(R.string.ext_installer_packageinstaller), PACKAGEINSTALLER(R.string.ext_installer_packageinstaller),

View File

@ -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)
}

View File

@ -4,9 +4,9 @@ import androidx.annotation.CallSuper
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.annotation.StringRes import androidx.annotation.StringRes
import eu.kanade.domain.base.BasePreferences
import eu.kanade.domain.track.service.TrackPreferences import eu.kanade.domain.track.service.TrackPreferences
import eu.kanade.tachiyomi.data.database.models.Track 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.data.track.model.TrackSearch
import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.network.NetworkHelper
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
@ -14,7 +14,7 @@ import uy.kohesive.injekt.injectLazy
abstract class TrackService(val id: Long) { abstract class TrackService(val id: Long) {
val preferences: PreferencesHelper by injectLazy() val preferences: BasePreferences by injectLazy()
val trackPreferences: TrackPreferences by injectLazy() val trackPreferences: TrackPreferences by injectLazy()
val networkService: NetworkHelper by injectLazy() val networkService: NetworkHelper by injectLazy()

View File

@ -2,7 +2,8 @@ package eu.kanade.tachiyomi.data.updater
import android.content.Context import android.content.Context
import eu.kanade.tachiyomi.BuildConfig 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.GET
import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.network.NetworkHelper
import eu.kanade.tachiyomi.network.await import eu.kanade.tachiyomi.network.await
@ -16,11 +17,14 @@ import java.util.concurrent.TimeUnit
class AppUpdateChecker { class AppUpdateChecker {
private val networkService: NetworkHelper by injectLazy() private val networkService: NetworkHelper by injectLazy()
private val preferences: PreferencesHelper by injectLazy() private val preferenceStore: PreferenceStore by injectLazy()
private val lastAppCheck: Preference<Long> by lazy {
preferenceStore.getLong("last_app_check", 0)
}
suspend fun checkForUpdate(context: Context, isUserPrompt: Boolean = false): AppUpdateResult { suspend fun checkForUpdate(context: Context, isUserPrompt: Boolean = false): AppUpdateResult {
// Limit checks to once a day at most // 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 return AppUpdateResult.NoNewUpdate
} }
@ -30,7 +34,7 @@ class AppUpdateChecker {
.await() .await()
.parseAs<GithubRelease>() .parseAs<GithubRelease>()
.let { .let {
preferences.lastAppCheck().set(Date().time) lastAppCheck.set(Date().time)
// Check if latest version is different from current version // Check if latest version is different from current version
if (isNewVersion(it.version)) { if (isNewVersion(it.version)) {

View File

@ -10,10 +10,10 @@ import androidx.work.NetworkType
import androidx.work.PeriodicWorkRequestBuilder import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager import androidx.work.WorkManager
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import eu.kanade.domain.base.BasePreferences
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.data.notification.Notifications 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.extension.api.ExtensionGithubApi
import eu.kanade.tachiyomi.util.system.logcat import eu.kanade.tachiyomi.util.system.logcat
import eu.kanade.tachiyomi.util.system.notification import eu.kanade.tachiyomi.util.system.notification
@ -68,7 +68,7 @@ class ExtensionUpdateJob(private val context: Context, workerParams: WorkerParam
private const val TAG = "ExtensionUpdate" private const val TAG = "ExtensionUpdate"
fun setupTask(context: Context, forceAutoUpdateJob: Boolean? = null) { fun setupTask(context: Context, forceAutoUpdateJob: Boolean? = null) {
val preferences = Injekt.get<PreferencesHelper>() val preferences = Injekt.get<BasePreferences>()
val autoUpdateJob = forceAutoUpdateJob ?: preferences.automaticExtUpdates().get() val autoUpdateJob = forceAutoUpdateJob ?: preferences.automaticExtUpdates().get()
if (autoUpdateJob) { if (autoUpdateJob) {
val constraints = Constraints.Builder() val constraints = Constraints.Builder()

View File

@ -1,7 +1,8 @@
package eu.kanade.tachiyomi.extension.api package eu.kanade.tachiyomi.extension.api
import android.content.Context 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.ExtensionManager
import eu.kanade.tachiyomi.extension.model.AvailableSources import eu.kanade.tachiyomi.extension.model.AvailableSources
import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.extension.model.Extension
@ -22,7 +23,10 @@ import java.util.concurrent.TimeUnit
internal class ExtensionGithubApi { internal class ExtensionGithubApi {
private val networkService: NetworkHelper by injectLazy() private val networkService: NetworkHelper by injectLazy()
private val preferences: PreferencesHelper by injectLazy() private val preferenceStore: PreferenceStore by injectLazy()
private val lastExtCheck: Preference<Long> by lazy {
preferenceStore.getLong("last_ext_check", 0)
}
private val extensionManager: ExtensionManager by injectLazy() private val extensionManager: ExtensionManager by injectLazy()
private var requiresFallbackSource = false private var requiresFallbackSource = false
@ -65,14 +69,14 @@ internal class ExtensionGithubApi {
suspend fun checkForUpdates(context: Context, fromAvailableExtensionList: Boolean = false): List<Extension.Installed>? { suspend fun checkForUpdates(context: Context, fromAvailableExtensionList: Boolean = false): List<Extension.Installed>? {
// Limit checks to once a day at most // 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 return null
} }
val extensions = if (fromAvailableExtensionList) { val extensions = if (fromAvailableExtensionList) {
extensionManager.availableExtensions extensionManager.availableExtensions
} else { } else {
findExtensions().also { preferences.lastExtCheck().set(Date().time) } findExtensions().also { lastExtCheck.set(Date().time) }
} }
val installedExtensions = ExtensionLoader.loadExtensions(context) val installedExtensions = ExtensionLoader.loadExtensions(context)

View File

@ -11,8 +11,8 @@ import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService import androidx.core.content.getSystemService
import androidx.core.net.toUri import androidx.core.net.toUri
import com.jakewharton.rxrelay.PublishRelay import com.jakewharton.rxrelay.PublishRelay
import eu.kanade.domain.base.BasePreferences
import eu.kanade.tachiyomi.data.preference.PreferenceValues 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.installer.Installer
import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.extension.model.Extension
import eu.kanade.tachiyomi.extension.model.InstallStep import eu.kanade.tachiyomi.extension.model.InstallStep
@ -54,7 +54,7 @@ internal class ExtensionInstaller(private val context: Context) {
*/ */
private val downloadsRelay = PublishRelay.create<Pair<Long, InstallStep>>() private val downloadsRelay = PublishRelay.create<Pair<Long, InstallStep>>()
private val installerPref = Injekt.get<PreferencesHelper>().extensionInstaller() private val extensionInstaller = Injekt.get<BasePreferences>().extensionInstaller()
/** /**
* Adds the given extension to the downloads queue and returns an observable containing its * 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. * @param uri The uri of the extension to install.
*/ */
fun installApk(downloadId: Long, uri: Uri) { fun installApk(downloadId: Long, uri: Uri) {
when (val installer = installerPref.get()) { when (val installer = extensionInstaller.get()) {
PreferenceValues.ExtensionInstaller.LEGACY -> { PreferenceValues.ExtensionInstaller.LEGACY -> {
val intent = Intent(context, ExtensionInstallActivity::class.java) val intent = Intent(context, ExtensionInstallActivity::class.java)
.setDataAndType(uri, APK_MIME) .setDataAndType(uri, APK_MIME)

View File

@ -3,7 +3,7 @@ package eu.kanade.tachiyomi.ui.base.activity
import android.content.Context import android.content.Context
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity 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.SecureActivityDelegate
import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegateImpl import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegateImpl
import eu.kanade.tachiyomi.ui.base.delegate.ThemingDelegate import eu.kanade.tachiyomi.ui.base.delegate.ThemingDelegate
@ -16,7 +16,7 @@ open class BaseActivity :
SecureActivityDelegate by SecureActivityDelegateImpl(), SecureActivityDelegate by SecureActivityDelegateImpl(),
ThemingDelegate by ThemingDelegateImpl() { ThemingDelegate by ThemingDelegateImpl() {
protected val preferences: PreferencesHelper by injectLazy() protected val preferences: BasePreferences by injectLazy()
override fun attachBaseContext(newBase: Context) { override fun attachBaseContext(newBase: Context) {
super.attachBaseContext(newBase.prepareTabletUiContext()) super.attachBaseContext(newBase.prepareTabletUiContext())

View File

@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.ui.base.activity
import android.content.Context import android.content.Context
import android.os.Bundle 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.SecureActivityDelegate
import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegateImpl import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegateImpl
import eu.kanade.tachiyomi.ui.base.delegate.ThemingDelegate import eu.kanade.tachiyomi.ui.base.delegate.ThemingDelegate
@ -17,7 +17,7 @@ open class BaseRxActivity<P : BasePresenter<*>> :
SecureActivityDelegate by SecureActivityDelegateImpl(), SecureActivityDelegate by SecureActivityDelegateImpl(),
ThemingDelegate by ThemingDelegateImpl() { ThemingDelegate by ThemingDelegateImpl() {
protected val preferences: PreferencesHelper by injectLazy() protected val preferences: BasePreferences by injectLazy()
override fun attachBaseContext(newBase: Context) { override fun attachBaseContext(newBase: Context) {
super.attachBaseContext(newBase.prepareTabletUiContext()) super.attachBaseContext(newBase.prepareTabletUiContext())

View File

@ -5,8 +5,8 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import eu.kanade.domain.base.BasePreferences
import eu.kanade.tachiyomi.core.security.SecurityPreferences 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.ui.security.UnlockActivity
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil import eu.kanade.tachiyomi.util.system.AuthenticatorUtil
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.isAuthenticationSupported import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.isAuthenticationSupported
@ -70,7 +70,7 @@ class SecureActivityDelegateImpl : SecureActivityDelegate, DefaultLifecycleObser
private lateinit var activity: AppCompatActivity private lateinit var activity: AppCompatActivity
private val preferences: PreferencesHelper by injectLazy() private val preferences: BasePreferences by injectLazy()
private val securityPreferences: SecurityPreferences by injectLazy() private val securityPreferences: SecurityPreferences by injectLazy()
override fun registerSecureActivity(activity: AppCompatActivity) { override fun registerSecureActivity(activity: AppCompatActivity) {

View File

@ -1,9 +1,9 @@
package eu.kanade.tachiyomi.ui.base.delegate package eu.kanade.tachiyomi.ui.base.delegate
import android.app.Activity 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.R
import eu.kanade.tachiyomi.data.preference.PreferenceValues
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -11,37 +11,37 @@ interface ThemingDelegate {
fun applyAppTheme(activity: Activity) fun applyAppTheme(activity: Activity)
companion object { companion object {
fun getThemeResIds(appTheme: PreferenceValues.AppTheme, isAmoled: Boolean): List<Int> { fun getThemeResIds(appTheme: AppTheme, isAmoled: Boolean): List<Int> {
val resIds = mutableListOf<Int>() val resIds = mutableListOf<Int>()
when (appTheme) { when (appTheme) {
PreferenceValues.AppTheme.MONET -> { AppTheme.MONET -> {
resIds += R.style.Theme_Tachiyomi_Monet resIds += R.style.Theme_Tachiyomi_Monet
} }
PreferenceValues.AppTheme.GREEN_APPLE -> { AppTheme.GREEN_APPLE -> {
resIds += R.style.Theme_Tachiyomi_GreenApple resIds += R.style.Theme_Tachiyomi_GreenApple
} }
PreferenceValues.AppTheme.LAVENDER -> { AppTheme.LAVENDER -> {
resIds += R.style.Theme_Tachiyomi_Lavender resIds += R.style.Theme_Tachiyomi_Lavender
} }
PreferenceValues.AppTheme.MIDNIGHT_DUSK -> { AppTheme.MIDNIGHT_DUSK -> {
resIds += R.style.Theme_Tachiyomi_MidnightDusk resIds += R.style.Theme_Tachiyomi_MidnightDusk
} }
PreferenceValues.AppTheme.STRAWBERRY_DAIQUIRI -> { AppTheme.STRAWBERRY_DAIQUIRI -> {
resIds += R.style.Theme_Tachiyomi_StrawberryDaiquiri resIds += R.style.Theme_Tachiyomi_StrawberryDaiquiri
} }
PreferenceValues.AppTheme.TAKO -> { AppTheme.TAKO -> {
resIds += R.style.Theme_Tachiyomi_Tako resIds += R.style.Theme_Tachiyomi_Tako
} }
PreferenceValues.AppTheme.TEALTURQUOISE -> { AppTheme.TEALTURQUOISE -> {
resIds += R.style.Theme_Tachiyomi_TealTurquoise resIds += R.style.Theme_Tachiyomi_TealTurquoise
} }
PreferenceValues.AppTheme.YINYANG -> { AppTheme.YINYANG -> {
resIds += R.style.Theme_Tachiyomi_YinYang resIds += R.style.Theme_Tachiyomi_YinYang
} }
PreferenceValues.AppTheme.YOTSUBA -> { AppTheme.YOTSUBA -> {
resIds += R.style.Theme_Tachiyomi_Yotsuba resIds += R.style.Theme_Tachiyomi_Yotsuba
} }
PreferenceValues.AppTheme.TIDAL_WAVE -> { AppTheme.TIDAL_WAVE -> {
resIds += R.style.Theme_Tachiyomi_TidalWave resIds += R.style.Theme_Tachiyomi_TidalWave
} }
else -> { else -> {
@ -60,8 +60,8 @@ interface ThemingDelegate {
class ThemingDelegateImpl : ThemingDelegate { class ThemingDelegateImpl : ThemingDelegate {
override fun applyAppTheme(activity: Activity) { override fun applyAppTheme(activity: Activity) {
val preferences = Injekt.get<PreferencesHelper>() val uiPreferences = Injekt.get<UiPreferences>()
ThemingDelegate.getThemeResIds(preferences.appTheme().get(), preferences.themeDarkAmoled().get()) ThemingDelegate.getThemeResIds(uiPreferences.appTheme().get(), uiPreferences.themeDarkAmoled().get())
.forEach { activity.setTheme(it) } .forEach { activity.setTheme(it) }
} }
} }

View File

@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.ui.browse
import android.os.Bundle import android.os.Bundle
import androidx.compose.runtime.getValue 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.base.presenter.BasePresenter
import eu.kanade.tachiyomi.ui.browse.extension.ExtensionsPresenter import eu.kanade.tachiyomi.ui.browse.extension.ExtensionsPresenter
import eu.kanade.tachiyomi.ui.browse.migration.sources.MigrationSourcesPresenter import eu.kanade.tachiyomi.ui.browse.migration.sources.MigrationSourcesPresenter
@ -11,7 +11,7 @@ import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
class BrowsePresenter( class BrowsePresenter(
preferences: PreferencesHelper = Injekt.get(), preferences: BasePreferences = Injekt.get(),
) : BasePresenter<BrowseController>() { ) : BasePresenter<BrowseController>() {
val isDownloadOnly: Boolean by preferences.downloadedOnly().asState() val isDownloadOnly: Boolean by preferences.downloadedOnly().asState()

View File

@ -9,7 +9,6 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
import eu.kanade.domain.manga.interactor.GetManga import eu.kanade.domain.manga.interactor.GetManga
import eu.kanade.domain.manga.model.Manga import eu.kanade.domain.manga.model.Manga
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.ui.base.controller.pushController import eu.kanade.tachiyomi.ui.base.controller.pushController
@ -21,7 +20,6 @@ import eu.kanade.tachiyomi.util.system.getSerializableCompat
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
class SearchController( class SearchController(
private var manga: Manga? = null, 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() { 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") @Suppress("DEPRECATION")
override fun onCreateDialog(savedViewState: Bundle?): Dialog { 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 enabledFlagsPositions = MigrationFlags.getEnabledFlagsPositions(prefValue)
val items = MigrationFlags.titles(manga) val items = MigrationFlags.titles(manga)
.map { resources?.getString(it) } .map { resources?.getString(it) }
@ -124,7 +121,7 @@ class SearchController(
val selectedIndices = mutableListOf<Int>() val selectedIndices = mutableListOf<Int>()
selected.forEachIndexed { i, b -> if (b) selectedIndices.add(i) } selected.forEachIndexed { i, b -> if (b) selectedIndices.add(i) }
val newValue = MigrationFlags.getFlagsFromPositions(selectedIndices.toTypedArray()) val newValue = MigrationFlags.getFlagsFromPositions(selectedIndices.toTypedArray())
preferences.migrateFlags().set(newValue) migrateFlags.set(newValue)
if (callingController != null) { if (callingController != null) {
if (callingController.javaClass == SourceSearchController::class.java) { if (callingController.javaClass == SourceSearchController::class.java) {

View File

@ -15,6 +15,8 @@ import eu.kanade.domain.manga.model.hasCustomCover
import eu.kanade.domain.manga.model.toDbManga import eu.kanade.domain.manga.model.toDbManga
import eu.kanade.domain.track.interactor.GetTracks import eu.kanade.domain.track.interactor.GetTracks
import eu.kanade.domain.track.interactor.InsertTrack 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.cache.CoverCache
import eu.kanade.tachiyomi.data.track.EnhancedTrackService import eu.kanade.tachiyomi.data.track.EnhancedTrackService
import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackManager
@ -45,12 +47,17 @@ class SearchPresenter(
private val getTracks: GetTracks = Injekt.get(), private val getTracks: GetTracks = Injekt.get(),
private val insertTrack: InsertTrack = Injekt.get(), private val insertTrack: InsertTrack = Injekt.get(),
private val setMangaCategories: SetMangaCategories = Injekt.get(), private val setMangaCategories: SetMangaCategories = Injekt.get(),
preferenceStore: PreferenceStore = Injekt.get(),
) : GlobalSearchPresenter(initialQuery) { ) : GlobalSearchPresenter(initialQuery) {
private val replacingMangaRelay = BehaviorRelay.create<Pair<Boolean, Manga?>>() private val replacingMangaRelay = BehaviorRelay.create<Pair<Boolean, Manga?>>()
private val coverCache: CoverCache by injectLazy() private val coverCache: CoverCache by injectLazy()
private val enhancedServices by lazy { Injekt.get<TrackManager>().services.filterIsInstance<EnhancedTrackService>() } private val enhancedServices by lazy { Injekt.get<TrackManager>().services.filterIsInstance<EnhancedTrackService>() }
val migrateFlags: Preference<Int> by lazy {
preferenceStore.getInt("migrate_flags", Int.MAX_VALUE)
}
override fun onCreate(savedState: Bundle?) { override fun onCreate(savedState: Bundle?) {
super.onCreate(savedState) super.onCreate(savedState)
@ -106,7 +113,7 @@ class SearchPresenter(
manga: Manga, manga: Manga,
replace: Boolean, replace: Boolean,
) { ) {
val flags = preferences.migrateFlags().get() val flags = migrateFlags.get()
val migrateChapters = MigrationFlags.hasChapters(flags) val migrateChapters = MigrationFlags.hasChapters(flags)
val migrateCategories = MigrationFlags.hasCategories(flags) val migrateCategories = MigrationFlags.hasCategories(flags)

View File

@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.ui.browse.source 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.GetEnabledSources
import eu.kanade.domain.source.interactor.ToggleSource import eu.kanade.domain.source.interactor.ToggleSource
import eu.kanade.domain.source.interactor.ToggleSourcePin 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.SourceUiModel
import eu.kanade.presentation.browse.SourcesState import eu.kanade.presentation.browse.SourcesState
import eu.kanade.presentation.browse.SourcesStateImpl 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.lang.launchIO
import eu.kanade.tachiyomi.util.system.logcat import eu.kanade.tachiyomi.util.system.logcat
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@ -25,7 +25,7 @@ import java.util.TreeMap
class SourcesPresenter( class SourcesPresenter(
private val presenterScope: CoroutineScope, private val presenterScope: CoroutineScope,
private val state: SourcesStateImpl = SourcesState() as SourcesStateImpl, 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 sourcePreferences: SourcePreferences = Injekt.get(),
private val getEnabledSources: GetEnabledSources = Injekt.get(), private val getEnabledSources: GetEnabledSources = Injekt.get(),
private val toggleSource: ToggleSource = Injekt.get(), private val toggleSource: ToggleSource = Injekt.get(),

View File

@ -19,6 +19,7 @@ import androidx.paging.map
import eu.davidea.flexibleadapter.items.IFlexible import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.core.prefs.CheckboxState import eu.kanade.core.prefs.CheckboxState
import eu.kanade.core.prefs.mapAsCheckboxState 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.GetCategories
import eu.kanade.domain.category.interactor.SetMangaCategories import eu.kanade.domain.category.interactor.SetMangaCategories
import eu.kanade.domain.chapter.interactor.GetChapterByMangaId 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.cache.CoverCache
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.database.models.toDomainManga 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.EnhancedTrackService
import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.data.track.TrackService
@ -87,8 +87,8 @@ open class BrowseSourcePresenter(
searchQuery: String? = null, searchQuery: String? = null,
private val state: BrowseSourceStateImpl = BrowseSourceState(searchQuery) as BrowseSourceStateImpl, private val state: BrowseSourceStateImpl = BrowseSourceState(searchQuery) as BrowseSourceStateImpl,
private val sourceManager: SourceManager = Injekt.get(), private val sourceManager: SourceManager = Injekt.get(),
private val preferences: PreferencesHelper = Injekt.get(), preferences: BasePreferences = Injekt.get(),
private val sourcePreferences: SourcePreferences = Injekt.get(), sourcePreferences: SourcePreferences = Injekt.get(),
private val libraryPreferences: LibraryPreferences = Injekt.get(), private val libraryPreferences: LibraryPreferences = Injekt.get(),
private val coverCache: CoverCache = Injekt.get(), private val coverCache: CoverCache = Injekt.get(),
private val getRemoteManga: GetRemoteManga = Injekt.get(), private val getRemoteManga: GetRemoteManga = Injekt.get(),

View File

@ -10,10 +10,10 @@ import androidx.appcompat.widget.SearchView
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import dev.chrisbanes.insetter.applyInsetter import dev.chrisbanes.insetter.applyInsetter
import eu.kanade.domain.base.BasePreferences
import eu.kanade.domain.manga.model.Manga import eu.kanade.domain.manga.model.Manga
import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.domain.source.service.SourcePreferences
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.databinding.GlobalSearchControllerBinding import eu.kanade.tachiyomi.databinding.GlobalSearchControllerBinding
import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.ui.base.controller.SearchableNucleusController import eu.kanade.tachiyomi.ui.base.controller.SearchableNucleusController
@ -34,7 +34,7 @@ open class GlobalSearchController(
GlobalSearchCardAdapter.OnMangaClickListener, GlobalSearchCardAdapter.OnMangaClickListener,
GlobalSearchAdapter.OnTitleClickListener { GlobalSearchAdapter.OnTitleClickListener {
private val preferences: PreferencesHelper by injectLazy() private val preferences: BasePreferences by injectLazy()
private val sourcePreferences: SourcePreferences by injectLazy() private val sourcePreferences: SourcePreferences by injectLazy()
/** /**

View File

@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.ui.browse.source.globalsearch package eu.kanade.tachiyomi.ui.browse.source.globalsearch
import android.os.Bundle import android.os.Bundle
import eu.kanade.domain.base.BasePreferences
import eu.kanade.domain.manga.interactor.GetManga import eu.kanade.domain.manga.interactor.GetManga
import eu.kanade.domain.manga.interactor.InsertManga import eu.kanade.domain.manga.interactor.InsertManga
import eu.kanade.domain.manga.interactor.UpdateManga 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.domain.source.service.SourcePreferences
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.database.models.toDomainManga 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.extension.ExtensionManager
import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.Source
@ -35,7 +35,7 @@ open class GlobalSearchPresenter(
private val initialQuery: String? = "", private val initialQuery: String? = "",
private val initialExtensionFilter: String? = null, private val initialExtensionFilter: String? = null,
val sourceManager: SourceManager = Injekt.get(), val sourceManager: SourceManager = Injekt.get(),
val preferences: PreferencesHelper = Injekt.get(), val preferences: BasePreferences = Injekt.get(),
val sourcePreferences: SourcePreferences = Injekt.get(), val sourcePreferences: SourcePreferences = Injekt.get(),
private val getManga: GetManga = Injekt.get(), private val getManga: GetManga = Injekt.get(),
private val insertManga: InsertManga = Injekt.get(), private val insertManga: InsertManga = Injekt.get(),

View File

@ -16,6 +16,7 @@ import eu.kanade.core.prefs.PreferenceMutableState
import eu.kanade.core.util.asFlow import eu.kanade.core.util.asFlow
import eu.kanade.core.util.asObservable import eu.kanade.core.util.asObservable
import eu.kanade.data.DatabaseHandler import eu.kanade.data.DatabaseHandler
import eu.kanade.domain.base.BasePreferences
import eu.kanade.domain.category.interactor.GetCategories import eu.kanade.domain.category.interactor.GetCategories
import eu.kanade.domain.category.interactor.SetMangaCategories import eu.kanade.domain.category.interactor.SetMangaCategories
import eu.kanade.domain.category.model.Category 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.LibraryManga
import eu.kanade.tachiyomi.data.database.models.toDomainManga import eu.kanade.tachiyomi.data.database.models.toDomainManga
import eu.kanade.tachiyomi.data.download.DownloadManager 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.data.track.TrackManager
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
@ -90,7 +90,7 @@ class LibraryPresenter(
private val setReadStatus: SetReadStatus = Injekt.get(), private val setReadStatus: SetReadStatus = Injekt.get(),
private val updateManga: UpdateManga = Injekt.get(), private val updateManga: UpdateManga = Injekt.get(),
private val setMangaCategories: SetMangaCategories = 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 libraryPreferences: LibraryPreferences = Injekt.get(),
private val coverCache: CoverCache = Injekt.get(), private val coverCache: CoverCache = Injekt.get(),
private val sourceManager: SourceManager = Injekt.get(), private val sourceManager: SourceManager = Injekt.get(),

View File

@ -4,6 +4,7 @@ import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View import android.view.View
import com.bluelinelabs.conductor.Router import com.bluelinelabs.conductor.Router
import eu.kanade.domain.base.BasePreferences
import eu.kanade.domain.category.interactor.SetDisplayModeForCategory import eu.kanade.domain.category.interactor.SetDisplayModeForCategory
import eu.kanade.domain.category.interactor.SetSortModeForCategory import eu.kanade.domain.category.interactor.SetSortModeForCategory
import eu.kanade.domain.category.model.Category 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.model.sort
import eu.kanade.domain.library.service.LibraryPreferences import eu.kanade.domain.library.service.LibraryPreferences
import eu.kanade.tachiyomi.R 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.TrackManager
import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.data.track.TrackService
import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.launchIO
@ -410,7 +410,7 @@ class LibrarySettingsSheet(
open inner class Settings(context: Context, attrs: AttributeSet?) : open inner class Settings(context: Context, attrs: AttributeSet?) :
ExtendedNavigationView(context, attrs) { ExtendedNavigationView(context, attrs) {
val preferences: PreferencesHelper by injectLazy() val preferences: BasePreferences by injectLazy()
val libraryPreferences: LibraryPreferences by injectLazy() val libraryPreferences: LibraryPreferences by injectLazy()
lateinit var adapter: Adapter lateinit var adapter: Adapter

View File

@ -33,6 +33,7 @@ import com.google.android.material.transition.platform.MaterialContainerTransfor
import dev.chrisbanes.insetter.applyInsetter import dev.chrisbanes.insetter.applyInsetter
import eu.kanade.domain.library.service.LibraryPreferences import eu.kanade.domain.library.service.LibraryPreferences
import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.domain.source.service.SourcePreferences
import eu.kanade.domain.ui.UiPreferences
import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.Migrations import eu.kanade.tachiyomi.Migrations
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
@ -82,6 +83,7 @@ class MainActivity : BaseActivity() {
private val sourcePreferences: SourcePreferences by injectLazy() private val sourcePreferences: SourcePreferences by injectLazy()
private val libraryPreferences: LibraryPreferences by injectLazy() private val libraryPreferences: LibraryPreferences by injectLazy()
private val uiPreferences: UiPreferences by injectLazy()
lateinit var binding: MainActivityBinding lateinit var binding: MainActivityBinding
@ -115,7 +117,9 @@ class MainActivity : BaseActivity() {
val didMigration = if (savedInstanceState == null) { val didMigration = if (savedInstanceState == null) {
Migrations.upgrade( Migrations.upgrade(
context = applicationContext, context = applicationContext,
preferences = preferences, basePreferences = preferences,
uiPreferences = uiPreferences,
preferenceStore = Injekt.get(),
networkPreferences = Injekt.get(), networkPreferences = Injekt.get(),
sourcePreferences = sourcePreferences, sourcePreferences = sourcePreferences,
securityPreferences = Injekt.get(), securityPreferences = Injekt.get(),
@ -154,7 +158,7 @@ class MainActivity : BaseActivity() {
setSplashScreenExitAnimation(splashScreen) setSplashScreenExitAnimation(splashScreen)
if (binding.sideNav != null) { if (binding.sideNav != null) {
preferences.sideNavIconAlignment() uiPreferences.sideNavIconAlignment()
.asHotFlow { .asHotFlow {
binding.sideNav?.menuGravity = when (it) { binding.sideNav?.menuGravity = when (it) {
1 -> Gravity.CENTER 1 -> Gravity.CENTER
@ -510,7 +514,7 @@ class MainActivity : BaseActivity() {
lifecycleScope.launchUI { resetExitConfirmation() } lifecycleScope.launchUI { resetExitConfirmation() }
} else if (backstackSize == 1 || !router.handleBack()) { } else if (backstackSize == 1 || !router.handleBack()) {
// Regular back (i.e. closing the app) // Regular back (i.e. closing the app)
if (preferences.autoClearChapterCache().get()) { if (libraryPreferences.autoClearChapterCache().get()) {
chapterCache.clear() chapterCache.clear()
} }
super.onBackPressed() super.onBackPressed()

View File

@ -6,6 +6,7 @@ import android.os.Bundle
import androidx.compose.runtime.Immutable import androidx.compose.runtime.Immutable
import eu.kanade.core.prefs.CheckboxState import eu.kanade.core.prefs.CheckboxState
import eu.kanade.core.prefs.mapAsCheckboxState 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.GetCategories
import eu.kanade.domain.category.interactor.SetMangaCategories import eu.kanade.domain.category.interactor.SetMangaCategories
import eu.kanade.domain.category.model.Category 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.interactor.InsertTrack
import eu.kanade.domain.track.model.toDbTrack import eu.kanade.domain.track.model.toDbTrack
import eu.kanade.domain.track.model.toDomainTrack import eu.kanade.domain.track.model.toDomainTrack
import eu.kanade.domain.ui.UiPreferences
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.database.models.Track
import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.download.model.Download 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.EnhancedTrackService
import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.data.track.TrackService
@ -82,7 +83,8 @@ import eu.kanade.domain.manga.model.Manga as DomainManga
class MangaPresenter( class MangaPresenter(
val mangaId: Long, val mangaId: Long,
val isFromSource: Boolean, 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 downloadPreferences: DownloadPreferences = Injekt.get(),
private val libraryPreferences: LibraryPreferences = Injekt.get(), private val libraryPreferences: LibraryPreferences = Injekt.get(),
private val trackManager: TrackManager = Injekt.get(), private val trackManager: TrackManager = Injekt.get(),
@ -189,8 +191,8 @@ class MangaPresenter(
val chapterItems = chapters.toChapterItems( val chapterItems = chapters.toChapterItems(
context = view?.activity ?: Injekt.get<Application>(), context = view?.activity ?: Injekt.get<Application>(),
manga = manga, manga = manga,
dateRelativeTime = preferences.relativeTime().get(), dateRelativeTime = uiPreferences.relativeTime().get(),
dateFormat = preferences.dateFormat(), dateFormat = UiPreferences.dateFormat(uiPreferences.dateFormat().get()),
) )
updateSuccessState { updateSuccessState {
it.copy( it.copy(
@ -213,11 +215,11 @@ class MangaPresenter(
} }
} }
preferences.incognitoMode() basePreferences.incognitoMode()
.asHotFlow { incognitoMode = it } .asHotFlow { incognitoMode = it }
.launchIn(presenterScope) .launchIn(presenterScope)
preferences.downloadedOnly() basePreferences.downloadedOnly()
.asHotFlow { downloadedOnlyMode = it } .asHotFlow { downloadedOnlyMode = it }
.launchIn(presenterScope) .launchIn(presenterScope)
} }

View File

@ -3,8 +3,8 @@ package eu.kanade.tachiyomi.ui.manga.track
import android.annotation.SuppressLint import android.annotation.SuppressLint
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import eu.kanade.domain.ui.UiPreferences
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.databinding.TrackItemBinding import eu.kanade.tachiyomi.databinding.TrackItemBinding
import eu.kanade.tachiyomi.util.view.popupMenu import eu.kanade.tachiyomi.util.view.popupMenu
import uy.kohesive.injekt.injectLazy 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) { 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 { private val dateFormat: DateFormat by lazy {
preferences.dateFormat() UiPreferences.dateFormat(preferences.dateFormat().get())
} }
private val listener = adapter.rowClickListener private val listener = adapter.rowClickListener

View File

@ -1,10 +1,10 @@
package eu.kanade.tachiyomi.ui.more package eu.kanade.tachiyomi.ui.more
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import eu.kanade.domain.ui.UiPreferences
import eu.kanade.presentation.more.about.AboutScreen import eu.kanade.presentation.more.about.AboutScreen
import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.R 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.AppUpdateChecker
import eu.kanade.tachiyomi.data.updater.AppUpdateResult import eu.kanade.tachiyomi.data.updater.AppUpdateResult
import eu.kanade.tachiyomi.ui.base.controller.BasicFullComposeController import eu.kanade.tachiyomi.ui.base.controller.BasicFullComposeController
@ -23,7 +23,7 @@ import java.util.TimeZone
class AboutController : BasicFullComposeController() { class AboutController : BasicFullComposeController() {
private val preferences: PreferencesHelper by injectLazy() private val preferences: UiPreferences by injectLazy()
private val updateChecker by lazy { AppUpdateChecker() } private val updateChecker by lazy { AppUpdateChecker() }
@Composable @Composable
@ -78,7 +78,7 @@ class AboutController : BasicFullComposeController() {
) )
outputDf.timeZone = TimeZone.getDefault() outputDf.timeZone = TimeZone.getDefault()
buildTime!!.toDateTimestampString(preferences.dateFormat()) buildTime!!.toDateTimestampString(UiPreferences.dateFormat(preferences.dateFormat().get()))
} catch (e: Exception) { } catch (e: Exception) {
BuildConfig.BUILD_TIME BuildConfig.BUILD_TIME
} }

View File

@ -1,9 +1,9 @@
package eu.kanade.tachiyomi.ui.more package eu.kanade.tachiyomi.ui.more
import android.os.Bundle import android.os.Bundle
import eu.kanade.domain.base.BasePreferences
import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.download.DownloadService 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.ui.base.presenter.BasePresenter
import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.launchIO
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
@ -18,7 +18,8 @@ import uy.kohesive.injekt.api.get
class MorePresenter( class MorePresenter(
private val downloadManager: DownloadManager = Injekt.get(), private val downloadManager: DownloadManager = Injekt.get(),
preferences: PreferencesHelper = Injekt.get(), preferences: BasePreferences = Injekt.get(),
) : BasePresenter<MoreController>() { ) : BasePresenter<MoreController>() {
val downloadedOnly = preferences.downloadedOnly().asState() val downloadedOnly = preferences.downloadedOnly().asState()

View File

@ -5,6 +5,7 @@ import android.content.Context
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import com.jakewharton.rxrelay.BehaviorRelay import com.jakewharton.rxrelay.BehaviorRelay
import eu.kanade.domain.base.BasePreferences
import eu.kanade.domain.chapter.interactor.GetChapterByMangaId import eu.kanade.domain.chapter.interactor.GetChapterByMangaId
import eu.kanade.domain.chapter.interactor.UpdateChapter import eu.kanade.domain.chapter.interactor.UpdateChapter
import eu.kanade.domain.chapter.model.ChapterUpdate 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.database.models.toDomainManga
import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.download.model.Download 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.Image
import eu.kanade.tachiyomi.data.saver.ImageSaver import eu.kanade.tachiyomi.data.saver.ImageSaver
import eu.kanade.tachiyomi.data.saver.Location import eu.kanade.tachiyomi.data.saver.Location
@ -80,7 +80,7 @@ import eu.kanade.tachiyomi.data.database.models.Chapter as DbChapter
class ReaderPresenter( class ReaderPresenter(
private val sourceManager: SourceManager = Injekt.get(), private val sourceManager: SourceManager = Injekt.get(),
private val downloadManager: DownloadManager = 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 downloadPreferences: DownloadPreferences = Injekt.get(),
private val readerPreferences: ReaderPreferences = Injekt.get(), private val readerPreferences: ReaderPreferences = Injekt.get(),
private val trackPreferences: TrackPreferences = Injekt.get(), private val trackPreferences: TrackPreferences = Injekt.get(),

View File

@ -13,6 +13,7 @@ import androidx.paging.compose.LazyPagingItems
import androidx.paging.compose.collectAsLazyPagingItems import androidx.paging.compose.collectAsLazyPagingItems
import androidx.paging.insertSeparators import androidx.paging.insertSeparators
import androidx.paging.map import androidx.paging.map
import eu.kanade.domain.base.BasePreferences
import eu.kanade.domain.chapter.model.Chapter import eu.kanade.domain.chapter.model.Chapter
import eu.kanade.domain.history.interactor.DeleteHistoryTable import eu.kanade.domain.history.interactor.DeleteHistoryTable
import eu.kanade.domain.history.interactor.GetHistory 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.domain.history.model.HistoryWithRelations
import eu.kanade.presentation.history.HistoryUiModel import eu.kanade.presentation.history.HistoryUiModel
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.launchIO
import eu.kanade.tachiyomi.util.lang.toDateKey import eu.kanade.tachiyomi.util.lang.toDateKey
@ -46,7 +46,7 @@ class HistoryPresenter(
private val deleteHistoryTable: DeleteHistoryTable = Injekt.get(), private val deleteHistoryTable: DeleteHistoryTable = Injekt.get(),
private val removeHistoryById: RemoveHistoryById = Injekt.get(), private val removeHistoryById: RemoveHistoryById = Injekt.get(),
private val removeHistoryByMangaId: RemoveHistoryByMangaId = Injekt.get(), private val removeHistoryByMangaId: RemoveHistoryByMangaId = Injekt.get(),
preferences: PreferencesHelper = Injekt.get(), preferences: BasePreferences = Injekt.get(),
) : BasePresenter<HistoryController>(), HistoryState by state { ) : BasePresenter<HistoryController>(), HistoryState by state {
private val _events: Channel<Event> = Channel(Int.MAX_VALUE) private val _events: Channel<Event> = Channel(Int.MAX_VALUE)

View File

@ -4,6 +4,7 @@ import android.os.Bundle
import androidx.compose.runtime.Immutable import androidx.compose.runtime.Immutable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import eu.kanade.domain.base.BasePreferences
import eu.kanade.domain.chapter.interactor.GetChapter import eu.kanade.domain.chapter.interactor.GetChapter
import eu.kanade.domain.chapter.interactor.SetReadStatus import eu.kanade.domain.chapter.interactor.SetReadStatus
import eu.kanade.domain.chapter.interactor.UpdateChapter 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.chapter.model.toDbChapter
import eu.kanade.domain.library.service.LibraryPreferences import eu.kanade.domain.library.service.LibraryPreferences
import eu.kanade.domain.manga.interactor.GetManga 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.interactor.GetUpdates
import eu.kanade.domain.updates.model.UpdatesWithRelations import eu.kanade.domain.updates.model.UpdatesWithRelations
import eu.kanade.presentation.components.ChapterDownloadAction 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.DownloadManager
import eu.kanade.tachiyomi.data.download.DownloadService import eu.kanade.tachiyomi.data.download.DownloadService
import eu.kanade.tachiyomi.data.download.model.Download 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.source.SourceManager
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
import eu.kanade.tachiyomi.util.lang.launchIO 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.catch
import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import logcat.LogPriority import logcat.LogPriority
@ -50,17 +52,18 @@ class UpdatesPresenter(
private val sourceManager: SourceManager = Injekt.get(), private val sourceManager: SourceManager = Injekt.get(),
private val downloadManager: DownloadManager = Injekt.get(), private val downloadManager: DownloadManager = Injekt.get(),
private val getChapter: GetChapter = Injekt.get(), private val getChapter: GetChapter = Injekt.get(),
preferences: PreferencesHelper = Injekt.get(), basePreferences: BasePreferences = Injekt.get(),
uiPreferences: UiPreferences = Injekt.get(),
libraryPreferences: LibraryPreferences = Injekt.get(), libraryPreferences: LibraryPreferences = Injekt.get(),
) : BasePresenter<UpdatesController>(), UpdatesState by state { ) : BasePresenter<UpdatesController>(), UpdatesState by state {
val isDownloadOnly: Boolean by preferences.downloadedOnly().asState() val isDownloadOnly: Boolean by basePreferences.downloadedOnly().asState()
val isIncognitoMode: Boolean by preferences.incognitoMode().asState() val isIncognitoMode: Boolean by basePreferences.incognitoMode().asState()
val lastUpdated by libraryPreferences.libraryUpdateLastTimestamp().asState() val lastUpdated by libraryPreferences.libraryUpdateLastTimestamp().asState()
val relativeTime: Int by preferences.relativeTime().asState() val relativeTime: Int by uiPreferences.relativeTime().asState()
val dateFormat: DateFormat by mutableStateOf(preferences.dateFormat()) val dateFormat: DateFormat by mutableStateOf(UiPreferences.dateFormat(uiPreferences.dateFormat().get()))
private val _events: Channel<Event> = Channel(Int.MAX_VALUE) private val _events: Channel<Event> = Channel(Int.MAX_VALUE)
val events: Flow<Event> = _events.receiveAsFlow() val events: Flow<Event> = _events.receiveAsFlow()

View File

@ -9,7 +9,10 @@ import android.webkit.WebView
import androidx.core.net.toUri import androidx.core.net.toUri
import androidx.preference.PreferenceScreen import androidx.preference.PreferenceScreen
import com.google.android.material.dialog.MaterialAlertDialogBuilder 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.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.R
import eu.kanade.tachiyomi.data.cache.ChapterCache import eu.kanade.tachiyomi.data.cache.ChapterCache
import eu.kanade.tachiyomi.data.library.LibraryUpdateService import eu.kanade.tachiyomi.data.library.LibraryUpdateService
@ -70,6 +73,8 @@ class SettingsAdvancedController(
private val chapterCache: ChapterCache by injectLazy() private val chapterCache: ChapterCache by injectLazy()
private val trackManager: TrackManager by injectLazy() private val trackManager: TrackManager by injectLazy()
private val networkPreferences: NetworkPreferences by injectLazy() private val networkPreferences: NetworkPreferences by injectLazy()
private val libraryPreferences: LibraryPreferences by injectLazy()
private val uiPreferences: UiPreferences by injectLazy()
@SuppressLint("BatteryLife") @SuppressLint("BatteryLife")
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
@ -156,7 +161,7 @@ class SettingsAdvancedController(
onClick { clearChapterCache() } onClick { clearChapterCache() }
} }
switchPreference { switchPreference {
bindTo(preferences.autoClearChapterCache()) bindTo(libraryPreferences.autoClearChapterCache())
titleRes = R.string.pref_auto_clear_chapter_cache titleRes = R.string.pref_auto_clear_chapter_cache
} }
preference { preference {
@ -327,11 +332,11 @@ class SettingsAdvancedController(
titleRes = R.string.pref_category_display titleRes = R.string.pref_category_display
listPreference { listPreference {
bindTo(preferences.tabletUiMode()) bindTo(uiPreferences.tabletUiMode())
titleRes = R.string.pref_tablet_ui_mode titleRes = R.string.pref_tablet_ui_mode
summary = "%s" summary = "%s"
entriesRes = PreferenceValues.TabletUiMode.values().map { it.titleResId }.toTypedArray() entriesRes = TabletUiMode.values().map { it.titleResId }.toTypedArray()
entryValues = PreferenceValues.TabletUiMode.values().map { it.name }.toTypedArray() entryValues = TabletUiMode.values().map { it.name }.toTypedArray()
onChange { onChange {
activity?.toast(R.string.requires_app_restart) activity?.toast(R.string.requires_app_restart)

View File

@ -5,9 +5,11 @@ import android.os.Bundle
import android.view.View import android.view.View
import androidx.core.app.ActivityCompat import androidx.core.app.ActivityCompat
import androidx.preference.PreferenceScreen 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.R
import eu.kanade.tachiyomi.util.preference.bindTo 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.entriesRes
import eu.kanade.tachiyomi.util.preference.initThenAdd import eu.kanade.tachiyomi.util.preference.initThenAdd
import eu.kanade.tachiyomi.util.preference.intListPreference 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.isDynamicColorAvailable
import eu.kanade.tachiyomi.util.system.isTablet import eu.kanade.tachiyomi.util.system.isTablet
import eu.kanade.tachiyomi.widget.preference.ThemesPreference import eu.kanade.tachiyomi.widget.preference.ThemesPreference
import uy.kohesive.injekt.injectLazy
import java.util.Date 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() { class SettingsAppearanceController : SettingsController() {
private var themesPreference: ThemesPreference? = null private var themesPreference: ThemesPreference? = null
private val uiPreferences: UiPreferences by injectLazy()
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
titleRes = R.string.pref_category_appearance titleRes = R.string.pref_category_appearance
@ -35,7 +37,7 @@ class SettingsAppearanceController : SettingsController() {
titleRes = R.string.pref_category_theme titleRes = R.string.pref_category_theme
listPreference { listPreference {
bindTo(preferences.themeMode()) bindTo(uiPreferences.themeMode())
titleRes = R.string.pref_theme_mode titleRes = R.string.pref_theme_mode
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@ -45,9 +47,9 @@ class SettingsAppearanceController : SettingsController() {
R.string.theme_dark, R.string.theme_dark,
) )
entryValues = arrayOf( entryValues = arrayOf(
Values.ThemeMode.system.name, ThemeMode.SYSTEM.name,
Values.ThemeMode.light.name, ThemeMode.LIGHT.name,
Values.ThemeMode.dark.name, ThemeMode.DARK.name,
) )
} else { } else {
entriesRes = arrayOf( entriesRes = arrayOf(
@ -55,19 +57,19 @@ class SettingsAppearanceController : SettingsController() {
R.string.theme_dark, R.string.theme_dark,
) )
entryValues = arrayOf( entryValues = arrayOf(
Values.ThemeMode.light.name, ThemeMode.LIGHT.name,
Values.ThemeMode.dark.name, ThemeMode.DARK.name,
) )
} }
summary = "%s" summary = "%s"
} }
themesPreference = initThenAdd(ThemesPreference(context)) { themesPreference = initThenAdd(ThemesPreference(context)) {
bindTo(preferences.appTheme()) bindTo(uiPreferences.appTheme())
titleRes = R.string.pref_app_theme titleRes = R.string.pref_app_theme
val appThemes = Values.AppTheme.values().filter { val appThemes = AppTheme.values().filter {
val monetFilter = if (it == Values.AppTheme.MONET) { val monetFilter = if (it == AppTheme.MONET) {
DeviceUtil.isDynamicColorAvailable DeviceUtil.isDynamicColorAvailable
} else { } else {
true true
@ -82,10 +84,10 @@ class SettingsAppearanceController : SettingsController() {
} }
} }
switchPreference { switchPreference {
bindTo(preferences.themeDarkAmoled()) bindTo(uiPreferences.themeDarkAmoled())
titleRes = R.string.pref_dark_theme_pure_black titleRes = R.string.pref_dark_theme_pure_black
visibleIf(preferences.themeMode()) { it != Values.ThemeMode.light } visibleIf(uiPreferences.themeMode()) { it != ThemeMode.LIGHT }
onChange { onChange {
activity?.let { ActivityCompat.recreate(it) } activity?.let { ActivityCompat.recreate(it) }
@ -99,7 +101,7 @@ class SettingsAppearanceController : SettingsController() {
titleRes = R.string.pref_category_navigation titleRes = R.string.pref_category_navigation
intListPreference { intListPreference {
bindTo(preferences.sideNavIconAlignment()) bindTo(uiPreferences.sideNavIconAlignment())
titleRes = R.string.pref_side_nav_icon_alignment titleRes = R.string.pref_side_nav_icon_alignment
entriesRes = arrayOf( entriesRes = arrayOf(
R.string.alignment_top, R.string.alignment_top,
@ -116,7 +118,7 @@ class SettingsAppearanceController : SettingsController() {
titleRes = R.string.pref_category_timestamps titleRes = R.string.pref_category_timestamps
intListPreference { intListPreference {
bindTo(preferences.relativeTime()) bindTo(uiPreferences.relativeTime())
titleRes = R.string.pref_relative_format titleRes = R.string.pref_relative_format
val values = arrayOf("0", "2", "7") val values = arrayOf("0", "2", "7")
entryValues = values entryValues = values
@ -131,13 +133,13 @@ class SettingsAppearanceController : SettingsController() {
} }
listPreference { listPreference {
key = Keys.dateFormat bindTo(uiPreferences.dateFormat())
titleRes = R.string.pref_date_format titleRes = R.string.pref_date_format
entryValues = arrayOf("", "MM/dd/yy", "dd/MM/yy", "yyyy-MM-dd", "dd MMM yyyy", "MMM dd, yyyy") entryValues = arrayOf("", "MM/dd/yy", "dd/MM/yy", "yyyy-MM-dd", "dd MMM yyyy", "MMM dd, yyyy")
val now = Date().time val now = Date().time
entries = entryValues.map { value -> entries = entryValues.map { value ->
val formattedDate = preferences.dateFormat(value.toString()).format(now) val formattedDate = UiPreferences.dateFormat(value.toString()).format(now)
if (value == "") { if (value == "") {
"${context.getString(R.string.label_default)} ($formattedDate)" "${context.getString(R.string.label_default)} ($formattedDate)"
} else { } else {
@ -145,7 +147,6 @@ class SettingsAppearanceController : SettingsController() {
} }
}.toTypedArray() }.toTypedArray()
defaultValue = ""
summary = "%s" summary = "%s"
} }
} }

View File

@ -19,8 +19,8 @@ import androidx.preference.PreferenceScreen
import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeHandler
import com.bluelinelabs.conductor.ControllerChangeType import com.bluelinelabs.conductor.ControllerChangeType
import dev.chrisbanes.insetter.applyInsetter import dev.chrisbanes.insetter.applyInsetter
import eu.kanade.domain.base.BasePreferences
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.util.preference.asHotFlow import eu.kanade.tachiyomi.util.preference.asHotFlow
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@ -33,7 +33,7 @@ import uy.kohesive.injekt.api.get
abstract class SettingsController : PreferenceController() { abstract class SettingsController : PreferenceController() {
var preferenceKey: String? = null var preferenceKey: String? = null
val preferences: PreferencesHelper = Injekt.get() val preferences: BasePreferences = Injekt.get()
val viewScope: CoroutineScope = MainScope() val viewScope: CoroutineScope = MainScope()
private var themedContext: Context? = null private var themedContext: Context? = null

View File

@ -1,7 +1,7 @@
package eu.kanade.tachiyomi.ui.setting.search package eu.kanade.tachiyomi.ui.setting.search
import android.os.Bundle 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 eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
@ -10,7 +10,7 @@ import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
class SettingsSearchPresenter( class SettingsSearchPresenter(
private val preferences: PreferencesHelper = Injekt.get(), private val preferences: BasePreferences = Injekt.get(),
) : BasePresenter<SettingsSearchController>() { ) : BasePresenter<SettingsSearchController>() {
private val _state: MutableStateFlow<List<SettingsSearchHelper.SettingsSearchResult>> = private val _state: MutableStateFlow<List<SettingsSearchHelper.SettingsSearchResult>> =

View File

@ -36,9 +36,9 @@ import androidx.core.graphics.green
import androidx.core.graphics.red import androidx.core.graphics.red
import androidx.core.net.toUri import androidx.core.net.toUri
import com.hippo.unifile.UniFile 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.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.base.delegate.ThemingDelegate
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
import eu.kanade.tachiyomi.util.lang.truncateCenter import eu.kanade.tachiyomi.util.lang.truncateCenter
@ -262,11 +262,11 @@ fun Context.isTablet(): Boolean {
fun Context.prepareTabletUiContext(): Context { fun Context.prepareTabletUiContext(): Context {
val configuration = resources.configuration val configuration = resources.configuration
val expected = when (Injekt.get<PreferencesHelper>().tabletUiMode().get()) { val expected = when (Injekt.get<UiPreferences>().tabletUiMode().get()) {
PreferenceValues.TabletUiMode.AUTOMATIC -> isTablet() TabletUiMode.AUTOMATIC -> isTablet()
PreferenceValues.TabletUiMode.ALWAYS -> true TabletUiMode.ALWAYS -> true
PreferenceValues.TabletUiMode.LANDSCAPE -> configuration.orientation == Configuration.ORIENTATION_LANDSCAPE TabletUiMode.LANDSCAPE -> configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
PreferenceValues.TabletUiMode.NEVER -> false TabletUiMode.NEVER -> false
} }
if (configuration.smallestScreenWidthDp >= TABLET_UI_MIN_SCREEN_WIDTH_DP != expected) { if (configuration.smallestScreenWidthDp >= TABLET_UI_MIN_SCREEN_WIDTH_DP != expected) {
val overrideConf = Configuration() 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 * 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 { fun Context.createReaderThemeContext(): Context {
val preferences = Injekt.get<PreferencesHelper>() val preferences = Injekt.get<UiPreferences>()
val readerPreferences = Injekt.get<ReaderPreferences>() val readerPreferences = Injekt.get<ReaderPreferences>()
val isDarkBackground = when (readerPreferences.readerTheme().get()) { val isDarkBackground = when (readerPreferences.readerTheme().get()) {
1, 2 -> true // Black, Gray 1, 2 -> true // Black, Gray

View File

@ -5,8 +5,8 @@ import android.util.AttributeSet
import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.core.view.inputmethod.EditorInfoCompat import androidx.core.view.inputmethod.EditorInfoCompat
import eu.kanade.domain.base.BasePreferences
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.util.preference.asHotFlow import eu.kanade.tachiyomi.util.preference.asHotFlow
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers 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 * 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( class TachiyomiSearchView @JvmOverloads constructor(
context: Context, context: Context,
@ -31,7 +31,7 @@ class TachiyomiSearchView @JvmOverloads constructor(
override fun onAttachedToWindow() { override fun onAttachedToWindow() {
super.onAttachedToWindow() super.onAttachedToWindow()
scope = CoroutineScope(SupervisorJob() + Dispatchers.Main) scope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
Injekt.get<PreferencesHelper>().incognitoMode() Injekt.get<BasePreferences>().incognitoMode()
.asHotFlow { .asHotFlow {
imeOptions = if (it) { imeOptions = if (it) {
imeOptions or EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING imeOptions or EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING

View File

@ -5,8 +5,8 @@ import android.util.AttributeSet
import android.widget.EditText import android.widget.EditText
import androidx.core.view.inputmethod.EditorInfoCompat import androidx.core.view.inputmethod.EditorInfoCompat
import com.google.android.material.textfield.TextInputEditText import com.google.android.material.textfield.TextInputEditText
import eu.kanade.domain.base.BasePreferences
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.util.preference.asHotFlow import eu.kanade.tachiyomi.util.preference.asHotFlow
import eu.kanade.tachiyomi.widget.TachiyomiTextInputEditText.Companion.setIncognito import eu.kanade.tachiyomi.widget.TachiyomiTextInputEditText.Companion.setIncognito
import kotlinx.coroutines.CoroutineScope 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 * 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 * @see setIncognito
*/ */
@ -46,10 +46,10 @@ class TachiyomiTextInputEditText @JvmOverloads constructor(
companion object { companion object {
/** /**
* Sets Flow to this [EditText] that sets [EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING] to imeOptions * 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) { fun EditText.setIncognito(viewScope: CoroutineScope) {
Injekt.get<PreferencesHelper>().incognitoMode() Injekt.get<BasePreferences>().incognitoMode()
.asHotFlow { .asHotFlow {
imeOptions = if (it) { imeOptions = if (it) {
imeOptions or EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING imeOptions or EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING

View File

@ -9,8 +9,8 @@ import com.bluelinelabs.conductor.ControllerChangeHandler
import com.bluelinelabs.conductor.ControllerChangeType import com.bluelinelabs.conductor.ControllerChangeType
import com.dd.processbutton.iml.ActionProcessButton import com.dd.processbutton.iml.ActionProcessButton
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import eu.kanade.domain.base.BasePreferences
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.databinding.PrefAccountLoginBinding import eu.kanade.tachiyomi.databinding.PrefAccountLoginBinding
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
@ -23,7 +23,7 @@ abstract class LoginDialogPreference(
var binding: PrefAccountLoginBinding? = null var binding: PrefAccountLoginBinding? = null
private set private set
val preferences: PreferencesHelper by injectLazy() val preferences: BasePreferences by injectLazy()
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
binding = PrefAccountLoginBinding.inflate(LayoutInflater.from(activity!!)) binding = PrefAccountLoginBinding.inflate(LayoutInflater.from(activity!!))

View File

@ -6,8 +6,8 @@ import androidx.preference.ListPreference
import androidx.preference.PreferenceViewHolder import androidx.preference.PreferenceViewHolder
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import eu.kanade.domain.ui.model.AppTheme
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferenceValues
import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.dpToPx
class ThemesPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : 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 lastScrollPosition: Int? = null
var entries: List<PreferenceValues.AppTheme> = emptyList() var entries: List<AppTheme> = emptyList()
set(value) { set(value) {
field = value field = value
adapter.setItems(value) adapter.setItems(value)

View File

@ -5,9 +5,9 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.view.ContextThemeWrapper import androidx.appcompat.view.ContextThemeWrapper
import androidx.recyclerview.widget.RecyclerView 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.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.databinding.PrefThemeItemBinding
import eu.kanade.tachiyomi.ui.base.delegate.ThemingDelegate import eu.kanade.tachiyomi.ui.base.delegate.ThemingDelegate
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
@ -16,9 +16,9 @@ import uy.kohesive.injekt.injectLazy
class ThemesPreferenceAdapter(private val clickListener: OnItemClickListener) : class ThemesPreferenceAdapter(private val clickListener: OnItemClickListener) :
RecyclerView.Adapter<ThemesPreferenceAdapter.ThemeViewHolder>() { RecyclerView.Adapter<ThemesPreferenceAdapter.ThemeViewHolder>() {
private val preferences: PreferencesHelper by injectLazy() private val preferences: UiPreferences by injectLazy()
private var themes = emptyList<PreferenceValues.AppTheme>() private var themes = emptyList<AppTheme>()
private lateinit var binding: PrefThemeItemBinding private lateinit var binding: PrefThemeItemBinding
@ -41,7 +41,7 @@ class ThemesPreferenceAdapter(private val clickListener: OnItemClickListener) :
holder.bind(themes[position]) holder.bind(themes[position])
} }
fun setItems(themes: List<PreferenceValues.AppTheme>) { fun setItems(themes: List<AppTheme>) {
this.themes = themes this.themes = themes
notifyDataSetChanged() notifyDataSetChanged()
} }
@ -51,7 +51,7 @@ class ThemesPreferenceAdapter(private val clickListener: OnItemClickListener) :
private val selectedColor = view.context.getResourceColor(R.attr.colorAccent) private val selectedColor = view.context.getResourceColor(R.attr.colorAccent)
private val unselectedColor = view.context.getResourceColor(android.R.attr.divider) 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!!) binding.name.text = view.context.getString(appTheme.titleResId!!)
// For rounded corners // For rounded corners