From ce3a7c564d31f08183e0017b929ae30adf882084 Mon Sep 17 00:00:00 2001 From: dankl Date: Wed, 30 Oct 2019 23:26:15 +0100 Subject: [PATCH] Implemented returning booked transactions of last 90 days if retrieved from addAccount() --- .../android/ui/MainWindowPresenter.kt | 7 +++- .../android/ui/dialogs/AddAccountDialog.kt | 40 +++++++++++++++---- .../android/ui/home/HomeFragment.kt | 14 +------ .../main/res/layout/dialog_add_account.xml | 16 +++++++- .../src/main/res/values/dimens.xml | 3 ++ .../src/main/res/values/strings.xml | 17 ++++++++ .../kotlin/net/dankito/fints/FinTsClient.kt | 18 +++++---- .../response/client/AddAccountResponse.kt | 19 +++++++++ .../response/client/FinTsClientResponse.kt | 5 +++ 9 files changed, 109 insertions(+), 30 deletions(-) create mode 100644 fints4javaLib/src/main/kotlin/net/dankito/fints/response/client/AddAccountResponse.kt diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/MainWindowPresenter.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/MainWindowPresenter.kt index 27485108..95d5054a 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/MainWindowPresenter.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/MainWindowPresenter.kt @@ -6,6 +6,7 @@ import net.dankito.fints.FinTsClientCallback import net.dankito.fints.banks.BankFinder import net.dankito.fints.model.* import net.dankito.fints.model.mapper.BankDataMapper +import net.dankito.fints.response.client.AddAccountResponse import net.dankito.fints.response.client.FinTsClientResponse import net.dankito.fints.response.client.GetTransactionsResponse import net.dankito.utils.IThreadPool @@ -34,8 +35,8 @@ open class MainWindowPresenter(callback: FinTsClientCallback) { protected val accountAddedListeners = mutableListOf<(BankData, CustomerData) -> Unit>() - open fun checkIfAccountExists(bankInfo: BankInfo, customerId: String, pin: String, - callback: (FinTsClientResponse) -> Unit) { + open fun addAccountAsync(bankInfo: BankInfo, customerId: String, pin: String, + callback: (AddAccountResponse) -> Unit) { val bank = bankDataMapper.mapFromBankInfo(bankInfo) val customer = CustomerData(customerId, pin) @@ -44,6 +45,8 @@ open class MainWindowPresenter(callback: FinTsClientCallback) { if (response.isSuccessful) { accounts.put(customer, bank) + // TODO: show booked transactions of last 90 days in HomeFragment if available + callAccountAddedListeners(bank, customer) } diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/AddAccountDialog.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/AddAccountDialog.kt index 08b380b9..1fef98ce 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/AddAccountDialog.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/AddAccountDialog.kt @@ -1,5 +1,6 @@ package net.dankito.banking.fints4java.android.ui.dialogs +import android.content.DialogInterface import android.os.Bundle import android.support.v4.app.DialogFragment import android.support.v7.app.AlertDialog @@ -15,7 +16,7 @@ import net.dankito.banking.fints4java.android.R import net.dankito.banking.fints4java.android.ui.MainWindowPresenter import net.dankito.banking.fints4java.android.ui.adapter.BankListAdapter import net.dankito.fints.model.BankInfo -import net.dankito.fints.response.client.FinTsClientResponse +import net.dankito.fints.response.client.AddAccountResponse import net.dankito.utils.android.extensions.asActivity @@ -71,32 +72,57 @@ open class AddAccountDialog : DialogFragment() { val customerId = edtxtCustomerId.text.toString() val pin = edtxtPin.text.toString() + btnAddAccount.isEnabled = false + pgrbrAddAccount.visibility = View.VISIBLE + presenter.addAccountAsync(selectedBank, customerId, pin) { response -> context?.asActivity()?.runOnUiThread { + btnAddAccount.isEnabled = true + pgrbrAddAccount.visibility = View.GONE + handleAccountCheckResponseOnUiThread(response) } } } } - protected open fun handleAccountCheckResponseOnUiThread(response: FinTsClientResponse) { + protected open fun handleAccountCheckResponseOnUiThread(response: AddAccountResponse) { context?.let { context -> if (response.isSuccessful) { - AlertDialog.Builder(context) - .setMessage("Successfully added account") - .setPositiveButton(android.R.string.ok) { dialog, _ -> dialog.dismiss() } - .show() this.dismiss() + + val messageId = if (response.supportsRetrievingTransactionsOfLast90DaysWithoutTan) + R.string.dialog_add_account_message_successfully_added_account_support_retrieving_transactions_of_last_90_days_without_tan + else R.string.dialog_add_account_message_successfully_added_account + + AlertDialog.Builder(context) + .setMessage(messageId) + .setPositiveButton(R.string.yes) { dialog, _ -> retrieveAccountTransactionsAndDismiss(response, dialog) } + .setNeutralButton(R.string.later) { dialog, _ -> dialog.dismiss() } + .setNegativeButton(R.string.do_not_ask_anymore) { dialog, _ -> setDoNotAskAnymoreAndDismiss(dialog) } + .show() } else { AlertDialog.Builder(context) - .setMessage("Could not add account: ${response.exception ?: response.errorsToShowToUser.joinToString("\n")}") + .setMessage(context.getString(R.string.dialog_add_account_message_could_not_add_account, (response.exception ?: response.errorsToShowToUser.joinToString("\n")))) .setPositiveButton(android.R.string.ok) { dialog, _ -> dialog.dismiss() } .show() } } } + protected open fun retrieveAccountTransactionsAndDismiss(response: AddAccountResponse, messageDialog: DialogInterface) { + presenter.getAccountTransactionsAsync(response.bank, response.customer) { } // TODO: show error message if not successful. Here or in HomeFragment + + messageDialog.dismiss() + } + + protected open fun setDoNotAskAnymoreAndDismiss(messageDialog: DialogInterface) { + // TODO: set flag to never retrieve all account transactions + + messageDialog.dismiss() + } + protected val otherEditTextChangedWatcher = object : TextWatcher { 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 bd6a2a92..508a1e4e 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 @@ -18,12 +18,12 @@ import net.dankito.banking.fints4java.android.R import net.dankito.banking.fints4java.android.ui.MainWindowPresenter import net.dankito.banking.fints4java.android.ui.adapter.AccountTransactionAdapter import net.dankito.banking.fints4java.android.ui.dialogs.BankTransferDialog -import net.dankito.fints.model.BankData import net.dankito.fints.model.BankTransferData -import net.dankito.fints.model.CustomerData import net.dankito.fints.response.client.GetTransactionsResponse import net.dankito.utils.android.extensions.asActivity import java.math.BigDecimal +import java.util.* +import kotlin.concurrent.schedule class HomeFragment : Fragment() { @@ -135,16 +135,6 @@ class HomeFragment : Fragment() { // TODO: this is such a bad code style (context as? MainActivity)?.presenter?.let { presenter -> this.presenter = presenter - - presenter.addAccountAddedListener { bank, customer -> - retrieveAccountTransactions(bank, customer) - } - } - } - - private fun retrieveAccountTransactions(bank: BankData, customer: CustomerData) { - presenter.getAccountTransactionsAsync(bank, customer) { response -> - handleGetTransactionsResponse(response) } } diff --git a/fints4javaAndroidApp/src/main/res/layout/dialog_add_account.xml b/fints4javaAndroidApp/src/main/res/layout/dialog_add_account.xml index e6ec70e8..9c2709c9 100644 --- a/fints4javaAndroidApp/src/main/res/layout/dialog_add_account.xml +++ b/fints4javaAndroidApp/src/main/res/layout/dialog_add_account.xml @@ -95,12 +95,24 @@ android:enabled="false" /> + +