forked from GitHub-Mirror/riotX-android
Hide FAB when list is scrolling
This commit is contained in:
parent
6978ec4246
commit
e959fe2e9d
@ -21,7 +21,9 @@ import android.os.Parcelable
|
|||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.airbnb.mvrx.*
|
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.failure.Failure
|
||||||
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
||||||
import im.vector.riotredesign.R
|
import im.vector.riotredesign.R
|
||||||
@ -41,6 +43,8 @@ data class RoomListParams(
|
|||||||
|
|
||||||
class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Callback {
|
class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Callback {
|
||||||
|
|
||||||
|
lateinit var fabButton: FloatingActionButton
|
||||||
|
|
||||||
enum class DisplayMode(@StringRes val titleRes: Int) {
|
enum class DisplayMode(@StringRes val titleRes: Int) {
|
||||||
HOME(R.string.bottom_action_home),
|
HOME(R.string.bottom_action_home),
|
||||||
PEOPLE(R.string.bottom_action_people),
|
PEOPLE(R.string.bottom_action_people),
|
||||||
@ -63,8 +67,8 @@ class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Callback {
|
|||||||
|
|
||||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
super.onActivityCreated(savedInstanceState)
|
super.onActivityCreated(savedInstanceState)
|
||||||
setupRecyclerView()
|
|
||||||
setupCreateRoomButton()
|
setupCreateRoomButton()
|
||||||
|
setupRecyclerView()
|
||||||
roomListViewModel.subscribe { renderState(it) }
|
roomListViewModel.subscribe { renderState(it) }
|
||||||
roomListViewModel.openRoomLiveData.observeEvent(this) {
|
roomListViewModel.openRoomLiveData.observeEvent(this) {
|
||||||
navigator.openRoom(it)
|
navigator.openRoom(it)
|
||||||
@ -72,14 +76,20 @@ class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupCreateRoomButton() {
|
private fun setupCreateRoomButton() {
|
||||||
createRoomButton.isVisible = roomListParams.displayMode == DisplayMode.HOME
|
fabButton = when (roomListParams.displayMode) {
|
||||||
createChatRoomButton.isVisible = roomListParams.displayMode == DisplayMode.PEOPLE
|
DisplayMode.HOME -> createRoomButton
|
||||||
createGroupRoomButton.isVisible = roomListParams.displayMode == DisplayMode.ROOMS
|
DisplayMode.PEOPLE -> createChatRoomButton
|
||||||
|
else -> createGroupRoomButton
|
||||||
|
}
|
||||||
|
|
||||||
|
fabButton.isVisible = true
|
||||||
|
|
||||||
createRoomButton.setOnClickListener {
|
createRoomButton.setOnClickListener {
|
||||||
|
// TODO Is it the expected action?
|
||||||
navigator.openRoomDirectory()
|
navigator.openRoomDirectory()
|
||||||
}
|
}
|
||||||
createChatRoomButton.setOnClickListener {
|
createChatRoomButton.setOnClickListener {
|
||||||
|
// TODO Is it the expected action?
|
||||||
navigator.openRoomDirectory()
|
navigator.openRoomDirectory()
|
||||||
}
|
}
|
||||||
createGroupRoomButton.setOnClickListener {
|
createGroupRoomButton.setOnClickListener {
|
||||||
@ -96,6 +106,26 @@ class RoomListFragment : VectorBaseFragment(), RoomSummaryController.Callback {
|
|||||||
roomController.addModelBuildListener { it.dispatchTo(stateRestorer) }
|
roomController.addModelBuildListener { it.dispatchTo(stateRestorer) }
|
||||||
stateView.contentView = epoxyRecyclerView
|
stateView.contentView = epoxyRecyclerView
|
||||||
epoxyRecyclerView.setController(roomController)
|
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) {
|
private fun renderState(state: RoomListViewState) {
|
||||||
|
11
vector/src/main/res/drawable/red_dot.xml
Normal file
11
vector/src/main/res/drawable/red_dot.xml
Normal 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>
|
@ -60,6 +60,7 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="48dp"
|
android:layout_height="48dp"
|
||||||
android:background="#FFFFFF"
|
android:background="#FFFFFF"
|
||||||
|
app:itemIconSize="20dp"
|
||||||
app:itemIconTint="@color/home_bottom_nav_view_tint"
|
app:itemIconTint="@color/home_bottom_nav_view_tint"
|
||||||
app:itemTextColor="@color/home_bottom_nav_view_tint"
|
app:itemTextColor="@color/home_bottom_nav_view_tint"
|
||||||
app:labelVisibilityMode="unlabeled"
|
app:labelVisibilityMode="unlabeled"
|
||||||
|
@ -22,7 +22,9 @@
|
|||||||
android:layout_gravity="bottom|end"
|
android:layout_gravity="bottom|end"
|
||||||
android:layout_margin="16dp"
|
android:layout_margin="16dp"
|
||||||
android:src="@drawable/ic_fab_add"
|
android:src="@drawable/ic_fab_add"
|
||||||
app:maxImageSize="14dp" />
|
android:visibility="gone"
|
||||||
|
app:maxImageSize="14dp"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
android:id="@+id/createChatRoomButton"
|
android:id="@+id/createChatRoomButton"
|
||||||
@ -32,8 +34,10 @@
|
|||||||
android:layout_margin="16dp"
|
android:layout_margin="16dp"
|
||||||
android:scaleType="center"
|
android:scaleType="center"
|
||||||
android:src="@drawable/ic_fab_add_chat"
|
android:src="@drawable/ic_fab_add_chat"
|
||||||
|
android:visibility="gone"
|
||||||
app:maxImageSize="34dp"
|
app:maxImageSize="34dp"
|
||||||
tools:layout_margin="66dp" />
|
tools:layout_margin="66dp"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
android:id="@+id/createGroupRoomButton"
|
android:id="@+id/createGroupRoomButton"
|
||||||
@ -43,7 +47,9 @@
|
|||||||
android:layout_margin="16dp"
|
android:layout_margin="16dp"
|
||||||
android:scaleType="center"
|
android:scaleType="center"
|
||||||
android:src="@drawable/ic_fab_add_room"
|
android:src="@drawable/ic_fab_add_room"
|
||||||
|
android:visibility="gone"
|
||||||
app:maxImageSize="32dp"
|
app:maxImageSize="32dp"
|
||||||
tools:layout_margin="116dp" />
|
tools:layout_margin="116dp"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
</im.vector.riotredesign.core.platform.StateView>
|
</im.vector.riotredesign.core.platform.StateView>
|
||||||
|
Loading…
Reference in New Issue
Block a user