From f30bd5192dd6a10ccc01105db55e0b3ebbfcae4c Mon Sep 17 00:00:00 2001
From: 821938089 <821938089@qq.com>
Date: Mon, 1 Aug 2022 08:57:31 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/io/legado/app/constant/PreferKey.kt | 1 +
.../io/legado/app/help/config/AppConfig.kt | 6 ++++++
.../legado/app/ui/book/read/page/ReadView.kt | 21 +++++++++++++++----
.../page/delegate/HorizontalPageDelegate.kt | 3 ++-
.../app/ui/config/OtherConfigFragment.kt | 14 +++++++++++++
app/src/main/res/values-es-rES/strings.xml | 3 +++
app/src/main/res/values-ja-rJP/strings.xml | 3 +++
app/src/main/res/values-pt-rBR/strings.xml | 3 +++
app/src/main/res/values-zh-rHK/strings.xml | 3 +++
app/src/main/res/values-zh-rTW/strings.xml | 3 +++
app/src/main/res/values-zh/strings.xml | 3 +++
app/src/main/res/values/strings.xml | 3 +++
app/src/main/res/xml/pref_config_other.xml | 6 ++++++
13 files changed, 67 insertions(+), 5 deletions(-)
diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt
index c91bed15d..ded6d3efb 100644
--- a/app/src/main/java/io/legado/app/constant/PreferKey.kt
+++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt
@@ -108,6 +108,7 @@ object PreferKey {
const val welcomeShowTextDark = "welcomeShowTextDark"
const val welcomeShowIcon = "welcomeShowIcon"
const val welcomeShowIconDark = "welcomeShowIconDark"
+ const val pageTouchSlop = "pageTouchSlop"
const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent"
diff --git a/app/src/main/java/io/legado/app/help/config/AppConfig.kt b/app/src/main/java/io/legado/app/help/config/AppConfig.kt
index 8be6ccd4f..81d15e3fe 100644
--- a/app/src/main/java/io/legado/app/help/config/AppConfig.kt
+++ b/app/src/main/java/io/legado/app/help/config/AppConfig.kt
@@ -321,6 +321,12 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
appCtx.putPrefString("searchGroup", value)
}
+ var pageTouchSlop: Int
+ get() = appCtx.getPrefInt(PreferKey.pageTouchSlop, 0)
+ set(value) {
+ appCtx.putPrefInt(PreferKey.pageTouchSlop, value)
+ }
+
private fun getPrefUserAgent(): String {
val ua = appCtx.getPrefString(PreferKey.userAgent)
if (ua.isNullOrBlank()) {
diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt
index 55b9356c2..62383664a 100644
--- a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt
+++ b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt
@@ -53,6 +53,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
val defaultAnimationSpeed = 300
private var pressDown = false
private var isMove = false
+ private var isPageMove = false
//起始点
var startX: Float = 0f
@@ -81,6 +82,13 @@ class ReadView(context: Context, attrs: AttributeSet) :
private val initialTextPos = TextPos(0, 0, 0)
val slopSquare by lazy { ViewConfiguration.get(context).scaledTouchSlop }
+ val pageSlopSquare by lazy {
+ if (AppConfig.pageTouchSlop == 0) {
+ slopSquare
+ } else {
+ AppConfig.pageTouchSlop
+ }
+ }
private val tlRect = RectF()
private val tcRect = RectF()
private val trRect = RectF()
@@ -188,6 +196,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
postDelayed(longPressRunnable, longPressTimeout)
pressDown = true
isMove = false
+ isPageMove = false
pageDelegate?.onTouch(event)
pageDelegate?.onDown()
setStartPoint(event.x, event.y)
@@ -197,12 +206,16 @@ class ReadView(context: Context, attrs: AttributeSet) :
isMove =
abs(startX - event.x) > slopSquare || abs(startY - event.y) > slopSquare
}
+ if (!isPageMove) {
+ isPageMove =
+ abs(startX - event.x) > pageSlopSquare || abs(startY - event.y) > pageSlopSquare
+ }
if (isMove) {
longPressed = false
removeCallbacks(longPressRunnable)
if (isTextSelected) {
selectText(event.x, event.y)
- } else {
+ } else if (isPageMove) {
pageDelegate?.onTouch(event)
}
}
@@ -212,7 +225,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
removeCallbacks(longPressRunnable)
if (!pressDown) return true
pressDown = false
- if (!isMove) {
+ if (!isPageMove) {
if (!longPressed && !pressOnTextSelected) {
onSingleTapUp()
return true
@@ -220,7 +233,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
}
if (isTextSelected) {
callBack.showTextActionMenu()
- } else if (isMove) {
+ } else if (isPageMove) {
pageDelegate?.onTouch(event)
}
pressOnTextSelected = false
@@ -231,7 +244,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
pressDown = false
if (isTextSelected) {
callBack.showTextActionMenu()
- } else if (isMove) {
+ } else if (isPageMove) {
pageDelegate?.onTouch(event)
}
pressOnTextSelected = false
diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt
index 471006247..d054c31e6 100644
--- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt
+++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt
@@ -11,6 +11,7 @@ abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readVie
protected var curBitmap: Bitmap? = null
protected var prevBitmap: Bitmap? = null
protected var nextBitmap: Bitmap? = null
+ protected val slopSquare by lazy { readView.slopSquare * readView.slopSquare }
override fun setDirection(direction: PageDirection) {
super.setDirection(direction)
@@ -71,7 +72,7 @@ abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readVie
val deltaX = (focusX - startX).toInt()
val deltaY = (focusY - startY).toInt()
val distance = deltaX * deltaX + deltaY * deltaY
- isMoved = distance > readView.slopSquare
+ isMoved = distance > slopSquare
if (isMoved) {
if (sumX - startX > 0) {
//如果上一页不存在
diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
index 9f9f9e038..e2b311262 100644
--- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
+++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
@@ -6,6 +6,7 @@ import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.os.Bundle
import android.view.View
+import android.view.ViewConfiguration
import androidx.core.view.postDelayed
import androidx.fragment.app.activityViewModels
import androidx.preference.ListPreference
@@ -42,6 +43,7 @@ class OtherConfigFragment : PreferenceFragment(),
AppConfig.defaultBookTreeUri = treeUri.toString()
}
}
+ private val slopSquare by lazy { ViewConfiguration.get(context).scaledTouchSlop }
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
putPrefBoolean(PreferKey.processText, isProcessTextEnabled())
@@ -58,6 +60,7 @@ class OtherConfigFragment : PreferenceFragment(),
}
upPreferenceSummary(PreferKey.checkSource, CheckSource.summary)
upPreferenceSummary(PreferKey.bitmapCacheSize, AppConfig.bitmapCacheSize.toString())
+ upPreferenceSummary(PreferKey.pageTouchSlop, slopSquare.toString())
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@@ -117,6 +120,16 @@ class OtherConfigFragment : PreferenceFragment(),
ImageProvider.bitmapLruCache.resize(ImageProvider.cacheSize)
}
}
+ PreferKey.pageTouchSlop -> {
+ NumberPickerDialog(requireContext())
+ .setTitle(getString(R.string.page_touch_slop_dialog_title))
+ .setMaxValue(9999)
+ .setMinValue(0)
+ .setValue(AppConfig.pageTouchSlop)
+ .show {
+ AppConfig.pageTouchSlop = it
+ }
+ }
}
return super.onPreferenceTreeClick(preference)
}
@@ -168,6 +181,7 @@ class OtherConfigFragment : PreferenceFragment(),
PreferKey.threadCount -> preference.summary = getString(R.string.threads_num, value)
PreferKey.webPort -> preference.summary = getString(R.string.web_port_summary, value)
PreferKey.bitmapCacheSize -> preference.summary = getString(R.string.bitmap_cache_size_summary, value)
+ PreferKey.pageTouchSlop -> preference.summary = getString(R.string.page_touch_slop_summary, value)
else -> if (preference is ListPreference) {
val index = preference.findIndexOfValue(value)
// Set the summary to reflect the new value.
diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml
index 745eeedba..da84ae19f 100644
--- a/app/src/main/res/values-es-rES/strings.xml
+++ b/app/src/main/res/values-es-rES/strings.xml
@@ -1003,4 +1003,7 @@
阅读时间排序
阅读时长:
最后阅读时间:
+ 滑动翻页阈值
+ 滑动翻页阈值(0 = 系统默认值)
+ 滑动多长距离才会触发滑动翻页(系统默认值 %s px)
diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml
index 0b8f25f64..5abffefef 100644
--- a/app/src/main/res/values-ja-rJP/strings.xml
+++ b/app/src/main/res/values-ja-rJP/strings.xml
@@ -1006,4 +1006,7 @@
阅读时间排序
阅读时长:
最后阅读时间:
+ 滑动翻页阈值
+ 滑动翻页阈值(0 = 系统默认值)
+ 滑动多长距离才会触发滑动翻页(系统默认值 %s px)
diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml
index 2330320d8..c408ab7a6 100644
--- a/app/src/main/res/values-pt-rBR/strings.xml
+++ b/app/src/main/res/values-pt-rBR/strings.xml
@@ -1006,4 +1006,7 @@
阅读时间排序
阅读时长:
最后阅读时间:
+ 滑动翻页阈值
+ 滑动翻页阈值(0 = 系统默认值)
+ 滑动多长距离才会触发滑动翻页(系统默认值 %s px)
diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml
index 0f79c0a58..80a3df2fa 100644
--- a/app/src/main/res/values-zh-rHK/strings.xml
+++ b/app/src/main/res/values-zh-rHK/strings.xml
@@ -1003,4 +1003,7 @@
阅读时间排序
阅读时长:
最后阅读时间:
+ 滑动翻页阈值
+ 滑动翻页阈值(0 = 系统默认值)
+ 滑动多长距离才会触发滑动翻页(系统默认值 %s px)
diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml
index 23fbac7a8..b6375b7bb 100644
--- a/app/src/main/res/values-zh-rTW/strings.xml
+++ b/app/src/main/res/values-zh-rTW/strings.xml
@@ -1005,4 +1005,7 @@
阅读时间排序
阅读时长:
最后阅读时间:
+ 滑动翻页阈值
+ 滑动翻页阈值(0 = 系统默认值)
+ 滑动多长距离才会触发滑动翻页(系统默认值 %s px)
diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml
index 2128c5fba..58bc32cf2 100644
--- a/app/src/main/res/values-zh/strings.xml
+++ b/app/src/main/res/values-zh/strings.xml
@@ -1005,4 +1005,7 @@
阅读时间排序
阅读时长:
最后阅读时间:
+ 滑动翻页阈值
+ 滑动翻页阈值(0 = 系统默认值)
+ 滑动多长距离才会触发滑动翻页(系统默认值 %s px)
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index bde301b76..1be2b90dd 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1006,4 +1006,7 @@
阅读时间排序
阅读时长:
最后阅读时间:
+ 滑动翻页阈值
+ 滑动翻页阈值(0 = 系统默认值)
+ 滑动多长距离才会触发滑动翻页(系统默认值 %s px)
diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml
index 8da45d5a6..033d88ad1 100644
--- a/app/src/main/res/xml/pref_config_other.xml
+++ b/app/src/main/res/xml/pref_config_other.xml
@@ -128,6 +128,12 @@
android:title="@string/threads_num_title"
app:iconSpaceReserved="false" />
+
+