mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 11:17:25 +01:00
Show page number only when toolbar is hidden (#2601)
* Show pagenumber only when toolbar is hidden * Fix fullscreen issue * Remove unneeded dependency * Fix menubar padding * Revert ReaderSeekBar height * Refine code Co-authored-by: arkon <arkon@users.noreply.github.com>
This commit is contained in:
parent
2854fb5f6c
commit
5fb3b0e0e3
@ -212,7 +212,6 @@ dependencies {
|
|||||||
implementation 'com.nononsenseapps:filepicker:2.5.2'
|
implementation 'com.nononsenseapps:filepicker:2.5.2'
|
||||||
implementation 'com.github.amulyakhare:TextDrawable:558677e'
|
implementation 'com.github.amulyakhare:TextDrawable:558677e'
|
||||||
implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
|
implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
|
||||||
implementation 'me.zhanghai.android.systemuihelper:library:1.0.0'
|
|
||||||
implementation 'com.nightlynexus.viewstatepageradapter:viewstatepageradapter:1.1.0'
|
implementation 'com.nightlynexus.viewstatepageradapter:viewstatepageradapter:1.1.0'
|
||||||
implementation 'com.github.mthli:Slice:v1.2'
|
implementation 'com.github.mthli:Slice:v1.2'
|
||||||
implementation 'me.gujun.android.taggroup:library:1.4@aar'
|
implementation 'me.gujun.android.taggroup:library:1.4@aar'
|
||||||
|
@ -20,6 +20,7 @@ import android.view.WindowManager
|
|||||||
import android.view.animation.Animation
|
import android.view.animation.Animation
|
||||||
import android.view.animation.AnimationUtils
|
import android.view.animation.AnimationUtils
|
||||||
import android.widget.SeekBar
|
import android.widget.SeekBar
|
||||||
|
import androidx.core.view.ViewCompat
|
||||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||||
@ -44,8 +45,7 @@ import eu.kanade.tachiyomi.util.lang.plusAssign
|
|||||||
import eu.kanade.tachiyomi.util.storage.getUriCompat
|
import eu.kanade.tachiyomi.util.storage.getUriCompat
|
||||||
import eu.kanade.tachiyomi.util.system.GLUtil
|
import eu.kanade.tachiyomi.util.system.GLUtil
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import eu.kanade.tachiyomi.util.view.gone
|
import eu.kanade.tachiyomi.util.view.*
|
||||||
import eu.kanade.tachiyomi.util.view.visible
|
|
||||||
import eu.kanade.tachiyomi.widget.SimpleAnimationListener
|
import eu.kanade.tachiyomi.widget.SimpleAnimationListener
|
||||||
import eu.kanade.tachiyomi.widget.SimpleSeekBarListener
|
import eu.kanade.tachiyomi.widget.SimpleSeekBarListener
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -102,11 +102,6 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
|||||||
var menuVisible = false
|
var menuVisible = false
|
||||||
private set
|
private set
|
||||||
|
|
||||||
/**
|
|
||||||
* System UI helper to hide status & navigation bar on all different API levels.
|
|
||||||
*/
|
|
||||||
private var systemUi: SystemUiHelper? = null
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration at reader level, like background color or forced orientation.
|
* Configuration at reader level, like background color or forced orientation.
|
||||||
*/
|
*/
|
||||||
@ -261,6 +256,17 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
|||||||
onBackPressed()
|
onBackPressed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ViewCompat.setOnApplyWindowInsetsListener(reader_menu) { _, insets ->
|
||||||
|
if (!window.isDefaultBar()) {
|
||||||
|
reader_menu.setPadding(
|
||||||
|
insets.systemWindowInsetLeft,
|
||||||
|
insets.systemWindowInsetTop,
|
||||||
|
insets.systemWindowInsetRight,
|
||||||
|
insets.systemWindowInsetBottom)
|
||||||
|
}
|
||||||
|
insets
|
||||||
|
}
|
||||||
|
|
||||||
// Init listeners on bottom menu
|
// Init listeners on bottom menu
|
||||||
page_seekbar.setOnSeekBarChangeListener(object : SimpleSeekBarListener() {
|
page_seekbar.setOnSeekBarChangeListener(object : SimpleSeekBarListener() {
|
||||||
override fun onProgressChanged(seekBar: SeekBar, value: Int, fromUser: Boolean) {
|
override fun onProgressChanged(seekBar: SeekBar, value: Int, fromUser: Boolean) {
|
||||||
@ -297,7 +303,11 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
|||||||
private fun setMenuVisibility(visible: Boolean, animate: Boolean = true) {
|
private fun setMenuVisibility(visible: Boolean, animate: Boolean = true) {
|
||||||
menuVisible = visible
|
menuVisible = visible
|
||||||
if (visible) {
|
if (visible) {
|
||||||
systemUi?.show()
|
if (preferences.fullscreen().getOrDefault()) {
|
||||||
|
window.showBar()
|
||||||
|
} else {
|
||||||
|
resetDefaultMenuAndBar()
|
||||||
|
}
|
||||||
reader_menu.visibility = View.VISIBLE
|
reader_menu.visibility = View.VISIBLE
|
||||||
|
|
||||||
if (animate) {
|
if (animate) {
|
||||||
@ -313,8 +323,16 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
|||||||
val bottomAnimation = AnimationUtils.loadAnimation(this, R.anim.enter_from_bottom)
|
val bottomAnimation = AnimationUtils.loadAnimation(this, R.anim.enter_from_bottom)
|
||||||
reader_menu_bottom.startAnimation(bottomAnimation)
|
reader_menu_bottom.startAnimation(bottomAnimation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (preferences.showPageNumber().getOrDefault()) {
|
||||||
|
config?.setPageNumberVisibility(false)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
systemUi?.hide()
|
if (preferences.fullscreen().getOrDefault()) {
|
||||||
|
window.hideBar()
|
||||||
|
} else {
|
||||||
|
resetDefaultMenuAndBar()
|
||||||
|
}
|
||||||
|
|
||||||
if (animate) {
|
if (animate) {
|
||||||
val toolbarAnimation = AnimationUtils.loadAnimation(this, R.anim.exit_to_top)
|
val toolbarAnimation = AnimationUtils.loadAnimation(this, R.anim.exit_to_top)
|
||||||
@ -328,9 +346,22 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
|||||||
val bottomAnimation = AnimationUtils.loadAnimation(this, R.anim.exit_to_bottom)
|
val bottomAnimation = AnimationUtils.loadAnimation(this, R.anim.exit_to_bottom)
|
||||||
reader_menu_bottom.startAnimation(bottomAnimation)
|
reader_menu_bottom.startAnimation(bottomAnimation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (preferences.showPageNumber().getOrDefault()) {
|
||||||
|
config?.setPageNumberVisibility(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset menu padding and system bar
|
||||||
|
*/
|
||||||
|
private fun resetDefaultMenuAndBar() {
|
||||||
|
reader_menu.setPadding(0, 0, 0, 0)
|
||||||
|
window.defaultBar()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called from the presenter when a manga is ready. Used to instantiate the appropriate viewer
|
* Called from the presenter when a manga is ready. Used to instantiate the appropriate viewer
|
||||||
* and the toolbar title.
|
* and the toolbar title.
|
||||||
@ -589,9 +620,6 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
|||||||
subscriptions += preferences.trueColor().asObservable()
|
subscriptions += preferences.trueColor().asObservable()
|
||||||
.subscribe { setTrueColor(it) }
|
.subscribe { setTrueColor(it) }
|
||||||
|
|
||||||
subscriptions += preferences.fullscreen().asObservable()
|
|
||||||
.subscribe { setFullscreen(it) }
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
subscriptions += preferences.cutoutShort().asObservable()
|
subscriptions += preferences.cutoutShort().asObservable()
|
||||||
.subscribe { setCutoutShort(it) }
|
.subscribe { setCutoutShort(it) }
|
||||||
@ -649,7 +677,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
|||||||
/**
|
/**
|
||||||
* Sets the visibility of the bottom page indicator according to [visible].
|
* Sets the visibility of the bottom page indicator according to [visible].
|
||||||
*/
|
*/
|
||||||
private fun setPageNumberVisibility(visible: Boolean) {
|
fun setPageNumberVisibility(visible: Boolean) {
|
||||||
page_number.visibility = if (visible) View.VISIBLE else View.INVISIBLE
|
page_number.visibility = if (visible) View.VISIBLE else View.INVISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -663,21 +691,6 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
|||||||
SubsamplingScaleImageView.setPreferredBitmapConfig(Bitmap.Config.RGB_565)
|
SubsamplingScaleImageView.setPreferredBitmapConfig(Bitmap.Config.RGB_565)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the fullscreen reading mode (immersive) according to [enabled].
|
|
||||||
*/
|
|
||||||
private fun setFullscreen(enabled: Boolean) {
|
|
||||||
systemUi = if (enabled) {
|
|
||||||
val level = SystemUiHelper.LEVEL_IMMERSIVE
|
|
||||||
val flags = SystemUiHelper.FLAG_IMMERSIVE_STICKY or
|
|
||||||
SystemUiHelper.FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES
|
|
||||||
|
|
||||||
SystemUiHelper(this@ReaderActivity, level, flags)
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.P)
|
@TargetApi(Build.VERSION_CODES.P)
|
||||||
private fun setCutoutShort(enabled: Boolean) {
|
private fun setCutoutShort(enabled: Boolean) {
|
||||||
window.attributes.layoutInDisplayCutoutMode = when (enabled) {
|
window.attributes.layoutInDisplayCutoutMode = when (enabled) {
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
package eu.kanade.tachiyomi.util.view
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import android.view.Window
|
||||||
|
|
||||||
|
fun Window.showBar() {
|
||||||
|
val uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
|
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
|
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||||
|
decorView.systemUiVisibility = uiFlags
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Window.hideBar() {
|
||||||
|
val uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
|
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
|
||||||
|
View.SYSTEM_UI_FLAG_FULLSCREEN or
|
||||||
|
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
|
||||||
|
View.SYSTEM_UI_FLAG_IMMERSIVE
|
||||||
|
decorView.systemUiVisibility = uiFlags
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Window.defaultBar() {
|
||||||
|
decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Window.isDefaultBar() = decorView.systemUiVisibility == View.SYSTEM_UI_FLAG_VISIBLE
|
@ -44,7 +44,6 @@
|
|||||||
android:id="@+id/reader_menu"
|
android:id="@+id/reader_menu"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:fitsSystemWindows="true"
|
|
||||||
android:theme="?attr/actionBarTheme"
|
android:theme="?attr/actionBarTheme"
|
||||||
android:visibility="invisible"
|
android:visibility="invisible"
|
||||||
tools:visibility="visible">
|
tools:visibility="visible">
|
||||||
|
Loading…
Reference in New Issue
Block a user