From ec2c8fc5c9e02ad3ae4a8b22ee7a86d6265577df Mon Sep 17 00:00:00 2001 From: dankito Date: Wed, 29 Apr 2020 22:46:31 +0200 Subject: [PATCH] Implemented not showing an error message if user cancelled action (e.g. entering TAN or selecting a TAN medium) --- .../cashtransfer/TransferMoneyDialog.kt | 2 +- .../ui/javafx/dialogs/tan/EnterTanDialog.kt | 2 +- .../ui/model/responses/AddAccountResponse.kt | 5 ++-- .../model/responses/BankingClientResponse.kt | 3 +- .../responses/GetTransactionsResponse.kt | 5 ++-- .../android/ui/dialogs/EnterTanDialog.kt | 2 +- .../android/ui/dialogs/TransferMoneyDialog.kt | 30 ++++++++++--------- .../android/ui/home/HomeFragment.kt | 2 +- .../banking/mapper/fints4javaModelMapper.kt | 3 +- .../kotlin/net/dankito/fints/FinTsClient.kt | 2 +- .../net/dankito/fints/response/Response.kt | 4 +-- .../response/client/FinTsClientResponse.kt | 5 +++- 12 files changed, 37 insertions(+), 28 deletions(-) diff --git a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/cashtransfer/TransferMoneyDialog.kt b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/cashtransfer/TransferMoneyDialog.kt index 5b65efac..2000e611 100644 --- a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/cashtransfer/TransferMoneyDialog.kt +++ b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/cashtransfer/TransferMoneyDialog.kt @@ -274,7 +274,7 @@ open class TransferMoneyDialog @JvmOverloads constructor( dialogService.showInfoMessage(String.format(messages["transfer.money.dialog.message.transfer.cash.success"], transferData.amount, currency, transferData.creditorName), null, currentStage) } - else { + else if (response.userCancelledAction == false) { dialogService.showErrorMessage(String.format(messages["transfer.money.dialog.message.transfer.cash.error"], transferData.amount, currency, transferData.creditorName, response.errorToShowToUser), null, response.error, currentStage) } diff --git a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/EnterTanDialog.kt b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/EnterTanDialog.kt index c39518ae..f1348d1f 100644 --- a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/EnterTanDialog.kt +++ b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/EnterTanDialog.kt @@ -196,7 +196,7 @@ open class EnterTanDialog( close() } - else { + else if (response.userCancelledAction == false) { dialogService.showErrorMessageOnUiThread(String.format(messages["enter.tan.dialog.tan.error.changing.tan.medium"], newUsedTanMedium.displayName, response.errorToShowToUser), null, response.error, currentStage) } diff --git a/BankingUiCommon/src/main/java/net/dankito/banking/ui/model/responses/AddAccountResponse.kt b/BankingUiCommon/src/main/java/net/dankito/banking/ui/model/responses/AddAccountResponse.kt index e88aafe8..caaa9fa1 100644 --- a/BankingUiCommon/src/main/java/net/dankito/banking/ui/model/responses/AddAccountResponse.kt +++ b/BankingUiCommon/src/main/java/net/dankito/banking/ui/model/responses/AddAccountResponse.kt @@ -14,9 +14,10 @@ open class AddAccountResponse( bookedTransactionsOfLast90Days: Map> = mapOf(), unbookedTransactionsOfLast90Days: Map> = mapOf(), balances: Map = mapOf(), - error: Exception? = null + error: Exception? = null, + userCancelledAction: Boolean = false ) - : GetTransactionsResponse(isSuccessful, errorToShowToUser, bookedTransactionsOfLast90Days, unbookedTransactionsOfLast90Days, balances, error) { + : GetTransactionsResponse(isSuccessful, errorToShowToUser, bookedTransactionsOfLast90Days, unbookedTransactionsOfLast90Days, balances, error, userCancelledAction) { override fun toString(): String { return account.toString() + " " + super.toString() diff --git a/BankingUiCommon/src/main/java/net/dankito/banking/ui/model/responses/BankingClientResponse.kt b/BankingUiCommon/src/main/java/net/dankito/banking/ui/model/responses/BankingClientResponse.kt index abcde0b6..89082782 100644 --- a/BankingUiCommon/src/main/java/net/dankito/banking/ui/model/responses/BankingClientResponse.kt +++ b/BankingUiCommon/src/main/java/net/dankito/banking/ui/model/responses/BankingClientResponse.kt @@ -4,7 +4,8 @@ package net.dankito.banking.ui.model.responses open class BankingClientResponse( val isSuccessful: Boolean, val errorToShowToUser: String?, - val error: Exception? = null + val error: Exception? = null, + val userCancelledAction: Boolean = false // TODO: not implemented in hbci4jBankingClient yet ) { diff --git a/BankingUiCommon/src/main/java/net/dankito/banking/ui/model/responses/GetTransactionsResponse.kt b/BankingUiCommon/src/main/java/net/dankito/banking/ui/model/responses/GetTransactionsResponse.kt index 1a266c75..9125a8d6 100644 --- a/BankingUiCommon/src/main/java/net/dankito/banking/ui/model/responses/GetTransactionsResponse.kt +++ b/BankingUiCommon/src/main/java/net/dankito/banking/ui/model/responses/GetTransactionsResponse.kt @@ -11,6 +11,7 @@ open class GetTransactionsResponse( val bookedTransactions: Map> = mapOf(), val unbookedTransactions: Map> = mapOf(), val balances: Map = mapOf(), - error: Exception? = null + error: Exception? = null, + userCancelledAction: Boolean = false ) - : BankingClientResponse(isSuccessful, errorToShowToUser, error) + : BankingClientResponse(isSuccessful, errorToShowToUser, error, userCancelledAction) diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/EnterTanDialog.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/EnterTanDialog.kt index 0a405daa..a03aca40 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/EnterTanDialog.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/EnterTanDialog.kt @@ -205,7 +205,7 @@ open class EnterTanDialog : DialogFragment() { } .show() } - else { + else if (response.userCancelledAction == false) { AlertDialog.Builder(context) .setMessage(context.getString(R.string.dialog_enter_tan_error_changing_tan_medium, newUsedTanMedium.displayName, response.errorToShowToUser)) .setPositiveButton(android.R.string.ok) { dialog, _ -> dialog.dismiss() } diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/TransferMoneyDialog.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/TransferMoneyDialog.kt index 1fe02508..2962eeef 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/TransferMoneyDialog.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/TransferMoneyDialog.kt @@ -213,21 +213,23 @@ open class TransferMoneyDialog : DialogFragment() { protected open fun handleTransferMoneyResultOnUiThread(transferData: TransferMoneyData, response: BankingClientResponse) { context?.let { context -> - val message = if (response.isSuccessful) { - context.getString(R.string.dialog_transfer_money_message_transfer_successful, - String.format("%.02f", transferData.amount), "€", transferData.creditorName) // TODO: where to get currency from? - } - else { - context.getString(R.string.dialog_transfer_money_message_transfer_failed, - String.format("%.02f", transferData.amount), "€", transferData.creditorName, // TODO: where to get currency from? - response.errorToShowToUser - ) - } + if (response.userCancelledAction == false) { + val message = if (response.isSuccessful) { + context.getString(R.string.dialog_transfer_money_message_transfer_successful, + String.format("%.02f", transferData.amount), "€", transferData.creditorName) // TODO: where to get currency from? + } + else { + context.getString(R.string.dialog_transfer_money_message_transfer_failed, + String.format("%.02f", transferData.amount), "€", transferData.creditorName, // TODO: where to get currency from? + response.errorToShowToUser + ) + } - AlertDialog.Builder(context) - .setMessage(message) - .setPositiveButton(android.R.string.ok) { dialog, _ -> dialog.dismiss() } - .show() + AlertDialog.Builder(context) + .setMessage(message) + .setPositiveButton(android.R.string.ok) { dialog, _ -> dialog.dismiss() } + .show() + } this.dismiss() } diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/home/HomeFragment.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/home/HomeFragment.kt index 553a70e8..e6ab5deb 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/home/HomeFragment.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/home/HomeFragment.kt @@ -158,7 +158,7 @@ class HomeFragment : Fragment() { if (response.isSuccessful) { updateTransactionsToDisplayOnUiThread() } - else { + else if (response.userCancelledAction == false) { // if user cancelled entering TAN then don't show a error message AlertDialog.Builder(activity) // TODO: may show account name in message .setMessage(activity.getString(R.string.fragment_home_could_not_retrieve_account_transactions, response.errorToShowToUser)) .setPositiveButton(android.R.string.ok) { dialog, _ -> dialog.dismiss() } diff --git a/fints4javaBankingClient/src/main/kotlin/net/dankito/banking/mapper/fints4javaModelMapper.kt b/fints4javaBankingClient/src/main/kotlin/net/dankito/banking/mapper/fints4javaModelMapper.kt index 63b68b9f..e41b97b2 100644 --- a/fints4javaBankingClient/src/main/kotlin/net/dankito/banking/mapper/fints4javaModelMapper.kt +++ b/fints4javaBankingClient/src/main/kotlin/net/dankito/banking/mapper/fints4javaModelMapper.kt @@ -42,6 +42,7 @@ open class fints4javaModelMapper { mappedBookedTransactions, mapOf(), // TODO: map unbooked transactions balances, + response.userCancelledAction, response.exception) } @@ -51,7 +52,7 @@ open class fints4javaModelMapper { mapOf(bankAccount to mapTransactions(bankAccount, response.bookedTransactions)), mapOf(), // TODO: map unbooked transactions response.balance?.let { mapOf(bankAccount to it) } ?: mapOf(), - response.exception) + response.exception, response.userCancelledAction) } open fun mapErrorToShowToUser(response: FinTsClientResponse): String? { diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt index c1321958..b4a15564 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt @@ -663,7 +663,7 @@ open class FinTsClient @JvmOverloads constructor( else if (enteredTanResult.enteredTan == null) { // i tried to send a HKTAN with cancelJob = true but then i saw there are no tan procedures that support cancellation (at least not at my bank) // but it's not required anyway, tan times out after some time. Simply don't respond anything and close dialog - response.tanRequiredButNotProvided = true + response.tanRequiredButUserDidNotEnterOne = true } else { return sendTanToBank(enteredTanResult.enteredTan, tanResponse, bank, customer, dialogData) diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/Response.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/Response.kt index 9c82c32b..b48c8211 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/Response.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/Response.kt @@ -27,11 +27,11 @@ open class Response( open val responseContainsErrors: Boolean get() = exception == null && messageFeedback?.isError == true - open var tanRequiredButNotProvided = false + open var tanRequiredButUserDidNotEnterOne = false open val successful: Boolean get() = noTanProcedureSelected == false && couldCreateMessage && didReceiveResponse - && responseContainsErrors == false && tanRequiredButNotProvided == false + && responseContainsErrors == false && tanRequiredButUserDidNotEnterOne == false open val isStrongAuthenticationRequired: Boolean get() = tanResponse?.isStrongAuthenticationRequired == true diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/client/FinTsClientResponse.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/client/FinTsClientResponse.kt index 96d5ac0b..46c5f6d7 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/client/FinTsClientResponse.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/client/FinTsClientResponse.kt @@ -20,6 +20,8 @@ open class FinTsClientResponse( */ val exception: Exception? = null, + val userCancelledAction: Boolean = false, + val isJobAllowed: Boolean = true, val isJobVersionSupported: Boolean = true, val allowedVersions: List = listOf(), @@ -29,7 +31,8 @@ open class FinTsClientResponse( constructor(response: Response) : this(response.successful, response.noTanProcedureSelected, response.isStrongAuthenticationRequired, response.tanResponse, response.errorsToShowToUser, - response.exception, response.messageCreationError?.isJobAllowed ?: true, + response.exception, response.tanRequiredButUserDidNotEnterOne, + response.messageCreationError?.isJobAllowed ?: true, response.messageCreationError?.isJobVersionSupported ?: true, response.messageCreationError?.allowedVersions ?: listOf(), response.messageCreationError?.supportedVersions ?: listOf())