From 748a7201991cb42fa7d9fef0d229a331dcc4039a Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 10 Aug 2020 12:04:51 -0400 Subject: [PATCH] Lift toolbar on scroll in extension details and manga controllers --- .../controller/ToolbarLiftOnScrollController.kt | 3 +++ .../details/ExtensionDetailsController.kt | 4 ++-- .../eu/kanade/tachiyomi/ui/main/MainActivity.kt | 15 +++++++++++---- .../kanade/tachiyomi/ui/manga/MangaController.kt | 2 ++ .../tachiyomi/widget/ElevationAppBarLayout.kt | 3 ++- 5 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ToolbarLiftOnScrollController.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ToolbarLiftOnScrollController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ToolbarLiftOnScrollController.kt new file mode 100644 index 0000000000..e3b296b47c --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ToolbarLiftOnScrollController.kt @@ -0,0 +1,3 @@ +package eu.kanade.tachiyomi.ui.base.controller + +interface ToolbarLiftOnScrollController diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt index a715ca4c84..2fb7f7a645 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt @@ -34,8 +34,8 @@ import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.ConfigurableSource import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.getPreferenceKey -import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController import eu.kanade.tachiyomi.ui.base.controller.NucleusController +import eu.kanade.tachiyomi.ui.base.controller.ToolbarLiftOnScrollController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.util.preference.DSL import eu.kanade.tachiyomi.util.preference.onChange @@ -50,7 +50,7 @@ import uy.kohesive.injekt.injectLazy @SuppressLint("RestrictedApi") class ExtensionDetailsController(bundle: Bundle? = null) : NucleusController(bundle), - NoToolbarElevationController { + ToolbarLiftOnScrollController { private val preferences: PreferencesHelper by injectLazy() 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 f34604e92b..1ce35ab00d 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 @@ -31,6 +31,7 @@ import eu.kanade.tachiyomi.ui.base.controller.FabController import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController import eu.kanade.tachiyomi.ui.base.controller.RootController import eu.kanade.tachiyomi.ui.base.controller.TabbedController +import eu.kanade.tachiyomi.ui.base.controller.ToolbarLiftOnScrollController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.browse.BrowseController import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchController @@ -355,10 +356,16 @@ class MainActivity : BaseActivity() { to.configureFab(binding.rootFab) } - if (to is NoToolbarElevationController) { - binding.appbar.disableElevation() - } else { - binding.appbar.enableElevation() + when (to) { + is NoToolbarElevationController -> { + binding.appbar.disableElevation() + } + is ToolbarLiftOnScrollController -> { + binding.appbar.enableElevation(true) + } + else -> { + binding.appbar.enableElevation(false) + } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index 75647d5c11..f9f6a1f2b0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -42,6 +42,7 @@ import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.ui.base.controller.FabController import eu.kanade.tachiyomi.ui.base.controller.NucleusController +import eu.kanade.tachiyomi.ui.base.controller.ToolbarLiftOnScrollController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.browse.migration.search.SearchController import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceController @@ -85,6 +86,7 @@ import uy.kohesive.injekt.injectLazy class MangaController : NucleusController, + ToolbarLiftOnScrollController, FabController, ActionMode.Callback, FlexibleAdapter.OnItemClickListener, diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/ElevationAppBarLayout.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/ElevationAppBarLayout.kt index 838bcab8e8..e64e793a36 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/ElevationAppBarLayout.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/ElevationAppBarLayout.kt @@ -18,8 +18,9 @@ class ElevationAppBarLayout @JvmOverloads constructor( origStateAnimator = stateListAnimator } - fun enableElevation() { + fun enableElevation(liftOnScroll: Boolean) { stateListAnimator = origStateAnimator + isLiftOnScroll = liftOnScroll } fun disableElevation() {