From 01e3e71f98526b612097cd5af0f58f020758d183 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 1 Jul 2019 17:26:24 +0200 Subject: [PATCH] Handle room invitation actions --- .../session/room/members/MembershipService.kt | 7 +- .../home/room/list/RoomInvitationItem.kt | 51 +++++++++-- .../home/room/list/RoomListActions.kt | 4 + .../home/room/list/RoomListFragment.kt | 15 +++- .../home/room/list/RoomListViewModel.kt | 86 ++++++++++++++++++- .../home/room/list/RoomListViewState.kt | 8 ++ .../home/room/list/RoomSummaryController.kt | 14 ++- .../home/room/list/RoomSummaryItemFactory.kt | 21 ++++- .../roomdirectory/PublicRoomsViewState.kt | 12 +-- .../roomdirectory/RoomDirectoryViewModel.kt | 86 +++++++++---------- vector/src/main/res/layout/activity_home.xml | 2 +- .../main/res/layout/item_room_invitation.xml | 24 ++++-- 12 files changed, 248 insertions(+), 82 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/members/MembershipService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/members/MembershipService.kt index ad9264675a..ca3b99b6bf 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/members/MembershipService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/members/MembershipService.kt @@ -47,7 +47,7 @@ interface MembershipService { */ fun getRoomMemberIdsLive(): LiveData> - fun getNumberOfJoinedMembers() : Int + fun getNumberOfJoinedMembers(): Int /** * Invite a user in the room @@ -55,13 +55,12 @@ interface MembershipService { fun invite(userId: String, callback: MatrixCallback) /** - * Join the room + * Join the room, or accept an invitation. */ fun join(callback: MatrixCallback) /** - * Leave the room. - * + * Leave the room, or reject an invitation. */ fun leave(callback: MatrixCallback) diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/list/RoomInvitationItem.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/list/RoomInvitationItem.kt index 4d0533e5cd..0da7de1839 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/list/RoomInvitationItem.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/list/RoomInvitationItem.kt @@ -17,15 +17,16 @@ package im.vector.riotredesign.features.home.room.list import android.view.ViewGroup -import android.widget.Button import android.widget.ImageView import android.widget.TextView +import androidx.core.view.isVisible import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyModelClass import im.vector.riotredesign.R import im.vector.riotredesign.core.epoxy.VectorEpoxyHolder import im.vector.riotredesign.core.epoxy.VectorEpoxyModel import im.vector.riotredesign.core.extensions.setTextOrHide +import im.vector.riotredesign.core.platform.ButtonStateView import im.vector.riotredesign.features.home.AvatarRenderer @@ -38,6 +39,10 @@ abstract class RoomInvitationItem : VectorEpoxyModel( @EpoxyAttribute var secondLine: CharSequence? = null @EpoxyAttribute var avatarUrl: String? = null @EpoxyAttribute var listener: (() -> Unit)? = null + @EpoxyAttribute var invitationAcceptInProgress: Boolean = false + @EpoxyAttribute var invitationAcceptInError: Boolean = false + @EpoxyAttribute var invitationRejectInProgress: Boolean = false + @EpoxyAttribute var invitationRejectInError: Boolean = false @EpoxyAttribute var acceptListener: (() -> Unit)? = null @EpoxyAttribute var rejectListener: (() -> Unit)? = null @@ -45,8 +50,44 @@ abstract class RoomInvitationItem : VectorEpoxyModel( override fun bind(holder: Holder) { super.bind(holder) holder.rootView.setOnClickListener { listener?.invoke() } - holder.acceptView.setOnClickListener { acceptListener?.invoke() } - holder.rejectView.setOnClickListener { rejectListener?.invoke() } + + // When a request is in progress (accept or reject), we only use the accept State button + val requestInProgress = invitationAcceptInProgress || invitationRejectInProgress + + when { + requestInProgress -> holder.acceptView.render(ButtonStateView.State.Loading) + invitationAcceptInError -> holder.acceptView.render(ButtonStateView.State.Error) + else -> holder.acceptView.render(ButtonStateView.State.Button) + } + // ButtonStateView.State.Loaded not used because roomSummary will not be displayed as a room invitation anymore + + + holder.acceptView.callback = object : ButtonStateView.Callback { + override fun onButtonClicked() { + acceptListener?.invoke() + } + + override fun onRetryClicked() { + acceptListener?.invoke() + } + } + + holder.rejectView.isVisible = !requestInProgress + + when { + invitationRejectInError -> holder.rejectView.render(ButtonStateView.State.Error) + else -> holder.rejectView.render(ButtonStateView.State.Button) + } + + holder.rejectView.callback = object : ButtonStateView.Callback { + override fun onButtonClicked() { + rejectListener?.invoke() + } + + override fun onRetryClicked() { + rejectListener?.invoke() + } + } holder.titleView.text = roomName holder.subtitleView.setTextOrHide(secondLine) avatarRenderer.render(avatarUrl, roomId, roomName.toString(), holder.avatarImageView) @@ -55,8 +96,8 @@ abstract class RoomInvitationItem : VectorEpoxyModel( class Holder : VectorEpoxyHolder() { val titleView by bind(R.id.roomInvitationNameView) val subtitleView by bind(R.id.roomInvitationSubTitle) - val acceptView by bind