Implemented changeTanMediumResultCallback

This commit is contained in:
dankl 2020-01-01 19:13:34 +01:00 committed by dankito
parent d7e0846433
commit 0c6f563385
3 changed files with 45 additions and 8 deletions

View File

@ -1,7 +1,9 @@
package net.dankito.banking.fints4java.android.ui.dialogs package net.dankito.banking.fints4java.android.ui.dialogs
import android.content.Context
import android.os.Bundle import android.os.Bundle
import android.support.v4.app.DialogFragment import android.support.v4.app.DialogFragment
import android.support.v7.app.AlertDialog
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.text.InputType import android.text.InputType
import android.view.LayoutInflater 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.adapter.TanMediumAdapter
import net.dankito.banking.fints4java.android.ui.listener.ListItemSelectedListener import net.dankito.banking.fints4java.android.ui.listener.ListItemSelectedListener
import net.dankito.banking.ui.model.Account import net.dankito.banking.ui.model.Account
import net.dankito.banking.ui.model.TanMedium
import net.dankito.banking.ui.model.TanMediumStatus import net.dankito.banking.ui.model.TanMediumStatus
import net.dankito.fints.messages.datenelemente.implementierte.tan.TanGeneratorTanMedium import net.dankito.fints.messages.datenelemente.implementierte.tan.TanGeneratorTanMedium
import net.dankito.fints.model.EnterTanResult import net.dankito.fints.model.EnterTanResult
import net.dankito.fints.model.TanChallenge import net.dankito.fints.model.TanChallenge
import net.dankito.fints.model.TanProcedureType import net.dankito.fints.model.TanProcedureType
import net.dankito.fints.response.client.FinTsClientResponse
import net.dankito.fints.tan.FlickercodeDecoder import net.dankito.fints.tan.FlickercodeDecoder
@ -92,10 +96,10 @@ open class EnterTanDialog : DialogFragment() {
rootView.spnTanMedium.onItemSelectedListener = ListItemSelectedListener(tanMediumAdapter) { selectedTanMedium -> rootView.spnTanMedium.onItemSelectedListener = ListItemSelectedListener(tanMediumAdapter) { selectedTanMedium ->
if (selectedTanMedium.status != TanMediumStatus.Used) { if (selectedTanMedium.status != TanMediumStatus.Used) {
(selectedTanMedium.originalObject as? TanGeneratorTanMedium)?.let { tanGeneratorTanMedium -> (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 // 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? // 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?) { protected open fun enteringTanDone(enteredTan: String?) {
val result = if (enteredTan != null) EnterTanResult.userEnteredTan(enteredTan) else EnterTanResult.userDidNotEnterTan() val result = if (enteredTan != null) EnterTanResult.userEnteredTan(enteredTan) else EnterTanResult.userDidNotEnterTan()

View File

@ -633,7 +633,8 @@ open class FinTsClient @JvmOverloads constructor(
tanResponse.challengeHHD_UC ?: "", customer.selectedTanProcedure)) tanResponse.challengeHHD_UC ?: "", customer.selectedTanProcedure))
if (enteredTanResult.changeTanMediumTo is TanGeneratorTanMedium) { 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) { 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) // 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, 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 val lastCreatedMessage = messageBuilder.lastCreatedMessage
@ -676,6 +678,8 @@ open class FinTsClient @JvmOverloads constructor(
val changeTanMediumResponse = changeTanMedium(changeTanMediumTo, bank, customer) val changeTanMediumResponse = changeTanMedium(changeTanMediumTo, bank, customer)
changeTanMediumResultCallback?.invoke(changeTanMediumResponse)
if (changeTanMediumResponse.isSuccessful == false || lastCreatedMessage == null) { if (changeTanMediumResponse.isSuccessful == false || lastCreatedMessage == null) {
return changeTanMediumResponse.toResponse() return changeTanMediumResponse.toResponse()
} }

View File

@ -1,11 +1,13 @@
package net.dankito.fints.model package net.dankito.fints.model
import net.dankito.fints.messages.datenelemente.implementierte.tan.TanMedium import net.dankito.fints.messages.datenelemente.implementierte.tan.TanMedium
import net.dankito.fints.response.client.FinTsClientResponse
open class EnterTanResult protected constructor( open class EnterTanResult protected constructor(
val enteredTan: String?, val enteredTan: String?,
val changeTanMediumTo: TanMedium? val changeTanMediumTo: TanMedium?,
val changeTanMediumResultCallback: ((FinTsClientResponse) -> Unit)? = null
) { ) {
companion object { companion object {
@ -18,8 +20,8 @@ open class EnterTanResult protected constructor(
return EnterTanResult(null, null) return EnterTanResult(null, null)
} }
fun userAsksToChangeTanMedium(changeTanMediumTo: TanMedium): EnterTanResult { fun userAsksToChangeTanMedium(changeTanMediumTo: TanMedium, changeTanMediumResultCallback: (FinTsClientResponse) -> Unit): EnterTanResult {
return EnterTanResult(null, changeTanMediumTo) return EnterTanResult(null, changeTanMediumTo, changeTanMediumResultCallback)
} }
} }