Move click listener setup

This commit is contained in:
Benoit Marty 2021-02-10 17:49:40 +01:00
parent f76b4c06c5
commit 18408377e4

View file

@ -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) {
private fun onAvatarClicked(view: View) = withState(roomProfileViewModel) { state ->
state.roomSummary()?.toMatrixItem()?.let { matrixItem ->
navigator.openBigImageViewer(requireActivity(), view, matrixItem)
}
}
}