@@ -62,8 +62,6 @@ import androidx.compose.ui.text.Placeholder
6262import androidx.compose.ui.text.PlaceholderVerticalAlign
6363import androidx.compose.ui.text.SpanStyle
6464import androidx.compose.ui.text.buildAnnotatedString
65- import androidx.compose.ui.text.font.FontWeight
66- import androidx.compose.ui.text.style.TextDecoration
6765import androidx.compose.ui.text.withStyle
6866import androidx.compose.ui.tooling.preview.Preview
6967import androidx.compose.ui.tooling.preview.PreviewParameter
@@ -117,6 +115,7 @@ fun getLongPressMenuView(
117115}
118116
119117internal val MinButtonWidth = 86 .dp
118+ internal val ThumbnailHeight = 60 .dp
120119
121120@Composable
122121fun LongPressMenu (
@@ -166,8 +165,12 @@ private fun LongPressMenuContent(
166165 .fillMaxWidth()
167166 .padding(start = 6 .dp, end = 6 .dp, bottom = 16 .dp)
168167 ) {
169- val buttonHeight = MinButtonWidth // landscape aspect ratio, square in the limit
170- val headerWidthInButtons = 5 // the header is 5 times as wide as the buttons
168+ // landscape aspect ratio, 1:1 square in the limit
169+ val buttonHeight = MinButtonWidth
170+ // max width for the portrait/full-width header, measured in button widths
171+ val maxHeaderWidthInButtonsFullSpan = 5
172+ // width for the landscape/reduced header, measured in button widths
173+ val headerWidthInButtonsReducedSpan = 4
171174 val buttonsPerRow = (this .maxWidth / MinButtonWidth ).toInt()
172175
173176 // the channel icon goes in the menu header, so do not show a button for it
@@ -217,33 +220,36 @@ private fun LongPressMenuContent(
217220 .weight(1F ),
218221 )
219222 rowIndex + = 1
220- } else if (headerWidthInButtons >= buttonsPerRow) {
221- // this branch is taken if the header is going to fit on one line
222- // (i.e. on phones in portrait)
223+ } else if (maxHeaderWidthInButtonsFullSpan >= buttonsPerRow) {
224+ // this branch is taken if the full-span header is going to fit on one
225+ // line (i.e. on phones in portrait)
223226 LongPressMenuHeader (
224227 item = longPressable,
225228 onUploaderClick = onUploaderClick,
226229 modifier = Modifier
230+ .padding(start = 6 .dp, end = 6 .dp, bottom = 6 .dp)
227231 // leave the height as small as possible, since it's the
228232 // only item on the row anyway
229- .padding(start = 6 .dp, end = 6 .dp, bottom = 6 .dp)
230233 .fillMaxWidth()
231- .weight(headerWidthInButtons .toFloat()),
234+ .weight(maxHeaderWidthInButtonsFullSpan .toFloat()),
232235 )
233- rowIndex + = headerWidthInButtons
236+ rowIndex + = maxHeaderWidthInButtonsFullSpan
234237 } else {
235238 // this branch is taken if the header will have some buttons to its
236- // right (i.e. on tablets or on phones in landscape)
239+ // right (i.e. on tablets, or on phones in landscape), and we have the
240+ // header's reduced span be less than its full span so that when this
241+ // branch is taken, at least two buttons will be on the right side of
242+ // the header (just one button would look off).
237243 LongPressMenuHeader (
238244 item = longPressable,
239245 onUploaderClick = onUploaderClick,
240246 modifier = Modifier
241- .padding(6 .dp)
242- .heightIn(min = 70 .dp )
247+ .padding(start = 8 .dp, top = 11 .dp, bottom = 11 .dp)
248+ .heightIn(min = ThumbnailHeight )
243249 .fillMaxWidth()
244- .weight(headerWidthInButtons .toFloat()),
250+ .weight(headerWidthInButtonsReducedSpan .toFloat()),
245251 )
246- rowIndex + = headerWidthInButtons
252+ rowIndex + = headerWidthInButtonsReducedSpan
247253 }
248254 actionIndex + = 1
249255 }
@@ -313,7 +319,7 @@ fun LongPressMenuHeader(
313319 val ctx = LocalContext .current
314320
315321 Surface (
316- color = MaterialTheme .colorScheme.surfaceVariant ,
322+ color = MaterialTheme .colorScheme.surfaceContainer ,
317323 contentColor = MaterialTheme .colorScheme.onSurfaceVariant,
318324 shape = MaterialTheme .shapes.large,
319325 modifier = modifier,
@@ -327,8 +333,8 @@ fun LongPressMenuHeader(
327333 placeholder = painterResource(R .drawable.placeholder_thumbnail_video),
328334 error = painterResource(R .drawable.placeholder_thumbnail_video),
329335 modifier = Modifier
330- .height(70 .dp )
331- .widthIn(max = 125 .dp ) // 16:9 thumbnail at most
336+ .height(ThumbnailHeight )
337+ .widthIn(max = ThumbnailHeight * 16 / 9 ) // 16:9 thumbnail at most
332338 .clip(MaterialTheme .shapes.large)
333339 )
334340 }
@@ -380,7 +386,7 @@ fun LongPressMenuHeader(
380386 contentColor = Color .White ,
381387 modifier = Modifier
382388 .align(Alignment .TopEnd )
383- .size(width = 40 .dp, height = 70 .dp )
389+ .size(width = 40 .dp, height = ThumbnailHeight )
384390 .clip(MaterialTheme .shapes.large),
385391 ) {
386392 Column (
@@ -409,7 +415,7 @@ fun LongPressMenuHeader(
409415 }
410416
411417 Column (
412- modifier = Modifier .padding(vertical = 12 .dp),
418+ modifier = Modifier .padding(vertical = 8 .dp),
413419 ) {
414420 Text (
415421 text = item.title,
@@ -657,14 +663,16 @@ private fun LongPressMenuPreview(
657663 var useDarkTheme by remember { mutableStateOf(initialUseDarkTheme) }
658664
659665 AppTheme (useDarkTheme = useDarkTheme) {
660- // longPressable is null when running the preview in an emulator for some reason...
661- @Suppress(" USELESS_ELVIS" )
662- LongPressMenuContent (
663- longPressable = longPressable ? : LongPressablePreviews ().values.first(),
664- longPressActions = LongPressAction .Type .entries
665- // disable Enqueue actions just to show it off
666- .map { t -> t.buildAction({ t != EnqueueNext }) { } },
667- onDismissRequest = {},
668- )
666+ Surface (color = MaterialTheme .colorScheme.surfaceContainerLow) {
667+ // longPressable is null when running the preview in an emulator for some reason...
668+ @Suppress(" USELESS_ELVIS" )
669+ LongPressMenuContent (
670+ longPressable = longPressable ? : LongPressablePreviews ().values.first(),
671+ longPressActions = LongPressAction .Type .entries
672+ // disable Enqueue actions just to show it off
673+ .map { t -> t.buildAction({ t != EnqueueNext }) { } },
674+ onDismissRequest = {},
675+ )
676+ }
669677 }
670678}
0 commit comments