mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 11:17:25 +01:00
Hide bottom nav on non-root controllers
This commit is contained in:
parent
e30b1de100
commit
164da0fd9f
@ -0,0 +1,3 @@
|
|||||||
|
package eu.kanade.tachiyomi.ui.base.controller
|
||||||
|
|
||||||
|
interface RootController
|
@ -23,6 +23,7 @@ import eu.kanade.tachiyomi.data.preference.getOrDefault
|
|||||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||||
import eu.kanade.tachiyomi.source.Source
|
import eu.kanade.tachiyomi.source.Source
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
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.requestPermissionsSafe
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||||
import eu.kanade.tachiyomi.ui.catalogue.browse.BrowseCatalogueController
|
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
|
* [CatalogueAdapter.OnLatestClickListener] call function data on latest item click
|
||||||
*/
|
*/
|
||||||
class CatalogueController : NucleusController<CataloguePresenter>(),
|
class CatalogueController : NucleusController<CataloguePresenter>(),
|
||||||
|
RootController,
|
||||||
FlexibleAdapter.OnItemClickListener,
|
FlexibleAdapter.OnItemClickListener,
|
||||||
FlexibleAdapter.OnItemLongClickListener,
|
FlexibleAdapter.OnItemLongClickListener,
|
||||||
CatalogueAdapter.OnBrowseClickListener,
|
CatalogueAdapter.OnBrowseClickListener,
|
||||||
|
@ -33,6 +33,7 @@ import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
|||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
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.SecondaryDrawerController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.TabbedController
|
import eu.kanade.tachiyomi.ui.base.controller.TabbedController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||||
@ -54,6 +55,7 @@ class LibraryController(
|
|||||||
bundle: Bundle? = null,
|
bundle: Bundle? = null,
|
||||||
private val preferences: PreferencesHelper = Injekt.get()
|
private val preferences: PreferencesHelper = Injekt.get()
|
||||||
) : NucleusController<LibraryPresenter>(bundle),
|
) : NucleusController<LibraryPresenter>(bundle),
|
||||||
|
RootController,
|
||||||
TabbedController,
|
TabbedController,
|
||||||
SecondaryDrawerController,
|
SecondaryDrawerController,
|
||||||
ActionMode.Callback,
|
ActionMode.Callback,
|
||||||
|
@ -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.activity.BaseActivity
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController
|
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.SecondaryDrawerController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.TabbedController
|
import eu.kanade.tachiyomi.ui.base.controller.TabbedController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
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?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@ -62,7 +64,8 @@ class MainActivity : BaseActivity() {
|
|||||||
|
|
||||||
setSupportActionBar(toolbar)
|
setSupportActionBar(toolbar)
|
||||||
|
|
||||||
tabAnimator = TabsAnimator(tabs)
|
tabAnimator = ViewHeightAnimator(tabs)
|
||||||
|
bottomNavAnimator = ViewHeightAnimator(bottom_nav)
|
||||||
|
|
||||||
// Set behavior of bottom nav
|
// Set behavior of bottom nav
|
||||||
bottom_nav.setOnNavigationItemSelectedListener { item ->
|
bottom_nav.setOnNavigationItemSelectedListener { item ->
|
||||||
@ -220,6 +223,13 @@ class MainActivity : BaseActivity() {
|
|||||||
|
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(router.backstackSize != 1)
|
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) {
|
if (from is TabbedController) {
|
||||||
from.cleanupTabs(tabs)
|
from.cleanupTabs(tabs)
|
||||||
}
|
}
|
||||||
|
@ -1,45 +1,46 @@
|
|||||||
package eu.kanade.tachiyomi.ui.main
|
package eu.kanade.tachiyomi.ui.main
|
||||||
|
|
||||||
import android.animation.ObjectAnimator
|
import android.animation.ObjectAnimator
|
||||||
|
import android.view.View
|
||||||
import android.view.ViewTreeObserver
|
import android.view.ViewTreeObserver
|
||||||
import android.view.animation.DecelerateInterpolator
|
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
|
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 {
|
private val animation by lazy {
|
||||||
ObjectAnimator.ofInt(this, "height", tabsHeight).apply {
|
ObjectAnimator.ofInt(this, "height", height).apply {
|
||||||
duration = 300L
|
duration = 300L
|
||||||
interpolator = DecelerateInterpolator()
|
interpolator = DecelerateInterpolator()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
tabs.viewTreeObserver.addOnGlobalLayoutListener(
|
view.viewTreeObserver.addOnGlobalLayoutListener(
|
||||||
object : ViewTreeObserver.OnGlobalLayoutListener {
|
object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||||
override fun onGlobalLayout() {
|
override fun onGlobalLayout() {
|
||||||
if (tabs.height > 0) {
|
if (view.height > 0) {
|
||||||
tabs.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
view.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
||||||
|
|
||||||
// Save the tabs default height.
|
// Save the tabs default height.
|
||||||
tabsHeight = tabs.height
|
height = view.height
|
||||||
|
|
||||||
// Now that we know the height, set the initial height.
|
// Now that we know the height, set the initial height.
|
||||||
if (isLastStateShown) {
|
if (isLastStateShown) {
|
||||||
setHeight(tabsHeight)
|
setHeight(height)
|
||||||
} else {
|
} else {
|
||||||
setHeight(0)
|
setHeight(0)
|
||||||
}
|
}
|
||||||
@ -54,9 +55,10 @@ class TabsAnimator(val tabs: TabLayout) {
|
|||||||
*
|
*
|
||||||
* @param newHeight The new height of the tab layout.
|
* @param newHeight The new height of the tab layout.
|
||||||
*/
|
*/
|
||||||
|
@Keep
|
||||||
fun setHeight(newHeight: Int) {
|
fun setHeight(newHeight: Int) {
|
||||||
tabs.layoutParams.height = newHeight
|
view.layoutParams.height = newHeight
|
||||||
tabs.requestLayout()
|
view.requestLayout()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,7 +66,7 @@ class TabsAnimator(val tabs: TabLayout) {
|
|||||||
* reflection.
|
* reflection.
|
||||||
*/
|
*/
|
||||||
fun getHeight(): Int {
|
fun getHeight(): Int {
|
||||||
return tabs.layoutParams.height
|
return view.layoutParams.height
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,8 +74,8 @@ class TabsAnimator(val tabs: TabLayout) {
|
|||||||
*/
|
*/
|
||||||
fun expand() {
|
fun expand() {
|
||||||
if (isMeasured) {
|
if (isMeasured) {
|
||||||
if (getHeight() != tabsHeight) {
|
if (getHeight() != height) {
|
||||||
animation.setIntValues(tabsHeight)
|
animation.setIntValues(height)
|
||||||
animation.start()
|
animation.start()
|
||||||
} else {
|
} else {
|
||||||
animation.cancel()
|
animation.cancel()
|
||||||
@ -101,5 +103,5 @@ class TabsAnimator(val tabs: TabLayout) {
|
|||||||
* Returns whether the tab layout has a known height.
|
* Returns whether the tab layout has a known height.
|
||||||
*/
|
*/
|
||||||
private val isMeasured: Boolean
|
private val isMeasured: Boolean
|
||||||
get() = tabsHeight > 0
|
get() = height > 0
|
||||||
}
|
}
|
@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.more
|
|||||||
|
|
||||||
import androidx.preference.PreferenceScreen
|
import androidx.preference.PreferenceScreen
|
||||||
import eu.kanade.tachiyomi.R
|
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.base.controller.withFadeTransaction
|
||||||
import eu.kanade.tachiyomi.ui.download.DownloadController
|
import eu.kanade.tachiyomi.ui.download.DownloadController
|
||||||
import eu.kanade.tachiyomi.ui.extension.ExtensionController
|
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.getResourceColor
|
||||||
import eu.kanade.tachiyomi.util.system.openInBrowser
|
import eu.kanade.tachiyomi.util.system.openInBrowser
|
||||||
|
|
||||||
class MoreController : SettingsController() {
|
class MoreController : SettingsController(), RootController {
|
||||||
|
|
||||||
override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) {
|
override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) {
|
||||||
titleRes = R.string.label_more
|
titleRes = R.string.label_more
|
||||||
|
@ -20,6 +20,7 @@ import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
|||||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController
|
import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
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.popControllerWithTag
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||||
@ -37,6 +38,7 @@ import timber.log.Timber
|
|||||||
* UI related actions should be called from here.
|
* UI related actions should be called from here.
|
||||||
*/
|
*/
|
||||||
class RecentChaptersController : NucleusController<RecentChaptersPresenter>(),
|
class RecentChaptersController : NucleusController<RecentChaptersPresenter>(),
|
||||||
|
RootController,
|
||||||
NoToolbarElevationController,
|
NoToolbarElevationController,
|
||||||
ActionMode.Callback,
|
ActionMode.Callback,
|
||||||
FlexibleAdapter.OnItemClickListener,
|
FlexibleAdapter.OnItemClickListener,
|
||||||
|
@ -9,6 +9,7 @@ import eu.kanade.tachiyomi.R
|
|||||||
import eu.kanade.tachiyomi.data.database.models.History
|
import eu.kanade.tachiyomi.data.database.models.History
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
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.base.controller.withFadeTransaction
|
||||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
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.
|
* UI related actions should be called from here.
|
||||||
*/
|
*/
|
||||||
class RecentlyReadController : NucleusController<RecentlyReadPresenter>(),
|
class RecentlyReadController : NucleusController<RecentlyReadPresenter>(),
|
||||||
|
RootController,
|
||||||
FlexibleAdapter.OnUpdateListener,
|
FlexibleAdapter.OnUpdateListener,
|
||||||
RecentlyReadAdapter.OnRemoveClickListener,
|
RecentlyReadAdapter.OnRemoveClickListener,
|
||||||
RecentlyReadAdapter.OnResumeClickListener,
|
RecentlyReadAdapter.OnResumeClickListener,
|
||||||
|
Loading…
Reference in New Issue
Block a user