taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

commit 4ceabb65609b5e6a84704ab38ec5a3601249e32a
parent 7db2a0846a8a7797c450f4df38d4d9099c01e9cd
Author: Marc Stibane <marc@taler.net>
Date:   Wed, 26 Jun 2024 15:19:19 +0200

remove QR from Overview

Diffstat:
MTalerWallet1/Views/Overview/OverviewListV.swift | 158+++++++++++++++++--------------------------------------------------------------
1 file changed, 33 insertions(+), 125 deletions(-)

diff --git a/TalerWallet1/Views/Overview/OverviewListV.swift b/TalerWallet1/Views/Overview/OverviewListV.swift @@ -5,78 +5,23 @@ import SwiftUI import taler_swift import SymLog -import AVFoundation /// This view shows the list of balances / currencies, each in its own section struct OverviewListV: View { private let symLog = SymLogV(0) let stack: CallStack - let navTitle: String @Binding var balances: [Balance] // @Binding var shouldReloadPending: Int @Binding var shouldReloadBalances: Int + let cameraAction: () -> Void @EnvironmentObject private var model: WalletModel @EnvironmentObject private var controller: Controller + @AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic @State private var lastReloadedBalances = 0 @State private var amountToTransfer = Amount.zero(currency: EMPTYSTRING) // Update currency when used @State private var summary: String = "" - @State private var showQRScanner: Bool = false - @State private var showCameraAlert: Bool = false - - private var openSettingsButton: some View { - Button("Open Settings") { - showCameraAlert = false - UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!) - } - } - let ClosingAnnouncement = AttributedString(localized: "Closing Camera") - private var dismissAlertButton: some View { - Button("Cancel", role: .cancel) { - if #available(iOS 17.0, *) { - AccessibilityNotification.Announcement(ClosingAnnouncement).post() - } - showCameraAlert = false - } - } - private func dismissingSheet() { - if #available(iOS 17.0, *) { - AccessibilityNotification.Announcement(ClosingAnnouncement).post() - } - } - - var defaultPriorityAnnouncement = AttributedString(localized: "Opening Camera") - var lowPriorityAnnouncement: AttributedString { - var lowPriorityString = AttributedString ("Camera Loading") - if #available(iOS 17.0, *) { - lowPriorityString.accessibilitySpeechAnnouncementPriority = .low - } - return lowPriorityString - } - var highPriorityAnnouncement: AttributedString { - var highPriorityString = AttributedString("Camera Active") - if #available(iOS 17.0, *) { - highPriorityString.accessibilitySpeechAnnouncementPriority = .high - } - return highPriorityString - } - private func checkCameraAvailable() -> Void { - // Open Camera when QR-Button was tapped - if #available(iOS 17.0, *) { - AccessibilityNotification.Announcement(defaultPriorityAnnouncement).post() - } - AVCaptureDevice.requestAccess(for: .video, completionHandler: { (granted: Bool) -> Void in - if granted { - showQRScanner = true // present sheet - if #available(iOS 17.0, *) { - AccessibilityNotification.Announcement(highPriorityAnnouncement).post() - } - } else { - showCameraAlert = true - } - }) - } /// runs on MainActor if called in some Task {} @discardableResult @@ -99,77 +44,40 @@ struct OverviewListV: View { let _ = Self._printChanges() let _ = symLog.vlog() // just to get the # to compare it with .onAppear & onDisappear #endif - Content(symLog: symLog, stack: stack.push(), balances: $balances, - amountToTransfer: $amountToTransfer, summary: $summary, -// shouldReloadPending: $shouldReloadPending, - shouldReloadBalances: $shouldReloadBalances, - reloadBalances: reloadBalances) - .navigationTitle(navTitle) - .navigationBarItems(trailing: QRButton(action: checkCameraAvailable)) - .alert("Scanning QR-codes requires access to the camera", - isPresented: $showCameraAlert, - actions: { openSettingsButton - dismissAlertButton }, - message: { Text("Please allow camera access in settings.") }) - .sheet(isPresented: $showQRScanner, onDismiss: dismissingSheet) { - let sheet = AnyView(QRSheet(stack: stack.push(".sheet"))) - Sheet(sheetView: sheet) - } // sheet - .task(id: shouldReloadBalances) { - symLog.log(".task shouldReloadBalances \(shouldReloadBalances)") - let invalidateCache = (lastReloadedBalances != shouldReloadBalances) - lastReloadedBalances = shouldReloadBalances - await reloadBalances(stack.push(".task"), invalidateCache) - } // task - } -} -// MARK: - -extension OverviewListV { - struct Content: View { - let symLog: SymLogV? - let stack: CallStack - @Binding var balances: [Balance] - @Binding var amountToTransfer: Amount - @Binding var summary: String -// @Binding var shouldReloadPending: Int - @Binding var shouldReloadBalances: Int - var reloadBalances: (_ stack: CallStack, _ invalidateCache: Bool) async -> Int? - - @AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic - - var body: some View { -#if PRINT_CHANGES - let _ = Self._printChanges() - let _ = symLog?.vlog() // just to get the # to compare it with .onAppear & onDisappear -#endif - Group { // necessary for .backslide transition (bug in SwiftUI) - let count = balances.count - if balances.isEmpty { - WalletEmptyView(stack: stack.push("isEmpty")) - } else { - List(balances, id: \.self) { balance in - OverviewSectionV(stack: stack.push("\(balance.scopeInfo.currency)"), - balance: balance, // this is the currency to be used - sectionCount: count, - amountToTransfer: $amountToTransfer, // does still have the wrong currency - summary: $summary, - shouldReloadBalances: $shouldReloadBalances) - } - .onAppear() { - DebugViewC.shared.setViewID(VIEW_BALANCES, stack: stack.push("onAppear")) - } - .listStyle(myListStyle.style).anyView + Group { // necessary for .backslide transition (bug in SwiftUI) + let count = balances.count + if balances.isEmpty { + WalletEmptyView(stack: stack.push("isEmpty")) + } else { + List(balances, id: \.self) { balance in + OverviewSectionV(stack: stack.push("\(balance.scopeInfo.currency)"), + balance: balance, // this is the currency to be used + sectionCount: count, + amountToTransfer: $amountToTransfer, // does still have the wrong currency + summary: $summary, + shouldReloadBalances: $shouldReloadBalances) } + .onAppear() { + DebugViewC.shared.setViewID(VIEW_BALANCES, stack: stack.push("onAppear")) + } + .listStyle(myListStyle.style).anyView } + } #if REFRESHABLE - .refreshable { // already async - symLog?.log("refreshing balances") - let count = await reloadBalances(stack.push("refreshing balances"), true) - if let count, count > 0 { - NotificationCenter.default.post(name: .BalanceReloaded, object: nil) - } + .refreshable { // already async + symLog?.log("refreshing balances") + let count = await reloadBalances(stack.push("refreshing balances"), true) + if let count, count > 0 { + NotificationCenter.default.post(name: .BalanceReloaded, object: nil) } + } #endif - } // body - } // Content + .navigationBarItems(trailing: QRButton(action: cameraAction)) + .task(id: shouldReloadBalances) { + symLog.log(".task shouldReloadBalances \(shouldReloadBalances)") + let invalidateCache = (lastReloadedBalances != shouldReloadBalances) + lastReloadedBalances = shouldReloadBalances + await reloadBalances(stack.push(".task"), invalidateCache) + } // task + } }