|
1 | 1 | package dev.typetype.android.core.ui.components |
2 | 2 |
|
| 3 | +import android.text.format.DateUtils |
3 | 4 | import androidx.compose.foundation.ExperimentalFoundationApi |
4 | 5 | import androidx.compose.foundation.background |
5 | 6 | import androidx.compose.foundation.combinedClickable |
@@ -39,6 +40,7 @@ import dev.typetype.android.core.ui.share.buildImageUrl |
39 | 40 | import dev.typetype.android.domain.feed.Video |
40 | 41 | import dev.typetype.android.domain.feed.VideoAvailability |
41 | 42 | import dev.typetype.android.domain.feed.availabilityAt |
| 43 | +import dev.typetype.android.domain.feed.releaseTimeMillis |
42 | 44 |
|
43 | 45 | @OptIn(ExperimentalFoundationApi::class) |
44 | 46 | @Composable |
@@ -137,7 +139,7 @@ fun RelatedVideoCard( |
137 | 139 | ) |
138 | 140 | } |
139 | 141 | Text( |
140 | | - text = stringResource(R.string.video_views_short, formatRelatedViews(video.viewCount)), |
| 142 | + text = video.metadataText(), |
141 | 143 | style = MaterialTheme.typography.labelSmall, |
142 | 144 | color = MaterialTheme.colorScheme.onSurfaceVariant, |
143 | 145 | maxLines = 1, |
@@ -169,3 +171,19 @@ private fun formatRelatedViews(views: Long): String = when { |
169 | 171 | views >= 1_000 -> "%.1fK".format(views / 1_000.0) |
170 | 172 | else -> views.toString() |
171 | 173 | } |
| 174 | + |
| 175 | +@Composable |
| 176 | +private fun Video.metadataText(): String { |
| 177 | + val views = stringResource(R.string.video_views_short, formatRelatedViews(viewCount)) |
| 178 | + val published = releaseTimeMillis() |
| 179 | + ?.takeIf { it <= System.currentTimeMillis() } |
| 180 | + ?.let { timestamp -> |
| 181 | + DateUtils.getRelativeTimeSpanString( |
| 182 | + timestamp, |
| 183 | + System.currentTimeMillis(), |
| 184 | + DateUtils.MINUTE_IN_MILLIS, |
| 185 | + DateUtils.FORMAT_ABBREV_RELATIVE, |
| 186 | + ).toString() |
| 187 | + } |
| 188 | + return listOfNotNull(views, published).joinToString(" · ") |
| 189 | +} |
0 commit comments