diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/MainActivity.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/MainActivity.kt index 315d7932..22fd9e91 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/MainActivity.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/MainActivity.kt @@ -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(null) - val enteredAtc = AtomicInteger() + private fun getAtcFromUserOffUiThread(customer: CustomerData, tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult { + val result = AtomicReference(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() } } diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/EnterAtcDialog.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/EnterAtcDialog.kt index 312d872c..bd6e7797 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/EnterAtcDialog.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/EnterAtcDialog.kt @@ -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() } diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt index 24d15427..f0aff8d1 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt @@ -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))) } diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClientCallback.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClientCallback.kt index 0b1cf7ce..d539e458 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClientCallback.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClientCallback.kt @@ -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 } \ No newline at end of file diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/model/EnterTanGeneratorAtcResult.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/model/EnterTanGeneratorAtcResult.kt index 88510962..9ef3cd7c 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/model/EnterTanGeneratorAtcResult.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/model/EnterTanGeneratorAtcResult.kt @@ -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" } 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 35aa7e93..08d41922 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/model/EnterTanResult.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/model/EnterTanResult.kt @@ -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? ) { diff --git a/fints4javaLib/src/test/java/net/dankito/fints/java/JavaShowcase.java b/fints4javaLib/src/test/java/net/dankito/fints/java/JavaShowcase.java index c30ca320..f25286a3 100644 --- a/fints4javaLib/src/test/java/net/dankito/fints/java/JavaShowcase.java +++ b/fints4javaLib/src/test/java/net/dankito/fints/java/JavaShowcase.java @@ -49,7 +49,7 @@ public class JavaShowcase { @Nullable @Override public EnterTanGeneratorAtcResult enterTanGeneratorAtc(@NotNull CustomerData customer, @NotNull TanGeneratorTanMedium tanMedium) { - return null; + return EnterTanGeneratorAtcResult.Companion.userDidNotEnterTan(); } }; diff --git a/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt b/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt index 502df397..36faa573 100644 --- a/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt +++ b/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt @@ -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 } }