Implemented remembering for which accounts FetchAllTransactionsOverlay has been dismissed to not show it again for these accounts

This commit is contained in:
dankito 2020-09-07 01:20:09 +02:00
parent f3332c6da7
commit 4d781aea65
3 changed files with 40 additions and 7 deletions

View File

@ -1,5 +1,6 @@
import SwiftUI import SwiftUI
import BankingUiSwift import BankingUiSwift
import Combine
extension View { extension View {
@ -95,6 +96,15 @@ extension View {
return self.animation(nil) 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()
}
}
} }

View File

@ -4,6 +4,9 @@ import BankingUiSwift
struct AccountTransactionsDialog: View { struct AccountTransactionsDialog: View {
static private let DoNotShowFetchAllTransactionsOverlayForUserDefaultsKeyPrefix = "DoNotShowFetchAllTransactionsOverlayFor_"
private let title: String private let title: String
private let allTransactions: [AccountTransaction] private let allTransactions: [AccountTransaction]
@ -126,7 +129,7 @@ struct AccountTransactionsDialog: View {
Spacer() Spacer()
HStack(alignment: .center) { HStack(alignment: .center) {
Button(action: { self.showFetchAllTransactionsOverlay = false }) { Button(action: { self.doNotShowFetchAllTransactionsOverlayAnymore() }) {
Text("x") Text("x")
.bold() .bold()
} }
@ -149,6 +152,9 @@ struct AccountTransactionsDialog: View {
.overlay(Divider(), alignment: .top) .overlay(Divider(), alignment: .top)
} }
} }
.executeMutatingMethod {
self.showFetchAllTransactionsOverlay = self.shouldShowFetchAllTransactionsOverlay
}
.alert(item: $errorMessage) { message in .alert(item: $errorMessage) { message in
Alert(title: message.title, message: message.message, dismissButton: message.primaryButton) Alert(title: message.title, message: message.message, dismissButton: message.primaryButton)
} }
@ -177,7 +183,7 @@ struct AccountTransactionsDialog: View {
private func handleGetAllTransactionsResult(_ response: GetTransactionsResponse) { private func handleGetAllTransactionsResult(_ response: GetTransactionsResponse) {
self.accountsForWhichNotAllTransactionsHaveBeenFetched = self.accountsForWhichNotAllTransactionsHaveBeenFetched.filter { $0.haveAllTransactionsBeenFetched == false } self.accountsForWhichNotAllTransactionsHaveBeenFetched = self.accountsForWhichNotAllTransactionsHaveBeenFetched.filter { $0.haveAllTransactionsBeenFetched == false }
self.haveAllTransactionsBeenFetched = self.accountsForWhichNotAllTransactionsHaveBeenFetched.isEmpty self.haveAllTransactionsBeenFetched = self.accountsForWhichNotAllTransactionsHaveBeenFetched.isEmpty
self.showFetchAllTransactionsOverlay = self.accountsForWhichNotAllTransactionsHaveBeenFetched.isNotEmpty self.showFetchAllTransactionsOverlay = shouldShowFetchAllTransactionsOverlay
if response.isSuccessful { if response.isSuccessful {
self.filterTransactions(self.searchText) self.filterTransactions(self.searchText)
@ -192,6 +198,27 @@ struct AccountTransactionsDialog: View {
self.balanceOfFilteredTransactions = query.isBlank ? balanceOfAllTransactions : filteredTransactions.sumAmounts() 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
}
} }

View File

@ -25,8 +25,6 @@ struct FlickerCodeTanView: View {
private let animator: FlickerCodeAnimator = FlickerCodeAnimator() 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))) @State private var frequency = CGFloat(UserDefaults.standard.float(forKey: Self.FlickerCodeFrequencyDefaultsKey, defaultValue: Float(FlickerCodeAnimator.DefaultFrequency)))
@ -150,9 +148,7 @@ struct FlickerCodeTanView: View {
.listRowInsets(EdgeInsets()) .listRowInsets(EdgeInsets())
} }
// what a hack to be able to call animator.animate() (otherwise compiler would throw 'use of immutable self in closure' error) // 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 .executeMutatingMethod {
self.timer.upstream.connect().cancel()
self.calculateStripeWidth() self.calculateStripeWidth()
self.animator.animate(self.tanChallenge.flickerCode.parsedDataSet, self.showStep) self.animator.animate(self.tanChallenge.flickerCode.parsedDataSet, self.showStep)