From 7b3fcb7798e96369df7180dd580901e241d58b2f Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 18 Feb 2020 12:11:51 +0100 Subject: [PATCH 1/3] When sharing to a room save a draft to pre-fill the composer --- .../riotx/features/home/room/detail/RoomDetailFragment.kt | 7 ++++--- .../riotx/features/home/room/detail/RoomDetailViewModel.kt | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt index 46d2c24853..c2eb61b3ca 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt @@ -303,13 +303,14 @@ class RoomDetailFragment @Inject constructor( if (savedInstanceState == null) { when (val sharedData = roomDetailArgs.sharedData) { is SharedData.Text -> { - roomDetailViewModel.handle(RoomDetailAction.ExitSpecialMode(composerLayout.text.toString())) + // Save a draft to set the shared text to the composer + roomDetailViewModel.handle(RoomDetailAction.SaveDraft(sharedData.text)) } is SharedData.Attachments -> { // open share edition onContentAttachmentsReady(sharedData.attachmentData) } - null -> Timber.v("No share data to process") + null -> Timber.v("No share data to process") }.exhaustive } } @@ -435,7 +436,7 @@ class RoomDetailFragment @Inject constructor( composerLayout.collapse() updateComposerText(text) - composerLayout.sendButton.setContentDescription(getString(R.string.send)) + composerLayout.sendButton.contentDescription = getString(R.string.send) } private fun renderSpecialMode(event: TimelineEvent, diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt index 78f2b9a577..1eccba7fa9 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt @@ -243,7 +243,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro is SendMode.REPLY -> room.saveDraft(UserDraft.REPLY(it.sendMode.timelineEvent.root.eventId!!, action.draft), NoOpMatrixCallback()) is SendMode.QUOTE -> room.saveDraft(UserDraft.QUOTE(it.sendMode.timelineEvent.root.eventId!!, action.draft), NoOpMatrixCallback()) is SendMode.EDIT -> room.saveDraft(UserDraft.EDIT(it.sendMode.timelineEvent.root.eventId!!, action.draft), NoOpMatrixCallback()) - } + }.exhaustive } } From d730f96c41d89a4e691fb0e03b486215172152f8 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 18 Feb 2020 12:24:27 +0100 Subject: [PATCH 2/3] Do not show alert when sharing text to a single room --- .../features/share/IncomingShareViewModel.kt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/share/IncomingShareViewModel.kt b/vector/src/main/java/im/vector/riotx/features/share/IncomingShareViewModel.kt index 7a0ce8bc47..8a425d70d4 100644 --- a/vector/src/main/java/im/vector/riotx/features/share/IncomingShareViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/share/IncomingShareViewModel.kt @@ -22,7 +22,6 @@ import com.airbnb.mvrx.ViewModelContext import com.jakewharton.rxrelay2.BehaviorRelay import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject -import im.vector.matrix.android.api.extensions.orFalse import im.vector.matrix.android.api.query.QueryStringValue import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.content.ContentAttachmentData @@ -179,6 +178,7 @@ class IncomingShareViewModel @AssistedInject constructor( private fun handleSelectRoom(action: IncomingShareAction.SelectRoom) = withState { state -> if (state.isInMultiSelectionMode) { + // One room is clicked (or long clicked) while in multi selection mode -> toggle this room val selectedRooms = state.selectedRoomIds val newSelectedRooms = if (selectedRooms.contains(action.roomSummary.roomId)) { selectedRooms.minus(action.roomSummary.roomId) @@ -187,11 +187,21 @@ class IncomingShareViewModel @AssistedInject constructor( } setState { copy(isInMultiSelectionMode = newSelectedRooms.isNotEmpty(), selectedRoomIds = newSelectedRooms) } } else if (action.enableMultiSelect) { + // One room is long clicked, not in multi selection mode -> enable multi selection mode setState { copy(isInMultiSelectionMode = true, selectedRoomIds = setOf(action.roomSummary.roomId)) } } else { + // One room is clicked, not in multi selection mode -> direct share val sharedData = state.sharedData ?: return@withState - // Do not show alert if the shared data contains only previewable attachments, because the user will get another chance to cancel the share - val doNotShowAlert = (sharedData as? SharedData.Attachments)?.attachmentData?.all { it.isPreviewable() }.orFalse() + val doNotShowAlert = when (sharedData) { + is SharedData.Attachments -> { + // Do not show alert if the shared data contains only previewable attachments, because the user will get another chance to cancel the share + sharedData.attachmentData.all { it.isPreviewable() } + } + is SharedData.Text -> { + // Do not show alert when sharing text to one room, because it will just fill the composer + true + } + } _viewEvents.post(IncomingShareViewEvents.ShareToRoom(action.roomSummary, sharedData, !doNotShowAlert)) } } From 86c38ebd2d1687cb0a2498fe35914c4b7d235873 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 18 Feb 2020 13:33:49 +0100 Subject: [PATCH 3/3] Create Set.toggle() method --- .../im/vector/riotx/core/extensions/Set.kt | 26 +++++++++++++++++++ .../features/share/IncomingShareViewModel.kt | 7 ++--- 2 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 vector/src/main/java/im/vector/riotx/core/extensions/Set.kt diff --git a/vector/src/main/java/im/vector/riotx/core/extensions/Set.kt b/vector/src/main/java/im/vector/riotx/core/extensions/Set.kt new file mode 100644 index 0000000000..43eb1b0d7c --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/core/extensions/Set.kt @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2020 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotx.core.extensions + +// Create a new Set including the provided element if not already present, or removing the element if already present +fun Set.toggle(element: T): Set { + return if (contains(element)) { + minus(element) + } else { + plus(element) + } +} diff --git a/vector/src/main/java/im/vector/riotx/features/share/IncomingShareViewModel.kt b/vector/src/main/java/im/vector/riotx/features/share/IncomingShareViewModel.kt index 8a425d70d4..c135460ee4 100644 --- a/vector/src/main/java/im/vector/riotx/features/share/IncomingShareViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/share/IncomingShareViewModel.kt @@ -29,6 +29,7 @@ import im.vector.matrix.android.api.session.room.model.Membership import im.vector.matrix.android.api.session.room.roomSummaryQueryParams import im.vector.matrix.rx.rx import im.vector.riotx.core.extensions.exhaustive +import im.vector.riotx.core.extensions.toggle import im.vector.riotx.core.platform.VectorViewModel import im.vector.riotx.features.attachments.isPreviewable import im.vector.riotx.features.attachments.toGroupedContentAttachmentData @@ -180,11 +181,7 @@ class IncomingShareViewModel @AssistedInject constructor( if (state.isInMultiSelectionMode) { // One room is clicked (or long clicked) while in multi selection mode -> toggle this room val selectedRooms = state.selectedRoomIds - val newSelectedRooms = if (selectedRooms.contains(action.roomSummary.roomId)) { - selectedRooms.minus(action.roomSummary.roomId) - } else { - selectedRooms.plus(action.roomSummary.roomId) - } + val newSelectedRooms = selectedRooms.toggle(action.roomSummary.roomId) setState { copy(isInMultiSelectionMode = newSelectedRooms.isNotEmpty(), selectedRoomIds = newSelectedRooms) } } else if (action.enableMultiSelect) { // One room is long clicked, not in multi selection mode -> enable multi selection mode