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 fb8cd929..0e61fbbb 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 @@ -1,7 +1,9 @@ package net.dankito.banking.fints4java.android.ui.dialogs +import android.content.Context import android.os.Bundle import android.support.v4.app.DialogFragment +import android.support.v7.app.AlertDialog import android.support.v7.app.AppCompatActivity import android.text.InputType import android.view.LayoutInflater @@ -13,11 +15,13 @@ import net.dankito.banking.fints4java.android.ui.MainWindowPresenter import net.dankito.banking.fints4java.android.ui.adapter.TanMediumAdapter import net.dankito.banking.fints4java.android.ui.listener.ListItemSelectedListener import net.dankito.banking.ui.model.Account +import net.dankito.banking.ui.model.TanMedium import net.dankito.banking.ui.model.TanMediumStatus import net.dankito.fints.messages.datenelemente.implementierte.tan.TanGeneratorTanMedium import net.dankito.fints.model.EnterTanResult import net.dankito.fints.model.TanChallenge import net.dankito.fints.model.TanProcedureType +import net.dankito.fints.response.client.FinTsClientResponse import net.dankito.fints.tan.FlickercodeDecoder @@ -92,10 +96,10 @@ open class EnterTanDialog : DialogFragment() { rootView.spnTanMedium.onItemSelectedListener = ListItemSelectedListener(tanMediumAdapter) { selectedTanMedium -> if (selectedTanMedium.status != TanMediumStatus.Used) { (selectedTanMedium.originalObject as? TanGeneratorTanMedium)?.let { tanGeneratorTanMedium -> - tanEnteredCallback(EnterTanResult.userAsksToChangeTanMedium(tanGeneratorTanMedium)) + tanEnteredCallback(EnterTanResult.userAsksToChangeTanMedium(tanGeneratorTanMedium) { response -> + handleChangeTanMediumResponse(selectedTanMedium, response) + }) // TODO: find a way to update account.tanMedia afterwards - - dismiss() // TODO: really dismiss? what if changing TAN medium fails? } // TODO: what to do if newActiveTanMedium.originalObject is not of type TanGeneratorTanMedium? @@ -104,6 +108,33 @@ open class EnterTanDialog : DialogFragment() { } + protected open fun handleChangeTanMediumResponse(newUsedTanMedium: TanMedium, response: FinTsClientResponse) { + activity?.let { activity -> + activity.runOnUiThread { + handleChangeTanMediumResponseOnUiThread(activity, newUsedTanMedium, response) + } + } + } + + protected open fun handleChangeTanMediumResponseOnUiThread(context: Context, newUsedTanMedium: TanMedium, response: FinTsClientResponse) { + if (response.isSuccessful) { + AlertDialog.Builder(context) + .setMessage(context.getString(R.string.dialog_enter_tan_tan_medium_successfully_changed, newUsedTanMedium.displayName)) + .setPositiveButton(android.R.string.ok) { dialog, _ -> + dialog.dismiss() + dismiss() + } + .show() + } + else { + AlertDialog.Builder(context) + .setMessage(context.getString(R.string.dialog_enter_tan_error_changing_tan_medium, newUsedTanMedium.displayName, presenter.getErrorToShowToUser(response))) + .setPositiveButton(android.R.string.ok) { dialog, _ -> dialog.dismiss() } + .show() + } + } + + protected open fun enteringTanDone(enteredTan: String?) { val result = if (enteredTan != null) EnterTanResult.userEnteredTan(enteredTan) else EnterTanResult.userDidNotEnterTan() diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt index f0aff8d1..9b34200f 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt @@ -633,7 +633,8 @@ open class FinTsClient @JvmOverloads constructor( tanResponse.challengeHHD_UC ?: "", customer.selectedTanProcedure)) if (enteredTanResult.changeTanMediumTo is TanGeneratorTanMedium) { - return handleUserAsksToChangeTanMediumAndResendLastMessage(enteredTanResult.changeTanMediumTo, bank, customer, dialogData) + return handleUserAsksToChangeTanMediumAndResendLastMessage(enteredTanResult.changeTanMediumTo, + bank, customer, dialogData, enteredTanResult.changeTanMediumResultCallback) } 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) @@ -667,7 +668,8 @@ open class FinTsClient @JvmOverloads constructor( } protected open fun handleUserAsksToChangeTanMediumAndResendLastMessage(changeTanMediumTo: TanGeneratorTanMedium, bank: BankData, - customer: CustomerData, dialogData: DialogData): Response { + customer: CustomerData, dialogData: DialogData, + changeTanMediumResultCallback: ((FinTsClientResponse) -> Unit)?): Response { val lastCreatedMessage = messageBuilder.lastCreatedMessage @@ -676,6 +678,8 @@ open class FinTsClient @JvmOverloads constructor( val changeTanMediumResponse = changeTanMedium(changeTanMediumTo, bank, customer) + changeTanMediumResultCallback?.invoke(changeTanMediumResponse) + if (changeTanMediumResponse.isSuccessful == false || lastCreatedMessage == null) { return changeTanMediumResponse.toResponse() } 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 08d41922..9e760730 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/model/EnterTanResult.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/model/EnterTanResult.kt @@ -1,11 +1,13 @@ package net.dankito.fints.model import net.dankito.fints.messages.datenelemente.implementierte.tan.TanMedium +import net.dankito.fints.response.client.FinTsClientResponse open class EnterTanResult protected constructor( val enteredTan: String?, - val changeTanMediumTo: TanMedium? + val changeTanMediumTo: TanMedium?, + val changeTanMediumResultCallback: ((FinTsClientResponse) -> Unit)? = null ) { companion object { @@ -18,8 +20,8 @@ open class EnterTanResult protected constructor( return EnterTanResult(null, null) } - fun userAsksToChangeTanMedium(changeTanMediumTo: TanMedium): EnterTanResult { - return EnterTanResult(null, changeTanMediumTo) + fun userAsksToChangeTanMedium(changeTanMediumTo: TanMedium, changeTanMediumResultCallback: (FinTsClientResponse) -> Unit): EnterTanResult { + return EnterTanResult(null, changeTanMediumTo, changeTanMediumResultCallback) } }