Supports page turning when holding volume keys

This commit is contained in:
FooIbar authored and tarsin committed 2023-01-26 08:44:14 +08:00
1 parent 1e620931a2
commit 065a14952a
8 files changed
+74 -5

No files matched your search

@@ -51,7 +51,16 @@ class ReaderGeneralSettings @JvmOverloads constructor(context: Context, attrs: A
binding.volumePage.bindToPreference(readerPreferences.readWithVolumeKeys())
binding.reserveVolumePage.bindToPreference(readerPreferences.readWithVolumeKeysInverted())
readerPreferences.readWithVolumeKeys().asHotFlow {
binding.volumePageSpeed.isVisible = it
binding.reserveVolumePage.isVisible = it
}.launchIn((context as ReaderActivity).lifecycleScope)
val volumePageInterval = readerPreferences.readWithVolumeKeysInterval().get()
binding.sliderVolumePageInterval.value = volumePageInterval.toFloat()
binding.sliderVolumePageInterval.addOnChangeListener { _, value, fromUser ->
if (fromUser) {
readerPreferences.readWithVolumeKeysInterval().set(value.toInt())
}
}
}
}
@@ -92,6 +92,8 @@ class ReaderPreferences(private val preferenceStore: PreferenceStore) {
fun readWithVolumeKeys() = preferenceStore.getBoolean("reader_volume_keys", false)
fun readWithVolumeKeysInterval() = preferenceStore.getInt("reader_volume_keys_interval", 0)
fun readWithVolumeKeysInverted() = preferenceStore.getBoolean("reader_volume_keys_inverted", false)
fun navigationModePager() = preferenceStore.getInt("reader_navigation_mode_pager", 0)
@@ -22,6 +22,7 @@ abstract class ViewerConfig(readerPreferences: ReaderPreferences, private val sc
var usePageTransitions = false
var doubleTapAnimDuration = 500
var volumeKeysEnabled = false
var volumeKeysInterval = 0
var volumeKeysInverted = false
var trueColor = false
var alwaysShowChapterTransition = true
@@ -54,6 +55,9 @@ abstract class ViewerConfig(readerPreferences: ReaderPreferences, private val sc
readerPreferences.readWithVolumeKeys()
.register({ volumeKeysEnabled = it })
readerPreferences.readWithVolumeKeysInterval()
.register({ volumeKeysInterval = it })
readerPreferences.readWithVolumeKeysInverted()
.register({ volumeKeysInverted = it })
@@ -11,8 +11,8 @@ import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.viewpager.widget.ViewPager
import com.hippo.ehviewer.R
import eu.kanade.tachiyomi.ui.reader.loader.PageLoader
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.ui.reader.loader.PageLoader
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation.NavigationRegion
@@ -70,6 +70,8 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
}
}
private var longPressed = false
init {
pager.isVisible = false // Don't layout the pager yet
pager.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
@@ -304,19 +306,22 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
override fun handleKeyEvent(event: KeyEvent): Boolean {
val isUp = event.action == KeyEvent.ACTION_UP
val ctrlPressed = event.metaState.and(KeyEvent.META_CTRL_ON) > 0
val interval = config.volumeKeysInterval
val movePage = longPressed && (interval == 0 || event.repeatCount % (interval + 1) == 0)
longPressed = event.isLongPress || !isUp && longPressed
when (event.keyCode) {
KeyEvent.KEYCODE_VOLUME_DOWN -> {
if (!config.volumeKeysEnabled || activity.menuVisible) {
return false
} else if (isUp) {
} else if (isUp != movePage) {
if (!config.volumeKeysInverted) moveDown() else moveUp()
}
}
KeyEvent.KEYCODE_VOLUME_UP -> {
if (!config.volumeKeysEnabled || activity.menuVisible) {
return false
} else if (isUp) {
} else if (isUp != movePage) {
if (!config.volumeKeysInverted) moveUp() else moveDown()
}
}
@@ -66,6 +66,8 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
private val threshold: Int = 13
private var longPressed = false
init {
recycler.isVisible = false // Don't let the recycler layout yet
recycler.layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)
@@ -214,19 +216,22 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
*/
override fun handleKeyEvent(event: KeyEvent): Boolean {
val isUp = event.action == KeyEvent.ACTION_UP
val interval = config.volumeKeysInterval
val movePage = longPressed && (interval == 0 || event.repeatCount % (interval + 1) == 0)
longPressed = event.isLongPress || !isUp && longPressed
when (event.keyCode) {
KeyEvent.KEYCODE_VOLUME_DOWN -> {
if (!config.volumeKeysEnabled || activity.menuVisible) {
return false
} else if (isUp) {
} else if (isUp != movePage) {
if (!config.volumeKeysInverted) scrollDown() else scrollUp()
}
}
KeyEvent.KEYCODE_VOLUME_UP -> {
if (!config.volumeKeysEnabled || activity.menuVisible) {
return false
} else if (isUp) {
} else if (isUp != movePage) {
if (!config.volumeKeysInverted) scrollUp() else scrollDown()
}
}
@@ -91,6 +91,46 @@
android:text="@string/settings_read_volume_page"
android:textColor="?android:attr/textColorSecondary" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/volume_page_speed"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/txt_volume_page_fast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="@string/settings_read_volume_page_fast"
app:layout_constraintBottom_toBottomOf="@id/slider_volume_page_interval"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/slider_volume_page_interval" />
<com.google.android.material.slider.Slider
android:id="@+id/slider_volume_page_interval"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:padding="8dp"
android:stepSize="1.0"
android:valueFrom="0.0"
android:valueTo="9.0"
app:layout_constraintEnd_toStartOf="@id/txt_volume_page_slow"
app:layout_constraintStart_toEndOf="@id/txt_volume_page_fast"
app:layout_constraintTop_toTopOf="@id/volume_page_speed" />
<TextView
android:id="@+id/txt_volume_page_slow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/settings_read_volume_page_slow"
app:layout_constraintBottom_toBottomOf="@id/slider_volume_page_interval"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/slider_volume_page_interval" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/reserve_volume_page"
android:layout_width="match_parent"
@@ -348,6 +348,8 @@
<string name="settings_eh_filter">屏蔽列表</string>
<string name="settings_eh_filter_summary">根据标题、上传者、标签、评论者屏蔽画廊或评论</string>
<string name="settings_read_volume_page">使用音量键翻页</string>
<string name="settings_read_volume_page_fast">快</string>
<string name="settings_read_volume_page_slow">慢</string>
<string name="settings_read_reverse_volume">翻转音量键</string>
<string name="settings_download">下载</string>
<string name="settings_download_download_location">下载路径</string>
+2
View File
@@ -390,6 +390,8 @@
<string name="settings_eh_filter">Blockers</string>
<string name="settings_eh_filter_summary">Block gallery or comment by title, uploader, tags and commenter</string>
<string name="settings_read_volume_page">Use volume key to turn pages</string>
<string name="settings_read_volume_page_fast">Fast</string>
<string name="settings_read_volume_page_slow">Slow</string>
<string name="settings_read_reverse_volume">Reverse volume key</string>
<string name="settings_download">Download</string>
<string name="settings_download_download_location">Download location</string>