fix and cleanup

release
Laurent 3 years ago
parent 30867eb258
commit 73b1cf09c0
  1. 4
      LeCountdown/AppDelegate.swift
  2. 13
      LeCountdown/Views/Components/SoundImageFormView.swift
  3. 7
      LeCountdown/Views/Components/SoundSelectionView.swift
  4. 55
      LeCountdown/Views/Components/TimerModel.swift
  5. 9
      LeCountdown/Views/Countdown/CountdownFormView.swift
  6. 3
      LeCountdown/Views/DialView.swift
  7. 2
      LeCountdown/Views/Stopwatch/StopwatchFormView.swift

@ -16,7 +16,7 @@ class AppDelegate : NSObject, UIApplicationDelegate {
Conductor.maestro.cleanupCountdowns() Conductor.maestro.cleanupCountdowns()
return true return true
} }
} }
extension AppDelegate: UNUserNotificationCenterDelegate { extension AppDelegate: UNUserNotificationCenterDelegate {
@ -31,7 +31,7 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
print("willPresent notification") print("willPresent notification")
completionHandler([.banner]) // completionHandler([.banner])
let timerId = self._timerId(notificationId: notification.request.identifier) let timerId = self._timerId(notificationId: notification.request.identifier)
Conductor.maestro.notifyUser(countdownId: timerId) Conductor.maestro.notifyUser(countdownId: timerId)

@ -58,7 +58,9 @@ struct SoundImageFormView : View {
} }
NavigationLink { NavigationLink {
PlaylistsView().environmentObject(self.model) NavigationStack {
PlaylistsView().environmentObject(self.model)
}
} label: { } label: {
HStack { HStack {
Text("Sound") Text("Sound")
@ -106,19 +108,12 @@ struct SoundImageFormView : View {
struct SoundImageFormView_Previews: PreviewProvider { struct SoundImageFormView_Previews: PreviewProvider {
static func soundBinding(sound: Sound) -> Binding<Bool> {
return .constant(true)
}
static func playlistBinding(playlist: Playlist) -> Binding<Bool> {
return .constant(true)
}
static var previews: some View { static var previews: some View {
Form { Form {
SoundImageFormView( SoundImageFormView(
imageBinding: .constant(.pic1), imageBinding: .constant(.pic1),
repeatCountBinding: .constant(2)) repeatCountBinding: .constant(2))
.environmentObject(SoundHolderPlaceholder()) .environmentObject(TimerModel())
} }
} }
} }

@ -117,13 +117,6 @@ struct SoundSelectionView: View {
struct PlaylistsView_Previews: PreviewProvider { struct PlaylistsView_Previews: PreviewProvider {
static func soundBinding(sound: Sound) -> Binding<Bool> {
return .constant(true)
}
static func playlistBinding(playlist: Playlist) -> Binding<Bool> {
return .constant(true)
}
static var previews: some View { static var previews: some View {
PlaylistsView() PlaylistsView()
.environmentObject(TimerModel()) .environmentObject(TimerModel())

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

@ -51,13 +51,6 @@ struct CountdownFormView_Previews: PreviewProvider {
@FocusState static var textFieldIsFocused: Bool @FocusState static var textFieldIsFocused: Bool
static func soundBinding(sound: Sound) -> Binding<Bool> {
return .constant(true)
}
static func playlistBinding(playlist: Playlist) -> Binding<Bool> {
return .constant(true)
}
static var previews: some View { static var previews: some View {
CountdownFormView( CountdownFormView(
secondsBinding: .constant(""), secondsBinding: .constant(""),
@ -66,6 +59,6 @@ struct CountdownFormView_Previews: PreviewProvider {
imageBinding: .constant(.pic3), imageBinding: .constant(.pic3),
repeatCountBinding: .constant(2), repeatCountBinding: .constant(2),
textFieldIsFocused: $textFieldIsFocused) textFieldIsFocused: $textFieldIsFocused)
.environmentObject(SoundHolderPlaceholder()) .environmentObject(TimerModel())
} }
} }

@ -79,10 +79,13 @@ struct DialView: View {
switch timer { switch timer {
case let countdown as Countdown: case let countdown as Countdown:
CountdownEditView(countdown: countdown, isPresented: isPresented) CountdownEditView(countdown: countdown, isPresented: isPresented)
.environment(\.managedObjectContext, viewContext)
case let alarm as Alarm: case let alarm as Alarm:
AlarmEditView(alarm: alarm, isPresented: isPresented) AlarmEditView(alarm: alarm, isPresented: isPresented)
.environment(\.managedObjectContext, viewContext)
case let stopwatch as Stopwatch: case let stopwatch as Stopwatch:
StopwatchEditView(stopwatch: stopwatch, isPresented: isPresented) StopwatchEditView(stopwatch: stopwatch, isPresented: isPresented)
.environment(\.managedObjectContext, viewContext)
default: default:
Text("missing edit view") Text("missing edit view")
} }

@ -43,6 +43,6 @@ struct StopwatchFormView_Previews: PreviewProvider {
imageBinding: .constant(.pic1), imageBinding: .constant(.pic1),
playSoundBinding: .constant(true), playSoundBinding: .constant(true),
textFieldIsFocused: $textFieldIsFocused) textFieldIsFocused: $textFieldIsFocused)
.environmentObject(SoundHolderPlaceholder()) .environmentObject(TimerModel())
} }
} }

Loading…
Cancel
Save