taler-ios

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

MoreSettingsView.swift (4493B)


      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("playSoundsI") var playSoundsI: Int = 1
     27     @AppStorage("playSoundsB") var playSoundsB: 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("oimEuro") var oimEuro: Bool = false
     34     @AppStorage("oimChart") var oimChart: Bool = false
     35 
     36     @State private var listID = UUID()
     37 
     38     func redraw(_ newFont: Int) -> Void {
     39         if newFont != talerFontIndex {
     40             talerFontIndex = newFont
     41             withAnimation { listID = UUID() }
     42         }
     43     }
     44 
     45     var body: some View {
     46 #if PRINT_CHANGES
     47         let _ = Self._printChanges()
     48         let _ = symLog.vlog()       // just to get the # to compare it with .onAppear & onDisappear
     49 #endif
     50         let walletCore = WalletCore.shared
     51         Group {
     52             List {
     53                 let showQRstring = String(localized: "Show QR codes")
     54                 let showQRhint = String(localized: "Automatically for P2P transactions")
     55                 if #available(iOS 17.7, *) {
     56                     SettingsToggle(name: showQRstring, value: $showQRauto17, id1: "showQRautomatic",
     57                             description: showQRhint)
     58                 } else {
     59                     SettingsToggle(name: showQRstring, value: $showQRauto16, id1: "showQRautomatic",
     60                             description: showQRhint)
     61                 }
     62 
     63                 if controller.hapticCapability.supportsHaptics {
     64                     SettingsToggle(name: String(localized: "Haptics"), value: $useHaptics,
     65                                     id1: "haptics",
     66                                    description: String(localized: "Vibration Feedback"))
     67                 }
     68 
     69                 SettingsToggle(name: String(localized: "Play Payment Sounds"), value: $playSoundsB,
     70                                 id1: "playSounds",
     71                         description: String(localized: "When a transaction finished")) {_ in}
     72 
     73                 /// Backup
     74                 let backupTitle = String(localized: "TitleBackup", defaultValue: "Backup / Restore")
     75                 let backupDest = BackupView(stack: stack.push(backupTitle),
     76                                          navTitle: backupTitle)
     77                 NavigationLink {
     78                     backupDest
     79                 } label: {
     80                     SettingsItem(name: backupTitle, id1: "backup",
     81                           description: String(localized: "Backup your money")) {}
     82                 }
     83 
     84 #if OIM
     85                 SettingsToggle(name: String(localized: "OIM: Euro"), value: $oimEuro,
     86                                 id1: "oimEuro",
     87                         description: String(localized: "OIM currency for KUDOS"))
     88 #endif
     89 #if OIM
     90                 SettingsToggle(name: String(localized: "OIM: Chart"), value: $oimChart,
     91                                 id1: "oimChart",
     92                         description: String(localized: "OIM history as chart"))
     93 #endif
     94 
     95 //                SettingsFont(title: String(localized: "Font:"), value: talerFontIndex, action: redraw)
     96 //                    .id("font")
     97             }
     98             .padding(.bottom)
     99             .id(listID)
    100             .listStyle(myListStyle.style).anyView
    101         }
    102         .navigationTitle(navTitle)
    103         .onAppear() {
    104             DebugViewC.shared.setViewID(VIEW_SETTINGS, stack: stack.push())
    105         }
    106     } // body
    107 }
    108 // MARK: -
    109 #if DEBUG
    110 //struct SettingsView_Previews: PreviewProvider {
    111 //    static var previews: some View {
    112 //        SettingsView(stack: CallStack("Preview"), balances: <#Binding<[Balance]>#>, navTitle: "Settings")
    113 //    }
    114 //}
    115 #endif