From 7907a4fc24c972811feb6dbf14e99200210e3925 Mon Sep 17 00:00:00 2001 From: Andreas Date: Sat, 7 Aug 2021 16:34:47 +0200 Subject: [PATCH] Add ability to tweak auto hide sensitivity in Webtoon Reader (#5650) * Tweak threshold * Put setting under Webtoon instead Because it only affects Webtoon related viewers --- .../tachiyomi/data/preference/PreferenceKeys.kt | 2 ++ .../data/preference/PreferenceValues.kt | 7 +++++++ .../data/preference/PreferencesHelper.kt | 2 ++ .../ui/reader/viewer/webtoon/WebtoonViewer.kt | 11 ++++++++++- .../ui/setting/SettingsReaderController.kt | 16 ++++++++++++++++ app/src/main/res/values/strings.xml | 5 +++++ 6 files changed, 42 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 404d760c7..e076002fe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -87,6 +87,8 @@ object PreferenceKeys { const val showNavigationOverlayOnStart = "reader_navigation_overlay_on_start" + const val readerHideThreshold = "reader_hide_threshold" + const val webtoonSidePadding = "webtoon_side_padding" const val portraitColumns = "pref_library_columns_portrait_key" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt index 59c524f55..77076c965 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt @@ -43,4 +43,11 @@ object PreferenceValues { VERTICAL(shouldInvertVertical = true), BOTH(shouldInvertHorizontal = true, shouldInvertVertical = true), } + + enum class ReaderHideThreshold(val threshold: Int) { + HIGHEST(5), + HIGH(13), + LOW(31), + LOWEST(47) + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index fd2fd47e4..04a0a81fe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -167,6 +167,8 @@ class PreferencesHelper(val context: Context) { fun showNavigationOverlayOnStart() = flowPrefs.getBoolean(Keys.showNavigationOverlayOnStart, false) + fun readerHideTreshold() = flowPrefs.getEnum(Keys.readerHideThreshold, Values.ReaderHideThreshold.LOW) + fun portraitColumns() = flowPrefs.getInt(Keys.portraitColumns, 0) fun landscapeColumns() = flowPrefs.getInt(Keys.landscapeColumns, 0) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt index ba8236df0..d6572aa89 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt @@ -10,6 +10,7 @@ import androidx.core.view.isGone import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.WebtoonLayoutManager +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 @@ -20,6 +21,8 @@ import kotlinx.coroutines.MainScope import kotlinx.coroutines.cancel import rx.subscriptions.CompositeSubscription import timber.log.Timber +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get import kotlin.math.max import kotlin.math.min @@ -70,6 +73,12 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr */ val subscriptions = CompositeSubscription() + private val threshold: Int = + Injekt.get() + .readerHideTreshold() + .get() + .threshold + init { recycler.isVisible = false // Don't let the recycler layout yet recycler.layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT) @@ -81,7 +90,7 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { onScrolled() - if ((dy > 37 || dy < -37) && activity.menuVisible) { + if ((dy > threshold || dy < -threshold) && activity.menuVisible) { activity.hideMenu() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt index f364cf8ca..de2191a9a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.setting import android.os.Build import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.preference.PreferenceValues import eu.kanade.tachiyomi.data.preference.PreferenceValues.TappingInvertMode import eu.kanade.tachiyomi.data.preference.asImmediateFlow import eu.kanade.tachiyomi.ui.reader.setting.OrientationType @@ -274,6 +275,21 @@ class SettingsReaderController : SettingsController() { defaultValue = "0" summary = "%s" } + listPreference { + key = Keys.readerHideThreshold + titleRes = R.string.pref_hide_threshold + entriesRes = arrayOf( + R.string.pref_highest, + R.string.pref_high, + R.string.pref_low, + R.string.pref_lowest + ) + entryValues = PreferenceValues.ReaderHideThreshold.values() + .map { it.name } + .toTypedArray() + defaultValue = "${PreferenceValues.ReaderHideThreshold.LOW}" + summary = "%s" + } switchPreference { key = Keys.cropBordersWebtoon titleRes = R.string.pref_crop_borders diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8e9745f34..f6b944824 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -358,6 +358,11 @@ 15% 20% 25% + Auto hide menu on scroll sensitivity + Highest + High + Low + Lowest Download location