From 7660751f7f85112d6c03872b5a3dc13148f425e0 Mon Sep 17 00:00:00 2001 From: Andreas Date: Sat, 31 Jul 2021 18:04:13 +0200 Subject: [PATCH] Don't hide menu when scrolling through with ReaderSeekBar (#5611) --- .../tachiyomi/ui/reader/ReaderActivity.kt | 13 ++++++++++ .../ui/reader/viewer/pager/PagerPageHolder.kt | 25 +++++++++++-------- .../ui/reader/viewer/pager/PagerViewer.kt | 5 +++- .../ui/reader/viewer/webtoon/WebtoonViewer.kt | 21 ++++++++-------- 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 3d1456080..0949d8b93 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -137,6 +137,9 @@ class ReaderActivity : BaseRxActivity() 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() // 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) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt index 2b5d9952a..5e0b7484d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt +++ b/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) + } } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt index a956b61b5..c34d0a2df 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt +++ b/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) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt index 700d5a731..ba8236df0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt +++ b/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)