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"
/>
+
+
diff --git a/fints4javaAndroidApp/src/main/res/values/dimens.xml b/fints4javaAndroidApp/src/main/res/values/dimens.xml
index 1faf9058..fdedbe7f 100644
--- a/fints4javaAndroidApp/src/main/res/values/dimens.xml
+++ b/fints4javaAndroidApp/src/main/res/values/dimens.xml
@@ -18,6 +18,9 @@
40dp
12dp
120dp
+ 40dp
+ 40dp
+ 12dp
60dp
60dp
diff --git a/fints4javaAndroidApp/src/main/res/values/strings.xml b/fints4javaAndroidApp/src/main/res/values/strings.xml
index cede3f41..bb1ec47f 100644
--- a/fints4javaAndroidApp/src/main/res/values/strings.xml
+++ b/fints4javaAndroidApp/src/main/res/values/strings.xml
@@ -4,6 +4,11 @@
Select
Cancel
+ Yes
+ No
+ Later
+ Don\'t ask anymore
+
Search
Open navigation drawer
@@ -24,6 +29,18 @@
Customer Id:
Pin:
Add
+ Could not add account: %s
+
+ Successfully added account.
+ \n\nWould you like to fetch all account transactions now? If so entering a TAN is required.
+ \n\nEven if not, please choose your TAN procedure here:
+
+
+ Successfully added account.
+ \n\nYour bank supports retrieving account transactions of last 90 days without TAN. These are already displayed in background.
+ \n\nWould you like to fetch all account transactions now? If so entering a TAN is required.
+ \n\nEven if not, please choose your TAN procedure here:
+
Name:
IBAN:
diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt
index 80e21ab1..d89c0eaa 100644
--- a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt
+++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt
@@ -10,6 +10,7 @@ import net.dankito.fints.model.*
import net.dankito.fints.response.InstituteSegmentId
import net.dankito.fints.response.Response
import net.dankito.fints.response.ResponseParser
+import net.dankito.fints.response.client.AddAccountResponse
import net.dankito.fints.response.client.FinTsClientResponse
import net.dankito.fints.response.client.GetTransactionsResponse
import net.dankito.fints.response.segments.*
@@ -88,7 +89,7 @@ open class FinTsClient @JvmOverloads constructor(
}
- open fun getBankAndCustomerInfoForNewUser(bank: BankData, customer: CustomerData): FinTsClientResponse {
+ open fun getBankAndCustomerInfoForNewUser(bank: BankData, customer: CustomerData): AddAccountResponse {
val dialogData = DialogData()
// just to ensure settings are in its initial state and that bank sends use bank parameter (BPD),
@@ -107,19 +108,19 @@ open class FinTsClient @JvmOverloads constructor(
closeDialog(bank, customer, dialogData)
- return FinTsClientResponse(initDialogResponse)
+ return AddAccountResponse(initDialogResponse, bank, customer)
}
open fun addAccountAsync(bank: BankData, customer: CustomerData,
- callback: (FinTsClientResponse) -> Unit) {
+ callback: (AddAccountResponse) -> Unit) {
threadPool.runAsync {
callback(addAccount(bank, customer))
}
}
- open fun addAccount(bank: BankData, customer: CustomerData): FinTsClientResponse {
+ open fun addAccount(bank: BankData, customer: CustomerData): AddAccountResponse {
val newUserInfoResponse = getBankAndCustomerInfoForNewUser(bank, customer)
@@ -148,8 +149,11 @@ open class FinTsClient @JvmOverloads constructor(
customer.resetSelectedTanProcedure()
}
- return if (transactionsOfLast90DaysResponse.isSuccessful) transactionsOfLast90DaysResponse
- else synchronizeCustomerResponse
+ return AddAccountResponse(synchronizeCustomerResponse.toResponse(), bank, customer,
+ transactionsOfLast90DaysResponse.isSuccessful,
+ transactionsOfLast90DaysResponse.bookedTransactions,
+ transactionsOfLast90DaysResponse.unbookedTransactions,
+ transactionsOfLast90DaysResponse.balance)
}
@@ -180,7 +184,7 @@ open class FinTsClient @JvmOverloads constructor(
val ninetyDaysAgo = Date(Date().time - NinetyDaysAgoMilliseconds)
val response = getTransactions(
- GetTransactionsParameter(false, ninetyDaysAgo), bank, customer)
+ GetTransactionsParameter(true, ninetyDaysAgo), bank, customer)
customer.triedToRetrieveTransactionsOfLast90DaysWithoutTan = true
diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/response/client/AddAccountResponse.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/client/AddAccountResponse.kt
new file mode 100644
index 00000000..61c1acd0
--- /dev/null
+++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/response/client/AddAccountResponse.kt
@@ -0,0 +1,19 @@
+package net.dankito.fints.response.client
+
+import net.dankito.fints.model.AccountTransaction
+import net.dankito.fints.model.BankData
+import net.dankito.fints.model.CustomerData
+import net.dankito.fints.response.Response
+import java.math.BigDecimal
+
+
+open class AddAccountResponse(
+ response: Response,
+ val bank: BankData,
+ val customer: CustomerData,
+ val supportsRetrievingTransactionsOfLast90DaysWithoutTan: Boolean = false,
+ val bookedTransactionsOfLast90Days: List = listOf(),
+ val unbookedTransactionsOfLast90Days: List = listOf(),
+ val balance: BigDecimal? = null
+)
+ : FinTsClientResponse(response)
\ No newline at end of file
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 18f95fd2..3485e97f 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
@@ -34,4 +34,9 @@ open class FinTsClientResponse(
response.messageCreationError?.allowedVersions ?: listOf(),
response.messageCreationError?.supportedVersions ?: listOf())
+
+ open fun toResponse(): Response {
+ return Response(this.isSuccessful)
+ }
+
}
\ No newline at end of file