From 3851653d39abcfbb8477fdd6672203701db49c6d Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 14 Feb 2023 13:34:05 +0100 Subject: [PATCH] Add some previews. --- .../roomlist/components/RoomSummaryRow.kt | 20 +++++++++ .../model/RoomListRoomSummaryProvider.kt | 44 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 features/roomlist/src/main/kotlin/io/element/android/features/roomlist/model/RoomListRoomSummaryProvider.kt diff --git a/features/roomlist/src/main/kotlin/io/element/android/features/roomlist/components/RoomSummaryRow.kt b/features/roomlist/src/main/kotlin/io/element/android/features/roomlist/components/RoomSummaryRow.kt index 53ca8b5d1f..506ced9a1d 100644 --- a/features/roomlist/src/main/kotlin/io/element/android/features/roomlist/components/RoomSummaryRow.kt +++ b/features/roomlist/src/main/kotlin/io/element/android/features/roomlist/components/RoomSummaryRow.kt @@ -46,13 +46,18 @@ import androidx.compose.ui.graphics.Path import androidx.compose.ui.graphics.Shape import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.unit.Density import androidx.compose.ui.unit.LayoutDirection import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.google.accompanist.placeholder.material.placeholder import io.element.android.features.roomlist.model.RoomListRoomSummary +import io.element.android.features.roomlist.model.RoomListRoomSummaryProvider import io.element.android.libraries.designsystem.components.avatar.Avatar +import io.element.android.libraries.designsystem.preview.ElementPreviewDark +import io.element.android.libraries.designsystem.preview.ElementPreviewLight import io.element.android.libraries.designsystem.theme.ElementTheme import io.element.android.libraries.designsystem.theme.components.Text import io.element.android.libraries.designsystem.theme.roomListPlaceHolder @@ -192,3 +197,18 @@ class PercentRectangleSizeShape(private val percent: Float) : Shape { return Outline.Generic(path) } } + +@Preview +@Composable +internal fun RoomSummaryRowLightPreview(@PreviewParameter(RoomListRoomSummaryProvider::class) data: RoomListRoomSummary) = + ElementPreviewLight { ContentToPreview(data) } + +@Preview +@Composable +internal fun RoomSummaryRowDarkPreview(@PreviewParameter(RoomListRoomSummaryProvider::class) data: RoomListRoomSummary) = + ElementPreviewDark { ContentToPreview(data) } + +@Composable +private fun ContentToPreview(data: RoomListRoomSummary) { + RoomSummaryRow(data) +} diff --git a/features/roomlist/src/main/kotlin/io/element/android/features/roomlist/model/RoomListRoomSummaryProvider.kt b/features/roomlist/src/main/kotlin/io/element/android/features/roomlist/model/RoomListRoomSummaryProvider.kt new file mode 100644 index 0000000000..41a6f96473 --- /dev/null +++ b/features/roomlist/src/main/kotlin/io/element/android/features/roomlist/model/RoomListRoomSummaryProvider.kt @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 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.roomlist.model + +import androidx.compose.ui.tooling.preview.PreviewParameterProvider +import io.element.android.libraries.designsystem.components.avatar.AvatarData +import io.element.android.libraries.matrix.core.RoomId + +open class RoomListRoomSummaryProvider : PreviewParameterProvider { + override val values: Sequence + get() = sequenceOf( + aRoomListRoomSummary(), + aRoomListRoomSummary().copy(lastMessage = null), + aRoomListRoomSummary().copy(hasUnread = true), + aRoomListRoomSummary().copy(timestamp = "88:88"), + aRoomListRoomSummary().copy(timestamp = "88:88", hasUnread = true), + aRoomListRoomSummary().copy(isPlaceholder = true), + ) +} + +fun aRoomListRoomSummary() = RoomListRoomSummary( + id = "!roomId", + roomId = RoomId("!roomId"), + name = "Room name", + hasUnread = false, + timestamp = null, + lastMessage = "Last message", + avatarData = AvatarData("!roomId", "Room name"), + isPlaceholder = false, +)