From 954db89e2f71d40593d2cc5e5d3fb4ee6b496131 Mon Sep 17 00:00:00 2001 From: dankl Date: Sun, 19 Jan 2020 16:22:43 +0100 Subject: [PATCH] Implemented that TAN media und procedures get updated and its changes persisted --- .../ui/presenter/MainWindowPresenter.kt | 15 +++++++++++- .../banking/fints4javaBankingClient.kt | 5 ++++ .../banking/mapper/fints4javaModelMapper.kt | 24 ++++++++++++------- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/MainWindowPresenter.kt b/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/MainWindowPresenter.kt index 997933c2..373f4baa 100644 --- a/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/MainWindowPresenter.kt +++ b/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/MainWindowPresenter.kt @@ -53,6 +53,8 @@ open class MainWindowPresenter( protected var selectedBankAccountsField = mutableListOf() + protected var saveAccountOnNextEnterTanInvocation = false + protected val accountsChangedListeners = mutableListOf<(List) -> Unit>() @@ -64,7 +66,18 @@ open class MainWindowPresenter( protected val callback: BankingClientCallback = object : BankingClientCallback { override fun enterTan(account: Account, tanChallenge: TanChallenge): EnterTanResult { - return router.getTanFromUserFromNonUiThread(account, tanChallenge, this@MainWindowPresenter) + if (saveAccountOnNextEnterTanInvocation) { + persistAccount(account) + saveAccountOnNextEnterTanInvocation = false + } + + val result = router.getTanFromUserFromNonUiThread(account, tanChallenge, this@MainWindowPresenter) + + if (result.changeTanProcedureTo != null || result.changeTanMediumTo != null) { // then either selected TAN medium or procedure will change -> save account on next call to enterTan() as then changes will be visible + saveAccountOnNextEnterTanInvocation = true + } + + return result } override fun enterTanGeneratorAtc(tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult { diff --git a/fints4javaBankingClient/src/main/kotlin/net/dankito/banking/fints4javaBankingClient.kt b/fints4javaBankingClient/src/main/kotlin/net/dankito/banking/fints4javaBankingClient.kt index 74ab6961..ad835ad7 100644 --- a/fints4javaBankingClient/src/main/kotlin/net/dankito/banking/fints4javaBankingClient.kt +++ b/fints4javaBankingClient/src/main/kotlin/net/dankito/banking/fints4javaBankingClient.kt @@ -45,12 +45,16 @@ open class fints4javaBankingClient( protected val client = FinTsClientForCustomer(bank, customer, webClient, base64Service, threadPool, object : FinTsClientCallback { override fun enterTan(customer: CustomerData, tanChallenge: TanChallenge): EnterTanResult { + mapper.updateTanMediaAndProcedures(account, customer) + val result = callback.enterTan(account, mapper.mapTanChallenge(tanChallenge)) return mapper.mapEnterTanResult(result, customer) } override fun enterTanGeneratorAtc(customer: CustomerData, tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult { + mapper.updateTanMediaAndProcedures(account, customer) + val result = callback.enterTanGeneratorAtc(mapper.mapTanMedium(tanMedium)) return mapper.mapEnterTanGeneratorAtcResult(result) @@ -84,4 +88,5 @@ open class fints4javaBankingClient( callback(mapper.mapResponse(response)) } } + } \ No newline at end of file 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 dffa6f0c..6ccb4706 100644 --- a/fints4javaBankingClient/src/main/kotlin/net/dankito/banking/mapper/fints4javaModelMapper.kt +++ b/fints4javaBankingClient/src/main/kotlin/net/dankito/banking/mapper/fints4javaModelMapper.kt @@ -64,14 +64,8 @@ open class fints4javaModelMapper { val account = Account(mappedBank, customer.customerId, customer.pin, customer.name, customer.userId) account.bankAccounts = mapBankAccounts(account, customer.accounts) - account.supportedTanProcedures = mapTanProcedures(customer.supportedTanProcedures) - if (customer.isTanProcedureSelected) { - account.selectedTanProcedure = findMappedTanProcedure(account, customer.selectedTanProcedure) - } - else { - account.selectedTanProcedure = null - } - account.tanMedia = mapTanMediums(customer.tanMedia) + + updateTanMediaAndProcedures(account, customer) return account } @@ -117,6 +111,20 @@ open class fints4javaModelMapper { } + open fun updateTanMediaAndProcedures(account: Account, customer: CustomerData) { + account.supportedTanProcedures = mapTanProcedures(customer.supportedTanProcedures) + + if (customer.isTanProcedureSelected) { + account.selectedTanProcedure = findMappedTanProcedure(account, customer.selectedTanProcedure) + } + else { + account.selectedTanProcedure = null + } + + account.tanMedia = mapTanMediums(customer.tanMedia) + } + + open fun mapTanProcedures(tanProcedures: List): List { return tanProcedures.map { mapTanProcedure(it) } }