pull/2111/head
821938089 2 years ago
parent 38e2fe103a
commit f30bd5192d
  1. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 6
      app/src/main/java/io/legado/app/help/config/AppConfig.kt
  3. 21
      app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt
  4. 3
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt
  5. 14
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
  6. 3
      app/src/main/res/values-es-rES/strings.xml
  7. 3
      app/src/main/res/values-ja-rJP/strings.xml
  8. 3
      app/src/main/res/values-pt-rBR/strings.xml
  9. 3
      app/src/main/res/values-zh-rHK/strings.xml
  10. 3
      app/src/main/res/values-zh-rTW/strings.xml
  11. 3
      app/src/main/res/values-zh/strings.xml
  12. 3
      app/src/main/res/values/strings.xml
  13. 6
      app/src/main/res/xml/pref_config_other.xml

@ -108,6 +108,7 @@ object PreferKey {
const val welcomeShowTextDark = "welcomeShowTextDark" const val welcomeShowTextDark = "welcomeShowTextDark"
const val welcomeShowIcon = "welcomeShowIcon" const val welcomeShowIcon = "welcomeShowIcon"
const val welcomeShowIconDark = "welcomeShowIconDark" const val welcomeShowIconDark = "welcomeShowIconDark"
const val pageTouchSlop = "pageTouchSlop"
const val cPrimary = "colorPrimary" const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent" const val cAccent = "colorAccent"

@ -321,6 +321,12 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
appCtx.putPrefString("searchGroup", value) appCtx.putPrefString("searchGroup", value)
} }
var pageTouchSlop: Int
get() = appCtx.getPrefInt(PreferKey.pageTouchSlop, 0)
set(value) {
appCtx.putPrefInt(PreferKey.pageTouchSlop, value)
}
private fun getPrefUserAgent(): String { private fun getPrefUserAgent(): String {
val ua = appCtx.getPrefString(PreferKey.userAgent) val ua = appCtx.getPrefString(PreferKey.userAgent)
if (ua.isNullOrBlank()) { if (ua.isNullOrBlank()) {

@ -53,6 +53,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
val defaultAnimationSpeed = 300 val defaultAnimationSpeed = 300
private var pressDown = false private var pressDown = false
private var isMove = false private var isMove = false
private var isPageMove = false
//起始点 //起始点
var startX: Float = 0f var startX: Float = 0f
@ -81,6 +82,13 @@ class ReadView(context: Context, attrs: AttributeSet) :
private val initialTextPos = TextPos(0, 0, 0) private val initialTextPos = TextPos(0, 0, 0)
val slopSquare by lazy { ViewConfiguration.get(context).scaledTouchSlop } 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 tlRect = RectF()
private val tcRect = RectF() private val tcRect = RectF()
private val trRect = RectF() private val trRect = RectF()
@ -188,6 +196,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
postDelayed(longPressRunnable, longPressTimeout) postDelayed(longPressRunnable, longPressTimeout)
pressDown = true pressDown = true
isMove = false isMove = false
isPageMove = false
pageDelegate?.onTouch(event) pageDelegate?.onTouch(event)
pageDelegate?.onDown() pageDelegate?.onDown()
setStartPoint(event.x, event.y) setStartPoint(event.x, event.y)
@ -197,12 +206,16 @@ class ReadView(context: Context, attrs: AttributeSet) :
isMove = isMove =
abs(startX - event.x) > slopSquare || abs(startY - event.y) > slopSquare 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) { if (isMove) {
longPressed = false longPressed = false
removeCallbacks(longPressRunnable) removeCallbacks(longPressRunnable)
if (isTextSelected) { if (isTextSelected) {
selectText(event.x, event.y) selectText(event.x, event.y)
} else { } else if (isPageMove) {
pageDelegate?.onTouch(event) pageDelegate?.onTouch(event)
} }
} }
@ -212,7 +225,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
removeCallbacks(longPressRunnable) removeCallbacks(longPressRunnable)
if (!pressDown) return true if (!pressDown) return true
pressDown = false pressDown = false
if (!isMove) { if (!isPageMove) {
if (!longPressed && !pressOnTextSelected) { if (!longPressed && !pressOnTextSelected) {
onSingleTapUp() onSingleTapUp()
return true return true
@ -220,7 +233,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
} }
if (isTextSelected) { if (isTextSelected) {
callBack.showTextActionMenu() callBack.showTextActionMenu()
} else if (isMove) { } else if (isPageMove) {
pageDelegate?.onTouch(event) pageDelegate?.onTouch(event)
} }
pressOnTextSelected = false pressOnTextSelected = false
@ -231,7 +244,7 @@ class ReadView(context: Context, attrs: AttributeSet) :
pressDown = false pressDown = false
if (isTextSelected) { if (isTextSelected) {
callBack.showTextActionMenu() callBack.showTextActionMenu()
} else if (isMove) { } else if (isPageMove) {
pageDelegate?.onTouch(event) pageDelegate?.onTouch(event)
} }
pressOnTextSelected = false pressOnTextSelected = false

@ -11,6 +11,7 @@ abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readVie
protected var curBitmap: Bitmap? = null protected var curBitmap: Bitmap? = null
protected var prevBitmap: Bitmap? = null protected var prevBitmap: Bitmap? = null
protected var nextBitmap: Bitmap? = null protected var nextBitmap: Bitmap? = null
protected val slopSquare by lazy { readView.slopSquare * readView.slopSquare }
override fun setDirection(direction: PageDirection) { override fun setDirection(direction: PageDirection) {
super.setDirection(direction) super.setDirection(direction)
@ -71,7 +72,7 @@ abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readVie
val deltaX = (focusX - startX).toInt() val deltaX = (focusX - startX).toInt()
val deltaY = (focusY - startY).toInt() val deltaY = (focusY - startY).toInt()
val distance = deltaX * deltaX + deltaY * deltaY val distance = deltaX * deltaX + deltaY * deltaY
isMoved = distance > readView.slopSquare isMoved = distance > slopSquare
if (isMoved) { if (isMoved) {
if (sumX - startX > 0) { if (sumX - startX > 0) {
//如果上一页不存在 //如果上一页不存在

@ -6,6 +6,7 @@ import android.content.SharedPreferences
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.view.ViewConfiguration
import androidx.core.view.postDelayed import androidx.core.view.postDelayed
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import androidx.preference.ListPreference import androidx.preference.ListPreference
@ -42,6 +43,7 @@ class OtherConfigFragment : PreferenceFragment(),
AppConfig.defaultBookTreeUri = treeUri.toString() AppConfig.defaultBookTreeUri = treeUri.toString()
} }
} }
private val slopSquare by lazy { ViewConfiguration.get(context).scaledTouchSlop }
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
putPrefBoolean(PreferKey.processText, isProcessTextEnabled()) putPrefBoolean(PreferKey.processText, isProcessTextEnabled())
@ -58,6 +60,7 @@ class OtherConfigFragment : PreferenceFragment(),
} }
upPreferenceSummary(PreferKey.checkSource, CheckSource.summary) upPreferenceSummary(PreferKey.checkSource, CheckSource.summary)
upPreferenceSummary(PreferKey.bitmapCacheSize, AppConfig.bitmapCacheSize.toString()) upPreferenceSummary(PreferKey.bitmapCacheSize, AppConfig.bitmapCacheSize.toString())
upPreferenceSummary(PreferKey.pageTouchSlop, slopSquare.toString())
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -117,6 +120,16 @@ class OtherConfigFragment : PreferenceFragment(),
ImageProvider.bitmapLruCache.resize(ImageProvider.cacheSize) 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) return super.onPreferenceTreeClick(preference)
} }
@ -168,6 +181,7 @@ class OtherConfigFragment : PreferenceFragment(),
PreferKey.threadCount -> preference.summary = getString(R.string.threads_num, value) PreferKey.threadCount -> preference.summary = getString(R.string.threads_num, value)
PreferKey.webPort -> preference.summary = getString(R.string.web_port_summary, 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.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) { else -> if (preference is ListPreference) {
val index = preference.findIndexOfValue(value) val index = preference.findIndexOfValue(value)
// Set the summary to reflect the new value. // Set the summary to reflect the new value.

@ -1003,4 +1003,7 @@
<string name="last_read_time_sort">阅读时间排序</string> <string name="last_read_time_sort">阅读时间排序</string>
<string name="reading_time_tag">阅读时长:</string> <string name="reading_time_tag">阅读时长:</string>
<string name="last_read_time_tag">最后阅读时间:</string> <string name="last_read_time_tag">最后阅读时间:</string>
<string name="page_touch_slop_title">滑动翻页阈值</string>
<string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string>
<string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string>
</resources> </resources>

@ -1006,4 +1006,7 @@
<string name="last_read_time_sort">阅读时间排序</string> <string name="last_read_time_sort">阅读时间排序</string>
<string name="reading_time_tag">阅读时长:</string> <string name="reading_time_tag">阅读时长:</string>
<string name="last_read_time_tag">最后阅读时间:</string> <string name="last_read_time_tag">最后阅读时间:</string>
<string name="page_touch_slop_title">滑动翻页阈值</string>
<string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string>
<string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string>
</resources> </resources>

@ -1006,4 +1006,7 @@
<string name="last_read_time_sort">阅读时间排序</string> <string name="last_read_time_sort">阅读时间排序</string>
<string name="reading_time_tag">阅读时长:</string> <string name="reading_time_tag">阅读时长:</string>
<string name="last_read_time_tag">最后阅读时间:</string> <string name="last_read_time_tag">最后阅读时间:</string>
<string name="page_touch_slop_title">滑动翻页阈值</string>
<string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string>
<string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string>
</resources> </resources>

@ -1003,4 +1003,7 @@
<string name="last_read_time_sort">阅读时间排序</string> <string name="last_read_time_sort">阅读时间排序</string>
<string name="reading_time_tag">阅读时长:</string> <string name="reading_time_tag">阅读时长:</string>
<string name="last_read_time_tag">最后阅读时间:</string> <string name="last_read_time_tag">最后阅读时间:</string>
<string name="page_touch_slop_title">滑动翻页阈值</string>
<string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string>
<string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string>
</resources> </resources>

@ -1005,4 +1005,7 @@
<string name="last_read_time_sort">阅读时间排序</string> <string name="last_read_time_sort">阅读时间排序</string>
<string name="reading_time_tag">阅读时长:</string> <string name="reading_time_tag">阅读时长:</string>
<string name="last_read_time_tag">最后阅读时间:</string> <string name="last_read_time_tag">最后阅读时间:</string>
<string name="page_touch_slop_title">滑动翻页阈值</string>
<string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string>
<string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string>
</resources> </resources>

@ -1005,4 +1005,7 @@
<string name="last_read_time_sort">阅读时间排序</string> <string name="last_read_time_sort">阅读时间排序</string>
<string name="reading_time_tag">阅读时长:</string> <string name="reading_time_tag">阅读时长:</string>
<string name="last_read_time_tag">最后阅读时间:</string> <string name="last_read_time_tag">最后阅读时间:</string>
<string name="page_touch_slop_title">滑动翻页阈值</string>
<string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string>
<string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string>
</resources> </resources>

@ -1006,4 +1006,7 @@
<string name="last_read_time_sort">阅读时间排序</string> <string name="last_read_time_sort">阅读时间排序</string>
<string name="reading_time_tag">阅读时长:</string> <string name="reading_time_tag">阅读时长:</string>
<string name="last_read_time_tag">最后阅读时间:</string> <string name="last_read_time_tag">最后阅读时间:</string>
<string name="page_touch_slop_title">滑动翻页阈值</string>
<string name="page_touch_slop_dialog_title">滑动翻页阈值(0 = 系统默认值)</string>
<string name="page_touch_slop_summary">滑动多长距离才会触发滑动翻页(系统默认值 %s px)</string>
</resources> </resources>

@ -128,6 +128,12 @@
android:title="@string/threads_num_title" android:title="@string/threads_num_title"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.lib.prefs.Preference
android:key="pageTouchSlop"
android:summary="@string/page_touch_slop_summary"
android:title="@string/page_touch_slop_title"
app:iconSpaceReserved="false" />
<io.legado.app.lib.prefs.SwitchPreference <io.legado.app.lib.prefs.SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:key="process_text" android:key="process_text"

Loading…
Cancel
Save