From e2158af5922190ebdf86bbc5c54493e70e2663d8 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 2 May 2020 12:27:23 -0400 Subject: [PATCH] Swap bottom nav and ActionToolbar when appropriate --- .../tachiyomi/ui/library/LibraryController.kt | 5 ++++ .../kanade/tachiyomi/ui/main/MainActivity.kt | 28 +++++++++++++------ .../ui/manga/chapter/ChaptersController.kt | 4 ++- .../ui/recent/updates/UpdatesController.kt | 6 ++++ 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index f9566edf22..78ab7e831c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -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() } 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 7448d02bad..21471938ea 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 @@ -328,17 +328,11 @@ class MainActivity : BaseActivity() { 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() { } } + 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" diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt index d95a10e3c9..924951176b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt @@ -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) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt index 232002178a..d945998aca 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt @@ -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() }