Skip to content

Commit ddf5a3e

Browse files
committed
Support long-click on video preview
1 parent 223b0f8 commit ddf5a3e

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

collect_app/src/main/java/org/odk/collect/android/widgets/WidgetAnswerFactory.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ fun WidgetAnswer(
1212
modifier: Modifier = Modifier,
1313
prompt: FormEntryPrompt,
1414
answer: String?,
15-
viewModelProvider: ViewModelProvider
15+
viewModelProvider: ViewModelProvider,
16+
onLongClick: () -> Unit = {}
1617
) {
1718
if (answer != null) {
1819
when (prompt.controlType) {
19-
Constants.CONTROL_VIDEO_CAPTURE -> VideoWidgetAnswer.Container(modifier, answer, viewModelProvider)
20+
Constants.CONTROL_VIDEO_CAPTURE -> VideoWidgetAnswer.Container(modifier, answer, viewModelProvider, onLongClick)
2021
else -> throw IllegalArgumentException("Unsupported control type: ${prompt.controlType}")
2122
}
2223
}

collect_app/src/main/java/org/odk/collect/android/widgets/video/ExVideoWidget.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,14 @@ class ExVideoWidget(
6868
readOnly,
6969
buttonFontSize,
7070
onLaunchClick = { launchExternalApp() },
71-
onLongClick = { this.showContextMenu() }
71+
onLongClick = { showContextMenu() }
7272
) {
7373
WidgetAnswer(
7474
Modifier.padding(top = dimensionResource(id = dimen.margin_standard)),
7575
formEntryPrompt,
7676
binaryName,
77-
viewModelProvider
77+
viewModelProvider,
78+
onLongClick = { showContextMenu() }
7879
)
7980
}
8081
}

collect_app/src/main/java/org/odk/collect/android/widgets/video/VideoWidget.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,14 @@ class VideoWidget(
8383
)
8484
},
8585
onChooseClick = { chooseVideo() },
86-
onLongClick = { this.showContextMenu() }
86+
onLongClick = { showContextMenu() }
8787
) {
8888
WidgetAnswer(
8989
Modifier.padding(top = dimensionResource(id = dimen.margin_standard)),
9090
formEntryPrompt,
9191
binaryName,
92-
viewModelProvider
92+
viewModelProvider,
93+
onLongClick = { showContextMenu() }
9394
)
9495
}
9596
}

collect_app/src/main/java/org/odk/collect/android/widgets/video/VideoWidgetAnswer.kt

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package org.odk.collect.android.widgets.video
22

33
import androidx.compose.foundation.Image
44
import androidx.compose.foundation.background
5-
import androidx.compose.foundation.clickable
5+
import androidx.compose.foundation.combinedClickable
66
import androidx.compose.foundation.layout.Box
77
import androidx.compose.foundation.layout.fillMaxSize
88
import androidx.compose.foundation.layout.fillMaxWidth
@@ -26,38 +26,49 @@ import androidx.compose.ui.res.stringResource
2626
import androidx.compose.ui.unit.dp
2727
import androidx.lifecycle.ViewModelProvider
2828
import androidx.lifecycle.compose.collectAsStateWithLifecycle
29+
import org.odk.collect.androidshared.ui.multiclicksafe.MultiClickGuard
2930

3031
object VideoWidgetAnswer {
3132
@Composable
3233
fun Container(
3334
modifier: Modifier,
3435
answer: String,
35-
viewModelProvider: ViewModelProvider
36+
viewModelProvider: ViewModelProvider,
37+
onLongClick: () -> Unit
3638
) {
3739
val context = LocalContext.current
3840
val viewModel = viewModelProvider[VideoWidgetAnswerViewModel::class]
3941

4042
val bitmapFlow = remember(answer) { viewModel.getFrame(answer, context) }
4143
val bitmap by bitmapFlow.collectAsStateWithLifecycle()
4244

43-
Content(modifier, bitmap) {
44-
viewModel.playVideo(context, answer)
45-
}
45+
Content(
46+
modifier,
47+
bitmap,
48+
onPlayClick = { viewModel.playVideo(context, answer) },
49+
onLongClick = onLongClick
50+
)
4651
}
4752

4853
@Composable
4954
fun Content(
5055
modifier: Modifier,
5156
bitmap: ImageBitmap?,
52-
onPlayClick: () -> Unit
57+
onPlayClick: () -> Unit,
58+
onLongClick: () -> Unit
5359
) {
5460
Box(
5561
modifier = modifier
5662
.fillMaxWidth()
5763
.heightIn(max = 200.dp)
5864
.clip(MaterialTheme.shapes.large)
59-
.clickable(
60-
onClick = onPlayClick,
65+
.combinedClickable(
66+
onClick = {
67+
if (MultiClickGuard.allowClick()) {
68+
onPlayClick()
69+
}
70+
},
71+
onLongClick = onLongClick,
6172
onClickLabel = stringResource(org.odk.collect.strings.R.string.play_video)
6273
),
6374
contentAlignment = Alignment.Center

0 commit comments

Comments
 (0)