diff options
Diffstat (limited to 'android/app')
3 files changed, 134 insertions, 5 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/DeleteCustomListConfirmationDialog.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/DeleteCustomListConfirmationDialog.kt new file mode 100644 index 0000000000..236dedec6a --- /dev/null +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/DeleteCustomListConfirmationDialog.kt @@ -0,0 +1,96 @@ +package net.mullvad.mullvadvpn.compose.dialog + +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview +import com.ramcosta.composedestinations.annotation.Destination +import com.ramcosta.composedestinations.result.ResultBackNavigator +import com.ramcosta.composedestinations.spec.DestinationStyle +import net.mullvad.mullvadvpn.R +import net.mullvad.mullvadvpn.compose.button.NegativeButton +import net.mullvad.mullvadvpn.compose.button.PrimaryButton +import net.mullvad.mullvadvpn.compose.communication.CustomListResult +import net.mullvad.mullvadvpn.compose.util.LaunchedEffectCollect +import net.mullvad.mullvadvpn.lib.theme.AppTheme +import net.mullvad.mullvadvpn.lib.theme.Dimens +import net.mullvad.mullvadvpn.viewmodel.DeleteCustomListConfirmationSideEffect +import net.mullvad.mullvadvpn.viewmodel.DeleteCustomListConfirmationViewModel +import org.koin.androidx.compose.koinViewModel +import org.koin.core.parameter.parametersOf + +@Preview +@Composable +private fun PreviewRemoveDeviceConfirmationDialog() { + AppTheme { DeleteCustomListConfirmationDialog("My Custom List") } +} + +@Composable +@Destination(style = DestinationStyle.Dialog::class) +fun DeleteCustomList( + navigator: ResultBackNavigator<CustomListResult.Deleted>, + customListId: String, + name: String +) { + val viewModel: DeleteCustomListConfirmationViewModel = + koinViewModel(parameters = { parametersOf(customListId) }) + + LaunchedEffectCollect(viewModel.uiSideEffect) { + when (it) { + is DeleteCustomListConfirmationSideEffect.ReturnWithResult -> + navigator.navigateBack(result = it.result) + } + } + + DeleteCustomListConfirmationDialog( + name = name, + onDelete = viewModel::deleteCustomList, + onBack = navigator::navigateBack + ) +} + +@Composable +fun DeleteCustomListConfirmationDialog( + name: String, + onDelete: () -> Unit = {}, + onBack: () -> Unit = {} +) { + AlertDialog( + onDismissRequest = onBack, + icon = { + Icon( + modifier = Modifier.fillMaxWidth().height(Dimens.dialogIconHeight), + painter = painterResource(id = R.drawable.icon_alert), + contentDescription = stringResource(id = R.string.remove_button), + tint = Color.Unspecified + ) + }, + title = { + Text( + text = + stringResource(id = R.string.delete_custom_list_confirmation_description, name) + ) + }, + dismissButton = { + PrimaryButton( + modifier = Modifier.focusRequester(FocusRequester()), + onClick = onBack, + text = stringResource(id = R.string.cancel) + ) + }, + confirmButton = { + NegativeButton(onClick = onDelete, text = stringResource(id = R.string.delete)) + }, + containerColor = MaterialTheme.colorScheme.background + ) +} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/RemoveDeviceConfirmationDialog.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/RemoveDeviceConfirmationDialog.kt index 9c48c0a1e8..a0270989cf 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/RemoveDeviceConfirmationDialog.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/RemoveDeviceConfirmationDialog.kt @@ -1,7 +1,7 @@ package net.mullvad.mullvadvpn.compose.dialog +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.width import androidx.compose.material3.AlertDialog import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme @@ -13,7 +13,6 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.result.EmptyResultBackNavigator @@ -25,6 +24,7 @@ import net.mullvad.mullvadvpn.compose.button.PrimaryButton import net.mullvad.mullvadvpn.compose.component.HtmlText import net.mullvad.mullvadvpn.compose.component.textResource import net.mullvad.mullvadvpn.lib.theme.AppTheme +import net.mullvad.mullvadvpn.lib.theme.Dimens import net.mullvad.mullvadvpn.model.Device @Preview @@ -42,12 +42,12 @@ private fun PreviewRemoveDeviceConfirmationDialog() { @Composable fun RemoveDeviceConfirmationDialog(navigator: ResultBackNavigator<String>, device: Device) { AlertDialog( - onDismissRequest = { navigator.navigateBack() }, + onDismissRequest = navigator::navigateBack, icon = { Icon( + modifier = Modifier.fillMaxWidth().height(Dimens.dialogIconHeight), painter = painterResource(id = R.drawable.icon_alert), - contentDescription = "Remove", - modifier = Modifier.width(50.dp).height(50.dp), + contentDescription = stringResource(id = R.string.remove_button), tint = Color.Unspecified ) }, diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeleteCustomListConfirmationViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeleteCustomListConfirmationViewModel.kt new file mode 100644 index 0000000000..e3c7f45664 --- /dev/null +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeleteCustomListConfirmationViewModel.kt @@ -0,0 +1,33 @@ +package net.mullvad.mullvadvpn.viewmodel + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.flow.receiveAsFlow +import kotlinx.coroutines.launch +import net.mullvad.mullvadvpn.compose.communication.CustomListAction +import net.mullvad.mullvadvpn.compose.communication.CustomListResult +import net.mullvad.mullvadvpn.usecase.customlists.CustomListActionUseCase + +class DeleteCustomListConfirmationViewModel( + private val customListId: String, + private val customListActionUseCase: CustomListActionUseCase +) : ViewModel() { + private val _uiSideEffect = Channel<DeleteCustomListConfirmationSideEffect>(Channel.BUFFERED) + val uiSideEffect = _uiSideEffect.receiveAsFlow() + + fun deleteCustomList() { + viewModelScope.launch { + val result = + customListActionUseCase + .performAction(CustomListAction.Delete(customListId)) + .getOrThrow() + _uiSideEffect.send(DeleteCustomListConfirmationSideEffect.ReturnWithResult(result)) + } + } +} + +sealed class DeleteCustomListConfirmationSideEffect { + data class ReturnWithResult(val result: CustomListResult.Deleted) : + DeleteCustomListConfirmationSideEffect() +} |
