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

@ -58,7 +58,9 @@ struct SoundImageFormView : View {
}
NavigationLink {
PlaylistsView().environmentObject(self.model)
NavigationStack {
PlaylistsView().environmentObject(self.model)
}
} label: {
HStack {
Text("Sound")
@ -106,19 +108,12 @@ struct SoundImageFormView : View {
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 {
Form {
SoundImageFormView(
imageBinding: .constant(.pic1),
repeatCountBinding: .constant(2))
.environmentObject(SoundHolderPlaceholder())
.environmentObject(TimerModel())
}
}
}

@ -117,13 +117,6 @@ struct SoundSelectionView: View {
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 {
PlaylistsView()
.environmentObject(TimerModel())

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

@ -51,13 +51,6 @@ struct CountdownFormView_Previews: PreviewProvider {
@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 {
CountdownFormView(
secondsBinding: .constant(""),
@ -66,6 +59,6 @@ struct CountdownFormView_Previews: PreviewProvider {
imageBinding: .constant(.pic3),
repeatCountBinding: .constant(2),
textFieldIsFocused: $textFieldIsFocused)
.environmentObject(SoundHolderPlaceholder())
.environmentObject(TimerModel())
}
}

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

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

Loading…
Cancel
Save