From ac71e095967791e20496efc38204fbf7696700fe Mon Sep 17 00:00:00 2001 From: dankito Date: Fri, 12 Nov 2021 23:33:48 +0100 Subject: [PATCH] Added imageBased() and first() methods --- .../banking/fints/util/TanMethodSelector.kt | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/util/TanMethodSelector.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/util/TanMethodSelector.kt index fef1ce35..a8cd064b 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/util/TanMethodSelector.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/util/TanMethodSelector.kt @@ -7,7 +7,11 @@ import net.dankito.banking.fints.model.TanMethodType open class TanMethodSelector { companion object { + val NonVisual = listOf(TanMethodType.AppTan, TanMethodType.SmsTan, TanMethodType.ChipTanManuell, TanMethodType.EnterTan) + + val ImageBased = listOf(TanMethodType.QrCode, TanMethodType.ChipTanQrCode, TanMethodType.photoTan, TanMethodType.ChipTanPhotoTanMatrixCode) + } @@ -15,7 +19,7 @@ open class TanMethodSelector { return tanMethods.firstOrNull { it.type != TanMethodType.ChipTanUsb && it.type != TanMethodType.SmsTan && it.type != TanMethodType.ChipTanManuell } ?: tanMethods.firstOrNull { it.type != TanMethodType.ChipTanUsb && it.type != TanMethodType.SmsTan } ?: tanMethods.firstOrNull { it.type != TanMethodType.ChipTanUsb } - ?: tanMethods.firstOrNull() + ?: first(tanMethods) } open fun findPreferredTanMethod(tanMethods: List, preferredTanMethods: List?): TanMethod? { @@ -28,10 +32,36 @@ open class TanMethodSelector { return null } - open fun selectNonVisual(tanMethods: List): TanMethod? { + + open fun nonVisual(tanMethods: List): TanMethod? { return findPreferredTanMethod(tanMethods, NonVisual) ?: tanMethods.firstOrNull { it.displayName.contains("manuell", true) } - ?: tanMethods.firstOrNull() + } + + open fun nonVisualOrFirst(tanMethods: List): TanMethod? { + return nonVisual(tanMethods) + ?: first(tanMethods) + } + + + open fun imageBased(tanMethods: List): TanMethod? { + return findPreferredTanMethod(tanMethods, ImageBased) + } + + open fun imageBasedOrFirst(tanMethods: List): TanMethod? { + return imageBased(tanMethods) + ?: first(tanMethods) + } + + + open fun nonVisualOrImageBasedOrFirst(tanMethods: List): TanMethod? { + return nonVisual(tanMethods) + ?: imageBased(tanMethods) + ?: first(tanMethods) + } + + open fun first(tanMethods: List): TanMethod? { + return tanMethods.firstOrNull() } } \ No newline at end of file