diff --git a/LeCountdown.xcodeproj/project.pbxproj b/LeCountdown.xcodeproj/project.pbxproj index fd99742..4d283db 100644 --- a/LeCountdown.xcodeproj/project.pbxproj +++ b/LeCountdown.xcodeproj/project.pbxproj @@ -41,7 +41,7 @@ C438C8012981327600BF3EF9 /* Persistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4060DC8297AE73D003FAB80 /* Persistence.swift */; }; C438C802298132B900BF3EF9 /* LeCountdown.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = C4060DCA297AE73D003FAB80 /* LeCountdown.xcdatamodeld */; }; C438C80529813FB400BF3EF9 /* TimeInterval+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4060DF4297AE9A7003FAB80 /* TimeInterval+Extensions.swift */; }; - C438C807298195E600BF3EF9 /* Countdown+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C438C806298195E600BF3EF9 /* Countdown+Extension.swift */; }; + C438C807298195E600BF3EF9 /* Countdown+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C438C806298195E600BF3EF9 /* Countdown+Extensions.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -126,7 +126,7 @@ C438C7FE2981300500BF3EF9 /* IntentDataProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntentDataProvider.swift; sourceTree = ""; }; C438C80329813B2500BF3EF9 /* LaunchIntents.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = LaunchIntents.entitlements; sourceTree = ""; }; C438C80429813B3100BF3EF9 /* LeCountdown.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = LeCountdown.entitlements; sourceTree = ""; }; - C438C806298195E600BF3EF9 /* Countdown+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Countdown+Extension.swift"; sourceTree = ""; }; + C438C806298195E600BF3EF9 /* Countdown+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Countdown+Extensions.swift"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -199,21 +199,17 @@ C4060DBE297AE73B003FAB80 /* LeCountdown */ = { isa = PBXGroup; children = ( + C438C7C829803CA000BF3EF9 /* AppDelegate.swift */, C4060DBF297AE73B003FAB80 /* LeCountdownApp.swift */, - C4060DC1297AE73B003FAB80 /* ContentView.swift */, - C4060DF6297AFEF2003FAB80 /* NewCountdownView.swift */, C438C7C02980228B00BF3EF9 /* CountdownScheduler.swift */, + C438C80B2981DE2E00BF3EF9 /* Views */, + C438C8092981DDF800BF3EF9 /* Model */, + C438C80A2981DE1A00BF3EF9 /* Utils */, + C438C8082981DDD200BF3EF9 /* Widget */, C4060DC3297AE73D003FAB80 /* Assets.xcassets */, - C438C7C829803CA000BF3EF9 /* AppDelegate.swift */, - C4060DC8297AE73D003FAB80 /* Persistence.swift */, - C438C7C4298024E900BF3EF9 /* NSManagedContext+Extensions.swift */, - C4060DF4297AE9A7003FAB80 /* TimeInterval+Extensions.swift */, - C438C7FE2981300500BF3EF9 /* IntentDataProvider.swift */, C438C80429813B3100BF3EF9 /* LeCountdown.entitlements */, C4060DCD297AE73D003FAB80 /* Info.plist */, - C4060DCA297AE73D003FAB80 /* LeCountdown.xcdatamodeld */, C4060DC5297AE73D003FAB80 /* Preview Content */, - C438C806298195E600BF3EF9 /* Countdown+Extension.swift */, ); path = LeCountdown; sourceTree = ""; @@ -277,6 +273,42 @@ path = LaunchIntents; sourceTree = ""; }; + C438C8082981DDD200BF3EF9 /* Widget */ = { + isa = PBXGroup; + children = ( + C438C7FE2981300500BF3EF9 /* IntentDataProvider.swift */, + ); + path = Widget; + sourceTree = ""; + }; + C438C8092981DDF800BF3EF9 /* Model */ = { + isa = PBXGroup; + children = ( + C4060DCA297AE73D003FAB80 /* LeCountdown.xcdatamodeld */, + C438C806298195E600BF3EF9 /* Countdown+Extensions.swift */, + C438C7C4298024E900BF3EF9 /* NSManagedContext+Extensions.swift */, + C4060DC8297AE73D003FAB80 /* Persistence.swift */, + ); + path = Model; + sourceTree = ""; + }; + C438C80A2981DE1A00BF3EF9 /* Utils */ = { + isa = PBXGroup; + children = ( + C4060DF4297AE9A7003FAB80 /* TimeInterval+Extensions.swift */, + ); + path = Utils; + sourceTree = ""; + }; + C438C80B2981DE2E00BF3EF9 /* Views */ = { + isa = PBXGroup; + children = ( + C4060DC1297AE73B003FAB80 /* ContentView.swift */, + C4060DF6297AFEF2003FAB80 /* NewCountdownView.swift */, + ); + path = Views; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -468,7 +500,7 @@ buildActionMask = 2147483647; files = ( C4060DC9297AE73D003FAB80 /* Persistence.swift in Sources */, - C438C807298195E600BF3EF9 /* Countdown+Extension.swift in Sources */, + C438C807298195E600BF3EF9 /* Countdown+Extensions.swift in Sources */, C438C7FF2981300500BF3EF9 /* IntentDataProvider.swift in Sources */, C4060DC2297AE73B003FAB80 /* ContentView.swift in Sources */, C438C7C12980228B00BF3EF9 /* CountdownScheduler.swift in Sources */, diff --git a/LeCountdown/Countdown+Extension.swift b/LeCountdown/Model/Countdown+Extensions.swift similarity index 100% rename from LeCountdown/Countdown+Extension.swift rename to LeCountdown/Model/Countdown+Extensions.swift diff --git a/LeCountdown/LeCountdown.xcdatamodeld/.xccurrentversion b/LeCountdown/Model/LeCountdown.xcdatamodeld/.xccurrentversion similarity index 100% rename from LeCountdown/LeCountdown.xcdatamodeld/.xccurrentversion rename to LeCountdown/Model/LeCountdown.xcdatamodeld/.xccurrentversion diff --git a/LeCountdown/LeCountdown.xcdatamodeld/LeCountdown.xcdatamodel/contents b/LeCountdown/Model/LeCountdown.xcdatamodeld/LeCountdown.xcdatamodel/contents similarity index 100% rename from LeCountdown/LeCountdown.xcdatamodeld/LeCountdown.xcdatamodel/contents rename to LeCountdown/Model/LeCountdown.xcdatamodeld/LeCountdown.xcdatamodel/contents diff --git a/LeCountdown/NSManagedContext+Extensions.swift b/LeCountdown/Model/NSManagedContext+Extensions.swift similarity index 100% rename from LeCountdown/NSManagedContext+Extensions.swift rename to LeCountdown/Model/NSManagedContext+Extensions.swift diff --git a/LeCountdown/Persistence.swift b/LeCountdown/Model/Persistence.swift similarity index 100% rename from LeCountdown/Persistence.swift rename to LeCountdown/Model/Persistence.swift diff --git a/LeCountdown/TimeInterval+Extensions.swift b/LeCountdown/Utils/TimeInterval+Extensions.swift similarity index 100% rename from LeCountdown/TimeInterval+Extensions.swift rename to LeCountdown/Utils/TimeInterval+Extensions.swift diff --git a/LeCountdown/ContentView.swift b/LeCountdown/Views/ContentView.swift similarity index 90% rename from LeCountdown/ContentView.swift rename to LeCountdown/Views/ContentView.swift index 88479de..abf6052 100644 --- a/LeCountdown/ContentView.swift +++ b/LeCountdown/Views/ContentView.swift @@ -19,6 +19,12 @@ struct CountdownLiveView: View { Text(countdown.name ?? "") if let date = environment.notificationDates[countdown.stringId] { Text(date, style: .timer) + Button { + CountdownScheduler.master.cancelCurrentNotifications(countdown: countdown) + } label: { + Text("Cancel").buttonStyle(.bordered).tint(.blue) + } + } else { Text(countdown.duration.minuteSecond) } @@ -81,10 +87,8 @@ struct ContentView: View { CountdownEditView(countdown: countdown, isPresented: $isShowingNewCountdown) .environment(\.managedObjectContext, viewContext) } label: { - Image(systemName: "pencil").font(.system(size: 30)) + Image(systemName: "gearshape.fill").font(.system(size: 30)) .padding(12.0) - .overlay(Circle().stroke(.blue, lineWidth: 4) - ) } } @@ -149,12 +153,12 @@ struct ContentView: View { } -private let itemFormatter: DateFormatter = { - let formatter = DateFormatter() - formatter.dateStyle = .short - formatter.timeStyle = .medium - return formatter -}() +//private let itemFormatter: DateFormatter = { +// let formatter = DateFormatter() +// formatter.dateStyle = .short +// formatter.timeStyle = .medium +// return formatter +//}() struct ContentView_Previews: PreviewProvider { static var previews: some View { diff --git a/LeCountdown/NewCountdownView.swift b/LeCountdown/Views/NewCountdownView.swift similarity index 83% rename from LeCountdown/NewCountdownView.swift rename to LeCountdown/Views/NewCountdownView.swift index 55b9bfa..861f4dc 100644 --- a/LeCountdown/NewCountdownView.swift +++ b/LeCountdown/Views/NewCountdownView.swift @@ -23,6 +23,38 @@ struct NewCountdownView : View { } +struct CountdownFormView : View { + + var secondsBinding: Binding + var minutesBinding: Binding + var nameBinding: Binding + + @FocusState private var textFieldIsFocused: Bool + + var body: some View { + Form { + Section(header: Text("Duration")) { + TextField("minutes", text: minutesBinding) + .keyboardType(.numberPad) + .focused($textFieldIsFocused) + TextField("seconds", text: secondsBinding) + .keyboardType(.numberPad) + .focused($textFieldIsFocused) + } + Section(header: Text("Name for tracking the activity")) { + TextField("name", text: nameBinding) + .focused($textFieldIsFocused) + } + + Section(header: Text("Properties")) { + Text("Image") + Text("Sound") + } + } + } + +} + struct CountdownEditView : View { @Environment(\.managedObjectContext) private var viewContext @@ -42,7 +74,7 @@ struct CountdownEditView : View { @State var error: Error? = nil @FocusState private var textFieldIsFocused: Bool - + @FetchRequest(sortDescriptors: []) private var countdowns: FetchedResults @@ -51,25 +83,10 @@ struct CountdownEditView : View { var body: some View { NavigationStack { - Form { - Section(header: Text("Duration")) { - TextField("minutes", text: $minutesString) - .keyboardType(.numberPad) - .focused($textFieldIsFocused) - TextField("seconds", text: $secondsString) - .keyboardType(.numberPad) - .focused($textFieldIsFocused) - } - Section(header: Text("Name for tracking the activity")) { - TextField("name", text: $nameString) - .focused($textFieldIsFocused) - } - - Section(header: Text("Properties")) { - Text("Image") - Text("Sound") - } - }.onAppear { + CountdownFormView(secondsBinding: $secondsString, + minutesBinding: $minutesString, + nameBinding: $nameString) + .onAppear { self._onAppear() } .confirmationDialog("", isPresented: $deleteConfirmationShown, actions: { diff --git a/LeCountdown/IntentDataProvider.swift b/LeCountdown/Widget/IntentDataProvider.swift similarity index 100% rename from LeCountdown/IntentDataProvider.swift rename to LeCountdown/Widget/IntentDataProvider.swift