txtodo

[DORMANT] a minimalist todo list app inspired by jeff huang
git clone git://git.figbert.com/txtodo.git
Log | Files | Refs | README

commit 414f18c57c63d70aaef56460a6c9ba3f677a190d
parent 70fafb5cc5b0c57b045c79fca56c71ceba2fb56c
Author: FIGBERT <figbert@figbert.com>
Date:   Sat, 21 Nov 2020 14:21:19 -0800

Replace Liberapay link with in-app purchases

Diffstat:
MShared/ContentView.swift | 5+++--
MShared/Settings Views/DonationSection.swift | 18++++++++++++++++--
MShared/en.lproj/Localizable.strings | 0
MShared/he.lproj/Localizable.strings | 0
MShared/txtodoApp.swift | 39++++++++++++++++++++++++++++++++++++---
MiOS/MenuView.swift | 5+++--
MiOS/SettingsSheet.swift | 7++++---
MmacOS/SettingsView.swift | 6++++--
8 files changed, 66 insertions(+), 14 deletions(-)

diff --git a/Shared/ContentView.swift b/Shared/ContentView.swift @@ -9,6 +9,7 @@ import SwiftUI struct ContentView: View { @Environment(\.managedObjectContext) var managedObjectContext + @StateObject var storeManager: StoreManager @FetchRequest( entity: Task.entity(), sortDescriptors: [ @@ -88,7 +89,7 @@ struct ContentView: View { .animation(.easeIn(duration: 0.15)) } #if os(iOS) - MenuView() + MenuView(storeManager: storeManager) #endif } .modifier(FrameModifier()) @@ -97,6 +98,6 @@ struct ContentView: View { struct ContentView_Previews: PreviewProvider { static var previews: some View { - ContentView() + ContentView(storeManager: StoreManager()) } } diff --git a/Shared/Settings Views/DonationSection.swift b/Shared/Settings Views/DonationSection.swift @@ -8,18 +8,32 @@ import SwiftUI struct DonationSection: View { + @StateObject var storeManager: StoreManager + @Environment(\.colorScheme) var colorScheme + var body: some View { VStack { Text("considerDonating") .multilineTextAlignment(.center) .padding() - Link(destination: URL(string: "https://liberapay.com/FIGBERT/")!) { Text("donateLiberapay") } + HStack { + ForEach(storeManager.myProducts.sorted(by: { first, second in return first.price.doubleValue < second.price.doubleValue }), id: \.self) { product in + Text(product.priceFormatted()) + .foregroundColor(Color.white) + .padding() + .background(Color.blue.opacity(self.colorScheme == .dark ? 0.3 : 0.75).cornerRadius(10)) + .onTapGesture { + self.storeManager.purchaseProduct(product: product) + } + } + } + .padding(.bottom) } } } struct DonationSection_Previews: PreviewProvider { static var previews: some View { - DonationSection() + DonationSection(storeManager: StoreManager()) } } diff --git a/Shared/en.lproj/Localizable.strings b/Shared/en.lproj/Localizable.strings Binary files differ. diff --git a/Shared/he.lproj/Localizable.strings b/Shared/he.lproj/Localizable.strings Binary files differ. diff --git a/Shared/txtodoApp.swift b/Shared/txtodoApp.swift @@ -7,15 +7,45 @@ import SwiftUI import CoreData +import StoreKit import UserNotifications @main struct txtodoApp: App { @Environment(\.scenePhase) private var scenePhase + @StateObject var storeManager = StoreManager() + + let productIDs = [ + "com.figbertind.txtodo.five_usd_tip", + "com.figbertind.txtodo.ten_usd_tip", + "com.figbertind.txtodo.fifteen_usd_tip" + ] @SceneBuilder var body: some Scene { + #if os(iOS) + WindowGroup { + ContentView(storeManager: storeManager) + .environment(\.managedObjectContext, self.persistentContainer.viewContext) + .onAppear(perform: { + SKPaymentQueue.default().add(storeManager) + storeManager.getProducts(productIDs: productIDs) + }) + } + .onChange(of: scenePhase) { phase in + switch phase { + case .active: + UNUserNotificationCenter.current().removeAllDeliveredNotifications() + case .inactive: + saveContext() + case .background: + saveContext() + @unknown default: + saveContext() + } + } + #elseif os(macOS) WindowGroup { - ContentView() + ContentView(storeManager: storeManager) .environment(\.managedObjectContext, self.persistentContainer.viewContext) } .onChange(of: scenePhase) { phase in @@ -30,9 +60,12 @@ struct txtodoApp: App { saveContext() } } - #if os(macOS) Settings { - SettingsView() + SettingsView(storeManager: storeManager) + .onAppear(perform: { + SKPaymentQueue.default().add(storeManager) + storeManager.getProducts(productIDs: productIDs) + }) } #endif } diff --git a/iOS/MenuView.swift b/iOS/MenuView.swift @@ -9,6 +9,7 @@ import SwiftUI struct MenuView: View { @State private var config = MenuViewConfig() + @StateObject var storeManager: StoreManager var body: some View { HStack { @@ -19,7 +20,7 @@ struct MenuView: View { config.showSettings = true } .sheet(isPresented: $config.showSettings) { - SettingsSheet() + SettingsSheet(storeManager: storeManager) } Label("about", systemImage: "book") .onTapGesture { @@ -50,6 +51,6 @@ struct MenuViewConfig { struct MenuView_Previews: PreviewProvider { static var previews: some View { - MenuView() + MenuView(storeManager: StoreManager()) } } diff --git a/iOS/SettingsSheet.swift b/iOS/SettingsSheet.swift @@ -8,6 +8,8 @@ import SwiftUI struct SettingsSheet: View { + @StateObject var storeManager: StoreManager + var body: some View { VStack { Text("settings") @@ -15,8 +17,7 @@ struct SettingsSheet: View { .padding() Form { NotificationSection() - DonationSection() - .padding(.bottom) + DonationSection(storeManager: storeManager) } .listStyle(GroupedListStyle()) } @@ -25,6 +26,6 @@ struct SettingsSheet: View { struct SettingsSheet_Previews: PreviewProvider { static var previews: some View { - SettingsSheet() + SettingsSheet(storeManager: StoreManager()) } } diff --git a/macOS/SettingsView.swift b/macOS/SettingsView.swift @@ -8,6 +8,8 @@ import SwiftUI struct SettingsView: View { + @StateObject var storeManager: StoreManager + var body: some View { TabView { VStack { @@ -26,7 +28,7 @@ struct SettingsView: View { Text("notifications") Image(systemName: "app.badge") } - DonationSection() + DonationSection(storeManager: storeManager) .tabItem { Text("tip jar") Image(systemName: "creditcard") @@ -38,6 +40,6 @@ struct SettingsView: View { struct SettingsView_Previews: PreviewProvider { static var previews: some View { - SettingsView() + SettingsView(storeManager: StoreManager()) } }