From 825a61e061abfd66ee4958c43ae8431b27bc04f5 Mon Sep 17 00:00:00 2001 From: dankl Date: Thu, 9 Jan 2020 00:23:15 +0100 Subject: [PATCH] Added TanImageView for QR code and PhotTan images --- .../ui/javafx/dialogs/tan/EnterTanDialog.kt | 17 +++++ .../tan/controls/ChipTanFlickerCodeView.kt | 56 +++++--------- .../dialogs/tan/controls/TanImageSizeView.kt | 44 +++++++++++ .../dialogs/tan/controls/TanImageView.kt | 73 +++++++++++++++++++ .../ui/views/ChipTanFlickerCodeView.kt | 16 ++-- 5 files changed, 159 insertions(+), 47 deletions(-) create mode 100644 BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/controls/TanImageSizeView.kt create mode 100644 BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/controls/TanImageView.kt diff --git a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/EnterTanDialog.kt b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/EnterTanDialog.kt index 7909901f..1ce49016 100644 --- a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/EnterTanDialog.kt +++ b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/EnterTanDialog.kt @@ -6,6 +6,7 @@ import javafx.geometry.Insets import javafx.geometry.Pos import net.dankito.banking.javafx.dialogs.tan.controls.ChipTanFlickerCodeView import net.dankito.banking.ui.javafx.dialogs.JavaFxDialogService +import net.dankito.banking.ui.javafx.dialogs.tan.controls.TanImageView import net.dankito.banking.ui.model.Account import net.dankito.banking.ui.model.responses.BankingClientResponse import net.dankito.banking.ui.model.tan.* @@ -98,6 +99,22 @@ open class EnterTanDialog( } } + (challenge as? ImageTanChallenge)?.let { imageTanChallenge -> + val decodedImage = imageTanChallenge.image + if (decodedImage.decodingSuccessful) { + add(TanImageView(decodedImage).apply { + + vboxConstraints { + marginLeftRight(30.0) + marginBottom = 12.0 + } + }) + } + else { + showDecodingTanChallengeFailedError(decodedImage.decodingError) + } + } + hbox { maxWidth = 400.0 diff --git a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/controls/ChipTanFlickerCodeView.kt b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/controls/ChipTanFlickerCodeView.kt index f4111bf1..2dbab86d 100644 --- a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/controls/ChipTanFlickerCodeView.kt +++ b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/controls/ChipTanFlickerCodeView.kt @@ -4,6 +4,7 @@ import javafx.beans.property.SimpleBooleanProperty import javafx.beans.property.SimpleDoubleProperty import javafx.geometry.Pos import javafx.scene.paint.Color +import net.dankito.banking.ui.javafx.dialogs.tan.controls.TanImageSizeView import net.dankito.banking.ui.model.tan.FlickerCode import net.dankito.banking.ui.util.FlickerCodeAnimator import net.dankito.fints.tan.Bit @@ -30,27 +31,27 @@ class ChipTanFlickerCodeView(private val flickerCode: FlickerCode): View() { } - private val flickerCodeLeftRightMargin = SimpleDoubleProperty(31.0) + protected val flickerCodeLeftRightMargin = SimpleDoubleProperty(31.0) - private val stripeHeight = SimpleDoubleProperty(127.0) - private val stripeWidth = SimpleDoubleProperty(42.0) - private val spaceBetweenStripes = SimpleDoubleProperty(10.0) + protected val stripeHeight = SimpleDoubleProperty(127.0) + protected val stripeWidth = SimpleDoubleProperty(42.0) + protected val spaceBetweenStripes = SimpleDoubleProperty(10.0) - private val flickerCodeViewWidth = SimpleDoubleProperty() + protected val flickerCodeViewWidth = SimpleDoubleProperty() - private val stripe1 = SimpleBooleanProperty() - private val stripe2 = SimpleBooleanProperty() - private val stripe3 = SimpleBooleanProperty() - private val stripe4 = SimpleBooleanProperty() - private val stripe5 = SimpleBooleanProperty() + protected val stripe1 = SimpleBooleanProperty() + protected val stripe2 = SimpleBooleanProperty() + protected val stripe3 = SimpleBooleanProperty() + protected val stripe4 = SimpleBooleanProperty() + protected val stripe5 = SimpleBooleanProperty() - private val isMinSizeReached = SimpleBooleanProperty(false) - private val isMaxSizeReached = SimpleBooleanProperty(false) + protected val isMinSizeReached = SimpleBooleanProperty(false) + protected val isMaxSizeReached = SimpleBooleanProperty(false) - private val isMinFrequencyReached = SimpleBooleanProperty(false) - private val isMaxFrequencyReached = SimpleBooleanProperty(false) + protected val isMinFrequencyReached = SimpleBooleanProperty(false) + protected val isMaxFrequencyReached = SimpleBooleanProperty(false) - private var currentFrequency = 20 + protected var currentFrequency = 20 protected val animator = FlickerCodeAnimator() @@ -79,30 +80,7 @@ class ChipTanFlickerCodeView(private val flickerCode: FlickerCode): View() { alignment = Pos.CENTER - label(messages["enter.tan.dialog.size.label"]) - - button("-") { - prefHeight = IconHeight - prefWidth = IconWidth - - disableWhen(isMinSizeReached) - - action { decreaseSize() } - - hboxConstraints { - marginLeft = 6.0 - marginRight = 4.0 - } - } - - button("+") { - prefHeight = IconHeight - prefWidth = IconWidth - - disableWhen(isMaxSizeReached) - - action { increaseSize() } - } + add(TanImageSizeView(IconHeight, IconWidth, isMinSizeReached, isMaxSizeReached, { decreaseSize() }, { increaseSize() } )) label(messages["enter.tan.dialog.frequency.label"]) { hboxConstraints { diff --git a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/controls/TanImageSizeView.kt b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/controls/TanImageSizeView.kt new file mode 100644 index 00000000..ba05c86c --- /dev/null +++ b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/controls/TanImageSizeView.kt @@ -0,0 +1,44 @@ +package net.dankito.banking.ui.javafx.dialogs.tan.controls + +import javafx.beans.property.SimpleBooleanProperty +import javafx.geometry.Pos +import tornadofx.* + + +open class TanImageSizeView(iconHeight: Double, iconWidth: Double, + isMinSizeReached: SimpleBooleanProperty, isMaxSizeReached: SimpleBooleanProperty, + protected val decreaseSizeAction: (() -> Unit), protected val increaseSizeAction: (() -> Unit)) : View() { + + + override val root = hbox { + prefHeight = iconHeight + 6.0 + + alignment = Pos.CENTER + + label(messages["enter.tan.dialog.size.label"]) + + button("-") { + prefHeight = iconHeight + prefWidth = iconWidth + + disableWhen(isMinSizeReached) + + action { decreaseSizeAction() } + + hboxConstraints { + marginLeft = 6.0 + marginRight = 4.0 + } + } + + button("+") { + prefHeight = iconHeight + prefWidth = iconWidth + + disableWhen(isMaxSizeReached) + + action { increaseSizeAction() } + } + } + +} \ No newline at end of file diff --git a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/controls/TanImageView.kt b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/controls/TanImageView.kt new file mode 100644 index 00000000..41659e56 --- /dev/null +++ b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/controls/TanImageView.kt @@ -0,0 +1,73 @@ +package net.dankito.banking.ui.javafx.dialogs.tan.controls + +import javafx.beans.property.SimpleBooleanProperty +import javafx.geometry.Pos +import javafx.scene.image.Image +import javafx.scene.image.ImageView +import net.dankito.banking.ui.model.tan.TanImage +import net.dankito.utils.javafx.ui.extensions.updateWindowSize +import org.slf4j.LoggerFactory +import tornadofx.* +import java.io.ByteArrayInputStream + + +open class TanImageView(protected val tanImage: TanImage) : View() { + + companion object { + private const val ChangeSizeStepSize = 10.0 + + const val MinHeight = 100.0 + const val MaxHeight = 500.0 + + private const val IconHeight = 26.0 + private const val IconWidth = 26.0 + } + + + protected val isMinSizeReached = SimpleBooleanProperty(false) + protected val isMaxSizeReached = SimpleBooleanProperty(false) + + protected var tanImageView: ImageView by singleAssign() + + + override val root = vbox { + add(TanImageSizeView(IconHeight, IconWidth, isMinSizeReached, isMaxSizeReached, { decreaseSize() }, { increaseSize() } )) + + tanImageView = imageview(Image(ByteArrayInputStream(tanImage.imageBytes))) { + fitHeight = 250.0 + + alignment = Pos.CENTER + + isPreserveRatio = true + + vboxConstraints { + marginTop = 8.0 + marginLeftRight(30.0) + marginBottom = 4.0 + } + } + } + + + open fun increaseSize() { + changeSizeBy(ChangeSizeStepSize) + } + + open fun decreaseSize() { + changeSizeBy(ChangeSizeStepSize * -1) + } + + protected open fun changeSizeBy(changeSizeBy: Double) { + val newWidthAndHeight = tanImageView.fitHeight + changeSizeBy + + if (newWidthAndHeight in MinHeight..MaxHeight) { + tanImageView.fitHeight = newWidthAndHeight + + updateWindowSize() + } + + isMinSizeReached.value = tanImageView.fitHeight <= MinHeight + isMaxSizeReached.value = tanImageView.fitHeight >= MaxHeight + } + +} \ No newline at end of file diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/ChipTanFlickerCodeView.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/ChipTanFlickerCodeView.kt index fa725332..07109780 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/ChipTanFlickerCodeView.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/views/ChipTanFlickerCodeView.kt @@ -107,6 +107,14 @@ open class ChipTanFlickerCodeView @JvmOverloads constructor( setWidth(context) } + open fun increaseSize() { + stripesHeight += StripesHeightStepSize + stripesWidth += StripesWidthStepSize + stripesMarginRight += StripesRightMarginStepSize + + setWidth(context) + } + protected open fun setWidth(context: Context) { allStripes.forEach { stripe -> val params = stripe.layoutParams @@ -146,14 +154,6 @@ open class ChipTanFlickerCodeView @JvmOverloads constructor( } } - open fun decreaseFrequency() { - if (currentFrequency - FrequencyStepSize >= MinFrequency) { - currentFrequency -= FrequencyStepSize - - setFrequency(currentFrequency) - } - } - open fun setFrequency(frequency: Int) { animator.setFrequency(frequency) }