@@ -29,12 +29,14 @@ import androidx.compose.material3.Text
2929import androidx.compose.material3.rememberModalBottomSheetState
3030import androidx.compose.material3.rememberStandardBottomSheetState
3131import androidx.compose.runtime.Composable
32+ import androidx.compose.runtime.DisposableEffect
3233import androidx.compose.ui.Alignment
3334import androidx.compose.ui.Modifier
3435import androidx.compose.ui.draw.clip
3536import androidx.compose.ui.graphics.Color
3637import androidx.compose.ui.platform.LocalContext
3738import androidx.compose.ui.res.painterResource
39+ import androidx.compose.ui.res.stringResource
3840import androidx.compose.ui.tooling.preview.Preview
3941import androidx.compose.ui.tooling.preview.PreviewParameter
4042import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider
@@ -130,51 +132,76 @@ fun LongPressMenuHeader(
130132 )
131133 }
132134
133- item.playlistSize?.let { playlistSize ->
134- Surface (
135- color = Color .Black .copy(alpha = 0.6f ),
136- contentColor = Color .White ,
137- modifier = Modifier
138- .align(Alignment .TopEnd )
139- .height(thumbnailHeight)
140- .width(40 .dp)
141- .clip(MaterialTheme .shapes.large),
142- ) {
143- Column (
144- verticalArrangement = Arrangement .Center ,
145- horizontalAlignment = Alignment .CenterHorizontally ,
146- modifier = Modifier .fillMaxWidth(),
147- ) {
148- Icon (
149- Icons .AutoMirrored .Default .PlaylistPlay ,
150- contentDescription = null ,
151- )
152- Text (
153- text = Localization .localizeStreamCountMini(ctx, playlistSize),
154- style = MaterialTheme .typography.labelMedium,
155- maxLines = 1 ,
156- )
135+ when (val decoration = item.decoration) {
136+ is LongPressableDecoration .Duration -> {
137+ // only show duration if there is a thumbnail
138+ if (item.thumbnailUrl != null ) {
139+ Surface (
140+ color = Color .Black .copy(alpha = 0.6f ),
141+ contentColor = Color .White ,
142+ modifier = Modifier
143+ .align(Alignment .BottomEnd )
144+ .padding(4 .dp)
145+ .clip(MaterialTheme .shapes.medium),
146+ ) {
147+ Text (
148+ text = Localization .getDurationString(decoration.duration),
149+ modifier = Modifier .padding(vertical = 2 .dp, horizontal = 4 .dp)
150+ )
151+ }
152+ }
153+ }
154+ is LongPressableDecoration .Live -> {
155+ // only show "Live" if there is a thumbnail
156+ if (item.thumbnailUrl != null ) {
157+ Surface (
158+ color = Color .Red .copy(alpha = 0.6f ),
159+ contentColor = Color .White ,
160+ modifier = Modifier
161+ .align(Alignment .BottomEnd )
162+ .padding(4 .dp)
163+ .clip(MaterialTheme .shapes.medium),
164+ ) {
165+ Text (
166+ text = stringResource(R .string.duration_live).uppercase(),
167+ modifier = Modifier .padding(vertical = 2 .dp, horizontal = 4 .dp)
168+ )
169+ }
157170 }
158171 }
159- }
160172
161- item.duration?.takeIf { it >= 0 }?.let { duration ->
162- // only show duration if there is a thumbnail and there is no playlist header
163- if (item.thumbnailUrl != null && item.playlistSize == null ) {
173+ is LongPressableDecoration .Playlist -> {
164174 Surface (
165175 color = Color .Black .copy(alpha = 0.6f ),
166176 contentColor = Color .White ,
167177 modifier = Modifier
168- .align(Alignment .BottomEnd )
169- .padding(4 .dp)
170- .clip(MaterialTheme .shapes.medium),
178+ .align(Alignment .TopEnd )
179+ .height(thumbnailHeight)
180+ .width(40 .dp)
181+ .clip(MaterialTheme .shapes.large),
171182 ) {
172- Text (
173- text = Localization .getDurationString(duration),
174- modifier = Modifier .padding(vertical = 2 .dp, horizontal = 3 .dp)
175- )
183+ Column (
184+ verticalArrangement = Arrangement .Center ,
185+ horizontalAlignment = Alignment .CenterHorizontally ,
186+ modifier = Modifier .fillMaxWidth(),
187+ ) {
188+ Icon (
189+ Icons .AutoMirrored .Default .PlaylistPlay ,
190+ contentDescription = null ,
191+ )
192+ Text (
193+ text = Localization .localizeStreamCountMini(
194+ ctx,
195+ decoration.itemCount
196+ ),
197+ style = MaterialTheme .typography.labelMedium,
198+ maxLines = 1 ,
199+ )
200+ }
176201 }
177202 }
203+
204+ null -> {}
178205 }
179206 }
180207
@@ -229,8 +256,7 @@ private class LongPressablePreviews : CollectionPreviewParameterProvider<LongPre
229256 override val uploaderUrl: String = "https://www.youtube.com/@BlenderOfficial "
230257 override val viewCount: Long = 8765432
231258 override val uploadDate: Either <String , OffsetDateTime > = Either .left("16 years ago")
232- override val playlistSize: Long = 12
233- override val duration: Long = 500
259+ override val decoration: LongPressableDecoration = LongPressableDecoration .Playlist (12)
234260
235261 override fun getPlayQueue(): PlayQueue {
236262 return SinglePlayQueue (listOf(), 0)
@@ -244,8 +270,7 @@ private class LongPressablePreviews : CollectionPreviewParameterProvider<LongPre
244270 override val uploaderUrl: String = "https://www.youtube.com/@BlenderOfficial "
245271 override val viewCount: Long = 8765432
246272 override val uploadDate: Either <String , OffsetDateTime > = Either .left("16 years ago")
247- override val playlistSize: Long? = null
248- override val duration: Long = 500
273+ override val decoration: LongPressableDecoration = LongPressableDecoration .Duration (500)
249274
250275 override fun getPlayQueue(): PlayQueue {
251276 return SinglePlayQueue (listOf(), 0)
@@ -259,8 +284,7 @@ private class LongPressablePreviews : CollectionPreviewParameterProvider<LongPre
259284 override val uploaderUrl: String = "https://www.youtube.com/@BlenderOfficial "
260285 override val viewCount: Long? = null
261286 override val uploadDate: Either <String , OffsetDateTime >? = null
262- override val playlistSize: Long? = null
263- override val duration: Long? = null
287+ override val decoration: LongPressableDecoration ? = null
264288
265289 override fun getPlayQueue(): PlayQueue {
266290 return SinglePlayQueue (listOf(), 0)
@@ -275,8 +299,7 @@ private class LongPressablePreviews : CollectionPreviewParameterProvider<LongPre
275299 override val uploaderUrl: String? = null
276300 override val viewCount: Long? = null
277301 override val uploadDate: Either <String , OffsetDateTime >? = null
278- override val playlistSize: Long? = null
279- override val duration: Long = 500
302+ override val decoration: LongPressableDecoration = LongPressableDecoration .Live
280303
281304 override fun getPlayQueue(): PlayQueue {
282305 return SinglePlayQueue (listOf(), 0)
@@ -290,8 +313,7 @@ private class LongPressablePreviews : CollectionPreviewParameterProvider<LongPre
290313 override val uploaderUrl: String? = null
291314 override val viewCount: Long? = null
292315 override val uploadDate: Either <String , OffsetDateTime > = Either .right(OffsetDateTime .now().minusSeconds(12))
293- override val playlistSize: Long = 1500
294- override val duration: Long = 500
316+ override val decoration: LongPressableDecoration = LongPressableDecoration .Playlist (1500)
295317
296318 override fun getPlayQueue(): PlayQueue {
297319 return SinglePlayQueue (listOf(), 0)
@@ -306,8 +328,12 @@ private class LongPressablePreviews : CollectionPreviewParameterProvider<LongPre
306328private fun LongPressMenuPreview (
307329 @PreviewParameter(LongPressablePreviews ::class ) longPressable : LongPressable
308330) {
331+ DisposableEffect (null ) {
332+ Localization .initPrettyTime(Localization .resolvePrettyTime())
333+ onDispose {}
334+ }
309335 LongPressMenu (
310- longPressable = LongPressablePreviews ().values.toList()[ 4 ] ,
336+ longPressable = longPressable ,
311337 onDismissRequest = {},
312338 sheetState = rememberStandardBottomSheetState(), // makes it start out as open
313339 )
0 commit comments