diff --git a/LeCountdown.xcodeproj/project.pbxproj b/LeCountdown.xcodeproj/project.pbxproj index ec0efb0..fd99742 100644 --- a/LeCountdown.xcodeproj/project.pbxproj +++ b/LeCountdown.xcodeproj/project.pbxproj @@ -41,6 +41,7 @@ C438C8012981327600BF3EF9 /* Persistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4060DC8297AE73D003FAB80 /* Persistence.swift */; }; C438C802298132B900BF3EF9 /* LeCountdown.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = C4060DCA297AE73D003FAB80 /* LeCountdown.xcdatamodeld */; }; C438C80529813FB400BF3EF9 /* TimeInterval+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4060DF4297AE9A7003FAB80 /* TimeInterval+Extensions.swift */; }; + C438C807298195E600BF3EF9 /* Countdown+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C438C806298195E600BF3EF9 /* Countdown+Extension.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -125,6 +126,7 @@ C438C7FE2981300500BF3EF9 /* IntentDataProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntentDataProvider.swift; sourceTree = ""; }; C438C80329813B2500BF3EF9 /* LaunchIntents.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = LaunchIntents.entitlements; sourceTree = ""; }; C438C80429813B3100BF3EF9 /* LeCountdown.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = LeCountdown.entitlements; sourceTree = ""; }; + C438C806298195E600BF3EF9 /* Countdown+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Countdown+Extension.swift"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -211,6 +213,7 @@ C4060DCD297AE73D003FAB80 /* Info.plist */, C4060DCA297AE73D003FAB80 /* LeCountdown.xcdatamodeld */, C4060DC5297AE73D003FAB80 /* Preview Content */, + C438C806298195E600BF3EF9 /* Countdown+Extension.swift */, ); path = LeCountdown; sourceTree = ""; @@ -465,6 +468,7 @@ buildActionMask = 2147483647; files = ( C4060DC9297AE73D003FAB80 /* Persistence.swift in Sources */, + C438C807298195E600BF3EF9 /* Countdown+Extension.swift in Sources */, C438C7FF2981300500BF3EF9 /* IntentDataProvider.swift in Sources */, C4060DC2297AE73B003FAB80 /* ContentView.swift in Sources */, C438C7C12980228B00BF3EF9 /* CountdownScheduler.swift in Sources */, diff --git a/LeCountdown/ContentView.swift b/LeCountdown/ContentView.swift index 7779e17..88479de 100644 --- a/LeCountdown/ContentView.swift +++ b/LeCountdown/ContentView.swift @@ -66,12 +66,13 @@ struct ContentView: View { Button { self._launchCountdown(countdown) } label: { + CountdownLiveView(countdown: countdown) .environmentObject(AppEnvironment.sun) .aspectRatio(contentMode: .fill) .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity) .aspectRatio(1, contentMode: .fit) - .background(Color(red: 0.9, green: 0.95, blue: 1.0)) + .background(countdown.colorForStatus) .cornerRadius(40.0) } // Text("ORder = \(countdown.order)") diff --git a/LeCountdown/Countdown+Extension.swift b/LeCountdown/Countdown+Extension.swift new file mode 100644 index 0000000..4e3de59 --- /dev/null +++ b/LeCountdown/Countdown+Extension.swift @@ -0,0 +1,29 @@ +// +// Countdown+Extension.swift +// LeCountdown +// +// Created by Laurent Morvillier on 25/01/2023. +// + +import Foundation +import SwiftUI + +extension Countdown { + + var endDate: Date? { + return AppEnvironment.sun.notificationDates[self.stringId] + } + + var isLive: Bool { + return endDate != nil + } + + var colorForStatus: Color { + if isLive { + return Color(red: 0.9, green: 1.0, blue: 0.95) + } else { + return Color(red: 0.9, green: 0.95, blue: 1.0) + } + } + +}