Mercurial > public > simoleon
comparison Simoleon/SettingsView.swift @ 156:84137052813d
Refactor code
author | Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com> |
---|---|
date | Sat, 28 Aug 2021 11:15:25 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
155:681f2cbe8c7f | 156:84137052813d |
---|---|
1 //// | |
2 //// SettingsView.swift | |
3 //// Simoleon | |
4 //// | |
5 //// Created by Dennis Concepción Martín on 19/07/2021. | |
6 //// | |
7 // | |
8 //import SwiftUI | |
9 //import Purchases | |
10 // | |
11 //struct SettingsView: View { | |
12 // @Environment(\.managedObjectContext) private var viewContext | |
13 // @FetchRequest(sortDescriptors: []) private var defaultCurrency: FetchedResults<DefaultCurrency> | |
14 // @State private var selectedDefaultCurrency = "" | |
15 // @State private var showingSubscriptionPaywall = false | |
16 // @State private var entitlementIsActive = false | |
17 // @State private var alertTitle = "" | |
18 // @State private var alertMessage = "" | |
19 // @State private var showingAlert = false | |
20 // @State private var searchCurrency = "" | |
21 // let file = File() | |
22 // | |
23 // /* | |
24 // If searched currency string is empty: | |
25 // * Show all currencies | |
26 // else: | |
27 // * Show filtered list of currencies containing searched currency string | |
28 // */ | |
29 // var searchResults: [String] { | |
30 // let currencyPairsSupported: [String] = try! file.read(json: "CurrencyPairsSupported.json") | |
31 // if searchCurrency.isEmpty { | |
32 // return currencyPairsSupported.sorted() | |
33 // } else { | |
34 // return currencyPairsSupported.filter { $0.contains(searchCurrency.uppercased()) } | |
35 // } | |
36 // } | |
37 // | |
38 // var body: some View { | |
39 // List { | |
40 // Section(header: Text("Preferences")) { | |
41 // if entitlementIsActive { | |
42 // Picker("Default currency", selection: $selectedDefaultCurrency) { | |
43 // SearchBar(placeholder: "Search...", text: $searchCurrency) | |
44 // .padding(5) | |
45 // | |
46 // ForEach(searchResults, id: \.self) { currencyPairsSupported in | |
47 // Text(currencyPairsSupported) | |
48 // .tag(currencyPairsSupported) | |
49 // } | |
50 // } | |
51 // } else { | |
52 // LockedCurrencyPicker() | |
53 // .contentShape(Rectangle()) | |
54 // .onTapGesture { showingSubscriptionPaywall = true } | |
55 // } | |
56 // } | |
57 // | |
58 // Section(header: Text("Stay in touch")) { | |
59 // Link(destination: URL(string: "https://itunes.apple.com/app/id1576390953?action=write-review")!) { | |
60 // HStack { | |
61 // Image(systemName: "heart.fill") | |
62 // .foregroundColor(Color(.systemRed)) | |
63 // .imageScale(.large) | |
64 // | |
65 // Text("Rate Simoleon") | |
66 // } | |
67 // } | |
68 // | |
69 // Link(destination: URL(string: "https://twitter.com/dennisconcep")!) { | |
70 // HStack { | |
71 // Image("TwitterLogo") | |
72 // .resizable() | |
73 // .frame(width: 30, height: 30) | |
74 // | |
75 // Text("Developer's Twitter") | |
76 // } | |
77 // } | |
78 // | |
79 // Link(destination: URL(string: "https://dennistech.io/contact")!) { | |
80 // HStack { | |
81 // Image(systemName: "envelope.fill") | |
82 // .foregroundColor(Color(.systemIndigo)) | |
83 // .imageScale(.large) | |
84 // | |
85 // Text("Contact") | |
86 // } | |
87 // } | |
88 // } | |
89 // | |
90 // Section(header: Text("About")) { | |
91 // Link(destination: URL(string: "https://dennistech.io")!) { | |
92 // Text("Website") | |
93 // } | |
94 // | |
95 // Link(destination: URL(string: "https://dennistech.io/simoleon-privacy-policy")!) { | |
96 // Text("Privacy Policy") | |
97 // } | |
98 // | |
99 // Link(destination: URL(string: "https://dennistech.io/simoleon-terms-of-use")!) { | |
100 // Text("Terms of Use") | |
101 // } | |
102 // } | |
103 // } | |
104 // .alert(isPresented: $showingAlert) { | |
105 // Alert(title: Text(alertTitle), message: Text(alertMessage), dismissButton: .default(Text("Ok"))) | |
106 // } | |
107 // .onAppear { | |
108 // checkEntitlement() | |
109 // /* | |
110 // if selectedDefaultCurrency is empty: | |
111 // * View is appearing for the first time | |
112 // * Set initial default curency for picker | |
113 // else: | |
114 // * View is appearing after user selected another default currency | |
115 // * Save it to core data | |
116 // */ | |
117 //// if selectedDefaultCurrency == "" { | |
118 //// selectedDefaultCurrency = defaultCurrency.first?.pair ?? "USD/GBP" | |
119 //// } else { | |
120 //// setCoreData() | |
121 //// } | |
122 // } | |
123 // .listStyle(InsetGroupedListStyle()) | |
124 // .navigationTitle("Settings") | |
125 // .sheet(isPresented: $showingSubscriptionPaywall, onDismiss: checkEntitlement) { | |
126 // SubscriptionPaywall(showingSubscriptionPaywall: $showingSubscriptionPaywall) | |
127 // } | |
128 // .if(UIDevice.current.userInterfaceIdiom == .phone) { content in | |
129 // NavigationView { content } | |
130 // } | |
131 // } | |
132 // | |
133 // // Save default currency to core data | |
134 //// private func setCoreData() { | |
135 //// if defaultCurrency.isEmpty { // If it's empty -> add record | |
136 //// let defaultCurrency = DefaultCurrency(context: viewContext) | |
137 //// defaultCurrency.pair = selectedDefaultCurrency | |
138 //// | |
139 //// do { | |
140 //// try viewContext.save() | |
141 //// } catch { | |
142 //// print(error.localizedDescription) | |
143 //// } | |
144 //// } else { // If not, update record | |
145 //// defaultCurrency.first?.pair = selectedDefaultCurrency | |
146 //// try? viewContext.save() | |
147 //// } | |
148 //// } | |
149 // | |
150 // // Check if user subscription is active | |
151 // private func checkEntitlement() { | |
152 // #if SCREENSHOTS | |
153 // entitlementIsActive = true | |
154 // #else | |
155 // Purchases.shared.purchaserInfo { (purchaserInfo, error) in | |
156 // if purchaserInfo?.entitlements["all"]?.isActive == true { | |
157 // entitlementIsActive = true | |
158 // } | |
159 // | |
160 // if let error = error as NSError? { | |
161 // alertTitle = error.localizedDescription | |
162 // alertMessage = error.localizedFailureReason ?? "" | |
163 // showingAlert = true | |
164 // } | |
165 // } | |
166 // #endif | |
167 // } | |
168 //} | |
169 // | |
170 //struct SettingsView_Previews: PreviewProvider { | |
171 // static var previews: some View { | |
172 // SettingsView() | |
173 // } | |
174 //} |