taler-ios

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

MoreSettingsView.swift (6251B)


      1 /*
      2  * This file is part of GNU Taler, ©2022-26 Taler Systems S.A.
      3  * See LICENSE.md
      4  */
      5 /**
      6  * @author Marc Stibane
      7  */
      8 import SwiftUI
      9 import taler_swift
     10 import SymLog
     11 
     12 struct MoreSettingsView: View {
     13     private let symLog = SymLogV(0)
     14     let stack: CallStack
     15     let navTitle: String
     16 
     17     @EnvironmentObject private var controller: Controller
     18     @EnvironmentObject private var model: WalletModel
     19 //    @Environment(\.colorSchemeContrast) private var colorSchemeContrast
     20 #if DEBUG
     21     @AppStorage("developerMode") var developerMode: Bool = true
     22 #else
     23     @AppStorage("developerMode") var developerMode: Bool = false
     24 #endif
     25     @AppStorage("useHaptics") var useHaptics: Bool = true
     26     @AppStorage("playSounds") var playSounds: Bool = false
     27     @AppStorage("pasteAutomatically") var pasteAutomatically: Bool = false
     28     @AppStorage("talerFontIndex") var talerFontIndex: Int = 0
     29     @AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic
     30     @AppStorage("minimalistic") var minimalistic: Bool = false
     31     @AppStorage("showQRauto16") var showQRauto16: Bool = true   // iOS 16 doesn't have NFC emulation
     32     @AppStorage("showQRauto17") var showQRauto17: Bool = false  // but iOS 17 does
     33     @AppStorage("preferredColorScheme") var preferredColorScheme: Int = 0
     34     @AppStorage("oimEuro") var oimEuro: Bool = false
     35     @AppStorage("oimChart") var oimChart: Bool = false
     36     @AppStorage("payTokenAutomatically") var payTokenAutomatically: Bool = true
     37     @AppStorage("payMoneyAutomatically") var payMoneyAutomatically: Bool = false
     38 
     39     @State private var listID = UUID()
     40 
     41     func redraw(_ newFont: Int) -> Void {
     42         if newFont != talerFontIndex {
     43             talerFontIndex = newFont
     44             withAnimation { listID = UUID() }
     45         }
     46     }
     47 
     48     var body: some View {
     49 #if PRINT_CHANGES
     50         let _ = Self._printChanges()
     51         let _ = symLog.vlog()       // just to get the # to compare it with .onAppear & onDisappear
     52 #endif
     53         let list = List {
     54             Section {
     55                 let showQRstring = String(localized: "Show QR codes")
     56                 let showQRhint = String(localized: "Automatically for P2P transactions")
     57                 if #available(iOS 17.7, *) {
     58                     SettingsToggle(name: showQRstring, value: $showQRauto17, id1: "showQRautomatic",
     59                             description: showQRhint)
     60                 } else {
     61                     SettingsToggle(name: showQRstring, value: $showQRauto16, id1: "showQRautomatic",
     62                             description: showQRhint)
     63                 }
     64                 SettingsQuadState(name: String(localized: "Preferred Appearance"),
     65                                  value: $preferredColorScheme,
     66                                    id1: "colorScheme")
     67                 if controller.hapticCapability.supportsHaptics {
     68                     SettingsToggle(name: String(localized: "Haptics"), value: $useHaptics,
     69                                     id1: "haptics",
     70                             description: String(localized: "Vibration Feedback"))
     71                 }
     72 
     73                 SettingsToggle(name: String(localized: "Play Payment Sounds"), value: $playSounds,
     74                                 id1: "playSounds",
     75                         description: String(localized: "When a transaction finished")) {_ in}
     76 
     77                 SettingsToggle(name: String(localized: "Paste automatically"), value: $pasteAutomatically,
     78                                 id1: "pasteAutomatically",
     79                         description: String(localized: "When this app activates")) {_ in}
     80 
     81                 /// Backup
     82                 let backupTitle = String(localized: "TitleBackup", defaultValue: "Backup / Restore")
     83                 let backupDest = BackupView(stack: stack.push(backupTitle),
     84                                          navTitle: backupTitle)
     85                 NavigationLink {
     86                     backupDest
     87                 } label: {
     88                     SettingsItem(name: backupTitle, id1: "backup",
     89                           description: String(localized: "Backup your money")) {}
     90                 }
     91 //                SettingsFont(title: String(localized: "Font:"), value: talerFontIndex, action: redraw)
     92 //                    .id("font")
     93             }
     94             Section(header: Text(String(localized: "Pay automatically"))) {
     95                 SettingsToggle(name: String(localized: "Pay token automatically"), value: $payTokenAutomatically,
     96                                 id1: "payTokenAutomatically",
     97                         description: String(localized: "Skip confirmation to speed up", comment: "Pay automatically"))
     98                 SettingsToggle(name: String(localized: "Pay money automatically"), value: $payMoneyAutomatically,
     99                                 id1: "payMoneyAutomatically",
    100                         description: String(localized: "Skip confirmation to speed up", comment: "Pay automatically"))
    101                 if payMoneyAutomatically {
    102                     Text("Not yet implemented...")
    103                     Text("Allow automatic payments for chosen merchants only.")
    104                 }
    105             } // Pay automatically
    106 #if OIM
    107             Section {
    108                 SettingsToggle(name: String(localized: "OIM: Euro"), value: $oimEuro,
    109                                 id1: "oimEuro",
    110                         description: String(localized: "OIM currency for KUDOS"))
    111                 SettingsToggle(name: String(localized: "OIM: Chart"), value: $oimChart,
    112                                 id1: "oimChart",
    113                         description: String(localized: "OIM history as chart"))
    114             } // OIM
    115 #endif
    116         }   .listStyle(myListStyle.style).anyView
    117             .id(listID)
    118             .navigationTitle(navTitle)
    119             .onAppear() {
    120                 DebugViewC.shared.setViewID(VIEW_SETTINGS2, stack: stack.push())
    121             }
    122         if #available(iOS 26.0, *) {
    123             list
    124         } else {
    125             list
    126                 .padding(.bottom)
    127         }
    128     } // body
    129 }
    130 // MARK: -
    131 #if DEBUG
    132 //struct SettingsView_Previews: PreviewProvider {
    133 //    static var previews: some View {
    134 //        SettingsView(stack: CallStack("Preview"), balances: <#Binding<[Balance]>#>, navTitle: "Settings")
    135 //    }
    136 //}
    137 #endif