This commit is contained in:
Horis 2023-12-23 22:57:25 +08:00
parent 0a75ad6c0f
commit 8ad6702fa7
14 changed files with 114 additions and 88 deletions

View File

@ -140,9 +140,10 @@ object PreferKey {
const val showBookshelfFastScroller = "showBookshelfFastScroller"
const val importKeepEnable = "importKeepEnable"
const val previewImageByClick = "previewImageByClick"
const val volumeKeyPageOnLongPress = "volumeKeyPageOnLongPress"
const val keyPageOnLongPress = "keyPageOnLongPress"
const val volumeKeyPage = "volumeKeyPage"
const val volumeKeyPageOnPlay = "volumeKeyPageOnPlay"
const val mouseWheelPage = "mouseWheelPage"
const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent"

View File

@ -467,8 +467,8 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
val progressBarBehavior: String?
get() = appCtx.getPrefString(PreferKey.progressBarBehavior, "page")
val volumeKeyPageOnLongPress
get() = appCtx.getPrefBoolean(PreferKey.volumeKeyPageOnLongPress, false)
val keyPageOnLongPress
get() = appCtx.getPrefBoolean(PreferKey.keyPageOnLongPress, false)
val volumeKeyPage
get() = appCtx.getPrefBoolean(PreferKey.volumeKeyPage, true)
@ -476,6 +476,9 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
val volumeKeyPageOnPlay
get() = appCtx.getPrefBoolean(PreferKey.volumeKeyPageOnPlay, true)
val mouseWheelPage
get() = appCtx.getPrefBoolean(PreferKey.mouseWheelPage, true)
var searchScope: String
get() = appCtx.getPrefString("searchScope") ?: ""
set(value) {

View File

@ -5,6 +5,7 @@ import android.content.pm.ActivityInfo
import android.os.Build
import android.os.Bundle
import android.view.Gravity
import android.view.KeyEvent
import android.view.View
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.WindowInsets
@ -34,8 +35,19 @@ import io.legado.app.ui.book.read.config.ClickActionConfigDialog
import io.legado.app.ui.book.read.config.PaddingConfigDialog
import io.legado.app.ui.book.read.config.PageKeyDialog
import io.legado.app.ui.file.HandleFileContract
import io.legado.app.utils.*
import io.legado.app.utils.ColorUtils
import io.legado.app.utils.FileDoc
import io.legado.app.utils.find
import io.legado.app.utils.getPrefString
import io.legado.app.utils.gone
import io.legado.app.utils.isTv
import io.legado.app.utils.navigationBarGravity
import io.legado.app.utils.navigationBarHeight
import io.legado.app.utils.setLightStatusBar
import io.legado.app.utils.setNavigationBarColorAuto
import io.legado.app.utils.showDialogFragment
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible
/**
* 阅读界面
@ -303,11 +315,17 @@ abstract class BaseReadBookActivity :
}
fun isPrevKey(keyCode: Int): Boolean {
if (keyCode == KeyEvent.KEYCODE_UNKNOWN) {
return false
}
val prevKeysStr = getPrefString(PreferKey.prevKeys)
return prevKeysStr?.split(",")?.contains(keyCode.toString()) ?: false
}
fun isNextKey(keyCode: Int): Boolean {
if (keyCode == KeyEvent.KEYCODE_UNKNOWN) {
return false
}
val nextKeysStr = getPrefString(PreferKey.nextKeys)
return nextKeysStr?.split(",")?.contains(keyCode.toString()) ?: false
}

View File

@ -6,6 +6,7 @@ import android.content.Intent
import android.content.res.Configuration
import android.net.Uri
import android.os.Bundle
import android.os.SystemClock
import android.view.Gravity
import android.view.InputDevice
import android.view.KeyEvent
@ -96,6 +97,7 @@ import io.legado.app.utils.LogUtils
import io.legado.app.utils.StartActivityContract
import io.legado.app.utils.SyncedRenderer
import io.legado.app.utils.applyOpenTint
import io.legado.app.utils.buildMainHandler
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.getPrefString
import io.legado.app.utils.hexString
@ -215,13 +217,15 @@ class ReadBookActivity : BaseReadBookActivity(),
override val pageFactory: TextPageFactory get() = binding.readView.pageFactory
override val headerHeight: Int get() = binding.readView.curPage.headerHeight
private val menuLayoutIsVisible get() = bottomDialog > 0 || binding.readMenu.isVisible
private val nextPageRunnable by lazy { Runnable { mouseWheelPage(PageDirection.NEXT) } }
private val prevPageRunnable by lazy { Runnable { mouseWheelPage(PageDirection.PREV) } }
private val nextPageRunnable by lazy { Runnable { keyPage(PageDirection.NEXT) } }
private val prevPageRunnable by lazy { Runnable { keyPage(PageDirection.PREV) } }
private var bookChanged = false
private var pageChanged = false
private var reloadContent = false
private val autoPageRenderer by lazy { SyncedRenderer { doAutoPage(it) } }
private var autoPageScrollOffset = 0.0
private val handler by lazy { buildMainHandler() }
private var lastKeyPageTime = 0L
//恢复跳转前进度对话框的交互结果
private var confirmRestoreProcess: Boolean? = null
@ -601,13 +605,11 @@ class ReadBookActivity : BaseReadBookActivity(),
if (event.action == MotionEvent.ACTION_SCROLL) {
val axisValue = event.getAxisValue(MotionEvent.AXIS_VSCROLL)
LogUtils.d("onGenericMotionEvent", "axisValue = $axisValue")
binding.root.removeCallbacks(nextPageRunnable)
binding.root.removeCallbacks(prevPageRunnable)
// 获得垂直坐标上的滚动方向
if (axisValue < 0.0f) { // 滚轮向下滚
binding.root.postDelayed(nextPageRunnable, 200)
mouseWheelPage(PageDirection.NEXT)
} else { // 滚轮向上滚
binding.root.postDelayed(prevPageRunnable, 200)
mouseWheelPage(PageDirection.PREV)
}
return true
}
@ -624,52 +626,40 @@ class ReadBookActivity : BaseReadBookActivity(),
}
when {
isPrevKey(keyCode) -> {
if (keyCode != KeyEvent.KEYCODE_UNKNOWN) {
binding.readView.cancelSelect()
binding.readView.pageDelegate?.keyTurnPage(PageDirection.PREV)
return true
}
handleKeyPage(PageDirection.PREV)
return true
}
isNextKey(keyCode) -> {
if (keyCode != KeyEvent.KEYCODE_UNKNOWN) {
binding.readView.cancelSelect()
binding.readView.pageDelegate?.keyTurnPage(PageDirection.NEXT)
return true
}
}
keyCode == KeyEvent.KEYCODE_VOLUME_UP -> {
if (volumeKeyPage(PageDirection.PREV, event.repeatCount > 0)) {
return true
}
}
keyCode == KeyEvent.KEYCODE_VOLUME_DOWN -> {
if (volumeKeyPage(PageDirection.NEXT, event.repeatCount > 0)) {
return true
}
}
keyCode == KeyEvent.KEYCODE_PAGE_UP -> {
binding.readView.cancelSelect()
binding.readView.pageDelegate?.keyTurnPage(PageDirection.PREV)
handleKeyPage(PageDirection.NEXT)
return true
}
keyCode == KeyEvent.KEYCODE_PAGE_DOWN -> {
binding.readView.cancelSelect()
binding.readView.pageDelegate?.keyTurnPage(PageDirection.NEXT)
return true
}
keyCode == KeyEvent.KEYCODE_SPACE -> {
binding.readView.cancelSelect()
binding.readView.pageDelegate?.keyTurnPage(PageDirection.NEXT)
return true
}
}
when (keyCode) {
KeyEvent.KEYCODE_VOLUME_UP -> if (volumeKeyPage(PageDirection.PREV)) {
return true
}
KeyEvent.KEYCODE_VOLUME_DOWN -> if (volumeKeyPage(PageDirection.NEXT)) {
return true
}
KeyEvent.KEYCODE_PAGE_UP -> {
handleKeyPage(PageDirection.PREV)
return true
}
KeyEvent.KEYCODE_PAGE_DOWN -> {
handleKeyPage(PageDirection.NEXT)
return true
}
KeyEvent.KEYCODE_SPACE -> {
handleKeyPage(PageDirection.NEXT)
return true
}
}
return super.onKeyDown(keyCode, event)
}
@ -679,7 +669,7 @@ class ReadBookActivity : BaseReadBookActivity(),
override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
when (keyCode) {
KeyEvent.KEYCODE_VOLUME_UP, KeyEvent.KEYCODE_VOLUME_DOWN -> {
if (volumeKeyPage(PageDirection.NONE, event.repeatCount > 0)) {
if (volumeKeyPage(PageDirection.NONE)) {
return true
}
}
@ -858,37 +848,61 @@ class ReadBookActivity : BaseReadBookActivity(),
/**
* 鼠标滚轮翻页
*/
private fun mouseWheelPage(direction: PageDirection): Boolean {
if (!binding.readMenu.isVisible) {
if (getPrefBoolean("mouseWheelPage", true)) {
binding.readView.pageDelegate?.isCancel = false
binding.readView.pageDelegate?.keyTurnPage(direction)
return true
}
private fun mouseWheelPage(direction: PageDirection) {
if (menuLayoutIsVisible || !AppConfig.mouseWheelPage) {
return
}
return false
keyPageDebounce(direction, 200L, true)
}
/**
* 音量键翻页
*/
private fun volumeKeyPage(direction: PageDirection, longPress: Boolean): Boolean {
if (menuLayoutIsVisible) {
return false
}
private fun volumeKeyPage(direction: PageDirection): Boolean {
if (!AppConfig.volumeKeyPage) {
return false
}
if (!AppConfig.volumeKeyPageOnPlay && BaseReadAloudService.isPlay()) {
return false
}
if (!AppConfig.volumeKeyPageOnLongPress && longPress) {
return true
handleKeyPage(direction)
return true
}
private fun handleKeyPage(direction: PageDirection) {
if (AppConfig.keyPageOnLongPress || direction == PageDirection.NONE) {
keyPage(direction)
} else {
keyPageDebounce(direction)
}
}
private fun keyPageDebounce(
direction: PageDirection,
delay: Long = 100L,
mouseWheel: Boolean = false
) {
handler.removeCallbacks(nextPageRunnable)
handler.removeCallbacks(prevPageRunnable)
if (!mouseWheel) {
val keyPageTime = SystemClock.uptimeMillis()
val elapsed = keyPageTime - lastKeyPageTime
lastKeyPageTime = keyPageTime
if (elapsed < 100) {
return
}
}
when (direction) {
PageDirection.NEXT -> handler.postDelayed(nextPageRunnable, delay)
PageDirection.PREV -> handler.postDelayed(prevPageRunnable, delay)
else -> {}
}
}
private fun keyPage(direction: PageDirection) {
binding.readView.cancelSelect()
binding.readView.pageDelegate?.isCancel = false
binding.readView.pageDelegate?.keyTurnPage(direction)
return true
}
override fun upMenuView() {

View File

@ -324,18 +324,8 @@ class PageView(context: Context) : FrameLayout(context) {
text = readProgress
}
}
tvTotalProgress1?.apply {
val progress = "${chapterIndex.plus(1)}/${chapterSize}"
if (text != progress) {
text = progress
}
}
tvPageAndTotal?.apply {
val pageAndTotal = "${index.plus(1)}/$pageSize $readProgress"
if (text != pageAndTotal) {
text = pageAndTotal
}
}
tvTotalProgress1?.text = "${chapterIndex.plus(1)}/${chapterSize}"
tvPageAndTotal?.text = "${index.plus(1)}/$pageSize $readProgress"
}
/**

View File

@ -1139,5 +1139,5 @@
<string name="adjust_chapter_page">调整本章页数</string>
<string name="adjust_chapter_index">调整章节位置</string>
<string name="clear_webview_data_success">清除成功3秒后自动重启应用</string>
<string name="volume_key_page_on_long_press">长按音量键翻页</string>
<string name="key_page_on_long_press">按键长按翻页</string>
</resources>

View File

@ -1142,5 +1142,5 @@
<string name="adjust_chapter_page">调整本章页数</string>
<string name="adjust_chapter_index">调整章节位置</string>
<string name="clear_webview_data_success">清除成功3秒后自动重启应用</string>
<string name="volume_key_page_on_long_press">长按音量键翻页</string>
<string name="key_page_on_long_press">按键长按翻页</string>
</resources>

View File

@ -1142,5 +1142,5 @@
<string name="adjust_chapter_page">调整本章页数</string>
<string name="adjust_chapter_index">调整章节位置</string>
<string name="clear_webview_data_success">清除成功3秒后自动重启应用</string>
<string name="volume_key_page_on_long_press">长按音量键翻页</string>
<string name="key_page_on_long_press">按键长按翻页</string>
</resources>

View File

@ -1138,5 +1138,5 @@ Còn </string>
<string name="adjust_chapter_page">调整本章页数</string>
<string name="adjust_chapter_index">调整章节位置</string>
<string name="clear_webview_data_success">清除成功3秒后自动重启应用</string>
<string name="volume_key_page_on_long_press">长按音量键翻页</string>
<string name="key_page_on_long_press">按键长按翻页</string>
</resources>

View File

@ -1139,5 +1139,5 @@
<string name="adjust_chapter_page">调整本章页数</string>
<string name="adjust_chapter_index">调整章节位置</string>
<string name="clear_webview_data_success">清除成功3秒后自动重启应用</string>
<string name="volume_key_page_on_long_press">长按音量键翻页</string>
<string name="key_page_on_long_press">按键长按翻页</string>
</resources>

View File

@ -1141,5 +1141,5 @@
<string name="adjust_chapter_page">调整本章页数</string>
<string name="adjust_chapter_index">调整章节位置</string>
<string name="clear_webview_data_success">清除成功3秒后自动重启应用</string>
<string name="volume_key_page_on_long_press">长按音量键翻页</string>
<string name="key_page_on_long_press">按键长按翻页</string>
</resources>

View File

@ -1141,5 +1141,5 @@
<string name="adjust_chapter_page">调整本章页数</string>
<string name="adjust_chapter_index">调整章节位置</string>
<string name="clear_webview_data_success">清除成功3秒后自动重启应用</string>
<string name="volume_key_page_on_long_press">长按音量键翻页</string>
<string name="key_page_on_long_press">按键长按翻页</string>
</resources>

View File

@ -1142,5 +1142,5 @@
<string name="adjust_chapter_page">Adjust of chapter page</string>
<string name="adjust_chapter_index">Adjust of chapter index</string>
<string name="clear_webview_data_success">Cleared successfully, automatically restarts the application after 3 seconds</string>
<string name="volume_key_page_on_long_press">Press and hold the volume key to turn the page</string>
<string name="key_page_on_long_press">Press and hold the key to turn the page</string>
</resources>

View File

@ -103,8 +103,8 @@
<io.legado.app.lib.prefs.SwitchPreference
android:defaultValue="false"
android:key="volumeKeyPageOnLongPress"
android:title="@string/volume_key_page_on_long_press"
android:key="keyPageOnLongPress"
android:title="@string/key_page_on_long_press"
app:iconSpaceReserved="false"
app:isBottomBackground="true" />