Create TimelineItemEventRowWithRRPreview to preview read receipts and send state in a timeline.
Also introduce ATimelineItemEventRow.
This commit is contained in:
parent
5e44722b51
commit
0a2b0f1a10
10 changed files with 185 additions and 130 deletions
|
|
@ -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 = {},
|
||||||
|
)
|
||||||
|
|
@ -688,7 +688,7 @@ private fun textForInReplyTo(inReplyTo: InReplyToDetails): String {
|
||||||
internal fun TimelineItemEventRowPreview() = ElementPreview {
|
internal fun TimelineItemEventRowPreview() = ElementPreview {
|
||||||
Column {
|
Column {
|
||||||
sequenceOf(false, true).forEach {
|
sequenceOf(false, true).forEach {
|
||||||
TimelineItemEventRow(
|
ATimelineItemEventRow(
|
||||||
event = aTimelineItemEvent(
|
event = aTimelineItemEvent(
|
||||||
isMine = it,
|
isMine = it,
|
||||||
content = aTimelineItemTextContent().copy(
|
content = aTimelineItemTextContent().copy(
|
||||||
|
|
@ -697,23 +697,8 @@ internal fun TimelineItemEventRowPreview() = ElementPreview {
|
||||||
),
|
),
|
||||||
groupPosition = TimelineItemGroupPosition.First,
|
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(
|
event = aTimelineItemEvent(
|
||||||
isMine = it,
|
isMine = it,
|
||||||
content = aTimelineItemImageContent().copy(
|
content = aTimelineItemImageContent().copy(
|
||||||
|
|
@ -721,21 +706,6 @@ internal fun TimelineItemEventRowPreview() = ElementPreview {
|
||||||
),
|
),
|
||||||
groupPosition = TimelineItemGroupPosition.Last,
|
groupPosition = TimelineItemGroupPosition.Last,
|
||||||
),
|
),
|
||||||
showReadReceipts = false,
|
|
||||||
isLastOutgoingMessage = false,
|
|
||||||
isHighlighted = false,
|
|
||||||
canReply = true,
|
|
||||||
onClick = {},
|
|
||||||
onLongClick = {},
|
|
||||||
onUserDataClick = {},
|
|
||||||
inReplyToClick = {},
|
|
||||||
onReactionClick = { _, _ -> },
|
|
||||||
onReactionLongClick = { _, _ -> },
|
|
||||||
onMoreReactionsClick = {},
|
|
||||||
onReadReceiptClick = {},
|
|
||||||
onTimestampClicked = {},
|
|
||||||
onSwipeToReply = {},
|
|
||||||
eventSink = {},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,24 +25,9 @@ import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
internal fun TimelineItemEventRowLongSenderNamePreview() = ElementPreviewLight {
|
internal fun TimelineItemEventRowLongSenderNamePreview() = ElementPreviewLight {
|
||||||
TimelineItemEventRow(
|
ATimelineItemEventRow(
|
||||||
event = aTimelineItemEvent(
|
event = aTimelineItemEvent(
|
||||||
senderDisplayName = "a long sender display name to test single line and ellipsis at the end of the line",
|
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 = {},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ internal fun TimelineItemEventRowTimestampPreview(
|
||||||
"Text which should be rendered on several lines",
|
"Text which should be rendered on several lines",
|
||||||
).forEach { str ->
|
).forEach { str ->
|
||||||
listOf(false, true).forEach { useDocument ->
|
listOf(false, true).forEach { useDocument ->
|
||||||
TimelineItemEventRow(
|
ATimelineItemEventRow(
|
||||||
event = event.copy(
|
event = event.copy(
|
||||||
content = oldContent.copy(
|
content = oldContent.copy(
|
||||||
body = str,
|
body = str,
|
||||||
|
|
@ -48,21 +48,6 @@ internal fun TimelineItemEventRowTimestampPreview(
|
||||||
reactionsState = aTimelineItemReactions(count = 0),
|
reactionsState = aTimelineItemReactions(count = 0),
|
||||||
senderDisplayName = if (useDocument) "Document case" else "Text case",
|
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 = {},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||||
internal fun TimelineItemEventRowWithManyReactionsPreview() = ElementPreview {
|
internal fun TimelineItemEventRowWithManyReactionsPreview() = ElementPreview {
|
||||||
Column {
|
Column {
|
||||||
listOf(false, true).forEach { isMine ->
|
listOf(false, true).forEach { isMine ->
|
||||||
TimelineItemEventRow(
|
ATimelineItemEventRow(
|
||||||
event = aTimelineItemEvent(
|
event = aTimelineItemEvent(
|
||||||
isMine = isMine,
|
isMine = isMine,
|
||||||
content = aTimelineItemTextContent().copy(
|
content = aTimelineItemTextContent().copy(
|
||||||
|
|
@ -38,21 +38,6 @@ internal fun TimelineItemEventRowWithManyReactionsPreview() = ElementPreview {
|
||||||
),
|
),
|
||||||
timelineItemReactions = aTimelineItemReactions(count = 20),
|
timelineItemReactions = aTimelineItemReactions(count = 20),
|
||||||
),
|
),
|
||||||
showReadReceipts = false,
|
|
||||||
isLastOutgoingMessage = false,
|
|
||||||
isHighlighted = false,
|
|
||||||
canReply = true,
|
|
||||||
onClick = {},
|
|
||||||
onLongClick = {},
|
|
||||||
onUserDataClick = {},
|
|
||||||
inReplyToClick = {},
|
|
||||||
onReactionClick = { _, _ -> },
|
|
||||||
onReactionLongClick = { _, _ -> },
|
|
||||||
onMoreReactionsClick = {},
|
|
||||||
onReadReceiptClick = {},
|
|
||||||
onSwipeToReply = {},
|
|
||||||
onTimestampClicked = {},
|
|
||||||
eventSink = {},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -53,7 +53,7 @@ internal fun TimelineItemEventRowWithReplyPreview(
|
||||||
) = ElementPreview {
|
) = ElementPreview {
|
||||||
Column {
|
Column {
|
||||||
sequenceOf(false, true).forEach {
|
sequenceOf(false, true).forEach {
|
||||||
TimelineItemEventRow(
|
ATimelineItemEventRow(
|
||||||
event = aTimelineItemEvent(
|
event = aTimelineItemEvent(
|
||||||
isMine = it,
|
isMine = it,
|
||||||
timelineItemReactions = aTimelineItemReactions(count = 0),
|
timelineItemReactions = aTimelineItemReactions(count = 0),
|
||||||
|
|
@ -63,23 +63,8 @@ internal fun TimelineItemEventRowWithReplyPreview(
|
||||||
inReplyTo = inReplyToDetails,
|
inReplyTo = inReplyToDetails,
|
||||||
groupPosition = TimelineItemGroupPosition.First,
|
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(
|
event = aTimelineItemEvent(
|
||||||
isMine = it,
|
isMine = it,
|
||||||
timelineItemReactions = aTimelineItemReactions(count = 0),
|
timelineItemReactions = aTimelineItemReactions(count = 0),
|
||||||
|
|
@ -90,21 +75,6 @@ internal fun TimelineItemEventRowWithReplyPreview(
|
||||||
isThreaded = true,
|
isThreaded = true,
|
||||||
groupPosition = TimelineItemGroupPosition.Last,
|
groupPosition = TimelineItemGroupPosition.Last,
|
||||||
),
|
),
|
||||||
showReadReceipts = false,
|
|
||||||
isLastOutgoingMessage = false,
|
|
||||||
isHighlighted = false,
|
|
||||||
canReply = true,
|
|
||||||
onClick = {},
|
|
||||||
onLongClick = {},
|
|
||||||
onUserDataClick = {},
|
|
||||||
inReplyToClick = {},
|
|
||||||
onReactionClick = { _, _ -> },
|
|
||||||
onReactionLongClick = { _, _ -> },
|
|
||||||
onMoreReactionsClick = {},
|
|
||||||
onReadReceiptClick = {},
|
|
||||||
onTimestampClicked = {},
|
|
||||||
onSwipeToReply = {},
|
|
||||||
eventSink = {},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,22 +26,7 @@ import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
internal fun TimelineItemEventTimestampBelowPreview() = ElementPreviewLight {
|
internal fun TimelineItemEventTimestampBelowPreview() = ElementPreviewLight {
|
||||||
TimelineItemEventRow(
|
ATimelineItemEventRow(
|
||||||
event = aTimelineItemEvent(content = aTimelineItemPollContent()),
|
event = aTimelineItemEvent(content = aTimelineItemPollContent()),
|
||||||
showReadReceipts = false,
|
|
||||||
isLastOutgoingMessage = false,
|
|
||||||
isHighlighted = false,
|
|
||||||
canReply = true,
|
|
||||||
onClick = {},
|
|
||||||
onLongClick = {},
|
|
||||||
onUserDataClick = {},
|
|
||||||
inReplyToClick = {},
|
|
||||||
onReactionClick = { _, _ -> },
|
|
||||||
onReactionLongClick = { _, _ -> },
|
|
||||||
onMoreReactionsClick = {},
|
|
||||||
onReadReceiptClick = {},
|
|
||||||
onSwipeToReply = {},
|
|
||||||
onTimestampClicked = {},
|
|
||||||
eventSink = {},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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<ReadReceiptViewState> {
|
||||||
|
override val values: Sequence<ReadReceiptViewState>
|
||||||
|
get() = sequenceOf(
|
||||||
|
aReadReceiptViewState(
|
||||||
|
sendState = LocalEventSendState.NotSentYet
|
||||||
|
),
|
||||||
|
aReadReceiptViewState(
|
||||||
|
sendState = LocalEventSendState.Sent(EventId("\$eventId")),
|
||||||
|
),
|
||||||
|
aReadReceiptViewState(
|
||||||
|
sendState = LocalEventSendState.Sent(EventId("\$eventId")),
|
||||||
|
receipts = mutableListOf<ReadReceiptData>().apply {
|
||||||
|
repeat(5) {
|
||||||
|
add(
|
||||||
|
aReadReceiptData(
|
||||||
|
it
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -54,7 +54,7 @@ class ReadReceiptViewStateProvider : PreviewParameterProvider<ReadReceiptViewSta
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun aReadReceiptViewState(
|
internal fun aReadReceiptViewState(
|
||||||
sendState: LocalEventSendState? = null,
|
sendState: LocalEventSendState? = null,
|
||||||
isLastOutgoingMessage: Boolean = true,
|
isLastOutgoingMessage: Boolean = true,
|
||||||
receipts: List<ReadReceiptData> = emptyList(),
|
receipts: List<ReadReceiptData> = emptyList(),
|
||||||
|
|
@ -64,7 +64,7 @@ private fun aReadReceiptViewState(
|
||||||
receipts = receipts.toImmutableList(),
|
receipts = receipts.toImmutableList(),
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun aReadReceiptData(
|
internal fun aReadReceiptData(
|
||||||
index: Int,
|
index: Int,
|
||||||
avatarData: AvatarData = anAvatarData(
|
avatarData: AvatarData = anAvatarData(
|
||||||
id = "$index",
|
id = "$index",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue