diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/ATimelineItemEventRow.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/ATimelineItemEventRow.kt new file mode 100644 index 0000000000..6cd28c7f94 --- /dev/null +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/ATimelineItemEventRow.kt @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.features.messages.impl.timeline.components + +import androidx.compose.runtime.Composable +import io.element.android.features.messages.impl.timeline.model.TimelineItem + +// For previews +@Composable +internal fun ATimelineItemEventRow( + event: TimelineItem.Event, + showReadReceipts: Boolean = false, + isLastOutgoingMessage: Boolean = false, + isHighlighted: Boolean = false, +) = TimelineItemEventRow( + event = event, + showReadReceipts = showReadReceipts, + isLastOutgoingMessage = isLastOutgoingMessage, + isHighlighted = isHighlighted, + canReply = true, + onClick = {}, + onLongClick = {}, + onUserDataClick = {}, + inReplyToClick = {}, + onReactionClick = { _, _ -> }, + onReactionLongClick = { _, _ -> }, + onMoreReactionsClick = {}, + onReadReceiptClick = {}, + onSwipeToReply = {}, + onTimestampClicked = {}, + eventSink = {}, +) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRow.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRow.kt index 906ed731a7..9642068704 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRow.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRow.kt @@ -688,7 +688,7 @@ private fun textForInReplyTo(inReplyTo: InReplyToDetails): String { internal fun TimelineItemEventRowPreview() = ElementPreview { Column { sequenceOf(false, true).forEach { - TimelineItemEventRow( + ATimelineItemEventRow( event = aTimelineItemEvent( isMine = it, content = aTimelineItemTextContent().copy( @@ -697,23 +697,8 @@ internal fun TimelineItemEventRowPreview() = ElementPreview { ), groupPosition = TimelineItemGroupPosition.First, ), - showReadReceipts = false, - isLastOutgoingMessage = false, - isHighlighted = false, - canReply = true, - onClick = {}, - onLongClick = {}, - onUserDataClick = {}, - inReplyToClick = {}, - onReactionClick = { _, _ -> }, - onReactionLongClick = { _, _ -> }, - onMoreReactionsClick = {}, - onReadReceiptClick = {}, - onTimestampClicked = {}, - onSwipeToReply = {}, - eventSink = {}, ) - TimelineItemEventRow( + ATimelineItemEventRow( event = aTimelineItemEvent( isMine = it, content = aTimelineItemImageContent().copy( @@ -721,21 +706,6 @@ internal fun TimelineItemEventRowPreview() = ElementPreview { ), groupPosition = TimelineItemGroupPosition.Last, ), - showReadReceipts = false, - isLastOutgoingMessage = false, - isHighlighted = false, - canReply = true, - onClick = {}, - onLongClick = {}, - onUserDataClick = {}, - inReplyToClick = {}, - onReactionClick = { _, _ -> }, - onReactionLongClick = { _, _ -> }, - onMoreReactionsClick = {}, - onReadReceiptClick = {}, - onTimestampClicked = {}, - onSwipeToReply = {}, - eventSink = {}, ) } } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowLongSenderNamePreview.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowLongSenderNamePreview.kt index 3e282279a3..061ad75690 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowLongSenderNamePreview.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowLongSenderNamePreview.kt @@ -25,24 +25,9 @@ import io.element.android.libraries.designsystem.preview.ElementPreviewLight @Preview @Composable internal fun TimelineItemEventRowLongSenderNamePreview() = ElementPreviewLight { - TimelineItemEventRow( + ATimelineItemEventRow( event = aTimelineItemEvent( senderDisplayName = "a long sender display name to test single line and ellipsis at the end of the line", ), - showReadReceipts = false, - isLastOutgoingMessage = false, - isHighlighted = false, - canReply = true, - onClick = {}, - onLongClick = {}, - onUserDataClick = {}, - inReplyToClick = {}, - onReactionClick = { _, _ -> }, - onReactionLongClick = { _, _ -> }, - onMoreReactionsClick = {}, - onReadReceiptClick = {}, - onSwipeToReply = {}, - onTimestampClicked = {}, - eventSink = {}, ) } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowTimestampPreview.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowTimestampPreview.kt index 554754568d..a1bef47731 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowTimestampPreview.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowTimestampPreview.kt @@ -39,7 +39,7 @@ internal fun TimelineItemEventRowTimestampPreview( "Text which should be rendered on several lines", ).forEach { str -> listOf(false, true).forEach { useDocument -> - TimelineItemEventRow( + ATimelineItemEventRow( event = event.copy( content = oldContent.copy( body = str, @@ -48,21 +48,6 @@ internal fun TimelineItemEventRowTimestampPreview( reactionsState = aTimelineItemReactions(count = 0), senderDisplayName = if (useDocument) "Document case" else "Text case", ), - showReadReceipts = false, - isLastOutgoingMessage = false, - isHighlighted = false, - canReply = true, - onClick = {}, - onLongClick = {}, - onUserDataClick = {}, - inReplyToClick = {}, - onReactionClick = { _, _ -> }, - onReactionLongClick = { _, _ -> }, - onMoreReactionsClick = {}, - onReadReceiptClick = {}, - onTimestampClicked = {}, - onSwipeToReply = {}, - eventSink = {}, ) } } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowWithManyReactionsPreview.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowWithManyReactionsPreview.kt index 0857572a2a..bbd65a62ad 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowWithManyReactionsPreview.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowWithManyReactionsPreview.kt @@ -29,7 +29,7 @@ import io.element.android.libraries.designsystem.preview.PreviewsDayNight internal fun TimelineItemEventRowWithManyReactionsPreview() = ElementPreview { Column { listOf(false, true).forEach { isMine -> - TimelineItemEventRow( + ATimelineItemEventRow( event = aTimelineItemEvent( isMine = isMine, content = aTimelineItemTextContent().copy( @@ -38,21 +38,6 @@ internal fun TimelineItemEventRowWithManyReactionsPreview() = ElementPreview { ), timelineItemReactions = aTimelineItemReactions(count = 20), ), - showReadReceipts = false, - isLastOutgoingMessage = false, - isHighlighted = false, - canReply = true, - onClick = {}, - onLongClick = {}, - onUserDataClick = {}, - inReplyToClick = {}, - onReactionClick = { _, _ -> }, - onReactionLongClick = { _, _ -> }, - onMoreReactionsClick = {}, - onReadReceiptClick = {}, - onSwipeToReply = {}, - onTimestampClicked = {}, - eventSink = {}, ) } } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowWithRRPreview.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowWithRRPreview.kt new file mode 100644 index 0000000000..4a9972d19b --- /dev/null +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowWithRRPreview.kt @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2023 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.features.messages.impl.timeline.components + +import androidx.compose.foundation.layout.Column +import androidx.compose.runtime.Composable +import androidx.compose.ui.tooling.preview.PreviewParameter +import io.element.android.features.messages.impl.timeline.aTimelineItemEvent +import io.element.android.features.messages.impl.timeline.aTimelineItemReactions +import io.element.android.features.messages.impl.timeline.components.receipt.ReadReceiptViewState +import io.element.android.features.messages.impl.timeline.components.receipt.ReadReceiptViewStateForTimelineItemEventRowProvider +import io.element.android.features.messages.impl.timeline.model.TimelineItemReadReceipts +import io.element.android.features.messages.impl.timeline.model.event.aTimelineItemTextContent +import io.element.android.libraries.designsystem.preview.ElementPreview +import io.element.android.libraries.designsystem.preview.PreviewsDayNight + +// Note: I add to reduce the size of the fun name, or it does not compile. +// Previous name: TimelineItemEventRowWithSendingStateAndReadReceiptPreview +@PreviewsDayNight +@Composable +internal fun TimelineItemEventRowWithRRPreview( + @PreviewParameter(ReadReceiptViewStateForTimelineItemEventRowProvider::class) state: ReadReceiptViewState, +) = ElementPreview { + Column { + // A message from someone else + ATimelineItemEventRow( + event = aTimelineItemEvent( + isMine = false, + sendState = null, + content = aTimelineItemTextContent().copy( + body = "A message from someone else" + ), + timelineItemReactions = aTimelineItemReactions(count = 0), + readReceiptState = TimelineItemReadReceipts(state.receipts), + ), + showReadReceipts = true, + isLastOutgoingMessage = false, + ) + // A message from current user + ATimelineItemEventRow( + event = aTimelineItemEvent( + isMine = true, + sendState = state.sendState, + content = aTimelineItemTextContent().copy( + body = "A message from me" + ), + timelineItemReactions = aTimelineItemReactions(count = 0), + readReceiptState = TimelineItemReadReceipts(state.receipts), + ), + showReadReceipts = true, + isLastOutgoingMessage = false, + ) + // Another message from current user + ATimelineItemEventRow( + event = aTimelineItemEvent( + isMine = true, + sendState = state.sendState, + content = aTimelineItemTextContent().copy( + body = "A last message from me" + ), + timelineItemReactions = aTimelineItemReactions(count = 0), + readReceiptState = TimelineItemReadReceipts(state.receipts), + ), + showReadReceipts = true, + isLastOutgoingMessage = true, + ) + } +} diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowWithReplyPreview.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowWithReplyPreview.kt index 66b385f6bf..8443ffafa2 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowWithReplyPreview.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRowWithReplyPreview.kt @@ -53,7 +53,7 @@ internal fun TimelineItemEventRowWithReplyPreview( ) = ElementPreview { Column { sequenceOf(false, true).forEach { - TimelineItemEventRow( + ATimelineItemEventRow( event = aTimelineItemEvent( isMine = it, timelineItemReactions = aTimelineItemReactions(count = 0), @@ -63,23 +63,8 @@ internal fun TimelineItemEventRowWithReplyPreview( inReplyTo = inReplyToDetails, groupPosition = TimelineItemGroupPosition.First, ), - showReadReceipts = false, - isLastOutgoingMessage = false, - isHighlighted = false, - canReply = true, - onClick = {}, - onLongClick = {}, - onUserDataClick = {}, - inReplyToClick = {}, - onReactionClick = { _, _ -> }, - onReactionLongClick = { _, _ -> }, - onMoreReactionsClick = {}, - onReadReceiptClick = {}, - onTimestampClicked = {}, - onSwipeToReply = {}, - eventSink = {}, ) - TimelineItemEventRow( + ATimelineItemEventRow( event = aTimelineItemEvent( isMine = it, timelineItemReactions = aTimelineItemReactions(count = 0), @@ -90,21 +75,6 @@ internal fun TimelineItemEventRowWithReplyPreview( isThreaded = true, groupPosition = TimelineItemGroupPosition.Last, ), - showReadReceipts = false, - isLastOutgoingMessage = false, - isHighlighted = false, - canReply = true, - onClick = {}, - onLongClick = {}, - onUserDataClick = {}, - inReplyToClick = {}, - onReactionClick = { _, _ -> }, - onReactionLongClick = { _, _ -> }, - onMoreReactionsClick = {}, - onReadReceiptClick = {}, - onTimestampClicked = {}, - onSwipeToReply = {}, - eventSink = {}, ) } } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventTimestampBelowPreview.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventTimestampBelowPreview.kt index 51cb4bb020..992ec63e7d 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventTimestampBelowPreview.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventTimestampBelowPreview.kt @@ -26,22 +26,7 @@ import io.element.android.libraries.designsystem.preview.ElementPreviewLight @Preview @Composable internal fun TimelineItemEventTimestampBelowPreview() = ElementPreviewLight { - TimelineItemEventRow( + ATimelineItemEventRow( event = aTimelineItemEvent(content = aTimelineItemPollContent()), - showReadReceipts = false, - isLastOutgoingMessage = false, - isHighlighted = false, - canReply = true, - onClick = {}, - onLongClick = {}, - onUserDataClick = {}, - inReplyToClick = {}, - onReactionClick = { _, _ -> }, - onReactionLongClick = { _, _ -> }, - onMoreReactionsClick = {}, - onReadReceiptClick = {}, - onSwipeToReply = {}, - onTimestampClicked = {}, - eventSink = {}, ) } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/receipt/ReadReceiptViewStateForTimelineItemEventRowProvider.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/receipt/ReadReceiptViewStateForTimelineItemEventRowProvider.kt new file mode 100644 index 0000000000..1595e59f54 --- /dev/null +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/receipt/ReadReceiptViewStateForTimelineItemEventRowProvider.kt @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.features.messages.impl.timeline.components.receipt + +import androidx.compose.ui.tooling.preview.PreviewParameterProvider +import io.element.android.features.messages.impl.timeline.model.ReadReceiptData +import io.element.android.libraries.matrix.api.core.EventId +import io.element.android.libraries.matrix.api.timeline.item.event.LocalEventSendState + +class ReadReceiptViewStateForTimelineItemEventRowProvider : + PreviewParameterProvider { + override val values: Sequence + get() = sequenceOf( + aReadReceiptViewState( + sendState = LocalEventSendState.NotSentYet + ), + aReadReceiptViewState( + sendState = LocalEventSendState.Sent(EventId("\$eventId")), + ), + aReadReceiptViewState( + sendState = LocalEventSendState.Sent(EventId("\$eventId")), + receipts = mutableListOf().apply { + repeat(5) { + add( + aReadReceiptData( + it + ) + ) + } + }, + ), + ) +} diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/receipt/ReadReceiptViewStateProvider.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/receipt/ReadReceiptViewStateProvider.kt index e0f72b010d..5c9e4d6ca9 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/receipt/ReadReceiptViewStateProvider.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/receipt/ReadReceiptViewStateProvider.kt @@ -54,7 +54,7 @@ class ReadReceiptViewStateProvider : PreviewParameterProvider = emptyList(), @@ -64,7 +64,7 @@ private fun aReadReceiptViewState( receipts = receipts.toImmutableList(), ) -private fun aReadReceiptData( +internal fun aReadReceiptData( index: Int, avatarData: AvatarData = anAvatarData( id = "$index",