home: make fab hide when fast scrolling

Hide the FAB when fast scrolling. This is just a UX enhancement.
This commit is contained in:
OxygenCobalt 2021-10-24 11:03:24 -06:00
parent 71480d0299
commit 3107464dd2
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
5 changed files with 33 additions and 4 deletions

View file

@ -205,6 +205,17 @@ class HomeFragment : Fragment() {
// --- VIEWMODEL SETUP ---
// There is no way a fast scrolling event can continue across a re-create. Reset it.
homeModel.updateFastScrolling(false)
homeModel.fastScrolling.observe(viewLifecycleOwner) { scrolling ->
if (scrolling) {
binding.homeFab.hide()
} else {
binding.homeFab.show()
}
}
homeModel.recreateTabs.observe(viewLifecycleOwner) { recreate ->
// notifyDataSetChanged is not practical for recreating here since it will cache
// the previous fragments. Just instantiate a whole new adapter.

View file

@ -61,6 +61,9 @@ class HomeViewModel : ViewModel(), SettingsManager.Callback {
private val mCurTab = MutableLiveData(tabs[0])
val curTab: LiveData<DisplayMode> = mCurTab
private val mFastScrolling = MutableLiveData(false)
val fastScrolling: LiveData<Boolean> = mFastScrolling
/**
* Marker to recreate all library tabs, usually initiated by a settings change.
* When this flag is set, all tabs (and their respective viewpager fragments) will be
@ -123,6 +126,14 @@ class HomeViewModel : ViewModel(), SettingsManager.Callback {
}
}
/**
* Update the fast scroll state. This is used to control the FAB visibility whenever
* the user begins to fast scroll.
*/
fun updateFastScrolling(scrolling: Boolean) {
mFastScrolling.value = scrolling
}
// --- OVERRIDES ---
override fun onLibTabsUpdate(libTabs: Array<Tab>) {

View file

@ -62,6 +62,7 @@ import kotlin.math.abs
* - Track view is now only used for touch bounds
* - Redundant functions have been merged
* - Variable names are no longer prefixed with m
* - Added drag listener
* - TODO: Added documentation
* - TODO: Popup will center itself to the thumb when possible
*
@ -72,7 +73,8 @@ class FastScrollRecyclerView @JvmOverloads constructor(
attrs: AttributeSet? = null,
defStyleAttr: Int = -1
) : RecyclerView(context, attrs, defStyleAttr) {
private var popupProvider: ((Int) -> String)? = null
var popupProvider: ((Int) -> String)? = null
var onDragListener: ((Boolean) -> Unit)? = null
private val minTouchTargetSize: Int = resources.getDimensionPixelSize(R.dimen.size_btn_small)
private val touchSlop: Int = ViewConfiguration.get(context).scaledTouchSlop
@ -191,7 +193,7 @@ class FastScrollRecyclerView @JvmOverloads constructor(
})
}
fun setup(provider: (Int) -> String) {
fun addPopupProvider(provider: (Int) -> String) {
popupProvider = provider
}
@ -496,6 +498,7 @@ class FastScrollRecyclerView @JvmOverloads constructor(
}
this.dragging = dragging
if (this.dragging) {
parent.requestDisallowInterceptTouchEvent(true)
}
@ -511,6 +514,8 @@ class FastScrollRecyclerView @JvmOverloads constructor(
postAutoHideScrollbar()
hidePopup()
}
onDragListener?.invoke(dragging)
}
// --- SCROLLBAR APPEARANCE ---

View file

@ -51,7 +51,10 @@ abstract class HomeListFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.homeRecycler.setup(popupProvider)
binding.homeRecycler.popupProvider = popupProvider
binding.homeRecycler.onDragListener = { dragging ->
homeModel.updateFastScrolling(dragging)
}
}
protected fun <T : BaseModel, VH : RecyclerView.ViewHolder> setupRecycler(

View file

@ -8,7 +8,6 @@
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical">
<org.oxycblt.auxio.ui.LiftAppBarLayout