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:
parent
291f61551a
commit
f0040b8392
3 changed files with 29 additions and 13 deletions
|
@ -149,7 +149,7 @@ fun initActivity(a: Activity) {
|
||||||
if (navBarHeight == 0) {
|
if (navBarHeight == 0) {
|
||||||
ViewCompat.getRootWindowInsets(window.decorView.findViewById(android.R.id.content))
|
ViewCompat.getRootWindowInsets(window.decorView.findViewById(android.R.id.content))
|
||||||
?.apply {
|
?.apply {
|
||||||
navBarHeight = this.getInsets(WindowInsetsCompat.Type.systemBars()).bottom
|
navBarHeight = this.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WindowInsetsControllerCompat(window, window.decorView).hide(WindowInsetsCompat.Type.statusBars())
|
WindowInsetsControllerCompat(window, window.decorView).hide(WindowInsetsCompat.Type.statusBars())
|
||||||
|
@ -165,9 +165,8 @@ fun initActivity(a: Activity) {
|
||||||
val windowInsets =
|
val windowInsets =
|
||||||
ViewCompat.getRootWindowInsets(window.decorView.findViewById(android.R.id.content))
|
ViewCompat.getRootWindowInsets(window.decorView.findViewById(android.R.id.content))
|
||||||
if (windowInsets != null) {
|
if (windowInsets != null) {
|
||||||
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
|
statusBarHeight = windowInsets.getInsets(WindowInsetsCompat.Type.statusBars()).top
|
||||||
statusBarHeight = insets.top
|
navBarHeight = windowInsets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom
|
||||||
navBarHeight = insets.bottom
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (a !is MainActivity) a.setNavigationTheme()
|
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() {
|
fun Activity.setNavigationTheme() {
|
||||||
val tv = TypedValue()
|
val tv = TypedValue()
|
||||||
theme.resolveAttribute(android.R.attr.colorBackground, tv, true)
|
theme.resolveAttribute(android.R.attr.colorBackground, tv, true)
|
||||||
|
|
|
@ -358,9 +358,6 @@ class MainActivity : AppCompatActivity() {
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
initActivity(this)
|
initActivity(this)
|
||||||
binding.includedNavbar.navbarContainer.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
|
||||||
bottomMargin = navBarHeight
|
|
||||||
}
|
|
||||||
window.navigationBarColor = getColor(android.R.color.transparent)
|
window.navigationBarColor = getColor(android.R.color.transparent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -122,8 +122,11 @@ class MangaReaderActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun hideBars() {
|
private fun hideSystemBars() {
|
||||||
if (!PrefManager.getVal<Boolean>(PrefName.ShowSystemBars)) hideSystemBars()
|
if (PrefManager.getVal<Boolean>(PrefName.ShowSystemBars))
|
||||||
|
showSystemBarsRetractView()
|
||||||
|
else
|
||||||
|
hideSystemBarsExtendView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
@ -153,7 +156,7 @@ class MangaReaderActivity : AppCompatActivity() {
|
||||||
|
|
||||||
controllerDuration = (PrefManager.getVal<Float>(PrefName.AnimationSpeed) * 200).toLong()
|
controllerDuration = (PrefManager.getVal<Float>(PrefName.AnimationSpeed) * 200).toLong()
|
||||||
|
|
||||||
hideBars()
|
hideSystemBars()
|
||||||
|
|
||||||
var pageSliderTimer = Timer()
|
var pageSliderTimer = Timer()
|
||||||
fun pageSliderHide() {
|
fun pageSliderHide() {
|
||||||
|
@ -395,7 +398,7 @@ class MangaReaderActivity : AppCompatActivity() {
|
||||||
fun applySettings() {
|
fun applySettings() {
|
||||||
|
|
||||||
saveReaderSettings("${media.id}_current_settings", defaultSettings)
|
saveReaderSettings("${media.id}_current_settings", defaultSettings)
|
||||||
hideBars()
|
hideSystemBars()
|
||||||
|
|
||||||
//true colors
|
//true colors
|
||||||
SubsamplingScaleImageView.setPreferredBitmapConfig(
|
SubsamplingScaleImageView.setPreferredBitmapConfig(
|
||||||
|
@ -779,7 +782,7 @@ class MangaReaderActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PrefManager.getVal<Boolean>(PrefName.ShowSystemBars)) {
|
if (!PrefManager.getVal<Boolean>(PrefName.ShowSystemBars)) {
|
||||||
hideBars()
|
hideSystemBars()
|
||||||
checkNotch()
|
checkNotch()
|
||||||
}
|
}
|
||||||
// Hide the scrollbar completely
|
// Hide the scrollbar completely
|
||||||
|
@ -937,7 +940,7 @@ class MangaReaderActivity : AppCompatActivity() {
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
runnable.run()
|
runnable.run()
|
||||||
}
|
}
|
||||||
.setOnCancelListener { hideBars() }
|
.setOnCancelListener { hideSystemBars() }
|
||||||
.create()
|
.create()
|
||||||
.show()
|
.show()
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue