浏览代码

Don't hide menu when scrolling through with ReaderSeekBar (#5611)

Andreas 3 年之前
父节点
当前提交
7660751f7f

+ 13 - 0
app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt

@@ -137,6 +137,9 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
 
     private val windowInsetsController by lazy { WindowInsetsControllerCompat(window, binding.root) }
 
+    var isScrollingThroughPages = false
+        private set
+
     /**
      * Called when the activity is created. Initializes the presenter and configuration.
      */
@@ -329,6 +332,16 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
         // Init listeners on bottom menu
         binding.pageSeekbar.setOnSeekBarChangeListener(
             object : SimpleSeekBarListener() {
+                override fun onStartTrackingTouch(seekBar: SeekBar) {
+                    super.onStartTrackingTouch(seekBar)
+                    isScrollingThroughPages = true
+                }
+
+                override fun onStopTrackingTouch(seekBar: SeekBar) {
+                    super.onStopTrackingTouch(seekBar)
+                    isScrollingThroughPages = false
+                }
+
                 override fun onProgressChanged(seekBar: SeekBar, value: Int, fromUser: Boolean) {
                     if (viewer != null && fromUser) {
                         moveToPageIndex(value)

+ 14 - 11
app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt

@@ -100,28 +100,31 @@ class PagerPageHolder(
      */
     private var readImageHeaderSubscription: Subscription? = null
 
+    val stateChangedListener = object : SubsamplingScaleImageView.OnStateChangedListener {
+        override fun onScaleChanged(newScale: Float, origin: Int) {
+            viewer.activity.hideMenu()
+        }
+
+        override fun onCenterChanged(newCenter: PointF?, origin: Int) {
+            viewer.activity.hideMenu()
+        }
+    }
     private var visibilityListener = ActionBar.OnMenuVisibilityListener { isVisible ->
         if (isVisible.not()) {
             subsamplingImageView?.setOnStateChangedListener(null)
             return@OnMenuVisibilityListener
         }
-        subsamplingImageView?.setOnStateChangedListener(
-            object : SubsamplingScaleImageView.OnStateChangedListener {
-                override fun onScaleChanged(newScale: Float, origin: Int) {
-                    viewer.activity.hideMenu()
-                }
-
-                override fun onCenterChanged(newCenter: PointF?, origin: Int) {
-                    viewer.activity.hideMenu()
-                }
-            }
-        )
+        subsamplingImageView?.setOnStateChangedListener(stateChangedListener)
     }
 
     init {
         addView(progressIndicator)
         observeStatus()
         viewer.activity.addOnMenuVisibilityListener(visibilityListener)
+        if (viewer.activity.menuVisible) {
+            // Listener will not be available if user changed page with seek bar
+            subsamplingImageView?.setOnStateChangedListener(stateChangedListener)
+        }
     }
 
     /**

+ 4 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt

@@ -81,6 +81,9 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
         pager.addOnPageChangeListener(
             object : ViewPager.SimpleOnPageChangeListener() {
                 override fun onPageSelected(position: Int) {
+                    if (activity.isScrollingThroughPages.not()) {
+                        activity.hideMenu()
+                    }
                     onPageChange(position)
                 }
 
@@ -97,6 +100,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
 
             val pos = PointF(event.rawX / pager.width, event.rawY / pager.height)
             val navigator = config.navigator
+
             when (navigator.getAction(pos)) {
                 NavigationRegion.MENU -> activity.toggleMenu()
                 NavigationRegion.NEXT -> moveToNext()
@@ -153,7 +157,6 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
      * Called when a new page (either a [ReaderPage] or [ChapterTransition]) is marked as active
      */
     private fun onPageChange(position: Int) {
-        activity.hideMenu()
         val page = adapter.items.getOrNull(position)
         if (page != null && currentPage != page) {
             val allowPreload = checkAllowPreload(page as? ReaderPage)

+ 11 - 10
app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt

@@ -81,6 +81,10 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
                 override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
                     onScrolled()
 
+                    if ((dy > 37 || dy < -37) && activity.menuVisible) {
+                        activity.hideMenu()
+                    }
+
                     if (dy < 0) {
                         val firstIndex = layoutManager.findFirstVisibleItemPosition()
                         val firstItem = adapter.items.getOrNull(firstIndex)
@@ -98,14 +102,12 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
             }
 
             val pos = PointF(event.rawX / recycler.width, event.rawY / recycler.height)
-            if (!config.tappingEnabled) activity.toggleMenu()
-            else {
-                val navigator = config.navigator
-                when (navigator.getAction(pos)) {
-                    NavigationRegion.MENU -> activity.toggleMenu()
-                    NavigationRegion.NEXT, NavigationRegion.RIGHT -> scrollDown()
-                    NavigationRegion.PREV, NavigationRegion.LEFT -> scrollUp()
-                }
+            val navigator = config.navigator
+
+            when (navigator.getAction(pos)) {
+                NavigationRegion.MENU -> activity.toggleMenu()
+                NavigationRegion.NEXT, NavigationRegion.RIGHT -> scrollDown()
+                NavigationRegion.PREV, NavigationRegion.LEFT -> scrollUp()
             }
         }
         recycler.longTapListener = f@{ event ->
@@ -235,7 +237,7 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
         if (position != -1) {
             recycler.scrollToPosition(position)
             if (layoutManager.findLastEndVisibleItemPosition() == -1) {
-                onScrolled(position)
+                onScrolled(pos = position)
             }
         } else {
             Timber.d("Page $page not found in adapter")
@@ -243,7 +245,6 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
     }
 
     fun onScrolled(pos: Int? = null) {
-        activity.hideMenu()
         val position = pos ?: layoutManager.findLastEndVisibleItemPosition()
         val item = adapter.items.getOrNull(position)
         val allowPreload = checkAllowPreload(item as? ReaderPage)