From a6564b646631d2154d902946a04375d1d4a0b968 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Wed, 11 May 2022 09:45:11 +0200 Subject: [PATCH] Adds click handling of invites --- .../java/im/vector/app/features/home/InvitesAdapter.kt | 3 +++ .../im/vector/app/features/home/InvitesBottomSheet.kt | 8 ++++++-- .../im/vector/app/features/home/SpaceListModalFragment.kt | 4 +++- .../im/vector/app/features/spaces/SpaceListViewModel.kt | 4 ++++ vector/src/main/res/layout/bottom_sheet_invites.xml | 3 ++- vector/src/main/res/layout/list_item_invite.xml | 1 + 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/InvitesAdapter.kt b/vector/src/main/java/im/vector/app/features/home/InvitesAdapter.kt index 3aeadeb3c6..24f15f0ece 100644 --- a/vector/src/main/java/im/vector/app/features/home/InvitesAdapter.kt +++ b/vector/src/main/java/im/vector/app/features/home/InvitesAdapter.kt @@ -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() { private val invites = mutableListOf() @@ -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) { diff --git a/vector/src/main/java/im/vector/app/features/home/InvitesBottomSheet.kt b/vector/src/main/java/im/vector/app/features/home/InvitesBottomSheet.kt index ff28a3bc4e..6fcfd0ad51 100644 --- a/vector/src/main/java/im/vector/app/features/home/InvitesBottomSheet.kt +++ b/vector/src/main/java/im/vector/app/features/home/InvitesBottomSheet.kt @@ -28,7 +28,8 @@ import org.matrix.android.sdk.api.session.room.model.RoomSummary class InvitesBottomSheet( private val invites: List, 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 diff --git a/vector/src/main/java/im/vector/app/features/home/SpaceListModalFragment.kt b/vector/src/main/java/im/vector/app/features/home/SpaceListModalFragment.kt index 291e3936d6..bf05452273 100644 --- a/vector/src/main/java/im/vector/app/features/home/SpaceListModalFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/SpaceListModalFragment.kt @@ -88,7 +88,9 @@ class SpaceListModalFragment : VectorBaseFragment binding.invitesGroup.referencedIds.map { binding.root.findViewById(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) } } diff --git a/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt index 1f6945a749..57068743e8 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt @@ -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 ) } diff --git a/vector/src/main/res/layout/bottom_sheet_invites.xml b/vector/src/main/res/layout/bottom_sheet_invites.xml index 3b6078c967..1ff8a7232d 100644 --- a/vector/src/main/res/layout/bottom_sheet_invites.xml +++ b/vector/src/main/res/layout/bottom_sheet_invites.xml @@ -21,9 +21,10 @@ diff --git a/vector/src/main/res/layout/list_item_invite.xml b/vector/src/main/res/layout/list_item_invite.xml index 4a867893e2..16672f9dbd 100644 --- a/vector/src/main/res/layout/list_item_invite.xml +++ b/vector/src/main/res/layout/list_item_invite.xml @@ -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">