Swap bottom nav and ActionToolbar when appropriate

This commit is contained in:
arkon 2020-05-02 12:27:23 -04:00
parent b06189ff95
commit e2158af592
4 changed files with 34 additions and 9 deletions

View File

@ -32,6 +32,7 @@ import eu.kanade.tachiyomi.ui.base.controller.RootController
import eu.kanade.tachiyomi.ui.base.controller.TabbedController
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.ui.main.offsetFabAppbarHeight
import eu.kanade.tachiyomi.ui.manga.MangaController
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.toast
@ -177,6 +178,8 @@ class LibraryController(
if (preferences.downloadedOnly().get()) {
binding.downloadedOnly.visible()
}
binding.actionToolbar.offsetFabAppbarHeight(activity!!)
}
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
@ -316,6 +319,7 @@ class LibraryController(
actionMode!!,
R.menu.library_selection
) { onActionItemClicked(actionMode!!, it!!) }
(activity as? MainActivity)?.showBottomNav(visible = false, collapse = true)
}
}
@ -323,6 +327,7 @@ class LibraryController(
* Destroys the action mode.
*/
private fun destroyActionModeIfNeeded() {
(activity as? MainActivity)?.showBottomNav(visible = true, collapse = true)
actionMode?.finish()
}

View File

@ -328,17 +328,11 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
binding.appbar.setExpanded(true)
if ((from == null || from is RootController) && to !is RootController) {
bottomNavAnimator.collapse()
showBottomNav(visible = false, collapse = true)
}
if (to is RootController) {
if (from !is RootController) {
bottomNavAnimator.expand()
}
// Always show bottom nav again when returning to a RootController
val layoutParams = binding.bottomNav.layoutParams as CoordinatorLayout.LayoutParams
val bottomViewNavigationBehavior = layoutParams.behavior as HideBottomViewOnScrollBehavior
bottomViewNavigationBehavior.slideUp(binding.bottomNav)
showBottomNav(visible = true, collapse = from !is RootController)
}
if (from is TabbedController) {
@ -359,6 +353,24 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
}
}
fun showBottomNav(visible: Boolean, collapse: Boolean = false) {
val layoutParams = binding.bottomNav.layoutParams as CoordinatorLayout.LayoutParams
val bottomViewNavigationBehavior = layoutParams.behavior as HideBottomViewOnScrollBehavior
if (visible) {
if (collapse) {
bottomNavAnimator.expand()
}
bottomViewNavigationBehavior.slideUp(binding.bottomNav)
} else {
if (collapse) {
bottomNavAnimator.collapse()
}
bottomViewNavigationBehavior.slideDown(binding.bottomNav)
}
}
companion object {
// Shortcut actions
const val SHORTCUT_LIBRARY = "eu.kanade.tachiyomi.SHOW_LIBRARY"

View File

@ -121,8 +121,10 @@ class ChaptersController :
}
.launchIn(scope)
binding.fab.offsetFabAppbarHeight(activity!!)
binding.fab.shrinkOnScroll(binding.recycler)
binding.actionToolbar.offsetFabAppbarHeight(activity!!)
binding.fab.offsetFabAppbarHeight(activity!!)
}
override fun onDestroyView(view: View) {

View File

@ -22,6 +22,8 @@ import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
import eu.kanade.tachiyomi.ui.base.controller.RootController
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.ui.main.offsetFabAppbarHeight
import eu.kanade.tachiyomi.ui.manga.MangaController
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.util.system.notificationManager
@ -109,6 +111,8 @@ class UpdatesController :
binding.swipeRefresh.isRefreshing = false
}
.launchIn(scope)
binding.actionToolbar.offsetFabAppbarHeight(activity!!)
}
override fun onDestroyView(view: View) {
@ -176,6 +180,7 @@ class UpdatesController :
actionMode!!,
R.menu.updates_chapter_selection
) { onActionItemClicked(actionMode!!, it!!) }
(activity as? MainActivity)?.showBottomNav(visible = false, collapse = true)
}
toggleSelection(position)
@ -266,6 +271,7 @@ class UpdatesController :
}
private fun destroyActionModeIfNeeded() {
(activity as? MainActivity)?.showBottomNav(visible = true, collapse = true)
actionMode?.finish()
}