Cancelling current action when closing dialog
This commit is contained in:
parent
66d9214c4f
commit
8fde7985d8
2 changed files with 31 additions and 8 deletions
|
@ -13,9 +13,7 @@ import androidx.compose.ui.graphics.Color
|
|||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.coroutines.*
|
||||
import net.codinux.banking.ui.IOorDefault
|
||||
import net.codinux.banking.ui.composables.BankIcon
|
||||
import net.codinux.banking.ui.config.Colors
|
||||
|
@ -47,20 +45,33 @@ fun AddAccountDialog(
|
|||
|
||||
var isAddingAccount by remember { mutableStateOf(false) }
|
||||
|
||||
var addAccountJob: Job? = null
|
||||
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
|
||||
fun dismiss() {
|
||||
addAccountJob?.cancel()
|
||||
|
||||
addAccountJob = null
|
||||
|
||||
onDismiss()
|
||||
}
|
||||
|
||||
fun confirmCalled() {
|
||||
selectedBank?.let { bank ->
|
||||
isAddingAccount = true
|
||||
|
||||
coroutineScope.launch(Dispatchers.IOorDefault) {
|
||||
addAccountJob = coroutineScope.launch(Dispatchers.IOorDefault) {
|
||||
val successful = DI.bankingService.addAccount(bank, loginName, password, retrieveAllTransactions)
|
||||
|
||||
addAccountJob = null
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
isAddingAccount = false
|
||||
|
||||
if (successful) {
|
||||
onDismiss()
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +85,7 @@ fun AddAccountDialog(
|
|||
confirmButtonEnabled = isRequiredDataEntered && isAddingAccount == false,
|
||||
showProgressIndicatorOnConfirmButton = isAddingAccount,
|
||||
useMoreThanPlatformDefaultWidthOnMobile = true,
|
||||
onDismiss = onDismiss,
|
||||
onDismiss = { dismiss() },
|
||||
onConfirm = {
|
||||
confirmCalled()
|
||||
}
|
||||
|
|
|
@ -78,13 +78,23 @@ fun TransferMoneyDialog(
|
|||
|
||||
var isInitialized by remember { mutableStateOf(false) }
|
||||
|
||||
var transferMoneyJob: Job? = null
|
||||
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
|
||||
fun dismiss() {
|
||||
transferMoneyJob?.cancel() // TODO: is it senseful to stop to ongoing process? as we cannot know its state, e.g. if the bank server already executed the transfer
|
||||
|
||||
transferMoneyJob = null
|
||||
|
||||
onDismiss()
|
||||
}
|
||||
|
||||
fun confirmCalled() {
|
||||
isTransferringMoney = true
|
||||
|
||||
coroutineScope.launch(Dispatchers.IOorDefault) {
|
||||
transferMoneyJob = coroutineScope.launch(Dispatchers.IOorDefault) {
|
||||
val successful = bankingService.transferMoney(
|
||||
accountsToUser[senderAccount]!!, senderAccount,
|
||||
recipientName, recipientAccountIdentifier,
|
||||
|
@ -94,11 +104,13 @@ fun TransferMoneyDialog(
|
|||
// TODO: determine BIC to IBAN
|
||||
)
|
||||
|
||||
transferMoneyJob = null
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
isTransferringMoney = false
|
||||
|
||||
if (successful) {
|
||||
onDismiss()
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue