diff --git a/LeCountdown/Subscription/AppGuard.swift b/LeCountdown/Subscription/AppGuard.swift index 7fab0c2..aef8ee9 100644 --- a/LeCountdown/Subscription/AppGuard.swift +++ b/LeCountdown/Subscription/AppGuard.swift @@ -32,6 +32,8 @@ extension Notification.Name { @objc class AppGuard: NSObject { + static let freeTimersCount: Int = 3 + static var main: AppGuard = AppGuard() @Published private(set) var purchasedTransactions = Set() @@ -124,7 +126,7 @@ extension Notification.Name { } var isSubscriber: Bool { - return self.currentPlan != .none + return true //self.currentPlan != .none } var currentPlan: StorePlan { diff --git a/LeCountdown/Views/ContentView.swift b/LeCountdown/Views/ContentView.swift index 023f2dd..9b07fb3 100644 --- a/LeCountdown/Views/ContentView.swift +++ b/LeCountdown/Views/ContentView.swift @@ -51,7 +51,9 @@ struct ContentView: View { .foregroundColor(.white) } - TimersView(isEditing: self.$isEditing, siriHandler: { timer in + TimersView(isEditing: self.$isEditing, + showSubscriptionSheet: self.$showSubscriptionSheet, + siriHandler: { timer in self._handleSiriTips(timer: timer) }) .environment(\.managedObjectContext, viewContext) diff --git a/LeCountdown/Views/DialView.swift b/LeCountdown/Views/DialView.swift index adb2158..e2cc896 100644 --- a/LeCountdown/Views/DialView.swift +++ b/LeCountdown/Views/DialView.swift @@ -15,24 +15,41 @@ struct DialView: View { @EnvironmentObject var conductor: Conductor @State var timer: AbstractTimer - var isEditingBinding: Binding + var isLaunchable: Bool + var isEditingBinding: Binding + @Binding var showSubscriptionSheet: Bool + var frameSize: CGFloat var handler: ((AbstractTimer) -> ())? = nil - + var body: some View { ZStack { switch self.isEditingBinding.wrappedValue { case false: Button { - self._launchTimer() + if self.isLaunchable { + self._launchTimer() + } else { + self.showSubscriptionSheet = true + } } label: { - VStack { - Spacer() - self._dialView().padding(.horizontal) - Spacer() + + ZStack { + + VStack { + Spacer() + self._dialView().padding(.horizontal) + Spacer() + } + + if !self.isLaunchable { + Group { + Image(systemName: "lock.circle").font(.title).foregroundColor(.white) + }.frame(maxWidth: .infinity, maxHeight: .infinity).background(Color(white: 0.0, opacity: 0.6)) + } } } case true: @@ -119,7 +136,10 @@ struct DialView_Previews: PreviewProvider { DialView( timer: Countdown.fake(context: PersistenceController.preview.container.viewContext), - isEditingBinding: .constant(true), frameSize: 150.0) + isLaunchable: true, + isEditingBinding: .constant(false), + showSubscriptionSheet: .constant(false), + frameSize: 150.0) .environmentObject(Conductor.maestro) .environmentObject(BoringContext()) diff --git a/LeCountdown/Views/PresetsView.swift b/LeCountdown/Views/PresetsView.swift index 3c66b95..2c189db 100644 --- a/LeCountdown/Views/PresetsView.swift +++ b/LeCountdown/Views/PresetsView.swift @@ -119,7 +119,7 @@ struct PresetsView: View { } fileprivate func _showNewCountdown() { - if AppGuard.main.isSubscriber || viewContext.count(entityName: "AbstractTimer") < 4 { + if AppGuard.main.isSubscriber || viewContext.count(entityName: "AbstractTimer") < AppGuard.freeTimersCount { self.isShowingNewCountdown = true } else { self.isShowingSubscription = true diff --git a/LeCountdown/Views/TimersView.swift b/LeCountdown/Views/TimersView.swift index ccfe3b9..44a0945 100644 --- a/LeCountdown/Views/TimersView.swift +++ b/LeCountdown/Views/TimersView.swift @@ -14,6 +14,7 @@ struct TimersView: View { @Environment(\.managedObjectContext) private var viewContext @Binding var isEditing: Bool + @Binding var showSubscriptionSheet: Bool var siriHandler: ((AbstractTimer) -> ()) @@ -24,6 +25,7 @@ struct TimersView: View { fileprivate let itemSpacing: CGFloat = 10.0 + var body: some View { let abstractTimers: [AbstractTimer] = Array(self.timers) @@ -43,8 +45,11 @@ struct TimersView: View { ReorderableForEach(items: abstractTimers) { timer in + let launchable: Bool = self._isLaunchable(timer: timer) DialView(timer: timer, + isLaunchable: launchable, isEditingBinding: self.$isEditing, + showSubscriptionSheet: self.$showSubscriptionSheet, frameSize: width, handler: { timer in self.siriHandler(timer) @@ -68,7 +73,16 @@ struct TimersView: View { } + fileprivate func _isLaunchable(timer: AbstractTimer) -> Bool { + return AppGuard.main.isSubscriber || (self.timers.firstIndex(of: timer) ?? 0) < AppGuard.freeTimersCount + } + fileprivate func _reorder(from: IndexSet, to: Int) { + + guard AppGuard.main.isSubscriber || self.timers.count < 4 else { + return + } + var timers: [AbstractTimer] = Array(self.timers) timers.move(fromOffsets: from, toOffset: to) for (i, countdown) in timers.enumerated() { @@ -102,6 +116,6 @@ struct TimersView: View { struct TimersView_Previews: PreviewProvider { static var previews: some View { - TimersView(isEditing: .constant(false), siriHandler: { _ in }) + TimersView(isEditing: .constant(false), showSubscriptionSheet: .constant(false), siriHandler: { _ in }) } }