widgets: add 'This Year' mode to Progress Dots (KC-53)

The Progress Dots lock-screen widget already supports Day/Week/Month via its
configuration picker — no code needed for those. Year was the only mode
missing. Added ProgressDotMode.year, a matching provider branch
(Calendar.dateInterval(of: .year)), and yearTitle(for:), mirroring the
existing day/week/month pattern exactly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
kutesir
2026-07-08 22:59:23 +03:00
committed by kutesir
parent 709eee2579
commit 7bb37d1995
2 changed files with 44 additions and 0 deletions

View File

@@ -40,6 +40,7 @@ enum ProgressDotMode: String, AppEnum {
case day
case week
case month
case year
case customEvent
static var typeDisplayRepresentation: TypeDisplayRepresentation = "Progress Mode"
@@ -47,6 +48,7 @@ enum ProgressDotMode: String, AppEnum {
.day: "This Day",
.week: "This Week",
.month: "This Month",
.year: "This Year",
.customEvent: "Custom Event",
]
}
@@ -115,6 +117,13 @@ struct ProgressDotProvider: AppIntentTimelineProvider {
return ProgressDotEntry(date: date, title: Self.monthTitle(for: date),
progress: Self.progress(now: date, start: start, end: end),
totalDots: 100)
case .year:
let interval = Calendar.current.dateInterval(of: .year, for: date)
let start = interval?.start ?? date
let end = interval?.end ?? date
return ProgressDotEntry(date: date, title: Self.yearTitle(for: date),
progress: Self.progress(now: date, start: start, end: end),
totalDots: 100)
case .customEvent:
guard let event = configuration.event,
let task = loadWidgetTasks().first(where: { $0.id.uuidString == event.id }),
@@ -251,6 +260,12 @@ struct ProgressDotProvider: AppIntentTimelineProvider {
formatter.dateFormat = "MMMM yyyy"
return formatter.string(from: date)
}
private static func yearTitle(for date: Date) -> String {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy"
return formatter.string(from: date)
}
}
struct DayProgressWidget: Widget {