Use enum instead of boolean

This commit is contained in:
Andreas E 2020-06-23 12:09:10 +02:00
parent 0ea0eba4f0
commit c8a6a2653f
No known key found for this signature in database
GPG key ID: D7D48B26482380B8
7 changed files with 41 additions and 8 deletions

View file

@ -30,4 +30,11 @@ object PreferenceValues {
COMFORTABLE_GRID, COMFORTABLE_GRID,
LIST, LIST,
} }
enum class TappingInvertMode {
NONE,
HORIZONTAL,
VERTICAL,
BOTH
}
} }

View file

@ -121,7 +121,7 @@ class PreferencesHelper(val context: Context) {
fun readWithTapping() = flowPrefs.getBoolean(Keys.readWithTapping, true) fun readWithTapping() = flowPrefs.getBoolean(Keys.readWithTapping, true)
fun readWithTappingInverted() = flowPrefs.getBoolean(Keys.readWithTappingInverted, false) fun readWithTappingInverted() = flowPrefs.getEnum(Keys.readWithTappingInverted, Values.TappingInvertMode.NONE)
fun readWithLongTap() = flowPrefs.getBoolean(Keys.readWithLongTap, true) fun readWithLongTap() = flowPrefs.getBoolean(Keys.readWithLongTap, true)

View file

@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.ui.reader.viewer package eu.kanade.tachiyomi.ui.reader.viewer
import com.tfcporciuncula.flow.Preference import com.tfcporciuncula.flow.Preference
import eu.kanade.tachiyomi.data.preference.PreferenceValues.TappingInvertMode
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -20,7 +21,7 @@ abstract class ViewerConfig(preferences: PreferencesHelper) {
var tappingEnabled = true var tappingEnabled = true
var longTapEnabled = true var longTapEnabled = true
var tappingInverted = false var tappingInverted = TappingInvertMode.NONE
var doubleTapAnimDuration = 500 var doubleTapAnimDuration = 500
var volumeKeysEnabled = false var volumeKeysEnabled = false
var volumeKeysInverted = false var volumeKeysInverted = false

View file

@ -7,6 +7,7 @@ import android.view.View
import android.view.ViewGroup.LayoutParams import android.view.ViewGroup.LayoutParams
import androidx.viewpager.widget.ViewPager import androidx.viewpager.widget.ViewPager
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferenceValues.TappingInvertMode
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
@ -80,10 +81,11 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
} }
}) })
pager.tapListener = { event -> pager.tapListener = { event ->
val tappingInverted = config.tappingInverted val invertMode = config.tappingInverted
if (this is VerticalPagerViewer) { if (this is VerticalPagerViewer) {
val positionY = event.y val positionY = event.y
val tappingInverted = invertMode == TappingInvertMode.VERTICAL || invertMode == TappingInvertMode.BOTH
val topSideTap = positionY < pager.height * 0.33f && config.tappingEnabled val topSideTap = positionY < pager.height * 0.33f && config.tappingEnabled
val bottomSideTap = positionY > pager.height * 0.66f && config.tappingEnabled val bottomSideTap = positionY > pager.height * 0.66f && config.tappingEnabled
@ -94,6 +96,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
} }
} else { } else {
val positionX = event.x val positionX = event.x
val tappingInverted = invertMode == TappingInvertMode.HORIZONTAL || invertMode == TappingInvertMode.BOTH
val leftSideTap = positionX < pager.width * 0.33f && config.tappingEnabled val leftSideTap = positionX < pager.width * 0.33f && config.tappingEnabled
val rightSideTap = positionX > pager.width * 0.66f && config.tappingEnabled val rightSideTap = positionX > pager.width * 0.66f && config.tappingEnabled

View file

@ -7,6 +7,7 @@ import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.view.ViewGroup.LayoutParams.MATCH_PARENT
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.PreferenceValues.TappingInvertMode
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
@ -14,10 +15,10 @@ import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters
import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer
import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.util.view.visible
import kotlin.math.max
import kotlin.math.min
import rx.subscriptions.CompositeSubscription import rx.subscriptions.CompositeSubscription
import timber.log.Timber import timber.log.Timber
import kotlin.math.max
import kotlin.math.min
/** /**
* Implementation of a [BaseViewer] to display pages with a [RecyclerView]. * Implementation of a [BaseViewer] to display pages with a [RecyclerView].
@ -94,10 +95,12 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
}) })
recycler.tapListener = { event -> recycler.tapListener = { event ->
val positionY = event.rawY val positionY = event.rawY
val tappingInverted = config.tappingInverted val invertMode = config.tappingInverted
val topSideTap = positionY < recycler.height * 0.33f && config.tappingEnabled val topSideTap = positionY < recycler.height * 0.33f && config.tappingEnabled
val bottomSideTap = positionY > recycler.height * 0.66f && config.tappingEnabled val bottomSideTap = positionY > recycler.height * 0.66f && config.tappingEnabled
val tappingInverted = invertMode == TappingInvertMode.VERTICAL || invertMode == TappingInvertMode.BOTH
when { when {
topSideTap && !tappingInverted || bottomSideTap && tappingInverted -> scrollUp() topSideTap && !tappingInverted || bottomSideTap && tappingInverted -> scrollUp()
bottomSideTap && !tappingInverted || topSideTap && tappingInverted -> scrollDown() bottomSideTap && !tappingInverted || topSideTap && tappingInverted -> scrollDown()

View file

@ -4,9 +4,11 @@ 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.PreferenceKeys as Keys import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
import eu.kanade.tachiyomi.data.preference.PreferenceValues.TappingInvertMode
import eu.kanade.tachiyomi.util.preference.defaultValue 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.intListPreference import eu.kanade.tachiyomi.util.preference.intListPreference
import eu.kanade.tachiyomi.util.preference.listPreference
import eu.kanade.tachiyomi.util.preference.preferenceCategory import eu.kanade.tachiyomi.util.preference.preferenceCategory
import eu.kanade.tachiyomi.util.preference.summaryRes import eu.kanade.tachiyomi.util.preference.summaryRes
import eu.kanade.tachiyomi.util.preference.switchPreference import eu.kanade.tachiyomi.util.preference.switchPreference
@ -190,10 +192,23 @@ class SettingsReaderController : SettingsController() {
titleRes = R.string.pref_read_with_tapping titleRes = R.string.pref_read_with_tapping
defaultValue = true defaultValue = true
} }
switchPreference { listPreference {
key = Keys.readWithTappingInverted key = Keys.readWithTappingInverted
titleRes = R.string.pref_read_with_tapping_inverted titleRes = R.string.pref_read_with_tapping_inverted
defaultValue = false entriesRes = arrayOf(
R.string.tapping_inverted_none,
R.string.tapping_inverted_horizontal,
R.string.tapping_inverted_vertical,
R.string.tapping_inverted_both
)
entryValues = arrayOf(
TappingInvertMode.NONE.name,
TappingInvertMode.HORIZONTAL.name,
TappingInvertMode.VERTICAL.name,
TappingInvertMode.BOTH.name
)
defaultValue = TappingInvertMode.NONE.name
summary = "%s"
}.apply { dependency = Keys.readWithTapping } }.apply { dependency = Keys.readWithTapping }
switchPreference { switchPreference {
key = Keys.readWithLongTap key = Keys.readWithLongTap

View file

@ -665,5 +665,9 @@
<string name="channel_backup_restore_progress">Progress</string> <string name="channel_backup_restore_progress">Progress</string>
<string name="channel_backup_restore_complete">Complete</string> <string name="channel_backup_restore_complete">Complete</string>
<string name="pref_read_with_tapping_inverted">Invert tapping</string> <string name="pref_read_with_tapping_inverted">Invert tapping</string>
<string name="tapping_inverted_none">None</string>
<string name="tapping_inverted_horizontal">Horizontal</string>
<string name="tapping_inverted_vertical">Vertical</string>
<string name="tapping_inverted_both">Both</string>
</resources> </resources>