diff --git a/LeCountdown.xcodeproj/project.pbxproj b/LeCountdown.xcodeproj/project.pbxproj index acc5607..ca2ee0c 100644 --- a/LeCountdown.xcodeproj/project.pbxproj +++ b/LeCountdown.xcodeproj/project.pbxproj @@ -51,6 +51,10 @@ C438C8182982BFC100BF3EF9 /* Persistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4060DC8297AE73D003FAB80 /* Persistence.swift */; }; C438C8192982BFDB00BF3EF9 /* NSManagedContext+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C438C7C4298024E900BF3EF9 /* NSManagedContext+Extensions.swift */; }; C438C81A2982BFF100BF3EF9 /* NSManagedContext+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C438C7C4298024E900BF3EF9 /* NSManagedContext+Extensions.swift */; }; + C4742B5729840F6400D5D950 /* Media.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4742B5629840F6400D5D950 /* Media.swift */; }; + C4742B59298411E800D5D950 /* CountdownFormView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4742B58298411E800D5D950 /* CountdownFormView.swift */; }; + C4742B5B298414B000D5D950 /* ImageSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4742B5A298414B000D5D950 /* ImageSelectionView.swift */; }; + C4742B5F2984205000D5D950 /* ViewModifiers.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4742B5E2984205000D5D950 /* ViewModifiers.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -115,6 +119,7 @@ C4060DE2297AE73D003FAB80 /* LeCountdownUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LeCountdownUITestsLaunchTests.swift; sourceTree = ""; }; C4060DF4297AE9A7003FAB80 /* TimeInterval+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TimeInterval+Extensions.swift"; sourceTree = ""; }; C4060DF6297AFEF2003FAB80 /* NewCountdownView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewCountdownView.swift; sourceTree = ""; }; + C418A14F298428CB00C22230 /* LeCountdown.0.1.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = LeCountdown.0.1.xcdatamodel; sourceTree = ""; }; C438C7C02980228B00BF3EF9 /* CountdownScheduler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CountdownScheduler.swift; sourceTree = ""; }; C438C7C4298024E900BF3EF9 /* NSManagedContext+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSManagedContext+Extensions.swift"; sourceTree = ""; }; C438C7C829803CA000BF3EF9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -139,6 +144,10 @@ C438C80C2982847300BF3EF9 /* CoreDataRequests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataRequests.swift; sourceTree = ""; }; C438C80E29828B8600BF3EF9 /* RecordsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecordsView.swift; sourceTree = ""; }; C438C81029829EAF00BF3EF9 /* PropertyWrappers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyWrappers.swift; sourceTree = ""; }; + C4742B5629840F6400D5D950 /* Media.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Media.swift; sourceTree = ""; }; + C4742B58298411E800D5D950 /* CountdownFormView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CountdownFormView.swift; sourceTree = ""; }; + C4742B5A298414B000D5D950 /* ImageSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageSelectionView.swift; sourceTree = ""; }; + C4742B5E2984205000D5D950 /* ViewModifiers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewModifiers.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -214,6 +223,7 @@ C438C7C829803CA000BF3EF9 /* AppDelegate.swift */, C4060DBF297AE73B003FAB80 /* LeCountdownApp.swift */, C438C7C02980228B00BF3EF9 /* CountdownScheduler.swift */, + C4742B5629840F6400D5D950 /* Media.swift */, C438C80B2981DE2E00BF3EF9 /* Views */, C438C8092981DDF800BF3EF9 /* Model */, C438C80A2981DE1A00BF3EF9 /* Utils */, @@ -308,8 +318,9 @@ C438C80A2981DE1A00BF3EF9 /* Utils */ = { isa = PBXGroup; children = ( - C4060DF4297AE9A7003FAB80 /* TimeInterval+Extensions.swift */, C438C81029829EAF00BF3EF9 /* PropertyWrappers.swift */, + C4060DF4297AE9A7003FAB80 /* TimeInterval+Extensions.swift */, + C4742B5E2984205000D5D950 /* ViewModifiers.swift */, ); path = Utils; sourceTree = ""; @@ -318,6 +329,8 @@ isa = PBXGroup; children = ( C4060DC1297AE73B003FAB80 /* ContentView.swift */, + C4742B58298411E800D5D950 /* CountdownFormView.swift */, + C4742B5A298414B000D5D950 /* ImageSelectionView.swift */, C4060DF6297AFEF2003FAB80 /* NewCountdownView.swift */, C438C80E29828B8600BF3EF9 /* RecordsView.swift */, ); @@ -517,18 +530,22 @@ C4060DC9297AE73D003FAB80 /* Persistence.swift in Sources */, C438C80F29828B8600BF3EF9 /* RecordsView.swift in Sources */, C438C80D2982847300BF3EF9 /* CoreDataRequests.swift in Sources */, + C4742B5F2984205000D5D950 /* ViewModifiers.swift in Sources */, C438C81129829EAF00BF3EF9 /* PropertyWrappers.swift in Sources */, C438C807298195E600BF3EF9 /* Model+Extensions.swift in Sources */, C438C7FF2981300500BF3EF9 /* IntentDataProvider.swift in Sources */, + C4742B59298411E800D5D950 /* CountdownFormView.swift in Sources */, C4060DC2297AE73B003FAB80 /* ContentView.swift in Sources */, C438C7C12980228B00BF3EF9 /* CountdownScheduler.swift in Sources */, C438C7C929803CA000BF3EF9 /* AppDelegate.swift in Sources */, C4060DF5297AE9A7003FAB80 /* TimeInterval+Extensions.swift in Sources */, C4060DF7297AFEF2003FAB80 /* NewCountdownView.swift in Sources */, C4060DCC297AE73D003FAB80 /* LeCountdown.xcdatamodeld in Sources */, + C4742B5B298414B000D5D950 /* ImageSelectionView.swift in Sources */, C438C7C5298024E900BF3EF9 /* NSManagedContext+Extensions.swift in Sources */, C4060DC0297AE73B003FAB80 /* LeCountdownApp.swift in Sources */, C438C7E02981216300BF3EF9 /* LaunchWidget.intentdefinition in Sources */, + C4742B5729840F6400D5D950 /* Media.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1030,9 +1047,10 @@ C4060DCA297AE73D003FAB80 /* LeCountdown.xcdatamodeld */ = { isa = XCVersionGroup; children = ( + C418A14F298428CB00C22230 /* LeCountdown.0.1.xcdatamodel */, C4060DCB297AE73D003FAB80 /* LeCountdown.xcdatamodel */, ); - currentVersion = C4060DCB297AE73D003FAB80 /* LeCountdown.xcdatamodel */; + currentVersion = C418A14F298428CB00C22230 /* LeCountdown.0.1.xcdatamodel */; path = LeCountdown.xcdatamodeld; sourceTree = ""; versionGroupType = wrapper.xcdatamodel; diff --git a/LeCountdown/Assets.xcassets/pic1.imageset/Contents.json b/LeCountdown/Assets.xcassets/pic1.imageset/Contents.json new file mode 100644 index 0000000..47049f5 --- /dev/null +++ b/LeCountdown/Assets.xcassets/pic1.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "pic1.jpg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/LeCountdown/Assets.xcassets/pic1.imageset/pic1.jpg b/LeCountdown/Assets.xcassets/pic1.imageset/pic1.jpg new file mode 100644 index 0000000..acca813 Binary files /dev/null and b/LeCountdown/Assets.xcassets/pic1.imageset/pic1.jpg differ diff --git a/LeCountdown/Assets.xcassets/pic2.imageset/Contents.json b/LeCountdown/Assets.xcassets/pic2.imageset/Contents.json new file mode 100644 index 0000000..c33bb96 --- /dev/null +++ b/LeCountdown/Assets.xcassets/pic2.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "pic2.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/LeCountdown/Assets.xcassets/pic2.imageset/pic2.png b/LeCountdown/Assets.xcassets/pic2.imageset/pic2.png new file mode 100644 index 0000000..aff746a Binary files /dev/null and b/LeCountdown/Assets.xcassets/pic2.imageset/pic2.png differ diff --git a/LeCountdown/Assets.xcassets/pic3.imageset/Contents.json b/LeCountdown/Assets.xcassets/pic3.imageset/Contents.json new file mode 100644 index 0000000..eee65ea --- /dev/null +++ b/LeCountdown/Assets.xcassets/pic3.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "pic3.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/LeCountdown/Assets.xcassets/pic3.imageset/pic3.png b/LeCountdown/Assets.xcassets/pic3.imageset/pic3.png new file mode 100644 index 0000000..b6be411 Binary files /dev/null and b/LeCountdown/Assets.xcassets/pic3.imageset/pic3.png differ diff --git a/LeCountdown/Assets.xcassets/pic4.imageset/Contents.json b/LeCountdown/Assets.xcassets/pic4.imageset/Contents.json new file mode 100644 index 0000000..4619ae9 --- /dev/null +++ b/LeCountdown/Assets.xcassets/pic4.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "pic4.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/LeCountdown/Assets.xcassets/pic4.imageset/pic4.png b/LeCountdown/Assets.xcassets/pic4.imageset/pic4.png new file mode 100644 index 0000000..fce7eff Binary files /dev/null and b/LeCountdown/Assets.xcassets/pic4.imageset/pic4.png differ diff --git a/LeCountdown/Assets.xcassets/pic5.imageset/Contents.json b/LeCountdown/Assets.xcassets/pic5.imageset/Contents.json new file mode 100644 index 0000000..0019e8c --- /dev/null +++ b/LeCountdown/Assets.xcassets/pic5.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "pic5.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/LeCountdown/Assets.xcassets/pic5.imageset/pic5.png b/LeCountdown/Assets.xcassets/pic5.imageset/pic5.png new file mode 100644 index 0000000..abc0b0b Binary files /dev/null and b/LeCountdown/Assets.xcassets/pic5.imageset/pic5.png differ diff --git a/LeCountdown/Assets.xcassets/pic6.imageset/Contents.json b/LeCountdown/Assets.xcassets/pic6.imageset/Contents.json new file mode 100644 index 0000000..1b8070d --- /dev/null +++ b/LeCountdown/Assets.xcassets/pic6.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "pic6.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/LeCountdown/Assets.xcassets/pic6.imageset/pic6.png b/LeCountdown/Assets.xcassets/pic6.imageset/pic6.png new file mode 100644 index 0000000..7ad8650 Binary files /dev/null and b/LeCountdown/Assets.xcassets/pic6.imageset/pic6.png differ diff --git a/LeCountdown/Assets.xcassets/pic7.imageset/Contents.json b/LeCountdown/Assets.xcassets/pic7.imageset/Contents.json new file mode 100644 index 0000000..7f07919 --- /dev/null +++ b/LeCountdown/Assets.xcassets/pic7.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "pic7.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/LeCountdown/Assets.xcassets/pic7.imageset/pic7.png b/LeCountdown/Assets.xcassets/pic7.imageset/pic7.png new file mode 100644 index 0000000..c9b228d Binary files /dev/null and b/LeCountdown/Assets.xcassets/pic7.imageset/pic7.png differ diff --git a/LeCountdown/Assets.xcassets/pic8.imageset/Contents.json b/LeCountdown/Assets.xcassets/pic8.imageset/Contents.json new file mode 100644 index 0000000..f3d6913 --- /dev/null +++ b/LeCountdown/Assets.xcassets/pic8.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "pic8.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/LeCountdown/Assets.xcassets/pic8.imageset/pic8.png b/LeCountdown/Assets.xcassets/pic8.imageset/pic8.png new file mode 100644 index 0000000..b028b3c Binary files /dev/null and b/LeCountdown/Assets.xcassets/pic8.imageset/pic8.png differ diff --git a/LeCountdown/Assets.xcassets/pic9.imageset/Contents.json b/LeCountdown/Assets.xcassets/pic9.imageset/Contents.json new file mode 100644 index 0000000..89a7a11 --- /dev/null +++ b/LeCountdown/Assets.xcassets/pic9.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "pic9.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/LeCountdown/Assets.xcassets/pic9.imageset/pic9.png b/LeCountdown/Assets.xcassets/pic9.imageset/pic9.png new file mode 100644 index 0000000..041016d Binary files /dev/null and b/LeCountdown/Assets.xcassets/pic9.imageset/pic9.png differ diff --git a/LeCountdown/Media.swift b/LeCountdown/Media.swift new file mode 100644 index 0000000..9f245c1 --- /dev/null +++ b/LeCountdown/Media.swift @@ -0,0 +1,32 @@ +// +// Sound.swift +// LeCountdown +// +// Created by Laurent Morvillier on 27/01/2023. +// + +import Foundation + +enum Sound : String, CaseIterable, Identifiable { + + var id: String { return self.rawValue } + + case sound1 + case pouet + +} + +enum CoolPic : String, CaseIterable, Identifiable { + + var id: String { return self.rawValue } + + case pic1 + case pic2 + case pic3 + case pic4 + case pic5 + case pic6 + case pic7 + case pic8 + case pic9 +} diff --git a/LeCountdown/Model/LeCountdown.xcdatamodeld/.xccurrentversion b/LeCountdown/Model/LeCountdown.xcdatamodeld/.xccurrentversion index 8d5c1e6..c4c1845 100644 --- a/LeCountdown/Model/LeCountdown.xcdatamodeld/.xccurrentversion +++ b/LeCountdown/Model/LeCountdown.xcdatamodeld/.xccurrentversion @@ -3,6 +3,6 @@ _XCCurrentVersionName - LeCountdown.xcdatamodel + LeCountdown.0.1.xcdatamodel diff --git a/LeCountdown/Model/LeCountdown.xcdatamodeld/LeCountdown.0.1.xcdatamodel/contents b/LeCountdown/Model/LeCountdown.xcdatamodeld/LeCountdown.0.1.xcdatamodel/contents new file mode 100644 index 0000000..04eaed4 --- /dev/null +++ b/LeCountdown/Model/LeCountdown.xcdatamodeld/LeCountdown.0.1.xcdatamodel/contents @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/LeCountdown/Model/Model+Extensions.swift b/LeCountdown/Model/Model+Extensions.swift index 4b22693..ea4b1d4 100644 --- a/LeCountdown/Model/Model+Extensions.swift +++ b/LeCountdown/Model/Model+Extensions.swift @@ -23,6 +23,10 @@ extension Countdown { } } + var imageName: String { + return self.image ?? "default" + } + static func fake(context: NSManagedObjectContext) -> Countdown { let cd = Countdown(context: context) cd.duration = 4 * 60.0 diff --git a/LeCountdown/Model/Persistence.swift b/LeCountdown/Model/Persistence.swift index 5268c71..ea55531 100644 --- a/LeCountdown/Model/Persistence.swift +++ b/LeCountdown/Model/Persistence.swift @@ -47,6 +47,8 @@ struct PersistenceController { let storeURL = URL.storeURL(for: "group.com.staxriver.countdown", databaseName: "group.com.staxriver.countdown") let storeDescription = NSPersistentStoreDescription(url: storeURL) +// storeDescription.shouldMigrateStoreAutomatically = true +// storeDescription.shouldInferMappingModelAutomatically = true container = NSPersistentCloudKitContainer(name: "LeCountdown") container.persistentStoreDescriptions = [storeDescription] diff --git a/LeCountdown/Utils/ViewModifiers.swift b/LeCountdown/Utils/ViewModifiers.swift new file mode 100644 index 0000000..92d03a7 --- /dev/null +++ b/LeCountdown/Utils/ViewModifiers.swift @@ -0,0 +1,35 @@ +// +// ViewModifiers.swift +// LeCountdown +// +// Created by Laurent Morvillier on 27/01/2023. +// + +import Foundation +import SwiftUI + +extension View { + + func roundedCorner(selected: Bool) -> some View { + modifier(RoundedCornerSelection(selected: selected)) + } + +} + +struct RoundedCornerSelection: ViewModifier { + + var selected: Bool + + func body(content: Content) -> some View { + if selected { + content + .overlay( + RoundedRectangle(cornerRadius: 40) + .stroke(Color.blue, lineWidth: 5) + ) + } else { + content + } + } + +} diff --git a/LeCountdown/Views/ContentView.swift b/LeCountdown/Views/ContentView.swift index f392c01..5001a72 100644 --- a/LeCountdown/Views/ContentView.swift +++ b/LeCountdown/Views/ContentView.swift @@ -29,7 +29,8 @@ struct CountdownLiveView: View { Text(countdown.duration.minuteSecond).monospaced() } } - .font(.title2) + .font(Font.system(size: 24.0, weight: .semibold)) + .foregroundColor(Color.white) } } @@ -53,7 +54,7 @@ struct ContentView: View { @State var showDefaultAlert: Bool = false @State var showPermissionAlert: Bool = false - private var columns: [GridItem] = [ + private let columns: [GridItem] = [ GridItem(spacing: 10.0), GridItem(spacing: 10.0), ] @@ -68,6 +69,7 @@ struct ContentView: View { ) { ForEach(countdowns) { countdown in + ZStack(alignment: .topTrailing) { Button { @@ -79,8 +81,9 @@ struct ContentView: View { .aspectRatio(contentMode: .fill) .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity) .aspectRatio(1, contentMode: .fit) - .background(countdown.colorForStatus) + .background(Image(countdown.imageName)) .cornerRadius(40.0) + } // Text("ORder = \(countdown.order)") @@ -88,8 +91,10 @@ struct ContentView: View { CountdownEditView(countdown: countdown, isPresented: $isShowingNewCountdown) .environment(\.managedObjectContext, viewContext) } label: { - Image(systemName: "gearshape.fill").font(.system(size: 30)) + Image(systemName: "gearshape.fill") + .font(.system(size: 30)) .padding(12.0) + .foregroundColor(Color.orange) } } diff --git a/LeCountdown/Views/CountdownFormView.swift b/LeCountdown/Views/CountdownFormView.swift new file mode 100644 index 0000000..d4f309d --- /dev/null +++ b/LeCountdown/Views/CountdownFormView.swift @@ -0,0 +1,83 @@ +// +// CountdownFormView.swift +// LeCountdown +// +// Created by Laurent Morvillier on 27/01/2023. +// + +import SwiftUI + + +struct CountdownFormView : View { + + var secondsBinding: Binding + var minutesBinding: Binding + var nameBinding: Binding + + var soundBinding: Binding + var imageBinding: Binding + + var textFieldIsFocused: FocusState.Binding + + 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")) { + + Picker(selection: soundBinding) { + ForEach(Sound.allCases) { sound in + Text(sound.rawValue).tag(sound) + } + } label: { + Text("Sound") + } + + } + + Section { + NavigationLink { + ImageSelectionView(imageBinding: imageBinding) + } label: { + Group { + if let image = self.imageBinding.wrappedValue { + Image(image.rawValue) + } else { + Image(imageBinding.wrappedValue.rawValue) + } + } .font(Font.system(size: 90.0)) + .aspectRatio(1, contentMode: .fit) + .frame(width: 100.0, height: 100.0) + .cornerRadius(40.0) + + + } + } + + } + + } + +} + +struct CountdownFormView_Previews: PreviewProvider { + + @FocusState static var textFieldIsFocused: Bool + + static var previews: some View { + CountdownFormView(secondsBinding: .constant(""), minutesBinding: .constant(""), + nameBinding: .constant(""), soundBinding: .constant(.sound1), + imageBinding: .constant(.pic3), textFieldIsFocused: $textFieldIsFocused) + } +} diff --git a/LeCountdown/Views/ImageSelectionView.swift b/LeCountdown/Views/ImageSelectionView.swift new file mode 100644 index 0000000..cbfe9a8 --- /dev/null +++ b/LeCountdown/Views/ImageSelectionView.swift @@ -0,0 +1,58 @@ +// +// ImageSelectionView.swift +// LeCountdown +// +// Created by Laurent Morvillier on 27/01/2023. +// + +import SwiftUI + +struct ImageSelectionView: View { + + var imageBinding: Binding + + private let columns: [GridItem] = [ + GridItem(spacing: 10.0), + GridItem(spacing: 10.0), + ] + + var body: some View { + + NavigationStack { + + ScrollView { + + LazyVGrid( + columns: columns, + spacing: 10.0 + ) { + + ForEach(CoolPic.allCases) { coolPic in + + Group { + Image(coolPic.rawValue) + .aspectRatio(contentMode: .fill) + .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity) + .aspectRatio(1, contentMode: .fit) + .cornerRadius(40.0) + .roundedCorner(selected: self.imageBinding.wrappedValue == coolPic) + + } + .onTapGesture { + self.imageBinding.wrappedValue = coolPic + print("coolPic = \(coolPic), image = \(String(describing: self.imageBinding.wrappedValue))") + } + + } + }.padding(10.0) + }.navigationTitle("Background") + + } + } +} + +struct ImageSelectionView_Previews: PreviewProvider { + static var previews: some View { + ImageSelectionView(imageBinding: .constant(.pic3)) + } +} diff --git a/LeCountdown/Views/NewCountdownView.swift b/LeCountdown/Views/NewCountdownView.swift index d4091ae..993a0dc 100644 --- a/LeCountdown/Views/NewCountdownView.swift +++ b/LeCountdown/Views/NewCountdownView.swift @@ -23,38 +23,6 @@ struct NewCountdownView : View { } -struct CountdownFormView : View { - - var secondsBinding: Binding - var minutesBinding: Binding - var nameBinding: Binding - - var textFieldIsFocused: FocusState.Binding - - 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 @@ -68,6 +36,9 @@ struct CountdownEditView : View { @State var minutesString: String = "" @State var nameString: String = "" + @State var sound: Sound = .sound1 + @State var image: CoolPic = .pic1 + @State var deleteConfirmationShown: Bool = false @State var activityNameConfirmationShown: Bool = false @State fileprivate var _rename: Bool? = nil @@ -88,6 +59,7 @@ struct CountdownEditView : View { CountdownFormView(secondsBinding: $secondsString, minutesBinding: $minutesString, nameBinding: $nameString, + soundBinding: $sound, imageBinding: $image, textFieldIsFocused: $textFieldIsFocused) .onAppear { self._onAppear() @@ -206,6 +178,10 @@ struct CountdownEditView : View { let max = self.countdowns.map { $0.order }.max() ?? 0 cd.order = max + 1 } + + cd.image = self.image.rawValue + cd.sound = self.sound.rawValue + if !self.nameString.isEmpty { if let activity = cd.activity, let currentActivityName = activity.name, self.nameString != currentActivityName { @@ -270,6 +246,6 @@ struct CountdownEditView : View { struct NewCountdownView_Previews: PreviewProvider { static var previews: some View { NewCountdownView(isPresented: .constant(true)) - .environment(\.managedObjectContext, PersistenceController.shared.container.viewContext) + .environment(\.managedObjectContext, PersistenceController.preview.container.viewContext) } }