From a462ce3626720ba770b6d1e991be9490a551e83c Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 23 May 2021 14:27:44 -0400 Subject: [PATCH] Option to move nav rail buttons to bottom of screen (closes #5158) Based on https://github.com/Jays2Kings/tachiyomiJ2K/commit/90be3e34948d41daf3fd695ef09d60eb6adf960e Co-authored-by: Jays2Kings --- .../tachiyomi/data/preference/PreferenceKeys.kt | 4 +++- .../tachiyomi/data/preference/PreferencesHelper.kt | 4 +++- .../eu/kanade/tachiyomi/ui/main/MainActivity.kt | 13 +++++++++++-- .../ui/setting/SettingsGeneralController.kt | 10 ++++++++-- app/src/main/res/values/strings.xml | 1 + 5 files changed, 26 insertions(+), 6 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 061dba2d3..e67bb334d 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,7 +13,9 @@ object PreferenceKeys { const val confirmExit = "pref_confirm_exit" - const val hideBottomBar = "pref_hide_bottom_bar_on_scroll" + const val hideBottomBarOnScroll = "pref_hide_bottom_bar_on_scroll" + + const val showSideNavOnBottom = "pref_show_side_nav_on_bottom" 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 c8518c24d..64b439a7e 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 @@ -63,7 +63,9 @@ class PreferencesHelper(val context: Context) { fun confirmExit() = prefs.getBoolean(Keys.confirmExit, false) - fun hideBottomBar() = flowPrefs.getBoolean(Keys.hideBottomBar, true) + fun hideBottomBarOnScroll() = flowPrefs.getBoolean(Keys.hideBottomBarOnScroll, true) + + fun showSideNavOnBottom() = flowPrefs.getBoolean(Keys.showSideNavOnBottom, false) fun useAuthenticator() = flowPrefs.getBoolean(Keys.useAuthenticator, false) 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 12189fb15..501bb0113 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 @@ -5,6 +5,7 @@ import android.content.Intent import android.graphics.Color import android.os.Build import android.os.Bundle +import android.view.Gravity import android.view.View import android.view.ViewGroup import android.widget.Toast @@ -145,11 +146,19 @@ class MainActivity : BaseViewBindingActivity() { ) // Set behavior of bottom nav - preferences.hideBottomBar() + preferences.hideBottomBarOnScroll() .asImmediateFlow { setBottomNavBehaviorOnScroll() } .launchIn(lifecycleScope) } + if (binding.sideNav != null) { + preferences.showSideNavOnBottom() + .asImmediateFlow { + binding.sideNav?.menuGravity = if (!it) Gravity.TOP else Gravity.BOTTOM + } + .launchIn(lifecycleScope) + } + nav.setOnItemSelectedListener { item -> val id = item.itemId @@ -505,7 +514,7 @@ class MainActivity : BaseViewBindingActivity() { binding.bottomNav?.updateLayoutParams { behavior = when { - preferences.hideBottomBar().get() -> HideBottomViewOnScrollBehavior() + preferences.hideBottomBarOnScroll().get() -> HideBottomViewOnScrollBehavior() else -> null } } 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 7eddcca91..5c53a1e35 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 @@ -46,9 +46,15 @@ class SettingsGeneralController : SettingsController() { titleRes = R.string.pref_confirm_exit defaultValue = false } - if (!context.isTablet()) { + if (context.isTablet()) { switchPreference { - key = Keys.hideBottomBar + key = Keys.showSideNavOnBottom + titleRes = R.string.pref_move_side_nav_to_bottom + defaultValue = false + } + } else { + switchPreference { + key = Keys.hideBottomBarOnScroll titleRes = R.string.pref_hide_bottom_bar_on_scroll defaultValue = true } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 32ba77e70..45c1b1cbe 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -166,6 +166,7 @@ Date format Confirm exit Hide bottom bar on scroll + Move side navigation buttons to bottom Manage notifications Security