From 432fd67ce20a7e50704b26b938f906e8ef4ed49e Mon Sep 17 00:00:00 2001 From: Valere Date: Tue, 25 May 2021 14:08:48 +0200 Subject: [PATCH] Fixes #3406 --- .../api/session/permalinks/PermalinkService.kt | 2 +- .../permalinks/DefaultPermalinkService.kt | 4 ++-- .../session/permalinks/PermalinkFactory.kt | 12 ++++++++++-- newsfragment/3401.bugfix | 3 ++- .../features/home/room/list/RoomListAction.kt | 1 + .../features/home/room/list/RoomListFragment.kt | 17 +++++++++++++---- .../features/home/room/list/RoomListListener.kt | 1 + .../home/room/list/RoomListViewEvents.kt | 1 + .../home/room/list/RoomListViewModel.kt | 7 +++++++ .../home/room/list/RoomSummaryItemFactory.kt | 6 +++--- .../room/list/SuggestedRoomListController.kt | 6 +----- .../app/features/media/ImageContentRenderer.kt | 4 ++-- 12 files changed, 44 insertions(+), 20 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/permalinks/PermalinkService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/permalinks/PermalinkService.kt index ac1d726d03..a6d4583c76 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/permalinks/PermalinkService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/permalinks/PermalinkService.kt @@ -54,7 +54,7 @@ interface PermalinkService { * * @return the permalink, or null in case of error */ - fun createRoomPermalink(roomId: String): String? + fun createRoomPermalink(roomId: String, viaServers: List? = null): String? /** * Creates a permalink for an event. If you have an event you can use [createPermalink] diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/permalinks/DefaultPermalinkService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/permalinks/DefaultPermalinkService.kt index 7db9d8f68a..8b45c9f570 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/permalinks/DefaultPermalinkService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/permalinks/DefaultPermalinkService.kt @@ -33,8 +33,8 @@ internal class DefaultPermalinkService @Inject constructor( return permalinkFactory.createPermalink(id) } - override fun createRoomPermalink(roomId: String): String? { - return permalinkFactory.createRoomPermalink(roomId) + override fun createRoomPermalink(roomId: String, via: List?): String? { + return permalinkFactory.createRoomPermalink(roomId, via) } override fun createPermalink(roomId: String, eventId: String): String { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/permalinks/PermalinkFactory.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/permalinks/PermalinkFactory.kt index 970752449a..f8bc1b9b34 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/permalinks/PermalinkFactory.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/permalinks/PermalinkFactory.kt @@ -19,6 +19,7 @@ package org.matrix.android.sdk.internal.session.permalinks import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.permalinks.PermalinkService.Companion.MATRIX_TO_URL_BASE import org.matrix.android.sdk.internal.di.UserId +import java.net.URLEncoder import javax.inject.Inject internal class PermalinkFactory @Inject constructor( @@ -40,11 +41,18 @@ internal class PermalinkFactory @Inject constructor( } else MATRIX_TO_URL_BASE + escape(id) } - fun createRoomPermalink(roomId: String): String? { + fun createRoomPermalink(roomId: String, via: List? = null): String? { return if (roomId.isEmpty()) { null } else { - MATRIX_TO_URL_BASE + escape(roomId) + viaParameterFinder.computeViaParams(userId, roomId) + buildString { + append(MATRIX_TO_URL_BASE) + append(escape(roomId)) + append( + via?.joinToString(prefix = "?via=", separator = "&via=") { URLEncoder.encode(it, "utf-8") } + ?: viaParameterFinder.computeViaParams(userId, roomId) + ) + } } } diff --git a/newsfragment/3401.bugfix b/newsfragment/3401.bugfix index 42509f3ae3..c1774521af 100644 --- a/newsfragment/3401.bugfix +++ b/newsfragment/3401.bugfix @@ -1 +1,2 @@ -Fix | On Android it seems to be impossible to view the complete description of a Space (without dev tools) (#3386) \ No newline at end of file +Fix | On Android it seems to be impossible to view the complete description of a Space (without dev tools) (#3386) +Fix | Suggest Rooms, Show a detailed view of the room on click (#3406) \ No newline at end of file diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListAction.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListAction.kt index 37f7d148aa..e6b6b34503 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListAction.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListAction.kt @@ -30,4 +30,5 @@ sealed class RoomListAction : VectorViewModelAction { data class ToggleTag(val roomId: String, val tag: String) : RoomListAction() data class LeaveRoom(val roomId: String) : RoomListAction() data class JoinSuggestedRoom(val roomId: String, val viaServers: List?) : RoomListAction() + data class ShowRoomDetails(val roomId: String, val viaServers: List?) : RoomListAction() } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt index 76d7752ea7..8049d3c057 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt @@ -108,10 +108,11 @@ class RoomListFragment @Inject constructor( sharedActionViewModel = activityViewModelProvider.get(RoomListQuickActionsSharedActionViewModel::class.java) roomListViewModel.observeViewEvents { when (it) { - is RoomListViewEvents.Loading -> showLoading(it.message) - is RoomListViewEvents.Failure -> showFailure(it.throwable) - is RoomListViewEvents.SelectRoom -> handleSelectRoom(it) - is RoomListViewEvents.Done -> Unit + is RoomListViewEvents.Loading -> showLoading(it.message) + is RoomListViewEvents.Failure -> showFailure(it.throwable) + is RoomListViewEvents.SelectRoom -> handleSelectRoom(it) + is RoomListViewEvents.Done -> Unit + is RoomListViewEvents.NavigateToMxToBottomSheet -> handleShowMxToLink(it.link) }.exhaustive } @@ -155,6 +156,10 @@ class RoomListFragment @Inject constructor( showErrorInSnackbar(throwable) } + private fun handleShowMxToLink(link: String) { + navigator.openMatrixToBottomSheet(requireContext(), link) + } + override fun onDestroyView() { adapterInfosList.onEach { it.contentEpoxyController.removeModelBuildListener(modelBuildListener) } adapterInfosList.clear() @@ -474,6 +479,10 @@ class RoomListFragment @Inject constructor( roomListViewModel.handle(RoomListAction.JoinSuggestedRoom(room.childRoomId, room.viaServers)) } + override fun onSuggestedRoomClicked(room: SpaceChildInfo) { + roomListViewModel.handle(RoomListAction.ShowRoomDetails(room.childRoomId, room.viaServers)) + } + override fun onRejectRoomInvitation(room: RoomSummary) { notificationDrawerManager.clearMemberShipNotificationForRoom(room.roomId) roomListViewModel.handle(RoomListAction.RejectInvitation(room)) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListListener.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListListener.kt index 0ba265f841..cf619ce435 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListListener.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListListener.kt @@ -26,4 +26,5 @@ interface RoomListListener : FilteredRoomFooterItem.FilteredRoomFooterItemListen fun onRejectRoomInvitation(room: RoomSummary) fun onAcceptRoomInvitation(room: RoomSummary) fun onJoinSuggestedRoom(room: SpaceChildInfo) + fun onSuggestedRoomClicked(room: SpaceChildInfo) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewEvents.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewEvents.kt index cb84d91373..df2ff58da6 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewEvents.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewEvents.kt @@ -29,4 +29,5 @@ sealed class RoomListViewEvents : VectorViewEvents { data class SelectRoom(val roomSummary: RoomSummary) : RoomListViewEvents() object Done : RoomListViewEvents() + data class NavigateToMxToBottomSheet(val link: String) : RoomListViewEvents() } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt index 246d5052cf..fbb8faebb0 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt @@ -161,6 +161,7 @@ class RoomListViewModel @Inject constructor( is RoomListAction.ToggleTag -> handleToggleTag(action) is RoomListAction.ToggleSection -> handleToggleSection(action.section) is RoomListAction.JoinSuggestedRoom -> handleJoinSuggestedRoom(action) + is RoomListAction.ShowRoomDetails -> handleShowRoomDetails(action) }.exhaustive } @@ -289,6 +290,12 @@ class RoomListViewModel @Inject constructor( } } + private fun handleShowRoomDetails(action: RoomListAction.ShowRoomDetails) { + session.permalinkService().createRoomPermalink(action.roomId, action.viaServers)?.let { + _viewEvents.post(RoomListViewEvents.NavigateToMxToBottomSheet(it)) + } + } + private fun handleToggleTag(action: RoomListAction.ToggleTag) { session.getRoom(action.roomId)?.let { room -> viewModelScope.launch(Dispatchers.IO) { diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt index e4826af04c..ec78a13c9f 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt @@ -16,7 +16,6 @@ package im.vector.app.features.home.room.list -import android.view.View import com.airbnb.mvrx.Async import com.airbnb.mvrx.Loading import im.vector.app.R @@ -56,7 +55,7 @@ class RoomSummaryItemFactory @Inject constructor(private val displayableEventFor fun createSuggestion(spaceChildInfo: SpaceChildInfo, suggestedRoomJoiningStates: Map>, - onJoinClick: View.OnClickListener): VectorEpoxyModel<*> { + listener: RoomListListener?): VectorEpoxyModel<*> { return SpaceChildInfoItem_() .id("sug_${spaceChildInfo.childRoomId}") .matrixItem(spaceChildInfo.toMatrixItem()) @@ -65,7 +64,8 @@ class RoomSummaryItemFactory @Inject constructor(private val displayableEventFor .buttonLabel(stringProvider.getString(R.string.join)) .loading(suggestedRoomJoiningStates[spaceChildInfo.childRoomId] is Loading) .memberCount(spaceChildInfo.activeMemberCount ?: 0) - .buttonClickListener(onJoinClick) + .buttonClickListener(DebouncedClickListener({ listener?.onJoinSuggestedRoom(spaceChildInfo) })) + .itemClickListener(DebouncedClickListener({ listener?.onSuggestedRoomClicked(spaceChildInfo) })) } private fun createInvitationItem(roomSummary: RoomSummary, diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/SuggestedRoomListController.kt b/vector/src/main/java/im/vector/app/features/home/room/list/SuggestedRoomListController.kt index 073fb43b6c..f9775967ee 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/SuggestedRoomListController.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/SuggestedRoomListController.kt @@ -24,11 +24,7 @@ class SuggestedRoomListController( override fun buildModels(data: SuggestedRoomInfo?) { data?.rooms?.forEach { info -> - roomSummaryItemFactory.createSuggestion(info, data.joinEcho) { - listener?.onJoinSuggestedRoom(info) - }.let { - add(it) - } + add(roomSummaryItemFactory.createSuggestion(info, data.joinEcho, listener)) } } } diff --git a/vector/src/main/java/im/vector/app/features/media/ImageContentRenderer.kt b/vector/src/main/java/im/vector/app/features/media/ImageContentRenderer.kt index 1c0d859fa9..8d6d1f467b 100644 --- a/vector/src/main/java/im/vector/app/features/media/ImageContentRenderer.kt +++ b/vector/src/main/java/im/vector/app/features/media/ImageContentRenderer.kt @@ -245,7 +245,7 @@ class ImageContentRenderer @Inject constructor(private val localFilesHelper: Loc val contentUrlResolver = activeSessionHolder.getActiveSession().contentUrlResolver() val resolvedUrl = when (mode) { Mode.FULL_SIZE, - Mode.STICKER -> resolveUrl(data) + Mode.STICKER -> resolveUrl(data) Mode.THUMBNAIL -> contentUrlResolver.resolveThumbnail(data.url, size.width, size.height, ContentUrlResolver.ThumbnailMethod.SCALE) } // Fallback to base url @@ -313,7 +313,7 @@ class ImageContentRenderer @Inject constructor(private val localFilesHelper: Loc finalHeight = min(maxImageWidth * height / width, maxImageHeight) finalWidth = finalHeight * width / height } - Mode.STICKER -> { + Mode.STICKER -> { // limit on width val maxWidthDp = min(dimensionConverter.dpToPx(120), maxImageWidth / 2) finalWidth = min(dimensionConverter.dpToPx(width), maxWidthDp)