FinTsClientCallback returns now EnterTanGeneratorAtcResult instead of EnterTanGeneratorAtcResult? and EnterAtcDialog returns EnterTanGeneratorAtcResult now
This commit is contained in:
parent
7b57e449ba
commit
d7e0846433
|
@ -17,7 +17,6 @@ import net.dankito.fints.FinTsClientCallback
|
|||
import net.dankito.fints.messages.datenelemente.implementierte.tan.TanGeneratorTanMedium
|
||||
import net.dankito.fints.model.*
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
|
||||
|
@ -36,7 +35,7 @@ class MainActivity : AppCompatActivity() {
|
|||
return getTanFromUserOffUiThread(customer, tanChallenge)
|
||||
}
|
||||
|
||||
override fun enterTanGeneratorAtc(customer: CustomerData, tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult? {
|
||||
override fun enterTanGeneratorAtc(customer: CustomerData, tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult {
|
||||
return getAtcFromUserOffUiThread(customer, tanMedium)
|
||||
}
|
||||
|
||||
|
@ -107,23 +106,21 @@ class MainActivity : AppCompatActivity() {
|
|||
return enteredTan.get()
|
||||
}
|
||||
|
||||
private fun getAtcFromUserOffUiThread(customer: CustomerData, tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult? {
|
||||
val enteredTan = AtomicReference<String>(null)
|
||||
val enteredAtc = AtomicInteger()
|
||||
private fun getAtcFromUserOffUiThread(customer: CustomerData, tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult {
|
||||
val result = AtomicReference<EnterTanGeneratorAtcResult>(null)
|
||||
val tanEnteredLatch = CountDownLatch(1)
|
||||
|
||||
runOnUiThread {
|
||||
// TODO: don't create a fints4javaModelMapper instance here, let MainWindowPresenter do the job
|
||||
EnterAtcDialog().show(fints4javaModelMapper().mapTanMedium(tanMedium), this@MainActivity, false) { tan, atc ->
|
||||
enteredTan.set(tan)
|
||||
atc?.let { enteredAtc.set(atc) }
|
||||
EnterAtcDialog().show(fints4javaModelMapper().mapTanMedium(tanMedium), this@MainActivity, false) { enteredResult ->
|
||||
result.set(enteredResult)
|
||||
tanEnteredLatch.countDown()
|
||||
}
|
||||
}
|
||||
|
||||
try { tanEnteredLatch.await() } catch (ignored: Exception) { }
|
||||
|
||||
return if (enteredTan.get() == null) null else EnterTanGeneratorAtcResult(enteredTan.get(), enteredAtc.get())
|
||||
return result.get()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import android.view.ViewGroup
|
|||
import kotlinx.android.synthetic.main.dialog_enter_atc.view.*
|
||||
import net.dankito.banking.fints4java.android.R
|
||||
import net.dankito.banking.ui.model.TanMedium
|
||||
import net.dankito.fints.model.EnterTanGeneratorAtcResult
|
||||
|
||||
|
||||
open class EnterAtcDialog : DialogFragment() {
|
||||
|
@ -22,11 +23,11 @@ open class EnterAtcDialog : DialogFragment() {
|
|||
|
||||
protected lateinit var tanMedium: TanMedium
|
||||
|
||||
protected lateinit var atcEnteredCallback: (tan: String?, atc: Int?) -> Unit
|
||||
protected lateinit var atcEnteredCallback: (EnterTanGeneratorAtcResult) -> Unit
|
||||
|
||||
|
||||
open fun show(tanMedium: TanMedium, activity: AppCompatActivity,
|
||||
fullscreen: Boolean = false, atcEnteredCallback: (tan: String?, atc: Int?) -> Unit) {
|
||||
fullscreen: Boolean = false, atcEnteredCallback: (EnterTanGeneratorAtcResult?) -> Unit) {
|
||||
|
||||
this.tanMedium = tanMedium
|
||||
this.atcEnteredCallback = atcEnteredCallback
|
||||
|
@ -69,7 +70,10 @@ open class EnterAtcDialog : DialogFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
atcEnteredCallback(enteredTan, enteredAtc)
|
||||
val result = if (enteredTan == null || enteredAtc == null) EnterTanGeneratorAtcResult.userDidNotEnterTan()
|
||||
else EnterTanGeneratorAtcResult.userEnteredAtc(enteredTan, enteredAtc)
|
||||
|
||||
atcEnteredCallback(result)
|
||||
|
||||
dismiss()
|
||||
}
|
||||
|
|
|
@ -339,7 +339,7 @@ open class FinTsClient @JvmOverloads constructor(
|
|||
if (bank.changeTanMediumParameters?.enteringAtcAndTanRequired == true) {
|
||||
enteredAtc = callback.enterTanGeneratorAtc(customer, newActiveTanMedium)
|
||||
|
||||
if (enteredAtc == null) {
|
||||
if (enteredAtc.hasAtcBeenEntered) {
|
||||
val message = "Bank requires to enter ATC and TAN in order to change TAN medium." // TODO: translate
|
||||
return FinTsClientResponse(Response(false, exception = Exception(message)))
|
||||
}
|
||||
|
|
|
@ -13,6 +13,6 @@ interface FinTsClientCallback {
|
|||
/**
|
||||
* This method gets called for chipTan TAN generators when the bank asks the customer to synchronize her/his TAN generator.
|
||||
*/
|
||||
fun enterTanGeneratorAtc(customer: CustomerData, tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult?
|
||||
fun enterTanGeneratorAtc(customer: CustomerData, tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult
|
||||
|
||||
}
|
|
@ -1,11 +1,28 @@
|
|||
package net.dankito.fints.model
|
||||
|
||||
|
||||
open class EnterTanGeneratorAtcResult(
|
||||
val tan: String,
|
||||
val atc: Int
|
||||
open class EnterTanGeneratorAtcResult protected constructor(
|
||||
val tan: String?,
|
||||
val atc: Int?
|
||||
) {
|
||||
|
||||
companion object {
|
||||
|
||||
fun userEnteredAtc(enteredTan: String, enteredAtc: Int): EnterTanGeneratorAtcResult {
|
||||
return EnterTanGeneratorAtcResult(enteredTan, enteredAtc)
|
||||
}
|
||||
|
||||
fun userDidNotEnterTan(): EnterTanGeneratorAtcResult {
|
||||
return EnterTanGeneratorAtcResult(null, null)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
val hasAtcBeenEntered: Boolean
|
||||
get() = tan != null && atc != null
|
||||
|
||||
|
||||
override fun toString(): String {
|
||||
return "TAN: $tan, ATC: $atc"
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package net.dankito.fints.model
|
|||
import net.dankito.fints.messages.datenelemente.implementierte.tan.TanMedium
|
||||
|
||||
|
||||
open class EnterTanResult constructor(
|
||||
open class EnterTanResult protected constructor(
|
||||
val enteredTan: String?,
|
||||
val changeTanMediumTo: TanMedium?
|
||||
) {
|
||||
|
|
|
@ -49,7 +49,7 @@ public class JavaShowcase {
|
|||
@Nullable
|
||||
@Override
|
||||
public EnterTanGeneratorAtcResult enterTanGeneratorAtc(@NotNull CustomerData customer, @NotNull TanGeneratorTanMedium tanMedium) {
|
||||
return null;
|
||||
return EnterTanGeneratorAtcResult.Companion.userDidNotEnterTan();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -43,10 +43,10 @@ class FinTsClientTest {
|
|||
return EnterTanResult.userDidNotEnterTan()
|
||||
}
|
||||
|
||||
override fun enterTanGeneratorAtc(customer: CustomerData, tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult? {
|
||||
override fun enterTanGeneratorAtc(customer: CustomerData, tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult {
|
||||
Assert.fail("Bank asks you to synchronize your TAN generator for card ${tanMedium.cardNumber} " +
|
||||
"(card sequence number ${tanMedium.cardSequenceNumber}). Please do this via your online banking portal or Banking UI.")
|
||||
return null // should actually never be called
|
||||
return EnterTanGeneratorAtcResult.userDidNotEnterTan() // should actually never be called
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue