diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/EnterTanDialog.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/EnterTanDialog.kt index 1dee80f4..1222785a 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/EnterTanDialog.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/dialogs/EnterTanDialog.kt @@ -32,11 +32,6 @@ import javax.inject.Inject open class EnterTanDialog : DialogFragment() { companion object { - val QrCodeTanMethods = listOf(TanMethodType.ChipTanQrCode, TanMethodType.QrCode) - - val OpticalTanMethods = listOf(TanMethodType.ChipTanFlickercode, TanMethodType.ChipTanQrCode, - TanMethodType.ChipTanPhotoTanMatrixCode, TanMethodType.photoTan, TanMethodType.QrCode) - const val DialogTag = "EnterTanDialog" } @@ -145,7 +140,7 @@ open class EnterTanDialog : DialogFragment() { } protected open fun setupTanView(rootView: View) { - if (OpticalTanMethods.contains(tanChallenge.tanMethod.type)) { + if (presenter.isOpticalTanMethod(tanChallenge.tanMethod)) { setupSelectTanMediumView(rootView) if (tanChallenge is FlickerCodeTanChallenge) { @@ -261,25 +256,16 @@ open class EnterTanDialog : DialogFragment() { protected open fun checkIfAppSettingsChanged() { if (flickerCodeView.didTanMethodSettingsChange) { - presenter.appSettings.flickerCodeSettings = flickerCodeView.tanMethodSettings - - presenter.appSettingsChanged() + presenter.updateTanMethodSettings(tanChallenge.tanMethod, flickerCodeView.tanMethodSettings) } if (tanImageView.didTanMethodSettingsChange) { - if (isQrTan(tanChallenge)) { - presenter.appSettings.qrCodeSettings = tanImageView.tanMethodSettings - } - else { - presenter.appSettings.photoTanSettings = tanImageView.tanMethodSettings - } - - presenter.appSettingsChanged() + presenter.updateTanMethodSettings(tanChallenge.tanMethod, tanImageView.tanMethodSettings) } } protected open fun isQrTan(tanChallenge: TanChallenge): Boolean { - return QrCodeTanMethods.contains(tanChallenge.tanMethod.type) + return presenter.isQrTanMethod(tanChallenge.tanMethod) } } \ No newline at end of file diff --git a/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/EnterTanDialog.kt b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/EnterTanDialog.kt index 6461520f..9fd9d39f 100644 --- a/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/EnterTanDialog.kt +++ b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/EnterTanDialog.kt @@ -27,8 +27,6 @@ open class EnterTanDialog( ) : Window() { companion object { - val QrCodeTanMethods = listOf(TanMethodType.ChipTanQrCode, TanMethodType.QrCode) - private val ButtonHeight = 40.0 private val ButtonWidth = 150.0 } @@ -262,25 +260,16 @@ open class EnterTanDialog( protected open fun checkIfAppSettingsChanged() { if (flickerCodeView?.didTanMethodSettingsChange == true) { - presenter.appSettings.flickerCodeSettings = flickerCodeView?.tanMethodSettings - - presenter.appSettingsChanged() + presenter.updateTanMethodSettings(challenge.tanMethod, flickerCodeView?.tanMethodSettings) } if (tanImageView?.didTanMethodSettingsChange == true) { - if (isQrTan(challenge)) { - presenter.appSettings.qrCodeSettings = tanImageView?.tanMethodSettings - } - else { - presenter.appSettings.photoTanSettings = tanImageView?.tanMethodSettings - } - - presenter.appSettingsChanged() + presenter.updateTanMethodSettings(challenge.tanMethod, tanImageView?.tanMethodSettings) } } protected open fun isQrTan(tanChallenge: TanChallenge): Boolean { - return QrCodeTanMethods.contains(tanChallenge.tanMethod.type) + return presenter.isQrTanMethod(tanChallenge.tanMethod) } } \ No newline at end of file diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt index c80787b2..e9781d07 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt @@ -22,6 +22,7 @@ import net.dankito.banking.ui.model.moneytransfer.ExtractTransferMoneyDataFromPd import net.dankito.banking.ui.model.moneytransfer.ExtractTransferMoneyDataFromPdfResultType import net.dankito.banking.ui.model.parameters.GetTransactionsParameter import net.dankito.banking.ui.model.settings.AppSettings +import net.dankito.banking.ui.model.settings.TanMethodSettings import net.dankito.banking.ui.model.tan.* import net.dankito.banking.ui.util.CurrencyInfo import net.dankito.banking.ui.util.CurrencyInfoProvider @@ -54,7 +55,14 @@ open class BankingPresenter( companion object { val ChipTanTanMethods = listOf(TanMethodType.ChipTanManuell, TanMethodType.ChipTanFlickercode, TanMethodType.ChipTanUsb, - TanMethodType.ChipTanQrCode, TanMethodType.ChipTanPhotoTanMatrixCode) + TanMethodType.ChipTanQrCode, TanMethodType.ChipTanPhotoTanMatrixCode) + + val QrCodeTanMethods = listOf(TanMethodType.ChipTanQrCode, TanMethodType.QrCode) + + val PhotoTanMethods = listOf(TanMethodType.ChipTanPhotoTanMatrixCode, TanMethodType.photoTan) + + val OpticalTanMethods = listOf(TanMethodType.ChipTanFlickercode, TanMethodType.ChipTanQrCode, + TanMethodType.ChipTanPhotoTanMatrixCode, TanMethodType.photoTan, TanMethodType.QrCode) protected const val OneDayMillis = 24 * 60 * 60 * 1000L @@ -879,6 +887,36 @@ open class BankingPresenter( } + open fun isFlickerCodeTanMethod(tanMethod: TanMethod): Boolean { + return tanMethod.type == TanMethodType.ChipTanFlickercode + } + + open fun isQrTanMethod(tanMethod: TanMethod): Boolean { + return QrCodeTanMethods.contains(tanMethod.type) + } + + open fun isPhotoTanMethod(tanMethod: TanMethod): Boolean { + return PhotoTanMethods.contains(tanMethod.type) + } + + open fun isOpticalTanMethod(tanMethod: TanMethod): Boolean { + return OpticalTanMethods.contains(tanMethod.type) + } + + open fun updateTanMethodSettings(tanMethod: TanMethod, settings: TanMethodSettings?) { + if (isFlickerCodeTanMethod(tanMethod)) { + appSettings.flickerCodeSettings = settings + } + else if (isQrTanMethod(tanMethod)) { + appSettings.qrCodeSettings = settings + } + else if (isPhotoTanMethod(tanMethod)) { + appSettings.photoTanSettings = settings + } + + appSettingsChanged() + } + open fun getTanMediaForTanMethod(bank: TypedBankData, tanMethod: TanMethod): List { if (ChipTanTanMethods.contains(tanMethod.type)) { return bank.tanMediaSorted.filterIsInstance() diff --git a/ui/BankingiOSApp/BankingiOSApp/persistence/Mapper.swift b/ui/BankingiOSApp/BankingiOSApp/persistence/Mapper.swift index d6f0d183..8eb9528e 100644 --- a/ui/BankingiOSApp/BankingiOSApp/persistence/Mapper.swift +++ b/ui/BankingiOSApp/BankingiOSApp/persistence/Mapper.swift @@ -66,6 +66,8 @@ class Mapper { mapped.userSetDisplayName = account.userSetDisplayName mapped.displayIndex = account.displayIndex + mapped.hideAccount = account.hideAccount + mapped.updateAccountAutomatically = account.updateAccountAutomatically mapped.doNotShowStrikingFetchAllTransactionsView = account.doNotShowStrikingFetchAllTransactionsView mapped.bookedTransactions = map(mapped, account.transactions as? Set) @@ -105,6 +107,8 @@ class Mapper { mapped.userSetDisplayName = account.userSetDisplayName mapped.displayIndex = account.displayIndex + mapped.hideAccount = account.hideAccount + mapped.updateAccountAutomatically = account.updateAccountAutomatically mapped.doNotShowStrikingFetchAllTransactionsView = account.doNotShowStrikingFetchAllTransactionsView mapped.transactions = NSSet(array: map(mapped, account.bookedTransactions, context)) diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/tan/FlickerCodeTanView.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/tan/FlickerCodeTanView.swift index f1d24f14..780f2eec 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/tan/FlickerCodeTanView.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/tan/FlickerCodeTanView.swift @@ -4,9 +4,6 @@ import BankingUiSwift struct FlickerCodeTanView: View { - private static let FlickerCodeScaleFactorUserDefaultsKey = "FlickerCodeScaleFactor" - private static let FlickerCodeFrequencyDefaultsKey = "FlickerCodeFrequency" - private static let SpaceBetweenStripesStepSize: CGFloat = 0.5 private static let StripesWidthStepSize: CGFloat = 2.35 * Self.SpaceBetweenStripesStepSize @@ -26,7 +23,9 @@ struct FlickerCodeTanView: View { private let animator: FlickerCodeAnimator = FlickerCodeAnimator() - @State private var frequency = CGFloat(UserDefaults.standard.float(forKey: Self.FlickerCodeFrequencyDefaultsKey, defaultValue: Float(FlickerCodeAnimator.DefaultFrequency))) + private var tanMethodSettings: TanMethodSettings? = nil + + @State private var frequency = CGFloat(FlickerCodeAnimator.DefaultFrequency) private var frequencyBinding: Binding { Binding( @@ -37,8 +36,6 @@ struct FlickerCodeTanView: View { self.animator.setFrequency(frequency: Int(newFrequency)) - UserDefaults.standard.set(newFrequency, forKey: Self.FlickerCodeFrequencyDefaultsKey) - DispatchQueue.main.async { self.frequency = newFrequency } @@ -51,7 +48,7 @@ struct FlickerCodeTanView: View { @State private var spaceBetweenStripes: CGFloat = 10 @State private var spaceBetweenTanGeneratorPositionMarker: CGFloat = 4 * 40 + 4 * 15 - TanGeneratorPositionMarker.Width - @State private var scaleFactor = CGFloat(UserDefaults.standard.float(forKey: Self.FlickerCodeScaleFactorUserDefaultsKey, defaultValue: 20.0)) + @State private var scaleFactor: CGFloat = 20.0 private var scaleFactorBinding: Binding { Binding( @@ -60,8 +57,6 @@ struct FlickerCodeTanView: View { if (self.scaleFactor != $0) { let newFlickerScaleFactor = $0 - UserDefaults.standard.set(newFlickerScaleFactor, forKey: Self.FlickerCodeScaleFactorUserDefaultsKey) - DispatchQueue.main.async { self.scaleFactor = newFlickerScaleFactor @@ -75,12 +70,22 @@ struct FlickerCodeTanView: View { @State private var isInitialized = false + @Inject private var presenter: BankingPresenterSwift + + init(_ tanChallenge: BankingUiSwift.FlickerCodeTanChallenge) { self.tanChallenge = tanChallenge let oneStepDiff = 5 * Self.StripesWidthStepSize + 4 * Self.SpaceBetweenStripesStepSize MaxScaleFactor = CGFloat(Int(UIScreen.main.bounds.width / oneStepDiff)) + self.tanMethodSettings = presenter.appSettings.flickerCodeSettings + + if let settings = tanMethodSettings { + self._scaleFactor = State(initialValue: CGFloat(settings.width)) + self._frequency = State(initialValue: CGFloat(settings.frequency)) + } + animator.setFrequency(frequency: Int(frequency)) } @@ -160,6 +165,9 @@ struct FlickerCodeTanView: View { self.animator.animate(self.tanChallenge.flickerCode.parsedDataSet, self.showStep) } } + .onDisappear { + self.saveChanges() + } } @@ -179,6 +187,21 @@ struct FlickerCodeTanView: View { spaceBetweenTanGeneratorPositionMarker = 4 * stripeWidth + 4 * spaceBetweenStripes - TanGeneratorPositionMarker.Width } + + private func saveChanges() { + let scaleFactorInt = Int32(scaleFactor) + let frequencyInt = Int32(frequency) + + if scaleFactorInt != tanMethodSettings?.width || frequencyInt != tanMethodSettings?.frequency { + let settings = tanMethodSettings ?? TanMethodSettings(width: 0, height: 0, space: 0, frequency: 0) + + settings.width = scaleFactorInt + settings.frequency = frequencyInt + + presenter.updateTanMethodSettings(tanMethod: tanChallenge.tanMethod, settings: settings) + } + } + } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/tan/ImageTanView.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/tan/ImageTanView.swift index 0c516e00..220220cc 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/tan/ImageTanView.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/tan/ImageTanView.swift @@ -4,26 +4,34 @@ import BankingUiSwift struct ImageTanView: View { - private static let ImageTanWidthDefaultsKey = "ImageTanWidth" - - private var tanChallenge: ImageTanChallenge private var imageData: Data - @State private var imageWidth = CGFloat(UserDefaults.standard.float(forKey: Self.ImageTanWidthDefaultsKey, defaultValue: Float(UIScreen.main.bounds.width / 2))) + @State private var imageWidth: CGFloat = CGFloat(UIScreen.main.bounds.width / 2) + + private var tanMethodSettings: TanMethodSettings? = nil + + + @Inject private var presenter: BankingPresenterSwift init(_ tanChallenge: ImageTanChallenge) { self.tanChallenge = tanChallenge self.imageData = tanChallenge.image.imageBytesAsNSData() + + self.tanMethodSettings = presenter.isQrTanMethod(tanMethod: tanChallenge.tanMethod) ? presenter.appSettings.qrCodeSettings : presenter.appSettings.photoTanSettings + + if let imageWidth = tanMethodSettings?.width { + self._imageWidth = State(initialValue: CGFloat(imageWidth)) + } } var body: some View { Section { - ScaleImageView($imageWidth.didSet(self.imageWidthDidChange)) + ScaleImageView($imageWidth) HStack { Spacer() @@ -35,12 +43,20 @@ struct ImageTanView: View { Spacer() } } + .onDisappear { + self.saveChanges() + } } - private func imageWidthDidChange(oldValue: CGFloat?, newValue: CGFloat?) { - if let newValue = newValue { - UserDefaults.standard.set(newValue, forKey: Self.ImageTanWidthDefaultsKey) + private func saveChanges() { + let imageWidthInt = Int32(imageWidth) + + if imageWidthInt != tanMethodSettings?.width { + let settings = tanMethodSettings ?? TanMethodSettings(width: imageWidthInt, height: 0, space: 0, frequency: 0) + settings.width = imageWidthInt + + presenter.updateTanMethodSettings(tanMethod: tanChallenge.tanMethod, settings: settings) } }