For quality issue and improve preview

This commit is contained in:
Benoit Marty 2026-05-22 12:13:09 +02:00
parent aa92bb61c1
commit a158da1d18
5 changed files with 23 additions and 11 deletions

View file

@ -133,6 +133,7 @@ class AttachmentsPreviewPresenter(
// If the media optimization selector is not displayed, we can pre-process the media
// to prepare it for sending. This is done to avoid blocking the UI thread when the
// user clicks on the send button.
@Suppress("ComplexCondition")
if (mediaOptimizationSelectorState.displayMediaSelectorViews == false &&
preprocessMediaJob == null &&
imageEditorState == null &&

View file

@ -12,7 +12,7 @@ import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.core.net.toUri
import io.element.android.features.messages.impl.attachments.Attachment
import io.element.android.features.messages.impl.attachments.preview.imageeditor.AttachmentImageEditorState
import io.element.android.features.messages.impl.attachments.preview.imageeditor.AttachmentImageEdits
import io.element.android.features.messages.impl.attachments.preview.imageeditor.anAttachmentImageEditorState
import io.element.android.features.messages.impl.attachments.video.MediaOptimizationSelectorState
import io.element.android.features.messages.impl.attachments.video.VideoUploadEstimation
import io.element.android.libraries.architecture.AsyncData
@ -45,7 +45,7 @@ open class AttachmentsPreviewStateProvider : PreviewParameterProvider<Attachment
anAttachmentsPreviewState(sendActionState = SendActionState.Sending.Uploading(aMediaUploadInfo())),
anAttachmentsPreviewState(sendActionState = SendActionState.Failure(RuntimeException("error"), aMediaUploadInfo())),
anAttachmentsPreviewState(
imageEditorState = AttachmentImageEditorState(LocalMedia("file://path".toUri(), anImageMediaInfo()), edits = AttachmentImageEdits())
imageEditorState = anAttachmentImageEditorState(),
),
anAttachmentsPreviewState(displayFileTooLargeError = true),
anAttachmentsPreviewState(

View file

@ -17,6 +17,8 @@ private const val MIN_CROP_SIZE = 0.1f
data class AttachmentImageEditorState(
val localMedia: LocalMedia,
val edits: AttachmentImageEdits,
// For preview only
val forceDrawGuidelines: Boolean = false,
)
@Immutable

View file

@ -40,6 +40,12 @@ open class AttachmentImageEditorStateProvider : PreviewParameterProvider<Attachm
cropRect = caterpillarCrop,
),
),
anAttachmentImageEditorState(
edits = AttachmentImageEdits(
cropRect = caterpillarCrop,
),
forceDrawGuidelines = true,
),
anAttachmentImageEditorState(
edits = AttachmentImageEdits(
cropRect = caterpillarCrop,
@ -48,14 +54,15 @@ open class AttachmentImageEditorStateProvider : PreviewParameterProvider<Attachm
)
}
private fun anAttachmentImageEditorState(
internal fun anAttachmentImageEditorState(
localMedia: LocalMedia = LocalMedia(
uri = "file://preview-image".toUri(),
info = anImageMediaInfo(),
),
edits: AttachmentImageEdits = AttachmentImageEdits(),
) =
AttachmentImageEditorState(
localMedia = localMedia,
edits = edits,
)
forceDrawGuidelines: Boolean = false,
) = AttachmentImageEditorState(
localMedia = localMedia,
edits = edits,
forceDrawGuidelines = forceDrawGuidelines,
)

View file

@ -266,6 +266,7 @@ private fun CropEditorCanvas(
CropOverlay(
cropRect = state.edits.cropRect,
forceDrawGuidelines = state.forceDrawGuidelines,
onCropRectChange = onCropRectChange,
)
}
@ -275,13 +276,14 @@ private fun CropEditorCanvas(
@Composable
private fun CropOverlay(
cropRect: NormalizedCropRect,
forceDrawGuidelines: Boolean,
onCropRectChange: (NormalizedCropRect) -> Unit,
) {
var dragTarget by remember { mutableStateOf<CropDragTarget?>(null) }
val latestCropRect by rememberUpdatedState(cropRect)
val borderColor = ElementTheme.colors.iconPrimary
val guideColor = ElementTheme.colors.iconPrimary
val drawGuidelines = dragTarget == CropDragTarget.Move
val drawGuidelines = dragTarget == CropDragTarget.Move || forceDrawGuidelines
Canvas(
modifier = Modifier
.fillMaxSize()
@ -352,11 +354,11 @@ private fun CropOverlay(
size = Size(width = cropRight - cropLeft, height = cropBottom - cropTop),
style = Stroke(width = 1.dp.toPx()),
)
// Guide lines dividing the crop area into 9 equal parts
// Guidelines dividing the crop area into 9 equal parts
if (drawGuidelines) {
val thirdWidth = (cropRight - cropLeft) / 3f
val thirdHeight = (cropBottom - cropTop) / 3f
(1..2).forEach { index ->
for (index in 1..2) {
val offsetX = cropLeft + thirdWidth * index
val offsetY = cropTop + thirdHeight * index
// Vertical guide line