|
|
|
|
@ -6,6 +6,7 @@ |
|
|
|
|
// |
|
|
|
|
|
|
|
|
|
import Foundation |
|
|
|
|
import SwiftUI |
|
|
|
|
|
|
|
|
|
protocol SoundHolder { |
|
|
|
|
func selectSound(_ sound: Sound, selected: Bool) |
|
|
|
|
@ -20,6 +21,25 @@ class TimerModel : ObservableObject, SoundHolder { |
|
|
|
|
@Published var playlists: Set<Playlist> = [] |
|
|
|
|
@Published var sounds: Set<Sound> = [] |
|
|
|
|
|
|
|
|
|
func binding(sound: Sound) -> Binding<Bool> { |
|
|
|
|
return Binding<Bool>(get: { |
|
|
|
|
return self.sounds.contains(sound) |
|
|
|
|
}, set: { value in |
|
|
|
|
if value { self.sounds.insert(sound) } |
|
|
|
|
else { self.sounds.remove(sound) } |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func binding(playlist: Playlist) -> Binding<Bool> { |
|
|
|
|
return Binding<Bool>(get: { |
|
|
|
|
return self.playlists.contains(playlist) |
|
|
|
|
}, set: { value in |
|
|
|
|
if value { self.playlists.insert(playlist) } |
|
|
|
|
else { self.playlists.remove(playlist) } |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MARK: - SoundHolder |
|
|
|
|
|
|
|
|
|
func selectSound(_ sound: Sound, selected: Bool) { |
|
|
|
|
@ -45,14 +65,16 @@ class TimerModel : ObservableObject, SoundHolder { |
|
|
|
|
func selectPlaylist(_ playlist: Playlist, selected: Bool) { |
|
|
|
|
print("selectPlaylist") |
|
|
|
|
|
|
|
|
|
let sounds: [Sound] = SoundCatalog.main.sounds(for: playlist) |
|
|
|
|
if selected { |
|
|
|
|
self.playlists.insert(playlist) |
|
|
|
|
self.sounds.formUnion(sounds) |
|
|
|
|
} else { |
|
|
|
|
self.playlists.remove(playlist) |
|
|
|
|
if self.sounds.isSuperset(of: sounds) { |
|
|
|
|
self.sounds.formSymmetricDifference(sounds) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let sounds: [Sound] = SoundCatalog.main.sounds(for: playlist) |
|
|
|
|
self.sounds.formSymmetricDifference(sounds) |
|
|
|
|
|
|
|
|
|
print("sounds = \(self.sounds.count)") |
|
|
|
|
} |
|
|
|
|
|