taler-ios

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

MoreSettingsView.swift (6215B)


      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
     32     @AppStorage("showQRauto17") var showQRauto17: Bool = false
     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                 let showQRstring = String(localized: "Show QR codes")
     55                 let showQRhint = String(localized: "Automatically for P2P transactions")
     56                 if #available(iOS 17.7, *) {
     57                     SettingsToggle(name: showQRstring, value: $showQRauto17, id1: "showQRautomatic",
     58                             description: showQRhint)
     59                 } else {
     60                     SettingsToggle(name: showQRstring, value: $showQRauto16, id1: "showQRautomatic",
     61                             description: showQRhint)
     62                 }
     63                 SettingsTriState(name: String(localized: "Preferred Appearance"), value: $preferredColorScheme,
     64                                   id1: "colorScheme",
     65                           description: String(localized: "Individual preference"))
     66                 if controller.hapticCapability.supportsHaptics {
     67                     SettingsToggle(name: String(localized: "Haptics"), value: $useHaptics,
     68                                     id1: "haptics",
     69                             description: String(localized: "Vibration Feedback"))
     70                 }
     71 
     72                 SettingsToggle(name: String(localized: "Play Payment Sounds"), value: $playSounds,
     73                                 id1: "playSounds",
     74                         description: String(localized: "When a transaction finished")) {_ in}
     75 
     76                 SettingsToggle(name: String(localized: "Paste automatically"), value: $pasteAutomatically,
     77                                 id1: "pasteAutomatically",
     78                         description: String(localized: "When this app activates")) {_ in}
     79 
     80                 /// Backup
     81                 let backupTitle = String(localized: "TitleBackup", defaultValue: "Backup / Restore")
     82                 let backupDest = BackupView(stack: stack.push(backupTitle),
     83                                          navTitle: backupTitle)
     84                 NavigationLink {
     85                     backupDest
     86                 } label: {
     87                     SettingsItem(name: backupTitle, id1: "backup",
     88                           description: String(localized: "Backup your money")) {}
     89                 }
     90 
     91                 Section(header: Text(String(localized: "Pay automatically"))) {
     92                     SettingsToggle(name: String(localized: "Pay token automatically"), value: $payTokenAutomatically,
     93                                     id1: "payTokenAutomatically",
     94                             description: String(localized: "Skip confirmation to speed up", comment: "Pay automatically"))
     95                     SettingsToggle(name: String(localized: "Pay money automatically"), value: $payMoneyAutomatically,
     96                                     id1: "payMoneyAutomatically",
     97                             description: String(localized: "Skip confirmation to speed up", comment: "Pay automatically"))
     98                     if payMoneyAutomatically {
     99                         Text("Not yet implemented...")
    100                         Text("Allow automatic payments for chosen merchants only.")
    101                     }
    102                 }
    103 #if OIM
    104                 SettingsToggle(name: String(localized: "OIM: Euro"), value: $oimEuro,
    105                                 id1: "oimEuro",
    106                         description: String(localized: "OIM currency for KUDOS"))
    107 #endif
    108 #if OIM
    109                 SettingsToggle(name: String(localized: "OIM: Chart"), value: $oimChart,
    110                                 id1: "oimChart",
    111                         description: String(localized: "OIM history as chart"))
    112 #endif
    113 
    114 //                SettingsFont(title: String(localized: "Font:"), value: talerFontIndex, action: redraw)
    115 //                    .id("font")
    116         }
    117             .id(listID)
    118             .listStyle(myListStyle.style).anyView
    119             .navigationTitle(navTitle)
    120             .onAppear() {
    121                 DebugViewC.shared.setViewID(VIEW_SETTINGS2, stack: stack.push())
    122             }
    123         if #available(iOS 26.0, *) {
    124             list
    125         } else {
    126             list
    127                 .padding(.bottom)
    128         }
    129     } // body
    130 }
    131 // MARK: -
    132 #if DEBUG
    133 //struct SettingsView_Previews: PreviewProvider {
    134 //    static var previews: some View {
    135 //        SettingsView(stack: CallStack("Preview"), balances: <#Binding<[Balance]>#>, navTitle: "Settings")
    136 //    }
    137 //}
    138 #endif