Skip to content

Commit

Permalink
Clean up bottom nav bar scrolling behavior toggling
Browse files Browse the repository at this point in the history
  • Loading branch information
arkon committed Sep 27, 2020
1 parent 7c69b1b commit caeab0a
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -90,7 +90,10 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
bottomNavAnimator = ViewHeightAnimator(binding.bottomNav)

// Set behavior of bottom nav
setBottomBarBehaviorOnScroll()
preferences.hideBottomBar()
.asImmediateFlow { setBottomNavBehaviorOnScroll() }
.launchIn(scope)

binding.bottomNav.setOnNavigationItemSelectedListener { item ->
val id = item.itemId

Expand Down Expand Up @@ -308,12 +311,6 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
!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) {
if (!isFinishing) {
binding.bottomNav.selectedItemId = itemId
Expand Down Expand Up @@ -343,7 +340,6 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
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) {
Expand Down Expand Up @@ -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 {
// Shortcut actions
const val SHORTCUT_LIBRARY = "eu.kanade.tachiyomi.SHOW_LIBRARY"
Expand Down

0 comments on commit caeab0a

Please sign in to comment.