Simplified persisting TanMethodSettings and implemented saving TanMethodSettings on AppSettings in iOS
This commit is contained in:
parent
589e1e673a
commit
88ba716639
|
@ -32,11 +32,6 @@ import javax.inject.Inject
|
||||||
open class EnterTanDialog : DialogFragment() {
|
open class EnterTanDialog : DialogFragment() {
|
||||||
|
|
||||||
companion object {
|
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"
|
const val DialogTag = "EnterTanDialog"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +140,7 @@ open class EnterTanDialog : DialogFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun setupTanView(rootView: View) {
|
protected open fun setupTanView(rootView: View) {
|
||||||
if (OpticalTanMethods.contains(tanChallenge.tanMethod.type)) {
|
if (presenter.isOpticalTanMethod(tanChallenge.tanMethod)) {
|
||||||
setupSelectTanMediumView(rootView)
|
setupSelectTanMediumView(rootView)
|
||||||
|
|
||||||
if (tanChallenge is FlickerCodeTanChallenge) {
|
if (tanChallenge is FlickerCodeTanChallenge) {
|
||||||
|
@ -261,25 +256,16 @@ open class EnterTanDialog : DialogFragment() {
|
||||||
|
|
||||||
protected open fun checkIfAppSettingsChanged() {
|
protected open fun checkIfAppSettingsChanged() {
|
||||||
if (flickerCodeView.didTanMethodSettingsChange) {
|
if (flickerCodeView.didTanMethodSettingsChange) {
|
||||||
presenter.appSettings.flickerCodeSettings = flickerCodeView.tanMethodSettings
|
presenter.updateTanMethodSettings(tanChallenge.tanMethod, flickerCodeView.tanMethodSettings)
|
||||||
|
|
||||||
presenter.appSettingsChanged()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tanImageView.didTanMethodSettingsChange) {
|
if (tanImageView.didTanMethodSettingsChange) {
|
||||||
if (isQrTan(tanChallenge)) {
|
presenter.updateTanMethodSettings(tanChallenge.tanMethod, tanImageView.tanMethodSettings)
|
||||||
presenter.appSettings.qrCodeSettings = tanImageView.tanMethodSettings
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
presenter.appSettings.photoTanSettings = tanImageView.tanMethodSettings
|
|
||||||
}
|
|
||||||
|
|
||||||
presenter.appSettingsChanged()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun isQrTan(tanChallenge: TanChallenge): Boolean {
|
protected open fun isQrTan(tanChallenge: TanChallenge): Boolean {
|
||||||
return QrCodeTanMethods.contains(tanChallenge.tanMethod.type)
|
return presenter.isQrTanMethod(tanChallenge.tanMethod)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -27,8 +27,6 @@ open class EnterTanDialog(
|
||||||
) : Window() {
|
) : Window() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val QrCodeTanMethods = listOf(TanMethodType.ChipTanQrCode, TanMethodType.QrCode)
|
|
||||||
|
|
||||||
private val ButtonHeight = 40.0
|
private val ButtonHeight = 40.0
|
||||||
private val ButtonWidth = 150.0
|
private val ButtonWidth = 150.0
|
||||||
}
|
}
|
||||||
|
@ -262,25 +260,16 @@ open class EnterTanDialog(
|
||||||
|
|
||||||
protected open fun checkIfAppSettingsChanged() {
|
protected open fun checkIfAppSettingsChanged() {
|
||||||
if (flickerCodeView?.didTanMethodSettingsChange == true) {
|
if (flickerCodeView?.didTanMethodSettingsChange == true) {
|
||||||
presenter.appSettings.flickerCodeSettings = flickerCodeView?.tanMethodSettings
|
presenter.updateTanMethodSettings(challenge.tanMethod, flickerCodeView?.tanMethodSettings)
|
||||||
|
|
||||||
presenter.appSettingsChanged()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tanImageView?.didTanMethodSettingsChange == true) {
|
if (tanImageView?.didTanMethodSettingsChange == true) {
|
||||||
if (isQrTan(challenge)) {
|
presenter.updateTanMethodSettings(challenge.tanMethod, tanImageView?.tanMethodSettings)
|
||||||
presenter.appSettings.qrCodeSettings = tanImageView?.tanMethodSettings
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
presenter.appSettings.photoTanSettings = tanImageView?.tanMethodSettings
|
|
||||||
}
|
|
||||||
|
|
||||||
presenter.appSettingsChanged()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun isQrTan(tanChallenge: TanChallenge): Boolean {
|
protected open fun isQrTan(tanChallenge: TanChallenge): Boolean {
|
||||||
return QrCodeTanMethods.contains(tanChallenge.tanMethod.type)
|
return presenter.isQrTanMethod(tanChallenge.tanMethod)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -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.moneytransfer.ExtractTransferMoneyDataFromPdfResultType
|
||||||
import net.dankito.banking.ui.model.parameters.GetTransactionsParameter
|
import net.dankito.banking.ui.model.parameters.GetTransactionsParameter
|
||||||
import net.dankito.banking.ui.model.settings.AppSettings
|
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.model.tan.*
|
||||||
import net.dankito.banking.ui.util.CurrencyInfo
|
import net.dankito.banking.ui.util.CurrencyInfo
|
||||||
import net.dankito.banking.ui.util.CurrencyInfoProvider
|
import net.dankito.banking.ui.util.CurrencyInfoProvider
|
||||||
|
@ -54,7 +55,14 @@ open class BankingPresenter(
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val ChipTanTanMethods = listOf(TanMethodType.ChipTanManuell, TanMethodType.ChipTanFlickercode, TanMethodType.ChipTanUsb,
|
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
|
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<TanMedium> {
|
open fun getTanMediaForTanMethod(bank: TypedBankData, tanMethod: TanMethod): List<TanMedium> {
|
||||||
if (ChipTanTanMethods.contains(tanMethod.type)) {
|
if (ChipTanTanMethods.contains(tanMethod.type)) {
|
||||||
return bank.tanMediaSorted.filterIsInstance<TanGeneratorTanMedium>()
|
return bank.tanMediaSorted.filterIsInstance<TanGeneratorTanMedium>()
|
||||||
|
|
|
@ -66,6 +66,8 @@ class Mapper {
|
||||||
mapped.userSetDisplayName = account.userSetDisplayName
|
mapped.userSetDisplayName = account.userSetDisplayName
|
||||||
mapped.displayIndex = account.displayIndex
|
mapped.displayIndex = account.displayIndex
|
||||||
|
|
||||||
|
mapped.hideAccount = account.hideAccount
|
||||||
|
mapped.updateAccountAutomatically = account.updateAccountAutomatically
|
||||||
mapped.doNotShowStrikingFetchAllTransactionsView = account.doNotShowStrikingFetchAllTransactionsView
|
mapped.doNotShowStrikingFetchAllTransactionsView = account.doNotShowStrikingFetchAllTransactionsView
|
||||||
|
|
||||||
mapped.bookedTransactions = map(mapped, account.transactions as? Set<PersistedAccountTransaction>)
|
mapped.bookedTransactions = map(mapped, account.transactions as? Set<PersistedAccountTransaction>)
|
||||||
|
@ -105,6 +107,8 @@ class Mapper {
|
||||||
mapped.userSetDisplayName = account.userSetDisplayName
|
mapped.userSetDisplayName = account.userSetDisplayName
|
||||||
mapped.displayIndex = account.displayIndex
|
mapped.displayIndex = account.displayIndex
|
||||||
|
|
||||||
|
mapped.hideAccount = account.hideAccount
|
||||||
|
mapped.updateAccountAutomatically = account.updateAccountAutomatically
|
||||||
mapped.doNotShowStrikingFetchAllTransactionsView = account.doNotShowStrikingFetchAllTransactionsView
|
mapped.doNotShowStrikingFetchAllTransactionsView = account.doNotShowStrikingFetchAllTransactionsView
|
||||||
|
|
||||||
mapped.transactions = NSSet(array: map(mapped, account.bookedTransactions, context))
|
mapped.transactions = NSSet(array: map(mapped, account.bookedTransactions, context))
|
||||||
|
|
|
@ -4,9 +4,6 @@ import BankingUiSwift
|
||||||
|
|
||||||
struct FlickerCodeTanView: View {
|
struct FlickerCodeTanView: View {
|
||||||
|
|
||||||
private static let FlickerCodeScaleFactorUserDefaultsKey = "FlickerCodeScaleFactor"
|
|
||||||
private static let FlickerCodeFrequencyDefaultsKey = "FlickerCodeFrequency"
|
|
||||||
|
|
||||||
private static let SpaceBetweenStripesStepSize: CGFloat = 0.5
|
private static let SpaceBetweenStripesStepSize: CGFloat = 0.5
|
||||||
private static let StripesWidthStepSize: CGFloat = 2.35 * Self.SpaceBetweenStripesStepSize
|
private static let StripesWidthStepSize: CGFloat = 2.35 * Self.SpaceBetweenStripesStepSize
|
||||||
|
|
||||||
|
@ -26,7 +23,9 @@ struct FlickerCodeTanView: View {
|
||||||
private let animator: FlickerCodeAnimator = FlickerCodeAnimator()
|
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<CGFloat> {
|
private var frequencyBinding: Binding<CGFloat> {
|
||||||
Binding<CGFloat>(
|
Binding<CGFloat>(
|
||||||
|
@ -37,8 +36,6 @@ struct FlickerCodeTanView: View {
|
||||||
|
|
||||||
self.animator.setFrequency(frequency: Int(newFrequency))
|
self.animator.setFrequency(frequency: Int(newFrequency))
|
||||||
|
|
||||||
UserDefaults.standard.set(newFrequency, forKey: Self.FlickerCodeFrequencyDefaultsKey)
|
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.frequency = newFrequency
|
self.frequency = newFrequency
|
||||||
}
|
}
|
||||||
|
@ -51,7 +48,7 @@ struct FlickerCodeTanView: View {
|
||||||
@State private var spaceBetweenStripes: CGFloat = 10
|
@State private var spaceBetweenStripes: CGFloat = 10
|
||||||
@State private var spaceBetweenTanGeneratorPositionMarker: CGFloat = 4 * 40 + 4 * 15 - TanGeneratorPositionMarker.Width
|
@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<CGFloat> {
|
private var scaleFactorBinding: Binding<CGFloat> {
|
||||||
Binding<CGFloat>(
|
Binding<CGFloat>(
|
||||||
|
@ -60,8 +57,6 @@ struct FlickerCodeTanView: View {
|
||||||
if (self.scaleFactor != $0) {
|
if (self.scaleFactor != $0) {
|
||||||
let newFlickerScaleFactor = $0
|
let newFlickerScaleFactor = $0
|
||||||
|
|
||||||
UserDefaults.standard.set(newFlickerScaleFactor, forKey: Self.FlickerCodeScaleFactorUserDefaultsKey)
|
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.scaleFactor = newFlickerScaleFactor
|
self.scaleFactor = newFlickerScaleFactor
|
||||||
|
|
||||||
|
@ -75,12 +70,22 @@ struct FlickerCodeTanView: View {
|
||||||
@State private var isInitialized = false
|
@State private var isInitialized = false
|
||||||
|
|
||||||
|
|
||||||
|
@Inject private var presenter: BankingPresenterSwift
|
||||||
|
|
||||||
|
|
||||||
init(_ tanChallenge: BankingUiSwift.FlickerCodeTanChallenge) {
|
init(_ tanChallenge: BankingUiSwift.FlickerCodeTanChallenge) {
|
||||||
self.tanChallenge = tanChallenge
|
self.tanChallenge = tanChallenge
|
||||||
|
|
||||||
let oneStepDiff = 5 * Self.StripesWidthStepSize + 4 * Self.SpaceBetweenStripesStepSize
|
let oneStepDiff = 5 * Self.StripesWidthStepSize + 4 * Self.SpaceBetweenStripesStepSize
|
||||||
MaxScaleFactor = CGFloat(Int(UIScreen.main.bounds.width / oneStepDiff))
|
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))
|
animator.setFrequency(frequency: Int(frequency))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,6 +165,9 @@ struct FlickerCodeTanView: View {
|
||||||
self.animator.animate(self.tanChallenge.flickerCode.parsedDataSet, self.showStep)
|
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
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,26 +4,34 @@ import BankingUiSwift
|
||||||
|
|
||||||
struct ImageTanView: View {
|
struct ImageTanView: View {
|
||||||
|
|
||||||
private static let ImageTanWidthDefaultsKey = "ImageTanWidth"
|
|
||||||
|
|
||||||
|
|
||||||
private var tanChallenge: ImageTanChallenge
|
private var tanChallenge: ImageTanChallenge
|
||||||
|
|
||||||
private var imageData: Data
|
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) {
|
init(_ tanChallenge: ImageTanChallenge) {
|
||||||
self.tanChallenge = tanChallenge
|
self.tanChallenge = tanChallenge
|
||||||
|
|
||||||
self.imageData = tanChallenge.image.imageBytesAsNSData()
|
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 {
|
var body: some View {
|
||||||
Section {
|
Section {
|
||||||
ScaleImageView($imageWidth.didSet(self.imageWidthDidChange))
|
ScaleImageView($imageWidth)
|
||||||
|
|
||||||
HStack {
|
HStack {
|
||||||
Spacer()
|
Spacer()
|
||||||
|
@ -35,12 +43,20 @@ struct ImageTanView: View {
|
||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.onDisappear {
|
||||||
|
self.saveChanges()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private func imageWidthDidChange(oldValue: CGFloat?, newValue: CGFloat?) {
|
private func saveChanges() {
|
||||||
if let newValue = newValue {
|
let imageWidthInt = Int32(imageWidth)
|
||||||
UserDefaults.standard.set(newValue, forKey: Self.ImageTanWidthDefaultsKey)
|
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue