Auto hide reader menu when user starts reading again (#5578)

* Hide reader menu when user starts reading again

* Hide menu on zoom and scrolling around during zoom

Didn't work for webtoon

* Only listen when menu is visible

(cherry picked from commit 356cd4ef522bec405253954ec4b2dea90a4e69c7)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt
This commit is contained in:
Andreas 2021-07-21 23:58:32 +02:00 committed by Jobobby04
parent 25629b5a4c
commit 1480829dd1
4 changed files with 46 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.reader
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.annotation.TargetApi import android.annotation.TargetApi
import android.app.ActionBar
import android.app.ProgressDialog import android.app.ProgressDialog
import android.content.ClipData import android.content.ClipData
import android.content.Context import android.content.Context
@ -265,6 +266,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
readingModeToast?.cancel() readingModeToast?.cancel()
progressDialog?.dismiss() progressDialog?.dismiss()
progressDialog = null progressDialog = null
listeners = mutableListOf()
// SY --> // SY -->
autoScrollJob?.cancel() autoScrollJob?.cancel()
autoScrollJob = null autoScrollJob = null
@ -901,12 +903,23 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
) )
} }
private var listeners: MutableList<ActionBar.OnMenuVisibilityListener> = 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 * Sets the visibility of the menu according to [visible] and with an optional parameter to
* [animate] the views. * [animate] the views.
*/ */
fun setMenuVisibility(visible: Boolean, animate: Boolean = true) { fun setMenuVisibility(visible: Boolean, animate: Boolean = true) {
menuVisible = visible menuVisible = visible
listeners.forEach { listener -> listener.onMenuVisibilityChanged(visible) }
if (visible) { if (visible) {
windowInsetsController.show(WindowInsetsCompat.Type.systemBars()) windowInsetsController.show(WindowInsetsCompat.Type.systemBars())
binding.readerMenu.isVisible = true binding.readerMenu.isVisible = true
@ -1298,6 +1311,15 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
} }
} }
/**
* 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 * 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. * will call [onShareImageResult] with the path the image was saved on when it's ready.

View File

@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.ui.reader.viewer.pager package eu.kanade.tachiyomi.ui.reader.viewer.pager
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.ActionBar
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
import android.graphics.PointF import android.graphics.PointF
import android.graphics.drawable.Animatable import android.graphics.drawable.Animatable
@ -117,6 +118,24 @@ class PagerPageHolder(
*/ */
private var readImageHeaderSubscription: Subscription? = null 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()
}
}
)
}
// SY --> // SY -->
var status: Int = 0 var status: Int = 0
var extraStatus: Int = 0 var extraStatus: Int = 0
@ -130,6 +149,7 @@ class PagerPageHolder(
addView(progressIndicator) addView(progressIndicator)
scope = CoroutineScope(Job() + Dispatchers.Default) scope = CoroutineScope(Job() + Dispatchers.Default)
observeStatus() observeStatus()
viewer.activity.addOnMenuVisibilityListener(visibilityListener)
} }
/** /**
@ -144,6 +164,8 @@ class PagerPageHolder(
unsubscribeStatus(2) unsubscribeStatus(2)
unsubscribeReadImageHeader() unsubscribeReadImageHeader()
subsamplingImageView?.setOnImageEventListener(null) subsamplingImageView?.setOnImageEventListener(null)
subsamplingImageView?.setOnStateChangedListener(null)
viewer.activity.removeOnMenuVisibilityListener(visibilityListener)
} }
/** /**

View File

@ -163,6 +163,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
* Called when a new page (either a [ReaderPage] or [ChapterTransition]) is marked as active * Called when a new page (either a [ReaderPage] or [ChapterTransition]) is marked as active
*/ */
private fun onPageChange(position: Int) { private fun onPageChange(position: Int) {
activity.hideMenu()
val page = adapter.joinedItems.getOrNull(position) val page = adapter.joinedItems.getOrNull(position)
if (page != null && currentPage != page) { if (page != null && currentPage != page) {
val allowPreload = checkAllowPreload(page.first as? ReaderPage) val allowPreload = checkAllowPreload(page.first as? ReaderPage)

View File

@ -249,6 +249,7 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
} }
fun onScrolled(pos: Int? = null) { fun onScrolled(pos: Int? = null) {
activity.hideMenu()
val position = pos ?: layoutManager.findLastEndVisibleItemPosition() val position = pos ?: layoutManager.findLastEndVisibleItemPosition()
val item = adapter.items.getOrNull(position) val item = adapter.items.getOrNull(position)
val allowPreload = checkAllowPreload(item as? ReaderPage) val allowPreload = checkAllowPreload(item as? ReaderPage)