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 57fb6ce96..c0a884318 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 @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.reader import android.annotation.SuppressLint import android.annotation.TargetApi +import android.app.ActionBar import android.app.ProgressDialog import android.content.ClipData import android.content.Context @@ -189,6 +190,7 @@ class ReaderActivity : BaseRxActivity() readingModeToast?.cancel() progressDialog?.dismiss() progressDialog = null + listeners = mutableListOf() } /** @@ -486,12 +488,23 @@ class ReaderActivity : BaseRxActivity() ) } + private var listeners: MutableList = mutableListOf() + + fun addOnMenuVisibilityListener(listener: ActionBar.OnMenuVisibilityListener) { + listeners.add(listener) + } + + fun removeOnMenuVisibilityListener(listener: ActionBar.OnMenuVisibilityListener) { + listeners.remove(listener) + } + /** * Sets the visibility of the menu according to [visible] and with an optional parameter to * [animate] the views. */ fun setMenuVisibility(visible: Boolean, animate: Boolean = true) { menuVisible = visible + listeners.forEach { listener -> listener.onMenuVisibilityChanged(visible) } if (visible) { windowInsetsController.show(WindowInsetsCompat.Type.systemBars()) binding.readerMenu.isVisible = true @@ -737,6 +750,15 @@ class ReaderActivity : BaseRxActivity() } } + /** + * Called from the viewer to hide the menu. + */ + fun hideMenu() { + if (menuVisible) { + setMenuVisibility(false) + } + } + /** * Called from the page sheet. It delegates the call to the presenter to do some IO, which * will call [onShareImageResult] with the path the image was saved on when it's ready. 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 455c4308f..814b16d33 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 @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.ui.reader.viewer.pager import android.annotation.SuppressLint +import android.app.ActionBar import android.graphics.PointF import android.graphics.drawable.Animatable import android.view.GestureDetector @@ -99,9 +100,28 @@ class PagerPageHolder( */ private var readImageHeaderSubscription: Subscription? = null + 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() + } + } + ) + } + init { addView(progressIndicator) observeStatus() + viewer.activity.addOnMenuVisibilityListener(visibilityListener) } /** @@ -114,6 +134,8 @@ class PagerPageHolder( unsubscribeStatus() unsubscribeReadImageHeader() subsamplingImageView?.setOnImageEventListener(null) + subsamplingImageView?.setOnStateChangedListener(null) + viewer.activity.removeOnMenuVisibilityListener(visibilityListener) } /** 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 fc37c3de0..a956b61b5 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 @@ -153,6 +153,7 @@ 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 eae4936ee..700d5a731 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 @@ -243,6 +243,7 @@ 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)