@@ -136,15 +136,22 @@ fun SelectLocation(
136
136
LaunchedEffectCollect (vm.uiSideEffect) {
137
137
when (it) {
138
138
SelectLocationSideEffect .CloseScreen -> navigator.navigateUp()
139
- is SelectLocationSideEffect .LocationAddedToCustomList -> {
139
+ is SelectLocationSideEffect .LocationAddedToCustomList ->
140
+ launch {
141
+ snackbarHostState.showResultSnackbar(
142
+ context = context,
143
+ result = it.result,
144
+ onUndo = vm::performAction
145
+ )
146
+ }
147
+ is SelectLocationSideEffect .LocationRemovedFromCustomList ->
140
148
launch {
141
149
snackbarHostState.showResultSnackbar(
142
150
context = context,
143
151
result = it.result,
144
152
onUndo = vm::performAction
145
153
)
146
154
}
147
- }
148
155
}
149
156
}
150
157
@@ -181,6 +188,7 @@ fun SelectLocation(
181
188
removeOwnershipFilter = vm::removeOwnerFilter,
182
189
removeProviderFilter = vm::removeProviderFilter,
183
190
onAddLocationToList = vm::addLocationToList,
191
+ onRemoveLocationFromList = vm::removeLocationFromList,
184
192
onEditCustomListName = {
185
193
navigator.navigate(
186
194
EditCustomListNameDestination (customListId = it.id, initialName = it.name)
@@ -213,6 +221,9 @@ fun SelectLocationScreen(
213
221
removeProviderFilter : () -> Unit = {},
214
222
onAddLocationToList : (location: RelayItem , customList: RelayItem .CustomList ) -> Unit = { _, _ ->
215
223
},
224
+ onRemoveLocationFromList : (location: RelayItem , customList: RelayItem .CustomList ) -> Unit =
225
+ { _, _ ->
226
+ },
216
227
onEditCustomListName : (RelayItem .CustomList ) -> Unit = {},
217
228
onEditLocationsCustomList : (RelayItem .CustomList ) -> Unit = {},
218
229
onDeleteCustomList : (RelayItem .CustomList ) -> Unit = {}
@@ -233,6 +244,7 @@ fun SelectLocationScreen(
233
244
onCreateCustomList = onCreateCustomList,
234
245
onEditCustomLists = onEditCustomLists,
235
246
onAddLocationToList = onAddLocationToList,
247
+ onRemoveLocationFromList = onRemoveLocationFromList,
236
248
onEditCustomListName = onEditCustomListName,
237
249
onEditLocationsCustomList = onEditLocationsCustomList,
238
250
onDeleteCustomList = onDeleteCustomList,
@@ -331,6 +343,15 @@ fun SelectLocationScreen(
331
343
onShowEditBottomSheet = { customList ->
332
344
bottomSheetState =
333
345
BottomSheetState .ShowEditCustomListBottomSheet (customList)
346
+ },
347
+ onShowEditCustomListEntryBottomSheet = {
348
+ item: RelayItem ,
349
+ customList: RelayItem .CustomList ->
350
+ bottomSheetState =
351
+ BottomSheetState .ShowCustomListsEntryBottomSheet (
352
+ customList,
353
+ item,
354
+ )
334
355
}
335
356
)
336
357
item {
@@ -379,7 +400,8 @@ private fun LazyListScope.customLists(
379
400
backgroundColor : Color ,
380
401
onSelectRelay : (item: RelayItem ) -> Unit ,
381
402
onShowCustomListBottomSheet : () -> Unit ,
382
- onShowEditBottomSheet : (RelayItem .CustomList ) -> Unit
403
+ onShowEditBottomSheet : (RelayItem .CustomList ) -> Unit ,
404
+ onShowEditCustomListEntryBottomSheet : (item: RelayItem , RelayItem .CustomList ) -> Unit
383
405
) {
384
406
item(
385
407
contentType = { ContentType .HEADER },
@@ -407,6 +429,8 @@ private fun LazyListScope.customLists(
407
429
onLongClick = {
408
430
if (it is RelayItem .CustomList ) {
409
431
onShowEditBottomSheet(it)
432
+ } else if (it in customList.locations) {
433
+ onShowEditCustomListEntryBottomSheet(it, customList)
410
434
}
411
435
},
412
436
modifier = Modifier .animateContentSize().animateItemPlacement(),
@@ -467,6 +491,7 @@ private fun BottomSheets(
467
491
onCreateCustomList : (RelayItem ? ) -> Unit ,
468
492
onEditCustomLists : () -> Unit ,
469
493
onAddLocationToList : (RelayItem , RelayItem .CustomList ) -> Unit ,
494
+ onRemoveLocationFromList : (RelayItem , RelayItem .CustomList ) -> Unit ,
470
495
onEditCustomListName : (RelayItem .CustomList ) -> Unit ,
471
496
onEditLocationsCustomList : (RelayItem .CustomList ) -> Unit ,
472
497
onDeleteCustomList : (RelayItem .CustomList ) -> Unit ,
@@ -522,6 +547,16 @@ private fun BottomSheets(
522
547
closeBottomSheet = onCloseBottomSheet
523
548
)
524
549
}
550
+ is BottomSheetState .ShowCustomListsEntryBottomSheet -> {
551
+ CustomListEntryBottomSheet (
552
+ sheetState = sheetState,
553
+ onBackgroundColor = onBackgroundColor,
554
+ customList = bottomSheetState.customList,
555
+ item = bottomSheetState.item,
556
+ onRemoveLocationFromList = onRemoveLocationFromList,
557
+ closeBottomSheet = onCloseBottomSheet
558
+ )
559
+ }
525
560
null -> {
526
561
/* Do nothing */
527
562
}
@@ -715,6 +750,40 @@ private fun EditCustomListBottomSheet(
715
750
}
716
751
}
717
752
753
+ @OptIn(ExperimentalMaterial3Api ::class )
754
+ @Composable
755
+ private fun CustomListEntryBottomSheet (
756
+ onBackgroundColor : Color ,
757
+ sheetState : SheetState ,
758
+ customList : RelayItem .CustomList ,
759
+ item : RelayItem ,
760
+ onRemoveLocationFromList : (location: RelayItem , customList: RelayItem .CustomList ) -> Unit ,
761
+ closeBottomSheet : (animate: Boolean ) -> Unit
762
+ ) {
763
+ MullvadModalBottomSheet (
764
+ sheetState = sheetState,
765
+ onDismissRequest = { closeBottomSheet(false ) },
766
+ modifier = Modifier .testTag(SELECT_LOCATION_LOCATION_BOTTOM_SHEET_TEST_TAG )
767
+ ) { ->
768
+ HeaderCell (
769
+ text = stringResource(id = R .string.remove_location_from_list, item.name),
770
+ background = Color .Unspecified
771
+ )
772
+ HorizontalDivider (color = onBackgroundColor)
773
+
774
+ IconCell (
775
+ iconId = R .drawable.ic_remove,
776
+ title = stringResource(id = R .string.remove_button),
777
+ titleColor = onBackgroundColor,
778
+ onClick = {
779
+ onRemoveLocationFromList(item, customList)
780
+ closeBottomSheet(true )
781
+ },
782
+ background = Color .Unspecified
783
+ )
784
+ }
785
+ }
786
+
718
787
private suspend fun LazyListState.animateScrollAndCentralizeItem (index : Int ) {
719
788
val itemInfo = this .layoutInfo.visibleItemsInfo.firstOrNull { it.index == index }
720
789
if (itemInfo != null ) {
@@ -785,6 +854,11 @@ sealed interface BottomSheetState {
785
854
786
855
data class ShowCustomListsBottomSheet (val editListEnabled : Boolean ) : BottomSheetState
787
856
857
+ data class ShowCustomListsEntryBottomSheet (
858
+ val customList : RelayItem .CustomList ,
859
+ val item : RelayItem
860
+ ) : BottomSheetState
861
+
788
862
data class ShowLocationBottomSheet (
789
863
val customLists : List <RelayItem .CustomList >,
790
864
val item : RelayItem
0 commit comments