mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-11-04 08:08:55 +01:00 
			
		
		
		
	Initial tablet NavigationRailView implementation
TODO: - Make the side nav go beside the toolbar too - Extract out common main_activity stuff to remove duplicated code
This commit is contained in:
		@@ -367,7 +367,7 @@ class LibraryController(
 | 
			
		||||
                actionMode!!,
 | 
			
		||||
                R.menu.library_selection
 | 
			
		||||
            ) { onActionItemClicked(it!!) }
 | 
			
		||||
            (activity as? MainActivity)?.showBottomNav(visible = false, collapse = true)
 | 
			
		||||
            (activity as? MainActivity)?.showNav(visible = false, collapse = true)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -476,7 +476,7 @@ class LibraryController(
 | 
			
		||||
        selectionRelay.call(LibrarySelectionEvent.Cleared())
 | 
			
		||||
 | 
			
		||||
        binding.actionToolbar.hide()
 | 
			
		||||
        (activity as? MainActivity)?.showBottomNav(visible = true, collapse = true)
 | 
			
		||||
        (activity as? MainActivity)?.showNav(visible = true, collapse = true)
 | 
			
		||||
 | 
			
		||||
        actionMode = null
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -24,6 +24,7 @@ import com.bluelinelabs.conductor.Router
 | 
			
		||||
import com.bluelinelabs.conductor.RouterTransaction
 | 
			
		||||
import com.google.android.material.appbar.AppBarLayout
 | 
			
		||||
import com.google.android.material.behavior.HideBottomViewOnScrollBehavior
 | 
			
		||||
import com.google.android.material.navigation.NavigationBarView
 | 
			
		||||
import dev.chrisbanes.insetter.applyInsetter
 | 
			
		||||
import eu.kanade.tachiyomi.BuildConfig
 | 
			
		||||
import eu.kanade.tachiyomi.Migrations
 | 
			
		||||
@@ -76,7 +77,7 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    lateinit var tabAnimator: ViewHeightAnimator
 | 
			
		||||
    private lateinit var bottomNavAnimator: ViewHeightAnimator
 | 
			
		||||
    private var bottomNavAnimator: ViewHeightAnimator? = null
 | 
			
		||||
 | 
			
		||||
    private var isConfirmingExit: Boolean = false
 | 
			
		||||
    private var isHandlingShortcut: Boolean = false
 | 
			
		||||
@@ -109,7 +110,7 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
 | 
			
		||||
                margin()
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        binding.bottomNav.applyInsetter {
 | 
			
		||||
        binding.bottomNav?.applyInsetter {
 | 
			
		||||
            type(navigationBars = true) {
 | 
			
		||||
                padding()
 | 
			
		||||
            }
 | 
			
		||||
@@ -131,23 +132,26 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        tabAnimator = ViewHeightAnimator(binding.tabs, 0L)
 | 
			
		||||
        bottomNavAnimator = ViewHeightAnimator(binding.bottomNav)
 | 
			
		||||
 | 
			
		||||
        // If bottom nav is hidden, make it visible again when the app bar is expanded
 | 
			
		||||
        binding.appbar.addOnOffsetChangedListener(
 | 
			
		||||
            AppBarLayout.OnOffsetChangedListener { _, verticalOffset ->
 | 
			
		||||
                if (verticalOffset == 0) {
 | 
			
		||||
                    showBottomNav(true)
 | 
			
		||||
        if (binding.bottomNav != null) {
 | 
			
		||||
            bottomNavAnimator = ViewHeightAnimator(binding.bottomNav!!)
 | 
			
		||||
 | 
			
		||||
            // If bottom nav is hidden, make it visible again when the app bar is expanded
 | 
			
		||||
            binding.appbar.addOnOffsetChangedListener(
 | 
			
		||||
                AppBarLayout.OnOffsetChangedListener { _, verticalOffset ->
 | 
			
		||||
                    if (verticalOffset == 0) {
 | 
			
		||||
                        showNav(true)
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        )
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        // Set behavior of bottom nav
 | 
			
		||||
        preferences.hideBottomBar()
 | 
			
		||||
            .asImmediateFlow { setBottomNavBehaviorOnScroll() }
 | 
			
		||||
            .launchIn(lifecycleScope)
 | 
			
		||||
            // Set behavior of bottom nav
 | 
			
		||||
            preferences.hideBottomBar()
 | 
			
		||||
                .asImmediateFlow { setBottomNavBehaviorOnScroll() }
 | 
			
		||||
                .launchIn(lifecycleScope)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        binding.bottomNav.setOnNavigationItemSelectedListener { item ->
 | 
			
		||||
        nav.setOnItemSelectedListener { item ->
 | 
			
		||||
            val id = item.itemId
 | 
			
		||||
 | 
			
		||||
            val currentRoot = router.backstack.firstOrNull()
 | 
			
		||||
@@ -256,9 +260,9 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
 | 
			
		||||
    private fun setExtensionsBadge() {
 | 
			
		||||
        val updates = preferences.extensionUpdatesCount().get()
 | 
			
		||||
        if (updates > 0) {
 | 
			
		||||
            binding.bottomNav.getOrCreateBadge(R.id.nav_browse).number = updates
 | 
			
		||||
            nav.getOrCreateBadge(R.id.nav_browse).number = updates
 | 
			
		||||
        } else {
 | 
			
		||||
            binding.bottomNav.removeBadge(R.id.nav_browse)
 | 
			
		||||
            nav.removeBadge(R.id.nav_browse)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -350,7 +354,7 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
 | 
			
		||||
        super.onDestroy()
 | 
			
		||||
 | 
			
		||||
        // Binding sometimes isn't actually instantiated yet somehow
 | 
			
		||||
        binding?.bottomNav.setOnNavigationItemSelectedListener(null)
 | 
			
		||||
        nav.setOnItemSelectedListener(null)
 | 
			
		||||
        binding?.toolbar.setNavigationOnClickListener(null)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -385,7 +389,7 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
 | 
			
		||||
 | 
			
		||||
    fun setSelectedNavItem(itemId: Int) {
 | 
			
		||||
        if (!isFinishing) {
 | 
			
		||||
            binding.bottomNav.selectedItemId = itemId
 | 
			
		||||
            nav.selectedItemId = itemId
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -407,11 +411,11 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
 | 
			
		||||
        binding.appbar.setExpanded(true)
 | 
			
		||||
 | 
			
		||||
        if ((from == null || from is RootController) && to !is RootController) {
 | 
			
		||||
            showBottomNav(visible = false, collapse = true)
 | 
			
		||||
            showNav(visible = false, collapse = true)
 | 
			
		||||
        }
 | 
			
		||||
        if (to is RootController) {
 | 
			
		||||
            // Always show bottom nav again when returning to a RootController
 | 
			
		||||
            showBottomNav(visible = true, collapse = from !is RootController)
 | 
			
		||||
            showNav(visible = true, collapse = from !is RootController)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (from is TabbedController) {
 | 
			
		||||
@@ -447,21 +451,28 @@ class MainActivity : BaseViewBindingActivity<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()
 | 
			
		||||
            }
 | 
			
		||||
    fun showNav(visible: Boolean, collapse: Boolean = false) {
 | 
			
		||||
        binding.bottomNav?.let {
 | 
			
		||||
            val layoutParams = it.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?.slideUp(it)
 | 
			
		||||
            } else {
 | 
			
		||||
                if (collapse) {
 | 
			
		||||
                    bottomNavAnimator?.collapse()
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            bottomViewNavigationBehavior?.slideDown(binding.bottomNav)
 | 
			
		||||
                bottomViewNavigationBehavior?.slideDown(it)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        binding.sideNav?.let {
 | 
			
		||||
            it.isVisible = visible
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -484,9 +495,9 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun setBottomNavBehaviorOnScroll() {
 | 
			
		||||
        showBottomNav(visible = true)
 | 
			
		||||
        showNav(visible = true)
 | 
			
		||||
 | 
			
		||||
        binding.bottomNav.updateLayoutParams<CoordinatorLayout.LayoutParams> {
 | 
			
		||||
        binding.bottomNav?.updateLayoutParams<CoordinatorLayout.LayoutParams> {
 | 
			
		||||
            behavior = when {
 | 
			
		||||
                preferences.hideBottomBar().get() -> HideBottomViewOnScrollBehavior<View>()
 | 
			
		||||
                else -> null
 | 
			
		||||
@@ -494,6 +505,9 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private val nav: NavigationBarView
 | 
			
		||||
        get() = binding.bottomNav ?: binding.sideNav!!
 | 
			
		||||
 | 
			
		||||
    companion object {
 | 
			
		||||
        // Shortcut actions
 | 
			
		||||
        const val SHORTCUT_LIBRARY = "eu.kanade.tachiyomi.SHOW_LIBRARY"
 | 
			
		||||
 
 | 
			
		||||
@@ -182,7 +182,7 @@ class UpdatesController :
 | 
			
		||||
                actionMode!!,
 | 
			
		||||
                R.menu.updates_chapter_selection
 | 
			
		||||
            ) { onActionItemClicked(it!!) }
 | 
			
		||||
            (activity as? MainActivity)?.showBottomNav(visible = false, collapse = true)
 | 
			
		||||
            (activity as? MainActivity)?.showNav(visible = false, collapse = true)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        toggleSelection(position)
 | 
			
		||||
@@ -380,7 +380,7 @@ class UpdatesController :
 | 
			
		||||
        adapter?.clearSelection()
 | 
			
		||||
 | 
			
		||||
        binding.actionToolbar.hide()
 | 
			
		||||
        (activity as? MainActivity)?.showBottomNav(visible = true, collapse = true)
 | 
			
		||||
        (activity as? MainActivity)?.showNav(visible = true, collapse = true)
 | 
			
		||||
 | 
			
		||||
        actionMode = null
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user