Adds click handling of invites

This commit is contained in:
ericdecanini 2022-05-11 09:45:11 +02:00
parent c72ba8d651
commit a6564b6466
6 changed files with 19 additions and 4 deletions

View File

@ -28,6 +28,7 @@ import org.matrix.android.sdk.api.util.toMatrixItem
class InvitesAdapter(
private val avatarRenderer: AvatarRenderer,
private val inviteUserTask: ((String) -> String?)?,
private val onInviteClicked: ((RoomSummary) -> Unit)?,
) : RecyclerView.Adapter<InvitesAdapter.ViewHolder>() {
private val invites = mutableListOf<RoomSummary>()
@ -55,6 +56,8 @@ class InvitesAdapter(
fun bind(invite: RoomSummary) {
avatarRenderer.render(invite.toMatrixItem(), binding.avatar)
binding.name.text = invite.name
binding.root.setOnClickListener { onInviteClicked?.invoke(invite) }
invite.inviterId?.let {
val inviterName = inviteUserTask?.invoke(it)
if (inviterName != null) {

View File

@ -28,7 +28,8 @@ import org.matrix.android.sdk.api.session.room.model.RoomSummary
class InvitesBottomSheet(
private val invites: List<RoomSummary>,
private val avatarRenderer: AvatarRenderer,
private val inviteUserTask: ((String) -> String?)?
private val inviteUserTask: ((String) -> String?)?,
private val onInviteClicked: ((RoomSummary) -> Unit)?
) : BottomSheetDialogFragment() {
private lateinit var binding: BottomSheetInvitesBinding
@ -48,7 +49,10 @@ class InvitesBottomSheet(
}
private fun setupInvitesList() {
val adapter = InvitesAdapter(avatarRenderer, inviteUserTask)
val adapter = InvitesAdapter(avatarRenderer, inviteUserTask) {
dismiss()
onInviteClicked?.invoke(it)
}
val layoutManager = LinearLayoutManager(context)
binding.invitesList.adapter = adapter
binding.invitesList.layoutManager = layoutManager

View File

@ -88,7 +88,9 @@ class SpaceListModalFragment : VectorBaseFragment<FragmentSpaceListModalBinding>
binding.invitesGroup.referencedIds.map { binding.root.findViewById<View>(it) }.forEach {
it.setOnClickListener {
withState(viewModel) { state ->
val invitesBottomSheet = InvitesBottomSheet(state.inviteSpaces.orEmpty(), avatarRenderer, state.inviteUserTask)
val invitesBottomSheet = InvitesBottomSheet(state.inviteSpaces.orEmpty(), avatarRenderer, state.inviteUserTask) { invite ->
sharedActionViewModel.post(HomeActivitySharedAction.OpenSpaceInvite(invite.roomId))
}
invitesBottomSheet.show(requireActivity().supportFragmentManager, InvitesBottomSheet.TAG)
}
}

View File

@ -332,6 +332,9 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa
val rootSpaces = asyncSpaceList?.invoke().orEmpty().filter { it.flattenParentIds.isEmpty() }
val displaySpaces = (currentSpaceChildren ?: rootSpaces).filter { it.inviterId == null }
val inviteSpaces = (currentSpaceChildren ?: rootSpaces).filter { it.inviterId != null }
val inviteUserTask: (String) -> String? = {
session.getUser(it)?.displayName
}
val orders = displaySpaces.associate {
it.roomId to session.getRoom(it.roomId)
?.roomAccountDataService()
@ -345,6 +348,7 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa
rootSpacesOrdered = displaySpaces.sortedWith(TopLevelSpaceComparator(orders)),
inviteSpaces = inviteSpaces.sortedWith(TopLevelSpaceComparator(orders)),
inviteCount = inviteSpaces.size,
inviteUserTask = inviteUserTask,
spaceOrderInfo = orders
)
}

View File

@ -21,9 +21,10 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/invites_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@id/invites_header"
app:layout_constraintBottom_toBottomOf="parent"
tools:listitem="@layout/list_item_invite"
tools:itemCount="3"/>

View File

@ -4,6 +4,7 @@
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:background="@drawable/ripple_grey"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">