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 5c3bff2d..cf06b351 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 @@ -11,15 +11,12 @@ import android.text.TextWatcher import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.AdapterView -import android.widget.Spinner import android.widget.TextView import kotlinx.android.synthetic.main.dialog_add_account.* import kotlinx.android.synthetic.main.dialog_add_account.view.* 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.banking.fints4java.android.ui.adapter.TanProceduresAdapter import net.dankito.banking.ui.model.responses.AddAccountResponse import net.dankito.fints.model.BankInfo import net.dankito.utils.android.extensions.asActivity @@ -129,25 +126,8 @@ open class AddAccountDialog : DialogFragment() { val view = context.asActivity()?.layoutInflater?.inflate(R.layout.view_successfully_added_account, null) - val adapter = TanProceduresAdapter() - adapter.setItems(response.account.supportedTanProcedures) - view?.findViewById(R.id.txtSuccessfullyAddedAccountMessage)?.setText(messageId) - view?.findViewById(R.id.spnTanProcedures)?.let { spinner -> - spinner.adapter = adapter - spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { - override fun onNothingSelected(parent: AdapterView<*>?) {} - - override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { - response.account.selectedTanProcedure = adapter.getItem(position) - } - - } - - spinner.setSelection(adapter.getItems().indexOfFirst { it.displayName.contains("manuell", true) == false }) - } - return view } 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 0e61fbbb..f845e212 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 @@ -9,10 +9,13 @@ import android.text.InputType import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.Spinner import kotlinx.android.synthetic.main.dialog_enter_tan.view.* import net.dankito.banking.fints4java.android.R +import net.dankito.banking.fints4java.android.mapper.fints4javaModelMapper import net.dankito.banking.fints4java.android.ui.MainWindowPresenter import net.dankito.banking.fints4java.android.ui.adapter.TanMediumAdapter +import net.dankito.banking.fints4java.android.ui.adapter.TanProceduresAdapter import net.dankito.banking.fints4java.android.ui.listener.ListItemSelectedListener import net.dankito.banking.ui.model.Account import net.dankito.banking.ui.model.TanMedium @@ -69,6 +72,8 @@ open class EnterTanDialog : DialogFragment() { protected open fun setupUI(rootView: View) { val flickerCodeView = rootView.flickerCodeView + setupSelectTanProcedureView(rootView) + if (tanChallenge.tanProcedure.type == TanProcedureType.ChipTanOptisch) { if (account.tanMedia.isNotEmpty()) { setupSelectTanMediumView(rootView) @@ -87,6 +92,29 @@ open class EnterTanDialog : DialogFragment() { rootView.btnEnteringTanDone.setOnClickListener { enteringTanDone(rootView.edtxtEnteredTan.text.toString()) } } + protected open fun setupSelectTanProcedureView(rootView: View) { + val adapter = TanProceduresAdapter() + adapter.setItems(account.supportedTanProcedures) + + rootView.findViewById(R.id.spnTanProcedures)?.let { spinner -> + spinner.adapter = adapter + + val selectedTanProcedure = account.selectedTanProcedure + ?: account.supportedTanProcedures.firstOrNull() + selectedTanProcedure?.let { spinner.setSelection(adapter.getItems().indexOf(selectedTanProcedure)) } + + spinner.onItemSelectedListener = ListItemSelectedListener(adapter) { newSelectedTanProcedure -> + if (newSelectedTanProcedure != selectedTanProcedure) { + val mappedTanProcedure = fints4javaModelMapper().mapTanProcedureBack(newSelectedTanProcedure) // TODO: move to MainWindowPresenter + tanEnteredCallback(EnterTanResult.userAsksToChangeTanProcedure(mappedTanProcedure)) + // TODO: find a way to update account.selectedTanProcedure afterwards + + dismiss() + } + } + } + } + protected open fun setupSelectTanMediumView(rootView: View) { rootView.lytTanMedium.visibility = View.VISIBLE diff --git a/fints4javaAndroidApp/src/main/res/layout/dialog_enter_tan.xml b/fints4javaAndroidApp/src/main/res/layout/dialog_enter_tan.xml index eb30a973..234657e5 100644 --- a/fints4javaAndroidApp/src/main/res/layout/dialog_enter_tan.xml +++ b/fints4javaAndroidApp/src/main/res/layout/dialog_enter_tan.xml @@ -6,6 +6,33 @@ android:padding="@dimen/dialog_enter_tan_padding" > + + + + + + + + \ No newline at end of file diff --git a/fints4javaAndroidApp/src/main/res/layout/view_successfully_added_account.xml b/fints4javaAndroidApp/src/main/res/layout/view_successfully_added_account.xml index b25392a8..61373fe4 100644 --- a/fints4javaAndroidApp/src/main/res/layout/view_successfully_added_account.xml +++ b/fints4javaAndroidApp/src/main/res/layout/view_successfully_added_account.xml @@ -15,21 +15,4 @@ style="@style/TextAppearance.AppCompat.Medium" /> - - - - - - \ No newline at end of file diff --git a/fints4javaAndroidApp/src/main/res/values/dimens.xml b/fints4javaAndroidApp/src/main/res/values/dimens.xml index 531ea7fa..9fcd51b4 100644 --- a/fints4javaAndroidApp/src/main/res/values/dimens.xml +++ b/fints4javaAndroidApp/src/main/res/values/dimens.xml @@ -50,8 +50,12 @@ 6dp 4dp + 30dp + 8dp + 15sp 30dp 8dp + 15sp 175dp 20dp 50dp @@ -62,8 +66,6 @@ 4dp - 15sp - 4dp 4dp diff --git a/fints4javaAndroidApp/src/main/res/values/strings.xml b/fints4javaAndroidApp/src/main/res/values/strings.xml index f14db977..08882430 100644 --- a/fints4javaAndroidApp/src/main/res/values/strings.xml +++ b/fints4javaAndroidApp/src/main/res/values/strings.xml @@ -34,13 +34,11 @@ 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: @@ -59,6 +57,7 @@ + - + TAN procedure TAN medium Enter TAN: TAN medium successfully changed to \'%s\'. diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt index 3902ab05..be990f04 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt @@ -611,7 +611,11 @@ open class FinTsClient @JvmOverloads constructor( val enteredTanResult = callback.enterTan(customer, TanChallenge(tanResponse.challenge ?: "", tanResponse.challengeHHD_UC ?: "", customer.selectedTanProcedure)) - if (enteredTanResult.changeTanMediumTo is TanGeneratorTanMedium) { + if (enteredTanResult.changeTanProcedureTo != null) { + return handleUserAsksToChangeTanProcedureAndResendLastMessage(enteredTanResult.changeTanProcedureTo, + bank, customer, dialogData) + } + else if (enteredTanResult.changeTanMediumTo is TanGeneratorTanMedium) { return handleUserAsksToChangeTanMediumAndResendLastMessage(enteredTanResult.changeTanMediumTo, bank, customer, dialogData, enteredTanResult.changeTanMediumResultCallback) } @@ -646,6 +650,24 @@ open class FinTsClient @JvmOverloads constructor( return getAndHandleResponseForMessageThatMayRequiresTan(message, bank, customer, dialogData) } + protected open fun handleUserAsksToChangeTanProcedureAndResendLastMessage(changeTanProcedureTo: TanProcedure, bank: BankData, + customer: CustomerData, dialogData: DialogData): Response { + + val lastCreatedMessage = messageBuilder.lastCreatedMessage + + customer.selectedTanProcedure = changeTanProcedureTo + + + lastCreatedMessage?.let { + closeDialog(bank, customer, dialogData) + + return resendMessageInNewDialog(lastCreatedMessage, bank, customer) + } + + val errorMessage = "There's no last action (like retrieve account transactions, transfer money, ...) to re-send with new TAN procedure. Probably an internal programming error." // TODO: translate + return Response(false, exception = Exception(errorMessage)) // should never come to this + } + protected open fun handleUserAsksToChangeTanMediumAndResendLastMessage(changeTanMediumTo: TanGeneratorTanMedium, bank: BankData, customer: CustomerData, dialogData: DialogData, changeTanMediumResultCallback: ((FinTsClientResponse) -> Unit)?): Response { diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/model/EnterTanResult.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/model/EnterTanResult.kt index 9e760730..c618e785 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/model/EnterTanResult.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/model/EnterTanResult.kt @@ -6,6 +6,7 @@ import net.dankito.fints.response.client.FinTsClientResponse open class EnterTanResult protected constructor( val enteredTan: String?, + val changeTanProcedureTo: TanProcedure?, val changeTanMediumTo: TanMedium?, val changeTanMediumResultCallback: ((FinTsClientResponse) -> Unit)? = null ) { @@ -13,15 +14,19 @@ open class EnterTanResult protected constructor( companion object { fun userEnteredTan(enteredTan: String): EnterTanResult { - return EnterTanResult(enteredTan, null) + return EnterTanResult(enteredTan, null, null) } fun userDidNotEnterTan(): EnterTanResult { - return EnterTanResult(null, null) + return EnterTanResult(null, null, null) + } + + fun userAsksToChangeTanProcedure(changeTanProcedureTo: TanProcedure): EnterTanResult { + return EnterTanResult(null, changeTanProcedureTo, null) } fun userAsksToChangeTanMedium(changeTanMediumTo: TanMedium, changeTanMediumResultCallback: (FinTsClientResponse) -> Unit): EnterTanResult { - return EnterTanResult(null, changeTanMediumTo, changeTanMediumResultCallback) + return EnterTanResult(null, null, changeTanMediumTo, changeTanMediumResultCallback) } }