|
| 1 | +package net.thunderbird.feature.mail.message.list.ui.component.molecule |
| 2 | + |
| 3 | +import android.content.res.Configuration |
| 4 | +import androidx.compose.foundation.layout.padding |
| 5 | +import androidx.compose.runtime.Composable |
| 6 | +import androidx.compose.runtime.CompositionLocalProvider |
| 7 | +import androidx.compose.ui.Modifier |
| 8 | +import androidx.compose.ui.graphics.Color |
| 9 | +import androidx.compose.ui.platform.LocalConfiguration |
| 10 | +import androidx.compose.ui.tooling.preview.PreviewLightDark |
| 11 | +import androidx.compose.ui.tooling.preview.PreviewParameter |
| 12 | +import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider |
| 13 | +import app.k9mail.core.ui.compose.common.window.WindowSizeClass |
| 14 | +import app.k9mail.core.ui.compose.designsystem.PreviewWithThemeLightDark |
| 15 | +import app.k9mail.core.ui.compose.designsystem.atom.text.TextTitleSmall |
| 16 | +import net.thunderbird.core.ui.compose.theme2.MainTheme |
| 17 | +import net.thunderbird.feature.mail.message.list.ui.component.config.MessageItemAccountIndicator |
| 18 | +import net.thunderbird.feature.mail.message.list.ui.component.config.MessageItemConfiguration |
| 19 | + |
| 20 | +private class AdaptiveMessageItemHeaderRowPreviewData( |
| 21 | + val previewName: String, |
| 22 | + val configuration: MessageItemConfiguration, |
| 23 | + val receivedAt: String, |
| 24 | + val screenWidth: Int, |
| 25 | +) |
| 26 | + |
| 27 | +private val screenWidths = listOf( |
| 28 | + "Small" to (WindowSizeClass.SMALL_MAX_WIDTH - 1), |
| 29 | + "Compact" to (WindowSizeClass.COMPACT_MAX_WIDTH - 1), |
| 30 | + "Medium" to (WindowSizeClass.MEDIUM_MAX_WIDTH - 1), |
| 31 | + "Expanded" to WindowSizeClass.MEDIUM_MAX_WIDTH, |
| 32 | +) |
| 33 | + |
| 34 | +private class AdaptiveMessageItemHeaderRowProvider : |
| 35 | + CollectionPreviewParameterProvider<AdaptiveMessageItemHeaderRowPreviewData>( |
| 36 | + screenWidths.flatMap { (sizeName, width) -> |
| 37 | + listOf( |
| 38 | + AdaptiveMessageItemHeaderRowPreviewData( |
| 39 | + previewName = "$sizeName - Default", |
| 40 | + configuration = MessageItemConfiguration(), |
| 41 | + receivedAt = "10:30 AM", |
| 42 | + screenWidth = width, |
| 43 | + ), |
| 44 | + AdaptiveMessageItemHeaderRowPreviewData( |
| 45 | + previewName = "$sizeName - Yesterday timestamp", |
| 46 | + configuration = MessageItemConfiguration(), |
| 47 | + receivedAt = "Yesterday", |
| 48 | + screenWidth = width, |
| 49 | + ), |
| 50 | + AdaptiveMessageItemHeaderRowPreviewData( |
| 51 | + previewName = "$sizeName - Date timestamp", |
| 52 | + configuration = MessageItemConfiguration(), |
| 53 | + receivedAt = "Mar 12, 2026", |
| 54 | + screenWidth = width, |
| 55 | + ), |
| 56 | + AdaptiveMessageItemHeaderRowPreviewData( |
| 57 | + previewName = "$sizeName - With account indicator", |
| 58 | + configuration = MessageItemConfiguration( |
| 59 | + accountIndicator = MessageItemAccountIndicator(color = Color(color = 0xFF1565C0)), |
| 60 | + ), |
| 61 | + receivedAt = "9:15 AM", |
| 62 | + screenWidth = width, |
| 63 | + ), |
| 64 | + AdaptiveMessageItemHeaderRowPreviewData( |
| 65 | + previewName = "$sizeName - With red account indicator", |
| 66 | + configuration = MessageItemConfiguration( |
| 67 | + accountIndicator = MessageItemAccountIndicator(color = Color(color = 0xFFC62828)), |
| 68 | + ), |
| 69 | + receivedAt = "2:45 PM", |
| 70 | + screenWidth = width, |
| 71 | + ), |
| 72 | + AdaptiveMessageItemHeaderRowPreviewData( |
| 73 | + previewName = "$sizeName - With green account indicator", |
| 74 | + configuration = MessageItemConfiguration( |
| 75 | + accountIndicator = MessageItemAccountIndicator(color = Color(color = 0xFF2E7D32)), |
| 76 | + ), |
| 77 | + receivedAt = "Jan 5", |
| 78 | + screenWidth = width, |
| 79 | + ), |
| 80 | + ) |
| 81 | + }, |
| 82 | + ) { |
| 83 | + override fun getDisplayName(index: Int): String = values.elementAt(index).previewName |
| 84 | +} |
| 85 | + |
| 86 | +@PreviewLightDark |
| 87 | +@Composable |
| 88 | +private fun AdaptiveMessageItemHeaderRowPreview( |
| 89 | + @PreviewParameter(AdaptiveMessageItemHeaderRowProvider::class) data: AdaptiveMessageItemHeaderRowPreviewData, |
| 90 | +) { |
| 91 | + PreviewWithThemeLightDark { |
| 92 | + CompositionLocalProvider( |
| 93 | + LocalConfiguration provides Configuration().apply { |
| 94 | + screenWidthDp = data.screenWidth |
| 95 | + }, |
| 96 | + ) { |
| 97 | + AdaptiveMessageItemHeaderRow( |
| 98 | + configuration = data.configuration, |
| 99 | + receivedAt = data.receivedAt, |
| 100 | + firstLine = { TextTitleSmall(data.previewName) }, |
| 101 | + modifier = Modifier.padding( |
| 102 | + horizontal = MainTheme.spacings.default, |
| 103 | + vertical = MainTheme.spacings.quadruple, |
| 104 | + ), |
| 105 | + ) |
| 106 | + } |
| 107 | + } |
| 108 | +} |
0 commit comments