Hide FAB when list is scrolling

This commit is contained in:
Benoit Marty 2019-05-29 14:50:55 +02:00
parent 6978ec4246
commit e959fe2e9d
4 changed files with 55 additions and 7 deletions

View File

@ -21,7 +21,9 @@ import android.os.Parcelable
import androidx.annotation.StringRes
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.airbnb.mvrx.*
import com.google.android.material.floatingactionbutton.FloatingActionButton
import im.vector.matrix.android.api.failure.Failure
import im.vector.matrix.android.api.session.room.model.RoomSummary
import im.vector.riotredesign.R
@ -41,6 +43,8 @@ data class RoomListParams(
class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Callback {
lateinit var fabButton: FloatingActionButton
enum class DisplayMode(@StringRes val titleRes: Int) {
HOME(R.string.bottom_action_home),
PEOPLE(R.string.bottom_action_people),
@ -63,8 +67,8 @@ class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Callback {
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
setupRecyclerView()
setupCreateRoomButton()
setupRecyclerView()
roomListViewModel.subscribe { renderState(it) }
roomListViewModel.openRoomLiveData.observeEvent(this) {
navigator.openRoom(it)
@ -72,14 +76,20 @@ class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Callback {
}
private fun setupCreateRoomButton() {
createRoomButton.isVisible = roomListParams.displayMode == DisplayMode.HOME
createChatRoomButton.isVisible = roomListParams.displayMode == DisplayMode.PEOPLE
createGroupRoomButton.isVisible = roomListParams.displayMode == DisplayMode.ROOMS
fabButton = when (roomListParams.displayMode) {
DisplayMode.HOME -> createRoomButton
DisplayMode.PEOPLE -> createChatRoomButton
else -> createGroupRoomButton
}
fabButton.isVisible = true
createRoomButton.setOnClickListener {
// TODO Is it the expected action?
navigator.openRoomDirectory()
}
createChatRoomButton.setOnClickListener {
// TODO Is it the expected action?
navigator.openRoomDirectory()
}
createGroupRoomButton.setOnClickListener {
@ -96,6 +106,26 @@ class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Callback {
roomController.addModelBuildListener { it.dispatchTo(stateRestorer) }
stateView.contentView = epoxyRecyclerView
epoxyRecyclerView.setController(roomController)
// Hide FAB when list is scrolling
epoxyRecyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
fabButton.removeCallbacks(showFabRunnable)
when (newState) {
RecyclerView.SCROLL_STATE_IDLE -> {
fabButton.postDelayed(showFabRunnable, 1000)
}
RecyclerView.SCROLL_STATE_DRAGGING,
RecyclerView.SCROLL_STATE_SETTLING -> {
fabButton.hide()
}
}
}
})
}
private val showFabRunnable = Runnable {
fabButton.show()
}
private fun renderState(state: RoomListViewState) {

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:width="8dp"
android:height="8dp" />
<solid android:color="#FF4B55" />
</shape>

View File

@ -60,6 +60,7 @@
android:layout_width="0dp"
android:layout_height="48dp"
android:background="#FFFFFF"
app:itemIconSize="20dp"
app:itemIconTint="@color/home_bottom_nav_view_tint"
app:itemTextColor="@color/home_bottom_nav_view_tint"
app:labelVisibilityMode="unlabeled"

View File

@ -22,7 +22,9 @@
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:src="@drawable/ic_fab_add"
app:maxImageSize="14dp" />
android:visibility="gone"
app:maxImageSize="14dp"
tools:visibility="visible" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/createChatRoomButton"
@ -32,8 +34,10 @@
android:layout_margin="16dp"
android:scaleType="center"
android:src="@drawable/ic_fab_add_chat"
android:visibility="gone"
app:maxImageSize="34dp"
tools:layout_margin="66dp" />
tools:layout_margin="66dp"
tools:visibility="visible" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/createGroupRoomButton"
@ -43,7 +47,9 @@
android:layout_margin="16dp"
android:scaleType="center"
android:src="@drawable/ic_fab_add_room"
android:visibility="gone"
app:maxImageSize="32dp"
tools:layout_margin="116dp" />
tools:layout_margin="116dp"
tools:visibility="visible" />
</im.vector.riotredesign.core.platform.StateView>