home: make fab hide when fast scrolling
Hide the FAB when fast scrolling. This is just a UX enhancement.
This commit is contained in:
parent
71480d0299
commit
3107464dd2
5 changed files with 33 additions and 4 deletions
|
@ -205,6 +205,17 @@ class HomeFragment : Fragment() {
|
||||||
|
|
||||||
// --- VIEWMODEL SETUP ---
|
// --- 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 ->
|
homeModel.recreateTabs.observe(viewLifecycleOwner) { recreate ->
|
||||||
// notifyDataSetChanged is not practical for recreating here since it will cache
|
// notifyDataSetChanged is not practical for recreating here since it will cache
|
||||||
// the previous fragments. Just instantiate a whole new adapter.
|
// the previous fragments. Just instantiate a whole new adapter.
|
||||||
|
|
|
@ -61,6 +61,9 @@ class HomeViewModel : ViewModel(), SettingsManager.Callback {
|
||||||
private val mCurTab = MutableLiveData(tabs[0])
|
private val mCurTab = MutableLiveData(tabs[0])
|
||||||
val curTab: LiveData<DisplayMode> = mCurTab
|
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.
|
* 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
|
* 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 ---
|
// --- OVERRIDES ---
|
||||||
|
|
||||||
override fun onLibTabsUpdate(libTabs: Array<Tab>) {
|
override fun onLibTabsUpdate(libTabs: Array<Tab>) {
|
||||||
|
|
|
@ -62,6 +62,7 @@ import kotlin.math.abs
|
||||||
* - Track view is now only used for touch bounds
|
* - Track view is now only used for touch bounds
|
||||||
* - Redundant functions have been merged
|
* - Redundant functions have been merged
|
||||||
* - Variable names are no longer prefixed with m
|
* - Variable names are no longer prefixed with m
|
||||||
|
* - Added drag listener
|
||||||
* - TODO: Added documentation
|
* - TODO: Added documentation
|
||||||
* - TODO: Popup will center itself to the thumb when possible
|
* - TODO: Popup will center itself to the thumb when possible
|
||||||
*
|
*
|
||||||
|
@ -72,7 +73,8 @@ class FastScrollRecyclerView @JvmOverloads constructor(
|
||||||
attrs: AttributeSet? = null,
|
attrs: AttributeSet? = null,
|
||||||
defStyleAttr: Int = -1
|
defStyleAttr: Int = -1
|
||||||
) : RecyclerView(context, attrs, defStyleAttr) {
|
) : 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 minTouchTargetSize: Int = resources.getDimensionPixelSize(R.dimen.size_btn_small)
|
||||||
private val touchSlop: Int = ViewConfiguration.get(context).scaledTouchSlop
|
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
|
popupProvider = provider
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,6 +498,7 @@ class FastScrollRecyclerView @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
this.dragging = dragging
|
this.dragging = dragging
|
||||||
|
|
||||||
if (this.dragging) {
|
if (this.dragging) {
|
||||||
parent.requestDisallowInterceptTouchEvent(true)
|
parent.requestDisallowInterceptTouchEvent(true)
|
||||||
}
|
}
|
||||||
|
@ -511,6 +514,8 @@ class FastScrollRecyclerView @JvmOverloads constructor(
|
||||||
postAutoHideScrollbar()
|
postAutoHideScrollbar()
|
||||||
hidePopup()
|
hidePopup()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onDragListener?.invoke(dragging)
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- SCROLLBAR APPEARANCE ---
|
// --- SCROLLBAR APPEARANCE ---
|
||||||
|
|
|
@ -51,7 +51,10 @@ abstract class HomeListFragment : Fragment() {
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
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(
|
protected fun <T : BaseModel, VH : RecyclerView.ViewHolder> setupRecycler(
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
android:id="@+id/main_layout"
|
android:id="@+id/main_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:animateLayoutChanges="true"
|
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<org.oxycblt.auxio.ui.LiftAppBarLayout
|
<org.oxycblt.auxio.ui.LiftAppBarLayout
|
||||||
|
|
Loading…
Reference in a new issue