mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 13:38:49 +03:00
Improve code
This commit is contained in:
parent
06ba478232
commit
d87b951403
3 changed files with 25 additions and 23 deletions
|
@ -22,11 +22,17 @@ fun ContentAttachmentData.isPreviewable(): Boolean {
|
|||
return type == ContentAttachmentData.Type.IMAGE || type == ContentAttachmentData.Type.VIDEO
|
||||
}
|
||||
|
||||
fun List<ContentAttachmentData>.filterPreviewables(): List<ContentAttachmentData> {
|
||||
return filter { it.isPreviewable() }
|
||||
}
|
||||
data class GroupedContentAttachmentData(
|
||||
val previewables: List<ContentAttachmentData>,
|
||||
val notPreviewables: List<ContentAttachmentData>
|
||||
)
|
||||
|
||||
fun List<ContentAttachmentData>.filterNonPreviewables(): List<ContentAttachmentData> {
|
||||
return filter { it.isPreviewable().not() }
|
||||
fun List<ContentAttachmentData>.toGroupedContentAttachmentData(): GroupedContentAttachmentData {
|
||||
return groupBy { it.isPreviewable() }
|
||||
.let {
|
||||
GroupedContentAttachmentData(
|
||||
it[true].orEmpty(),
|
||||
it[false].orEmpty()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -116,10 +116,9 @@ import im.vector.riotx.core.utils.toast
|
|||
import im.vector.riotx.features.attachments.AttachmentTypeSelectorView
|
||||
import im.vector.riotx.features.attachments.AttachmentsHelper
|
||||
import im.vector.riotx.features.attachments.ContactAttachment
|
||||
import im.vector.riotx.features.attachments.filterNonPreviewables
|
||||
import im.vector.riotx.features.attachments.filterPreviewables
|
||||
import im.vector.riotx.features.attachments.preview.AttachmentsPreviewActivity
|
||||
import im.vector.riotx.features.attachments.preview.AttachmentsPreviewArgs
|
||||
import im.vector.riotx.features.attachments.toGroupedContentAttachmentData
|
||||
import im.vector.riotx.features.command.Command
|
||||
import im.vector.riotx.features.crypto.util.toImageRes
|
||||
import im.vector.riotx.features.crypto.verification.VerificationBottomSheet
|
||||
|
@ -1351,14 +1350,13 @@ class RoomDetailFragment @Inject constructor(
|
|||
// AttachmentsHelper.Callback
|
||||
|
||||
override fun onContentAttachmentsReady(attachments: List<ContentAttachmentData>) {
|
||||
val previewable = attachments.filterPreviewables()
|
||||
val nonPreviewable = attachments.filterNonPreviewables()
|
||||
if (nonPreviewable.isNotEmpty()) {
|
||||
val grouped = attachments.toGroupedContentAttachmentData()
|
||||
if (grouped.notPreviewables.isNotEmpty()) {
|
||||
// Send the non previewable attachment right now (?)
|
||||
roomDetailViewModel.handle(RoomDetailAction.SendMedia(nonPreviewable, false))
|
||||
roomDetailViewModel.handle(RoomDetailAction.SendMedia(grouped.notPreviewables, false))
|
||||
}
|
||||
if (previewable.isNotEmpty()) {
|
||||
val intent = AttachmentsPreviewActivity.newIntent(requireContext(), AttachmentsPreviewArgs(previewable))
|
||||
if (grouped.previewables.isNotEmpty()) {
|
||||
val intent = AttachmentsPreviewActivity.newIntent(requireContext(), AttachmentsPreviewArgs(grouped.previewables))
|
||||
startActivityForResult(intent, AttachmentsPreviewActivity.REQUEST_CODE)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,8 +30,7 @@ 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.platform.VectorViewModel
|
||||
import im.vector.riotx.features.attachments.filterNonPreviewables
|
||||
import im.vector.riotx.features.attachments.filterPreviewables
|
||||
import im.vector.riotx.features.attachments.toGroupedContentAttachmentData
|
||||
import im.vector.riotx.features.home.room.list.ChronologicalRoomComparator
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
|
@ -140,18 +139,17 @@ class IncomingShareViewModel @AssistedInject constructor(@Assisted initialState:
|
|||
?.let { roomId -> session.getRoom(roomId) }
|
||||
?.sendMedias(attachmentData, compressMediaBeforeSending, selectedRoomIds)
|
||||
} else {
|
||||
val previewable = attachmentData.filterPreviewables()
|
||||
val nonPreviewable = attachmentData.filterNonPreviewables()
|
||||
if (nonPreviewable.isNotEmpty()) {
|
||||
// Send the non previewable attachment right now (?)
|
||||
val grouped = attachmentData.toGroupedContentAttachmentData()
|
||||
if (grouped.notPreviewables.isNotEmpty()) {
|
||||
// Send the not previewable attachment right now (?)
|
||||
// Pick the first room to send the media
|
||||
selectedRoomIds.firstOrNull()
|
||||
?.let { roomId -> session.getRoom(roomId) }
|
||||
?.sendMedias(nonPreviewable, compressMediaBeforeSending, selectedRoomIds)
|
||||
?.sendMedias(grouped.notPreviewables, compressMediaBeforeSending, selectedRoomIds)
|
||||
}
|
||||
if (previewable.isNotEmpty()) {
|
||||
if (grouped.previewables.isNotEmpty()) {
|
||||
// In case of multiple share of media, edit them first
|
||||
_viewEvents.post(IncomingShareViewEvents.EditMediaBeforeSending(previewable))
|
||||
_viewEvents.post(IncomingShareViewEvents.EditMediaBeforeSending(grouped.previewables))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue