Clean up bottom nav bar scrolling behavior toggling

This commit is contained in:
arkon 2020-09-27 13:42:49 -04:00
parent 7c69b1b649
commit caeab0a63b

View file

@ -9,6 +9,7 @@ import android.view.ViewGroup
import android.widget.Toast import android.widget.Toast
import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.preference.PreferenceDialogController import androidx.preference.PreferenceDialogController
import com.bluelinelabs.conductor.Conductor import com.bluelinelabs.conductor.Conductor
import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.Controller
@ -43,7 +44,6 @@ import eu.kanade.tachiyomi.ui.recent.history.HistoryController
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController
import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.launchIO
import eu.kanade.tachiyomi.util.lang.launchUI import eu.kanade.tachiyomi.util.lang.launchUI
import eu.kanade.tachiyomi.util.system.toast
import kotlinx.android.synthetic.main.main_activity.appbar import kotlinx.android.synthetic.main.main_activity.appbar
import kotlinx.android.synthetic.main.main_activity.tabs import kotlinx.android.synthetic.main.main_activity.tabs
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
@ -90,7 +90,10 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
bottomNavAnimator = ViewHeightAnimator(binding.bottomNav) bottomNavAnimator = ViewHeightAnimator(binding.bottomNav)
// Set behavior of bottom nav // Set behavior of bottom nav
setBottomBarBehaviorOnScroll() preferences.hideBottomBar()
.asImmediateFlow { setBottomNavBehaviorOnScroll() }
.launchIn(scope)
binding.bottomNav.setOnNavigationItemSelectedListener { item -> binding.bottomNav.setOnNavigationItemSelectedListener { item ->
val id = item.itemId val id = item.itemId
@ -308,12 +311,6 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
!isConfirmingExit !isConfirmingExit
} }
private fun setBottomBarBehaviorOnScroll() {
val layoutParams = binding.bottomNav.layoutParams as CoordinatorLayout.LayoutParams
layoutParams.behavior =
if (preferences.hideBottomBar().get()) HideBottomViewOnScrollBehavior<View>() else null
}
fun setSelectedNavItem(itemId: Int) { fun setSelectedNavItem(itemId: Int) {
if (!isFinishing) { if (!isFinishing) {
binding.bottomNav.selectedItemId = itemId binding.bottomNav.selectedItemId = itemId
@ -343,7 +340,6 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
if (to is RootController) { if (to is RootController) {
// Always show bottom nav again when returning to a RootController // Always show bottom nav again when returning to a RootController
showBottomNav(visible = true, collapse = from !is RootController) showBottomNav(visible = true, collapse = from !is RootController)
setBottomBarBehaviorOnScroll()
} }
if (from is TabbedController) { if (from is TabbedController) {
@ -397,6 +393,17 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
} }
} }
private fun setBottomNavBehaviorOnScroll() {
showBottomNav(visible = true)
binding.bottomNav.updateLayoutParams<CoordinatorLayout.LayoutParams> {
behavior = when {
preferences.hideBottomBar().get() -> HideBottomViewOnScrollBehavior<View>()
else -> null
}
}
}
companion object { companion object {
// Shortcut actions // Shortcut actions
const val SHORTCUT_LIBRARY = "eu.kanade.tachiyomi.SHOW_LIBRARY" const val SHORTCUT_LIBRARY = "eu.kanade.tachiyomi.SHOW_LIBRARY"