Horis 2 年 前
親
コミット
e39105f781

+ 2 - 1
app/src/main/java/io/legado/app/constant/PreferKey.kt

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

+ 5 - 2
app/src/main/java/io/legado/app/help/config/AppConfig.kt

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

+ 19 - 1
app/src/main/java/io/legado/app/ui/book/read/BaseReadBookActivity.kt

@@ -5,6 +5,7 @@ import android.content.pm.ActivityInfo
 import android.os.Build
 import android.os.Build
 import android.os.Bundle
 import android.os.Bundle
 import android.view.Gravity
 import android.view.Gravity
+import android.view.KeyEvent
 import android.view.View
 import android.view.View
 import android.view.ViewGroup.LayoutParams.MATCH_PARENT
 import android.view.ViewGroup.LayoutParams.MATCH_PARENT
 import android.view.WindowInsets
 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.PaddingConfigDialog
 import io.legado.app.ui.book.read.config.PageKeyDialog
 import io.legado.app.ui.book.read.config.PageKeyDialog
 import io.legado.app.ui.file.HandleFileContract
 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.viewbindingdelegate.viewBinding
+import io.legado.app.utils.visible
 
 
 /**
 /**
  * 阅读界面
  * 阅读界面
@@ -303,11 +315,17 @@ abstract class BaseReadBookActivity :
     }
     }
 
 
     fun isPrevKey(keyCode: Int): Boolean {
     fun isPrevKey(keyCode: Int): Boolean {
+        if (keyCode == KeyEvent.KEYCODE_UNKNOWN) {
+            return false
+        }
         val prevKeysStr = getPrefString(PreferKey.prevKeys)
         val prevKeysStr = getPrefString(PreferKey.prevKeys)
         return prevKeysStr?.split(",")?.contains(keyCode.toString()) ?: false
         return prevKeysStr?.split(",")?.contains(keyCode.toString()) ?: false
     }
     }
 
 
     fun isNextKey(keyCode: Int): Boolean {
     fun isNextKey(keyCode: Int): Boolean {
+        if (keyCode == KeyEvent.KEYCODE_UNKNOWN) {
+            return false
+        }
         val nextKeysStr = getPrefString(PreferKey.nextKeys)
         val nextKeysStr = getPrefString(PreferKey.nextKeys)
         return nextKeysStr?.split(",")?.contains(keyCode.toString()) ?: false
         return nextKeysStr?.split(",")?.contains(keyCode.toString()) ?: false
     }
     }

+ 65 - 51
app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt

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

+ 2 - 12
app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt

@@ -324,18 +324,8 @@ class PageView(context: Context) : FrameLayout(context) {
                 text = readProgress
                 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"
     }
     }
 
 
     /**
     /**

+ 1 - 1
app/src/main/res/values-es-rES/strings.xml

@@ -1139,5 +1139,5 @@
     <string name="adjust_chapter_page">调整本章页数</string>
     <string name="adjust_chapter_page">调整本章页数</string>
     <string name="adjust_chapter_index">调整章节位置</string>
     <string name="adjust_chapter_index">调整章节位置</string>
     <string name="clear_webview_data_success">清除成功,3秒后自动重启应用</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>
 </resources>

+ 1 - 1
app/src/main/res/values-ja-rJP/strings.xml

@@ -1142,5 +1142,5 @@
     <string name="adjust_chapter_page">调整本章页数</string>
     <string name="adjust_chapter_page">调整本章页数</string>
     <string name="adjust_chapter_index">调整章节位置</string>
     <string name="adjust_chapter_index">调整章节位置</string>
     <string name="clear_webview_data_success">清除成功,3秒后自动重启应用</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>
 </resources>

+ 1 - 1
app/src/main/res/values-pt-rBR/strings.xml

@@ -1142,5 +1142,5 @@
     <string name="adjust_chapter_page">调整本章页数</string>
     <string name="adjust_chapter_page">调整本章页数</string>
     <string name="adjust_chapter_index">调整章节位置</string>
     <string name="adjust_chapter_index">调整章节位置</string>
     <string name="clear_webview_data_success">清除成功,3秒后自动重启应用</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>
 </resources>

+ 1 - 1
app/src/main/res/values-vi/strings.xml

@@ -1138,5 +1138,5 @@ Còn </string>
     <string name="adjust_chapter_page">调整本章页数</string>
     <string name="adjust_chapter_page">调整本章页数</string>
     <string name="adjust_chapter_index">调整章节位置</string>
     <string name="adjust_chapter_index">调整章节位置</string>
     <string name="clear_webview_data_success">清除成功,3秒后自动重启应用</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>
 </resources>

+ 1 - 1
app/src/main/res/values-zh-rHK/strings.xml

@@ -1139,5 +1139,5 @@
     <string name="adjust_chapter_page">调整本章页数</string>
     <string name="adjust_chapter_page">调整本章页数</string>
     <string name="adjust_chapter_index">调整章节位置</string>
     <string name="adjust_chapter_index">调整章节位置</string>
     <string name="clear_webview_data_success">清除成功,3秒后自动重启应用</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>
 </resources>

+ 1 - 1
app/src/main/res/values-zh-rTW/strings.xml

@@ -1141,5 +1141,5 @@
     <string name="adjust_chapter_page">调整本章页数</string>
     <string name="adjust_chapter_page">调整本章页数</string>
     <string name="adjust_chapter_index">调整章节位置</string>
     <string name="adjust_chapter_index">调整章节位置</string>
     <string name="clear_webview_data_success">清除成功,3秒后自动重启应用</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>
 </resources>

+ 1 - 1
app/src/main/res/values-zh/strings.xml

@@ -1141,5 +1141,5 @@
     <string name="adjust_chapter_page">调整本章页数</string>
     <string name="adjust_chapter_page">调整本章页数</string>
     <string name="adjust_chapter_index">调整章节位置</string>
     <string name="adjust_chapter_index">调整章节位置</string>
     <string name="clear_webview_data_success">清除成功,3秒后自动重启应用</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>
 </resources>

+ 1 - 1
app/src/main/res/values/strings.xml

@@ -1142,5 +1142,5 @@
     <string name="adjust_chapter_page">Adjust of chapter page</string>
     <string name="adjust_chapter_page">Adjust of chapter page</string>
     <string name="adjust_chapter_index">Adjust of chapter index</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="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>
 </resources>

+ 2 - 2
app/src/main/res/xml/pref_config_read.xml

@@ -103,8 +103,8 @@
 
 
     <io.legado.app.lib.prefs.SwitchPreference
     <io.legado.app.lib.prefs.SwitchPreference
         android:defaultValue="false"
         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:iconSpaceReserved="false"
         app:isBottomBackground="true" />
         app:isBottomBackground="true" />