Skip to content

Commit 3083762

Browse files
committed
feat: show publication date on related videos
1 parent 5b7d2ed commit 3083762

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

‎app/src/main/java/dev/typetype/android/core/ui/components/RelatedVideoCard.kt‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.typetype.android.core.ui.components
22

3+
import android.text.format.DateUtils
34
import androidx.compose.foundation.ExperimentalFoundationApi
45
import androidx.compose.foundation.background
56
import androidx.compose.foundation.combinedClickable
@@ -39,6 +40,7 @@ import dev.typetype.android.core.ui.share.buildImageUrl
3940
import dev.typetype.android.domain.feed.Video
4041
import dev.typetype.android.domain.feed.VideoAvailability
4142
import dev.typetype.android.domain.feed.availabilityAt
43+
import dev.typetype.android.domain.feed.releaseTimeMillis
4244

4345
@OptIn(ExperimentalFoundationApi::class)
4446
@Composable
@@ -137,7 +139,7 @@ fun RelatedVideoCard(
137139
)
138140
}
139141
Text(
140-
text = stringResource(R.string.video_views_short, formatRelatedViews(video.viewCount)),
142+
text = video.metadataText(),
141143
style = MaterialTheme.typography.labelSmall,
142144
color = MaterialTheme.colorScheme.onSurfaceVariant,
143145
maxLines = 1,
@@ -169,3 +171,19 @@ private fun formatRelatedViews(views: Long): String = when {
169171
views >= 1_000 -> "%.1fK".format(views / 1_000.0)
170172
else -> views.toString()
171173
}
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

Comments
 (0)