forked from firka/firka
Several watch UI and sync improvements: clamp CountdownRing values and use clamped values for progress/color/display; add optional backgroundColor to FirkaCard and refactor HomeView to use lessonTitleWithStatus, lessonCardBackgroundColor and improved break time calculation and refresh handling (onChange of lastUpdated). TimetableView now shows status icons/colors via helper methods. DataStore now returns a localized "time_now" for recent updates. WatchSessionManager handles Flutter channel/unready states by serving shared language state when available and avoids empty language replies. Dart fixes: await initLang in settings, return null from WatchSyncHelper when uninitialized, and attempt to publish language to watch after initialization in main.
65 lines
1.8 KiB
Swift
65 lines
1.8 KiB
Swift
import SwiftUI
|
|
|
|
struct CountdownRing: View {
|
|
let totalMinutes: Int
|
|
let remainingMinutes: Int
|
|
let label: String
|
|
var size: CGFloat = 80
|
|
var lineWidth: CGFloat = 8
|
|
var displayOffset: Int = 0 // Add to displayed minutes (e.g., +1)
|
|
|
|
private var clampedRemainingMinutes: Int {
|
|
guard totalMinutes > 0 else { return 0 }
|
|
return max(0, min(remainingMinutes, totalMinutes))
|
|
}
|
|
|
|
var progress: Double {
|
|
guard totalMinutes > 0 else { return 0 }
|
|
return Double(totalMinutes - clampedRemainingMinutes) / Double(totalMinutes)
|
|
}
|
|
|
|
var displayedMinutes: Int {
|
|
max(0, remainingMinutes + displayOffset)
|
|
}
|
|
|
|
var ringColor: Color {
|
|
if clampedRemainingMinutes < 5 { return .red }
|
|
if clampedRemainingMinutes < 10 { return .yellow }
|
|
return .green
|
|
}
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
Circle()
|
|
.stroke(Color(white: 0.2), lineWidth: lineWidth)
|
|
|
|
Circle()
|
|
.trim(from: 0, to: progress)
|
|
.stroke(ringColor, style: StrokeStyle(lineWidth: lineWidth, lineCap: .round))
|
|
.rotationEffect(.degrees(-90))
|
|
.animation(.easeInOut, value: progress)
|
|
|
|
VStack(spacing: 1) {
|
|
Text("\(displayedMinutes)")
|
|
.font(size > 60 ? .title2 : .headline)
|
|
.fontWeight(.bold)
|
|
Text(label)
|
|
.font(.caption2)
|
|
.foregroundColor(.secondary)
|
|
}
|
|
}
|
|
.frame(width: size, height: size)
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
VStack(spacing: 20) {
|
|
CountdownRing(totalMinutes: 45, remainingMinutes: 30, label: "min")
|
|
|
|
CountdownRing(totalMinutes: 45, remainingMinutes: 8, label: "min")
|
|
|
|
CountdownRing(totalMinutes: 45, remainingMinutes: 3, label: "min")
|
|
}
|
|
.padding()
|
|
}
|