From caeab0a63b41cad0fe500be5bb022569095aaf1e Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 27 Sep 2020 13:42:49 -0400 Subject: [PATCH] Clean up bottom nav bar scrolling behavior toggling --- .../kanade/tachiyomi/ui/main/MainActivity.kt | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 40aefce3ef..43517b2214 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -9,6 +9,7 @@ import android.view.ViewGroup import android.widget.Toast import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.core.view.isVisible +import androidx.core.view.updateLayoutParams import androidx.preference.PreferenceDialogController import com.bluelinelabs.conductor.Conductor 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.util.lang.launchIO 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.tabs import kotlinx.coroutines.delay @@ -90,7 +90,10 @@ class MainActivity : BaseActivity() { bottomNavAnimator = ViewHeightAnimator(binding.bottomNav) // Set behavior of bottom nav - setBottomBarBehaviorOnScroll() + preferences.hideBottomBar() + .asImmediateFlow { setBottomNavBehaviorOnScroll() } + .launchIn(scope) + binding.bottomNav.setOnNavigationItemSelectedListener { item -> val id = item.itemId @@ -308,12 +311,6 @@ class MainActivity : BaseActivity() { !isConfirmingExit } - private fun setBottomBarBehaviorOnScroll() { - val layoutParams = binding.bottomNav.layoutParams as CoordinatorLayout.LayoutParams - layoutParams.behavior = - if (preferences.hideBottomBar().get()) HideBottomViewOnScrollBehavior() else null - } - fun setSelectedNavItem(itemId: Int) { if (!isFinishing) { binding.bottomNav.selectedItemId = itemId @@ -343,7 +340,6 @@ class MainActivity : BaseActivity() { if (to is RootController) { // Always show bottom nav again when returning to a RootController showBottomNav(visible = true, collapse = from !is RootController) - setBottomBarBehaviorOnScroll() } if (from is TabbedController) { @@ -397,6 +393,17 @@ class MainActivity : BaseActivity() { } } + private fun setBottomNavBehaviorOnScroll() { + showBottomNav(visible = true) + + binding.bottomNav.updateLayoutParams { + behavior = when { + preferences.hideBottomBar().get() -> HideBottomViewOnScrollBehavior() + else -> null + } + } + } + companion object { // Shortcut actions const val SHORTCUT_LIBRARY = "eu.kanade.tachiyomi.SHOW_LIBRARY"