Adds click handling of invites
This commit is contained in:
parent
c72ba8d651
commit
a6564b6466
|
@ -28,6 +28,7 @@ import org.matrix.android.sdk.api.util.toMatrixItem
|
||||||
class InvitesAdapter(
|
class InvitesAdapter(
|
||||||
private val avatarRenderer: AvatarRenderer,
|
private val avatarRenderer: AvatarRenderer,
|
||||||
private val inviteUserTask: ((String) -> String?)?,
|
private val inviteUserTask: ((String) -> String?)?,
|
||||||
|
private val onInviteClicked: ((RoomSummary) -> Unit)?,
|
||||||
) : RecyclerView.Adapter<InvitesAdapter.ViewHolder>() {
|
) : RecyclerView.Adapter<InvitesAdapter.ViewHolder>() {
|
||||||
|
|
||||||
private val invites = mutableListOf<RoomSummary>()
|
private val invites = mutableListOf<RoomSummary>()
|
||||||
|
@ -55,6 +56,8 @@ class InvitesAdapter(
|
||||||
fun bind(invite: RoomSummary) {
|
fun bind(invite: RoomSummary) {
|
||||||
avatarRenderer.render(invite.toMatrixItem(), binding.avatar)
|
avatarRenderer.render(invite.toMatrixItem(), binding.avatar)
|
||||||
binding.name.text = invite.name
|
binding.name.text = invite.name
|
||||||
|
binding.root.setOnClickListener { onInviteClicked?.invoke(invite) }
|
||||||
|
|
||||||
invite.inviterId?.let {
|
invite.inviterId?.let {
|
||||||
val inviterName = inviteUserTask?.invoke(it)
|
val inviterName = inviteUserTask?.invoke(it)
|
||||||
if (inviterName != null) {
|
if (inviterName != null) {
|
||||||
|
|
|
@ -28,7 +28,8 @@ import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||||
class InvitesBottomSheet(
|
class InvitesBottomSheet(
|
||||||
private val invites: List<RoomSummary>,
|
private val invites: List<RoomSummary>,
|
||||||
private val avatarRenderer: AvatarRenderer,
|
private val avatarRenderer: AvatarRenderer,
|
||||||
private val inviteUserTask: ((String) -> String?)?
|
private val inviteUserTask: ((String) -> String?)?,
|
||||||
|
private val onInviteClicked: ((RoomSummary) -> Unit)?
|
||||||
) : BottomSheetDialogFragment() {
|
) : BottomSheetDialogFragment() {
|
||||||
|
|
||||||
private lateinit var binding: BottomSheetInvitesBinding
|
private lateinit var binding: BottomSheetInvitesBinding
|
||||||
|
@ -48,7 +49,10 @@ class InvitesBottomSheet(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupInvitesList() {
|
private fun setupInvitesList() {
|
||||||
val adapter = InvitesAdapter(avatarRenderer, inviteUserTask)
|
val adapter = InvitesAdapter(avatarRenderer, inviteUserTask) {
|
||||||
|
dismiss()
|
||||||
|
onInviteClicked?.invoke(it)
|
||||||
|
}
|
||||||
val layoutManager = LinearLayoutManager(context)
|
val layoutManager = LinearLayoutManager(context)
|
||||||
binding.invitesList.adapter = adapter
|
binding.invitesList.adapter = adapter
|
||||||
binding.invitesList.layoutManager = layoutManager
|
binding.invitesList.layoutManager = layoutManager
|
||||||
|
|
|
@ -88,7 +88,9 @@ class SpaceListModalFragment : VectorBaseFragment<FragmentSpaceListModalBinding>
|
||||||
binding.invitesGroup.referencedIds.map { binding.root.findViewById<View>(it) }.forEach {
|
binding.invitesGroup.referencedIds.map { binding.root.findViewById<View>(it) }.forEach {
|
||||||
it.setOnClickListener {
|
it.setOnClickListener {
|
||||||
withState(viewModel) { state ->
|
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)
|
invitesBottomSheet.show(requireActivity().supportFragmentManager, InvitesBottomSheet.TAG)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -332,6 +332,9 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa
|
||||||
val rootSpaces = asyncSpaceList?.invoke().orEmpty().filter { it.flattenParentIds.isEmpty() }
|
val rootSpaces = asyncSpaceList?.invoke().orEmpty().filter { it.flattenParentIds.isEmpty() }
|
||||||
val displaySpaces = (currentSpaceChildren ?: rootSpaces).filter { it.inviterId == null }
|
val displaySpaces = (currentSpaceChildren ?: rootSpaces).filter { it.inviterId == null }
|
||||||
val inviteSpaces = (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 {
|
val orders = displaySpaces.associate {
|
||||||
it.roomId to session.getRoom(it.roomId)
|
it.roomId to session.getRoom(it.roomId)
|
||||||
?.roomAccountDataService()
|
?.roomAccountDataService()
|
||||||
|
@ -345,6 +348,7 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa
|
||||||
rootSpacesOrdered = displaySpaces.sortedWith(TopLevelSpaceComparator(orders)),
|
rootSpacesOrdered = displaySpaces.sortedWith(TopLevelSpaceComparator(orders)),
|
||||||
inviteSpaces = inviteSpaces.sortedWith(TopLevelSpaceComparator(orders)),
|
inviteSpaces = inviteSpaces.sortedWith(TopLevelSpaceComparator(orders)),
|
||||||
inviteCount = inviteSpaces.size,
|
inviteCount = inviteSpaces.size,
|
||||||
|
inviteUserTask = inviteUserTask,
|
||||||
spaceOrderInfo = orders
|
spaceOrderInfo = orders
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,10 @@
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/invites_list"
|
android:id="@+id/invites_list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="0dp"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
app:layout_constraintTop_toBottomOf="@id/invites_header"
|
app:layout_constraintTop_toBottomOf="@id/invites_header"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
tools:listitem="@layout/list_item_invite"
|
tools:listitem="@layout/list_item_invite"
|
||||||
tools:itemCount="3"/>
|
tools:itemCount="3"/>
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingTop="8dp"
|
android:paddingTop="8dp"
|
||||||
android:paddingBottom="8dp"
|
android:paddingBottom="8dp"
|
||||||
|
android:background="@drawable/ripple_grey"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue