From aa70be525d2c032db43593e811fd340308a4c90b Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 10 Apr 2020 15:39:28 -0400 Subject: [PATCH] Add text to chapter FAB, shrink extended FABs on scroll --- .../browse/BrowseCatalogueController.kt | 5 ++++- .../ui/manga/chapter/ChaptersController.kt | 2 ++ .../tachiyomi/util/view/ViewExtensions.kt | 18 ++++++++++++++++++ .../main/res/layout/chapters_controller.xml | 5 +++-- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt index 1b360ccbc2..b34e8b99bd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt @@ -36,6 +36,7 @@ import eu.kanade.tachiyomi.util.system.connectivityManager import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.inflate +import eu.kanade.tachiyomi.util.view.shrinkOnScroll import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.widget.AutofitRecyclerView @@ -203,8 +204,8 @@ open class BrowseCatalogueController(bundle: Bundle) : } } - // Add bottom padding if filter FAB is visible if (presenter.sourceFilters.isNotEmpty()) { + // Add bottom padding if filter FAB is visible recycler.setPadding( 0, 0, @@ -212,6 +213,8 @@ open class BrowseCatalogueController(bundle: Bundle) : view.resources.getDimensionPixelOffset(R.dimen.fab_list_padding) ) recycler.clipToPadding = false + + binding.fabFilter.shrinkOnScroll(recycler) } recycler.setHasFixedSize(true) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt index 4b49830d78..b6eb5a73d9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt @@ -32,6 +32,7 @@ import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.getCoordinates +import eu.kanade.tachiyomi.util.view.shrinkOnScroll import eu.kanade.tachiyomi.util.view.snack import timber.log.Timber @@ -110,6 +111,7 @@ class ChaptersController : NucleusController(), view.context.toast(R.string.no_next_chapter) } } + binding.fab.shrinkOnScroll(binding.recycler) } override fun onDestroyView(view: View) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt index 4bbef73a5a..41bbfa24f4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt @@ -13,8 +13,10 @@ import android.widget.ImageView import android.widget.TextView import androidx.annotation.MenuRes import androidx.appcompat.widget.PopupMenu +import androidx.recyclerview.widget.RecyclerView import com.amulyakhare.textdrawable.TextDrawable import com.amulyakhare.textdrawable.util.ColorGenerator +import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton import com.google.android.material.snackbar.Snackbar import eu.kanade.tachiyomi.R import kotlin.math.min @@ -94,3 +96,19 @@ fun ImageView.roundTextIcon(text: String) { ) ) } + +/** + * Shrink an ExtendedFloatingActionButton when the associated RecyclerView is scrolled down. + * + * @param recycler [RecyclerView] that the FAB should shrink/extend in response to. + */ +fun ExtendedFloatingActionButton.shrinkOnScroll(recycler: RecyclerView) { + recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() { + override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { + if (dy <= 0) + extend() + else + shrink() + } + }) +} diff --git a/app/src/main/res/layout/chapters_controller.xml b/app/src/main/res/layout/chapters_controller.xml index 32fb318b06..e2f2c817fb 100644 --- a/app/src/main/res/layout/chapters_controller.xml +++ b/app/src/main/res/layout/chapters_controller.xml @@ -50,10 +50,11 @@ android:layout_height="wrap_content" android:layout_gravity="bottom" /> - + app:icon="@drawable/ic_play_arrow_24dp" />