Adds sound and image selection

release
Laurent 3 years ago
parent 0821a5c952
commit d67ccf25aa
  1. 22
      LeCountdown.xcodeproj/project.pbxproj
  2. 21
      LeCountdown/Assets.xcassets/pic1.imageset/Contents.json
  3. BIN
      LeCountdown/Assets.xcassets/pic1.imageset/pic1.jpg
  4. 21
      LeCountdown/Assets.xcassets/pic2.imageset/Contents.json
  5. BIN
      LeCountdown/Assets.xcassets/pic2.imageset/pic2.png
  6. 21
      LeCountdown/Assets.xcassets/pic3.imageset/Contents.json
  7. BIN
      LeCountdown/Assets.xcassets/pic3.imageset/pic3.png
  8. 21
      LeCountdown/Assets.xcassets/pic4.imageset/Contents.json
  9. BIN
      LeCountdown/Assets.xcassets/pic4.imageset/pic4.png
  10. 21
      LeCountdown/Assets.xcassets/pic5.imageset/Contents.json
  11. BIN
      LeCountdown/Assets.xcassets/pic5.imageset/pic5.png
  12. 21
      LeCountdown/Assets.xcassets/pic6.imageset/Contents.json
  13. BIN
      LeCountdown/Assets.xcassets/pic6.imageset/pic6.png
  14. 21
      LeCountdown/Assets.xcassets/pic7.imageset/Contents.json
  15. BIN
      LeCountdown/Assets.xcassets/pic7.imageset/pic7.png
  16. 21
      LeCountdown/Assets.xcassets/pic8.imageset/Contents.json
  17. BIN
      LeCountdown/Assets.xcassets/pic8.imageset/pic8.png
  18. 21
      LeCountdown/Assets.xcassets/pic9.imageset/Contents.json
  19. BIN
      LeCountdown/Assets.xcassets/pic9.imageset/pic9.png
  20. 32
      LeCountdown/Media.swift
  21. 2
      LeCountdown/Model/LeCountdown.xcdatamodeld/.xccurrentversion
  22. 20
      LeCountdown/Model/LeCountdown.xcdatamodeld/LeCountdown.0.1.xcdatamodel/contents
  23. 4
      LeCountdown/Model/Model+Extensions.swift
  24. 2
      LeCountdown/Model/Persistence.swift
  25. 35
      LeCountdown/Utils/ViewModifiers.swift
  26. 13
      LeCountdown/Views/ContentView.swift
  27. 83
      LeCountdown/Views/CountdownFormView.swift
  28. 58
      LeCountdown/Views/ImageSelectionView.swift
  29. 42
      LeCountdown/Views/NewCountdownView.swift

@ -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 = "<group>"; };
C4060DF4297AE9A7003FAB80 /* TimeInterval+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TimeInterval+Extensions.swift"; sourceTree = "<group>"; };
C4060DF6297AFEF2003FAB80 /* NewCountdownView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewCountdownView.swift; sourceTree = "<group>"; };
C418A14F298428CB00C22230 /* LeCountdown.0.1.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = LeCountdown.0.1.xcdatamodel; sourceTree = "<group>"; };
C438C7C02980228B00BF3EF9 /* CountdownScheduler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CountdownScheduler.swift; sourceTree = "<group>"; };
C438C7C4298024E900BF3EF9 /* NSManagedContext+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSManagedContext+Extensions.swift"; sourceTree = "<group>"; };
C438C7C829803CA000BF3EF9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@ -139,6 +144,10 @@
C438C80C2982847300BF3EF9 /* CoreDataRequests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataRequests.swift; sourceTree = "<group>"; };
C438C80E29828B8600BF3EF9 /* RecordsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecordsView.swift; sourceTree = "<group>"; };
C438C81029829EAF00BF3EF9 /* PropertyWrappers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyWrappers.swift; sourceTree = "<group>"; };
C4742B5629840F6400D5D950 /* Media.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Media.swift; sourceTree = "<group>"; };
C4742B58298411E800D5D950 /* CountdownFormView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CountdownFormView.swift; sourceTree = "<group>"; };
C4742B5A298414B000D5D950 /* ImageSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageSelectionView.swift; sourceTree = "<group>"; };
C4742B5E2984205000D5D950 /* ViewModifiers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewModifiers.swift; sourceTree = "<group>"; };
/* 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 = "<group>";
@ -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 = "<group>";
versionGroupType = wrapper.xcdatamodel;

@ -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
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

@ -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
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 275 KiB

@ -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
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 KiB

@ -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
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

@ -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
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

@ -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
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

@ -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
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

@ -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
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

@ -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
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

@ -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
}

@ -3,6 +3,6 @@
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>LeCountdown.xcdatamodel</string>
<string>LeCountdown.0.1.xcdatamodel</string>
</dict>
</plist>

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21513" systemVersion="22A400" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithCloudKit="YES" userDefinedModelVersionIdentifier="">
<entity name="Activity" representedClassName="Activity" syncable="YES" codeGenerationType="class">
<attribute name="name" attributeType="String" defaultValueString=""/>
<relationship name="countdowns" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="Countdown" inverseName="activity" inverseEntity="Countdown"/>
<relationship name="records" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="Record" inverseName="activity" inverseEntity="Record"/>
</entity>
<entity name="Countdown" representedClassName="Countdown" syncable="YES" codeGenerationType="class">
<attribute name="duration" attributeType="Double" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="image" optional="YES" attributeType="String"/>
<attribute name="order" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="sound" optional="YES" attributeType="String"/>
<relationship name="activity" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Activity" inverseName="countdowns" inverseEntity="Activity"/>
</entity>
<entity name="Record" representedClassName="Record" syncable="YES" codeGenerationType="class">
<attribute name="end" attributeType="Date" defaultDateTimeInterval="696425400" usesScalarValueType="NO"/>
<attribute name="start" attributeType="Date" defaultDateTimeInterval="696425400" usesScalarValueType="NO"/>
<relationship name="activity" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Activity" inverseName="records" inverseEntity="Activity"/>
</entity>
</model>

@ -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

@ -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]

@ -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
}
}
}

@ -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)
}
}

@ -0,0 +1,83 @@
//
// CountdownFormView.swift
// LeCountdown
//
// Created by Laurent Morvillier on 27/01/2023.
//
import SwiftUI
struct CountdownFormView : View {
var secondsBinding: Binding<String>
var minutesBinding: Binding<String>
var nameBinding: Binding<String>
var soundBinding: Binding<Sound>
var imageBinding: Binding<CoolPic>
var textFieldIsFocused: FocusState<Bool>.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)
}
}

@ -0,0 +1,58 @@
//
// ImageSelectionView.swift
// LeCountdown
//
// Created by Laurent Morvillier on 27/01/2023.
//
import SwiftUI
struct ImageSelectionView: View {
var imageBinding: Binding<CoolPic>
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))
}
}

@ -23,38 +23,6 @@ struct NewCountdownView : View {
}
struct CountdownFormView : View {
var secondsBinding: Binding<String>
var minutesBinding: Binding<String>
var nameBinding: Binding<String>
var textFieldIsFocused: FocusState<Bool>.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)
}
}

Loading…
Cancel
Save