Mercurial > public > simoleon
comparison Simoleon/ContentView.swift @ 42:d25b02d439d4
Minor updates subscription and legal requirements
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Mon, 26 Jul 2021 15:35:06 +0100 |
parents | 98ac88c07ee1 |
children | 2eb05f396fcd |
comparison
equal
deleted
inserted
replaced
41:7703c122ce96 | 42:d25b02d439d4 |
---|---|
4 // | 4 // |
5 // Created by Dennis Concepción Martín on 15/07/2021. | 5 // Created by Dennis Concepción Martín on 15/07/2021. |
6 // | 6 // |
7 | 7 |
8 import SwiftUI | 8 import SwiftUI |
9 import Purchases | |
10 | 9 |
11 struct ContentView: View { | 10 struct ContentView: View { |
12 @State private var tab: Tab = .convert | 11 @State private var tab: Tab = .convert |
13 @StateObject var subscriptionController = SubscriptionController() | 12 @Environment(\.managedObjectContext) private var viewContext |
13 @FetchRequest(sortDescriptors: []) private var defaultCurrency: FetchedResults<DefaultCurrency> | |
14 | 14 |
15 var body: some View { | 15 var body: some View { |
16 TabView(selection: $tab) { | 16 TabView(selection: $tab) { |
17 Conversion(fetchUserSettings: true, currencyPair: "USD/GBP") | 17 Conversion(currencyPair: defaultCurrency.first?.pair ?? "USD/GBP") |
18 .environmentObject(subscriptionController) | |
19 .tabItem { | 18 .tabItem { |
20 Text("Convert", comment: "Tab bar button to show conversion") | 19 Text("Convert", comment: "Tab bar button to show conversion") |
21 Image(systemName: "arrow.counterclockwise.circle") | 20 Image(systemName: "arrow.counterclockwise.circle") |
22 } | 21 } |
23 .tag(Tab.convert) | 22 .tag(Tab.convert) |
24 | 23 |
25 Favourites() | 24 Favourites() |
26 .environmentObject(subscriptionController) | |
27 .tabItem { | 25 .tabItem { |
28 Text("Favourites", comment: "Tab bar button to show favourites") | 26 Text("Favourites", comment: "Tab bar button to show favourites") |
29 Image(systemName: "star") | 27 Image(systemName: "star") |
30 } | 28 } |
31 .tag(Tab.favourites) | 29 .tag(Tab.favourites) |
32 | 30 |
33 Settings() | 31 Settings() |
34 .environmentObject(subscriptionController) | |
35 .tabItem { | 32 .tabItem { |
36 Text("Settings", comment: "Tab bar button to show settings") | 33 Text("Settings", comment: "Tab bar button to show settings") |
37 Image(systemName: "gear") | 34 Image(systemName: "gear") |
38 } | 35 } |
39 .tag(Tab.settings) | 36 .tag(Tab.settings) |
40 } | |
41 .onAppear(perform: checkEntitlements) | |
42 } | |
43 | |
44 private func checkEntitlements() { | |
45 Purchases.shared.purchaserInfo { (purchaserInfo, error) in | |
46 if purchaserInfo?.entitlements["all"]?.isActive == true { | |
47 self.subscriptionController.isActive = true | |
48 } else { | |
49 // User subscription is not active | |
50 } | |
51 } | 37 } |
52 } | 38 } |
53 | 39 |
54 private enum Tab { | 40 private enum Tab { |
55 case convert, favourites, settings | 41 case convert, favourites, settings |
57 } | 43 } |
58 | 44 |
59 struct ContentView_Previews: PreviewProvider { | 45 struct ContentView_Previews: PreviewProvider { |
60 static var previews: some View { | 46 static var previews: some View { |
61 ContentView() | 47 ContentView() |
62 // .environment(\.locale, .init(identifier: "es")) | |
63 } | 48 } |
64 } | 49 } |