feat: add an option to revert bar hide (#242)

* feat: add an option to revert bar hide

* fix: clarify the bars being hidden
This commit is contained in:
TwistedUmbrellaX 2024-03-13 09:15:13 -04:00 committed by GitHub
parent 291f61551a
commit f0040b8392
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 13 deletions

View file

@ -149,7 +149,7 @@ fun initActivity(a: Activity) {
if (navBarHeight == 0) {
ViewCompat.getRootWindowInsets(window.decorView.findViewById(android.R.id.content))
?.apply {
navBarHeight = this.getInsets(WindowInsetsCompat.Type.systemBars()).bottom
navBarHeight = this.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom
}
}
WindowInsetsControllerCompat(window, window.decorView).hide(WindowInsetsCompat.Type.statusBars())
@ -165,9 +165,8 @@ fun initActivity(a: Activity) {
val windowInsets =
ViewCompat.getRootWindowInsets(window.decorView.findViewById(android.R.id.content))
if (windowInsets != null) {
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
statusBarHeight = insets.top
navBarHeight = insets.bottom
statusBarHeight = windowInsets.getInsets(WindowInsetsCompat.Type.statusBars()).top
navBarHeight = windowInsets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom
}
}
if (a !is MainActivity) a.setNavigationTheme()
@ -181,6 +180,23 @@ fun Activity.hideSystemBars() {
}
}
fun Activity.hideSystemBarsExtendView() {
WindowCompat.setDecorFitsSystemWindows(window, false)
hideSystemBars()
}
fun Activity.showSystemBars() {
WindowInsetsControllerCompat(window, window.decorView).let { controller ->
controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_DEFAULT
controller.show(WindowInsetsCompat.Type.systemBars())
}
}
fun Activity.showSystemBarsRetractView() {
WindowCompat.setDecorFitsSystemWindows(window, true)
showSystemBars()
}
fun Activity.setNavigationTheme() {
val tv = TypedValue()
theme.resolveAttribute(android.R.attr.colorBackground, tv, true)

View file

@ -358,9 +358,6 @@ class MainActivity : AppCompatActivity() {
override fun onResume() {
super.onResume()
initActivity(this)
binding.includedNavbar.navbarContainer.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = navBarHeight
}
window.navigationBarColor = getColor(android.R.color.transparent)
}

View file

@ -122,8 +122,11 @@ class MangaReaderActivity : AppCompatActivity() {
}
}
private fun hideBars() {
if (!PrefManager.getVal<Boolean>(PrefName.ShowSystemBars)) hideSystemBars()
private fun hideSystemBars() {
if (PrefManager.getVal<Boolean>(PrefName.ShowSystemBars))
showSystemBarsRetractView()
else
hideSystemBarsExtendView()
}
override fun onDestroy() {
@ -153,7 +156,7 @@ class MangaReaderActivity : AppCompatActivity() {
controllerDuration = (PrefManager.getVal<Float>(PrefName.AnimationSpeed) * 200).toLong()
hideBars()
hideSystemBars()
var pageSliderTimer = Timer()
fun pageSliderHide() {
@ -395,7 +398,7 @@ class MangaReaderActivity : AppCompatActivity() {
fun applySettings() {
saveReaderSettings("${media.id}_current_settings", defaultSettings)
hideBars()
hideSystemBars()
//true colors
SubsamplingScaleImageView.setPreferredBitmapConfig(
@ -779,7 +782,7 @@ class MangaReaderActivity : AppCompatActivity() {
}
if (!PrefManager.getVal<Boolean>(PrefName.ShowSystemBars)) {
hideBars()
hideSystemBars()
checkNotch()
}
// Hide the scrollbar completely
@ -937,7 +940,7 @@ class MangaReaderActivity : AppCompatActivity() {
dialog.dismiss()
runnable.run()
}
.setOnCancelListener { hideBars() }
.setOnCancelListener { hideSystemBars() }
.create()
.show()
} else {