krz/daybyday

iOS learning games for young children: days, months, seasons, numbers, letters, animals and more. education ios kids swift https://krz.sh/apps/daybyday/

Commit 221c7466ab

221c7466ab4c6205e8dfc420ff3024311d7a263f

parent: edfb9a609e

Unsigned

cmc <hello@cleberg.net> · 2026-10-17 01:30 UTC

Part 5: Today routine and sticker calendar (!7)

Today routine from the home banner: spoken step cards ("Hi, Maya!", birthday line, today/yesterday/tomorrow, day picture, month, season), then the child picks today's weather and gets a weather sticker on a month calendar (browse back through earlier months; Done to leave). Banner shows "Tap for your sticker!" or today's sticker. Parents set day pictures per child (swim, school, grandma, …) in the profile editor; they appear on day cards and in the routine. Day cards restyled to flat fills that pass 3:1.

Data: Sticker and DayPicture are new SwiftData entities referencing the child by id, so Profile is unchanged and stores from earlier builds open as-is (tested by reopening an old-schema store). All app dates now use one Gregorian calendar regardless of the device calendar setting. 166 tests.

Art review: nothing blocking; suggestions taken (date kept on stickered days, clearer today ring, bigger banner sticker and sticker glyphs, clearer grandma/dance icons).

Deferred minors: the editor's day-picture "loaded" check uses an empty dictionary; calendar-cell speech isn't cancelled when the routine closes.

Closes #5

Layout: unified · split

DayByDay/DayCard.swift +26 −13
@@ -6,10 +6,12 @@
66import SwiftUI
77
88/// A single large, colorful card representing one day of the week.
9/// Tapping the card plays a bounce animation and speaks the day name aloud.
9/// Tapping the card plays a bounce animation and speaks the day name aloud,
10/// plus the child's day picture when there is one ("It's swim day!").
1011struct DayCard: View {
1112 let day: DayOfWeek
1213 var isHighlighted = false
14 var picture: DayPictureKind? = nil
1315 @State private var isTapped = false
1416
1517 private var cardScale: CGFloat {
@@ -21,7 +23,7 @@ struct DayCard: View {
2123 var body: some View {
2224 ZStack {
2325 RoundedRectangle(cornerRadius: 32, style: .continuous)
24 .fill(day.color.gradient)
26 .fill(day.color)
2527 .shadow(color: day.color.opacity(0.4), radius: 8, y: 4)
2628
2729 VStack(spacing: 16) {
@@ -35,6 +37,17 @@ struct DayCard: View {
3537 .foregroundStyle(.white)
3638 }
3739 }
40 .overlay(alignment: .topTrailing) {
41 if let picture {
42 Image(systemName: picture.symbol)
43 .font(.system(size: 30, weight: .bold))
44 .foregroundStyle(day.color)
45 .frame(width: 60, height: 60)
46 .background(Circle().fill(.white))
47 .padding(14)
48 .accessibilityHidden(true)
49 }
50 }
3851 .overlay {
3952 if isHighlighted {
4053 RoundedRectangle(cornerRadius: 32, style: .continuous)
@@ -48,12 +61,12 @@ struct DayCard: View {
4861 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
4962 .onTapGesture {
5063 isTapped = true
51 SpeechSynthesizer.shared.speak(day.name)
64 CardVoice.shared.say(picture.map { "\(day.name). It's \($0.name)!" } ?? day.name, after: nil)
5265 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
5366 isTapped = false
5467 }
5568 }
56 .accessibilityLabel(day.name)
69 .accessibilityLabel(picture.map { "\(day.name), \($0.name)" } ?? day.name)
5770 .accessibilityAddTraits(.isButton)
5871 }
5972}
@@ -68,7 +81,7 @@ nonisolated enum DayOfWeek: Int, CaseIterable, Identifiable {
6881 /// The day of the week for today's date.
6982 static var current: DayOfWeek {
7083 // Calendar weekday: 1 = Sunday, 7 = Saturday
71 let weekday = Calendar.current.component(.weekday, from: Date())
84 let weekday = AppCalendar.current.component(.weekday, from: Date())
7285 return DayOfWeek(rawValue: weekday - 1)!
7386 }
7487
@@ -98,16 +111,16 @@ nonisolated enum DayOfWeek: Int, CaseIterable, Identifiable {
98111 }
99112 }
100113
101 /// Bright, child-friendly colour for each card.
114 /// A color per day, each at least 3:1 against the white icon and name.
102115 var color: Color {
103116 switch self {
104 case .sunday: Color(red: 1.0, green: 0.6, blue: 0.2) // orange
105 case .monday: Color(red: 0.35, green: 0.5, blue: 0.9) // blue
106 case .tuesday: Color(red: 0.9, green: 0.3, blue: 0.4) // red-pink
107 case .wednesday: Color(red: 0.3, green: 0.75, blue: 0.45) // green
108 case .thursday: Color(red: 0.55, green: 0.4, blue: 0.9) // purple
109 case .friday: Color(red: 1.0, green: 0.8, blue: 0.2) // yellow
110 case .saturday: Color(red: 0.2, green: 0.8, blue: 0.8) // teal
117 case .sunday: Color(red: 0.80, green: 0.42, blue: 0.08) // orange
118 case .monday: Color(red: 0.25, green: 0.42, blue: 0.85) // blue
119 case .tuesday: Color(red: 0.84, green: 0.22, blue: 0.34) // red-pink
120 case .wednesday: Color(red: 0.18, green: 0.56, blue: 0.28) // green
121 case .thursday: Color(red: 0.55, green: 0.4, blue: 0.85) // purple
122 case .friday: Color(red: 0.66, green: 0.50, blue: 0.0) // mustard
123 case .saturday: Color(red: 0.0, green: 0.53, blue: 0.56) // teal
111124 }
112125 }
113126}
DayByDay/DaysOfWeekView.swift +10 −1
@@ -3,11 +3,14 @@
33// DayByDay
44//
55
6import SwiftData
67import SwiftUI
78
89/// Displays all seven days of the week as large, tappable cards in a scrollable grid.
910/// Adapts between 1 and 2 columns depending on available width.
1011struct DaysOfWeekView: View {
12 @Environment(ProfileSession.self) private var session
13
1114 private let columns = [
1215 GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24)
1316 ]
@@ -16,15 +19,21 @@ struct DaysOfWeekView: View {
1619 ScrollView {
1720 LazyVGrid(columns: columns, spacing: 24) {
1821 ForEach(DayOfWeek.allCases) { day in
19 DayCard(day: day, isHighlighted: day == .current)
22 DayCard(day: day, isHighlighted: day == .current, picture: picture(on: day))
2023 .frame(height: 200)
2124 }
2225 }
2326 .padding(32)
2427 }
28 .onDisappear { CardVoice.shared.cancel() }
29 }
30
31 private func picture(on day: DayOfWeek) -> DayPictureKind? {
32 session.current.flatMap { session.store.picture(on: day, for: $0) }
2533 }
2634}
2735
2836#Preview {
2937 DaysOfWeekView()
38 .environment(ProfileSession(store: ProfileStore(context: ProfileStore.makeContainer(inMemory: true).mainContext)))
3039}
DayByDay/Home/HomeView.swift +1 −1
@@ -21,7 +21,7 @@ struct HomeView: View {
2121 ScrollView {
2222 VStack(spacing: 24) {
2323 NavigationLink {
24 TodayView().navigationTitle(Category.today.label)
24 TodayRoutineView().navigationTitle(Category.today.label)
2525 } label: {
2626 TodayBanner()
2727 }
DayByDay/Home/TodayBanner.swift +14
@@ -7,6 +7,10 @@ import SwiftUI
77
88/// The mascot and today's day and date, at the top of home.
99struct TodayBanner: View {
10 @Environment(ProfileSession.self) private var session
11 /// Today's sticker, read when home appears.
12 @State private var sticker: LearnWeather?
13
1014 static let gradientColors: [Color] = [Color(red: 0.84, green: 0.40, blue: 0.05), Color(red: 0.80, green: 0.45, blue: 0.0)]
1115
1216 var body: some View {
@@ -19,6 +23,12 @@ struct TodayBanner: View {
1923 Text(Date.now.formatted(.dateTime.month(.wide).day()))
2024 .font(.system(size: 22, weight: .semibold, design: .rounded))
2125 .opacity(0.9)
26 if let sticker {
27 StickerBadge(weather: sticker).frame(width: 56, height: 56)
28 } else {
29 Text("Tap for your sticker!")
30 .font(.system(size: 18, weight: .bold, design: .rounded))
31 }
2232 }
2333 .foregroundStyle(.white)
2434 Spacer(minLength: 0)
@@ -32,5 +42,9 @@ struct TodayBanner: View {
3242 )
3343 .accessibilityElement(children: .combine)
3444 .accessibilityAddTraits(.isButton)
45 .onAppear {
46 let today = AppCalendar.current.dateComponents([.year, .month, .day], from: .now)
47 sticker = session.current.flatMap { session.store.sticker(for: $0, on: today)?.weather }
48 }
3549 }
3650}
DayByDay/MonthCard.swift +1 −1
@@ -69,7 +69,7 @@ nonisolated enum MonthOfYear: Int, CaseIterable, Identifiable {
6969 /// The month for today's date.
7070 static var current: MonthOfYear {
7171 // Calendar month: 1 = January, 12 = December
72 let month = Calendar.current.component(.month, from: Date())
72 let month = AppCalendar.current.component(.month, from: Date())
7373 return MonthOfYear(rawValue: month - 1)!
7474 }
7575
DayByDay/Profiles/DayPicture.swift added +45
@@ -0,0 +1,45 @@
1//
2// DayPicture.swift
3// DayByDay
4//
5
6import Foundation
7import SwiftData
8
9/// Something special a child does on a weekday, set by a grown-up.
10nonisolated enum DayPictureKind: String, CaseIterable, Identifiable {
11 case swim, school, grandma, park, music, soccer, library, dance
12
13 var id: String { rawValue }
14
15 var name: String { "\(rawValue) day" }
16
17 var symbol: String {
18 switch self {
19 case .swim: "figure.pool.swim"
20 case .school: "backpack.fill"
21 case .grandma: "house.fill"
22 case .park: "tree.fill"
23 case .music: "music.note"
24 case .soccer: "soccerball"
25 case .library: "books.vertical.fill"
26 case .dance: "figure.socialdance"
27 }
28 }
29}
30
31/// A day picture for one child and weekday. Points at its child by id.
32@Model
33final class DayPicture {
34 var profileID: UUID
35 var weekdayRaw: Int
36 var kindRaw: String
37
38 init(profileID: UUID, weekday: DayOfWeek, kind: DayPictureKind) {
39 self.profileID = profileID
40 self.weekdayRaw = weekday.rawValue
41 self.kindRaw = kind.rawValue
42 }
43
44 var kind: DayPictureKind? { DayPictureKind(rawValue: kindRaw) }
45}
DayByDay/Profiles/ProfileEditorView.swift +32 −2
@@ -18,6 +18,7 @@ struct ProfileEditorView: View {
1818 @State private var month = 1
1919 @State private var day = 1
2020 @State private var error: ProfileError?
21 @State private var pictures: [DayOfWeek: DayPictureKind] = [:]
2122
2223 private let avatarColumns = [GridItem(.adaptive(minimum: 64), spacing: 12)]
2324
@@ -75,12 +76,30 @@ struct ProfileEditorView: View {
7576 .padding(.vertical, 6)
7677 }
7778
79 Section {
80 ForEach(DayOfWeek.allCases) { day in
81 Picker(day.name, selection: Binding(
82 get: { pictures[day] },
83 set: { pictures[day] = $0 }
84 )) {
85 Text("None").tag(DayPictureKind?.none)
86 ForEach(DayPictureKind.allCases) { kind in
87 Label(kind.name.capitalized, systemImage: kind.symbol).tag(DayPictureKind?.some(kind))
88 }
89 }
90 }
91 } header: {
92 Text("Day pictures")
93 } footer: {
94 Text("Shown on that day's card and said in the Today routine, e.g. \"Today is swim day!\"")
95 }
96
7897 Section("Birthday") {
7998 Toggle("Add birthday", isOn: $hasBirthday)
8099 if hasBirthday {
81100 Picker("Month", selection: $month) {
82101 ForEach(1...12, id: \.self) { m in
83 Text(Calendar.current.monthSymbols[m - 1]).tag(m)
102 Text(AppCalendar.current.monthSymbols[m - 1]).tag(m)
84103 }
85104 }
86105 Picker("Day", selection: $day) {
@@ -97,6 +116,12 @@ struct ProfileEditorView: View {
97116 Button("Save", action: save)
98117 }
99118 }
119 .onAppear {
120 guard let profile, pictures.isEmpty else { return }
121 for day in DayOfWeek.allCases {
122 pictures[day] = session.store.picture(on: day, for: profile)
123 }
124 }
100125 .onChange(of: month) {
101126 day = min(day, ProfileStore.daysInMonth[month - 1])
102127 }
@@ -105,10 +130,15 @@ struct ProfileEditorView: View {
105130 private func save() {
106131 let birthday = hasBirthday ? (month: month, day: day) : nil
107132 do {
133 let saved: Profile
108134 if let profile {
109135 try session.store.update(profile, name: name, avatar: avatar, color: color, birthday: birthday)
136 saved = profile
110137 } else {
111 try session.store.create(name: name, avatar: avatar, color: color, birthday: birthday)
138 saved = try session.store.create(name: name, avatar: avatar, color: color, birthday: birthday)
139 }
140 for day in DayOfWeek.allCases {
141 session.store.setPicture(pictures[day], on: day, for: saved)
112142 }
113143 session.profilesChanged()
114144 dismiss()
DayByDay/Profiles/ProfileStore.swift +53 −1
@@ -18,9 +18,13 @@ final class ProfileStore {
1818 self.context = context
1919 }
2020
21 /// Stickers and day pictures were added after the first release as new
22 /// entities only, so earlier stores migrate without a versioned schema.
23 static let modelTypes: [any PersistentModel.Type] = [Profile.self, AnswerRecord.self, Sticker.self, DayPicture.self]
24
2125 static func makeContainer(inMemory: Bool) -> ModelContainer {
2226 let config = ModelConfiguration(isStoredInMemoryOnly: inMemory)
23 return try! ModelContainer(for: Profile.self, AnswerRecord.self, configurations: config)
27 return try! ModelContainer(for: Schema(modelTypes), configurations: config)
2428 }
2529
2630 func all() -> [Profile] {
@@ -51,6 +55,9 @@ final class ProfileStore {
5155 }
5256
5357 func delete(_ profile: Profile) {
58 let id = profile.id
59 try? context.delete(model: Sticker.self, where: #Predicate { $0.profileID == id })
60 try? context.delete(model: DayPicture.self, where: #Predicate { $0.profileID == id })
5461 context.delete(profile)
5562 try? context.save()
5663 }
@@ -85,4 +92,49 @@ final class ProfileStore {
8592 (1...daysInMonth[birthday.month - 1]).contains(birthday.day)
8693 else { throw ProfileError.invalidBirthday }
8794 }
95
96 // MARK: - Stickers
97
98 /// Adds the day's sticker, or changes its weather if there is one.
99 func addSticker(for profile: Profile, on date: DateComponents, weather: LearnWeather) {
100 if let existing = sticker(for: profile, on: date) {
101 existing.weatherRaw = weather.rawValue
102 } else {
103 context.insert(Sticker(profileID: profile.id, year: date.year!, month: date.month!,
104 day: date.day!, weather: weather))
105 }
106 try? context.save()
107 }
108
109 func sticker(for profile: Profile, on date: DateComponents) -> Sticker? {
110 let id = profile.id, y = date.year!, m = date.month!, d = date.day!
111 let descriptor = FetchDescriptor<Sticker>(predicate: #Predicate {
112 $0.profileID == id && $0.year == y && $0.month == m && $0.day == d
113 })
114 return try? context.fetch(descriptor).first
115 }
116
117 func stickers(for profile: Profile, year: Int, month: Int) -> [Sticker] {
118 let id = profile.id
119 let descriptor = FetchDescriptor<Sticker>(predicate: #Predicate {
120 $0.profileID == id && $0.year == year && $0.month == month
121 }, sortBy: [SortDescriptor(\.day)])
122 return (try? context.fetch(descriptor)) ?? []
123 }
124
125 // MARK: - Day pictures
126
127 /// Sets or, with nil, removes the child's picture for a weekday.
128 func setPicture(_ kind: DayPictureKind?, on weekday: DayOfWeek, for profile: Profile) {
129 let id = profile.id, w = weekday.rawValue
130 try? context.delete(model: DayPicture.self, where: #Predicate { $0.profileID == id && $0.weekdayRaw == w })
131 if let kind { context.insert(DayPicture(profileID: id, weekday: weekday, kind: kind)) }
132 try? context.save()
133 }
134
135 func picture(on weekday: DayOfWeek, for profile: Profile) -> DayPictureKind? {
136 let id = profile.id, w = weekday.rawValue
137 let descriptor = FetchDescriptor<DayPicture>(predicate: #Predicate { $0.profileID == id && $0.weekdayRaw == w })
138 return (try? context.fetch(descriptor).first)?.kind
139 }
88140}
DayByDay/Profiles/Sticker.swift added +30
@@ -0,0 +1,30 @@
1//
2// Sticker.swift
3// DayByDay
4//
5
6import Foundation
7import SwiftData
8
9/// A finished Today routine: one per child per day, showing that day's weather.
10/// Points at its child by id, so the Profile entity stays unchanged.
11@Model
12final class Sticker {
13 var profileID: UUID
14 var year: Int
15 var month: Int
16 var day: Int
17 var weatherRaw: Int
18 var createdAt: Date
19
20 init(profileID: UUID, year: Int, month: Int, day: Int, weather: LearnWeather, createdAt: Date = .now) {
21 self.profileID = profileID
22 self.year = year
23 self.month = month
24 self.day = day
25 self.weatherRaw = weather.rawValue
26 self.createdAt = createdAt
27 }
28
29 var weather: LearnWeather { LearnWeather(rawValue: weatherRaw) ?? .sunny }
30}
DayByDay/SeasonCard.swift +1 −1
@@ -69,7 +69,7 @@ nonisolated enum Season: Int, CaseIterable, Identifiable {
6969 /// Spring: March–May, Summer: June–August,
7070 /// Fall: September–November, Winter: December–February.
7171 static var current: Season {
72 let month = Calendar.current.component(.month, from: Date())
72 let month = AppCalendar.current.component(.month, from: Date())
7373 switch month {
7474 case 3...5: return .spring
7575 case 6...8: return .summer
DayByDay/Today/AppCalendar.swift added +18
@@ -0,0 +1,18 @@
1//
2// AppCalendar.swift
3// DayByDay
4//
5
6import Foundation
7
8/// The calendar for every date the app shows or stores: Gregorian, weeks
9/// starting on Sunday, in the device's time zone, whatever calendar the
10/// device itself is set to.
11nonisolated enum AppCalendar {
12 static var current: Calendar {
13 var calendar = Calendar(identifier: .gregorian)
14 calendar.timeZone = .current
15 calendar.firstWeekday = 1
16 return calendar
17 }
18}
DayByDay/Today/MonthGrid.swift added +40
@@ -0,0 +1,40 @@
1//
2// MonthGrid.swift
3// DayByDay
4//
5
6import Foundation
7
8/// A month laid out in Sunday-first weeks.
9nonisolated struct MonthGrid: Equatable {
10 let year: Int
11 let month: Int
12 /// Empty cells before the 1st.
13 let leadingBlanks: Int
14 let days: Int
15 private let calendar: Calendar
16
17 init(year: Int, month: Int, calendar: Calendar) {
18 self.year = year
19 self.month = month
20 self.calendar = calendar
21 let first = calendar.date(from: DateComponents(year: year, month: month, day: 1))!
22 leadingBlanks = calendar.component(.weekday, from: first) - 1
23 days = calendar.range(of: .day, in: .month, for: first)!.count
24 }
25
26 /// Blanks, then 1 through the last day.
27 var cells: [Int?] { Array(repeating: nil, count: leadingBlanks) + (1...days).map { $0 } }
28
29 /// Whether a later month may be shown: never past `today`'s month.
30 func canGoLater(than today: (year: Int, month: Int)) -> Bool {
31 (year, month) < (today.year, today.month)
32 }
33
34 func shifted(by months: Int) -> MonthGrid {
35 let index = year * 12 + (month - 1) + months
36 return MonthGrid(year: index / 12, month: index % 12 + 1, calendar: calendar)
37 }
38
39 static func == (a: MonthGrid, b: MonthGrid) -> Bool { a.year == b.year && a.month == b.month }
40}
DayByDay/Today/RoutineScript.swift added +46
@@ -0,0 +1,46 @@
1//
2// RoutineScript.swift
3// DayByDay
4//
5
6import Foundation
7
8/// What the Today routine says, line by line, before the weather pick.
9nonisolated struct RoutineScript {
10 struct Line: Equatable {
11 let text: String
12 let symbol: String
13 }
14
15 let lines: [Line]
16
17 init(date: Date, calendar: Calendar, name: String?, birthday: (month: Int, day: Int)?, picture: DayPictureKind?) {
18 func weekday(_ offset: Int) -> DayOfWeek {
19 let day = calendar.date(byAdding: .day, value: offset, to: date)!
20 return DayOfWeek(rawValue: calendar.component(.weekday, from: day) - 1)!
21 }
22 let parts = calendar.dateComponents([.month, .day], from: date)
23 let month = MonthOfYear(rawValue: parts.month! - 1)!
24 let today = weekday(0), yesterday = weekday(-1), tomorrow = weekday(1)
25
26 var lines = [Line(text: name.map { "Hi, \($0)!" } ?? "Hi!", symbol: "sun.max.fill")]
27 if let birthday {
28 if birthday.month == parts.month, birthday.day == parts.day {
29 lines.append(Line(text: "Today is your birthday! Happy birthday!", symbol: "birthday.cake.fill"))
30 } else if birthday.month == parts.month {
31 lines.append(Line(text: "Your birthday is in \(month.name)!", symbol: "gift.fill"))
32 }
33 }
34 lines.append(Line(text: "Today is \(today.name).", symbol: today.symbol))
35 if let picture {
36 lines.append(Line(text: "Today is \(picture.name)!", symbol: picture.symbol))
37 }
38 lines += [
39 Line(text: "Yesterday was \(yesterday.name).", symbol: yesterday.symbol),
40 Line(text: "Tomorrow is \(tomorrow.name).", symbol: tomorrow.symbol),
41 Line(text: "It's \(month.name).", symbol: month.symbol),
42 Line(text: "It's \(month.season.name).", symbol: month.season.symbol),
43 ]
44 self.lines = lines
45 }
46}
DayByDay/Today/StickerCalendarView.swift added +130
@@ -0,0 +1,130 @@
1//
2// StickerCalendarView.swift
3// DayByDay
4//
5
6import SwiftUI
7
8enum StickerStyle {
9 /// White weather symbols sit on this, at least 3:1.
10 static let fill = Category.weather.color
11}
12
13/// A sticker in the weather of that day.
14struct StickerBadge: View {
15 let weather: LearnWeather
16
17 var body: some View {
18 Circle()
19 .fill(StickerStyle.fill)
20 .overlay {
21 Image(systemName: weather.symbol)
22 .resizable()
23 .scaledToFit()
24 .foregroundStyle(.white)
25 .padding(5)
26 }
27 .accessibilityLabel(weather.name)
28 }
29}
30
31/// One month of a child's stickers. Arrows go back through earlier months,
32/// never past the current one.
33struct StickerCalendarView: View {
34 let profile: Profile?
35
36 @Environment(ProfileSession.self) private var session
37 @State private var grid: MonthGrid
38 private let today: DateComponents
39 private let calendar: Calendar
40
41 init(profile: Profile?, calendar: Calendar = AppCalendar.current, now: Date = .now) {
42 self.profile = profile
43 self.calendar = calendar
44 today = calendar.dateComponents([.year, .month, .day], from: now)
45 _grid = State(initialValue: MonthGrid(year: today.year!, month: today.month!, calendar: calendar))
46 }
47
48 private var isCurrentMonth: Bool { grid.year == today.year && grid.month == today.month }
49 private var canGoLater: Bool { grid.canGoLater(than: (year: today.year!, month: today.month!)) }
50 private var monthName: String { MonthOfYear(rawValue: grid.month - 1)!.name }
51
52 private var stickers: [Int: Sticker] {
53 guard let profile else { return [:] }
54 return Dictionary(session.store.stickers(for: profile, year: grid.year, month: grid.month).map { ($0.day, $0) },
55 uniquingKeysWith: { a, _ in a })
56 }
57
58 var body: some View {
59 let stickers = self.stickers
60 VStack(spacing: 16) {
61 HStack {
62 arrow("chevron.left", label: "Earlier month") { grid = grid.shifted(by: -1) }
63 Spacer()
64 Text(verbatim: "\(monthName) \(grid.year)")
65 .font(.system(size: 28, weight: .heavy, design: .rounded))
66 Spacer()
67 arrow("chevron.right", label: "Later month") { grid = grid.shifted(by: 1) }
68 .disabled(!canGoLater)
69 .opacity(canGoLater ? 1 : 0.3)
70 }
71 LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 6), count: 7), spacing: 6) {
72 ForEach(Array(["S", "M", "T", "W", "T", "F", "S"].enumerated()), id: \.offset) { _, d in
73 Text(d).font(.system(size: 16, weight: .bold, design: .rounded)).foregroundStyle(.primary)
74 }
75 ForEach(Array(grid.cells.enumerated()), id: \.offset) { _, day in
76 if let day {
77 cell(day, sticker: stickers[day])
78 } else {
79 Color.clear.frame(height: 48)
80 }
81 }
82 }
83 }
84 .padding(16)
85 }
86
87 private func cell(_ day: Int, sticker: Sticker?) -> some View {
88 let isToday = isCurrentMonth && day == today.day
89 return ZStack {
90 if let sticker {
91 StickerBadge(weather: sticker.weather)
92 .padding(isToday ? 5 : 0)
93 .overlay(alignment: .bottomTrailing) {
94 // Keep the date readable on a stickered day.
95 Text("\(day)")
96 .font(.system(size: 11, weight: .bold, design: .rounded))
97 .padding(3)
98 .background(Circle().fill(Color(.systemBackground)))
99 }
100 } else {
101 Text("\(day)").font(.system(size: 18, weight: .semibold, design: .rounded))
102 }
103 }
104 .frame(height: 48)
105 .frame(maxWidth: .infinity)
106 .overlay {
107 if isToday {
108 Circle().strokeBorder(Color.primary, lineWidth: 4).frame(width: 52, height: 52)
109 }
110 }
111 .contentShape(Rectangle())
112 .onTapGesture {
113 let line = sticker.map { "On \(monthName) \(day), it was \($0.weather.name.lowercased())." }
114 ?? "\(monthName) \(day)."
115 CardVoice.shared.say(line, after: nil)
116 }
117 .accessibilityLabel(sticker.map { "\(monthName) \(day), \($0.weather.name)" } ?? "\(monthName) \(day)")
118 }
119
120 private func arrow(_ symbol: String, label: String, action: @escaping () -> Void) -> some View {
121 Button(action: action) {
122 Image(systemName: symbol)
123 .font(.system(size: 26, weight: .bold))
124 .frame(width: 56, height: 56)
125 .background(Circle().fill(Color(.systemGray6)))
126 }
127 .buttonStyle(.plain)
128 .accessibilityLabel(label)
129 }
130}
DayByDay/Today/TodayRoutineView.swift added +171
@@ -0,0 +1,171 @@
1//
2// TodayRoutineView.swift
3// DayByDay
4//
5
6import SwiftUI
7
8/// The morning routine: a few spoken lines about today, the child picks
9/// today's weather, and a sticker goes on the calendar.
10struct TodayRoutineView: View {
11 static let weathers: [LearnWeather] = [.sunny, .cloudy, .rainy, .snowy, .windy]
12
13 private enum Phase: Equatable { case line(Int), weather, done }
14
15 @Environment(ProfileSession.self) private var session
16 @Environment(\.dismiss) private var dismiss
17 @State private var phase = Phase.line(0)
18 @State private var lines: [RoutineScript.Line] = []
19 @State private var celebrating = false
20 @State private var speechToken = 0
21 /// Bumped when the screen goes away, so pending work does nothing.
22 @State private var generation = 0
23
24 private let columns = [GridItem(.adaptive(minimum: 140, maximum: 220), spacing: 16)]
25
26 var body: some View {
27 ZStack {
28 switch phase {
29 case .line(let i) where i < lines.count:
30 lineCard(lines[i])
31 case .line:
32 Color.clear
33 case .weather:
34 weatherPick
35 case .done:
36 ScrollView {
37 VStack(spacing: 20) {
38 StickerCalendarView(profile: session.current)
39 .frame(maxWidth: 560)
40 .padding(.top, 8)
41 Button { dismiss() } label: {
42 Label("Done", systemImage: "checkmark")
43 .font(.system(size: 28, weight: .bold, design: .rounded))
44 .foregroundStyle(.white)
45 .padding(.horizontal, 44)
46 .padding(.vertical, 20)
47 .background(Capsule().fill(RoundStyle.playAgainFill))
48 }
49 .buttonStyle(.plain)
50 }
51 .padding(.bottom, 24)
52 }
53 }
54 }
55 .overlay { CelebrationOverlay(isActive: celebrating) }
56 .onAppear {
57 if lines.isEmpty { lines = script().lines }
58 speakCurrent()
59 }
60 .onDisappear {
61 generation += 1
62 speechToken += 1
63 SpeechSynthesizer.shared.stop()
64 }
65 }
66
67 private func script() -> RoutineScript {
68 let profile = session.current
69 let birthday = profile.flatMap { p in p.birthdayMonth.flatMap { m in p.birthdayDay.map { (month: m, day: $0) } } }
70 return RoutineScript(date: .now, calendar: AppCalendar.current, name: profile?.name, birthday: birthday,
71 picture: profile.flatMap { session.store.picture(on: .current, for: $0) })
72 }
73
74 private func lineCard(_ line: RoutineScript.Line) -> some View {
75 VStack(spacing: 28) {
76 hearAgain
77 VStack(spacing: 20) {
78 Image(systemName: line.symbol)
79 .font(.system(size: 110))
80 .frame(height: 130)
81 Text(line.text)
82 .font(.system(size: 32, weight: .heavy, design: .rounded))
83 .multilineTextAlignment(.center)
84 .minimumScaleFactor(0.6)
85 }
86 .foregroundStyle(.white)
87 .padding(28)
88 .frame(maxWidth: 520, minHeight: 300)
89 .background(RoundedRectangle(cornerRadius: 36, style: .continuous).fill(TodayBanner.gradientColors[0]))
90 .accessibilityElement(children: .combine)
91
92 Button(action: next) {
93 Image(systemName: "arrow.right")
94 .font(.system(size: 40, weight: .heavy))
95 .foregroundStyle(.white)
96 .frame(width: 96, height: 96)
97 .background(Circle().fill(RoundStyle.playAgainFill))
98 }
99 .buttonStyle(.plain)
100 .accessibilityLabel("Next")
101 }
102 .padding(24)
103 }
104
105 private var weatherPick: some View {
106 ScrollView {
107 VStack(spacing: 24) {
108 hearAgain
109 LazyVGrid(columns: columns, spacing: 16) {
110 ForEach(Self.weathers) { weather in
111 Button { pick(weather) } label: {
112 ChoiceTile(item: Category.weather.item(weather)).frame(height: 140)
113 }
114 .buttonStyle(.plain)
115 .accessibilityLabel(weather.name)
116 }
117 }
118 }
119 .padding(24)
120 }
121 }
122
123 private var hearAgain: some View {
124 Button(action: speakCurrent) {
125 Label("Hear it again", systemImage: "speaker.wave.2.fill")
126 .font(.system(size: 22, weight: .bold, design: .rounded))
127 .padding(.horizontal, 24)
128 .padding(.vertical, 14)
129 .background(Capsule().fill(Color(.systemGray6)))
130 }
131 .buttonStyle(.plain)
132 }
133
134 private func next() {
135 guard case .line(let i) = phase else { return }
136 phase = i + 1 < lines.count ? .line(i + 1) : .weather
137 speakCurrent()
138 }
139
140 private func speakCurrent() {
141 switch phase {
142 case .line(let i) where i < lines.count: say(lines[i].text)
143 case .weather: say("What's the weather like today?")
144 default: break
145 }
146 }
147
148 private func pick(_ weather: LearnWeather) {
149 guard phase == .weather else { return }
150 let today = AppCalendar.current.dateComponents([.year, .month, .day], from: .now)
151 if let profile = session.current {
152 session.store.addSticker(for: profile, on: today, weather: weather)
153 }
154 SoundEngine.shared.play(.success)
155 celebrating = true
156 phase = .done
157 say("It's \(weather.name.lowercased()) today! Here's your sticker!", after: RoundStyle.speechDelay)
158 let gen = generation
159 DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
160 if gen == generation { celebrating = false }
161 }
162 }
163
164 private func say(_ text: String, after delay: TimeInterval = 0) {
165 speechToken += 1
166 let token = speechToken, gen = generation
167 DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
168 if token == speechToken, gen == generation { SpeechSynthesizer.shared.speak(text) }
169 }
170 }
171}
DayByDayTests/ContrastTests.swift +8
@@ -68,6 +68,14 @@ struct ContrastTests {
6868 #expect(contrast(SortStyle.binFill, .black, .dark) >= 3)
6969 }
7070
71 @Test(arguments: DayOfWeek.allCases) func dayColorAgainstWhite(_ day: DayOfWeek) {
72 #expect(contrast(day.color, .white, .light) >= 3, "\(day)")
73 }
74
75 @Test func stickerFillAgainstWhite() {
76 #expect(contrast(StickerStyle.fill, .white, .light) >= 3)
77 }
78
7179 @Test func playAgainAgainstWhite() {
7280 #expect(contrast(RoundStyle.playAgainFill, .white, .light) >= 3)
7381 }
DayByDayTests/ReviewExport.swift +12
@@ -57,6 +57,14 @@ struct ReviewExport {
5757 try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
5858 let container = ProfileStore.makeContainer(inMemory: true)
5959 let session = ProfileSession(store: ProfileStore(context: container.mainContext))
60 if let maya = try? session.store.create(name: "Maya", avatar: .cat, color: .pink, birthday: (month: 10, day: 30)) {
61 session.store.setPicture(.swim, on: .friday, for: maya)
62 session.store.setPicture(.school, on: .monday, for: maya)
63 for (d, w) in [(1, LearnWeather.sunny), (2, .cloudy), (5, .rainy), (9, .windy), (12, .snowy), (15, .sunny)] {
64 session.store.addSticker(for: maya, on: DateComponents(year: 2026, month: 10, day: d), weather: w)
65 }
66 session.profilesChanged()
67 }
6068 var rng = SeededGenerator(seed: 1)
6169 var train = SequencePuzzle.weekTrain(using: &rng)
6270 for d in [DayOfWeek.sunday, .monday, .tuesday] { _ = train.place(DayByDay.Category.days.item(d)) }
@@ -75,6 +83,10 @@ struct ReviewExport {
7583 ("moves", AnyView(MovesView())),
7684 ("weather", AnyView(WeatherView())),
7785 ("rain", AnyView(RainOverlay(isActive: true).background(Color(.systemBackground)))),
86 ("days", AnyView(DaysOfWeekView())),
87 ("routine", AnyView(TodayRoutineView())),
88 ("calendar", AnyView(StickerCalendarView(profile: session.current, now: DateComponents(calendar: .current, year: 2026, month: 10, day: 16).date!))),
89 ("banner", AnyView(TodayBanner().padding())),
7890 ("animals", AnyView(AnimalsView())),
7991 ("alphabet", AnyView(AlphabetView())),
8092 ("counting", AnyView(CountingView())),
DayByDayTests/RoutineScriptTests.swift added +115
@@ -0,0 +1,115 @@
1import Foundation
2import Testing
3@testable import DayByDay
4
5struct RoutineScriptTests {
6 static var calendar: Calendar {
7 var c = Calendar(identifier: .gregorian)
8 c.timeZone = TimeZone(identifier: "UTC")!
9 return c
10 }
11
12 func date(_ y: Int, _ m: Int, _ d: Int) -> Date {
13 Self.calendar.date(from: DateComponents(year: y, month: m, day: d, hour: 9))!
14 }
15
16 func script(_ y: Int, _ m: Int, _ d: Int, name: String? = "Maya",
17 birthday: (month: Int, day: Int)? = nil, picture: DayPictureKind? = nil) -> [String] {
18 RoutineScript(date: date(y, m, d), calendar: Self.calendar, name: name,
19 birthday: birthday, picture: picture).lines.map(\.text)
20 }
21
22 @Test func fridayScript() {
23 #expect(script(2026, 10, 16) == [
24 "Hi, Maya!", "Today is Friday.", "Yesterday was Thursday.", "Tomorrow is Saturday.",
25 "It's October.", "It's Fall.",
26 ])
27 #expect(script(2026, 10, 16, name: nil).first == "Hi!")
28 let lines = RoutineScript(date: date(2026, 10, 16), calendar: Self.calendar, name: nil,
29 birthday: nil, picture: nil).lines
30 #expect(lines[1].symbol == DayOfWeek.friday.symbol)
31 #expect(lines[4].symbol == MonthOfYear.october.symbol)
32 #expect(lines[5].symbol == Season.fall.symbol)
33 }
34
35 @Test func birthdayMonthLine() {
36 #expect(script(2026, 10, 16, birthday: (month: 10, day: 30))[1] == "Your birthday is in October!")
37 #expect(!script(2026, 10, 16, birthday: (month: 5, day: 1)).contains { $0.contains("birthday") })
38 }
39
40 @Test func birthdayTodayBeatsMonth() {
41 let lines = script(2026, 10, 16, birthday: (month: 10, day: 16))
42 #expect(lines[1] == "Today is your birthday! Happy birthday!")
43 #expect(!lines.contains("Your birthday is in October!"))
44 }
45
46 @Test func leapBirthday() {
47 #expect(script(2027, 2, 28, birthday: (month: 2, day: 29))[1] == "Your birthday is in February!")
48 #expect(script(2028, 2, 29, birthday: (month: 2, day: 29))[1] == "Today is your birthday! Happy birthday!")
49 #expect(!script(2027, 3, 1, birthday: (month: 2, day: 29)).contains { $0.contains("birthday") })
50 }
51
52 @Test func pictureLine() {
53 let lines = script(2026, 10, 16, picture: .swim)
54 #expect(lines[1] == "Today is Friday.")
55 #expect(lines[2] == "Today is swim day!")
56 }
57
58 @Test func weekWraps() {
59 #expect(script(2026, 10, 18).contains("Yesterday was Saturday."))
60 #expect(script(2026, 10, 18)[1] == "Today is Sunday.")
61 #expect(script(2026, 10, 17).contains("Tomorrow is Sunday."))
62 }
63
64 @Test func monthEnd() {
65 let lines = script(2026, 10, 31)
66 #expect(lines.contains("Tomorrow is Sunday."))
67 #expect(lines.contains("It's October."))
68 }
69
70 /// Dates are always Gregorian, whatever calendar the device uses.
71 @Test func appCalendarIsGregorian() {
72 #expect(AppCalendar.current.identifier == .gregorian)
73 #expect(AppCalendar.current.firstWeekday == 1)
74 #expect(AppCalendar.current.timeZone == .current)
75 }
76
77 @Test func yearEnd() {
78 let lines = script(2027, 1, 1)
79 #expect(lines.contains("It's January."))
80 #expect(lines.contains("Yesterday was Thursday."))
81 #expect(lines.contains("It's Winter."))
82 }
83}
84
85struct MonthGridTests {
86 let calendar = RoutineScriptTests.calendar
87
88 @Test func octoberGrid() {
89 let g = MonthGrid(year: 2026, month: 10, calendar: calendar)
90 #expect(g.leadingBlanks == 4)
91 #expect(g.days == 31)
92 #expect(g.cells.prefix(5) == [nil, nil, nil, nil, 1])
93 #expect(g.cells.last == 31)
94 }
95
96 @Test func februaryGrids() {
97 #expect(MonthGrid(year: 2027, month: 2, calendar: calendar).days == 28)
98 #expect(MonthGrid(year: 2028, month: 2, calendar: calendar).days == 29)
99 }
100
101 @Test func neverPastCurrentMonth() {
102 let today = (year: 2026, month: 10)
103 #expect(!MonthGrid(year: 2026, month: 10, calendar: calendar).canGoLater(than: today))
104 #expect(MonthGrid(year: 2026, month: 9, calendar: calendar).canGoLater(than: today))
105 #expect(MonthGrid(year: 2025, month: 12, calendar: calendar).canGoLater(than: today))
106 #expect(!MonthGrid(year: 2027, month: 1, calendar: calendar).canGoLater(than: today))
107 }
108
109 @Test func shiftAcrossYear() {
110 let jan = MonthGrid(year: 2026, month: 12, calendar: calendar).shifted(by: 1)
111 #expect(jan.year == 2027 && jan.month == 1)
112 let nov = MonthGrid(year: 2027, month: 1, calendar: calendar).shifted(by: -2)
113 #expect(nov.year == 2026 && nov.month == 11)
114 }
115}
DayByDayTests/StickerStoreTests.swift added +86
@@ -0,0 +1,86 @@
1import Foundation
2import SwiftData
3import Testing
4import UIKit
5@testable import DayByDay
6
7struct StickerStoreTests {
8 let container = ProfileStore.makeContainer(inMemory: true)
9 var store: ProfileStore { ProfileStore(context: container.mainContext) }
10
11 func day(_ y: Int, _ m: Int, _ d: Int) -> DateComponents { DateComponents(year: y, month: m, day: d) }
12
13 @Test func stickerUpsertsPerDay() throws {
14 let s = store
15 let maya = try s.create(name: "Maya", avatar: .cat, color: .red, birthday: nil)
16 s.addSticker(for: maya, on: day(2026, 10, 16), weather: .sunny)
17 s.addSticker(for: maya, on: day(2026, 10, 16), weather: .rainy)
18 let stickers = s.stickers(for: maya, year: 2026, month: 10)
19 #expect(stickers.count == 1)
20 #expect(stickers.first?.weatherRaw == LearnWeather.rainy.rawValue)
21 #expect(s.sticker(for: maya, on: day(2026, 10, 16)) != nil)
22 #expect(s.sticker(for: maya, on: day(2026, 10, 17)) == nil)
23 }
24
25 @Test func stickersByMonth() throws {
26 let s = store
27 let maya = try s.create(name: "Maya", avatar: .cat, color: .red, birthday: nil)
28 s.addSticker(for: maya, on: day(2026, 9, 30), weather: .sunny)
29 s.addSticker(for: maya, on: day(2026, 10, 1), weather: .cloudy)
30 s.addSticker(for: maya, on: day(2026, 10, 2), weather: .windy)
31 #expect(s.stickers(for: maya, year: 2026, month: 10).map(\.day).sorted() == [1, 2])
32 #expect(s.stickers(for: maya, year: 2025, month: 10).isEmpty)
33 }
34
35 @Test func picturesSetReplaceRemove() throws {
36 let s = store
37 let maya = try s.create(name: "Maya", avatar: .cat, color: .red, birthday: nil)
38 s.setPicture(.swim, on: .monday, for: maya)
39 #expect(s.picture(on: .monday, for: maya) == .swim)
40 s.setPicture(.school, on: .monday, for: maya)
41 #expect(s.picture(on: .monday, for: maya) == .school)
42 s.setPicture(nil, on: .monday, for: maya)
43 #expect(s.picture(on: .monday, for: maya) == nil)
44 #expect(try container.mainContext.fetch(FetchDescriptor<DayPicture>()).isEmpty)
45 }
46
47 @Test func deleteRemovesOnlyThatChildsData() throws {
48 let s = store
49 let maya = try s.create(name: "Maya", avatar: .cat, color: .red, birthday: nil)
50 let sam = try s.create(name: "Sam", avatar: .dog, color: .blue, birthday: nil)
51 for p in [maya, sam] {
52 s.addSticker(for: p, on: day(2026, 10, 16), weather: .sunny)
53 s.setPicture(.park, on: .friday, for: p)
54 }
55 s.delete(maya)
56 #expect(try container.mainContext.fetch(FetchDescriptor<Sticker>()).count == 1)
57 #expect(try container.mainContext.fetch(FetchDescriptor<DayPicture>()).count == 1)
58 #expect(s.picture(on: .friday, for: sam) == .park)
59 }
60
61 @Test(arguments: DayPictureKind.allCases) func pictureSymbolsExist(_ kind: DayPictureKind) {
62 #expect(UIImage(systemName: kind.symbol) != nil, "\(kind.symbol)")
63 #expect(kind.name.hasSuffix(" day"))
64 }
65
66 /// A store written before stickers existed opens with the new schema and keeps its data.
67 @Test func oldStoreOpens() throws {
68 let url = FileManager.default.temporaryDirectory
69 .appendingPathComponent("old-\(UUID().uuidString).store")
70 do {
71 let old = try ModelContainer(for: Profile.self, AnswerRecord.self,
72 configurations: ModelConfiguration(url: url))
73 let s = ProfileStore(context: old.mainContext)
74 let maya = try s.create(name: "Maya", avatar: .cat, color: .red, birthday: (month: 5, day: 1))
75 s.record(DayByDay.Category.days.quizItems[0], correct: true, for: maya)
76 }
77 let new = try ModelContainer(for: Schema(ProfileStore.modelTypes),
78 configurations: ModelConfiguration(url: url))
79 let profiles = try new.mainContext.fetch(FetchDescriptor<Profile>())
80 #expect(profiles.map(\.name) == ["Maya"])
81 #expect(profiles.first?.answers.count == 1)
82 let s = ProfileStore(context: new.mainContext)
83 s.addSticker(for: profiles[0], on: day(2026, 10, 16), weather: .snowy)
84 #expect(s.stickers(for: profiles[0], year: 2026, month: 10).count == 1)
85 }
86}
NumberCard.swift +1 −1
@@ -70,7 +70,7 @@ nonisolated enum LearnNumber: Int, CaseIterable, Identifiable {
7070
7171 /// Highlight the number matching today's day-of-month if it falls in 1–10.
7272 static var current: LearnNumber? {
73 let day = Calendar.current.component(.day, from: Date())
73 let day = AppCalendar.current.component(.day, from: Date())
7474 return LearnNumber(rawValue: day)
7575 }
7676
TodayView.swift +2 −2
@@ -13,7 +13,7 @@ struct TodayView: View {
1313 private var todayText: String {
1414 let day = DayOfWeek.current.name
1515 let month = MonthOfYear.current.name
16 let date = Calendar.current.component(.day, from: Date())
16 let date = AppCalendar.current.component(.day, from: Date())
1717 let season = Season.current.name
1818 return "Today is \(day), \(month) \(date). It is \(season)."
1919 }
@@ -39,7 +39,7 @@ struct TodayView: View {
3939 .foregroundStyle(.white)
4040
4141 // Date number
42 let dayNumber = Calendar.current.component(.day, from: Date())
42 let dayNumber = AppCalendar.current.component(.day, from: Date())
4343 Text("\(dayNumber)")
4444 .font(.system(size: 72, weight: .heavy, design: .rounded))
4545 .foregroundStyle(.white.opacity(0.9))
docs/superpowers/plans/2026-10-16-part5-today-routine.md added +99
@@ -0,0 +1,99 @@
1# Part 5: Today Routine Implementation Plan
2
3> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
4
5**Goal:** A short spoken morning routine (greeting, birthday line, today/yesterday/tomorrow, day picture, month, season, pick today's weather) that ends with a weather sticker on a browsable month calendar, per child, plus parent-set day pictures shown on day cards and in the routine.
6
7**Architecture:** Two new SwiftData models, `Sticker` and `DayPicture`, reference a child by `profileID` instead of a relationship, so the existing `Profile` entity is unchanged and earlier stores open with a purely additive schema change; `ProfileStore` deletes them with the profile. The routine's lines come from a pure `RoutineScript`; the calendar layout from a pure `MonthGrid`. Views: `TodayRoutineView` (step cards, weather pick, sticker award) reached from the home banner, `StickerCalendarView`, and a day-pictures section in the profile editor.
8
9**Tech Stack:** SwiftUI, SwiftData, Swift Testing, Xcode 27.
10
11**Spec:** `docs/superpowers/specs/2026-10-16-learning-games-design.md` (part 5). Builds on the part 1–4 plans in this folder.
12
13## Global Constraints
14
15- iOS 17.5 target; SF Symbols must be in SF Symbols 5; each new symbol gets a `UIImage(systemName:)` test.
16- `SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor`; pure logic `nonisolated`.
17- No change to the `Profile` or `AnswerRecord` entities. New entities only. A store written by the current main build must open with the new container and keep its profiles (test in Task 1).
18- One sticker per child per calendar day; finishing the routine again that day replaces the sticker's weather.
19- Weeks start on Sunday. Seasons as in `MonthOfYear.season`. The weather pick is not a quiz: any choice is accepted.
20- Every prompt spoken; the child never needs to read. Flat fills; every new fill with white content ≥ 3:1 in `ContrastTests`.
21- Lifecycle: `generation` guard on every `asyncAfter`; `ZStack` for screen states; advance on speech completion with a step-scoped backstop.
22- Day pictures are set behind the parent gate (profile editor), per child.
23- Branch `feat/today-routine`. Every commit `Ref #N` (last `Closes #N`). No AI attribution.
24- Test command: `xcodebuild test -project DayByDay.xcodeproj -scheme DayByDay -destination 'platform=iOS Simulator,name=iPhone 18 Pro'` (full suite ~10 min; run in background).
25
26## Review Focus
27
281. Day boundaries: yesterday/tomorrow wrap at the week's ends and across month and year ends (Friday Jan 1, 2027 → "Yesterday was Thursday.", "It's January."). Test in Task 2.
292. Birthday lines: Feb 29 birthdays in non-leap years get the month line all February and no "today" line; birthday today beats birthday month. Test in Task 2.
303. Stickers: finishing twice the same day keeps one sticker; deleting a child removes their stickers and day pictures and no one else's. Test in Task 1.
314. A store from the previous build (profiles and answers only) opens with the new schema and keeps its data. Test in Task 1.
325. Calendar browsing never goes past the current month, and a month with no stickers still renders its grid. Test in Task 2 (`MonthGrid`) and Task 5.
33
34---
35
36### Task 0: Branch and issue
37
38- [ ] `git checkout -b feat/today-routine main`; `gitbay issue create --title "Part 5: Today routine and sticker calendar" --json --file -`; commit this plan with `Ref #N`.
39
40### Task 1: Stickers and day pictures in the store
41
42**Files:** Create `DayByDay/Profiles/Sticker.swift`, `DayByDay/Profiles/DayPicture.swift`. Modify `ProfileStore.swift` (container types, methods, delete). Test `DayByDayTests/StickerStoreTests.swift`.
43
44**Interfaces:**
45- `@Model final class Sticker { var profileID: UUID; var year: Int; var month: Int; var day: Int; var weatherRaw: Int; var createdAt: Date }`.
46- `nonisolated enum DayPictureKind: String, CaseIterable { swim, school, grandma, park, music, soccer, library, dance }` with `name` ("swim day", "school day", "grandma day", "park day", "music day", "soccer day", "library day", "dance day") and `symbol` (`figure.pool.swim`, `backpack.fill`, `heart.fill`, `tree.fill`, `music.note`, `soccerball`, `books.vertical.fill`, `figure.dance`).
47- `@Model final class DayPicture { var profileID: UUID; var weekdayRaw: Int; var kindRaw: String }`.
48- `ProfileStore.makeContainer` includes `Sticker` and `DayPicture`. New methods: `addSticker(for: Profile, on: DateComponents (year, month, day), weather: LearnWeather)` (upsert), `stickers(for: Profile, year: Int, month: Int) -> [Sticker]`, `sticker(for: Profile, on:) -> Sticker?`, `setPicture(_ kind: DayPictureKind?, on: DayOfWeek, for: Profile)` (nil removes), `picture(on: DayOfWeek, for: Profile) -> DayPictureKind?`. `delete(_:)` also deletes the profile's stickers and pictures.
49
50- [ ] Tests: `stickerUpsertsPerDay`, `stickersByMonth`, `picturesSetReplaceRemove`, `deleteRemovesOnlyThatChildsData`, `pictureSymbolsExist`, `oldStoreOpens` (create an on-disk store at a temp URL with a container of `Profile` and `AnswerRecord` only, insert a profile and an answer, drop it, open the same URL with `makeContainer`'s full type list, expect the profile and answer). RED, implement, GREEN, commit `feat: stickers and day pictures`.
51
52### Task 2: Routine script and month grid
53
54**Files:** Create `DayByDay/Today/RoutineScript.swift`, `DayByDay/Today/MonthGrid.swift`. Test `DayByDayTests/RoutineScriptTests.swift`, `DayByDayTests/MonthGridTests.swift`.
55
56**Interfaces:**
57- `nonisolated struct RoutineScript { struct Line: Equatable { let text: String; let symbol: String } ; init(date: Date, calendar: Calendar, name: String?, birthday: (month: Int, day: Int)?, picture: DayPictureKind?); let lines: [Line] }`. Order:
58 1. `"Hi, \(name)!"` (or `"Hi!"`), symbol `sun.max.fill`.
59 2. Birthday today: `"Today is your birthday! Happy birthday!"` (`birthday.cake.fill`); else birthday month: `"Your birthday is in \(Month)!"` (`gift.fill`). Feb 29 birthdays count as "today" only on Feb 29.
60 3. `"Today is \(Day)."` (that day's `DayOfWeek.symbol`); then, if a picture is set for today, `"Today is \(picture.name)!"` (picture symbol).
61 4. `"Yesterday was \(Day)."`, 5. `"Tomorrow is \(Day)."` (day symbols).
62 6. `"It's \(Month)."` (month symbol), 7. `"It's \(Season)."` (season symbol).
63- `nonisolated struct MonthGrid { init(year: Int, month: Int, calendar: Calendar); let leadingBlanks: Int (Sunday-first); let days: Int; var cells: [Int?] (blanks then 1…days); func shifted(by months: Int) -> MonthGrid }`.
64
65- [ ] Tests with a Gregorian calendar fixed to UTC: `fridayScript` (2026-10-16, "Maya", no birthday, no picture → the 7 lines exactly), `birthdayMonthLine`, `birthdayTodayBeatsMonth`, `leapBirthday` (Feb 29 birthday on 2027-02-28 → month line only; on 2028-02-29 → today line), `pictureLine`, `weekWraps` (2026-10-18 Sunday → yesterday Saturday; 2026-10-17 Saturday → tomorrow Sunday), `yearEnd` (2027-01-01 → "It's January.", yesterday Thursday), `octoberGrid` (2026-10: 4 blanks, 31 days), `februaryGrids` (2027: 28, 2028: 29), `shiftAcrossYear` (2026-12 shifted by 1 → 2027-01). RED, implement, GREEN, commit `feat: routine script and month grid`.
66
67### Task 3: Day pictures for parents and on day cards
68
69**Files:** Modify `DayByDay/Profiles/ProfileEditorView.swift` (section), `DayByDay/DayCard.swift` (flat fill + badge), `DayByDay/DaysOfWeekView.swift`. Test `ContrastTests`.
70
71**Interfaces:**
72- Profile editor (existing profiles only): section "Day pictures" with a picker per weekday (None + each kind, symbol and name), saving through `setPicture`.
73- `DayCard(day:isHighlighted:picture:)`: flat fill; `DayOfWeek.color` changed to values ≥ 3:1 against white; when `picture` is set, a white badge circle with the picture symbol in the day color sits in the top-trailing corner, and tapping says `"\(Day). It's \(picture.name)!"` instead of the day name.
74- `DaysOfWeekView` reads the current profile's pictures from the session.
75
76- [ ] Test `dayColorAgainstWhite` over all days. RED, implement, GREEN, render, commit `feat: day pictures`.
77
78### Task 4: Today routine screen
79
80**Files:** Create `DayByDay/Today/TodayRoutineView.swift`. Modify `DayByDay/Home/HomeView.swift`, `DayByDay/Home/TodayBanner.swift`.
81
82**Interfaces:**
83- `TodayRoutineView`: one large step card at a time (symbol 120 pt, the line in large text on the today color), spoken on appear; a big "next" arrow button advances (and "Hear it again"). After the last line: `"What's the weather like today?"` with `ChoiceTile`s for sunny, cloudy, rainy, snowy, windy. Any tap: `.success`, `"It's \(weather) today! Here's your sticker!"`, `addSticker(today, weather)`, then `StickerCalendarView` for the current month with today's sticker, plus "Play again" style "Done" back navigation. Without a current profile (cannot happen past the picker) the routine still runs and skips the sticker.
84- Home banner links to `TodayRoutineView`; its subtitle line shows "Tap for your sticker!" until today's sticker exists, then a small sticker in today's weather.
85
86- [ ] Build, render (steps and weather pick), commit `feat: today routine`.
87
88### Task 5: Sticker calendar
89
90**Files:** Create `DayByDay/Today/StickerCalendarView.swift`.
91
92**Interfaces:**
93- `StickerCalendarView(profile:, year:, month:)`: month name and year header with back/forward arrows (forward disabled at the current month); weekday initials row; 7-column grid from `MonthGrid`; each day cell shows its number, today outlined, and a sticker (weather symbol, white, in a circle of `Category.weather.color`) when present. Tapping a stickered day says `"On October 3, it was sunny."`.
94
95- [ ] Build, render a month with stickers and an empty month, commit `feat: sticker calendar`.
96
97### Task 6: Reviews, MR, merge
98
99- [ ] Extend `ReviewExport`. Fresh art/sound reviewer (two rounds max). Fresh whole-branch code reviewer with this Review Focus. One fix pass, RED→GREEN. Full suite green. Push, MR `Closes #N`, squash-merge, delete branch.