mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-04 19:10:43 +00:00
Introduce derived state editedAttachments
This commit is contained in:
+12
-5
@@ -11,6 +11,7 @@ package io.element.android.features.messages.impl.attachments.preview
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.MutableState
|
import androidx.compose.runtime.MutableState
|
||||||
|
import androidx.compose.runtime.derivedStateOf
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableIntStateOf
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
@@ -121,6 +122,12 @@ class AttachmentsPreviewPresenter(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val editedAttachments by remember {
|
||||||
|
derivedStateOf {
|
||||||
|
attachmentsAndEdits.map { it.attachment }.toImmutableList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var preprocessMediaJob by remember { mutableStateOf<Job?>(null) }
|
var preprocessMediaJob by remember { mutableStateOf<Job?>(null) }
|
||||||
|
|
||||||
val firstMediaAttachment = attachments.first() as Attachment.Media
|
val firstMediaAttachment = attachments.first() as Attachment.Media
|
||||||
@@ -148,7 +155,7 @@ class AttachmentsPreviewPresenter(
|
|||||||
preprocessMediaJob?.cancel()
|
preprocessMediaJob?.cancel()
|
||||||
preprocessMediaJob = coroutineScope.launch(dispatchers.io) {
|
preprocessMediaJob = coroutineScope.launch(dispatchers.io) {
|
||||||
preProcessAttachments(
|
preProcessAttachments(
|
||||||
attachments = attachmentsAndEdits.map { it.attachment },
|
attachments = editedAttachments,
|
||||||
mediaOptimizationConfig = config,
|
mediaOptimizationConfig = config,
|
||||||
displayProgress = false,
|
displayProgress = false,
|
||||||
sendActionState = sendActionState,
|
sendActionState = sendActionState,
|
||||||
@@ -206,7 +213,7 @@ class AttachmentsPreviewPresenter(
|
|||||||
)
|
)
|
||||||
preprocessMediaJob = coroutineScope.launch(dispatchers.io) {
|
preprocessMediaJob = coroutineScope.launch(dispatchers.io) {
|
||||||
preProcessAttachments(
|
preProcessAttachments(
|
||||||
attachments = attachmentsAndEdits.map { it.attachment },
|
attachments = editedAttachments,
|
||||||
mediaOptimizationConfig = config,
|
mediaOptimizationConfig = config,
|
||||||
displayProgress = true,
|
displayProgress = true,
|
||||||
sendActionState = sendActionState,
|
sendActionState = sendActionState,
|
||||||
@@ -221,7 +228,7 @@ class AttachmentsPreviewPresenter(
|
|||||||
)
|
)
|
||||||
preprocessMediaJob = coroutineScope.launch(dispatchers.io) {
|
preprocessMediaJob = coroutineScope.launch(dispatchers.io) {
|
||||||
preProcessAttachments(
|
preProcessAttachments(
|
||||||
attachments = attachmentsAndEdits.map { it.attachment },
|
attachments = editedAttachments,
|
||||||
mediaOptimizationConfig = config,
|
mediaOptimizationConfig = config,
|
||||||
displayProgress = true,
|
displayProgress = true,
|
||||||
sendActionState = sendActionState,
|
sendActionState = sendActionState,
|
||||||
@@ -273,7 +280,7 @@ class AttachmentsPreviewPresenter(
|
|||||||
|
|
||||||
// Dismiss the screen
|
// Dismiss the screen
|
||||||
dismiss(
|
dismiss(
|
||||||
attachments = attachmentsAndEdits.map { it.attachment },
|
attachments = editedAttachments,
|
||||||
sendActionState = sendActionState,
|
sendActionState = sendActionState,
|
||||||
editedTempFiles = editedTempFiles,
|
editedTempFiles = editedTempFiles,
|
||||||
)
|
)
|
||||||
@@ -395,7 +402,7 @@ class AttachmentsPreviewPresenter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return AttachmentsPreviewState(
|
return AttachmentsPreviewState(
|
||||||
attachments = attachmentsAndEdits.map { it.attachment }.toImmutableList(),
|
attachments = editedAttachments,
|
||||||
imageEditorState = imageEditorState,
|
imageEditorState = imageEditorState,
|
||||||
canEditImage = canEditImage,
|
canEditImage = canEditImage,
|
||||||
isApplyingImageEdits = isApplyingImageEdits,
|
isApplyingImageEdits = isApplyingImageEdits,
|
||||||
|
|||||||
Reference in New Issue
Block a user