|
|
|
|
@ -11,15 +11,16 @@ import SwiftUI |
|
|
|
|
protocol SoundHolder { |
|
|
|
|
func selectSound(_ sound: Sound, selected: Bool) |
|
|
|
|
func selectPlaylist(_ playlist: Playlist, selected: Bool) |
|
|
|
|
|
|
|
|
|
func isSelected(sound: Sound) -> Bool |
|
|
|
|
func isSelected(playlist: Playlist) -> Bool |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class TimerModel : ObservableObject, SoundHolder { |
|
|
|
|
|
|
|
|
|
@Published var playlists: Set<Playlist> = [] |
|
|
|
|
@Published var sounds: Set<Sound> = [] |
|
|
|
|
@Published var sounds: Set<Sound> = [] { |
|
|
|
|
didSet { |
|
|
|
|
self._selectPlaylists() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var soundSelection: String { |
|
|
|
|
if !sounds.isEmpty { |
|
|
|
|
@ -50,11 +51,9 @@ class TimerModel : ObservableObject, SoundHolder { |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MARK: - SoundHolder |
|
|
|
|
|
|
|
|
|
func selectSound(_ sound: Sound, selected: Bool) { |
|
|
|
|
print("selectSound") |
|
|
|
|
|
|
|
|
|
if selected { |
|
|
|
|
self.sounds.insert(sound) |
|
|
|
|
@ -62,8 +61,18 @@ class TimerModel : ObservableObject, SoundHolder { |
|
|
|
|
self.sounds.remove(sound) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
self._togglePlaylist(sound.playlist) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _selectPlaylists() { |
|
|
|
|
let playlists: Set<Playlist> = Set(self.sounds.map { $0.playlist }) |
|
|
|
|
for playlist in playlists { |
|
|
|
|
self._togglePlaylist(playlist) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _togglePlaylist(_ playlist: Playlist) { |
|
|
|
|
// toggle playlist if necessary |
|
|
|
|
let playlist = sound.playlist |
|
|
|
|
let playlistSounds: [Sound] = SoundCatalog.main.sounds(for: playlist) |
|
|
|
|
if self.sounds.isSuperset(of: playlistSounds) { |
|
|
|
|
self.playlists.insert(playlist) |
|
|
|
|
@ -74,7 +83,6 @@ class TimerModel : ObservableObject, SoundHolder { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func selectPlaylist(_ playlist: Playlist, selected: Bool) { |
|
|
|
|
print("selectPlaylist") |
|
|
|
|
|
|
|
|
|
let sounds: [Sound] = SoundCatalog.main.sounds(for: playlist) |
|
|
|
|
if selected { |
|
|
|
|
@ -87,31 +95,14 @@ class TimerModel : ObservableObject, SoundHolder { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
print("sounds = \(self.sounds.count)") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func isSelected(sound: Sound) -> Bool { |
|
|
|
|
self.sounds.contains(sound) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func isSelected(playlist: Playlist) -> Bool { |
|
|
|
|
self.playlists.contains(playlist) |
|
|
|
|
} |
|
|
|
|
// func isSelected(sound: Sound) -> Bool { |
|
|
|
|
// self.sounds.contains(sound) |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// func isSelected(playlist: Playlist) -> Bool { |
|
|
|
|
// self.playlists.contains(playlist) |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class SoundHolderPlaceholder : ObservableObject, SoundHolder { |
|
|
|
|
func selectSound(_ sound: Sound, selected: Bool) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func selectPlaylist(_ playlist: Playlist, selected: Bool) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func isSelected(sound: Sound) -> Bool { |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func isSelected(playlist: Playlist) -> Bool { |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|