mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
//如果上一页不存在
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -1003,4 +1003,7 @@
|
||||
<string name="last_read_time_sort">阅读时间排序</string>
|
||||
<string name="reading_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>
|
||||
|
||||
@@ -1006,4 +1006,7 @@
|
||||
<string name="last_read_time_sort">阅读时间排序</string>
|
||||
<string name="reading_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>
|
||||
|
||||
@@ -1006,4 +1006,7 @@
|
||||
<string name="last_read_time_sort">阅读时间排序</string>
|
||||
<string name="reading_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>
|
||||
|
||||
@@ -1003,4 +1003,7 @@
|
||||
<string name="last_read_time_sort">阅读时间排序</string>
|
||||
<string name="reading_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>
|
||||
|
||||
@@ -1005,4 +1005,7 @@
|
||||
<string name="last_read_time_sort">阅读时间排序</string>
|
||||
<string name="reading_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>
|
||||
|
||||
@@ -1005,4 +1005,7 @@
|
||||
<string name="last_read_time_sort">阅读时间排序</string>
|
||||
<string name="reading_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>
|
||||
|
||||
@@ -1006,4 +1006,7 @@
|
||||
<string name="last_read_time_sort">阅读时间排序</string>
|
||||
<string name="reading_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>
|
||||
|
||||
@@ -128,6 +128,12 @@
|
||||
android:title="@string/threads_num_title"
|
||||
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
|
||||
android:defaultValue="true"
|
||||
android:key="process_text"
|
||||
|
||||
Reference in New Issue
Block a user