From 3784d1a8f2886e1ebc598cd83afa2622f9c44b43 Mon Sep 17 00:00:00 2001 From: scb261 <65343233+scb261@users.noreply.github.com> Date: Sun, 27 Sep 2020 20:25:30 +0300 Subject: [PATCH] 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 --- .../tachiyomi/data/preference/PreferenceKeys.kt | 2 ++ .../tachiyomi/data/preference/PreferencesHelper.kt | 2 ++ .../eu/kanade/tachiyomi/ui/main/MainActivity.kt | 14 +++++++++++--- .../ui/setting/SettingsGeneralController.kt | 5 +++++ app/src/main/res/layout/main_activity.xml | 1 - app/src/main/res/values/strings.xml | 1 + 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 0d3d974ec..73c3dad48 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -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" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index ddf513f45..86e1733aa 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -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) 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 4c02134a9..40aefce3e 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 @@ -90,6 +90,7 @@ class MainActivity : BaseActivity() { 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() { !isConfirmingExit } + private fun setBottomBarBehaviorOnScroll() { + val layoutParams = binding.bottomNav.layoutParams as CoordinatorLayout.LayoutParams + layoutParams.behavior = + if (preferences.hideBottomBar().get()) HideBottomViewOnScrollBehavior() else null + } + fun setSelectedNavItem(itemId: Int) { if (!isFinishing) { binding.bottomNav.selectedItemId = itemId @@ -336,6 +343,7 @@ class MainActivity : BaseActivity() { 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() { 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) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt index 8052663c6..7e5ce7ed7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt @@ -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" diff --git a/app/src/main/res/layout/main_activity.xml b/app/src/main/res/layout/main_activity.xml index ac97a5f09..ecad09f10 100644 --- a/app/src/main/res/layout/main_activity.xml +++ b/app/src/main/res/layout/main_activity.xml @@ -47,7 +47,6 @@ app:itemIconTint="@color/bottom_nav_selector" app:itemTextColor="@color/bottom_nav_selector" app:labelVisibilityMode="labeled" - app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior" app:layout_insetEdge="bottom" app:menu="@menu/bottom_nav" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ad558883c..e06130ad7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -157,6 +157,7 @@ Default Date format Confirm exit + Hide bottom bar on scroll Manage notifications Security