@@ -22,13 +22,16 @@ import androidx.compose.ui.res.stringResource
22
22
import androidx.compose.ui.tooling.preview.Preview
23
23
import com.ramcosta.composedestinations.annotation.Destination
24
24
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
25
+ import com.ramcosta.composedestinations.result.NavResult
26
+ import com.ramcosta.composedestinations.result.ResultRecipient
25
27
import net.mullvad.mullvadvpn.R
26
28
import net.mullvad.mullvadvpn.compose.cell.TwoRowCell
27
29
import net.mullvad.mullvadvpn.compose.component.MullvadCircularProgressIndicatorLarge
28
30
import net.mullvad.mullvadvpn.compose.component.NavigateBackIconButton
29
31
import net.mullvad.mullvadvpn.compose.component.ScaffoldWithMediumTopBar
30
32
import net.mullvad.mullvadvpn.compose.component.SpacedColumn
31
33
import net.mullvad.mullvadvpn.compose.destinations.CustomListLocationsDestination
34
+ import net.mullvad.mullvadvpn.compose.destinations.DeleteCustomListConfirmationDialogDestination
32
35
import net.mullvad.mullvadvpn.compose.destinations.EditCustomListNameDestination
33
36
import net.mullvad.mullvadvpn.compose.state.EditCustomListState
34
37
import net.mullvad.mullvadvpn.compose.transitions.SlideInFromRightTransition
@@ -51,7 +54,12 @@ fun PreviewEditCustomListScreen() {
51
54
52
55
@Composable
53
56
@Destination(style = SlideInFromRightTransition ::class )
54
- fun EditCustomList (navigator : DestinationsNavigator , customListId : String ) {
57
+ fun EditCustomList (
58
+ navigator : DestinationsNavigator ,
59
+ customListId : String ,
60
+ confirmDeleteListResultRecipient :
61
+ ResultRecipient <DeleteCustomListConfirmationDialogDestination , Boolean >
62
+ ) {
55
63
val viewModel =
56
64
koinViewModel<EditCustomListViewModel >(parameters = { parametersOf(customListId) })
57
65
@@ -63,10 +71,26 @@ fun EditCustomList(navigator: DestinationsNavigator, customListId: String) {
63
71
}
64
72
}
65
73
74
+ confirmDeleteListResultRecipient.onNavResult {
75
+ when (it) {
76
+ NavResult .Canceled -> {
77
+ // Do nothing
78
+ }
79
+ is NavResult .Value ->
80
+ if (it.value) {
81
+ viewModel.deleteList()
82
+ }
83
+ }
84
+ }
85
+
66
86
val uiState by viewModel.uiState.collectAsState()
67
87
EditCustomListScreen (
68
88
uiState = uiState,
69
- onDeleteList = { viewModel.deleteList() },
89
+ onDeleteList = { name ->
90
+ navigator.navigate(DeleteCustomListConfirmationDialogDestination (name)) {
91
+ launchSingleTop = true
92
+ }
93
+ },
70
94
onNameClicked = { id, name -> navigator.navigate(EditCustomListNameDestination (id, name)) },
71
95
onLocationsClicked = {
72
96
navigator.navigate(CustomListLocationsDestination (customListKey = it, newList = false ))
@@ -78,7 +102,7 @@ fun EditCustomList(navigator: DestinationsNavigator, customListId: String) {
78
102
@Composable
79
103
fun EditCustomListScreen (
80
104
uiState : EditCustomListState ,
81
- onDeleteList : () -> Unit = {},
105
+ onDeleteList : (name: String ) -> Unit = {},
82
106
onNameClicked : (id: String , name: String ) -> Unit = { _, _ -> },
83
107
onLocationsClicked : (String ) -> Unit = {},
84
108
onBackClick : () -> Unit = {}
@@ -91,7 +115,7 @@ fun EditCustomListScreen(
91
115
ScaffoldWithMediumTopBar (
92
116
appBarTitle = title,
93
117
navigationIcon = { NavigateBackIconButton (onNavigateBack = onBackClick) },
94
- actions = { Actions (onDeleteList = onDeleteList) },
118
+ actions = { Actions (onDeleteList = { onDeleteList(title) } ) },
95
119
) { modifier: Modifier ->
96
120
SpacedColumn (modifier = modifier, alignment = Alignment .Top ) {
97
121
when (uiState) {
0 commit comments