1
1
package net.mullvad.mullvadvpn.compose.cell
2
2
3
3
import androidx.compose.animation.animateContentSize
4
+ import androidx.compose.foundation.ExperimentalFoundationApi
4
5
import androidx.compose.foundation.Image
5
6
import androidx.compose.foundation.background
6
7
import androidx.compose.foundation.clickable
8
+ import androidx.compose.foundation.combinedClickable
7
9
import androidx.compose.foundation.layout.Box
8
10
import androidx.compose.foundation.layout.BoxScope
9
11
import androidx.compose.foundation.layout.Column
@@ -258,7 +260,8 @@ fun NormalRelayLocationCell(
258
260
inactiveColor : Color = MaterialTheme .colorScheme.error,
259
261
disabledColor : Color = MaterialTheme .colorScheme.onSecondary,
260
262
selectedItem : RelayItem ? = null,
261
- onSelectRelay : (item: RelayItem ) -> Unit = {}
263
+ onSelectRelay : (item: RelayItem ) -> Unit = {},
264
+ onLongClick : (item: RelayItem ) -> Unit = {}
262
265
) {
263
266
RelayLocationCell (
264
267
relay = relay,
@@ -304,6 +307,7 @@ fun NormalRelayLocationCell(
304
307
}
305
308
},
306
309
onClick = onSelectRelay,
310
+ onLongClick = onLongClick,
307
311
depth = 0
308
312
)
309
313
}
@@ -326,17 +330,20 @@ fun CheckableRelayLocationCell(
326
330
},
327
331
modifier = modifier,
328
332
onClick = { onRelayCheckedChange(it, ! selectedRelays.contains(it)) },
333
+ onLongClick = {},
329
334
depth = 0
330
335
)
331
336
}
332
337
338
+ @OptIn(ExperimentalFoundationApi ::class )
333
339
@Composable
334
340
private fun RelayLocationCell (
335
341
relay : RelayItem ,
336
342
leadingContent : @Composable BoxScope .(relay: RelayItem ) -> Unit ,
337
343
modifier : Modifier = Modifier ,
338
344
specialBackgroundColor : @Composable (relayItem: RelayItem ) -> Color ? = { null },
339
345
onClick : (item: RelayItem ) -> Unit ,
346
+ onLongClick : (item: RelayItem ) -> Unit ,
340
347
depth : Int
341
348
) {
342
349
val startPadding =
@@ -376,7 +383,13 @@ private fun RelayLocationCell(
376
383
)
377
384
) {
378
385
Row (
379
- modifier = Modifier .weight(1f ).clickable(enabled = relay.active) { onClick(relay) }
386
+ modifier =
387
+ Modifier .weight(1f )
388
+ .combinedClickable(
389
+ enabled = relay.active,
390
+ onClick = { onClick(relay) },
391
+ onLongClick = { onLongClick(relay) },
392
+ )
380
393
) {
381
394
Box (
382
395
modifier =
@@ -428,7 +441,8 @@ private fun RelayLocationCell(
428
441
modifier = Modifier .animateContentSize(),
429
442
leadingContent = leadingContent,
430
443
specialBackgroundColor = specialBackgroundColor,
431
- depth = depth + 1
444
+ onLongClick = onLongClick,
445
+ depth = depth + 1 ,
432
446
)
433
447
}
434
448
}
@@ -440,6 +454,7 @@ private fun RelayLocationCell(
440
454
modifier = Modifier .animateContentSize(),
441
455
leadingContent = leadingContent,
442
456
specialBackgroundColor = specialBackgroundColor,
457
+ onLongClick = onLongClick,
443
458
depth = depth + 1
444
459
)
445
460
}
@@ -452,6 +467,7 @@ private fun RelayLocationCell(
452
467
modifier = Modifier .animateContentSize(),
453
468
leadingContent = leadingContent,
454
469
specialBackgroundColor = specialBackgroundColor,
470
+ onLongClick = onLongClick,
455
471
depth = depth + 1
456
472
)
457
473
}
0 commit comments