mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 20:06:51 +03:00
Add SearchView to filter members.
Author: Onuray (I squashed 2 commits)
This commit is contained in:
parent
f030e098a8
commit
85417eb24c
7 changed files with 61 additions and 2 deletions
|
@ -11,6 +11,7 @@ Improvements 🙌:
|
|||
- Small optimisation of scrolling experience in timeline (#2114)
|
||||
- Allow user to reset cross signing if he has no way to recover (#2052)
|
||||
- Create home shortcut for any room (#1525)
|
||||
- Filter room member by name (#2184)
|
||||
|
||||
Bugfix 🐛:
|
||||
- Improve support for image/audio/video/file selection with intent changes (#1376)
|
||||
|
|
|
@ -20,4 +20,5 @@ import im.vector.app.core.platform.VectorViewModelAction
|
|||
|
||||
sealed class RoomMemberListAction : VectorViewModelAction {
|
||||
data class RevokeThreePidInvite(val stateKey: String) : RoomMemberListAction()
|
||||
data class FilterMemberList(val searchTerm: String) : RoomMemberListAction()
|
||||
}
|
||||
|
|
|
@ -53,7 +53,9 @@ class RoomMemberListController @Inject constructor(
|
|||
}
|
||||
|
||||
override fun buildModels(data: RoomMemberListViewState?) {
|
||||
val roomMembersByPowerLevel = data?.roomMemberSummaries?.invoke() ?: return
|
||||
data ?: return
|
||||
|
||||
val roomMembersByPowerLevel = data.filteredRoomMemberSummaries ?: data.roomMemberSummaries.invoke() ?: return
|
||||
val threePidInvites = data.threePidInvites().orEmpty()
|
||||
var threePidInvitesDone = threePidInvites.isEmpty()
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ import android.view.Menu
|
|||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.core.view.isVisible
|
||||
import com.airbnb.mvrx.args
|
||||
import com.airbnb.mvrx.fragmentViewModel
|
||||
import com.airbnb.mvrx.withState
|
||||
|
@ -72,12 +74,27 @@ class RoomMemberListFragment @Inject constructor(
|
|||
super.onViewCreated(view, savedInstanceState)
|
||||
roomMemberListController.callback = this
|
||||
setupToolbar(roomSettingsToolbar)
|
||||
setupSearchView()
|
||||
recyclerView.configureWith(roomMemberListController, hasFixedSize = true)
|
||||
viewModel.selectSubscribe(this, RoomMemberListViewState::actionsPermissions) {
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupSearchView() {
|
||||
searchView.isVisible = true
|
||||
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||
override fun onQueryTextSubmit(query: String): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onQueryTextChange(newText: String): Boolean {
|
||||
viewModel.handle(RoomMemberListAction.FilterMemberList(newText))
|
||||
return true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
recyclerView.cleanup()
|
||||
super.onDestroyView()
|
||||
|
|
|
@ -188,6 +188,7 @@ class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState
|
|||
override fun handle(action: RoomMemberListAction) {
|
||||
when (action) {
|
||||
is RoomMemberListAction.RevokeThreePidInvite -> handleRevokeThreePidInvite(action)
|
||||
is RoomMemberListAction.FilterMemberList -> handleFilterMemberList(action)
|
||||
}.exhaustive
|
||||
}
|
||||
|
||||
|
@ -201,4 +202,28 @@ class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleFilterMemberList(action: RoomMemberListAction.FilterMemberList) = withState { state ->
|
||||
if (action.searchTerm.isBlank()) {
|
||||
setState { copy(filteredRoomMemberSummaries = null) }
|
||||
return@withState
|
||||
}
|
||||
val roomMemberSummaries = state.roomMemberSummaries.invoke()
|
||||
roomMemberSummaries
|
||||
?.mapNotNull { (powerLevelCategory, roomMemberList) ->
|
||||
roomMemberList
|
||||
.filter { it.displayName?.contains(action.searchTerm).orFalse() || it.userId.contains(action.searchTerm) }
|
||||
.takeIf { it.isNotEmpty() }
|
||||
?.let { filteredMemberList ->
|
||||
Pair(powerLevelCategory, filteredMemberList)
|
||||
}
|
||||
}
|
||||
?.also { filteredRoomMemberSummaries ->
|
||||
setState {
|
||||
copy(
|
||||
filteredRoomMemberSummaries = filteredRoomMemberSummaries
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ data class RoomMemberListViewState(
|
|||
val roomId: String,
|
||||
val roomSummary: Async<RoomSummary> = Uninitialized,
|
||||
val roomMemberSummaries: Async<RoomMemberSummaries> = Uninitialized,
|
||||
val filteredRoomMemberSummaries: RoomMemberSummaries? = null,
|
||||
val threePidInvites: Async<List<Event>> = Uninitialized,
|
||||
val trustLevelMap: Async<Map<String, RoomEncryptionTrustLevel?>> = Uninitialized,
|
||||
val actionsPermissions: ActionPermissions = ActionPermissions()
|
||||
|
|
|
@ -53,6 +53,18 @@
|
|||
|
||||
</androidx.appcompat.widget.Toolbar>
|
||||
|
||||
<androidx.appcompat.widget.SearchView
|
||||
android:id="@+id/searchView"
|
||||
style="@style/VectorSearchView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
app:queryHint="@string/search_hint"
|
||||
app:layout_constraintTop_toBottomOf="@id/roomSettingsToolbar"
|
||||
android:background="@null" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="0dp"
|
||||
|
@ -61,7 +73,7 @@
|
|||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/roomSettingsToolbar"
|
||||
app:layout_constraintTop_toBottomOf="@+id/searchView"
|
||||
tools:listitem="@layout/item_profile_action" />
|
||||
|
||||
<include layout="@layout/merge_overlay_waiting_view" />
|
||||
|
|
Loading…
Reference in a new issue