changeset 77:1069c33d3a42

Added new method to show unlocked content
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Sat, 31 Jul 2021 17:09:58 +0100
parents 1f657241c28f
children 822175ac4343
files Simoleon.xcodeproj/project.pbxproj Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate Simoleon/Helpers/CurrencyRow.swift Simoleon/Helpers/CurrencySelector.swift Simoleon/Helpers/ListModifier.swift
diffstat 5 files changed, 65 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/Simoleon.xcodeproj/project.pbxproj	Sat Jul 31 16:36:01 2021 +0100
+++ b/Simoleon.xcodeproj/project.pbxproj	Sat Jul 31 17:09:58 2021 +0100
@@ -10,6 +10,7 @@
 		950A377726A820F800CAB175 /* DefaultCurrency+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950A377626A820F400CAB175 /* DefaultCurrency+CoreDataProperties.swift */; };
 		950A377826A820F800CAB175 /* DefaultCurrency+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950A377526A820F400CAB175 /* DefaultCurrency+CoreDataClass.swift */; };
 		9522BEA926B5A4D20076B098 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9522BEA826B5A4D20076B098 /* AppDelegate.swift */; };
+		9522BEAB26B5AACB0076B098 /* ListModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9522BEAA26B5AACB0076B098 /* ListModifier.swift */; };
 		9555933A269B0AB8000FD726 /* ParseJson.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95559339269B0AB8000FD726 /* ParseJson.swift */; };
 		95561E3F26AF25EF00CCB543 /* SubscriptionFeature.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95561E3E26AF25EF00CCB543 /* SubscriptionFeature.swift */; };
 		95562D4D26A8962A0047E778 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95562D4C26A8962A0047E778 /* StoreKit.framework */; };
@@ -95,6 +96,7 @@
 		950A377526A820F400CAB175 /* DefaultCurrency+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DefaultCurrency+CoreDataClass.swift"; sourceTree = "<group>"; };
 		950A377626A820F400CAB175 /* DefaultCurrency+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DefaultCurrency+CoreDataProperties.swift"; sourceTree = "<group>"; };
 		9522BEA826B5A4D20076B098 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
+		9522BEAA26B5AACB0076B098 /* ListModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListModifier.swift; sourceTree = "<group>"; };
 		95559339269B0AB8000FD726 /* ParseJson.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseJson.swift; sourceTree = "<group>"; };
 		95561E3E26AF25EF00CCB543 /* SubscriptionFeature.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionFeature.swift; sourceTree = "<group>"; };
 		95562D4C26A8962A0047E778 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; };
@@ -401,6 +403,7 @@
 				95D8C8D026A9BC6200BCC188 /* LockedCurrencyPicker.swift */,
 				95561E3E26AF25EF00CCB543 /* SubscriptionFeature.swift */,
 				95909CB226B07BFC00D051AB /* SearchBar.swift */,
+				9522BEAA26B5AACB0076B098 /* ListModifier.swift */,
 			);
 			path = Helpers;
 			sourceTree = "<group>";
@@ -572,6 +575,7 @@
 				95C5B2312697752700941585 /* Persistence.swift in Sources */,
 				9585BB1226A6B71B00E3193E /* ReadConfig.swift in Sources */,
 				95AEBC9526A03ECB00613729 /* ContentView.swift in Sources */,
+				9522BEAB26B5AACB0076B098 /* ListModifier.swift in Sources */,
 				95909CB326B07BFC00D051AB /* SearchBar.swift in Sources */,
 				95AEBC9B26A04A4200613729 /* CurrencyMetadataModel.swift in Sources */,
 				9522BEA926B5A4D20076B098 /* AppDelegate.swift in Sources */,
Binary file Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
--- a/Simoleon/Helpers/CurrencyRow.swift	Sat Jul 31 16:36:01 2021 +0100
+++ b/Simoleon/Helpers/CurrencyRow.swift	Sat Jul 31 17:09:58 2021 +0100
@@ -9,6 +9,7 @@
 
 struct CurrencyRow: View {
     var currencyPairName: String
+    var isLocked: Bool?
     let currencyMetadata: [String: CurrencyMetadataModel] = parseJson("CurrencyMetadata.json")
     
     var body: some View {
@@ -36,6 +37,11 @@
                 .padding(.leading)
             
             Spacer()
+            
+            if isLocked ?? false {
+                Image(systemName: "lock")
+                    .foregroundColor(Color(.systemGray))
+            }
         }
     }
 }
--- a/Simoleon/Helpers/CurrencySelector.swift	Sat Jul 31 16:36:01 2021 +0100
+++ b/Simoleon/Helpers/CurrencySelector.swift	Sat Jul 31 17:09:58 2021 +0100
@@ -12,6 +12,7 @@
     @Binding var currencyPair: String
     @Binding var showingCurrencySelector: Bool
     
+    @State private var entitlementIsActive = false
     @State private var searchCurrency = ""
     @State private var showingSubscriptionPaywall = false
     @State private var alertTitle = ""
@@ -40,18 +41,24 @@
                 SearchBar(placeholder: "Search...", text: $searchCurrency)
                     .padding()
                 
+                if entitlementIsActive {
                     List(searchResults, id: \.self) { currencyPair in
-                        Button(action: { select(currencyPair.name) }) {
+                        Button(action: {
+                            self.currencyPair = currencyPair.name
+                            showingCurrencySelector = false
+                        }) {
                             CurrencyRow(currencyPairName: currencyPair.name)
                         }
                     }
-                .id(UUID())
-                .listStyle(PlainListStyle())
-                .gesture(DragGesture()
-                            .onChanged({ _ in
-                                UIApplication.shared.dismissKeyboard()
-                            })
-                )
+                    .listStyle()
+                } else {
+                    List(searchResults, id: \.self) { currencyPair in
+                        Button(action: { select(currencyPair) }) {
+                            CurrencyRow(currencyPairName: currencyPair.name, isLocked: currencyPair.isLocked)
+                        }
+                    }
+                    .listStyle()
+                }
             }
             .navigationTitle("Currencies")
             .navigationBarTitleDisplayMode(.inline)
@@ -63,10 +70,11 @@
                 }
             }
         }
+        .onAppear(perform: checkEntitlement)
         .alert(isPresented: $showingAlert) {
             Alert(title: Text(alertTitle), message: Text(alertMessage), dismissButton: .default(Text("Ok")))
         }
-        .sheet(isPresented: $showingSubscriptionPaywall) {
+        .sheet(isPresented: $showingSubscriptionPaywall, onDismiss: checkEntitlement) {
             SubscriptionPaywall(showingSubscriptionPaywall: $showingSubscriptionPaywall)
         }
     }
@@ -77,13 +85,20 @@
      else:
      * Show subscription paywall
      */
-    private func select(_ currencyPair: String) {
+    private func select(_ currencyPair: CurrencyPairModel) {
+        if currencyPair.isLocked {
+            showingSubscriptionPaywall = true
+        } else {
+            self.currencyPair = currencyPair.name
+            showingCurrencySelector = false
+        }
+    }
+    
+    // Check if user subscription is active
+    private func checkEntitlement() {
         Purchases.shared.purchaserInfo { (purchaserInfo, error) in
             if purchaserInfo?.entitlements["all"]?.isActive == true {
-                self.currencyPair = currencyPair
-                showingCurrencySelector = false
-            } else {
-                showingSubscriptionPaywall = true
+                entitlementIsActive = true
             }
             
             if let error = error as NSError? {
@@ -94,6 +109,11 @@
         }
     }
 }
+extension View {
+    func listStyle() -> some View {
+        self.modifier(ListModifier())
+    }
+}
 
 
 struct CurrencySelector_Previews: PreviewProvider {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Simoleon/Helpers/ListModifier.swift	Sat Jul 31 17:09:58 2021 +0100
@@ -0,0 +1,21 @@
+//
+//  ListModifier.swift
+//  Simoleon
+//
+//  Created by Dennis Concepción Martín on 31/7/21.
+//
+
+import SwiftUI
+
+struct ListModifier: ViewModifier {
+    func body(content: Content) -> some View {
+            content
+                .id(UUID())
+                .listStyle(PlainListStyle())
+                .gesture(DragGesture()
+                            .onChanged({ _ in
+                                UIApplication.shared.dismissKeyboard()
+                            })
+                )
+        }
+}