From 4c8f5e1f7acd3f2940ae3e295056fc6568b788da Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Sun, 26 Dec 2021 23:38:35 +0700 Subject: [PATCH] Use animation to hide/show fab (#6385) --- .../ui/browse/source/browse/BrowseSourceController.kt | 9 ++++----- .../java/eu/kanade/tachiyomi/ui/main/MainActivity.kt | 5 +++-- .../java/eu/kanade/tachiyomi/ui/manga/MangaController.kt | 2 +- .../ui/setting/database/ClearDatabaseController.kt | 8 ++++++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt index 0af596c38d..a8deef9a69 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt @@ -159,13 +159,12 @@ open class BrowseSourceController(bundle: Bundle) : ) filterSheet?.setFilters(presenter.filterItems) - // TODO: [ExtendedFloatingActionButton] hide/show methods don't work properly - filterSheet?.setOnShowListener { actionFab?.isVisible = false } - filterSheet?.setOnDismissListener { actionFab?.isVisible = true } + filterSheet?.setOnShowListener { actionFab?.hide() } + filterSheet?.setOnDismissListener { actionFab?.show() } actionFab?.setOnClickListener { filterSheet?.show() } - actionFab?.isVisible = true + actionFab?.show() } override fun configureFab(fab: ExtendedFloatingActionButton) { @@ -175,7 +174,7 @@ open class BrowseSourceController(bundle: Bundle) : fab.setIconResource(R.drawable.ic_filter_list_24dp) // Controlled by initFilterSheet() - fab.isVisible = false + fab.hide() initFilterSheet() } 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 c892f10416..6944b6c733 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 @@ -562,12 +562,13 @@ class MainActivity : BaseViewBindingActivity() { binding.tabs.isVisible = to is TabbedController if (from is FabController) { - binding.fabLayout.rootFab.isVisible = false from.cleanupFab(binding.fabLayout.rootFab) } if (to is FabController) { - binding.fabLayout.rootFab.isVisible = true + binding.fabLayout.rootFab.show() to.configureFab(binding.fabLayout.rootFab) + } else { + binding.fabLayout.rootFab.hide() } if (!isTablet()) { 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 d67d14e1d4..99fb8e4b2a 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 @@ -303,7 +303,7 @@ class MangaController : actionFabScrollListener = actionFab?.shrinkOnScroll(chapterRecycler) // Initially set FAB invisible; will become visible if unread chapters are present - actionFab?.isVisible = false + actionFab?.hide() binding.swipeRefresh.refreshes() .onEach { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/database/ClearDatabaseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/database/ClearDatabaseController.kt index 2b66018815..6bcfc6e575 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/database/ClearDatabaseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/database/ClearDatabaseController.kt @@ -125,7 +125,7 @@ class ClearDatabaseController : override fun configureFab(fab: ExtendedFloatingActionButton) { fab.setIconResource(R.drawable.ic_delete_24dp) fab.setText(R.string.action_delete) - fab.isVisible = false + fab.hide() fab.setOnClickListener { val ctrl = ClearDatabaseSourcesDialog() ctrl.targetController = this @@ -136,7 +136,11 @@ class ClearDatabaseController : private fun updateFab() { val adapter = adapter ?: return - actionFab?.isVisible = adapter.selectedItemCount > 0 + if (adapter.selectedItemCount > 0) { + actionFab?.show() + } else { + actionFab?.hide() + } } override fun cleanupFab(fab: ExtendedFloatingActionButton) {