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
This commit is contained in:
Andreas 2021-08-07 16:34:47 +02:00 committed by GitHub
parent 2f94f62a56
commit 7907a4fc24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 1 deletions

View File

@ -87,6 +87,8 @@ object PreferenceKeys {
const val showNavigationOverlayOnStart = "reader_navigation_overlay_on_start" const val showNavigationOverlayOnStart = "reader_navigation_overlay_on_start"
const val readerHideThreshold = "reader_hide_threshold"
const val webtoonSidePadding = "webtoon_side_padding" const val webtoonSidePadding = "webtoon_side_padding"
const val portraitColumns = "pref_library_columns_portrait_key" const val portraitColumns = "pref_library_columns_portrait_key"

View File

@ -43,4 +43,11 @@ object PreferenceValues {
VERTICAL(shouldInvertVertical = true), VERTICAL(shouldInvertVertical = true),
BOTH(shouldInvertHorizontal = true, shouldInvertVertical = true), BOTH(shouldInvertHorizontal = true, shouldInvertVertical = true),
} }
enum class ReaderHideThreshold(val threshold: Int) {
HIGHEST(5),
HIGH(13),
LOW(31),
LOWEST(47)
}
} }

View File

@ -167,6 +167,8 @@ class PreferencesHelper(val context: Context) {
fun showNavigationOverlayOnStart() = flowPrefs.getBoolean(Keys.showNavigationOverlayOnStart, false) fun showNavigationOverlayOnStart() = flowPrefs.getBoolean(Keys.showNavigationOverlayOnStart, false)
fun readerHideTreshold() = flowPrefs.getEnum(Keys.readerHideThreshold, Values.ReaderHideThreshold.LOW)
fun portraitColumns() = flowPrefs.getInt(Keys.portraitColumns, 0) fun portraitColumns() = flowPrefs.getInt(Keys.portraitColumns, 0)
fun landscapeColumns() = flowPrefs.getInt(Keys.landscapeColumns, 0) fun landscapeColumns() = flowPrefs.getInt(Keys.landscapeColumns, 0)

View File

@ -10,6 +10,7 @@ import androidx.core.view.isGone
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.WebtoonLayoutManager 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.ReaderActivity
import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
@ -20,6 +21,8 @@ import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel import kotlinx.coroutines.cancel
import rx.subscriptions.CompositeSubscription import rx.subscriptions.CompositeSubscription
import timber.log.Timber import timber.log.Timber
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import kotlin.math.max import kotlin.math.max
import kotlin.math.min import kotlin.math.min
@ -70,6 +73,12 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
*/ */
val subscriptions = CompositeSubscription() val subscriptions = CompositeSubscription()
private val threshold: Int =
Injekt.get<PreferencesHelper>()
.readerHideTreshold()
.get()
.threshold
init { init {
recycler.isVisible = false // Don't let the recycler layout yet recycler.isVisible = false // Don't let the recycler layout yet
recycler.layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT) 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) { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
onScrolled() onScrolled()
if ((dy > 37 || dy < -37) && activity.menuVisible) { if ((dy > threshold || dy < -threshold) && activity.menuVisible) {
activity.hideMenu() activity.hideMenu()
} }

View File

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.setting
import android.os.Build import android.os.Build
import androidx.preference.PreferenceScreen import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.R 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.PreferenceValues.TappingInvertMode
import eu.kanade.tachiyomi.data.preference.asImmediateFlow import eu.kanade.tachiyomi.data.preference.asImmediateFlow
import eu.kanade.tachiyomi.ui.reader.setting.OrientationType import eu.kanade.tachiyomi.ui.reader.setting.OrientationType
@ -274,6 +275,21 @@ class SettingsReaderController : SettingsController() {
defaultValue = "0" defaultValue = "0"
summary = "%s" 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 { switchPreference {
key = Keys.cropBordersWebtoon key = Keys.cropBordersWebtoon
titleRes = R.string.pref_crop_borders titleRes = R.string.pref_crop_borders

View File

@ -358,6 +358,11 @@
<string name="webtoon_side_padding_15">15%</string> <string name="webtoon_side_padding_15">15%</string>
<string name="webtoon_side_padding_20">20%</string> <string name="webtoon_side_padding_20">20%</string>
<string name="webtoon_side_padding_25">25%</string> <string name="webtoon_side_padding_25">25%</string>
<string name="pref_hide_threshold">Auto hide menu on scroll sensitivity</string>
<string name="pref_highest">Highest</string>
<string name="pref_high">High</string>
<string name="pref_low">Low</string>
<string name="pref_lowest">Lowest</string>
<!-- Downloads section --> <!-- Downloads section -->
<string name="pref_download_directory">Download location</string> <string name="pref_download_directory">Download location</string>