Merge pull request #1035 from vector-im/feature/share_text

Fix share text to a single room issue
This commit is contained in:
Benoit Marty 2020-02-19 10:08:29 +01:00 committed by GitHub
commit 571db7da55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 12 deletions

View File

@ -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 <T> Set<T>.toggle(element: T): Set<T> {
return if (contains(element)) {
minus(element)
} else {
plus(element)
}
}

View File

@ -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,

View File

@ -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
}
}

View File

@ -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
@ -30,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
@ -179,19 +179,26 @@ 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)
} 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
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))
}
}