Skip to content

Commit e3b0de1

Browse files
committed
Dismiss long press menu after click on a button
1 parent d5cc530 commit e3b0de1

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,14 @@ fun LongPressMenu(
128128

129129
// the channel icon goes in the menu header, so do not show a button for it
130130
val actions = longPressActions.toMutableList()
131-
val showChannelAction = actions.popFirst { it.type == ShowChannelDetails }
132131
val ctx = LocalContext.current
132+
val onUploaderClick = actions.popFirst { it.type == ShowChannelDetails }
133+
?.let { showChannelDetailsAction ->
134+
{
135+
showChannelDetailsAction.action(ctx)
136+
onDismissRequest()
137+
}
138+
}
133139

134140
Column {
135141
var actionIndex = -1 // -1 indicates the header
@@ -157,7 +163,10 @@ fun LongPressMenu(
157163
LongPressMenuButton(
158164
icon = action.type.icon,
159165
text = stringResource(action.type.label),
160-
onClick = { action.action(ctx) },
166+
onClick = {
167+
action.action(ctx)
168+
onDismissRequest()
169+
},
161170
enabled = action.enabled(false),
162171
modifier = Modifier
163172
.height(buttonHeight)
@@ -171,7 +180,7 @@ fun LongPressMenu(
171180
// (i.e. on phones in portrait)
172181
LongPressMenuHeader(
173182
item = longPressable,
174-
onUploaderClickAction = showChannelAction?.action,
183+
onUploaderClick = onUploaderClick,
175184
modifier = Modifier
176185
// leave the height as small as possible, since it's the
177186
// only item on the row anyway
@@ -186,7 +195,7 @@ fun LongPressMenu(
186195
// right (i.e. on tablets or on phones in landscape)
187196
LongPressMenuHeader(
188197
item = longPressable,
189-
onUploaderClickAction = showChannelAction?.action,
198+
onUploaderClick = onUploaderClick,
190199
modifier = Modifier
191200
.padding(6.dp)
192201
.heightIn(min = 70.dp)
@@ -236,7 +245,7 @@ fun LongPressMenuDragHandle(onEditActions: () -> Unit = {}) {
236245
@Composable
237246
fun LongPressMenuHeader(
238247
item: LongPressable,
239-
onUploaderClickAction: ((context: Context) -> Unit)?,
248+
onUploaderClick: (() -> Unit)?,
240249
modifier: Modifier = Modifier,
241250
) {
242251
val ctx = LocalContext.current
@@ -346,7 +355,7 @@ fun LongPressMenuHeader(
346355

347356
val subtitle = getSubtitleAnnotatedString(
348357
item = item,
349-
showLink = onUploaderClickAction != null,
358+
showLink = onUploaderClick != null,
350359
linkColor = MaterialTheme.customColors.onSurfaceVariantLink,
351360
ctx = ctx,
352361
)
@@ -356,11 +365,13 @@ fun LongPressMenuHeader(
356365
Text(
357366
text = subtitle,
358367
style = MaterialTheme.typography.bodyMedium,
359-
modifier = if (onUploaderClickAction == null) {
368+
modifier = if (onUploaderClick == null) {
360369
Modifier
361370
} else {
362-
Modifier.clickable { onUploaderClickAction(ctx) }
363-
}.basicMarquee(iterations = Int.MAX_VALUE)
371+
Modifier.clickable(onClick = onUploaderClick)
372+
}
373+
.fillMaxWidth()
374+
.basicMarquee(iterations = Int.MAX_VALUE)
364375
)
365376
}
366377
}

0 commit comments

Comments
 (0)