Hide bottom nav on non-root controllers

This commit is contained in:
arkon 2020-03-06 21:53:25 -05:00
parent e30b1de100
commit 164da0fd9f
8 changed files with 45 additions and 21 deletions

View File

@ -0,0 +1,3 @@
package eu.kanade.tachiyomi.ui.base.controller
interface RootController

View File

@ -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<CataloguePresenter>(),
RootController,
FlexibleAdapter.OnItemClickListener,
FlexibleAdapter.OnItemLongClickListener,
CatalogueAdapter.OnBrowseClickListener,

View File

@ -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<LibraryPresenter>(bundle),
RootController,
TabbedController,
SecondaryDrawerController,
ActionMode.Callback,

View File

@ -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)
}

View File

@ -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
}

View File

@ -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

View File

@ -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<RecentChaptersPresenter>(),
RootController,
NoToolbarElevationController,
ActionMode.Callback,
FlexibleAdapter.OnItemClickListener,

View File

@ -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<RecentlyReadPresenter>(),
RootController,
FlexibleAdapter.OnUpdateListener,
RecentlyReadAdapter.OnRemoveClickListener,
RecentlyReadAdapter.OnResumeClickListener,