Adds subscription button

main
Laurent 3 years ago
parent 2ce1b66eff
commit e87d380a9a
  1. 4
      LeCountdown/Subscription/AppGuard.swift
  2. 32
      LeCountdown/Subscription/StoreView.swift
  3. 76
      LeCountdown/Views/ContentView.swift
  4. 2
      LeCountdown/Views/PresetsView.swift
  5. 4
      LeCountdown/Views/Reusable/SoundSelectionView.swift

@ -123,8 +123,8 @@ extension Notification.Name {
return transaction
}
var isAuthorized: Bool {
return self.currentPlan != .none
var isSubscriber: Bool {
return false // self.currentPlan != .none
}
var currentPlan: StorePlan {

@ -33,30 +33,26 @@ struct StoreView: View, StoreDelegate {
@State var errorMessage: String? = nil
init() {
self.store.delegate = self
// if SKPaymentQueue.canMakePayments() {
// self._store = Store(delegate: self)
// } else {
// self.errorMessage = NSLocalizedString("In-app purchase disabled", comment: "")
// }
}
var body: some View {
if !self.store.products.isEmpty {
PlanView()
.environmentObject(self.store)
} else {
ProgressView()
.progressViewStyle(.circular)
Group {
if !self.store.products.isEmpty {
PlanView()
.environmentObject(self.store)
} else {
ProgressView()
.progressViewStyle(.circular)
}
}.onAppear {
self._configure()
}
}
fileprivate func _configure() {
self.store.delegate = self
}
// MARK: - StoreDelegate
func productsReceived() {

@ -10,7 +10,6 @@ import CoreData
import Combine
class BoringContext : ObservableObject {
@Published var isShowingNewData = false
@Published var error: Error?
@Published var showDefaultAlert: Bool = false
@ -18,35 +17,12 @@ class BoringContext : ObservableObject {
@Published var siriTimer: AbstractTimer? = nil
}
class TimerSpot : Identifiable, Equatable {
var id: Int16 { return self.order }
var order: Int16
var timer: AbstractTimer?
init(order: Int16, timer: AbstractTimer? = nil) {
self.order = order
self.timer = timer
}
func setOrder(order: Int16) {
self.order = order
self.timer?.order = order
}
static func == (lhs: TimerSpot, rhs: TimerSpot) -> Bool {
return lhs.order == rhs.order && lhs.timer?.stringId == rhs.timer?.stringId
}
}
struct ContentView<T : AbstractTimer>: View {
@StateObject var boringContext: BoringContext = BoringContext()
@EnvironmentObject var conductor: Conductor
@Environment(\.managedObjectContext) private var viewContext
@EnvironmentObject var conductor: Conductor
@StateObject var boringContext: BoringContext = BoringContext()
@State private var isEditing: Bool = false
@ -56,10 +32,25 @@ struct ContentView<T : AbstractTimer>: View {
@State private var showSettingsSheet: Bool = false
@State private var showSubscriptionSheet: Bool = false
var body: some View {
VStack {
if !AppGuard.main.isSubscriber {
Button {
self.showSubscriptionSheet = true
} label: {
Text("Get fully enchanted")
.frame(maxWidth: .infinity)
} .background(Color.accentColor)
.cornerRadius(8.0)
.padding(.horizontal)
.buttonStyle(.bordered)
.foregroundColor(.white)
}
TimersView(isEditing: self.$isEditing, siriHandler: { timer in
self._handleSiriTips(timer: timer)
})
@ -122,6 +113,9 @@ struct ContentView<T : AbstractTimer>: View {
SettingsView()
.presentationDetents([.height(240.0)])
})
.sheet(isPresented: self.$showSubscriptionSheet, content: {
StoreView()
})
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button {
@ -184,7 +178,7 @@ struct ContentView<T : AbstractTimer>: View {
print("_performActionIfPossible")
let urlString = url.absoluteString
if let timer = viewContext.object(stringId: urlString) as? AbstractTimer {
if let timer = self.viewContext.object(stringId: urlString) as? AbstractTimer {
if timer is T {
print("performAction")
@ -261,9 +255,33 @@ fileprivate extension Countdown {
}
class TimerSpot : Identifiable, Equatable {
var id: Int16 { return self.order }
var order: Int16
var timer: AbstractTimer?
init(order: Int16, timer: AbstractTimer? = nil) {
self.order = order
self.timer = timer
}
func setOrder(order: Int16) {
self.order = order
self.timer?.order = order
}
static func == (lhs: TimerSpot, rhs: TimerSpot) -> Bool {
return lhs.order == rhs.order && lhs.timer?.stringId == rhs.timer?.stringId
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView<Countdown>().environment(\.managedObjectContext, PersistenceController.preview.container.viewContext) .environmentObject(Conductor.maestro)
ContentView<Countdown>()
.environment(\.managedObjectContext, PersistenceController.preview.container.viewContext).environmentObject(Conductor.maestro)
}
}

@ -119,7 +119,7 @@ struct PresetsView: View {
}
fileprivate func _showNewCountdown() {
if AppGuard.main.isAuthorized || viewContext.count(entityName: "AbstractTimer") < 4 {
if AppGuard.main.isSubscriber || viewContext.count(entityName: "AbstractTimer") < 4 {
self.isShowingNewCountdown = true
} else {
self.isShowingSubscription = true

@ -46,7 +46,7 @@ struct PlaylistSectionView: View {
self._playSound(sound)
}
Spacer()
if !sound.isRestricted || AppGuard.main.isAuthorized {
if !sound.isRestricted || AppGuard.main.isSubscriber {
RightAlignToggleRow(item: sound, selected: self.model.binding(sound: sound), keyPath: \.formattedDuration) { selected in
self.model.selectSound(sound, selected: selected)
}.frame(width: 120.0)
@ -67,7 +67,7 @@ struct PlaylistSectionView: View {
}
fileprivate func _playSound(_ sound: Sound) {
if AppGuard.main.isAuthorized {
if AppGuard.main.isSubscriber {
Conductor.maestro.playSound(sound)
} else {
Conductor.maestro.playSound(sound, duration: 30.0)

Loading…
Cancel
Save