Skip to content

Commit a73e756

Browse files
committed
Slight adjustments to long press menu
1 parent e3997c3 commit a73e756

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

app/src/main/java/org/schabi/newpipe/ui/components/menu/LongPressMenu.kt

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ import androidx.compose.foundation.layout.height
2222
import androidx.compose.foundation.layout.heightIn
2323
import androidx.compose.foundation.layout.padding
2424
import androidx.compose.foundation.layout.size
25+
import androidx.compose.foundation.layout.width
2526
import androidx.compose.foundation.layout.widthIn
2627
import androidx.compose.material.icons.Icons
2728
import androidx.compose.material.icons.automirrored.filled.PlaylistPlay
29+
import androidx.compose.material.icons.filled.Panorama
2830
import androidx.compose.material.icons.filled.Settings
2931
import androidx.compose.material3.BottomSheetDefaults
3032
import androidx.compose.material3.ExperimentalMaterial3Api
@@ -110,7 +112,7 @@ fun LongPressMenu(
110112
longPressActions: List<LongPressAction>,
111113
onDismissRequest: () -> Unit,
112114
onEditActions: () -> Unit = {}, // TODO handle this menu
113-
sheetState: SheetState = rememberModalBottomSheetState(),
115+
sheetState: SheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true),
114116
) {
115117
ModalBottomSheet(
116118
onDismissRequest,
@@ -122,8 +124,8 @@ fun LongPressMenu(
122124
.fillMaxWidth()
123125
.padding(start = 6.dp, end = 6.dp, bottom = 16.dp)
124126
) {
125-
val minButtonWidth = 80.dp
126-
val buttonHeight = 85.dp
127+
val minButtonWidth = 86.dp
128+
val buttonHeight = 86.dp
127129
val headerWidthInButtons = 5 // the header is 5 times as wide as the buttons
128130
val buttonsPerRow = (maxWidth / minButtonWidth).toInt()
129131

@@ -282,11 +284,13 @@ fun LongPressMenuHeader(
282284
) {
283285
Text(
284286
text = Localization.getDurationString(decoration.duration),
285-
modifier = Modifier.padding(vertical = 2.dp, horizontal = 4.dp)
287+
style = MaterialTheme.typography.bodySmall,
288+
modifier = Modifier.padding(vertical = 2.dp, horizontal = 4.dp),
286289
)
287290
}
288291
}
289292
}
293+
290294
is LongPressable.Decoration.Live -> {
291295
// only show "Live" if there is a thumbnail
292296
if (item.thumbnailUrl != null) {
@@ -300,6 +304,7 @@ fun LongPressMenuHeader(
300304
) {
301305
Text(
302306
text = stringResource(R.string.duration_live).uppercase(),
307+
style = MaterialTheme.typography.bodySmall,
303308
modifier = Modifier.padding(vertical = 2.dp, horizontal = 4.dp)
304309
)
305310
}
@@ -343,11 +348,17 @@ fun LongPressMenuHeader(
343348
Column(
344349
modifier = Modifier.padding(vertical = 12.dp, horizontal = 12.dp),
345350
) {
351+
val marquee = Modifier.basicMarquee(
352+
// wait some time before starting animations, to not distract the user
353+
initialDelayMillis = 4000,
354+
iterations = Int.MAX_VALUE
355+
)
356+
346357
Text(
347358
text = item.title,
348359
style = MaterialTheme.typography.titleMedium,
349360
maxLines = 1,
350-
modifier = Modifier.basicMarquee(iterations = Int.MAX_VALUE),
361+
modifier = marquee,
351362
)
352363

353364
val subtitle = getSubtitleAnnotatedString(
@@ -368,7 +379,7 @@ fun LongPressMenuHeader(
368379
Modifier.clickable(onClick = onUploaderClick)
369380
}
370381
.fillMaxWidth()
371-
.basicMarquee(iterations = Int.MAX_VALUE)
382+
.then(marquee)
372383
)
373384
}
374385
}
@@ -466,6 +477,17 @@ fun LongPressMenuButton(
466477
}
467478
}
468479

480+
@Preview
481+
@Composable
482+
private fun LongPressMenuButtonPreview() {
483+
LongPressMenuButton(
484+
icon = Icons.Default.Panorama,
485+
text = "Set as playlist thumbnail",
486+
onClick = { },
487+
modifier = Modifier.width(86.dp)
488+
)
489+
}
490+
469491
private class LongPressablePreviews : CollectionPreviewParameterProvider<LongPressable>(
470492
listOf(
471493
LongPressable(
@@ -498,6 +520,16 @@ private class LongPressablePreviews : CollectionPreviewParameterProvider<LongPre
498520
uploadDate = null,
499521
decoration = null,
500522
),
523+
LongPressable(
524+
title = LoremIpsum().values.first(),
525+
url = "https://www.youtube.com/watch?v=YE7VzlLtp-4",
526+
thumbnailUrl = "https://i.ytimg.com/vi_webp/YE7VzlLtp-4/maxresdefault.webp",
527+
uploader = null,
528+
uploaderUrl = null,
529+
viewCount = null,
530+
uploadDate = null,
531+
decoration = LongPressable.Decoration.Duration(500),
532+
),
501533
LongPressable(
502534
title = LoremIpsum().values.first(),
503535
url = "https://www.youtube.com/watch?v=YE7VzlLtp-4",

0 commit comments

Comments
 (0)