diff --git a/app/build.gradle b/app/build.gradle index fda95086b..16a60626c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -212,7 +212,6 @@ dependencies { implementation 'com.nononsenseapps:filepicker:2.5.2' implementation 'com.github.amulyakhare:TextDrawable:558677e' 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.github.mthli:Slice:v1.2' implementation 'me.gujun.android.taggroup:library:1.4@aar' 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 6f4434c71..5fa3870b2 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 @@ -20,6 +20,7 @@ import android.view.WindowManager import android.view.animation.Animation import android.view.animation.AnimationUtils import android.widget.SeekBar +import androidx.core.view.ViewCompat import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import eu.kanade.tachiyomi.R 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.system.GLUtil import eu.kanade.tachiyomi.util.system.toast -import eu.kanade.tachiyomi.util.view.gone -import eu.kanade.tachiyomi.util.view.visible +import eu.kanade.tachiyomi.util.view.* import eu.kanade.tachiyomi.widget.SimpleAnimationListener import eu.kanade.tachiyomi.widget.SimpleSeekBarListener import java.io.File @@ -102,11 +102,6 @@ class ReaderActivity : BaseRxActivity() { var menuVisible = false 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. */ @@ -261,6 +256,17 @@ class ReaderActivity : BaseRxActivity() { 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 page_seekbar.setOnSeekBarChangeListener(object : SimpleSeekBarListener() { override fun onProgressChanged(seekBar: SeekBar, value: Int, fromUser: Boolean) { @@ -297,7 +303,11 @@ class ReaderActivity : BaseRxActivity() { private fun setMenuVisibility(visible: Boolean, animate: Boolean = true) { menuVisible = visible if (visible) { - systemUi?.show() + if (preferences.fullscreen().getOrDefault()) { + window.showBar() + } else { + resetDefaultMenuAndBar() + } reader_menu.visibility = View.VISIBLE if (animate) { @@ -313,8 +323,16 @@ class ReaderActivity : BaseRxActivity() { val bottomAnimation = AnimationUtils.loadAnimation(this, R.anim.enter_from_bottom) reader_menu_bottom.startAnimation(bottomAnimation) } + + if (preferences.showPageNumber().getOrDefault()) { + config?.setPageNumberVisibility(false) + } } else { - systemUi?.hide() + if (preferences.fullscreen().getOrDefault()) { + window.hideBar() + } else { + resetDefaultMenuAndBar() + } if (animate) { val toolbarAnimation = AnimationUtils.loadAnimation(this, R.anim.exit_to_top) @@ -328,9 +346,22 @@ class ReaderActivity : BaseRxActivity() { val bottomAnimation = AnimationUtils.loadAnimation(this, R.anim.exit_to_bottom) 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 * and the toolbar title. @@ -589,9 +620,6 @@ class ReaderActivity : BaseRxActivity() { subscriptions += preferences.trueColor().asObservable() .subscribe { setTrueColor(it) } - subscriptions += preferences.fullscreen().asObservable() - .subscribe { setFullscreen(it) } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { subscriptions += preferences.cutoutShort().asObservable() .subscribe { setCutoutShort(it) } @@ -649,7 +677,7 @@ class ReaderActivity : BaseRxActivity() { /** * 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 } @@ -663,21 +691,6 @@ class ReaderActivity : BaseRxActivity() { 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) private fun setCutoutShort(enabled: Boolean) { window.attributes.layoutInDisplayCutoutMode = when (enabled) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/WindowExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/WindowExtensions.kt new file mode 100644 index 000000000..45050d024 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/WindowExtensions.kt @@ -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 \ No newline at end of file diff --git a/app/src/main/res/layout/reader_activity.xml b/app/src/main/res/layout/reader_activity.xml index 2e0fe871a..e09617551 100644 --- a/app/src/main/res/layout/reader_activity.xml +++ b/app/src/main/res/layout/reader_activity.xml @@ -44,7 +44,6 @@ android:id="@+id/reader_menu" android:layout_width="match_parent" android:layout_height="match_parent" - android:fitsSystemWindows="true" android:theme="?attr/actionBarTheme" android:visibility="invisible" tools:visibility="visible">