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:
parent
25629b5a4c
commit
1480829dd1
@ -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
|
||||
@ -265,6 +266,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
||||
readingModeToast?.cancel()
|
||||
progressDialog?.dismiss()
|
||||
progressDialog = null
|
||||
listeners = mutableListOf()
|
||||
// SY -->
|
||||
autoScrollJob?.cancel()
|
||||
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
|
||||
* [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
|
||||
@ -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
|
||||
* will call [onShareImageResult] with the path the image was saved on when it's ready.
|
||||
|
@ -1,6 +1,7 @@
|
||||
package eu.kanade.tachiyomi.ui.reader.viewer.pager
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.ActionBar
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.PointF
|
||||
import android.graphics.drawable.Animatable
|
||||
@ -117,6 +118,24 @@ 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()
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// SY -->
|
||||
var status: Int = 0
|
||||
var extraStatus: Int = 0
|
||||
@ -130,6 +149,7 @@ class PagerPageHolder(
|
||||
addView(progressIndicator)
|
||||
scope = CoroutineScope(Job() + Dispatchers.Default)
|
||||
observeStatus()
|
||||
viewer.activity.addOnMenuVisibilityListener(visibilityListener)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -144,6 +164,8 @@ class PagerPageHolder(
|
||||
unsubscribeStatus(2)
|
||||
unsubscribeReadImageHeader()
|
||||
subsamplingImageView?.setOnImageEventListener(null)
|
||||
subsamplingImageView?.setOnStateChangedListener(null)
|
||||
viewer.activity.removeOnMenuVisibilityListener(visibilityListener)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
*/
|
||||
private fun onPageChange(position: Int) {
|
||||
activity.hideMenu()
|
||||
val page = adapter.joinedItems.getOrNull(position)
|
||||
if (page != null && currentPage != page) {
|
||||
val allowPreload = checkAllowPreload(page.first as? ReaderPage)
|
||||
|
@ -249,6 +249,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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user