mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 06:17:57 +01:00 
			
		
		
		
	Add option to hide bottom bar when scrolling (#3758)
* [wip] hardcoded flag for hide on scroll * add corresponding option in settings * clean up a little Co-authored-by: arkon <arkon@users.noreply.github.com>
This commit is contained in:
		| @@ -13,6 +13,8 @@ object PreferenceKeys { | ||||
|  | ||||
|     const val confirmExit = "pref_confirm_exit" | ||||
|  | ||||
|     const val hideBottomBar = "pref_hide_bottom_bar_on_scroll" | ||||
|  | ||||
|     const val rotation = "pref_rotation_type_key" | ||||
|  | ||||
|     const val enableTransitions = "pref_enable_transitions_key" | ||||
|   | ||||
| @@ -61,6 +61,8 @@ class PreferencesHelper(val context: Context) { | ||||
|  | ||||
|     fun confirmExit() = prefs.getBoolean(Keys.confirmExit, false) | ||||
|  | ||||
|     fun hideBottomBar() = flowPrefs.getBoolean(Keys.hideBottomBar, true) | ||||
|  | ||||
|     fun useBiometricLock() = flowPrefs.getBoolean(Keys.useBiometricLock, false) | ||||
|  | ||||
|     fun lockAppAfter() = flowPrefs.getInt(Keys.lockAppAfter, 0) | ||||
|   | ||||
| @@ -90,6 +90,7 @@ class MainActivity : BaseActivity<MainActivityBinding>() { | ||||
|         bottomNavAnimator = ViewHeightAnimator(binding.bottomNav) | ||||
|  | ||||
|         // Set behavior of bottom nav | ||||
|         setBottomBarBehaviorOnScroll() | ||||
|         binding.bottomNav.setOnNavigationItemSelectedListener { item -> | ||||
|             val id = item.itemId | ||||
|  | ||||
| @@ -307,6 +308,12 @@ class MainActivity : BaseActivity<MainActivityBinding>() { | ||||
|             !isConfirmingExit | ||||
|     } | ||||
|  | ||||
|     private fun setBottomBarBehaviorOnScroll() { | ||||
|         val layoutParams = binding.bottomNav.layoutParams as CoordinatorLayout.LayoutParams | ||||
|         layoutParams.behavior = | ||||
|             if (preferences.hideBottomBar().get()) HideBottomViewOnScrollBehavior<View>() else null | ||||
|     } | ||||
|  | ||||
|     fun setSelectedNavItem(itemId: Int) { | ||||
|         if (!isFinishing) { | ||||
|             binding.bottomNav.selectedItemId = itemId | ||||
| @@ -336,6 +343,7 @@ class MainActivity : BaseActivity<MainActivityBinding>() { | ||||
|         if (to is RootController) { | ||||
|             // Always show bottom nav again when returning to a RootController | ||||
|             showBottomNav(visible = true, collapse = from !is RootController) | ||||
|             setBottomBarBehaviorOnScroll() | ||||
|         } | ||||
|  | ||||
|         if (from is TabbedController) { | ||||
| @@ -373,19 +381,19 @@ class MainActivity : BaseActivity<MainActivityBinding>() { | ||||
|  | ||||
|     fun showBottomNav(visible: Boolean, collapse: Boolean = false) { | ||||
|         val layoutParams = binding.bottomNav.layoutParams as CoordinatorLayout.LayoutParams | ||||
|         val bottomViewNavigationBehavior = layoutParams.behavior as HideBottomViewOnScrollBehavior | ||||
|         val bottomViewNavigationBehavior = layoutParams.behavior as? HideBottomViewOnScrollBehavior | ||||
|         if (visible) { | ||||
|             if (collapse) { | ||||
|                 bottomNavAnimator.expand() | ||||
|             } | ||||
|  | ||||
|             bottomViewNavigationBehavior.slideUp(binding.bottomNav) | ||||
|             bottomViewNavigationBehavior?.slideUp(binding.bottomNav) | ||||
|         } else { | ||||
|             if (collapse) { | ||||
|                 bottomNavAnimator.collapse() | ||||
|             } | ||||
|  | ||||
|             bottomViewNavigationBehavior.slideDown(binding.bottomNav) | ||||
|             bottomViewNavigationBehavior?.slideDown(binding.bottomNav) | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -45,6 +45,11 @@ class SettingsGeneralController : SettingsController() { | ||||
|             titleRes = R.string.pref_confirm_exit | ||||
|             defaultValue = false | ||||
|         } | ||||
|         switchPreference { | ||||
|             key = Keys.hideBottomBar | ||||
|             titleRes = R.string.pref_hide_bottom_bar_on_scroll | ||||
|             defaultValue = true | ||||
|         } | ||||
|         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||||
|             preference { | ||||
|                 key = "pref_manage_notifications" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user