From 18408377e41a2f98d49b444e1c70a5a4590e61ce Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 10 Feb 2021 17:49:40 +0100 Subject: [PATCH] Move click listener setup --- .../roomprofile/RoomProfileFragment.kt | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt index dd920cda18..eb00e7af08 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileFragment.kt @@ -52,7 +52,6 @@ import im.vector.app.features.home.room.list.actions.RoomListQuickActionsSharedA import im.vector.app.features.home.room.list.actions.RoomListQuickActionsSharedActionViewModel import kotlinx.parcelize.Parcelize import org.matrix.android.sdk.api.session.room.notification.RoomNotificationState -import org.matrix.android.sdk.api.util.MatrixItem import org.matrix.android.sdk.api.util.toMatrixItem import timber.log.Timber import javax.inject.Inject @@ -127,7 +126,7 @@ class RoomProfileFragment @Inject constructor( private fun setupClicks() { // Shortcut to room settings - listOf( + setOf( headerViews.roomProfileNameView, views.matrixProfileToolbarTitleView, ).forEach { @@ -139,6 +138,13 @@ class RoomProfileFragment @Inject constructor( headerViews.roomProfileAliasView.setOnClickListener { roomProfileSharedActionViewModel.post(RoomProfileSharedAction.OpenRoomAliasesSettings) } + // Open Avatar + setOf( + headerViews.roomProfileAvatarView, + views.matrixProfileToolbarAvatarImageView + ).forEach { view -> + view.setOnClickListener { onAvatarClicked(view) } + } } private fun setupLongClicks() { @@ -187,7 +193,7 @@ class RoomProfileFragment @Inject constructor( override fun invalidate() = withState(roomProfileViewModel) { state -> views.waitingView.root.isVisible = state.isLoading - state.roomSummary()?.also { + state.roomSummary()?.let { if (it.membership.isLeft()) { Timber.w("The room has been left") activity?.finish() @@ -201,13 +207,6 @@ class RoomProfileFragment @Inject constructor( headerViews.roomProfileDecorationImageView.isVisible = it.roomEncryptionTrustLevel != null headerViews.roomProfileDecorationImageView.setImageResource(it.roomEncryptionTrustLevel.toImageRes()) views.matrixProfileDecorationToolbarAvatarImageView.setImageResource(it.roomEncryptionTrustLevel.toImageRes()) - - headerViews.roomProfileAvatarView.setOnClickListener { view -> - onAvatarClicked(view, matrixItem) - } - views.matrixProfileToolbarAvatarImageView.setOnClickListener { view -> - onAvatarClicked(view, matrixItem) - } } } roomProfileController.setData(state) @@ -311,7 +310,9 @@ class RoomProfileFragment @Inject constructor( ) } - private fun onAvatarClicked(view: View, matrixItem: MatrixItem.RoomItem) { - navigator.openBigImageViewer(requireActivity(), view, matrixItem) + private fun onAvatarClicked(view: View) = withState(roomProfileViewModel) { state -> + state.roomSummary()?.toMatrixItem()?.let { matrixItem -> + navigator.openBigImageViewer(requireActivity(), view, matrixItem) + } } }