Fixes sounds selection

release
Laurent 3 years ago
parent b1c0927bbf
commit 929127cb8f
  1. 1
      LeCountdown/CountdownScheduler.swift
  2. 6
      LeCountdown/Views/Components/SoundSelectionView.swift
  3. 28
      LeCountdown/Views/Components/TimerModel.swift

@ -44,6 +44,7 @@ class CountdownScheduler {
content.body = body
content.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: countdown.soundName))
content.interruptionLevel = .critical
content.relevanceScore = 1.0
let notificationCount = 1 + countdown.repeatCount

@ -35,12 +35,12 @@ struct PlaylistSectionView: View {
Section {
let sounds = SoundCatalog.main.sounds(for: self.playlist)
List(sounds) { sound in
ToggleRow(item: sound, selected: self.model.isSelected(sound: sound)) { selected in
ToggleRow(item: sound, selected: self.model.binding(sound: sound)) { selected in
self.model.selectSound(sound, selected: selected)
}
}
} header: {
ToggleRow(item: self.playlist, selected: self.model.isSelected(playlist: self.playlist)) { selected in
ToggleRow(item: self.playlist, selected: self.model.binding(playlist: playlist)) { selected in
self.model.selectPlaylist(self.playlist, selected: selected)
}
}
@ -51,7 +51,7 @@ struct PlaylistSectionView: View {
struct ToggleRow<T : Localized>: View {
var item: T
@State var selected: Bool
@Binding var selected: Bool
var handleSelection: (Bool) -> ()
var body: some View {

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

Loading…
Cancel
Save