Split reader preferences from PreferencesHelper (#8042)

This commit is contained in:
Andreas 2022-09-20 14:36:57 +02:00 committed by GitHub
parent 2b089648a3
commit e275897bf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 309 additions and 268 deletions

View file

@ -29,6 +29,7 @@ import eu.kanade.tachiyomi.extension.ExtensionManager
import eu.kanade.tachiyomi.network.NetworkHelper
import eu.kanade.tachiyomi.network.NetworkPreferences
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
import eu.kanade.tachiyomi.util.system.isDevFlavor
import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory
import kotlinx.serialization.json.Json
@ -151,6 +152,9 @@ class PreferenceModule(val application: Application) : InjektModule {
addSingletonFactory {
LibraryPreferences(get())
}
addSingletonFactory {
ReaderPreferences(get())
}
addSingletonFactory {
PreferencesHelper(
context = application,

View file

@ -18,6 +18,7 @@ import eu.kanade.tachiyomi.extension.ExtensionUpdateJob
import eu.kanade.tachiyomi.network.NetworkPreferences
import eu.kanade.tachiyomi.network.PREF_DOH_CLOUDFLARE
import eu.kanade.tachiyomi.ui.reader.setting.OrientationType
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
import eu.kanade.tachiyomi.util.preference.minusAssign
import eu.kanade.tachiyomi.util.preference.plusAssign
import eu.kanade.tachiyomi.util.system.DeviceUtil
@ -42,6 +43,7 @@ object Migrations {
sourcePreferences: SourcePreferences,
securityPreferences: SecurityPreferences,
libraryPreferences: LibraryPreferences,
readerPreferences: ReaderPreferences,
): Boolean {
val oldVersion = preferences.lastVersionCode().get()
if (oldVersion < BuildConfig.VERSION_CODE) {
@ -269,8 +271,8 @@ object Migrations {
if (oldVersion < 77) {
val oldReaderTap = prefs.getBoolean("reader_tap", false)
if (!oldReaderTap) {
preferences.navigationModePager().set(5)
preferences.navigationModeWebtoon().set(5)
readerPreferences.navigationModePager().set(5)
readerPreferences.navigationModeWebtoon().set(5)
}
}
if (oldVersion < 81) {

View file

@ -10,8 +10,6 @@ import eu.kanade.tachiyomi.core.preference.getEnum
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.track.TrackService
import eu.kanade.tachiyomi.data.track.anilist.Anilist
import eu.kanade.tachiyomi.ui.reader.setting.OrientationType
import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType
import eu.kanade.tachiyomi.util.system.DeviceUtil
import eu.kanade.tachiyomi.util.system.isDynamicColorAvailable
import java.io.File
@ -59,90 +57,6 @@ class PreferencesHelper(
fun themeDarkAmoled() = preferenceStore.getBoolean("pref_theme_dark_amoled_key", false)
fun pageTransitions() = preferenceStore.getBoolean("pref_enable_transitions_key", true)
fun doubleTapAnimSpeed() = preferenceStore.getInt("pref_double_tap_anim_speed", 500)
fun showPageNumber() = preferenceStore.getBoolean("pref_show_page_number_key", true)
fun dualPageSplitPaged() = preferenceStore.getBoolean("pref_dual_page_split", false)
fun dualPageInvertPaged() = preferenceStore.getBoolean("pref_dual_page_invert", false)
fun dualPageSplitWebtoon() = preferenceStore.getBoolean("pref_dual_page_split_webtoon", false)
fun dualPageInvertWebtoon() = preferenceStore.getBoolean("pref_dual_page_invert_webtoon", false)
fun longStripSplitWebtoon() = preferenceStore.getBoolean("pref_long_strip_split_webtoon", true)
fun showReadingMode() = preferenceStore.getBoolean("pref_show_reading_mode", true)
fun trueColor() = preferenceStore.getBoolean("pref_true_color_key", false)
fun fullscreen() = preferenceStore.getBoolean("fullscreen", true)
fun cutoutShort() = preferenceStore.getBoolean("cutout_short", true)
fun keepScreenOn() = preferenceStore.getBoolean("pref_keep_screen_on_key", true)
fun customBrightness() = preferenceStore.getBoolean("pref_custom_brightness_key", false)
fun customBrightnessValue() = preferenceStore.getInt("custom_brightness_value", 0)
fun colorFilter() = preferenceStore.getBoolean("pref_color_filter_key", false)
fun colorFilterValue() = preferenceStore.getInt("color_filter_value", 0)
fun colorFilterMode() = preferenceStore.getInt("color_filter_mode", 0)
fun grayscale() = preferenceStore.getBoolean("pref_grayscale", false)
fun invertedColors() = preferenceStore.getBoolean("pref_inverted_colors", false)
fun defaultReadingMode() = preferenceStore.getInt("pref_default_reading_mode_key", ReadingModeType.RIGHT_TO_LEFT.flagValue)
fun defaultOrientationType() = preferenceStore.getInt("pref_default_orientation_type_key", OrientationType.FREE.flagValue)
fun imageScaleType() = preferenceStore.getInt("pref_image_scale_type_key", 1)
fun zoomStart() = preferenceStore.getInt("pref_zoom_start_key", 1)
fun readerTheme() = preferenceStore.getInt("pref_reader_theme_key", 1)
fun alwaysShowChapterTransition() = preferenceStore.getBoolean("always_show_chapter_transition", true)
fun cropBorders() = preferenceStore.getBoolean("crop_borders", false)
fun navigateToPan() = preferenceStore.getBoolean("navigate_pan", true)
fun landscapeZoom() = preferenceStore.getBoolean("landscape_zoom", true)
fun cropBordersWebtoon() = preferenceStore.getBoolean("crop_borders_webtoon", false)
fun webtoonSidePadding() = preferenceStore.getInt("webtoon_side_padding", 0)
fun pagerNavInverted() = preferenceStore.getEnum("reader_tapping_inverted", Values.TappingInvertMode.NONE)
fun webtoonNavInverted() = preferenceStore.getEnum("reader_tapping_inverted_webtoon", Values.TappingInvertMode.NONE)
fun readWithLongTap() = preferenceStore.getBoolean("reader_long_tap", true)
fun readWithVolumeKeys() = preferenceStore.getBoolean("reader_volume_keys", false)
fun readWithVolumeKeysInverted() = preferenceStore.getBoolean("reader_volume_keys_inverted", false)
fun navigationModePager() = preferenceStore.getInt("reader_navigation_mode_pager", 0)
fun navigationModeWebtoon() = preferenceStore.getInt("reader_navigation_mode_webtoon", 0)
fun showNavigationOverlayNewUser() = preferenceStore.getBoolean("reader_navigation_overlay_new_user", true)
fun showNavigationOverlayOnStart() = preferenceStore.getBoolean("reader_navigation_overlay_on_start", false)
fun readerHideThreshold() = preferenceStore.getEnum("reader_hide_threshold", Values.ReaderHideThreshold.LOW)
fun autoUpdateTrack() = preferenceStore.getBoolean("pref_auto_update_manga_sync_key", true)
fun lastVersionCode() = preferenceStore.getInt("last_version_code", 0)
fun trackUsername(sync: TrackService) = preferenceStore.getString(Keys.trackUsername(sync.id), "")
@ -175,8 +89,6 @@ class PreferencesHelper(
fun splitTallImages() = preferenceStore.getBoolean("split_tall_images", false)
fun folderPerManga() = preferenceStore.getBoolean("create_folder_per_manga", false)
fun numberOfBackups() = preferenceStore.getInt("backup_slots", 2)
fun backupInterval() = preferenceStore.getInt("backup_interval", 12)
@ -203,9 +115,7 @@ class PreferencesHelper(
fun autoDownloadWhileReading() = preferenceStore.getInt("auto_download_while_reading", 0)
fun skipRead() = preferenceStore.getBoolean("skip_read", false)
fun skipFiltered() = preferenceStore.getBoolean("skip_filtered", true)
fun autoUpdateTrack() = preferenceStore.getBoolean("pref_auto_update_manga_sync_key", true)
fun migrateFlags() = preferenceStore.getInt("migrate_flags", Int.MAX_VALUE)

View file

@ -120,6 +120,7 @@ class MainActivity : BaseActivity() {
sourcePreferences = sourcePreferences,
securityPreferences = Injekt.get(),
libraryPreferences = libraryPreferences,
readerPreferences = Injekt.get(),
)
} else {
false

View file

@ -60,6 +60,7 @@ import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters
import eu.kanade.tachiyomi.ui.reader.setting.OrientationType
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsSheet
import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType
import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer
@ -85,6 +86,7 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.sample
import logcat.LogPriority
import nucleus.factory.RequiresPresenter
import uy.kohesive.injekt.injectLazy
import kotlin.math.abs
import kotlin.math.max
@ -112,6 +114,8 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
const val SHARED_ELEMENT_NAME = "reader_shared_element_root"
}
private val readerPreferences: ReaderPreferences by injectLazy()
lateinit var binding: ReaderActivityBinding
val hasCutout by lazy { hasDisplayCutout() }
@ -446,7 +450,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
presenter.setMangaReadingMode(newReadingMode.flagValue)
menuToggleToast?.cancel()
if (!preferences.showReadingMode().get()) {
if (!readerPreferences.showReadingMode().get()) {
menuToggleToast = toast(newReadingMode.stringRes)
}
@ -462,9 +466,9 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
setOnClickListener {
val isPagerType = ReadingModeType.isPagerType(presenter.getMangaReadingMode())
val enabled = if (isPagerType) {
preferences.cropBorders().toggle()
readerPreferences.cropBorders().toggle()
} else {
preferences.cropBordersWebtoon().toggle()
readerPreferences.cropBordersWebtoon().toggle()
}
menuToggleToast?.cancel()
@ -478,7 +482,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
}
}
updateCropBordersShortcut()
listOf(preferences.cropBorders(), preferences.cropBordersWebtoon())
listOf(readerPreferences.cropBorders(), readerPreferences.cropBordersWebtoon())
.forEach { pref ->
pref.changes()
.onEach { updateCropBordersShortcut() }
@ -493,7 +497,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
popupMenu(
items = OrientationType.values().map { it.flagValue to it.stringRes },
selectedItemId = presenter.manga?.orientationType
?: preferences.defaultOrientationType().get(),
?: readerPreferences.defaultOrientationType().get(),
) {
val newOrientation = OrientationType.fromPreference(itemId)
@ -530,9 +534,9 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
private fun updateCropBordersShortcut() {
val isPagerType = ReadingModeType.isPagerType(presenter.getMangaReadingMode())
val enabled = if (isPagerType) {
preferences.cropBorders().get()
readerPreferences.cropBorders().get()
} else {
preferences.cropBordersWebtoon().get()
readerPreferences.cropBordersWebtoon().get()
}
binding.actionCropBorders.setImageResource(
@ -572,11 +576,11 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
binding.readerMenuBottom.startAnimation(bottomAnimation)
}
if (preferences.showPageNumber().get()) {
if (readerPreferences.showPageNumber().get()) {
config?.setPageNumberVisibility(false)
}
} else {
if (preferences.fullscreen().get()) {
if (readerPreferences.fullscreen().get()) {
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
@ -598,7 +602,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
binding.readerMenuBottom.startAnimation(bottomAnimation)
}
if (preferences.showPageNumber().get()) {
if (readerPreferences.showPageNumber().get()) {
config?.setPageNumberVisibility(true)
}
}
@ -632,10 +636,10 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
binding.viewerContainer.removeAllViews()
}
viewer = newViewer
updateViewerInset(preferences.fullscreen().get())
updateViewerInset(readerPreferences.fullscreen().get())
binding.viewerContainer.addView(newViewer.getView())
if (preferences.showReadingMode().get()) {
if (readerPreferences.showReadingMode().get()) {
showReadingModeToast(presenter.getMangaReadingMode())
}
@ -949,10 +953,10 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
* Initializes the reader subscriptions.
*/
init {
preferences.readerTheme().changes()
.onEach {
readerPreferences.readerTheme().changes()
.onEach { theme ->
binding.readerContainer.setBackgroundResource(
when (preferences.readerTheme().get()) {
when (theme) {
0 -> android.R.color.white
2 -> R.color.reader_background_dark
3 -> automaticBackgroundColor()
@ -962,41 +966,41 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
}
.launchIn(lifecycleScope)
preferences.showPageNumber().changes()
readerPreferences.showPageNumber().changes()
.onEach { setPageNumberVisibility(it) }
.launchIn(lifecycleScope)
preferences.trueColor().changes()
readerPreferences.trueColor().changes()
.onEach { setTrueColor(it) }
.launchIn(lifecycleScope)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
preferences.cutoutShort().changes()
readerPreferences.cutoutShort().changes()
.onEach { setCutoutShort(it) }
.launchIn(lifecycleScope)
}
preferences.keepScreenOn().changes()
readerPreferences.keepScreenOn().changes()
.onEach { setKeepScreenOn(it) }
.launchIn(lifecycleScope)
preferences.customBrightness().changes()
readerPreferences.customBrightness().changes()
.onEach { setCustomBrightness(it) }
.launchIn(lifecycleScope)
preferences.colorFilter().changes()
readerPreferences.colorFilter().changes()
.onEach { setColorFilter(it) }
.launchIn(lifecycleScope)
preferences.colorFilterMode().changes()
.onEach { setColorFilter(preferences.colorFilter().get()) }
readerPreferences.colorFilterMode().changes()
.onEach { setColorFilter(readerPreferences.colorFilter().get()) }
.launchIn(lifecycleScope)
merge(preferences.grayscale().changes(), preferences.invertedColors().changes())
.onEach { setLayerPaint(preferences.grayscale().get(), preferences.invertedColors().get()) }
merge(readerPreferences.grayscale().changes(), readerPreferences.invertedColors().changes())
.onEach { setLayerPaint(readerPreferences.grayscale().get(), readerPreferences.invertedColors().get()) }
.launchIn(lifecycleScope)
preferences.fullscreen().changes()
readerPreferences.fullscreen().changes()
.onEach {
WindowCompat.setDecorFitsSystemWindows(window, !it)
updateViewerInset(it)
@ -1060,7 +1064,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
*/
private fun setCustomBrightness(enabled: Boolean) {
if (enabled) {
preferences.customBrightnessValue().changes()
readerPreferences.customBrightnessValue().changes()
.sample(100)
.onEach { setCustomBrightnessValue(it) }
.launchIn(lifecycleScope)
@ -1074,7 +1078,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
*/
private fun setColorFilter(enabled: Boolean) {
if (enabled) {
preferences.colorFilterValue().changes()
readerPreferences.colorFilterValue().changes()
.sample(100)
.onEach { setColorFilterValue(it) }
.launchIn(lifecycleScope)
@ -1118,7 +1122,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
*/
private fun setColorFilterValue(value: Int) {
binding.colorOverlay.isVisible = true
binding.colorOverlay.setFilterColor(value, preferences.colorFilterMode().get())
binding.colorOverlay.setFilterColor(value, readerPreferences.colorFilterMode().get())
}
private fun setLayerPaint(grayscale: Boolean, invertedColors: Boolean) {

View file

@ -42,6 +42,7 @@ import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
import eu.kanade.tachiyomi.ui.reader.model.StencilPage
import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters
import eu.kanade.tachiyomi.ui.reader.setting.OrientationType
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType
import eu.kanade.tachiyomi.util.chapter.getChapterSort
import eu.kanade.tachiyomi.util.editCover
@ -78,6 +79,7 @@ class ReaderPresenter(
private val sourceManager: SourceManager = Injekt.get(),
private val downloadManager: DownloadManager = Injekt.get(),
private val preferences: PreferencesHelper = Injekt.get(),
private val readerPreferences: ReaderPreferences = Injekt.get(),
private val delayedTrackingStore: DelayedTrackingStore = Injekt.get(),
private val getManga: GetManga = Injekt.get(),
private val getChapterByMangaId: GetChapterByMangaId = Injekt.get(),
@ -140,11 +142,11 @@ class ReaderPresenter(
?: error("Requested chapter of id $chapterId not found in chapter list")
val chaptersForReader = when {
(preferences.skipRead().get() || preferences.skipFiltered().get()) -> {
(readerPreferences.skipRead().get() || readerPreferences.skipFiltered().get()) -> {
val filteredChapters = chapters.filterNot {
when {
preferences.skipRead().get() && it.read -> true
preferences.skipFiltered().get() -> {
readerPreferences.skipRead().get() && it.read -> true
readerPreferences.skipFiltered().get() -> {
(manga.readFilter == DomainManga.CHAPTER_SHOW_READ.toInt() && !it.read) ||
(manga.readFilter == DomainManga.CHAPTER_SHOW_UNREAD.toInt() && it.read) ||
(manga.downloadedFilter == DomainManga.CHAPTER_SHOW_DOWNLOADED.toInt() && !downloadManager.isChapterDownloaded(it.name, it.scanlator, manga.title, manga.source)) ||
@ -619,7 +621,7 @@ class ReaderPresenter(
* Returns the viewer position used by this manga or the default one.
*/
fun getMangaReadingMode(resolveDefault: Boolean = true): Int {
val default = preferences.defaultReadingMode().get()
val default = readerPreferences.defaultReadingMode().get()
val readingMode = ReadingModeType.fromPreference(manga?.readingModeType)
return when {
resolveDefault && readingMode == ReadingModeType.DEFAULT -> default
@ -656,7 +658,7 @@ class ReaderPresenter(
* Returns the orientation type used by this manga or the default one.
*/
fun getMangaOrientationType(resolveDefault: Boolean = true): Int {
val default = preferences.defaultOrientationType().get()
val default = readerPreferences.defaultOrientationType().get()
val orientation = OrientationType.fromPreference(manga?.orientationType)
return when {
resolveDefault && orientation == OrientationType.DEFAULT -> default
@ -714,7 +716,7 @@ class ReaderPresenter(
val filename = generateFilename(manga, page)
// Pictures directory.
val relativePath = if (preferences.folderPerManga().get()) DiskUtil.buildValidFilename(manga.title) else ""
val relativePath = if (readerPreferences.folderPerManga().get()) DiskUtil.buildValidFilename(manga.title) else ""
// Copy file in background.
try {

View file

@ -10,7 +10,7 @@ import androidx.core.graphics.green
import androidx.core.graphics.red
import androidx.core.widget.NestedScrollView
import androidx.lifecycle.lifecycleScope
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.core.preference.getAndSet
import eu.kanade.tachiyomi.databinding.ReaderColorFilterSettingsBinding
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.util.preference.bindToPreference
@ -25,28 +25,28 @@ import uy.kohesive.injekt.injectLazy
class ReaderColorFilterSettings @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
NestedScrollView(context, attrs) {
private val preferences: PreferencesHelper by injectLazy()
private val readerPreferences: ReaderPreferences by injectLazy()
private val binding = ReaderColorFilterSettingsBinding.inflate(LayoutInflater.from(context), this, false)
init {
addView(binding.root)
preferences.colorFilter().changes()
readerPreferences.colorFilter().changes()
.onEach { setColorFilter(it) }
.launchIn((context as ReaderActivity).lifecycleScope)
preferences.colorFilterMode().changes()
.onEach { setColorFilter(preferences.colorFilter().get()) }
readerPreferences.colorFilterMode().changes()
.onEach { setColorFilter(readerPreferences.colorFilter().get()) }
.launchIn(context.lifecycleScope)
preferences.customBrightness().changes()
readerPreferences.customBrightness().changes()
.onEach { setCustomBrightness(it) }
.launchIn(context.lifecycleScope)
// Get color and update values
val color = preferences.colorFilterValue().get()
val brightness = preferences.customBrightnessValue().get()
val color = readerPreferences.colorFilterValue().get()
val brightness = readerPreferences.customBrightnessValue().get()
val argb = setValues(color)
@ -61,11 +61,11 @@ class ReaderColorFilterSettings @JvmOverloads constructor(context: Context, attr
binding.sliderColorFilterBlue.value = argb[3].toFloat()
// Set listeners
binding.switchColorFilter.bindToPreference(preferences.colorFilter())
binding.customBrightness.bindToPreference(preferences.customBrightness())
binding.colorFilterMode.bindToPreference(preferences.colorFilterMode())
binding.grayscale.bindToPreference(preferences.grayscale())
binding.invertedColors.bindToPreference(preferences.invertedColors())
binding.switchColorFilter.bindToPreference(readerPreferences.colorFilter())
binding.customBrightness.bindToPreference(readerPreferences.customBrightness())
binding.colorFilterMode.bindToPreference(readerPreferences.colorFilterMode())
binding.grayscale.bindToPreference(readerPreferences.grayscale())
binding.invertedColors.bindToPreference(readerPreferences.invertedColors())
binding.sliderColorFilterAlpha.addOnChangeListener { _, value, fromUser ->
if (fromUser) {
@ -90,7 +90,7 @@ class ReaderColorFilterSettings @JvmOverloads constructor(context: Context, attr
binding.sliderBrightness.addOnChangeListener { _, value, fromUser ->
if (fromUser) {
preferences.customBrightnessValue().set(value.toInt())
readerPreferences.customBrightnessValue().set(value.toInt())
}
}
}
@ -139,7 +139,7 @@ class ReaderColorFilterSettings @JvmOverloads constructor(context: Context, attr
*/
private fun setCustomBrightness(enabled: Boolean) {
if (enabled) {
preferences.customBrightnessValue().changes()
readerPreferences.customBrightnessValue().changes()
.sample(100)
.onEach { setCustomBrightnessValue(it) }
.launchIn((context as ReaderActivity).lifecycleScope)
@ -167,7 +167,7 @@ class ReaderColorFilterSettings @JvmOverloads constructor(context: Context, attr
*/
private fun setColorFilter(enabled: Boolean) {
if (enabled) {
preferences.colorFilterValue().changes()
readerPreferences.colorFilterValue().changes()
.sample(100)
.onEach { setColorFilterValue(it) }
.launchIn((context as ReaderActivity).lifecycleScope)
@ -190,9 +190,9 @@ class ReaderColorFilterSettings @JvmOverloads constructor(context: Context, attr
* @param bitShift amounts of bits that gets shifted to receive value
*/
private fun setColorValue(color: Int, mask: Long, bitShift: Int) {
val currentColor = preferences.colorFilterValue().get()
val updatedColor = (color shl bitShift) or (currentColor and mask.inv().toInt())
preferences.colorFilterValue().set(updatedColor)
readerPreferences.colorFilterValue().getAndSet { currentColor ->
(color shl bitShift) or (currentColor and mask.inv().toInt())
}
}
}

View file

@ -7,7 +7,6 @@ import androidx.core.view.isVisible
import androidx.core.widget.NestedScrollView
import androidx.lifecycle.lifecycleScope
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.databinding.ReaderGeneralSettingsBinding
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.util.preference.asHotFlow
@ -21,7 +20,7 @@ import uy.kohesive.injekt.injectLazy
class ReaderGeneralSettings @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
NestedScrollView(context, attrs) {
private val preferences: PreferencesHelper by injectLazy()
private val readerPreferences: ReaderPreferences by injectLazy()
private val binding = ReaderGeneralSettingsBinding.inflate(LayoutInflater.from(context), this, false)
@ -35,20 +34,20 @@ class ReaderGeneralSettings @JvmOverloads constructor(context: Context, attrs: A
* Init general reader preferences.
*/
private fun initGeneralPreferences() {
binding.backgroundColor.bindToIntPreference(preferences.readerTheme(), R.array.reader_themes_values)
binding.showPageNumber.bindToPreference(preferences.showPageNumber())
binding.fullscreen.bindToPreference(preferences.fullscreen())
preferences.fullscreen()
binding.backgroundColor.bindToIntPreference(readerPreferences.readerTheme(), R.array.reader_themes_values)
binding.showPageNumber.bindToPreference(readerPreferences.showPageNumber())
binding.fullscreen.bindToPreference(readerPreferences.fullscreen())
readerPreferences.fullscreen()
.asHotFlow {
// If the preference is explicitly disabled, that means the setting was configured since there is a cutout
binding.cutoutShort.isVisible = it && ((context as ReaderActivity).hasCutout || !preferences.cutoutShort().get())
binding.cutoutShort.bindToPreference(preferences.cutoutShort())
binding.cutoutShort.isVisible = it && ((context as ReaderActivity).hasCutout || !readerPreferences.cutoutShort().get())
binding.cutoutShort.bindToPreference(readerPreferences.cutoutShort())
}
.launchIn((context as ReaderActivity).lifecycleScope)
binding.keepscreen.bindToPreference(preferences.keepScreenOn())
binding.longTap.bindToPreference(preferences.readWithLongTap())
binding.alwaysShowChapterTransition.bindToPreference(preferences.alwaysShowChapterTransition())
binding.pageTransitions.bindToPreference(preferences.pageTransitions())
binding.keepscreen.bindToPreference(readerPreferences.keepScreenOn())
binding.longTap.bindToPreference(readerPreferences.readWithLongTap())
binding.alwaysShowChapterTransition.bindToPreference(readerPreferences.alwaysShowChapterTransition())
binding.pageTransitions.bindToPreference(readerPreferences.pageTransitions())
}
}

View file

@ -0,0 +1,114 @@
package eu.kanade.tachiyomi.ui.reader.setting
import eu.kanade.tachiyomi.core.preference.PreferenceStore
import eu.kanade.tachiyomi.core.preference.getEnum
import eu.kanade.tachiyomi.data.preference.PreferenceValues
class ReaderPreferences(
private val preferenceStore: PreferenceStore,
) {
// region General
fun pageTransitions() = preferenceStore.getBoolean("pref_enable_transitions_key", true)
fun doubleTapAnimSpeed() = preferenceStore.getInt("pref_double_tap_anim_speed", 500)
fun showPageNumber() = preferenceStore.getBoolean("pref_show_page_number_key", true)
fun showReadingMode() = preferenceStore.getBoolean("pref_show_reading_mode", true)
fun trueColor() = preferenceStore.getBoolean("pref_true_color_key", false)
fun fullscreen() = preferenceStore.getBoolean("fullscreen", true)
fun cutoutShort() = preferenceStore.getBoolean("cutout_short", true)
fun keepScreenOn() = preferenceStore.getBoolean("pref_keep_screen_on_key", true)
fun defaultReadingMode() = preferenceStore.getInt("pref_default_reading_mode_key", ReadingModeType.RIGHT_TO_LEFT.flagValue)
fun defaultOrientationType() = preferenceStore.getInt("pref_default_orientation_type_key", OrientationType.FREE.flagValue)
fun longStripSplitWebtoon() = preferenceStore.getBoolean("pref_long_strip_split_webtoon", true)
fun imageScaleType() = preferenceStore.getInt("pref_image_scale_type_key", 1)
fun zoomStart() = preferenceStore.getInt("pref_zoom_start_key", 1)
fun readerTheme() = preferenceStore.getInt("pref_reader_theme_key", 1)
fun alwaysShowChapterTransition() = preferenceStore.getBoolean("always_show_chapter_transition", true)
fun cropBorders() = preferenceStore.getBoolean("crop_borders", false)
fun navigateToPan() = preferenceStore.getBoolean("navigate_pan", true)
fun landscapeZoom() = preferenceStore.getBoolean("landscape_zoom", true)
fun cropBordersWebtoon() = preferenceStore.getBoolean("crop_borders_webtoon", false)
fun webtoonSidePadding() = preferenceStore.getInt("webtoon_side_padding", 0)
fun readerHideThreshold() = preferenceStore.getEnum("reader_hide_threshold", PreferenceValues.ReaderHideThreshold.LOW)
fun folderPerManga() = preferenceStore.getBoolean("create_folder_per_manga", false)
fun skipRead() = preferenceStore.getBoolean("skip_read", false)
fun skipFiltered() = preferenceStore.getBoolean("skip_filtered", true)
// endregion
// region Split two page spread
fun dualPageSplitPaged() = preferenceStore.getBoolean("pref_dual_page_split", false)
fun dualPageInvertPaged() = preferenceStore.getBoolean("pref_dual_page_invert", false)
fun dualPageSplitWebtoon() = preferenceStore.getBoolean("pref_dual_page_split_webtoon", false)
fun dualPageInvertWebtoon() = preferenceStore.getBoolean("pref_dual_page_invert_webtoon", false)
// endregion
// region Color filter
fun customBrightness() = preferenceStore.getBoolean("pref_custom_brightness_key", false)
fun customBrightnessValue() = preferenceStore.getInt("custom_brightness_value", 0)
fun colorFilter() = preferenceStore.getBoolean("pref_color_filter_key", false)
fun colorFilterValue() = preferenceStore.getInt("color_filter_value", 0)
fun colorFilterMode() = preferenceStore.getInt("color_filter_mode", 0)
fun grayscale() = preferenceStore.getBoolean("pref_grayscale", false)
fun invertedColors() = preferenceStore.getBoolean("pref_inverted_colors", false)
// endregion
// region Controls
fun readWithLongTap() = preferenceStore.getBoolean("reader_long_tap", true)
fun readWithVolumeKeys() = preferenceStore.getBoolean("reader_volume_keys", false)
fun readWithVolumeKeysInverted() = preferenceStore.getBoolean("reader_volume_keys_inverted", false)
fun navigationModePager() = preferenceStore.getInt("reader_navigation_mode_pager", 0)
fun navigationModeWebtoon() = preferenceStore.getInt("reader_navigation_mode_webtoon", 0)
fun pagerNavInverted() = preferenceStore.getEnum("reader_tapping_inverted", PreferenceValues.TappingInvertMode.NONE)
fun webtoonNavInverted() = preferenceStore.getEnum("reader_tapping_inverted_webtoon", PreferenceValues.TappingInvertMode.NONE)
fun showNavigationOverlayNewUser() = preferenceStore.getBoolean("reader_navigation_overlay_new_user", true)
fun showNavigationOverlayOnStart() = preferenceStore.getBoolean("reader_navigation_overlay_on_start", false)
// endregion
}

View file

@ -7,7 +7,6 @@ import androidx.core.view.isVisible
import androidx.core.widget.NestedScrollView
import androidx.lifecycle.lifecycleScope
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.databinding.ReaderReadingModeSettingsBinding
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerViewer
@ -23,7 +22,7 @@ import uy.kohesive.injekt.injectLazy
class ReaderReadingModeSettings @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
NestedScrollView(context, attrs) {
private val preferences: PreferencesHelper by injectLazy()
private val readerPreferences: ReaderPreferences by injectLazy()
private val binding = ReaderReadingModeSettingsBinding.inflate(LayoutInflater.from(context), this, false)
@ -69,29 +68,29 @@ class ReaderReadingModeSettings @JvmOverloads constructor(context: Context, attr
binding.webtoonPrefsGroup.root.isVisible = false
binding.pagerPrefsGroup.root.isVisible = true
binding.pagerPrefsGroup.tappingInverted.bindToPreference(preferences.pagerNavInverted())
binding.pagerPrefsGroup.tappingInverted.bindToPreference(readerPreferences.pagerNavInverted())
binding.pagerPrefsGroup.pagerNav.bindToPreference(preferences.navigationModePager())
preferences.navigationModePager()
binding.pagerPrefsGroup.pagerNav.bindToPreference(readerPreferences.navigationModePager())
readerPreferences.navigationModePager()
.asHotFlow { binding.pagerPrefsGroup.tappingInverted.isVisible = it != 5 }
.launchIn((context as ReaderActivity).lifecycleScope)
// Makes so that landscape zoom gets hidden away when image scale type is not fit screen
binding.pagerPrefsGroup.scaleType.bindToPreference(preferences.imageScaleType(), 1)
preferences.imageScaleType()
binding.pagerPrefsGroup.scaleType.bindToPreference(readerPreferences.imageScaleType(), 1)
readerPreferences.imageScaleType()
.asHotFlow { binding.pagerPrefsGroup.landscapeZoom.isVisible = it == 1 }
.launchIn((context as ReaderActivity).lifecycleScope)
binding.pagerPrefsGroup.landscapeZoom.bindToPreference(preferences.landscapeZoom())
binding.pagerPrefsGroup.landscapeZoom.bindToPreference(readerPreferences.landscapeZoom())
binding.pagerPrefsGroup.zoomStart.bindToPreference(preferences.zoomStart(), 1)
binding.pagerPrefsGroup.cropBorders.bindToPreference(preferences.cropBorders())
binding.pagerPrefsGroup.navigatePan.bindToPreference(preferences.navigateToPan())
binding.pagerPrefsGroup.zoomStart.bindToPreference(readerPreferences.zoomStart(), 1)
binding.pagerPrefsGroup.cropBorders.bindToPreference(readerPreferences.cropBorders())
binding.pagerPrefsGroup.navigatePan.bindToPreference(readerPreferences.navigateToPan())
binding.pagerPrefsGroup.dualPageSplit.bindToPreference(preferences.dualPageSplitPaged())
binding.pagerPrefsGroup.dualPageSplit.bindToPreference(readerPreferences.dualPageSplitPaged())
// Makes it so that dual page invert gets hidden away when dual page split is turned off
preferences.dualPageSplitPaged()
readerPreferences.dualPageSplitPaged()
.asHotFlow { binding.pagerPrefsGroup.dualPageInvert.isVisible = it }
.launchIn((context as ReaderActivity).lifecycleScope)
binding.pagerPrefsGroup.dualPageInvert.bindToPreference(preferences.dualPageInvertPaged())
binding.pagerPrefsGroup.dualPageInvert.bindToPreference(readerPreferences.dualPageInvertPaged())
}
/**
@ -101,21 +100,21 @@ class ReaderReadingModeSettings @JvmOverloads constructor(context: Context, attr
binding.pagerPrefsGroup.root.isVisible = false
binding.webtoonPrefsGroup.root.isVisible = true
binding.webtoonPrefsGroup.tappingInverted.bindToPreference(preferences.webtoonNavInverted())
binding.webtoonPrefsGroup.tappingInverted.bindToPreference(readerPreferences.webtoonNavInverted())
binding.webtoonPrefsGroup.webtoonNav.bindToPreference(preferences.navigationModeWebtoon())
preferences.navigationModeWebtoon()
binding.webtoonPrefsGroup.webtoonNav.bindToPreference(readerPreferences.navigationModeWebtoon())
readerPreferences.navigationModeWebtoon()
.asHotFlow { binding.webtoonPrefsGroup.tappingInverted.isVisible = it != 5 }
.launchIn((context as ReaderActivity).lifecycleScope)
binding.webtoonPrefsGroup.cropBordersWebtoon.bindToPreference(preferences.cropBordersWebtoon())
binding.webtoonPrefsGroup.webtoonSidePadding.bindToIntPreference(preferences.webtoonSidePadding(), R.array.webtoon_side_padding_values)
binding.webtoonPrefsGroup.cropBordersWebtoon.bindToPreference(readerPreferences.cropBordersWebtoon())
binding.webtoonPrefsGroup.webtoonSidePadding.bindToIntPreference(readerPreferences.webtoonSidePadding(), R.array.webtoon_side_padding_values)
binding.webtoonPrefsGroup.dualPageSplit.bindToPreference(preferences.dualPageSplitWebtoon())
binding.webtoonPrefsGroup.dualPageSplit.bindToPreference(readerPreferences.dualPageSplitWebtoon())
// Makes it so that dual page invert gets hidden away when dual page split is turned off
preferences.dualPageSplitWebtoon()
readerPreferences.dualPageSplitWebtoon()
.asHotFlow { binding.webtoonPrefsGroup.dualPageInvert.isVisible = it }
.launchIn((context as ReaderActivity).lifecycleScope)
binding.webtoonPrefsGroup.dualPageInvert.bindToPreference(preferences.dualPageInvertWebtoon())
binding.webtoonPrefsGroup.longStripSplit.bindToPreference(preferences.longStripSplitWebtoon())
binding.webtoonPrefsGroup.dualPageInvert.bindToPreference(readerPreferences.dualPageInvertWebtoon())
binding.webtoonPrefsGroup.longStripSplit.bindToPreference(readerPreferences.longStripSplitWebtoon())
}
}

View file

@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.ui.reader.viewer
import eu.kanade.tachiyomi.core.preference.Preference
import eu.kanade.tachiyomi.data.preference.PreferenceValues.TappingInvertMode
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.launchIn
@ -11,7 +11,7 @@ import kotlinx.coroutines.flow.onEach
/**
* Common configuration for all viewers.
*/
abstract class ViewerConfig(preferences: PreferencesHelper, private val scope: CoroutineScope) {
abstract class ViewerConfig(readerPreferences: ReaderPreferences, private val scope: CoroutineScope) {
var imagePropertyChangedListener: (() -> Unit)? = null
@ -42,33 +42,33 @@ abstract class ViewerConfig(preferences: PreferencesHelper, private val scope: C
protected set
init {
preferences.readWithLongTap()
readerPreferences.readWithLongTap()
.register({ longTapEnabled = it })
preferences.pageTransitions()
readerPreferences.pageTransitions()
.register({ usePageTransitions = it })
preferences.doubleTapAnimSpeed()
readerPreferences.doubleTapAnimSpeed()
.register({ doubleTapAnimDuration = it })
preferences.readWithVolumeKeys()
readerPreferences.readWithVolumeKeys()
.register({ volumeKeysEnabled = it })
preferences.readWithVolumeKeysInverted()
readerPreferences.readWithVolumeKeysInverted()
.register({ volumeKeysInverted = it })
preferences.trueColor()
readerPreferences.trueColor()
.register({ trueColor = it }, { imagePropertyChangedListener?.invoke() })
preferences.alwaysShowChapterTransition()
readerPreferences.alwaysShowChapterTransition()
.register({ alwaysShowChapterTransition = it })
forceNavigationOverlay = preferences.showNavigationOverlayNewUser().get()
forceNavigationOverlay = readerPreferences.showNavigationOverlayNewUser().get()
if (forceNavigationOverlay) {
preferences.showNavigationOverlayNewUser().set(false)
readerPreferences.showNavigationOverlayNewUser().set(false)
}
preferences.showNavigationOverlayOnStart()
readerPreferences.showNavigationOverlayOnStart()
.register({ navigationOverlayOnStart = it })
}

View file

@ -1,6 +1,6 @@
package eu.kanade.tachiyomi.ui.reader.viewer.pager
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderPageImageView
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerConfig
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation
@ -22,10 +22,10 @@ import uy.kohesive.injekt.api.get
class PagerConfig(
private val viewer: PagerViewer,
scope: CoroutineScope,
preferences: PreferencesHelper = Injekt.get(),
) : ViewerConfig(preferences, scope) {
readerPreferences: ReaderPreferences = Injekt.get(),
) : ViewerConfig(readerPreferences, scope) {
var theme = preferences.readerTheme().get()
var theme = readerPreferences.readerTheme().get()
private set
var automaticBackground = false
@ -49,7 +49,7 @@ class PagerConfig(
private set
init {
preferences.readerTheme()
readerPreferences.readerTheme()
.register(
{
theme = it
@ -58,32 +58,32 @@ class PagerConfig(
{ imagePropertyChangedListener?.invoke() },
)
preferences.imageScaleType()
readerPreferences.imageScaleType()
.register({ imageScaleType = it }, { imagePropertyChangedListener?.invoke() })
preferences.zoomStart()
readerPreferences.zoomStart()
.register({ zoomTypeFromPreference(it) }, { imagePropertyChangedListener?.invoke() })
preferences.cropBorders()
readerPreferences.cropBorders()
.register({ imageCropBorders = it }, { imagePropertyChangedListener?.invoke() })
preferences.navigateToPan()
readerPreferences.navigateToPan()
.register({ navigateToPan = it })
preferences.landscapeZoom()
readerPreferences.landscapeZoom()
.register({ landscapeZoom = it }, { imagePropertyChangedListener?.invoke() })
preferences.navigationModePager()
readerPreferences.navigationModePager()
.register({ navigationMode = it }, { updateNavigation(navigationMode) })
preferences.pagerNavInverted()
readerPreferences.pagerNavInverted()
.register({ tappingInverted = it }, { navigator.invertMode = it })
preferences.pagerNavInverted().changes()
readerPreferences.pagerNavInverted().changes()
.drop(1)
.onEach { navigationModeChangedListener?.invoke() }
.launchIn(scope)
preferences.dualPageSplitPaged()
readerPreferences.dualPageSplitPaged()
.register(
{ dualPageSplit = it },
{
@ -92,7 +92,7 @@ class PagerConfig(
},
)
preferences.dualPageInvertPaged()
readerPreferences.dualPageInvertPaged()
.register({ dualPageInvert = it }, { imagePropertyChangedListener?.invoke() })
}

View file

@ -1,6 +1,6 @@
package eu.kanade.tachiyomi.ui.reader.viewer.webtoon
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerConfig
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation
import eu.kanade.tachiyomi.ui.reader.viewer.navigation.DisabledNavigation
@ -21,8 +21,8 @@ import uy.kohesive.injekt.api.get
*/
class WebtoonConfig(
scope: CoroutineScope,
preferences: PreferencesHelper = Injekt.get(),
) : ViewerConfig(preferences, scope) {
readerPreferences: ReaderPreferences = Injekt.get(),
) : ViewerConfig(readerPreferences, scope) {
var themeChangedListener: (() -> Unit)? = null
@ -37,32 +37,32 @@ class WebtoonConfig(
var longStripSplitChangedListener: ((Boolean) -> Unit)? = null
val theme = preferences.readerTheme().get()
val theme = readerPreferences.readerTheme().get()
init {
preferences.cropBordersWebtoon()
readerPreferences.cropBordersWebtoon()
.register({ imageCropBorders = it }, { imagePropertyChangedListener?.invoke() })
preferences.webtoonSidePadding()
readerPreferences.webtoonSidePadding()
.register({ sidePadding = it }, { imagePropertyChangedListener?.invoke() })
preferences.navigationModeWebtoon()
readerPreferences.navigationModeWebtoon()
.register({ navigationMode = it }, { updateNavigation(it) })
preferences.webtoonNavInverted()
readerPreferences.webtoonNavInverted()
.register({ tappingInverted = it }, { navigator.invertMode = it })
preferences.webtoonNavInverted().changes()
readerPreferences.webtoonNavInverted().changes()
.drop(1)
.onEach { navigationModeChangedListener?.invoke() }
.launchIn(scope)
preferences.dualPageSplitWebtoon()
readerPreferences.dualPageSplitWebtoon()
.register({ dualPageSplit = it }, { imagePropertyChangedListener?.invoke() })
preferences.dualPageInvertWebtoon()
readerPreferences.dualPageInvertWebtoon()
.register({ dualPageInvert = it }, { imagePropertyChangedListener?.invoke() })
preferences.longStripSplitWebtoon()
readerPreferences.longStripSplitWebtoon()
.register(
{ longStripSplit = it },
{
@ -71,7 +71,7 @@ class WebtoonConfig(
},
)
preferences.readerTheme().changes()
readerPreferences.readerTheme().changes()
.drop(1)
.distinctUntilChanged()
.onEach { themeChangedListener?.invoke() }

View file

@ -12,12 +12,12 @@ import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.WebtoonLayoutManager
import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
import eu.kanade.tachiyomi.ui.reader.model.StencilPage
import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation.NavigationRegion
import eu.kanade.tachiyomi.util.system.logcat
@ -80,7 +80,7 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
val subscriptions = CompositeSubscription()
private val threshold: Int =
Injekt.get<PreferencesHelper>()
Injekt.get<ReaderPreferences>()
.readerHideThreshold()
.get()
.threshold

View file

@ -6,6 +6,7 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferenceValues
import eu.kanade.tachiyomi.data.preference.PreferenceValues.TappingInvertMode
import eu.kanade.tachiyomi.ui.reader.setting.OrientationType
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType
import eu.kanade.tachiyomi.util.preference.bindTo
import eu.kanade.tachiyomi.util.preference.entriesRes
@ -16,14 +17,17 @@ import eu.kanade.tachiyomi.util.preference.summaryRes
import eu.kanade.tachiyomi.util.preference.switchPreference
import eu.kanade.tachiyomi.util.preference.titleRes
import eu.kanade.tachiyomi.util.system.hasDisplayCutout
import uy.kohesive.injekt.injectLazy
class SettingsReaderController : SettingsController() {
private val readerPreferences: ReaderPreferences by injectLazy()
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
titleRes = R.string.pref_category_reader
intListPreference {
bindTo(preferences.defaultReadingMode())
bindTo(readerPreferences.defaultReadingMode())
titleRes = R.string.pref_viewer_type
entriesRes = arrayOf(
R.string.left_to_right_viewer,
@ -37,31 +41,31 @@ class SettingsReaderController : SettingsController() {
summary = "%s"
}
intListPreference {
bindTo(preferences.doubleTapAnimSpeed())
bindTo(readerPreferences.doubleTapAnimSpeed())
titleRes = R.string.pref_double_tap_anim_speed
entries = arrayOf(context.getString(R.string.double_tap_anim_speed_0), context.getString(R.string.double_tap_anim_speed_normal), context.getString(R.string.double_tap_anim_speed_fast))
entryValues = arrayOf("1", "500", "250") // using a value of 0 breaks the image viewer, so min is 1
summary = "%s"
}
switchPreference {
bindTo(preferences.showReadingMode())
bindTo(readerPreferences.showReadingMode())
titleRes = R.string.pref_show_reading_mode
summaryRes = R.string.pref_show_reading_mode_summary
}
switchPreference {
bindTo(preferences.showNavigationOverlayOnStart())
bindTo(readerPreferences.showNavigationOverlayOnStart())
titleRes = R.string.pref_show_navigation_mode
summaryRes = R.string.pref_show_navigation_mode_summary
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
switchPreference {
bindTo(preferences.trueColor())
bindTo(readerPreferences.trueColor())
titleRes = R.string.pref_true_color
summaryRes = R.string.pref_true_color_summary
}
}
switchPreference {
bindTo(preferences.pageTransitions())
bindTo(readerPreferences.pageTransitions())
titleRes = R.string.pref_page_transitions
}
@ -69,7 +73,7 @@ class SettingsReaderController : SettingsController() {
titleRes = R.string.pref_category_display
intListPreference {
bindTo(preferences.defaultOrientationType())
bindTo(readerPreferences.defaultOrientationType())
titleRes = R.string.pref_rotation_type
entriesRes = arrayOf(
R.string.rotation_free,
@ -84,32 +88,32 @@ class SettingsReaderController : SettingsController() {
summary = "%s"
}
intListPreference {
bindTo(preferences.readerTheme())
bindTo(readerPreferences.readerTheme())
titleRes = R.string.pref_reader_theme
entriesRes = arrayOf(R.string.black_background, R.string.gray_background, R.string.white_background, R.string.automatic_background)
entryValues = arrayOf("1", "2", "0", "3")
summary = "%s"
}
switchPreference {
bindTo(preferences.fullscreen())
bindTo(readerPreferences.fullscreen())
titleRes = R.string.pref_fullscreen
}
if (activity?.hasDisplayCutout() == true) {
switchPreference {
bindTo(preferences.cutoutShort())
bindTo(readerPreferences.cutoutShort())
titleRes = R.string.pref_cutout_short
visibleIf(preferences.fullscreen()) { it }
visibleIf(readerPreferences.fullscreen()) { it }
}
}
switchPreference {
bindTo(preferences.keepScreenOn())
bindTo(readerPreferences.keepScreenOn())
titleRes = R.string.pref_keep_screen_on
}
switchPreference {
bindTo(preferences.showPageNumber())
bindTo(readerPreferences.showPageNumber())
titleRes = R.string.pref_show_page_number
}
}
@ -118,15 +122,15 @@ class SettingsReaderController : SettingsController() {
titleRes = R.string.pref_category_reading
switchPreference {
bindTo(preferences.skipRead())
bindTo(readerPreferences.skipRead())
titleRes = R.string.pref_skip_read_chapters
}
switchPreference {
bindTo(preferences.skipFiltered())
bindTo(readerPreferences.skipFiltered())
titleRes = R.string.pref_skip_filtered_chapters
}
switchPreference {
bindTo(preferences.alwaysShowChapterTransition())
bindTo(readerPreferences.alwaysShowChapterTransition())
titleRes = R.string.pref_always_show_chapter_transition
}
}
@ -135,7 +139,7 @@ class SettingsReaderController : SettingsController() {
titleRes = R.string.pager_viewer
intListPreference {
bindTo(preferences.navigationModePager())
bindTo(readerPreferences.navigationModePager())
titleRes = R.string.pref_viewer_nav
entries = context.resources.getStringArray(R.array.pager_nav).also { values ->
entryValues = values.indices.map { index -> "$index" }.toTypedArray()
@ -143,7 +147,7 @@ class SettingsReaderController : SettingsController() {
summary = "%s"
}
listPreference {
bindTo(preferences.pagerNavInverted())
bindTo(readerPreferences.pagerNavInverted())
titleRes = R.string.pref_read_with_tapping_inverted
entriesRes = arrayOf(
R.string.tapping_inverted_none,
@ -158,10 +162,10 @@ class SettingsReaderController : SettingsController() {
TappingInvertMode.BOTH.name,
)
summary = "%s"
visibleIf(preferences.navigationModePager()) { it != 5 }
visibleIf(readerPreferences.navigationModePager()) { it != 5 }
}
intListPreference {
bindTo(preferences.imageScaleType())
bindTo(readerPreferences.imageScaleType())
titleRes = R.string.pref_image_scale_type
entriesRes = arrayOf(
R.string.scale_type_fit_screen,
@ -175,12 +179,12 @@ class SettingsReaderController : SettingsController() {
summary = "%s"
}
switchPreference {
bindTo(preferences.landscapeZoom())
bindTo(readerPreferences.landscapeZoom())
titleRes = R.string.pref_landscape_zoom
visibleIf(preferences.imageScaleType()) { it == 1 }
visibleIf(readerPreferences.imageScaleType()) { it == 1 }
}
intListPreference {
bindTo(preferences.zoomStart())
bindTo(readerPreferences.zoomStart())
titleRes = R.string.pref_zoom_start
entriesRes = arrayOf(
R.string.zoom_start_automatic,
@ -192,22 +196,22 @@ class SettingsReaderController : SettingsController() {
summary = "%s"
}
switchPreference {
bindTo(preferences.cropBorders())
bindTo(readerPreferences.cropBorders())
titleRes = R.string.pref_crop_borders
}
switchPreference {
bindTo(preferences.navigateToPan())
bindTo(readerPreferences.navigateToPan())
titleRes = R.string.pref_navigate_pan
}
switchPreference {
bindTo(preferences.dualPageSplitPaged())
bindTo(readerPreferences.dualPageSplitPaged())
titleRes = R.string.pref_dual_page_split
}
switchPreference {
bindTo(preferences.dualPageInvertPaged())
bindTo(readerPreferences.dualPageInvertPaged())
titleRes = R.string.pref_dual_page_invert
summaryRes = R.string.pref_dual_page_invert_summary
visibleIf(preferences.dualPageSplitPaged()) { it }
visibleIf(readerPreferences.dualPageSplitPaged()) { it }
}
}
@ -215,7 +219,7 @@ class SettingsReaderController : SettingsController() {
titleRes = R.string.webtoon_viewer
intListPreference {
bindTo(preferences.navigationModeWebtoon())
bindTo(readerPreferences.navigationModeWebtoon())
titleRes = R.string.pref_viewer_nav
entries = context.resources.getStringArray(R.array.webtoon_nav).also { values ->
entryValues = values.indices.map { index -> "$index" }.toTypedArray()
@ -223,7 +227,7 @@ class SettingsReaderController : SettingsController() {
summary = "%s"
}
listPreference {
bindTo(preferences.webtoonNavInverted())
bindTo(readerPreferences.webtoonNavInverted())
titleRes = R.string.pref_read_with_tapping_inverted
entriesRes = arrayOf(
R.string.tapping_inverted_none,
@ -238,10 +242,10 @@ class SettingsReaderController : SettingsController() {
TappingInvertMode.BOTH.name,
)
summary = "%s"
visibleIf(preferences.navigationModeWebtoon()) { it != 5 }
visibleIf(readerPreferences.navigationModeWebtoon()) { it != 5 }
}
intListPreference {
bindTo(preferences.webtoonSidePadding())
bindTo(readerPreferences.webtoonSidePadding())
titleRes = R.string.pref_webtoon_side_padding
entriesRes = arrayOf(
R.string.webtoon_side_padding_0,
@ -255,7 +259,7 @@ class SettingsReaderController : SettingsController() {
summary = "%s"
}
listPreference {
bindTo(preferences.readerHideThreshold())
bindTo(readerPreferences.readerHideThreshold())
titleRes = R.string.pref_hide_threshold
entriesRes = arrayOf(
R.string.pref_highest,
@ -269,21 +273,21 @@ class SettingsReaderController : SettingsController() {
summary = "%s"
}
switchPreference {
bindTo(preferences.cropBordersWebtoon())
bindTo(readerPreferences.cropBordersWebtoon())
titleRes = R.string.pref_crop_borders
}
switchPreference {
bindTo(preferences.dualPageSplitWebtoon())
bindTo(readerPreferences.dualPageSplitWebtoon())
titleRes = R.string.pref_dual_page_split
}
switchPreference {
bindTo(preferences.dualPageInvertWebtoon())
bindTo(readerPreferences.dualPageInvertWebtoon())
titleRes = R.string.pref_dual_page_invert
summaryRes = R.string.pref_dual_page_invert_summary
visibleIf(preferences.dualPageSplitWebtoon()) { it }
visibleIf(readerPreferences.dualPageSplitWebtoon()) { it }
}
switchPreference {
bindTo(preferences.longStripSplitWebtoon())
bindTo(readerPreferences.longStripSplitWebtoon())
titleRes = R.string.pref_long_strip_split
summaryRes = R.string.split_tall_images_summary
}
@ -293,13 +297,13 @@ class SettingsReaderController : SettingsController() {
titleRes = R.string.pref_reader_navigation
switchPreference {
bindTo(preferences.readWithVolumeKeys())
bindTo(readerPreferences.readWithVolumeKeys())
titleRes = R.string.pref_read_with_volume_keys
}
switchPreference {
bindTo(preferences.readWithVolumeKeysInverted())
bindTo(readerPreferences.readWithVolumeKeysInverted())
titleRes = R.string.pref_read_with_volume_keys_inverted
visibleIf(preferences.readWithVolumeKeys()) { it }
visibleIf(readerPreferences.readWithVolumeKeys()) { it }
}
}
@ -307,11 +311,11 @@ class SettingsReaderController : SettingsController() {
titleRes = R.string.pref_reader_actions
switchPreference {
bindTo(preferences.readWithLongTap())
bindTo(readerPreferences.readWithLongTap())
titleRes = R.string.pref_read_with_long_tap
}
switchPreference {
bindTo(preferences.folderPerManga())
bindTo(readerPreferences.folderPerManga())
titleRes = R.string.pref_create_folder_per_manga
summaryRes = R.string.pref_create_folder_per_manga_summary
}

View file

@ -40,6 +40,7 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferenceValues
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.base.delegate.ThemingDelegate
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
import eu.kanade.tachiyomi.util.lang.truncateCenter
import logcat.LogPriority
import uy.kohesive.injekt.Injekt
@ -295,7 +296,8 @@ fun Context.isNightMode(): Boolean {
*/
fun Context.createReaderThemeContext(): Context {
val preferences = Injekt.get<PreferencesHelper>()
val isDarkBackground = when (preferences.readerTheme().get()) {
val readerPreferences = Injekt.get<ReaderPreferences>()
val isDarkBackground = when (readerPreferences.readerTheme().get()) {
1, 2 -> true // Black, Gray
3 -> applicationContext.isNightMode() // Automatic bg uses activity background by default
else -> false // White