parent
6137196be7
commit
7797796901
@ -0,0 +1,22 @@ |
|||||||
|
// |
||||||
|
// LiveData.swift |
||||||
|
// LeCountdown |
||||||
|
// |
||||||
|
// Created by Laurent Morvillier on 03/02/2023. |
||||||
|
// |
||||||
|
|
||||||
|
import Foundation |
||||||
|
import CoreData |
||||||
|
|
||||||
|
struct LiveTimer: Identifiable, Comparable { |
||||||
|
var id: String |
||||||
|
var date: Date |
||||||
|
|
||||||
|
static func < (lhs: LiveTimer, rhs: LiveTimer) -> Bool { |
||||||
|
return lhs.date < rhs.date |
||||||
|
} |
||||||
|
|
||||||
|
func timer(context: NSManagedObjectContext) -> AbstractTimer? { |
||||||
|
return context.object(stringId: self.id) as? AbstractTimer |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,70 @@ |
|||||||
|
// |
||||||
|
// LiveTimerView.swift |
||||||
|
// LeCountdown |
||||||
|
// |
||||||
|
// Created by Laurent Morvillier on 03/02/2023. |
||||||
|
// |
||||||
|
|
||||||
|
import SwiftUI |
||||||
|
|
||||||
|
struct LiveTimerView: View { |
||||||
|
|
||||||
|
@Environment(\.managedObjectContext) private var viewContext |
||||||
|
|
||||||
|
@EnvironmentObject var conductor: Conductor |
||||||
|
|
||||||
|
var body: some View { |
||||||
|
LazyVStack { |
||||||
|
ForEach(conductor.liveTimers) { liveTimer in |
||||||
|
|
||||||
|
let timer = liveTimer.timer(context: self.viewContext) |
||||||
|
|
||||||
|
HStack { |
||||||
|
Text(timer?.displayName.uppercased() ?? "missing") |
||||||
|
Spacer() |
||||||
|
Text(liveTimer.date, style: .timer) |
||||||
|
Spacer() |
||||||
|
Button { |
||||||
|
self._stopTimer(timer) |
||||||
|
} label: { |
||||||
|
Text("STOP") |
||||||
|
.padding(8.0) |
||||||
|
.foregroundColor(.red) |
||||||
|
.background(.white) |
||||||
|
.fontWeight(.semibold) |
||||||
|
.cornerRadius(8.0) |
||||||
|
}//.buttonStyle(.bordered).tint(.red) |
||||||
|
|
||||||
|
} |
||||||
|
.padding() |
||||||
|
.frame(height: 55.0) |
||||||
|
.foregroundColor(.white) |
||||||
|
.monospaced() |
||||||
|
.background(.cyan) |
||||||
|
.cornerRadius(16.0) |
||||||
|
} |
||||||
|
}.padding(8.0) |
||||||
|
} |
||||||
|
|
||||||
|
fileprivate func _stopTimer(_ timer: AbstractTimer?) { |
||||||
|
|
||||||
|
guard let timer else { |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
TimerRouter.stopTimer(timer: timer) |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
struct LiveTimerView_Previews: PreviewProvider { |
||||||
|
|
||||||
|
init() { |
||||||
|
Conductor.maestro.currentCountdowns["fef"] = DateInterval(start: Date(), end: Date()) |
||||||
|
} |
||||||
|
|
||||||
|
static var previews: some View { |
||||||
|
LiveTimerView().environmentObject(Conductor.maestro) |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue