Add text to chapter FAB, shrink extended FABs on scroll

This commit is contained in:
arkon 2020-04-10 15:39:28 -04:00
parent f7ac969a4a
commit aa70be525d
4 changed files with 27 additions and 3 deletions

View File

@ -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)

View File

@ -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<ChaptersPresenter>(),
view.context.toast(R.string.no_next_chapter)
}
}
binding.fab.shrinkOnScroll(binding.recycler)
}
override fun onDestroyView(view: View) {

View File

@ -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()
}
})
}

View File

@ -50,10 +50,11 @@
android:layout_height="wrap_content"
android:layout_gravity="bottom" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/fab"
style="@style/Theme.Widget.FAB"
android:text="@string/action_resume"
app:layout_anchor="@id/recycler"
app:srcCompat="@drawable/ic_play_arrow_24dp" />
app:icon="@drawable/ic_play_arrow_24dp" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>