Skip to content

Commit 4bf32f9

Browse files
committed
Add more previews to LongPressMenu
1 parent 6e22af8 commit 4bf32f9

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed

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

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import androidx.compose.foundation.layout.Arrangement
1414
import androidx.compose.foundation.layout.Box
1515
import androidx.compose.foundation.layout.BoxWithConstraints
1616
import androidx.compose.foundation.layout.Column
17+
import androidx.compose.foundation.layout.ExperimentalLayoutApi
18+
import androidx.compose.foundation.layout.FlowRow
1719
import androidx.compose.foundation.layout.PaddingValues
1820
import androidx.compose.foundation.layout.Row
1921
import androidx.compose.foundation.layout.Spacer
@@ -22,12 +24,10 @@ import androidx.compose.foundation.layout.height
2224
import androidx.compose.foundation.layout.heightIn
2325
import androidx.compose.foundation.layout.padding
2426
import androidx.compose.foundation.layout.size
25-
import androidx.compose.foundation.layout.width
2627
import androidx.compose.foundation.layout.widthIn
2728
import androidx.compose.material.icons.Icons
2829
import androidx.compose.material.icons.automirrored.filled.PlaylistPlay
29-
import androidx.compose.material.icons.filled.Panorama
30-
import androidx.compose.material.icons.filled.Settings
30+
import androidx.compose.material.icons.filled.Tune
3131
import androidx.compose.material3.BottomSheetDefaults
3232
import androidx.compose.material3.ExperimentalMaterial3Api
3333
import androidx.compose.material3.Icon
@@ -213,9 +213,8 @@ fun LongPressMenu(
213213
}
214214
}
215215

216-
@Preview
217216
@Composable
218-
fun LongPressMenuDragHandle(onEditActions: () -> Unit = {}) {
217+
fun LongPressMenuDragHandle(onEditActions: () -> Unit) {
219218
Box(
220219
modifier = Modifier.fillMaxWidth()
221220
) {
@@ -229,7 +228,7 @@ fun LongPressMenuDragHandle(onEditActions: () -> Unit = {}) {
229228
// show a small button here, it's not an important button and it shouldn't
230229
// capture the user attention
231230
Icon(
232-
imageVector = Icons.Default.Settings,
231+
imageVector = Icons.Default.Tune,
233232
contentDescription = stringResource(R.string.edit),
234233
// same color and height as the DragHandle
235234
tint = MaterialTheme.colorScheme.onSurfaceVariant,
@@ -241,6 +240,17 @@ fun LongPressMenuDragHandle(onEditActions: () -> Unit = {}) {
241240
}
242241
}
243242

243+
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO or Configuration.UI_MODE_TYPE_NORMAL)
244+
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL)
245+
@Composable
246+
private fun LongPressMenuDragHandlePreview() {
247+
AppTheme {
248+
Surface(color = MaterialTheme.colorScheme.surfaceContainerLow) {
249+
LongPressMenuDragHandle {}
250+
}
251+
}
252+
}
253+
244254
@Composable
245255
fun LongPressMenuHeader(
246256
item: LongPressable,
@@ -443,6 +453,8 @@ fun LongPressMenuButton(
443453
enabled: Boolean = true,
444454
modifier: Modifier = Modifier,
445455
) {
456+
// TODO possibly make it so that when you long-press on the button, the label appears on-screen
457+
// as a small popup, so in case the label text is cut off the users can still read it in full
446458
OutlinedButton(
447459
onClick = onClick,
448460
enabled = enabled,
@@ -477,15 +489,25 @@ fun LongPressMenuButton(
477489
}
478490
}
479491

480-
@Preview
492+
@ExperimentalLayoutApi
493+
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO or Configuration.UI_MODE_TYPE_NORMAL)
494+
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL)
481495
@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-
)
496+
private fun LongPressMenuButtonPreviews() {
497+
AppTheme {
498+
Surface(color = MaterialTheme.colorScheme.surfaceContainerLow) {
499+
FlowRow {
500+
for (entry in LongPressAction.Type.entries) {
501+
LongPressMenuButton(
502+
icon = entry.icon,
503+
text = stringResource(entry.label),
504+
onClick = { },
505+
modifier = Modifier.size(86.dp)
506+
)
507+
}
508+
}
509+
}
510+
}
489511
}
490512

491513
private class LongPressablePreviews : CollectionPreviewParameterProvider<LongPressable>(

0 commit comments

Comments
 (0)