From 164da0fd9f0203e811e7528c21adf38d63322836 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 6 Mar 2020 21:53:25 -0500 Subject: [PATCH] Hide bottom nav on non-root controllers --- .../ui/base/controller/RootController.kt | 3 ++ .../ui/catalogue/CatalogueController.kt | 2 + .../tachiyomi/ui/library/LibraryController.kt | 2 + .../kanade/tachiyomi/ui/main/MainActivity.kt | 14 ++++++- ...{TabsAnimator.kt => ViewHeightAnimator.kt} | 38 ++++++++++--------- .../tachiyomi/ui/more/MoreController.kt | 3 +- .../RecentChaptersController.kt | 2 + .../recently_read/RecentlyReadController.kt | 2 + 8 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/RootController.kt rename app/src/main/java/eu/kanade/tachiyomi/ui/main/{TabsAnimator.kt => ViewHeightAnimator.kt} (68%) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/RootController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/RootController.kt new file mode 100644 index 0000000000..17b27f911b --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/RootController.kt @@ -0,0 +1,3 @@ +package eu.kanade.tachiyomi.ui.base.controller + +interface RootController diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt index 57f1b13ff3..fcb5db5d10 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt @@ -23,6 +23,7 @@ import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.ui.base.controller.NucleusController +import eu.kanade.tachiyomi.ui.base.controller.RootController import eu.kanade.tachiyomi.ui.base.controller.requestPermissionsSafe import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.catalogue.browse.BrowseCatalogueController @@ -40,6 +41,7 @@ import uy.kohesive.injekt.api.get * [CatalogueAdapter.OnLatestClickListener] call function data on latest item click */ class CatalogueController : NucleusController(), + RootController, FlexibleAdapter.OnItemClickListener, FlexibleAdapter.OnItemLongClickListener, CatalogueAdapter.OnBrowseClickListener, 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 ff53b3717c..504f991294 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 @@ -33,6 +33,7 @@ import eu.kanade.tachiyomi.data.library.LibraryUpdateService import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.ui.base.controller.NucleusController +import eu.kanade.tachiyomi.ui.base.controller.RootController import eu.kanade.tachiyomi.ui.base.controller.SecondaryDrawerController import eu.kanade.tachiyomi.ui.base.controller.TabbedController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction @@ -54,6 +55,7 @@ class LibraryController( bundle: Bundle? = null, private val preferences: PreferencesHelper = Injekt.get() ) : NucleusController(bundle), + RootController, TabbedController, SecondaryDrawerController, ActionMode.Callback, 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 7cd83f13ed..9ff314ac5d 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 @@ -16,6 +16,7 @@ import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.ui.base.activity.BaseActivity import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController +import eu.kanade.tachiyomi.ui.base.controller.RootController import eu.kanade.tachiyomi.ui.base.controller.SecondaryDrawerController import eu.kanade.tachiyomi.ui.base.controller.TabbedController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction @@ -47,7 +48,8 @@ class MainActivity : BaseActivity() { } } - lateinit var tabAnimator: TabsAnimator + lateinit var tabAnimator: ViewHeightAnimator + lateinit var bottomNavAnimator: ViewHeightAnimator override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -62,7 +64,8 @@ class MainActivity : BaseActivity() { setSupportActionBar(toolbar) - tabAnimator = TabsAnimator(tabs) + tabAnimator = ViewHeightAnimator(tabs) + bottomNavAnimator = ViewHeightAnimator(bottom_nav) // Set behavior of bottom nav bottom_nav.setOnNavigationItemSelectedListener { item -> @@ -220,6 +223,13 @@ class MainActivity : BaseActivity() { supportActionBar?.setDisplayHomeAsUpEnabled(router.backstackSize != 1) + if (from is RootController && to !is RootController) { + bottomNavAnimator.collapse() + } + if (to is RootController && from !is RootController) { + bottomNavAnimator.expand() + } + if (from is TabbedController) { from.cleanupTabs(tabs) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/TabsAnimator.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/ViewHeightAnimator.kt similarity index 68% rename from app/src/main/java/eu/kanade/tachiyomi/ui/main/TabsAnimator.kt rename to app/src/main/java/eu/kanade/tachiyomi/ui/main/ViewHeightAnimator.kt index 304473c17c..3e4a2704b6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/TabsAnimator.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/ViewHeightAnimator.kt @@ -1,45 +1,46 @@ package eu.kanade.tachiyomi.ui.main import android.animation.ObjectAnimator +import android.view.View import android.view.ViewTreeObserver import android.view.animation.DecelerateInterpolator -import com.google.android.material.tabs.TabLayout +import androidx.annotation.Keep -class TabsAnimator(val tabs: TabLayout) { +class ViewHeightAnimator(val view: View) { /** - * The default height of the tab layout. It's unknown until the view is layout. + * The default height of the view. It's unknown until the view is layout. */ - private var tabsHeight = 0 + private var height = 0 /** - * Whether the last state of the tab layout is shown or hidden. + * Whether the last state of the view is shown or hidden. */ private var isLastStateShown = true /** - * Animation used to expand and collapse the tab layout. + * Animation used to expand and collapse the view. */ private val animation by lazy { - ObjectAnimator.ofInt(this, "height", tabsHeight).apply { + ObjectAnimator.ofInt(this, "height", height).apply { duration = 300L interpolator = DecelerateInterpolator() } } init { - tabs.viewTreeObserver.addOnGlobalLayoutListener( + view.viewTreeObserver.addOnGlobalLayoutListener( object : ViewTreeObserver.OnGlobalLayoutListener { override fun onGlobalLayout() { - if (tabs.height > 0) { - tabs.viewTreeObserver.removeOnGlobalLayoutListener(this) + if (view.height > 0) { + view.viewTreeObserver.removeOnGlobalLayoutListener(this) // Save the tabs default height. - tabsHeight = tabs.height + height = view.height // Now that we know the height, set the initial height. if (isLastStateShown) { - setHeight(tabsHeight) + setHeight(height) } else { setHeight(0) } @@ -54,9 +55,10 @@ class TabsAnimator(val tabs: TabLayout) { * * @param newHeight The new height of the tab layout. */ + @Keep fun setHeight(newHeight: Int) { - tabs.layoutParams.height = newHeight - tabs.requestLayout() + view.layoutParams.height = newHeight + view.requestLayout() } /** @@ -64,7 +66,7 @@ class TabsAnimator(val tabs: TabLayout) { * reflection. */ fun getHeight(): Int { - return tabs.layoutParams.height + return view.layoutParams.height } /** @@ -72,8 +74,8 @@ class TabsAnimator(val tabs: TabLayout) { */ fun expand() { if (isMeasured) { - if (getHeight() != tabsHeight) { - animation.setIntValues(tabsHeight) + if (getHeight() != height) { + animation.setIntValues(height) animation.start() } else { animation.cancel() @@ -101,5 +103,5 @@ class TabsAnimator(val tabs: TabLayout) { * Returns whether the tab layout has a known height. */ private val isMeasured: Boolean - get() = tabsHeight > 0 + get() = height > 0 } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt index 159944e5fb..c8effdfc71 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.more import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.ui.base.controller.RootController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.download.DownloadController import eu.kanade.tachiyomi.ui.extension.ExtensionController @@ -17,7 +18,7 @@ import eu.kanade.tachiyomi.util.preference.titleRes import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.openInBrowser -class MoreController : SettingsController() { +class MoreController : SettingsController(), RootController { override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { titleRes = R.string.label_more diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt index 82028b1968..ec95e113fe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt @@ -20,6 +20,7 @@ import eu.kanade.tachiyomi.data.library.LibraryUpdateService import eu.kanade.tachiyomi.data.notification.Notifications 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.popControllerWithTag import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.manga.MangaController @@ -37,6 +38,7 @@ import timber.log.Timber * UI related actions should be called from here. */ class RecentChaptersController : NucleusController(), + RootController, NoToolbarElevationController, ActionMode.Callback, FlexibleAdapter.OnItemClickListener, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt index 3840311f5d..677b2212e0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadController.kt @@ -9,6 +9,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.History import eu.kanade.tachiyomi.data.database.models.Manga 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.manga.MangaController import eu.kanade.tachiyomi.ui.reader.ReaderActivity @@ -22,6 +23,7 @@ import kotlinx.android.synthetic.main.recently_read_controller.recycler * UI related actions should be called from here. */ class RecentlyReadController : NucleusController(), + RootController, FlexibleAdapter.OnUpdateListener, RecentlyReadAdapter.OnRemoveClickListener, RecentlyReadAdapter.OnResumeClickListener,