Fixes issues with stopwatch editing

main
Laurent 3 years ago
parent 528c3d0af9
commit e4758a3fea
  1. 16
      LeCountdown.xcodeproj/project.pbxproj
  2. 4
      LeCountdown/Model/Generation/AbstractSoundTimer+CoreDataProperties.swift
  3. 4
      LeCountdown/Model/Generation/AbstractTimer+CoreDataProperties.swift
  4. 5
      LeCountdown/Model/Generation/Stopwatch+CoreDataClass.swift
  5. 2
      LeCountdown/Model/Generation/Stopwatch+CoreDataProperties.swift
  6. 2
      LeCountdown/Model/LeCountdown.xcdatamodeld/LeCountdown.0.6.4.xcdatamodel/contents
  7. 12
      LeCountdown/Model/Model+Extensions.swift
  8. 1
      LeCountdown/Views/Countdown/CountdownFormView.swift
  9. 1
      LeCountdown/Views/Countdown/NewCountdownView.swift
  10. 3
      LeCountdown/Views/Reusable/SoundFormView.swift
  11. 68
      LeCountdown/Views/Stopwatch/NewStopwatchView.swift
  12. 2
      LeCountdown/Views/Stopwatch/StopwatchFormView.swift

@ -38,6 +38,9 @@
C415D3FB29C37A460037B215 /* QP01 0096 Wetland lake early morning.wav in Resources */ = {isa = PBXBuildFile; fileRef = C415D3FA29C37A460037B215 /* QP01 0096 Wetland lake early morning.wav */; };
C415D3FD29C37AA40037B215 /* QP01 0118 Riparian Zone thrush.wav in Resources */ = {isa = PBXBuildFile; fileRef = C415D3FC29C37AA40037B215 /* QP01 0118 Riparian Zone thrush.wav */; };
C4286E962A14EC4E0070D075 /* AppError.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4286E952A14EC4E0070D075 /* AppError.swift */; };
C4286EA12A1502FD0070D075 /* Stopwatch+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4286E9F2A1502FD0070D075 /* Stopwatch+CoreDataClass.swift */; };
C4286EA32A1503320070D075 /* Stopwatch+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4286E9F2A1502FD0070D075 /* Stopwatch+CoreDataClass.swift */; };
C4286EA42A1503330070D075 /* Stopwatch+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4286E9F2A1502FD0070D075 /* Stopwatch+CoreDataClass.swift */; };
C42E96FB29E59E72005B1B8C /* BackgroundBlurView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42E96FA29E59E72005B1B8C /* BackgroundBlurView.swift */; };
C42E96FD29E5B06D005B1B8C /* ActivityCalendarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C42E96FC29E5B06D005B1B8C /* ActivityCalendarView.swift */; };
C42E96FE29E5B5CD005B1B8C /* Filter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4BA2B6429A3C37D00CB4FBA /* Filter.swift */; };
@ -249,14 +252,12 @@
C4F8B17C298AC234005C86A5 /* Record+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B16E298AC234005C86A5 /* Record+CoreDataClass.swift */; };
C4F8B17D298AC234005C86A5 /* Record+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B16F298AC234005C86A5 /* Record+CoreDataProperties.swift */; };
C4F8B17E298AC234005C86A5 /* Alarm+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B170298AC234005C86A5 /* Alarm+CoreDataClass.swift */; };
C4F8B182298AC234005C86A5 /* Stopwatch+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B174298AC234005C86A5 /* Stopwatch+CoreDataClass.swift */; };
C4F8B184298AC234005C86A5 /* AbstractTimer+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B176298AC234005C86A5 /* AbstractTimer+CoreDataClass.swift */; };
C4F8B185298AC234005C86A5 /* AbstractTimer+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B177298AC234005C86A5 /* AbstractTimer+CoreDataProperties.swift */; };
C4F8B186298AC234005C86A5 /* Activity+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B178298AC234005C86A5 /* Activity+CoreDataClass.swift */; };
C4F8B187298AC234005C86A5 /* Activity+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B179298AC234005C86A5 /* Activity+CoreDataProperties.swift */; };
C4F8B18B298AC288005C86A5 /* Record+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B16E298AC234005C86A5 /* Record+CoreDataClass.swift */; };
C4F8B18C298AC288005C86A5 /* Alarm+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B170298AC234005C86A5 /* Alarm+CoreDataClass.swift */; };
C4F8B18D298AC288005C86A5 /* Stopwatch+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B174298AC234005C86A5 /* Stopwatch+CoreDataClass.swift */; };
C4F8B18E298AC288005C86A5 /* AbstractTimer+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B177298AC234005C86A5 /* AbstractTimer+CoreDataProperties.swift */; };
C4F8B18F298AC288005C86A5 /* AbstractTimer+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B176298AC234005C86A5 /* AbstractTimer+CoreDataClass.swift */; };
C4F8B192298AC288005C86A5 /* Activity+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B179298AC234005C86A5 /* Activity+CoreDataProperties.swift */; };
@ -265,7 +266,6 @@
C4F8B195298AC288005C86A5 /* Activity+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B178298AC234005C86A5 /* Activity+CoreDataClass.swift */; };
C4F8B199298AC288005C86A5 /* Record+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B16E298AC234005C86A5 /* Record+CoreDataClass.swift */; };
C4F8B19A298AC288005C86A5 /* Alarm+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B170298AC234005C86A5 /* Alarm+CoreDataClass.swift */; };
C4F8B19B298AC288005C86A5 /* Stopwatch+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B174298AC234005C86A5 /* Stopwatch+CoreDataClass.swift */; };
C4F8B19C298AC288005C86A5 /* AbstractTimer+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B177298AC234005C86A5 /* AbstractTimer+CoreDataProperties.swift */; };
C4F8B19D298AC288005C86A5 /* AbstractTimer+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B176298AC234005C86A5 /* AbstractTimer+CoreDataClass.swift */; };
C4F8B1A0298AC288005C86A5 /* Activity+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4F8B179298AC234005C86A5 /* Activity+CoreDataProperties.swift */; };
@ -372,6 +372,7 @@
C415D3FC29C37AA40037B215 /* QP01 0118 Riparian Zone thrush.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = "QP01 0118 Riparian Zone thrush.wav"; sourceTree = "<group>"; };
C418A14F298428CB00C22230 /* LeCountdown.0.1.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = LeCountdown.0.1.xcdatamodel; sourceTree = "<group>"; };
C4286E952A14EC4E0070D075 /* AppError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppError.swift; sourceTree = "<group>"; };
C4286E9F2A1502FD0070D075 /* Stopwatch+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Stopwatch+CoreDataClass.swift"; sourceTree = "<group>"; };
C42E96FA29E59E72005B1B8C /* BackgroundBlurView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundBlurView.swift; sourceTree = "<group>"; };
C42E96FC29E5B06D005B1B8C /* ActivityCalendarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityCalendarView.swift; sourceTree = "<group>"; };
C42E970129E6B32B005B1B8C /* CalendarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarView.swift; sourceTree = "<group>"; };
@ -507,7 +508,6 @@
C4F8B16E298AC234005C86A5 /* Record+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Record+CoreDataClass.swift"; sourceTree = "<group>"; };
C4F8B16F298AC234005C86A5 /* Record+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Record+CoreDataProperties.swift"; sourceTree = "<group>"; };
C4F8B170298AC234005C86A5 /* Alarm+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Alarm+CoreDataClass.swift"; sourceTree = "<group>"; };
C4F8B174298AC234005C86A5 /* Stopwatch+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Stopwatch+CoreDataClass.swift"; sourceTree = "<group>"; };
C4F8B176298AC234005C86A5 /* AbstractTimer+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AbstractTimer+CoreDataClass.swift"; sourceTree = "<group>"; };
C4F8B177298AC234005C86A5 /* AbstractTimer+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AbstractTimer+CoreDataProperties.swift"; sourceTree = "<group>"; };
C4F8B178298AC234005C86A5 /* Activity+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Activity+CoreDataClass.swift"; sourceTree = "<group>"; };
@ -900,7 +900,7 @@
C4BA2B47299FCE0C00CB4FBA /* IntervalGroup+CoreDataProperties.swift */,
C4F8B16E298AC234005C86A5 /* Record+CoreDataClass.swift */,
C4F8B16F298AC234005C86A5 /* Record+CoreDataProperties.swift */,
C4F8B174298AC234005C86A5 /* Stopwatch+CoreDataClass.swift */,
C4286E9F2A1502FD0070D075 /* Stopwatch+CoreDataClass.swift */,
C4BA2B48299FCE0C00CB4FBA /* Stopwatch+CoreDataProperties.swift */,
);
path = Generation;
@ -1255,6 +1255,7 @@
C445FA922987CC8A0054D761 /* Sound.swift in Sources */,
C4F8B1D0298BF2E2005C86A5 /* DialView.swift in Sources */,
C4BA2B11299BE61E00CB4FBA /* IntervalGroup+CoreDataClass.swift in Sources */,
C4286EA12A1502FD0070D075 /* Stopwatch+CoreDataClass.swift in Sources */,
C4BA2AFD299A3A3700CB4FBA /* AppleMusicPlayer.swift in Sources */,
C4BA2B3A299F838000CB4FBA /* Model+SharedExtensions.swift in Sources */,
C4BA2AF32996A11900CB4FBA /* AbstractSoundTimer+CoreDataProperties.swift in Sources */,
@ -1279,7 +1280,6 @@
C4F8B169298AA236005C86A5 /* StopwatchFormView.swift in Sources */,
C4F8B1BD298AC8DE005C86A5 /* AlarmDialView.swift in Sources */,
C4F8B1532987FE6F005C86A5 /* LaunchWidgetLiveActivity.swift in Sources */,
C4F8B182298AC234005C86A5 /* Stopwatch+CoreDataClass.swift in Sources */,
C4BA2ADB299549BC00CB4FBA /* TimerModel.swift in Sources */,
C4BA2B6529A3C37D00CB4FBA /* Filter.swift in Sources */,
C4F8B16B298AA240005C86A5 /* NewStopwatchView.swift in Sources */,
@ -1372,6 +1372,7 @@
C473C31929A926F50056B38A /* LaunchWidget.intentdefinition in Sources */,
C4BA2B5C299FFAB000CB4FBA /* Logger.swift in Sources */,
C473C2FA29A8DC1E0056B38A /* LaunchWidgetAttributes.swift in Sources */,
C4286EA42A1503330070D075 /* Stopwatch+CoreDataClass.swift in Sources */,
C438C7E82981255D00BF3EF9 /* TimeInterval+Extensions.swift in Sources */,
C4BA2B37299F82FF00CB4FBA /* Fakes.swift in Sources */,
C4F8B18F298AC288005C86A5 /* AbstractTimer+CoreDataClass.swift in Sources */,
@ -1389,7 +1390,6 @@
C4F8B1AE298AC451005C86A5 /* Alarm+CoreDataProperties.swift in Sources */,
C4BA2B32299F75DE00CB4FBA /* DefaultView.swift in Sources */,
C48ECC0829DAC45900DE5A66 /* AppGuard.swift in Sources */,
C4F8B18D298AC288005C86A5 /* Stopwatch+CoreDataClass.swift in Sources */,
C438C8182982BFC100BF3EF9 /* Persistence.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -1421,7 +1421,6 @@
C473C2F629A8DB1D0056B38A /* Sound.swift in Sources */,
C4BA2B1B299BE6A100CB4FBA /* Interval+CoreDataProperties.swift in Sources */,
C438C802298132B900BF3EF9 /* LeCountdown.xcdatamodeld in Sources */,
C4F8B19B298AC288005C86A5 /* Stopwatch+CoreDataClass.swift in Sources */,
C4F8B1A0298AC288005C86A5 /* Activity+CoreDataProperties.swift in Sources */,
C42E96FE29E5B5CD005B1B8C /* Filter.swift in Sources */,
C438C81A2982BFF100BF3EF9 /* NSManagedContext+Extensions.swift in Sources */,
@ -1442,6 +1441,7 @@
C473C2F129A8DA0B0056B38A /* Conductor.swift in Sources */,
C4BA2B1E299BE6A100CB4FBA /* Interval+CoreDataClass.swift in Sources */,
C473C2FC29A8DC4B0056B38A /* Date+Extensions.swift in Sources */,
C4286EA32A1503320070D075 /* Stopwatch+CoreDataClass.swift in Sources */,
C473C2F429A8DAE70056B38A /* Model+Extensions.swift in Sources */,
C445FA86298448720054D761 /* CoolPic.swift in Sources */,
C4BA2B4E299FCE0C00CB4FBA /* Stopwatch+CoreDataProperties.swift in Sources */,

@ -2,7 +2,7 @@
// AbstractSoundTimer+CoreDataProperties.swift
// LeCountdown
//
// Created by Laurent Morvillier on 28/03/2023.
// Created by Laurent Morvillier on 17/05/2023.
//
//
@ -17,7 +17,7 @@ extension AbstractSoundTimer {
}
@NSManaged public var confirmationSoundList: String?
@NSManaged public var repeatCount: Int16
@NSManaged public var playableIds: String?
@NSManaged public var repeatCount: Int16
}

@ -2,7 +2,7 @@
// AbstractTimer+CoreDataProperties.swift
// LeCountdown
//
// Created by Laurent Morvillier on 01/02/2023.
// Created by Laurent Morvillier on 17/05/2023.
//
//
@ -16,8 +16,8 @@ extension AbstractTimer {
return NSFetchRequest<AbstractTimer>(entityName: "AbstractTimer")
}
@NSManaged public var order: Int16
@NSManaged public var image: String?
@NSManaged public var order: Int16
@NSManaged public var activity: Activity?
}

@ -2,15 +2,14 @@
// Stopwatch+CoreDataClass.swift
// LeCountdown
//
// Created by Laurent Morvillier on 01/02/2023.
// Created by Laurent Morvillier on 17/05/2023.
//
//
import Foundation
import CoreData
import SwiftUI
@objc(Stopwatch)
public class Stopwatch: AbstractTimer {
public class Stopwatch: AbstractSoundTimer {
}

@ -2,7 +2,7 @@
// Stopwatch+CoreDataProperties.swift
// LeCountdown
//
// Created by Laurent Morvillier on 17/02/2023.
// Created by Laurent Morvillier on 17/05/2023.
//
//

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21513" systemVersion="22A400" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithCloudKit="YES" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21754" systemVersion="22A400" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithCloudKit="YES" userDefinedModelVersionIdentifier="">
<entity name="AbstractSoundTimer" representedClassName="AbstractSoundTimer" isAbstract="YES" parentEntity="AbstractTimer" elementID="soundList" syncable="YES">
<attribute name="confirmationSoundList" optional="YES" attributeType="String"/>
<attribute name="playableIds" optional="YES" attributeType="String"/>

@ -12,9 +12,17 @@ import CoreData
extension AbstractSoundTimer {
var playables: [any Playable] {
if let playableIds {
return playables(idList: self.playableIds)
}
var confirmationPlayables: [any Playable] {
return playables(idList: self.confirmationSoundList)
}
func playables(idList: String?) -> [any Playable] {
if let idList {
var playables: [any Playable] = []
let ids: [String] = playableIds.components(separatedBy: idSeparator)
let ids: [String] = idList.components(separatedBy: idSeparator)
for id in ids {
if let intId = numberFormatter.number(from: id)?.intValue,
let sound = Sound(rawValue: intId) {

@ -76,7 +76,6 @@ struct CountdownFormView : View {
model: self.model,
imageBinding: imageBinding,
repeatCountBinding: repeatCountBinding)
}
}

@ -273,6 +273,7 @@ struct CountdownEditView : View {
}
self.model.soundModel.setPlayables(countdown.playables)
self.model.confirmationSoundModel.setPlayables(countdown.confirmationPlayables)
self.soundRepeatCount = countdown.repeatCount

@ -52,7 +52,8 @@ struct SoundFormView : View {
title: NSLocalizedString("Confirmation Sound", comment: ""))
}.sheet(isPresented: self.$imageSelectionSheetShown) {
ImageSelectionView(showBinding: self.$imageSelectionSheetShown, imageBinding: self.imageBinding)
ImageSelectionView(showBinding: self.$imageSelectionSheetShown,
imageBinding: self.imageBinding)
}
}

@ -57,7 +57,8 @@ struct StopwatchEditView: View {
@State var error: Error? = nil
@State var _isAdding: Bool = false
@State var _hasLoaded = false
@Environment(\.isPresented) var envIsPresented
var tabSelection: Binding<Int>? = nil
@ -139,76 +140,26 @@ struct StopwatchEditView: View {
}
// MARK: - Bindings
// func playlistBinding(playlist: Playlist) -> Binding<Bool> {
// Binding<Bool>(
// get: { self.playlists.contains(playlist) },
// set: { self._playlistChange(playlist, selected: $0) }
// )
// }
//
// fileprivate func _playlistChange(_ playlist: Playlist, selected: Bool) {
//
// print("_playlistChange")
//
// let sounds: [Sound] = SoundCatalog.main.sounds(for: playlist)
// if selected {
// self.playlists.insert(playlist)
// self.sounds.formUnion(sounds)
// } else {
// self.playlists.remove(playlist)
// self.sounds.formIntersection(sounds)
// }
// }
//
// func soundBinding(sound: Sound) -> Binding<Bool> {
// Binding<Bool>(
// get: { self.sounds.contains(sound) },
// set: { self._soundChange(sound, selected: $0) }
// )
// }
//
// fileprivate func _soundChange(_ sound: Sound, selected: Bool) {
//
// print("_soundChange")
//
// if selected {
// self.sounds.insert(sound)
// } else {
// self.sounds.remove(sound)
// }
//
// // 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)
// } else {
// self.playlists.remove(playlist)
// }
//
// }
// MARK: - Business
fileprivate func _onAppear() {
self._isAdding = (self.stopwatch == nil)
if let stopwatch {
if let stopwatch, !self._hasLoaded {
if let name = stopwatch.activity?.name, !name.isEmpty {
self.nameString = name
}
// if let sound = Sound(rawValue: Int(stopwatch.sound)) {
// self.sound = sound
// }
self.model.soundModel.setPlayables(stopwatch.playables)
self.model.confirmationSoundModel.setPlayables(stopwatch.confirmationPlayables)
if let image = stopwatch.image, let coolpic = CoolPic(rawValue: image) {
self.image = coolpic
}
self._hasLoaded = true
}
}
@ -237,6 +188,11 @@ struct StopwatchEditView: View {
sw.order = max
}
sw.playableIds = self.model.soundModel.playableIds
sw.confirmationSoundList = self.model.confirmationSoundModel.playableIds
// sw.setConfirmationSounds(self.model.confirmationSoundModel.sounds)
// if self._isAdding {
// let max = self.countdowns.map { $0.order }.max() ?? 0

@ -21,8 +21,6 @@ struct StopwatchFormView: View {
@EnvironmentObject var model: TimerModel
// var textFieldIsFocused: FocusState<Bool>.Binding
var body: some View {
Form {

Loading…
Cancel
Save