Skip to content

Commit

Permalink
feat: add an option to revert bar hide (#242)
Browse files Browse the repository at this point in the history
* feat: add an option to revert bar hide

* fix: clarify the bars being hidden
  • Loading branch information
TwistedUmbrellaX authored Mar 13, 2024
1 parent 291f615 commit f0040b8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
24 changes: 20 additions & 4 deletions app/src/main/java/ani/dantotsu/Functions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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()
Expand All @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/java/ani/dantotsu/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -153,7 +156,7 @@ class MangaReaderActivity : AppCompatActivity() {

controllerDuration = (PrefManager.getVal<Float>(PrefName.AnimationSpeed) * 200).toLong()

hideBars()
hideSystemBars()

var pageSliderTimer = Timer()
fun pageSliderHide() {
Expand Down Expand Up @@ -395,7 +398,7 @@ class MangaReaderActivity : AppCompatActivity() {
fun applySettings() {

saveReaderSettings("${media.id}_current_settings", defaultSettings)
hideBars()
hideSystemBars()

//true colors
SubsamplingScaleImageView.setPreferredBitmapConfig(
Expand Down Expand Up @@ -779,7 +782,7 @@ class MangaReaderActivity : AppCompatActivity() {
}

if (!PrefManager.getVal<Boolean>(PrefName.ShowSystemBars)) {
hideBars()
hideSystemBars()
checkNotch()
}
// Hide the scrollbar completely
Expand Down Expand Up @@ -937,7 +940,7 @@ class MangaReaderActivity : AppCompatActivity() {
dialog.dismiss()
runnable.run()
}
.setOnCancelListener { hideBars() }
.setOnCancelListener { hideSystemBars() }
.create()
.show()
} else {
Expand Down

0 comments on commit f0040b8

Please sign in to comment.