diff --git a/LeCountdown.xcodeproj/project.pbxproj b/LeCountdown.xcodeproj/project.pbxproj index e3d591e..e98aac9 100644 --- a/LeCountdown.xcodeproj/project.pbxproj +++ b/LeCountdown.xcodeproj/project.pbxproj @@ -68,6 +68,7 @@ C498E5A3298D720600E90DE0 /* TestView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C498E5A2298D720600E90DE0 /* TestView.swift */; }; C498E5A5299152B400E90DE0 /* GreenCheckmarkView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C498E5A4299152B400E90DE0 /* GreenCheckmarkView.swift */; }; C498E5A6299152C600E90DE0 /* GreenCheckmarkView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C498E5A4299152B400E90DE0 /* GreenCheckmarkView.swift */; }; + C4BA2AD62993F62700CB4FBA /* SoundSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4BA2AD52993F62700CB4FBA /* SoundSelectionView.swift */; }; C4F8B1532987FE6F005C86A5 /* LaunchWidgetLiveActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = C438C7D72981216200BF3EF9 /* LaunchWidgetLiveActivity.swift */; }; C4F8B15729891271005C86A5 /* Conductor.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B15629891271005C86A5 /* Conductor.swift */; }; C4F8B15929891528005C86A5 /* forest_stream.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = C4F8B15829891528005C86A5 /* forest_stream.mp3 */; }; @@ -232,6 +233,8 @@ C498E5A0298D543900E90DE0 /* LiveTimer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveTimer.swift; sourceTree = ""; }; C498E5A2298D720600E90DE0 /* TestView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestView.swift; sourceTree = ""; }; C498E5A4299152B400E90DE0 /* GreenCheckmarkView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GreenCheckmarkView.swift; sourceTree = ""; }; + C4BA2AD52993F62700CB4FBA /* SoundSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SoundSelectionView.swift; sourceTree = ""; }; + C4BA2AD72993F7D200CB4FBA /* LeCountdown.0.5.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = LeCountdown.0.5.xcdatamodel; sourceTree = ""; }; C4F8B15629891271005C86A5 /* Conductor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Conductor.swift; sourceTree = ""; }; C4F8B15829891528005C86A5 /* forest_stream.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = forest_stream.mp3; sourceTree = ""; }; C4F8B15E298961A7005C86A5 /* ReorderableForEach.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReorderableForEach.swift; sourceTree = ""; }; @@ -538,6 +541,7 @@ C498E5A4299152B400E90DE0 /* GreenCheckmarkView.swift */, C4F8B1D1298BF646005C86A5 /* PermissionAlertView.swift */, C4F8B165298A9ABB005C86A5 /* SoundImageFormView.swift */, + C4BA2AD52993F62700CB4FBA /* SoundSelectionView.swift */, ); path = Components; sourceTree = ""; @@ -752,6 +756,7 @@ C438C807298195E600BF3EF9 /* Model+Extensions.swift in Sources */, C438C7FF2981300500BF3EF9 /* IntentDataProvider.swift in Sources */, C4F8B183298AC234005C86A5 /* Stopwatch+CoreDataProperties.swift in Sources */, + C4BA2AD62993F62700CB4FBA /* SoundSelectionView.swift in Sources */, C4F8B1A8298AC2FC005C86A5 /* AbstractSoundTimer+CoreDataProperties.swift in Sources */, C498E5A5299152B400E90DE0 /* GreenCheckmarkView.swift in Sources */, C4F8B1B8298AC81D005C86A5 /* CountdownDialView.swift in Sources */, @@ -1328,13 +1333,14 @@ C4060DCA297AE73D003FAB80 /* LeCountdown.xcdatamodeld */ = { isa = XCVersionGroup; children = ( + C4BA2AD72993F7D200CB4FBA /* LeCountdown.0.5.xcdatamodel */, C40FDB672993D5E80042A390 /* LeCountdown.0.4.xcdatamodel */, C4F8B160298A90E8005C86A5 /* LeCountdown.0.3.xcdatamodel */, C445FA902987C0CF0054D761 /* LeCountdown.0.2.xcdatamodel */, C418A14F298428CB00C22230 /* LeCountdown.0.1.xcdatamodel */, C4060DCB297AE73D003FAB80 /* LeCountdown.xcdatamodel */, ); - currentVersion = C40FDB672993D5E80042A390 /* LeCountdown.0.4.xcdatamodel */; + currentVersion = C4BA2AD72993F7D200CB4FBA /* LeCountdown.0.5.xcdatamodel */; path = LeCountdown.xcdatamodeld; sourceTree = ""; versionGroupType = wrapper.xcdatamodel; diff --git a/LeCountdown/LeCountdownApp.swift b/LeCountdown/LeCountdownApp.swift index bfbf4ac..72768a8 100644 --- a/LeCountdown/LeCountdownApp.swift +++ b/LeCountdown/LeCountdownApp.swift @@ -71,17 +71,17 @@ struct LeCountdownApp: App { fileprivate func _onAppear() { self._registerBackgroundRefreshes() - let voices = AVSpeechSynthesisVoice.speechVoices() - let grouped = Dictionary(grouping: voices, by: { $0.language }) - for language in grouped.keys { - if let lvoices = grouped[language] { - print("language = \(language)") - for voice in lvoices { - print("name = \(voice.name), gender = \(voice.gender)") - } - print("========") - } - } +// let voices = AVSpeechSynthesisVoice.speechVoices() +// let grouped = Dictionary(grouping: voices, by: { $0.language }) +// for language in grouped.keys { +// if let lvoices = grouped[language] { +// print("language = \(language)") +// for voice in lvoices { +// print("name = \(voice.name), gender = \(voice.gender)") +// } +// print("========") +// } +// } } diff --git a/LeCountdown/Model/Generation/AbstractSoundTimer+CoreDataProperties.swift b/LeCountdown/Model/Generation/AbstractSoundTimer+CoreDataProperties.swift index 1ac7aa8..a113d0e 100644 --- a/LeCountdown/Model/Generation/AbstractSoundTimer+CoreDataProperties.swift +++ b/LeCountdown/Model/Generation/AbstractSoundTimer+CoreDataProperties.swift @@ -17,6 +17,7 @@ extension AbstractSoundTimer { } @NSManaged public var repeatCount: Int16 - @NSManaged public var sound: Int16 + @NSManaged public var playlistList: String? + @NSManaged public var soundList: String? } diff --git a/LeCountdown/Model/LeCountdown.xcdatamodeld/.xccurrentversion b/LeCountdown/Model/LeCountdown.xcdatamodeld/.xccurrentversion index bb066f0..154daa0 100644 --- a/LeCountdown/Model/LeCountdown.xcdatamodeld/.xccurrentversion +++ b/LeCountdown/Model/LeCountdown.xcdatamodeld/.xccurrentversion @@ -3,6 +3,6 @@ _XCCurrentVersionName - LeCountdown.0.4.xcdatamodel + LeCountdown.0.5.xcdatamodel diff --git a/LeCountdown/Model/LeCountdown.xcdatamodeld/LeCountdown.0.5.xcdatamodel/contents b/LeCountdown/Model/LeCountdown.xcdatamodeld/LeCountdown.0.5.xcdatamodel/contents new file mode 100644 index 0000000..0a6e75f --- /dev/null +++ b/LeCountdown/Model/LeCountdown.xcdatamodeld/LeCountdown.0.5.xcdatamodel/contents @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/LeCountdown/Model/Model+Extensions.swift b/LeCountdown/Model/Model+Extensions.swift index 0b927fc..ea0af2f 100644 --- a/LeCountdown/Model/Model+Extensions.swift +++ b/LeCountdown/Model/Model+Extensions.swift @@ -46,8 +46,33 @@ extension AbstractTimer { extension AbstractSoundTimer { + var sounds: [Sound] { + if let soundList { + return soundList.enumItems() + } + return [] + } + + var playlists: [Playlist] { + if let playlistList { + return playlistList.enumItems() + } + return [] + } + + func setSounds(_ sounds: [Sound]) { + self.soundList = sounds.stringRepresentation + } + + func setPlaylists(_ playlists: [Playlist]) { + self.playlistList = playlists.stringRepresentation + } + var coolSound: Sound { - return Sound(rawValue: Int(self.sound)) ?? Sound.allCases[0] + var allSounds: [Sound] = [] + allSounds.append(contentsOf: self.sounds) + allSounds.append(contentsOf: self.playlists.reduce([], { $0 + $1.sounds })) + return allSounds.randomElement() ?? Sound.allCases[0] } var soundName: String { @@ -120,3 +145,27 @@ extension Activity { } } + +// MARK: - Storage convenience + +fileprivate let separator = "|" +fileprivate let formatter: NumberFormatter = NumberFormatter() + +extension String { + + func enumItems>() -> [T] { + let ids: [String] = self.components(separatedBy: separator) + let intIds: [Int] = ids.compactMap { formatter.number(from: $0)?.intValue } + return intIds.compactMap { T(rawValue: $0) } + } + +} + +extension Array where Element : RawRepresentable { + + var stringRepresentation: String { + let ids = self.compactMap { formatter.string(from: NSNumber(value: $0.rawValue)) } + return ids.joined(separator: separator) + } + +} diff --git a/LeCountdown/Sound/Sound.swift b/LeCountdown/Sound/Sound.swift index 3d780d0..f48b591 100644 --- a/LeCountdown/Sound/Sound.swift +++ b/LeCountdown/Sound/Sound.swift @@ -8,8 +8,88 @@ import Foundation import AVFoundation +struct PlaylistSelection: Identifiable { + var id: Int { return self.playlist.id } + var playlist: Playlist + + var selected: Bool { + didSet { + if selected { + self.sounds = playlist.sounds + } else { + self.sounds = [] + } + } + } + + fileprivate var _sounds: [Sound] = [] + var sounds: [Sound] { + set { + _sounds = newValue + + if !selected && (newValue.count == self.playlist.sounds.count) { + self.selected = true + } else if selected && (newValue.count != self.playlist.sounds.count) { + self.selected = false + } + + } + get { + return _sounds + } + } + + static func allPlaylists() -> [PlaylistSelection] { + + var playlistSelections: [PlaylistSelection] = [] + for playlist in Playlist.allCases { + let playlistSelection = PlaylistSelection(playlist: playlist, selected: false) + playlistSelections.append(playlistSelection) + } + return playlistSelections + } + +} + +struct SoundSelection: Identifiable { + var id: Int { return self.sound.id } + var sound: Sound + var selected: Bool +} + +enum Playlist: Int, CaseIterable, Identifiable { + + var id: Int { return self.rawValue } + + case nature = 1 + case fun + case stephanBodzin + + var sounds: [Sound] { + switch self { + case .nature: + return Sound.allCases + case .fun: + return Sound.allCases + case .stephanBodzin: + return Sound.allCases + } + } + + var localizedString: String { + switch self { + case .nature: + return NSLocalizedString("Nature", comment: "") + case .fun: + return NSLocalizedString("Fun", comment: "") + case .stephanBodzin: + return "Stephan Bodzin" + } + } +} + // Sound id are stored thus case order should not be changed -enum Sound : Int, CaseIterable, Identifiable { +enum Sound: Int, CaseIterable, Identifiable { var id: Int { return self.rawValue } diff --git a/LeCountdown/Views/Alarm/AlarmFormView.swift b/LeCountdown/Views/Alarm/AlarmFormView.swift index c6a7ce8..392f885 100644 --- a/LeCountdown/Views/Alarm/AlarmFormView.swift +++ b/LeCountdown/Views/Alarm/AlarmFormView.swift @@ -12,14 +12,25 @@ struct AlarmFormView: View { var dateBinding: Binding var imageBinding: Binding - var soundBinding: Binding + var soundsBinding: Binding<[Sound]> + var playlistsBinding: Binding<[Playlist]> var repeatCountBinding: Binding var body: some View { Form { - DatePicker("Time", selection: dateBinding, displayedComponents: .hourAndMinute) - SoundImageFormView(imageBinding: imageBinding, soundBinding: soundBinding, repeatCountBinding: self.repeatCountBinding) + + Text("todo") + + +// DatePicker("Time", selection: dateBinding, displayedComponents: .hourAndMinute) +// +// SoundImageFormView(imageBinding: self.imageBinding, +// soundsBinding: self.soundBinding, +// playlistsBinding: self.playlistsBinding, +// repeatCountBinding: self.repeatCountBinding) + +// SoundImageFormView(imageBinding: imageBinding, soundBinding: soundBinding, repeatCountBinding: self.repeatCountBinding) } } } @@ -27,6 +38,6 @@ struct AlarmFormView: View { struct AlarmFormView_Previews: PreviewProvider { static var previews: some View { AlarmFormView(dateBinding: .constant(Date()), - imageBinding: .constant(.pic1), soundBinding: .constant(.trainhorn), repeatCountBinding: .constant(2)) + imageBinding: .constant(.pic1), soundsBinding: .constant([]), playlistsBinding: .constant([]), repeatCountBinding: .constant(2)) } } diff --git a/LeCountdown/Views/Alarm/NewAlarmView.swift b/LeCountdown/Views/Alarm/NewAlarmView.swift index cd1625f..0345838 100644 --- a/LeCountdown/Views/Alarm/NewAlarmView.swift +++ b/LeCountdown/Views/Alarm/NewAlarmView.swift @@ -36,7 +36,9 @@ struct AlarmEditView: View { @State var nameString: String = "" - @State var sound: Sound = .trainhorn + @State var sounds: [Sound] = [.trainhorn] + @State var playlists: [Playlist] = [] + @State var soundRepeatCount: Int16 = 0 @State var image: CoolPic = .pic1 @@ -65,10 +67,14 @@ struct AlarmEditView: View { self._save() } } - AlarmFormView(dateBinding: self.$time, - imageBinding: self.$image, - soundBinding: self.$sound, - repeatCountBinding: self.$soundRepeatCount) + + Text("todo") +// AlarmFormView(dateBinding: self.$time, +// imageBinding: self.$image, +// +// +// soundBinding: self.$sound, +// repeatCountBinding: self.$soundRepeatCount) .onAppear { self._onAppear() } @@ -146,9 +152,8 @@ struct AlarmEditView: View { self.nameString = name } - if let sound = Sound(rawValue: Int(alarm.sound)) { - self.sound = sound - } + self.sounds = alarm.sounds + self.playlists = alarm.playlists if let image = alarm.image, let coolpic = CoolPic(rawValue: image) { self.image = coolpic @@ -177,7 +182,10 @@ struct AlarmEditView: View { a.fireDate = self.time a.image = self.image.rawValue - a.sound = Int16(self.sound.rawValue) + + a.setSounds(self.sounds) + a.setPlaylists(self.playlists) + a.repeatCount = self.soundRepeatCount if !self.nameString.isEmpty { diff --git a/LeCountdown/Views/Components/SoundImageFormView.swift b/LeCountdown/Views/Components/SoundImageFormView.swift index ae52992..afddd59 100644 --- a/LeCountdown/Views/Components/SoundImageFormView.swift +++ b/LeCountdown/Views/Components/SoundImageFormView.swift @@ -10,7 +10,9 @@ import SwiftUI struct SoundImageFormView : View { var imageBinding: Binding - var soundBinding: Binding + + var playlistBinding: Binding<[PlaylistSelection]> + var repeatCountBinding: Binding? = nil var optionalSound: Binding? = nil @@ -27,25 +29,37 @@ struct SoundImageFormView : View { Toggle("Play sound on end", isOn: optionalSound!) if self.optionalSound?.wrappedValue == true { - Picker(selection: soundBinding) { - ForEach(Sound.allCases) { sound in - Text(sound.localizedString).tag(sound) - } + NavigationLink { + SoundSelectionView(playlistBinding: playlistBinding) } label: { Text("Sound") } + +// Picker(selection: soundBinding) { +// ForEach(Sound.allCases) { sound in +// Text(sound.localizedString).tag(sound) +// } +// } label: { +// Text("Sound") +// } } } else { - Picker(selection: soundBinding) { - ForEach(Sound.allCases) { sound in - Text(sound.localizedString).tag(sound) - } - } label: { - Text("Sound") - } +// Picker(selection: soundBinding) { +// ForEach(Sound.allCases) { sound in +// Text(sound.localizedString).tag(sound) +// } +// } label: { +// Text("Sound") +// } } + NavigationLink { + SoundSelectionView(playlistBinding: playlistBinding) + } label: { + Text("Sound") + } + Picker("Repeat Count", selection: self.repeatCountBinding!) { ForEach(0..<6) { let count = Int16($0) @@ -54,17 +68,6 @@ struct SoundImageFormView : View { } -// if self.repeatCountBinding != nil { -// Picker(selection: self.repeatCountBinding!) { -// ForEach(0..<6) { count in -// Text("\(count)").tag(count) -// } -// } label: { -// Text("Repeat count") -// } -// -//// Toggle("Sound repeats", isOn: repeatsBinding!) -// } } Section(header: Text("Background")) { @@ -100,7 +103,7 @@ struct SoundImageFormView_Previews: PreviewProvider { Form { SoundImageFormView( imageBinding: .constant(.pic1), - soundBinding: .constant(.forestStream), + playlistBinding: .constant([]), repeatCountBinding: .constant(2)) } } diff --git a/LeCountdown/Views/Components/SoundSelectionView.swift b/LeCountdown/Views/Components/SoundSelectionView.swift new file mode 100644 index 0000000..2bc9a3a --- /dev/null +++ b/LeCountdown/Views/Components/SoundSelectionView.swift @@ -0,0 +1,63 @@ +// +// SoundSelectionView.swift +// LeCountdown +// +// Created by Laurent Morvillier on 08/02/2023. +// + +import SwiftUI + +struct SoundRow: View { + var sound: Sound + @State var selected: Bool + var handleSelection: (Bool) -> () + + var body: some View { + Toggle(sound.localizedString, isOn: $selected) + .onChange(of: selected, perform: handleSelection) + } + +} + +struct SoundSelectionView: View { + + @Binding var playlistBinding: [PlaylistSelection] + + var body: some View { + + Form { + + ForEach($playlistBinding, id: \.id) { $ps in + + List(selection: <#T##Binding<_?>?#>) { + <#code#> + } + + + Section { + ForEach(ps.playlist.sounds) { sound in + + SoundRow(sound: sound, selected: ps.sounds.contains(sound)) { selected in + if selected { + ps.sounds.append(sound) + } else { + ps.sounds.removeAll(where: { $0 == sound }) + } + } + } + } header: { + Toggle(ps.playlist.localizedString, isOn: $ps.selected) + } + }.navigationTitle("Sounds") + + } + + } +} + +struct SoundSelectionView_Previews: PreviewProvider { + static var previews: some View { + SoundSelectionView( + playlistBinding: .constant([])) + } +} diff --git a/LeCountdown/Views/Countdown/CountdownFormView.swift b/LeCountdown/Views/Countdown/CountdownFormView.swift index 332ff9b..691d352 100644 --- a/LeCountdown/Views/Countdown/CountdownFormView.swift +++ b/LeCountdown/Views/Countdown/CountdownFormView.swift @@ -15,7 +15,7 @@ struct CountdownFormView : View { var nameBinding: Binding var imageBinding: Binding - var soundBinding: Binding + var playlistBinding: Binding<[PlaylistSelection]> var repeatCountBinding: Binding var textFieldIsFocused: FocusState.Binding @@ -37,7 +37,7 @@ struct CountdownFormView : View { SoundImageFormView( imageBinding: imageBinding, - soundBinding: soundBinding, + playlistBinding: playlistBinding, repeatCountBinding: repeatCountBinding) } @@ -51,6 +51,6 @@ struct CountdownFormView_Previews: PreviewProvider { static var previews: some View { CountdownFormView(secondsBinding: .constant(""), minutesBinding: .constant(""), - nameBinding: .constant(""), imageBinding: .constant(.pic3), soundBinding: .constant(.trainhorn), repeatCountBinding: .constant(2), textFieldIsFocused: $textFieldIsFocused) + nameBinding: .constant(""), imageBinding: .constant(.pic3), playlistBinding: .constant([]), repeatCountBinding: .constant(2), textFieldIsFocused: $textFieldIsFocused) } } diff --git a/LeCountdown/Views/Countdown/NewCountdownView.swift b/LeCountdown/Views/Countdown/NewCountdownView.swift index 5ea5024..48e4268 100644 --- a/LeCountdown/Views/Countdown/NewCountdownView.swift +++ b/LeCountdown/Views/Countdown/NewCountdownView.swift @@ -36,7 +36,8 @@ struct CountdownEditView : View { @State var minutesString: String = "" @State var nameString: String = "" - @State var sound: Sound = .trainhorn +// @State var sounds: [SoundSelection] = [] + @State var playlists: [PlaylistSelection] = [] @State var soundRepeatCount: Int16 = 0 @State var image: CoolPic = .pic1 @@ -70,7 +71,7 @@ struct CountdownEditView : View { minutesBinding: $minutesString, nameBinding: $nameString, imageBinding: $image, - soundBinding: $sound, + playlistBinding: $playlists, repeatCountBinding: $soundRepeatCount, textFieldIsFocused: $textFieldIsFocused) .onAppear { @@ -138,6 +139,8 @@ struct CountdownEditView : View { fileprivate func _onAppear() { + self.playlists = PlaylistSelection.allPlaylists() + self._isAdding = (self.countdown == nil) if let countdown { @@ -157,9 +160,11 @@ struct CountdownEditView : View { self.nameString = name } - if let sound = Sound(rawValue: Int(countdown.sound)) { - self.sound = sound - } +// self.sounds = countdown.sounds + +// if let sound = Sound(rawValue: Int(countdown.sound)) { +// self.sound = sound +// } self.soundRepeatCount = countdown.repeatCount if let image = countdown.image, let coolpic = CoolPic(rawValue: image) { @@ -200,7 +205,8 @@ struct CountdownEditView : View { } cd.image = self.image.rawValue - cd.sound = Int16(self.sound.rawValue) +// cd.setSounds(self.sounds) +// cd.setPlaylists(self.playlists) cd.repeatCount = self.soundRepeatCount if !self.nameString.isEmpty { diff --git a/LeCountdown/Views/DialView.swift b/LeCountdown/Views/DialView.swift index a40747a..cb4e26b 100644 --- a/LeCountdown/Views/DialView.swift +++ b/LeCountdown/Views/DialView.swift @@ -114,7 +114,7 @@ struct DialView_Previews: PreviewProvider { DialView( timer: Countdown.fake(context: PersistenceController.preview.container.viewContext), - isEditingBinding: .constant(true), frameSize: 150.0) + isEditingBinding: .constant(false), frameSize: 150.0) .environmentObject(Conductor.maestro) .environmentObject(BoringContext()) diff --git a/LeCountdown/Views/Stopwatch/NewStopwatchView.swift b/LeCountdown/Views/Stopwatch/NewStopwatchView.swift index 073cf0e..dbc6751 100644 --- a/LeCountdown/Views/Stopwatch/NewStopwatchView.swift +++ b/LeCountdown/Views/Stopwatch/NewStopwatchView.swift @@ -37,7 +37,7 @@ struct StopwatchEditView: View { @State var nameString: String = "" @State var playSound: Bool = false - @State var sound: Sound = .trainhorn + @State var playlists: [PlaylistSelection] = [] @State var image: CoolPic = .pic1 @State var deleteConfirmationShown: Bool = false @@ -67,7 +67,8 @@ struct StopwatchEditView: View { } StopwatchFormView(nameBinding: self.$nameString, imageBinding: self.$image, - soundBinding: self.$sound, playSoundBinding: self.$playSound, + playSoundBinding: self.$playSound, + playlistBinding: self.$playlists, textFieldIsFocused: $textFieldIsFocused) .onAppear { self._onAppear() @@ -142,9 +143,9 @@ struct StopwatchEditView: View { self.nameString = name } - if let sound = Sound(rawValue: Int(stopwatch.sound)) { - self.sound = sound - } +// if let sound = Sound(rawValue: Int(stopwatch.sound)) { +// self.sound = sound +// } if let image = stopwatch.image, let coolpic = CoolPic(rawValue: image) { self.image = coolpic @@ -174,11 +175,11 @@ struct StopwatchEditView: View { sw.image = self.image.rawValue - if self.playSound { - sw.sound = Int16(self.sound.rawValue) - } else { -// sw.sound = nil - } +// if self.playSound { +// sw.sound = Int16(self.sound.rawValue) +// } else { +//// sw.sound = nil +// } if !self.nameString.isEmpty { diff --git a/LeCountdown/Views/Stopwatch/StopwatchFormView.swift b/LeCountdown/Views/Stopwatch/StopwatchFormView.swift index ddfc404..8936234 100644 --- a/LeCountdown/Views/Stopwatch/StopwatchFormView.swift +++ b/LeCountdown/Views/Stopwatch/StopwatchFormView.swift @@ -11,9 +11,10 @@ struct StopwatchFormView: View { var nameBinding: Binding var imageBinding: Binding - var soundBinding: Binding var playSoundBinding: Binding + var playlistBinding: Binding<[PlaylistSelection]> + var textFieldIsFocused: FocusState.Binding var body: some View { @@ -25,7 +26,7 @@ struct StopwatchFormView: View { } SoundImageFormView(imageBinding: imageBinding, - soundBinding: soundBinding, + playlistBinding: playlistBinding, optionalSound: playSoundBinding) } @@ -39,6 +40,7 @@ struct StopwatchFormView_Previews: PreviewProvider { static var previews: some View { StopwatchFormView(nameBinding: .constant(""), imageBinding: .constant(.pic1), - soundBinding: .constant(.trainhorn), playSoundBinding: .constant(true), textFieldIsFocused: $textFieldIsFocused) + playSoundBinding: .constant(true), + playlistBinding: .constant([]), textFieldIsFocused: $textFieldIsFocused) } }