iOS agenda redesign !182

merged merged by cmc on 2026-10-09 05:18 UTC · krz/orgstar:ios-agenda-redesign into main

7 files changed, +668 −72

Layout: unified · split

Sources/OrgPresentation/ThemeSpec.swift +15 −14
@@ -141,16 +141,17 @@ public struct ThemeSpec: Equatable, Sendable {
141141 pairs.compactMapValues { RGBA(hex: $0) }
142142 }
143143
144 /// Calm colors after GitHub's light and dark themes: headings colored by level, keywords
145 /// clear without shouting, code in the colors developers know.
144 /// Calm colors after GitHub's light and dark themes for text and code: headings colored by
145 /// level, code in the colors developers know. Keywords, priorities and the agenda's states
146 /// use the system's accessible reds, oranges, blues and greens, so they match iOS and macOS.
146147 public static let `default` = ThemeSpec(
147148 light: palette([
148149 "background": "#ffffff", "foreground": "#1f2328", "cursor": "#0969da", "selection": "#0969da33",
149150 "heading-1": "#0550ae", "heading-2": "#8250df", "heading-3": "#116329", "heading-4": "#953800",
150151 "heading-5": "#0550ae", "heading-6": "#8250df", "heading-7": "#116329", "heading-8": "#953800",
151 "todo": "#cf222e", "done": "#1a7f37", "priority": "#bc4c00", "tags": "#6e7781",
152 "todo-next": "#0969da", "todo-waiting": "#9a6700", "todo-cancelled": "#6e7781",
153 "priority-a": "#cf222e", "priority-b": "#bc4c00", "priority-c": "#57606a",
152 "todo": "#d70015", "done": "#248a3d", "priority": "#c93400", "tags": "#6e7781",
153 "todo-next": "#0a66d8", "todo-waiting": "#b25000", "todo-cancelled": "#8e8e93",
154 "priority-a": "#d70015", "priority-b": "#c93400", "priority-c": "#6c7a8c",
154155 "link": "#0969da", "timestamp": "#8250df", "code": "#953800", "verbatim": "#0a3069", "inline-background": "#afb8c133",
155156 "markup": "#8c959f", "comment": "#6e7781", "keyword": "#6e7781", "metadata": "#6e7781", "special": "#1b7c83",
156157 "block-background": "#f6f8fa", "block-delimiter": "#8c959f", "table": "#1f2328",
@@ -158,18 +159,18 @@ public struct ThemeSpec: Equatable, Sendable {
158159 "syntax-keyword": "#cf222e", "syntax-string": "#0a3069", "syntax-comment": "#6e7781", "syntax-function": "#8250df",
159160 "syntax-type": "#953800", "syntax-number": "#1b7c83", "syntax-property": "#0550ae", "syntax-label": "#8250df",
160161 "modeline-highlight": "#1f2328", "state-normal": "#0969da", "state-insert": "#1a7f37", "state-visual": "#bc4c00",
161 "agenda-date": "#1f2328", "agenda-today": "#0969da", "agenda-time": "#6e7781", "agenda-category": "#6e7781",
162 "agenda-deadline": "#cf222e", "agenda-upcoming": "#bc4c00", "agenda-scheduled": "#6e7781", "agenda-scheduled-past": "#953800",
163 "agenda-overdue": "#cf222e", "agenda-due-soon": "#bc4c00", "agenda-event": "#8250df",
162 "agenda-date": "#1f2328", "agenda-today": "#007aff", "agenda-time": "#6c6c70", "agenda-category": "#6c6c70",
163 "agenda-deadline": "#d70015", "agenda-upcoming": "#c93400", "agenda-scheduled": "#6c6c70", "agenda-scheduled-past": "#c93400",
164 "agenda-overdue": "#d70015", "agenda-due-soon": "#c93400", "agenda-event": "#8944ab",
164165 "habit-clear": "#54aeff", "habit-ready": "#4ac26b", "habit-alert": "#d4a72c", "habit-overdue": "#ff8182",
165166 ]),
166167 dark: palette([
167168 "background": "#0d1117", "foreground": "#e6edf3", "cursor": "#58a6ff", "selection": "#388bfd66",
168169 "heading-1": "#79c0ff", "heading-2": "#d2a8ff", "heading-3": "#7ee787", "heading-4": "#ffa657",
169170 "heading-5": "#79c0ff", "heading-6": "#d2a8ff", "heading-7": "#7ee787", "heading-8": "#ffa657",
170 "todo": "#ff7b72", "done": "#3fb950", "priority": "#ffa657", "tags": "#8b949e",
171 "todo-next": "#58a6ff", "todo-waiting": "#d29922", "todo-cancelled": "#8b949e",
172 "priority-a": "#ff7b72", "priority-b": "#ffa657", "priority-c": "#8b949e",
171 "todo": "#ff6961", "done": "#30d158", "priority": "#ff9f0a", "tags": "#8b949e",
172 "todo-next": "#409cff", "todo-waiting": "#ffd60a", "todo-cancelled": "#8e8e93",
173 "priority-a": "#ff6961", "priority-b": "#ff9f0a", "priority-c": "#98a6b8",
173174 "link": "#58a6ff", "timestamp": "#d2a8ff", "code": "#ffa657", "verbatim": "#a5d6ff", "inline-background": "#6e768166",
174175 "markup": "#6e7681", "comment": "#8b949e", "keyword": "#8b949e", "metadata": "#8b949e", "special": "#56d4dd",
175176 "block-background": "#161b22", "block-delimiter": "#6e7681", "table": "#e6edf3",
@@ -177,9 +178,9 @@ public struct ThemeSpec: Equatable, Sendable {
177178 "syntax-keyword": "#ff7b72", "syntax-string": "#a5d6ff", "syntax-comment": "#8b949e", "syntax-function": "#d2a8ff",
178179 "syntax-type": "#ffa657", "syntax-number": "#56d4dd", "syntax-property": "#79c0ff", "syntax-label": "#d2a8ff",
179180 "modeline-highlight": "#e6edf3", "state-normal": "#1f6feb", "state-insert": "#238636", "state-visual": "#9e6a03",
180 "agenda-date": "#e6edf3", "agenda-today": "#58a6ff", "agenda-time": "#8b949e", "agenda-category": "#8b949e",
181 "agenda-deadline": "#ff7b72", "agenda-upcoming": "#ffa657", "agenda-scheduled": "#8b949e", "agenda-scheduled-past": "#d29922",
182 "agenda-overdue": "#ff7b72", "agenda-due-soon": "#ffa657", "agenda-event": "#d2a8ff",
181 "agenda-date": "#e6edf3", "agenda-today": "#0a84ff", "agenda-time": "#98989d", "agenda-category": "#98989d",
182 "agenda-deadline": "#ff6961", "agenda-upcoming": "#ff9f0a", "agenda-scheduled": "#98989d", "agenda-scheduled-past": "#ff9f0a",
183 "agenda-overdue": "#ff6961", "agenda-due-soon": "#ff9f0a", "agenda-event": "#da8fff",
183184 "habit-clear": "#1f6feb", "habit-ready": "#238636", "habit-alert": "#9e6a03", "habit-overdue": "#da3633",
184185 ])
185186 )
Sources/OrgstarMobile/AgendaScreen.swift +505 −50
@@ -2,6 +2,7 @@
22import OrgApp
33import OrgCore
44import OrgDocument
5import OrgPresentation
56import SwiftUI
67
78/// The agenda over the workspace's agenda files: the day/week view, the TODO list, tag and
@@ -15,6 +16,7 @@ struct AgendaScreen: View {
1516 @State private var message: String?
1617 @Environment(ClockModel.self) private var clock
1718 @Environment(MobileModel.self) private var model
19 @Environment(\.colorScheme) private var colorScheme
1820 @State private var tick = 0
1921 @State private var views = AgendaViewLoader.builtIn
2022 @State private var viewName = "Agenda"
@@ -24,6 +26,15 @@ struct AgendaScreen: View {
2426 @State private var prompt: EditorScreen.PromptRequest?
2527 @State private var refiling: AgendaItem?
2628 @State private var archiving: AgendaItem?
29 /// The day, week or month shown; nil for `org-agenda-span` and `org-agenda-start-day`.
30 @State private var range: SpanRange?
31 /// The mode `range` set, to notice when something else changes the view.
32 @State private var rangeMode: AgendaMode?
33 @State private var jumping = false
34 @State private var rescheduling: AgendaRow?
35 @AppStorage("agendaOverdueExpanded") private var overdueExpanded = true
36 @State private var done = 0
37 @State private var moved = 0
2738
2839 /// A match typed for the tag and property view.
2940 private enum Asking: Identifiable {
@@ -31,6 +42,12 @@ struct AgendaScreen: View {
3142 var id: Int { 0 }
3243 }
3344
45 enum SpanRange: String, CaseIterable, Identifiable {
46 case day, week, month
47 var id: String { rawValue }
48 var title: String { rawValue.capitalized }
49 }
50
3451 private struct Key: Equatable {
3552 var files: Int
3653 var changed: Int?
@@ -41,47 +58,56 @@ struct AgendaScreen: View {
4158 var span: Int
4259 var startOffset: Int
4360 var subfolders: Bool
61 var settings: Int
4462 }
4563
64 private var isDark: Bool { colorScheme == .dark }
65 private var theme: ThemeSpec { model.theme }
66
4667 var body: some View {
4768 List {
4869 // With no folders the empty state stands alone, not over a column of empty days.
4970 if workspace.rootPaths.isEmpty {
5071 } else if case .agenda = agenda.mode {
51 ForEach(agenda.days, id: \.day) { day in
72 let _ = model.settingsVersion
73 ForEach(agenda.groups(showAllDates: OrgPreferences.agendaShowAllDates(), keep: filter.keeps)) { group in
5274 Section {
53 let items = day.items.filter(\.isEntry).filter(filter.keeps)
54 ForEach(items.indices, id: \.self) { i in row(items[i]) }
75 day(group)
5576 } header: {
56 Text(day.header.split(separator: " ", omittingEmptySubsequences: true).prefix(4).joined(separator: " "))
57 .foregroundStyle(day.isToday ? Color.accentColor : .secondary)
77 header(group)
5878 }
5979 }
6080 } else {
61 let items = agenda.list.filter(filter.keeps)
62 if items.isEmpty, !agenda.isComputing { Text("No entries").foregroundStyle(.secondary) }
63 ForEach(items.indices, id: \.self) { i in row(items[i]) }
81 let rows = agenda.list.filter(filter.keeps).compactMap { AgendaRow(item: $0, day: agenda.today, today: agenda.today) }
82 if rows.isEmpty, !agenda.isComputing { Text("No entries").foregroundStyle(.secondary) }
83 ForEach(rows) { row($0, day: agenda.today) }
6484 }
6585 if let reminderStatus {
6686 Section { } footer: { Text(reminderStatus) }
6787 }
6888 }
6989 .listStyle(.insetGrouped)
70 .navigationTitle(viewName)
90 .listSectionSpacing(.compact)
91 // The now line is shorter than a row.
92 .environment(\.defaultMinListRowHeight, 16)
93 .navigationTitle(title)
94 .navigationBarTitleDisplayMode(.inline)
95 .sensoryFeedback(.success, trigger: done)
96 .sensoryFeedback(.impact(weight: .light), trigger: moved)
7197 .onChange(of: agenda.start) {
7298 // Days a followed timestamp asked for.
7399 if agenda.start != nil, case .agenda = agenda.mode { viewName = "Agenda" }
74100 }
101 .onChange(of: agenda.mode) {
102 if agenda.mode != rangeMode { range = nil }
103 }
75104 .overlay {
76105 if workspace.rootPaths.isEmpty {
77106 ContentUnavailableView("No folders", systemImage: "folder", description: Text("Add a folder of org files under Folders."))
78107 }
79108 }
80109 .safeAreaInset(edge: .bottom) {
81 if let status = message ?? (filter.isEmpty ? nil : "Filter: " + filter.description) {
82 Text(status).font(.callout).padding(8).frame(maxWidth: .infinity).background(.bar)
83 .onTapGesture { message = nil }
84 }
110 if !workspace.rootPaths.isEmpty { bottomBar }
85111 }
86112 .toolbar {
87113 ToolbarItem(placement: .topBarLeading) {
@@ -90,25 +116,26 @@ struct AgendaScreen: View {
90116 Button(definition.name) { show(definition) }
91117 }
92118 Button("Tags and Properties…") { asking = .match }
93 if case .agenda = agenda.mode {
94 Divider()
95 Button("Today", systemImage: "calendar.circle") { agenda.showToday() }
96 Button("Earlier", systemImage: "chevron.left") { agenda.shift(forward: false) }
97 Button("Later", systemImage: "chevron.right") { agenda.shift(forward: true) }
98 }
99119 } label: {
100 Label("Views", systemImage: "calendar")
101 }
102 }
103 ToolbarItem(placement: .topBarLeading) {
104 Button("Filter", systemImage: filter.isEmpty ? "line.3.horizontal.decrease.circle" : "line.3.horizontal.decrease.circle.fill") {
105 showingFilter = true
120 Label("Views", systemImage: "list.bullet.rectangle")
106121 }
107122 }
108123 }
109124 .sheet(isPresented: $showingFilter) {
110125 FilterSheet(filter: $filter, items: shownItems)
111126 }
127 .sheet(isPresented: $jumping) {
128 DateSheet(title: "Go to Date", action: "Go", initial: date(firstDay)) { picked in
129 jumping = false
130 if let picked { jump(to: Days.absolute(picked, calendar: .current)) }
131 }
132 }
133 .sheet(item: $rescheduling) { row in
134 DateSheet(title: row.icon == .deadline ? "Deadline" : "Schedule", action: "Set", initial: date(row.planningDay ?? agenda.today)) { picked in
135 rescheduling = nil
136 if let picked, let item = row.item { reschedule(row, item, to: Days.absolute(picked, calendar: .current)) }
137 }
138 }
112139 .sheet(item: $asking) { _ in
113140 PromptSheet(prompt: Prompt(key: "match", message: "Match: tags and properties, as +work-home or TODO=\"WAIT\"")) { answer in
114141 asking = nil
@@ -146,9 +173,14 @@ struct AgendaScreen: View {
146173 views = loaded.views
147174 if let problem = loaded.problems.first { message = problem }
148175 }
176 // Calendar access is asked for when calendar-events is turned on.
177 .task(id: model.settingsVersion) {
178 guard OrgPreferences.calendarEvents(), !CalendarEvents.isAuthorized else { return }
179 if await model.calendarEvents.requestAccess() { tick += 1 }
180 }
149181 .task(id: Key(files: workspace.files.count, changed: workspace.changedFile?.version, edits: session.editVersion, tick: tick,
150182 mode: agenda.mode, start: agenda.start, span: agenda.span, startOffset: agenda.startOffset,
151 subfolders: agenda.includeSubfolders)) {
183 subfolders: agenda.includeSubfolders, settings: model.settingsVersion)) {
152184 await agenda.refresh(open: session.openTexts)
153185 }
154186 }
@@ -173,24 +205,220 @@ struct AgendaScreen: View {
173205 + ". Open Orgstar to set later ones."
174206 }
175207
208 // MARK: - Days
209
210 private func day(_ group: AgendaDayGroup) -> some View {
211 Group {
212 if group.isToday, !group.overdue.isEmpty {
213 Button {
214 withAnimation { overdueExpanded.toggle() }
215 } label: {
216 HStack(spacing: 6) {
217 Image(systemName: "chevron.right")
218 .font(.caption.weight(.semibold))
219 .rotationEffect(.degrees(overdueExpanded ? 90 : 0))
220 Text("Overdue").font(.subheadline.weight(.semibold))
221 Text("\(group.overdue.count)").font(.subheadline.monospacedDigit())
222 Spacer()
223 }
224 .foregroundStyle(themed(theme.statusColor(.overdue, dark: isDark), .red))
225 .contentShape(Rectangle())
226 }
227 .buttonStyle(.plain)
228 if overdueExpanded {
229 ForEach(group.overdue) { row($0, day: group.day) }
230 }
231 }
232 if group.isEmpty {
233 Text("Nothing scheduled").font(.subheadline).foregroundStyle(.secondary)
234 }
235 let now = nowIndex(group)
236 ForEach(Array(group.rows.enumerated()), id: \.element.id) { index, item in
237 if index == now { NowLine(color: todayColor) }
238 row(item, day: group.day)
239 }
240 if let now, now == group.rows.count { NowLine(color: todayColor) }
241 }
242 }
243
244 private func nowIndex(_ group: AgendaDayGroup) -> Int? {
245 let c = Calendar.current.dateComponents([.hour, .minute], from: Date())
246 return group.nowIndex(now: (c.hour ?? 0) * 100 + (c.minute ?? 0))
247 }
248
249 private var todayColor: Color { themed(theme.color("agenda-today", dark: isDark), .accentColor) }
250
251 private func header(_ group: AgendaDayGroup) -> some View {
252 let day = date(group.day).formatted(.dateTime.weekday(.abbreviated).day().month(.abbreviated))
253 return HStack(alignment: .firstTextBaseline) {
254 Text(group.isToday ? "Today · " + day : day)
255 .font(.subheadline.weight(group.isToday ? .bold : .semibold))
256 .foregroundStyle(group.isToday ? todayColor : .primary)
257 Spacer()
258 Button("Add to \(day)", systemImage: "plus.circle") { model.captureRequest = CaptureRequest(day: group.day) }
259 .labelStyle(.iconOnly)
260 .font(.body)
261 .foregroundStyle(group.isToday ? todayColor : .secondary)
262 }
263 .textCase(nil)
264 }
265
266 // MARK: - Span
267
268 /// The first day shown, as `Days` numbers it, and how many.
269 private var shown: (first: Int, span: Int) {
270 var span = agenda.span
271 var offset = agenda.startOffset
272 if case .agenda(let viewSpan, let viewStart) = agenda.mode {
273 span = viewSpan ?? span
274 offset = viewStart ?? offset
275 }
276 return (agenda.start ?? agenda.today + offset, span)
277 }
278
279 private var firstDay: Int { shown.first }
280
281 /// The span: `Thu 8 Oct`, `Week of 5 Oct`, `October 2026`, or the days, `5 – 14 Oct`.
282 private var title: String {
283 guard case .agenda = agenda.mode else { return viewName }
284 if viewName != "Agenda", range == nil, agenda.start == nil { return viewName }
285 let (first, span) = shown
286 let start = date(first)
287 if span == 1 { return start.formatted(.dateTime.weekday(.abbreviated).day().month(.abbreviated)) }
288 if span == 7, first == weekStart(first) { return "Week of " + start.formatted(.dateTime.day().month(.abbreviated)) }
289 let d = Days.date(first)
290 if d.day == 1, span == Days.absolute(year: d.year, month: d.month + 1, day: 1) - first {
291 return start.formatted(.dateTime.month(.wide).year())
292 }
293 return start.formatted(.dateTime.day().month(.abbreviated)) + " – " + date(first + span - 1).formatted(.dateTime.day().month(.abbreviated))
294 }
295
296 private func weekStart(_ day: Int) -> Int {
297 day - (Days.weekday(day) - (Calendar.current.firstWeekday - 1) + 7) % 7
298 }
299
300 /// Shows `range` around `day`; nil returns to the configured span.
301 private func show(_ range: SpanRange?, around day: Int) {
302 self.range = range
303 let mode: AgendaMode
304 let start: Int?
305 switch range {
306 case .day:
307 (mode, start) = (.agenda(span: 1, startOffset: 0), day)
308 case .week:
309 (mode, start) = (.agenda(span: 7, startOffset: 0), weekStart(day))
310 case .month:
311 let d = Days.date(day)
312 let first = Days.absolute(year: d.year, month: d.month, day: 1)
313 (mode, start) = (.agenda(span: Days.absolute(year: d.year, month: d.month + 1, day: 1) - first, startOffset: 0), first)
314 case nil:
315 (mode, start) = (.agenda(span: nil, startOffset: nil), day == agenda.today ? nil : day)
316 }
317 rangeMode = mode
318 viewName = "Agenda"
319 agenda.mode = mode
320 agenda.start = start
321 }
322
323 private func step(forward: Bool) {
324 if range == nil, case .agenda = agenda.mode {
325 agenda.shift(forward: forward)
326 } else {
327 let (first, span) = shown
328 show(range, around: forward ? first + span : first - 1)
329 }
330 }
331
332 private func jump(to day: Int) {
333 show(range, around: day)
334 }
335
336 private func goToday() {
337 if range == nil { show(nil, around: agenda.today) } else { show(range, around: agenda.today) }
338 }
339
340 private var bottomBar: some View {
341 VStack(spacing: 8) {
342 if let status = message ?? (filter.isEmpty ? nil : "Filter: " + filter.description) {
343 Text(status).font(.footnote).padding(.horizontal, 12).padding(.vertical, 6)
344 .glassEffect(.regular, in: Capsule())
345 .onTapGesture { message = nil }
346 }
347 HStack(spacing: 2) {
348 let isAgenda = if case .agenda = agenda.mode { true } else { false }
349 if isAgenda {
350 barButton("Earlier", "chevron.left") { step(forward: false) }
351 }
352 barButton("Filter", filter.isEmpty ? "line.3.horizontal.decrease" : "line.3.horizontal.decrease.circle.fill") { showingFilter = true }
353 if isAgenda {
354 barButton("Today", "smallcircle.filled.circle") { goToday() }
355 barButton("Go to Date", "calendar") { jumping = true }
356 Menu {
357 Picker("Span", selection: Binding { range } set: { show($0, around: $0 == nil ? agenda.today : firstDay) }) {
358 ForEach(SpanRange.allCases) { Text($0.title).tag(Optional($0)) }
359 Text("\(agenda.span) Days").tag(SpanRange?.none)
360 }
361 } label: {
362 Text(range?.title ?? "\(agenda.span) Days")
363 .font(.footnote.weight(.semibold).monospacedDigit())
364 .lineLimit(1)
365 .frame(minWidth: 52, minHeight: 44)
366 .contentShape(Rectangle())
367 }
368 .accessibilityLabel("Span")
369 barButton("Later", "chevron.right") { step(forward: true) }
370 } else {
371 barButton("Agenda", "calendar") { show(nil, around: agenda.today) }
372 }
373 }
374 .padding(.horizontal, 6)
375 .glassEffect(.regular.interactive(), in: Capsule())
376 }
377 .padding(.bottom, 8)
378 .frame(maxWidth: .infinity)
379 }
380
381 private func barButton(_ title: String, _ image: String, action: @escaping () -> Void) -> some View {
382 Button(title, systemImage: image, action: action)
383 .labelStyle(.iconOnly)
384 .font(.body.weight(.medium))
385 .frame(width: 44, height: 44)
386 .contentShape(Rectangle())
387 }
388
176389 // MARK: - Rows
177390
178 private func row(_ item: AgendaItem) -> some View {
391 private func row(_ row: AgendaRow, day: Int) -> some View {
179392 Group {
180 if let path = item.path, let offset = item.headingOffset ?? item.markerOffset {
181 NavigationLink(value: ReaderRoute.offset(path, offset)) { entry(item) }
393 if let item = row.item, let path = item.path, let offset = item.headingOffset ?? item.markerOffset {
394 NavigationLink(value: ReaderRoute.offset(path, offset)) { AgendaRowView(row: row, day: day, theme: theme, dark: isDark) }
182395 } else {
183 entry(item)
396 AgendaRowView(row: row, day: day, theme: theme, dark: isDark)
184397 }
185398 }
186399 .swipeActions(edge: .trailing) {
187 if item.todo != nil, !item.isDone, doneKeyword(for: item) != nil {
400 if let item = row.item, item.todo != nil, !item.isDone, doneKeyword(for: item) != nil {
188401 Button("Done", systemImage: "checkmark") { markDone(item) }.tint(.green)
402 Button("Next State", systemImage: "arrow.right.circle") { run("org.todo.next", on: item) }.tint(.blue)
403 }
404 }
405 .swipeActions(edge: .leading) {
406 if canReschedule(row), let item = row.item {
407 Button("Tomorrow", systemImage: "sunrise") { reschedule(row, item, to: agenda.today + 1) }.tint(.orange)
408 Button("Next Week", systemImage: "calendar.badge.plus") { reschedule(row, item, to: agenda.today + 7) }.tint(.indigo)
409 Button("Pick Date", systemImage: "calendar") { rescheduling = row }.tint(.gray)
189410 }
190411 }
191412 .contextMenu {
192 if item.path != nil {
413 if let item = row.item, item.path != nil {
193414 Button("TODO State…", systemImage: "checkmark.circle") { run("org.todo.cycle", on: item) }
415 if canReschedule(row) {
416 Menu("Reschedule", systemImage: "calendar.badge.clock") {
417 Button("Tomorrow") { reschedule(row, item, to: agenda.today + 1) }
418 Button("Next Week") { reschedule(row, item, to: agenda.today + 7) }
419 Button("Pick Date…") { rescheduling = row }
420 }
421 }
194422 Button("Schedule…", systemImage: "calendar") { run("org.schedule", on: item) }
195423 Button("Deadline…", systemImage: "calendar.badge.exclamationmark") { run("org.deadline", on: item) }
196424 Button("Tags…", systemImage: "tag") { run("org.tags.set", on: item) }
@@ -205,26 +433,26 @@ struct AgendaScreen: View {
205433 }
206434 }
207435
208 private func entry(_ item: AgendaItem) -> some View {
209 VStack(alignment: .leading, spacing: 2) {
210 HStack(alignment: .firstTextBaseline, spacing: 6) {
211 if let time = item.time.firstMatch(of: /[0-9]{1,2}:[0-9]{2}(-[0-9]{1,2}:[0-9]{2})?/) {
212 Text(time.output.0).font(.callout.monospacedDigit()).foregroundStyle(.secondary)
213 }
214 Text(item.text).strikethrough(item.isDone)
215 }
216 HStack(spacing: 6) {
217 Text(item.category)
218 let extra = item.extra.split(whereSeparator: \.isWhitespace).joined(separator: " ")
219 if !extra.isEmpty { Text(extra) }
220 if !item.tags.isEmpty { Text(item.tags.map { ":" + $0 }.joined() + ":") }
221 }
222 .font(.caption)
223 .foregroundStyle(.secondary)
224 }
436 // MARK: - Actions
437
438 /// Entries with a heading, not done, that a schedule or deadline can move.
439 private func canReschedule(_ row: AgendaRow) -> Bool {
440 guard let item = row.item, item.path != nil, item.headingLine != nil, !row.isDone else { return false }
441 return item.todo != nil || row.icon == .scheduled || row.icon == .deadline || row.icon == .habit
225442 }
226443
227 // MARK: - Actions
444 /// Moves the row's deadline (on a deadline row) or schedule to `day`, keeping its times,
445 /// as `org-agenda-schedule` and `org-agenda-deadline` with a date typed.
446 private func reschedule(_ row: AgendaRow, _ item: AgendaItem, to day: Int) {
447 let d = Days.date(day)
448 var answer = String(format: "%04d-%02d-%02d", d.year, d.month, d.day)
449 if let start = row.start {
450 answer += String(format: " %02d:%02d", start / 100 % 24, start % 100)
451 if let end = row.end { answer += String(format: "-%02d:%02d", end / 100 % 24, end % 100) }
452 }
453 run(row.icon == .deadline ? "org.deadline" : "org.schedule", on: item, answers: ["date": answer])
454 moved += 1
455 }
228456
229457 /// The heading of `item` now, found again by its line in case the file changed.
230458 private func locate(_ item: AgendaItem) -> (path: String, offset: Int)? {
@@ -280,6 +508,7 @@ struct AgendaScreen: View {
280508 private func markDone(_ item: AgendaItem) {
281509 guard let keyword = doneKeyword(for: item) else { return }
282510 run(SetTodo(keyword: keyword), on: item)
511 done += 1
283512 }
284513
285514 private func refile(_ item: AgendaItem, to target: RefileTarget) {
@@ -300,6 +529,232 @@ struct AgendaScreen: View {
300529 message = session.archive(from: (path, offset))
301530 tick += 1
302531 }
532
533 private func date(_ day: Int) -> Date {
534 let d = Days.date(day)
535 return Calendar.current.date(from: DateComponents(year: d.year, month: d.month, day: d.day)) ?? Date()
536 }
537
538 private func themed(_ color: RGBA?, _ fallback: Color) -> Color { color?.swiftUI ?? fallback }
539}
540
541extension RGBA {
542 var swiftUI: Color { Color(.sRGB, red: red, green: green, blue: blue, opacity: alpha) }
543}
544
545/// One agenda line: the time or status with an icon in the gutter; the category, title,
546/// progress and tags; the TODO keyword and priority on the right.
547struct AgendaRowView: View {
548 let row: AgendaRow
549 /// The day the row is on, for habit graphs.
550 let day: Int
551 let theme: ThemeSpec
552 let dark: Bool
553
554 var body: some View {
555 HStack(alignment: .top, spacing: 10) {
556 // TODO and match lists have no times or statuses.
557 if !row.gutter.isEmpty || row.icon != nil { gutter.frame(width: 82, alignment: .leading) }
558 VStack(alignment: .leading, spacing: 2) {
559 HStack(spacing: 5) {
560 if !row.category.isEmpty {
561 Circle().fill(categoryColor).frame(width: 7, height: 7)
562 Text(row.category).lineLimit(1).layoutPriority(1)
563 }
564 if let progress = row.progress {
565 Text(progress).monospacedDigit()
566 .padding(.horizontal, 5)
567 .background(.quaternary.opacity(0.7), in: Capsule())
568 }
569 ForEach(row.tags.prefix(3), id: \.self) { tag in
570 Text(tag).lineLimit(1)
571 .padding(.horizontal, 5)
572 .background(.quaternary.opacity(0.7), in: Capsule())
573 }
574 Spacer(minLength: 4)
575 marks
576 }
577 .font(.caption)
578 .foregroundStyle(.secondary)
579 Text(row.title.isEmpty ? " " : row.title)
580 .font(.body)
581 .strikethrough(row.isDone)
582 .foregroundStyle(row.isDone ? .secondary : .primary)
583 if let location = row.event?.location {
584 Label(location, systemImage: "mappin").font(.caption).foregroundStyle(.secondary).lineLimit(1)
585 }
586 if let habit = row.item?.habit {
587 HabitStrip(cells: habit.graph(today: day), theme: theme, dark: dark).padding(.top, 3)
588 }
589 }
590 }
591 .padding(.vertical, 2)
592 .opacity(row.isDone ? 0.75 : 1)
593 }
594
595 /// The TODO keyword and the priority, on the category's line.
596 private var marks: some View {
597 HStack(spacing: 5) {
598 if let todo = row.todo {
599 let color = theme.todoColor(todo, isDone: row.isDone, dark: dark)?.swiftUI ?? .secondary
600 Text(todo)
601 .font(.caption2.weight(.semibold))
602 .foregroundStyle(color)
603 .padding(.horizontal, 6).padding(.vertical, 2)
604 .background(color.opacity(0.14), in: Capsule())
605 }
606 if let priority = row.priority {
607 let color = theme.priorityColor(priority, dark: dark)?.swiftUI ?? .orange
608 Text(priority)
609 .font(.caption2.weight(.bold))
610 .foregroundStyle(color)
611 .frame(width: 18, height: 18)
612 .background(color.opacity(0.14), in: Circle())
613 .overlay(Circle().strokeBorder(color, lineWidth: 1.2))
614 .accessibilityLabel("Priority \(priority)")
615 }
616 }
617 .fixedSize()
618 }
619
620 private var statusColor: Color {
621 theme.statusColor(row.status, dark: dark)?.swiftUI ?? .secondary
622 }
623
624 private var categoryColor: Color {
625 if let event = row.event { return theme.eventColor(event, dark: dark)?.swiftUI ?? .purple }
626 return theme.categoryColor(row.category, dark: dark).swiftUI
627 }
628
629 /// The start over the end for timed rows, else the status; the icon under them.
630 private var gutter: some View {
631 HStack(alignment: .firstTextBaseline, spacing: 4) {
632 Image(systemName: icon ?? "circle").font(.caption2.weight(.semibold)).foregroundStyle(iconColor)
633 .frame(width: 14)
634 .opacity(icon == nil ? 0 : 1)
635 VStack(alignment: .leading, spacing: 1) {
636 if row.start != nil {
637 let parts = row.gutter.split(separator: "–", maxSplits: 1)
638 Text(parts.first.map(String.init) ?? row.gutter)
639 .font(.subheadline.monospacedDigit().weight(.semibold))
640 .foregroundStyle(row.status == .normal ? Color.primary : row.status == .done ? Color.secondary : statusColor)
641 if parts.count > 1 {
642 Text(parts[1]).font(.caption.monospacedDigit()).foregroundStyle(.secondary)
643 }
644 } else if !row.gutter.isEmpty {
645 Text(row.gutter)
646 .font(.caption.weight(.medium).monospacedDigit())
647 .foregroundStyle(statusColor)
648 .lineLimit(2)
649 .allowsTightening(true)
650 .minimumScaleFactor(0.85)
651 .fixedSize(horizontal: false, vertical: true)
652 }
653 }
654 }
655 }
656
657 private var icon: String? {
658 switch row.icon {
659 case .scheduled: row.status == .overdue ? "exclamationmark.circle.fill" : "calendar"
660 case .deadline: row.status == .overdue ? "exclamationmark.triangle.fill" : "flag.fill"
661 case .habit: "repeat"
662 case .event: "calendar"
663 case .timestamp: "clock"
664 case nil: nil
665 }
666 }
667
668 private var iconColor: Color {
669 if row.isEvent { return categoryColor }
670 return row.status == .normal ? Color(.tertiaryLabel) : statusColor
671 }
672}
673
674/// The current time between timed rows, as Org's `now - - -` line.
675struct NowLine: View {
676 let color: Color
677
678 var body: some View {
679 HStack(spacing: 6) {
680 Text(Date.now.formatted(date: .omitted, time: .shortened))
681 .font(.caption2.weight(.semibold).monospacedDigit())
682 .foregroundStyle(color)
683 Circle().fill(color).frame(width: 6, height: 6)
684 Rectangle().fill(color).frame(height: 1.5)
685 }
686 .listRowInsets(EdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16))
687 .listRowSeparator(.hidden)
688 .frame(height: 16)
689 .accessibilityLabel("Now")
690 }
691}
692
693/// org-habit's consistency graph, compact: a bar per day, a dot where the habit was done,
694/// today outlined.
695struct HabitStrip: View {
696 let cells: [Habit.Cell]
697 let theme: ThemeSpec
698 let dark: Bool
699
700 var body: some View {
701 HStack(spacing: 1) {
702 ForEach(cells, id: \.day) { cell in
703 RoundedRectangle(cornerRadius: 1.5)
704 .fill(color(cell.face))
705 .frame(width: 4, height: 12)
706 .overlay {
707 if cell.glyph == "*" { Circle().fill(.white.opacity(0.9)).frame(width: 3, height: 3) }
708 }
709 .overlay {
710 if cell.glyph == "!" { RoundedRectangle(cornerRadius: 1.5).strokeBorder(Color.primary, lineWidth: 1) }
711 }
712 }
713 }
714 .accessibilityElement(children: .ignore)
715 .accessibilityLabel("Done \(cells.filter { $0.glyph == "*" }.count) of the last \(Habit.precedingDays) days")
716 }
717
718 /// Due-state colors, lighter for days to come, as org-habit's faces.
719 private func color(_ face: Habit.Face) -> Color {
720 func themed(_ key: String, _ fallback: Color) -> Color { theme.color(key, dark: dark)?.swiftUI ?? fallback }
721 switch face {
722 case .clear: return themed("habit-clear", .blue).opacity(0.7)
723 case .clearFuture: return themed("habit-clear", .blue).opacity(0.3)
724 case .ready: return themed("habit-ready", .green).opacity(0.8)
725 case .readyFuture: return themed("habit-ready", .green).opacity(0.3)
726 case .alert: return themed("habit-alert", .yellow).opacity(0.85)
727 case .alertFuture: return themed("habit-alert", .yellow).opacity(0.35)
728 case .overdue: return themed("habit-overdue", .red).opacity(0.8)
729 case .overdueFuture: return themed("habit-overdue", .red).opacity(0.3)
730 }
731 }
732}
733
734/// A date to go to or to schedule on.
735struct DateSheet: View {
736 let title: String
737 let action: String
738 let initial: Date
739 let done: (Date?) -> Void
740 @State private var date = Date()
741
742 var body: some View {
743 NavigationStack {
744 DatePicker(title, selection: $date, displayedComponents: .date)
745 .datePickerStyle(.graphical)
746 .padding(.horizontal)
747 .navigationTitle(title)
748 .navigationBarTitleDisplayMode(.inline)
749 .toolbar {
750 ToolbarItem(placement: .cancellationAction) { Button("Cancel") { done(nil) } }
751 ToolbarItem(placement: .confirmationAction) { Button(action) { done(date) } }
752 }
753 Spacer()
754 }
755 .presentationDetents([.medium, .large])
756 .onAppear { date = initial }
757 }
303758}
304759
305760extension AgendaItem: @retroactive Identifiable {
Sources/OrgstarMobile/CaptureScreen.swift +43 −6
@@ -42,7 +42,7 @@ struct CaptureScreen: View {
4242 }
4343 } else {
4444 ForEach(questions.indices, id: \.self) { index in
45 QuestionField(question: questions[index], answer: $answers[index])
45 QuestionField(question: questions[index], answer: $answers[index], defaultDate: request.day.map(Self.date))
4646 }
4747 if let problem { Text(problem).foregroundStyle(.red) }
4848 }
@@ -95,11 +95,12 @@ struct CaptureScreen: View {
9595 /// The template expanded with the answers; the caret where `%?` was.
9696 private func fill() {
9797 guard let template else { return }
98 context.now = Date()
98 context.now = request.day.map(Self.date) ?? Date()
9999 switch Capture.fill(template.template, context: context, answers: answers) {
100100 case .success(let filled):
101 text = filled.text
102 selection = TextSelection(insertionPoint: String.Index(utf16Offset: filled.cursor, in: filled.text))
101 let (filledText, cursor) = request.day.map { Self.scheduling(filled.text, cursor: filled.cursor, on: $0) } ?? (filled.text, filled.cursor)
102 text = filledText
103 selection = TextSelection(insertionPoint: String.Index(utf16Offset: cursor, in: filledText))
103104 problem = nil
104105 editing = true
105106 focused = true
@@ -109,6 +110,31 @@ struct CaptureScreen: View {
109110 }
110111 }
111112
113 /// Now's time of day on `day` (a `Days` number): the default time of an agenda day's
114 /// capture, as `org-agenda-capture` sets `org-overriding-default-time`.
115 static func date(_ day: Int) -> Date {
116 let calendar = Calendar.current
117 let d = Days.date(day)
118 var parts = calendar.dateComponents([.hour, .minute, .second], from: Date())
119 (parts.year, parts.month, parts.day) = (d.year, d.month, d.day)
120 return calendar.date(from: parts) ?? Date()
121 }
122
123 /// An entry captured from an agenda day is scheduled on it: a SCHEDULED line goes under
124 /// the heading unless the template already gave the entry an active timestamp. The caret
125 /// keeps its place in the text.
126 static func scheduling(_ text: String, cursor: Int, on day: Int) -> (String, Int) {
127 guard text.hasPrefix("*"), text.firstMatch(of: /<[0-9]{4}-[0-9]{2}-[0-9]{2}/) == nil else { return (text, cursor) }
128 let d = Days.date(day)
129 let weekday = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][Days.weekday(day)]
130 let line = String(format: "SCHEDULED: <%04d-%02d-%02d ", d.year, d.month, d.day) + weekday + ">"
131 let utf16 = Array(text.utf16)
132 let end = utf16.firstIndex(of: 10) ?? utf16.count
133 let inserted = "\n" + line
134 let result = String(decoding: utf16[..<end], as: UTF16.self) + inserted + String(decoding: utf16[end...], as: UTF16.self)
135 return (result, cursor > end ? cursor + inserted.utf16.count : cursor)
136 }
137
112138 private func file() {
113139 guard let template else { return }
114140 let now = Date()
@@ -135,7 +161,16 @@ struct CaptureScreen: View {
135161struct QuestionField: View {
136162 let question: Capture.Question
137163 @Binding var answer: String
138 @State private var date = Date()
164 /// What an empty date answer means: now, or the agenda day capture started from.
165 let defaultDate: Date?
166 @State private var date: Date
167
168 init(question: Capture.Question, answer: Binding<String>, defaultDate: Date? = nil) {
169 self.question = question
170 _answer = answer
171 self.defaultDate = defaultDate
172 _date = State(initialValue: defaultDate ?? Date())
173 }
139174
140175 var body: some View {
141176 Section {
@@ -165,7 +200,9 @@ struct QuestionField: View {
165200 switch question.kind {
166201 case .text, .property, .clipboard: question.defaultValue
167202 case .tags: "tag:tag"
168 case .date(let withTime, _): withTime ? "now; or +2d, fri 14:00" : "today; or +2d, fri"
203 case .date(let withTime, _):
204 defaultDate.map { Self.stamp($0, withTime: withTime) + "; or +2d, fri" }
205 ?? (withTime ? "now; or +2d, fri 14:00" : "today; or +2d, fri")
169206 }
170207 }
171208
Sources/OrgstarMobile/MobileModel.swift +27
@@ -32,6 +32,10 @@ final class MobileModel {
3232 var openRequest: ReaderRoute?
3333 /// Agenda days to show, from a followed timestamp: the first (a `Days` number) and how many.
3434 var agendaRequest: AgendaDays?
35 /// A capture to show, from the agenda.
36 var captureRequest: CaptureRequest?
37 /// Calendar's events for the agenda, with `calendar-events`.
38 let calendarEvents = CalendarEvents()
3539
3640 struct AgendaDays: Equatable {
3741 let start: Int
@@ -115,10 +119,33 @@ final class MobileModel {
115119 agenda.startOffset = OrgPreferences.agendaStartOffset()
116120 agenda.includeSubfolders = OrgPreferences.agendaSubfolders()
117121 agenda.options = OrgPreferences.agendaOptions(agenda.options)
122 agenda.calendarEvents = OrgPreferences.calendarEvents() ? calendarEvents : nil
123 agenda.calendarNames = OrgPreferences.calendarEventCalendars()
118124 }
119125 settingsVersion += 1
120126 }
121127
128 /// Changes a setting from the app: in the folder's config.toml when there is a folder, as
129 /// the Mac's Settings write it, else in this device's settings.
130 func set(_ defaultsKey: String, to value: TOML.Value) {
131 guard let setting = UserConfig.settings.first(where: { $0.defaultsKey == defaultsKey }) else { return }
132 if let configFolder {
133 let file = configFolder.appendingPathComponent("config.toml")
134 var error: NSError?
135 NSFileCoordinator(filePresenter: nil).coordinate(writingItemAt: file, options: [], error: &error) { url in
136 let text = (try? String(contentsOf: url, encoding: .utf8)) ?? ""
137 try? UserConfig.setting(text, section: setting.section, key: setting.key, to: value).write(to: url, atomically: true, encoding: .utf8)
138 }
139 } else {
140 switch value {
141 case .bool(let b): UserDefaults.standard.set(b, forKey: defaultsKey)
142 case .string(let s): UserDefaults.standard.set(s, forKey: defaultsKey)
143 case .integer(let i): UserDefaults.standard.set(i, forKey: defaultsKey)
144 }
145 }
146 reloadConfig()
147 }
148
122149 /// The capture templates, for the share extension to offer.
123150 private func shareTemplates() {
124151 try? inbox?.setTemplates(CaptureTemplates.load().templates.map { CaptureInbox.Template(key: $0.key, name: $0.name) })
Sources/OrgstarMobile/MobileTheme.swift +3 −2
@@ -37,10 +37,11 @@ struct MobileTheme {
3737
3838 var foreground: UIColor { color("foreground") ?? .label }
3939
40 /// A TODO keyword's color: its own from `[theme.todo]`, else the theme's TODO or DONE.
40 /// A TODO keyword's color: its own from `[theme.todo]`, else its class's (`todo-next`,
41 /// `todo-waiting`, `todo-cancelled`, `todo`, `done`).
4142 func keywordColor(_ keyword: String, done: Bool) -> UIColor? {
4243 if let custom = spec.todo[keyword] { return Self.dynamic(custom, custom) }
43 return color(done ? "done" : "todo")
44 return color(ThemeSpec.TodoClass.of(keyword, isDone: done).key)
4445 }
4546
4647 /// A heading's font: larger by the heading step for levels 1 to 3, bold.
Sources/OrgstarMobile/OrgstarMobileApp.swift +7
@@ -64,6 +64,8 @@ struct CaptureRequest: Identifiable {
6464 let id = UUID()
6565 var template: String?
6666 var properties: [String: String] = [:]
67 /// An agenda day (a `Days` number) the entry is scheduled on.
68 var day: Int?
6769}
6870
6971extension CaptureRequest {
@@ -167,6 +169,11 @@ struct RootView: View {
167169 // An open file takes in what changed on disk.
168170 if let path = workspace.changedFile?.path { session.fileChanged(path) }
169171 }
172 .onChange(of: model.captureRequest?.id) {
173 guard let request = model.captureRequest else { return }
174 model.captureRequest = nil
175 capture = request
176 }
170177 .sheet(item: $capture, onDismiss: showWaiting) { request in
171178 CaptureScreen(workspace: workspace, session: session, request: request)
172179 }
Sources/OrgstarMobile/SettingsScreen.swift +68
@@ -1,6 +1,7 @@
11#if os(iOS)
22import OrgApp
33import OrgCore
4import OrgPresentation
45import SwiftUI
56import UIKit
67
@@ -9,6 +10,13 @@ import UIKit
910struct SettingsScreen: View {
1011 let model: MobileModel
1112 @State private var choosing = false
13 @State private var calendars: [CalendarChoice] = []
14
15 private struct CalendarChoice {
16 let id: String
17 let title: String
18 let color: RGBA?
19 }
1220
1321 var body: some View {
1422 Form {
@@ -24,6 +32,7 @@ struct SettingsScreen: View {
2432 } footer: {
2533 Text("A folder with config.toml and capture.toml, such as a synced copy of ~/.config/orgstar from your Mac. Changes to them apply as they sync.")
2634 }
35 calendarSection
2736 Section("In use") {
2837 let _ = model.settingsVersion
2938 LabeledContent("TODO keywords", value: todoKeywords)
@@ -40,6 +49,65 @@ struct SettingsScreen: View {
4049 }
4150 }
4251
52 /// `calendar-events` and `calendar-event-calendars`, written to config.toml.
53 private var calendarSection: some View {
54 let _ = model.settingsVersion
55 let on = OrgPreferences.calendarEvents()
56 let chosen = OrgPreferences.calendarEventCalendars()
57 return Section {
58 Toggle("Show Calendar Events", isOn: Binding {
59 on
60 } set: { value in
61 model.set("calendarEvents", to: .bool(value))
62 if value { Task { await requestCalendars() } }
63 })
64 if on {
65 if !CalendarEvents.isAuthorized {
66 Button("Allow Access to Calendars…") { Task { await requestCalendars() } }
67 }
68 ForEach(calendars, id: \.id) { calendar in
69 let shown = CalendarEvents.chooses(id: calendar.id, title: calendar.title, chosen: chosen)
70 Button {
71 toggle(calendar.title, shown: shown, chosen: chosen)
72 } label: {
73 HStack {
74 Circle().fill(calendar.color?.swiftUI ?? .secondary).frame(width: 10, height: 10)
75 Text(calendar.title).foregroundStyle(.primary)
76 Spacer()
77 if shown { Image(systemName: "checkmark").foregroundStyle(Color.accentColor) }
78 }
79 }
80 .tint(.primary)
81 }
82 }
83 } header: {
84 Text("Calendar")
85 } footer: {
86 Text(on ? "Events from the checked calendars show in the agenda, read-only." : "Show events from Calendar in the agenda, read-only.")
87 }
88 .task(id: on) { loadCalendars() }
89 }
90
91 private func requestCalendars() async {
92 _ = await model.calendarEvents.requestAccess()
93 loadCalendars()
94 model.reloadConfig()
95 }
96
97 private func loadCalendars() {
98 calendars = model.calendarEvents.calendars()
99 .sorted { $0.title.localizedStandardCompare($1.title) == .orderedAscending }
100 .map { CalendarChoice(id: $0.id, title: $0.title, color: $0.color) }
101 }
102
103 /// Shows or hides a calendar's events; with every calendar checked the setting is empty.
104 private func toggle(_ title: String, shown: Bool, chosen: [String]) {
105 var titles = chosen.isEmpty ? calendars.map(\.title) : chosen
106 if shown { titles.removeAll { $0 == title } } else { titles.append(title) }
107 let value = Set(titles) == Set(calendars.map(\.title)) ? "" : titles.joined(separator: ", ")
108 model.set("calendarEventCalendars", to: .string(value))
109 }
110
43111 /// The span and start day, worded as the Mac's Settings word the start.
44112 private var agenda: String {
45113 func days(_ count: Int) -> String { count == 1 ? "1 day" : "\(count) days" }