diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/ViewExtensions.swift b/ui/BankingiOSApp/BankingiOSApp/ui/ViewExtensions.swift index 5133ad66..5c2b783d 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/ViewExtensions.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/ViewExtensions.swift @@ -1,5 +1,6 @@ import SwiftUI import BankingUiSwift +import Combine extension View { @@ -95,6 +96,15 @@ extension View { return self.animation(nil) } + func executeMutatingMethod(method: @escaping () -> Void) -> some View { + let timerPublisher = Timer.publish(every: 0.1, on: .main, in: .common) + + return self.onReceive(timerPublisher.autoconnect()) { _ in + timerPublisher.connect().cancel() + + method() + } + } } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountTransactionsDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountTransactionsDialog.swift index 15b9feda..8ffb3875 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountTransactionsDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountTransactionsDialog.swift @@ -4,6 +4,9 @@ import BankingUiSwift struct AccountTransactionsDialog: View { + static private let DoNotShowFetchAllTransactionsOverlayForUserDefaultsKeyPrefix = "DoNotShowFetchAllTransactionsOverlayFor_" + + private let title: String private let allTransactions: [AccountTransaction] @@ -126,7 +129,7 @@ struct AccountTransactionsDialog: View { Spacer() HStack(alignment: .center) { - Button(action: { self.showFetchAllTransactionsOverlay = false }) { + Button(action: { self.doNotShowFetchAllTransactionsOverlayAnymore() }) { Text("x") .bold() } @@ -149,6 +152,9 @@ struct AccountTransactionsDialog: View { .overlay(Divider(), alignment: .top) } } + .executeMutatingMethod { + self.showFetchAllTransactionsOverlay = self.shouldShowFetchAllTransactionsOverlay + } .alert(item: $errorMessage) { message in Alert(title: message.title, message: message.message, dismissButton: message.primaryButton) } @@ -177,7 +183,7 @@ struct AccountTransactionsDialog: View { private func handleGetAllTransactionsResult(_ response: GetTransactionsResponse) { self.accountsForWhichNotAllTransactionsHaveBeenFetched = self.accountsForWhichNotAllTransactionsHaveBeenFetched.filter { $0.haveAllTransactionsBeenFetched == false } self.haveAllTransactionsBeenFetched = self.accountsForWhichNotAllTransactionsHaveBeenFetched.isEmpty - self.showFetchAllTransactionsOverlay = self.accountsForWhichNotAllTransactionsHaveBeenFetched.isNotEmpty + self.showFetchAllTransactionsOverlay = shouldShowFetchAllTransactionsOverlay if response.isSuccessful { self.filterTransactions(self.searchText) @@ -192,6 +198,27 @@ struct AccountTransactionsDialog: View { self.balanceOfFilteredTransactions = query.isBlank ? balanceOfAllTransactions : filteredTransactions.sumAmounts() } + + + private func doNotShowFetchAllTransactionsOverlayAnymore() { + for account in accountsForWhichNotAllTransactionsHaveBeenFetched { + UserDefaults.standard.set(true, forKey: Self.DoNotShowFetchAllTransactionsOverlayForUserDefaultsKeyPrefix + account.technicalId) + } + + showFetchAllTransactionsOverlay = false + } + + private var shouldShowFetchAllTransactionsOverlay: Bool { + if accountsForWhichNotAllTransactionsHaveBeenFetched.isNotEmpty { + var copy = accountsForWhichNotAllTransactionsHaveBeenFetched + + copy.removeAll { UserDefaults.standard.bool(forKey: Self.DoNotShowFetchAllTransactionsOverlayForUserDefaultsKeyPrefix + $0.technicalId, defaultValue: false) } + + return copy.isNotEmpty + } + + return false + } } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/FlickerCodeTanView.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/FlickerCodeTanView.swift index 211aff82..0b2d1aa9 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/FlickerCodeTanView.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/FlickerCodeTanView.swift @@ -25,8 +25,6 @@ struct FlickerCodeTanView: View { private let animator: FlickerCodeAnimator = FlickerCodeAnimator() - private let timer = Timer.publish(every: 0.1, on: .main, in: .common).autoconnect() - @State private var frequency = CGFloat(UserDefaults.standard.float(forKey: Self.FlickerCodeFrequencyDefaultsKey, defaultValue: Float(FlickerCodeAnimator.DefaultFrequency))) @@ -150,9 +148,7 @@ struct FlickerCodeTanView: View { .listRowInsets(EdgeInsets()) } // what a hack to be able to call animator.animate() (otherwise compiler would throw 'use of immutable self in closure' error) - .onReceive(timer) { timer in - self.timer.upstream.connect().cancel() - + .executeMutatingMethod { self.calculateStripeWidth() self.animator.animate(self.tanChallenge.flickerCode.parsedDataSet, self.showStep)