For quality issue and improve preview
This commit is contained in:
parent
f4a136db77
commit
12c8240d04
5 changed files with 23 additions and 11 deletions
|
|
@ -133,6 +133,7 @@ class AttachmentsPreviewPresenter(
|
||||||
// If the media optimization selector is not displayed, we can pre-process the media
|
// 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
|
// to prepare it for sending. This is done to avoid blocking the UI thread when the
|
||||||
// user clicks on the send button.
|
// user clicks on the send button.
|
||||||
|
@Suppress("ComplexCondition")
|
||||||
if (mediaOptimizationSelectorState.displayMediaSelectorViews == false &&
|
if (mediaOptimizationSelectorState.displayMediaSelectorViews == false &&
|
||||||
preprocessMediaJob == null &&
|
preprocessMediaJob == null &&
|
||||||
imageEditorState == null &&
|
imageEditorState == null &&
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import io.element.android.features.messages.impl.attachments.Attachment
|
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.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.MediaOptimizationSelectorState
|
||||||
import io.element.android.features.messages.impl.attachments.video.VideoUploadEstimation
|
import io.element.android.features.messages.impl.attachments.video.VideoUploadEstimation
|
||||||
import io.element.android.libraries.architecture.AsyncData
|
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.Sending.Uploading(aMediaUploadInfo())),
|
||||||
anAttachmentsPreviewState(sendActionState = SendActionState.Failure(RuntimeException("error"), aMediaUploadInfo())),
|
anAttachmentsPreviewState(sendActionState = SendActionState.Failure(RuntimeException("error"), aMediaUploadInfo())),
|
||||||
anAttachmentsPreviewState(
|
anAttachmentsPreviewState(
|
||||||
imageEditorState = AttachmentImageEditorState(LocalMedia("file://path".toUri(), anImageMediaInfo()), edits = AttachmentImageEdits())
|
imageEditorState = anAttachmentImageEditorState(),
|
||||||
),
|
),
|
||||||
anAttachmentsPreviewState(displayFileTooLargeError = true),
|
anAttachmentsPreviewState(displayFileTooLargeError = true),
|
||||||
anAttachmentsPreviewState(
|
anAttachmentsPreviewState(
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@ private const val MIN_CROP_SIZE = 0.1f
|
||||||
data class AttachmentImageEditorState(
|
data class AttachmentImageEditorState(
|
||||||
val localMedia: LocalMedia,
|
val localMedia: LocalMedia,
|
||||||
val edits: AttachmentImageEdits,
|
val edits: AttachmentImageEdits,
|
||||||
|
// For preview only
|
||||||
|
val forceDrawGuidelines: Boolean = false,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,12 @@ open class AttachmentImageEditorStateProvider : PreviewParameterProvider<Attachm
|
||||||
cropRect = caterpillarCrop,
|
cropRect = caterpillarCrop,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
anAttachmentImageEditorState(
|
||||||
|
edits = AttachmentImageEdits(
|
||||||
|
cropRect = caterpillarCrop,
|
||||||
|
),
|
||||||
|
forceDrawGuidelines = true,
|
||||||
|
),
|
||||||
anAttachmentImageEditorState(
|
anAttachmentImageEditorState(
|
||||||
edits = AttachmentImageEdits(
|
edits = AttachmentImageEdits(
|
||||||
cropRect = caterpillarCrop,
|
cropRect = caterpillarCrop,
|
||||||
|
|
@ -48,14 +54,15 @@ open class AttachmentImageEditorStateProvider : PreviewParameterProvider<Attachm
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun anAttachmentImageEditorState(
|
internal fun anAttachmentImageEditorState(
|
||||||
localMedia: LocalMedia = LocalMedia(
|
localMedia: LocalMedia = LocalMedia(
|
||||||
uri = "file://preview-image".toUri(),
|
uri = "file://preview-image".toUri(),
|
||||||
info = anImageMediaInfo(),
|
info = anImageMediaInfo(),
|
||||||
),
|
),
|
||||||
edits: AttachmentImageEdits = AttachmentImageEdits(),
|
edits: AttachmentImageEdits = AttachmentImageEdits(),
|
||||||
) =
|
forceDrawGuidelines: Boolean = false,
|
||||||
AttachmentImageEditorState(
|
) = AttachmentImageEditorState(
|
||||||
localMedia = localMedia,
|
localMedia = localMedia,
|
||||||
edits = edits,
|
edits = edits,
|
||||||
)
|
forceDrawGuidelines = forceDrawGuidelines,
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -266,6 +266,7 @@ private fun CropEditorCanvas(
|
||||||
|
|
||||||
CropOverlay(
|
CropOverlay(
|
||||||
cropRect = state.edits.cropRect,
|
cropRect = state.edits.cropRect,
|
||||||
|
forceDrawGuidelines = state.forceDrawGuidelines,
|
||||||
onCropRectChange = onCropRectChange,
|
onCropRectChange = onCropRectChange,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -275,13 +276,14 @@ private fun CropEditorCanvas(
|
||||||
@Composable
|
@Composable
|
||||||
private fun CropOverlay(
|
private fun CropOverlay(
|
||||||
cropRect: NormalizedCropRect,
|
cropRect: NormalizedCropRect,
|
||||||
|
forceDrawGuidelines: Boolean,
|
||||||
onCropRectChange: (NormalizedCropRect) -> Unit,
|
onCropRectChange: (NormalizedCropRect) -> Unit,
|
||||||
) {
|
) {
|
||||||
var dragTarget by remember { mutableStateOf<CropDragTarget?>(null) }
|
var dragTarget by remember { mutableStateOf<CropDragTarget?>(null) }
|
||||||
val latestCropRect by rememberUpdatedState(cropRect)
|
val latestCropRect by rememberUpdatedState(cropRect)
|
||||||
val borderColor = ElementTheme.colors.iconPrimary
|
val borderColor = ElementTheme.colors.iconPrimary
|
||||||
val guideColor = ElementTheme.colors.iconPrimary
|
val guideColor = ElementTheme.colors.iconPrimary
|
||||||
val drawGuidelines = dragTarget == CropDragTarget.Move
|
val drawGuidelines = dragTarget == CropDragTarget.Move || forceDrawGuidelines
|
||||||
Canvas(
|
Canvas(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
|
|
@ -352,11 +354,11 @@ private fun CropOverlay(
|
||||||
size = Size(width = cropRight - cropLeft, height = cropBottom - cropTop),
|
size = Size(width = cropRight - cropLeft, height = cropBottom - cropTop),
|
||||||
style = Stroke(width = 1.dp.toPx()),
|
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) {
|
if (drawGuidelines) {
|
||||||
val thirdWidth = (cropRight - cropLeft) / 3f
|
val thirdWidth = (cropRight - cropLeft) / 3f
|
||||||
val thirdHeight = (cropBottom - cropTop) / 3f
|
val thirdHeight = (cropBottom - cropTop) / 3f
|
||||||
(1..2).forEach { index ->
|
for (index in 1..2) {
|
||||||
val offsetX = cropLeft + thirdWidth * index
|
val offsetX = cropLeft + thirdWidth * index
|
||||||
val offsetY = cropTop + thirdHeight * index
|
val offsetY = cropTop + thirdHeight * index
|
||||||
// Vertical guide line
|
// Vertical guide line
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue