diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 633eb414b..7fcab742b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -1196,6 +1196,7 @@ class ReadBookActivity : BaseReadBookActivity(), } observeEvent(EventBus.UP_CONFIG) { upSystemUiVisibility() + readView.upPageSlopSquare() readView.upBg() readView.upStyle() readView.upBgAlpha() diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt index 76462ca18..18a452c3b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt @@ -11,6 +11,7 @@ import androidx.preference.Preference import io.legado.app.R import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey +import io.legado.app.help.config.AppConfig import io.legado.app.help.config.ReadBookConfig import io.legado.app.lib.prefs.fragment.PreferenceFragment import io.legado.app.lib.theme.bottomBackground @@ -18,6 +19,7 @@ import io.legado.app.lib.theme.primaryColor import io.legado.app.model.ReadBook import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.read.page.provider.ChapterProvider +import io.legado.app.ui.widget.number.NumberPickerDialog import io.legado.app.utils.dpToPx import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.postEvent @@ -70,9 +72,12 @@ class MoreConfigDialog : DialogFragment() { class ReadPreferenceFragment : PreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener { + private val slopSquare by lazy { ViewConfiguration.get(context).scaledTouchSlop } + @SuppressLint("RestrictedApi") override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.pref_config_read) + upPreferenceSummary(PreferKey.pageTouchSlop, slopSquare.toString()) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -137,9 +142,29 @@ class MoreConfigDialog : DialogFragment() { "clickRegionalConfig" -> { (activity as? ReadBookActivity)?.showClickRegionalConfig() } + PreferKey.pageTouchSlop -> { + NumberPickerDialog(requireContext()) + .setTitle(getString(R.string.page_touch_slop_dialog_title)) + .setMaxValue(9999) + .setMinValue(0) + .setValue(AppConfig.pageTouchSlop) + .show { + AppConfig.pageTouchSlop = it + postEvent(EventBus.UP_CONFIG, false) + } + } } return super.onPreferenceTreeClick(preference) } + @Suppress("SameParameterValue") + private fun upPreferenceSummary(preferenceKey: String, value: String?) { + val preference = findPreference(preferenceKey) ?: return + when (preferenceKey) { + PreferKey.pageTouchSlop -> preference.summary = + getString(R.string.page_touch_slop_summary, value) + } + } + } } \ No newline at end of file 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 ad6fb8fc9..06cfa3326 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 @@ -82,13 +82,7 @@ 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 var pageSlopSquare: Int = slopSquare private val tlRect = RectF() private val tcRect = RectF() private val trRect = RectF() @@ -112,6 +106,7 @@ class ReadView(context: Context, attrs: AttributeSet) : upBg() setWillNotDraw(false) upPageAnim() + upPageSlopSquare() } } @@ -511,6 +506,11 @@ class ReadView(context: Context, attrs: AttributeSet) : callBack.screenOffTimerStart() } + fun upPageSlopSquare() { + val pageTouchSlop = AppConfig.pageTouchSlop + this.pageSlopSquare = if (pageTouchSlop == 0) slopSquare else pageTouchSlop + } + /** * 更新样式 */ 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 e2b311262..b2492bb41 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,7 +6,6 @@ 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 @@ -28,7 +27,9 @@ import io.legado.app.ui.widget.number.NumberPickerDialog import io.legado.app.utils.* import splitties.init.appCtx - +/** + * 其它设置 + */ class OtherConfigFragment : PreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener { @@ -43,7 +44,6 @@ 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()) @@ -60,7 +60,6 @@ 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?) { @@ -120,16 +119,7 @@ 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) } @@ -181,7 +171,6 @@ 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/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml index 47d6e7d28..6a6b44c68 100644 --- a/app/src/main/res/xml/pref_config_other.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -134,12 +134,6 @@ android:title="@string/threads_num_title" app:iconSpaceReserved="false" /> - - + +