Do not show alert when sharing text to a single room

This commit is contained in:
Benoit Marty 2020-02-18 12:24:27 +01:00
parent 7b3fcb7798
commit d730f96c41

View file

@ -22,7 +22,6 @@ import com.airbnb.mvrx.ViewModelContext
import com.jakewharton.rxrelay2.BehaviorRelay import com.jakewharton.rxrelay2.BehaviorRelay
import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.Assisted
import com.squareup.inject.assisted.AssistedInject 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.query.QueryStringValue
import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.Session
import im.vector.matrix.android.api.session.content.ContentAttachmentData 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 -> private fun handleSelectRoom(action: IncomingShareAction.SelectRoom) = withState { state ->
if (state.isInMultiSelectionMode) { if (state.isInMultiSelectionMode) {
// One room is clicked (or long clicked) while in multi selection mode -> toggle this room
val selectedRooms = state.selectedRoomIds val selectedRooms = state.selectedRoomIds
val newSelectedRooms = if (selectedRooms.contains(action.roomSummary.roomId)) { val newSelectedRooms = if (selectedRooms.contains(action.roomSummary.roomId)) {
selectedRooms.minus(action.roomSummary.roomId) selectedRooms.minus(action.roomSummary.roomId)
@ -187,11 +187,21 @@ class IncomingShareViewModel @AssistedInject constructor(
} }
setState { copy(isInMultiSelectionMode = newSelectedRooms.isNotEmpty(), selectedRoomIds = newSelectedRooms) } setState { copy(isInMultiSelectionMode = newSelectedRooms.isNotEmpty(), selectedRoomIds = newSelectedRooms) }
} else if (action.enableMultiSelect) { } 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)) } setState { copy(isInMultiSelectionMode = true, selectedRoomIds = setOf(action.roomSummary.roomId)) }
} else { } else {
// One room is clicked, not in multi selection mode -> direct share
val sharedData = state.sharedData ?: return@withState 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 = when (sharedData) {
val doNotShowAlert = (sharedData as? SharedData.Attachments)?.attachmentData?.all { it.isPreviewable() }.orFalse() 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)) _viewEvents.post(IncomingShareViewEvents.ShareToRoom(action.roomSummary, sharedData, !doNotShowAlert))
} }
} }