Added TanImageView for QR code and PhotTan images

This commit is contained in:
dankl 2020-01-09 00:23:15 +01:00 committed by dankito
parent 8268a8f2dd
commit 825a61e061
5 changed files with 159 additions and 47 deletions

View File

@ -6,6 +6,7 @@ import javafx.geometry.Insets
import javafx.geometry.Pos import javafx.geometry.Pos
import net.dankito.banking.javafx.dialogs.tan.controls.ChipTanFlickerCodeView import net.dankito.banking.javafx.dialogs.tan.controls.ChipTanFlickerCodeView
import net.dankito.banking.ui.javafx.dialogs.JavaFxDialogService 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.Account
import net.dankito.banking.ui.model.responses.BankingClientResponse import net.dankito.banking.ui.model.responses.BankingClientResponse
import net.dankito.banking.ui.model.tan.* 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 { hbox {
maxWidth = 400.0 maxWidth = 400.0

View File

@ -4,6 +4,7 @@ import javafx.beans.property.SimpleBooleanProperty
import javafx.beans.property.SimpleDoubleProperty import javafx.beans.property.SimpleDoubleProperty
import javafx.geometry.Pos import javafx.geometry.Pos
import javafx.scene.paint.Color 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.model.tan.FlickerCode
import net.dankito.banking.ui.util.FlickerCodeAnimator import net.dankito.banking.ui.util.FlickerCodeAnimator
import net.dankito.fints.tan.Bit 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) protected val stripeHeight = SimpleDoubleProperty(127.0)
private val stripeWidth = SimpleDoubleProperty(42.0) protected val stripeWidth = SimpleDoubleProperty(42.0)
private val spaceBetweenStripes = SimpleDoubleProperty(10.0) protected val spaceBetweenStripes = SimpleDoubleProperty(10.0)
private val flickerCodeViewWidth = SimpleDoubleProperty() protected val flickerCodeViewWidth = SimpleDoubleProperty()
private val stripe1 = SimpleBooleanProperty() protected val stripe1 = SimpleBooleanProperty()
private val stripe2 = SimpleBooleanProperty() protected val stripe2 = SimpleBooleanProperty()
private val stripe3 = SimpleBooleanProperty() protected val stripe3 = SimpleBooleanProperty()
private val stripe4 = SimpleBooleanProperty() protected val stripe4 = SimpleBooleanProperty()
private val stripe5 = SimpleBooleanProperty() protected val stripe5 = SimpleBooleanProperty()
private val isMinSizeReached = SimpleBooleanProperty(false) protected val isMinSizeReached = SimpleBooleanProperty(false)
private val isMaxSizeReached = SimpleBooleanProperty(false) protected val isMaxSizeReached = SimpleBooleanProperty(false)
private val isMinFrequencyReached = SimpleBooleanProperty(false) protected val isMinFrequencyReached = SimpleBooleanProperty(false)
private val isMaxFrequencyReached = SimpleBooleanProperty(false) protected val isMaxFrequencyReached = SimpleBooleanProperty(false)
private var currentFrequency = 20 protected var currentFrequency = 20
protected val animator = FlickerCodeAnimator() protected val animator = FlickerCodeAnimator()
@ -79,30 +80,7 @@ class ChipTanFlickerCodeView(private val flickerCode: FlickerCode): View() {
alignment = Pos.CENTER alignment = Pos.CENTER
label(messages["enter.tan.dialog.size.label"]) add(TanImageSizeView(IconHeight, IconWidth, isMinSizeReached, isMaxSizeReached, { decreaseSize() }, { increaseSize() } ))
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() }
}
label(messages["enter.tan.dialog.frequency.label"]) { label(messages["enter.tan.dialog.frequency.label"]) {
hboxConstraints { hboxConstraints {

View File

@ -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() }
}
}
}

View File

@ -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
}
}

View File

@ -107,6 +107,14 @@ open class ChipTanFlickerCodeView @JvmOverloads constructor(
setWidth(context) setWidth(context)
} }
open fun increaseSize() {
stripesHeight += StripesHeightStepSize
stripesWidth += StripesWidthStepSize
stripesMarginRight += StripesRightMarginStepSize
setWidth(context)
}
protected open fun setWidth(context: Context) { protected open fun setWidth(context: Context) {
allStripes.forEach { stripe -> allStripes.forEach { stripe ->
val params = stripe.layoutParams 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) { open fun setFrequency(frequency: Int) {
animator.setFrequency(frequency) animator.setFrequency(frequency)
} }