From 5f1f7b88a9fe7bed31aec27e2177510df1181589 Mon Sep 17 00:00:00 2001 From: MikenRafter Date: Wed, 18 Nov 2026 23:33:01 -0700 Subject: [PATCH 1/3] day timeline: any repeated band event collapses into one expandable row --- lib/ui2/screens/day_timeline.dart | 180 +++++++++++++++++++----------- test/day_timeline_test.dart | 122 ++++++++++++++++++++ 2 files changed, 238 insertions(+), 64 deletions(-) diff --git a/lib/ui2/screens/day_timeline.dart b/lib/ui2/screens/day_timeline.dart index 32fcfea52..f9542c30c 100644 --- a/lib/ui2/screens/day_timeline.dart +++ b/lib/ui2/screens/day_timeline.dart @@ -63,6 +63,7 @@ class Moment { this.color, this.until, this.detail = '', + this.members = const [], }); /// Epoch seconds. The ONLY sort key — nothing on this page is ranked. @@ -80,6 +81,11 @@ class Moment { /// not on. Those render in muted ink, because a colour is a claim that the /// row belongs to a domain and none of them do. final Color? color; + + /// Epoch seconds of each event folded into this line, in order, when it is a + /// run of the same band event (see [kEventRunGapSec]); empty for anything + /// that stands alone. [MomentRow] opens a run to these. + final List members; } /// Something that was logged for this day and carries no time of day. Kept @@ -105,8 +111,9 @@ Map _events(AppLocalizations? l) => { 57: (l?.dayTimelineAlarmWentOff ?? 'Alarm went off', LucideIcons.alarmClock), }; -/// Double-taps closer together than this are one run on the timeline. -const int kDoubleTapRunGapSec = 10 * 60; +/// The same band event closer to the last one than this is one run on the +/// timeline (double-taps, restarts, an alarm's snoozes). +const int kEventRunGapSec = 10 * 60; /// An off-wrist gap shorter than this is a dropout, not an event in a day. /// Listing every one of them would bury the four that mean something under @@ -248,43 +255,43 @@ List dayMoments({ // times, and a day with the charger on it should not read as four chargers. final seen = {}; final events = _events(l); - final taps = []; + final stream = <(int, int)>[]; // (ts, event id) for (final e in (timeline['events'] as List?) ?? const []) { if (e is! Map) continue; final id = asInt(e['event_id']), t = asInt(e['ts']); final def = id == null ? null : events[id]; if (def == null || t == null || !seen.add('$id/$t')) continue; - if (id == kTriathlonDoubleTapEventId) { - taps.add(t); - continue; - } - out.add(Moment( - at: t, - title: def.$1, - detail: clockOfTs(t), - icon: def.$2, - )); + stream.add((t, id!)); } - // Double-taps in a run (a ball sport sets the firmware's tap detector off on - // every contact) are one span carrying the band's own count, not one line - // per tap burying the rest of the day. - taps.sort(); - final tap = events[kTriathlonDoubleTapEventId]!; - for (var i = 0; i < taps.length;) { + // The same band event again and again (a ball sport sets the firmware's tap + // detector off on every contact; a boot loop restarts it) is one span + // carrying the band's own count, not one line per event burying the day. + // A run is consecutive events of one kind, each under [kEventRunGapSec] + // after the last; any other band event between ends it, so a charger that + // goes on and off is still told in order. + stream.sort((a, b) { + final c = a.$1.compareTo(b.$1); + return c != 0 ? c : a.$2.compareTo(b.$2); + }); + for (var i = 0; i < stream.length;) { + final id = stream[i].$2; var j = i; - while (j + 1 < taps.length && - taps[j + 1] - taps[j] < kDoubleTapRunGapSec) { + while (j + 1 < stream.length && + stream[j + 1].$2 == id && + stream[j + 1].$1 - stream[j].$1 < kEventRunGapSec) { j++; } - final n = j - i + 1; + final n = j - i + 1, from = stream[i].$1, to = stream[j].$1; + final def = events[id]!; out.add(Moment( - at: taps[i], - until: n > 1 ? taps[j] : null, - title: tap.$1, + at: from, + until: n > 1 ? to : null, + title: def.$1, detail: n > 1 - ? '${clockOfTs(taps[i])}–${clockOfTs(taps[j])} · $n×' - : clockOfTs(taps[i]), - icon: tap.$2, + ? '${clockOfTs(from)}–${clockOfTs(to)} · $n×' + : clockOfTs(from), + icon: def.$2, + members: n > 1 ? [for (var k = i; k <= j; k++) stream[k].$1] : const [], )); i = j + 1; } @@ -1368,53 +1375,98 @@ List timelineBody(BuildContext c, TimelineData d, /// One line of the day. The time is the left column and everything aligns to /// it, because the ONE thing this page is ordered by should be the one thing /// you can scan. -class MomentRow extends StatelessWidget { +class MomentRow extends StatefulWidget { const MomentRow(this.m, {super.key}); final Moment m; + @override + State createState() => _MomentRowState(); +} + +class _MomentRowState extends State { + bool _open = false; + @override Widget build(BuildContext c) { - final p = P.of(c); - return Semantics( - label: '${clockOfTs(m.at)}, ${m.title}. ${m.detail}', - excludeSemantics: true, - child: Padding( - padding: const EdgeInsets.symmetric(vertical: S.x3), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // Scaled with the text, not fixed: the column exists so the times - // line up, and a hard 62 px is a clipped clock at 3.1x on exactly - // the phones whose owners chose 3.1x. - SizedBox( - width: MediaQuery.textScalerOf(c).scale(58), - child: Text(clockOfTs(m.at), style: F.n17.copyWith(color: p.ink3)), + final m = widget.m, p = P.of(c); + final row = Padding( + padding: const EdgeInsets.symmetric(vertical: S.x3), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // Scaled with the text, not fixed: the column exists so the times + // line up, and a hard 62 px is a clipped clock at 3.1x on exactly + // the phones whose owners chose 3.1x. + SizedBox( + width: MediaQuery.textScalerOf(c).scale(58), + child: Text(clockOfTs(m.at), style: F.n17.copyWith(color: p.ink3)), + ), + Padding( + padding: const EdgeInsets.only(top: 2), + child: Icon(m.icon, + size: 17, color: m.color == null ? p.ink3 : p.on(m.color!)), + ), + const SizedBox(width: S.x3), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + m.title, + style: F.body + .copyWith(color: p.ink, fontWeight: FontWeight.w600), + ), + if (m.detail.isNotEmpty) + Text(m.detail, + style: F.cap.copyWith(color: p.ink2, height: 1.4)), + ], ), + ), + if (m.members.isNotEmpty) Padding( padding: const EdgeInsets.only(top: 2), - child: Icon(m.icon, - size: 17, color: m.color == null ? p.ink3 : p.on(m.color!)), - ), - const SizedBox(width: S.x3), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - m.title, - style: F.body - .copyWith(color: p.ink, fontWeight: FontWeight.w600), - ), - if (m.detail.isNotEmpty) - Text(m.detail, - style: F.cap.copyWith(color: p.ink2, height: 1.4)), - ], - ), + child: Icon( + _open ? LucideIcons.chevronUp : LucideIcons.chevronDown, + size: 17, + color: p.ink3), ), - ], - ), + ], ), ); + final label = '${clockOfTs(m.at)}, ${m.title}. ${m.detail}'; + // A lone event is exactly the line it always was; only a run opens. + if (m.members.isEmpty) { + return Semantics(label: label, excludeSemantics: true, child: row); + } + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Semantics( + label: label, + button: true, + expanded: _open, + excludeSemantics: true, + child: InkWell( + onTap: () => setState(() => _open = !_open), + child: row, + ), + ), + if (_open) + Padding( + padding: EdgeInsets.only( + left: MediaQuery.textScalerOf(c).scale(58), + bottom: S.x3), + child: Wrap( + spacing: S.x4, + runSpacing: S.x1, + children: [ + for (final t in m.members) + Text(clockOfTs(t), style: F.n17.copyWith(color: p.ink2)), + ], + ), + ), + ], + ); } } diff --git a/test/day_timeline_test.dart b/test/day_timeline_test.dart index f4d10125e..5a1e2ca61 100644 --- a/test/day_timeline_test.dart +++ b/test/day_timeline_test.dart @@ -10,6 +10,7 @@ import 'package:openstrap_edge/data/day_label.dart'; import 'package:openstrap_edge/data/journal_fields.dart'; import 'package:openstrap_edge/data/nutrition_store.dart'; import 'package:openstrap_edge/ui2/screens/day_timeline.dart'; +import 'package:openstrap_edge/ui2/screens/home_screen.dart' show clockOfTs; import 'package:openstrap_edge/ui2/ui2.dart'; final int _day = DateTime(2026, 8, 14).millisecondsSinceEpoch ~/ 1000; @@ -107,6 +108,127 @@ void main() { expect(m.every((x) => x.until == null), isTrue); }); + test('any repeated band event is one line with its count and each time', + () { + // Three restarts in a boot loop, a snoozed alarm ringing twice. + final m = dayMoments(timeline: { + 'day_start': _day, + 'events': [ + for (final i in [0, 3, 6]) {'event_id': 15, 'ts': _at(9, i)}, + for (final i in [0, 9]) {'event_id': 57, 'ts': _at(7, i)}, + ], + }); + expect(m, hasLength(2)); + final alarm = m.first, restart = m.last; + expect(alarm.at, _at(7)); + expect(alarm.until, _at(7, 9)); + expect(alarm.detail, '${clockOfTs(_at(7))}–${clockOfTs(_at(7, 9))} · 2×'); + expect(alarm.members, [_at(7), _at(7, 9)]); + expect(restart.detail, '${clockOfTs(_at(9))}–${clockOfTs(_at(9, 6))} · 3×'); + expect(restart.members, [_at(9), _at(9, 3), _at(9, 6)]); + }); + + test('a run is counted after the (id, ts) dedupe, never before', () { + final m = dayMoments(timeline: { + 'day_start': _day, + 'events': [ + {'event_id': 15, 'ts': _at(9)}, + {'event_id': 15, 'ts': _at(9)}, + {'event_id': 15, 'ts': _at(9, 4)}, + ], + }); + expect(m.single.members, [_at(9), _at(9, 4)]); + expect(m.single.detail, contains('2×')); + }); + + test('a lone band event is unchanged and carries no members', () { + final m = dayMoments(timeline: { + 'day_start': _day, + 'events': [ + {'event_id': 15, 'ts': _at(9)}, + ], + }); + expect(m.single.until, isNull); + expect(m.single.members, isEmpty); + expect(m.single.detail, isNot(contains('×'))); + }); + + test('a different band event in between ends the run', () { + // On and off alternate: folding the ons together would put the offs in + // the middle of their span and misorder what happened. + final m = dayMoments(timeline: { + 'day_start': _day, + 'events': [ + {'event_id': 7, 'ts': _at(22)}, + {'event_id': 8, 'ts': _at(22, 2)}, + {'event_id': 7, 'ts': _at(22, 4)}, + {'event_id': 8, 'ts': _at(22, 6)}, + ], + }); + expect(m, hasLength(4)); + expect(m.every((x) => x.members.isEmpty), isTrue); + }); + + test('the gap applies to every kind: 10 minutes apart are two lines', () { + final m = dayMoments(timeline: { + 'day_start': _day, + 'events': [ + {'event_id': 15, 'ts': _at(9)}, + {'event_id': 15, 'ts': _at(9, 10)}, + ], + }); + expect(m, hasLength(2)); + }); + + test('sleep, sessions and naps are never folded into a run', () { + final m = dayMoments(timeline: { + 'day_start': _day, + 'sessions': [ + {'start_ts': _at(10), 'end_ts': _at(10, 5), 'type': 'run'}, + {'start_ts': _at(10, 6), 'end_ts': _at(10, 9), 'type': 'run'}, + ], + 'naps': [ + {'start': _at(10, 1), 'end': _at(10, 4), 'duration_min': 3}, + {'start': _at(10, 5), 'end': _at(10, 8), 'duration_min': 3}, + ], + }); + expect(m, hasLength(4)); + expect(m.every((x) => x.members.isEmpty), isTrue); + }); + + testWidgets('a run opens to each time when tapped and closes again', + (t) async { + final m = dayMoments(timeline: { + 'day_start': _day, + 'events': [ + for (final i in [0, 3, 6]) {'event_id': 15, 'ts': _at(9, i)}, + ], + }).single; + await t.pumpWidget(MaterialApp( + home: Scaffold(body: SingleChildScrollView(child: MomentRow(m))))); + final mid = clockOfTs(_at(9, 3)); + expect(find.text(mid), findsNothing); + await t.tap(find.text(m.title)); + await t.pumpAndSettle(); + expect(find.text(mid), findsOneWidget); + // The last time is only in the run's range text until the run opens. + expect(find.text(clockOfTs(_at(9, 6))), findsOneWidget); + await t.tap(find.text(m.title)); + await t.pumpAndSettle(); + expect(find.text(mid), findsNothing); + }); + + testWidgets('a lone event is not tappable', (t) async { + final m = dayMoments(timeline: { + 'day_start': _day, + 'events': [ + {'event_id': 15, 'ts': _at(9)}, + ], + }).single; + await t.pumpWidget(MaterialApp(home: Scaffold(body: MomentRow(m)))); + expect(find.byType(InkWell), findsNothing); + }); + test('a meal with no time is never placed, and is not lost either', () { const timed = FoodEntry( id: 'a', date: '2026-08-14', meal: 'Lunch', label: 'Soup', kcal: 300); From 045e2dabd2b4d604689d2d5a9b3e1b2a6fb65113 Mon Sep 17 00:00:00 2001 From: MikenRafter Date: Thu, 19 Nov 2026 00:12:51 -0700 Subject: [PATCH 2/3] fix timeline run semantic activation and pin visible grouping policy --- lib/ui2/screens/day_timeline.dart | 7 +- test/day_timeline_test.dart | 112 +++++++++++++++++++++++++++--- 2 files changed, 108 insertions(+), 11 deletions(-) diff --git a/lib/ui2/screens/day_timeline.dart b/lib/ui2/screens/day_timeline.dart index f9542c30c..576a85557 100644 --- a/lib/ui2/screens/day_timeline.dart +++ b/lib/ui2/screens/day_timeline.dart @@ -267,7 +267,7 @@ List dayMoments({ // detector off on every contact; a boot loop restarts it) is one span // carrying the band's own count, not one line per event burying the day. // A run is consecutive events of one kind, each under [kEventRunGapSec] - // after the last; any other band event between ends it, so a charger that + // after the last; a different visible band event ends it, so a charger that // goes on and off is still told in order. stream.sort((a, b) { final c = a.$1.compareTo(b.$1); @@ -1386,6 +1386,8 @@ class MomentRow extends StatefulWidget { class _MomentRowState extends State { bool _open = false; + void _toggle() => setState(() => _open = !_open); + @override Widget build(BuildContext c) { final m = widget.m, p = P.of(c); @@ -1445,9 +1447,10 @@ class _MomentRowState extends State { label: label, button: true, expanded: _open, + onTap: _toggle, excludeSemantics: true, child: InkWell( - onTap: () => setState(() => _open = !_open), + onTap: _toggle, child: row, ), ), diff --git a/test/day_timeline_test.dart b/test/day_timeline_test.dart index 5a1e2ca61..bdd515c8d 100644 --- a/test/day_timeline_test.dart +++ b/test/day_timeline_test.dart @@ -4,6 +4,8 @@ // mis-slotted sample puts a workout under the wrong hour; a missed hole draws // a line through the time the band spent on the charger. +import 'dart:ui' show SemanticsAction, Tristate; + import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:openstrap_edge/data/day_label.dart'; @@ -153,7 +155,7 @@ void main() { expect(m.single.detail, isNot(contains('×'))); }); - test('a different band event in between ends the run', () { + test('a different visible band event in between ends the run', () { // On and off alternate: folding the ons together would put the offs in // the middle of their span and misorder what happened. final m = dayMoments(timeline: { @@ -180,6 +182,55 @@ void main() { expect(m, hasLength(2)); }); + // Hidden diagnostics must not create unexplained breaks in visible rows. + test('a hidden band event does not end a visible run', () { + final m = dayMoments(timeline: { + 'events': [ + {'event_id': 15, 'ts': _at(9)}, + {'event_id': 31, 'ts': _at(9, 1)}, + {'event_id': 15, 'ts': _at(9, 2)}, + ], + }); + expect(m, hasLength(1)); + expect(m.single.members, [_at(9), _at(9, 2)]); + expect(m.single.detail, contains('2×')); + }); + + // The threshold bounds adjacent gaps, with equality starting a new row. + test('599 seconds groups and 600 seconds splits', () { + final m = dayMoments(timeline: { + 'events': [ + {'event_id': 15, 'ts': _at(9)}, + {'event_id': 15, 'ts': _at(9) + 599}, + {'event_id': 15, 'ts': _at(9) + 1199}, + ], + }); + expect(m, hasLength(2)); + expect(m.first.members, [_at(9), _at(9) + 599]); + expect(m.first.until, _at(9) + 599); + expect(m.last.at, _at(9) + 1199); + expect(m.last.members, isEmpty); + expect(m.last.until, isNull); + }); + + // Delivery order must not change grouping or the order of member times. + test('reversed input still groups chronologically with visible separators', + () { + final m = dayMoments(timeline: { + 'events': [ + {'event_id': 15, 'ts': _at(9, 4)}, + {'event_id': 57, 'ts': _at(9, 3)}, + {'event_id': 15, 'ts': _at(9, 2)}, + {'event_id': 15, 'ts': _at(9)}, + ], + }); + expect(m, hasLength(3)); + expect(m.map((x) => x.at), [_at(9), _at(9, 3), _at(9, 4)]); + expect(m.first.members, [_at(9), _at(9, 2)]); + expect(m.first.until, _at(9, 2)); + expect(m.skip(1).every((x) => x.members.isEmpty), isTrue); + }); + test('sleep, sessions and naps are never folded into a run', () { final m = dayMoments(timeline: { 'day_start': _day, @@ -218,15 +269,58 @@ void main() { expect(find.text(mid), findsNothing); }); + // Screen readers activate semantics actions without a pointer gesture. + testWidgets('semantic tap expands and collapses a run', (t) async { + final semantics = t.ensureSemantics(); + try { + final m = dayMoments(timeline: { + 'events': [ + for (final i in [0, 3, 6]) {'event_id': 15, 'ts': _at(9, i)}, + ], + }).single; + await t.pumpWidget(MaterialApp( + home: Scaffold(body: SingleChildScrollView(child: MomentRow(m))))); + final control = find.bySemanticsLabel( + '${clockOfTs(m.at)}, ${m.title}. ${m.detail}'); + expect(control, findsOneWidget); + final mid = clockOfTs(_at(9, 3)); + for (var step = 0; step < 3; step++) { + final expanded = step == 1; + final node = t.getSemantics(control); + expect(node.flagsCollection.isButton, isTrue); + expect(node.flagsCollection.isExpanded, + expanded ? Tristate.isTrue : Tristate.isFalse); + expect(node.getSemanticsData().hasAction(SemanticsAction.tap), isTrue); + expect(find.text(mid), expanded ? findsOneWidget : findsNothing); + if (step < 2) { + node.owner!.performAction(node.id, SemanticsAction.tap); + await t.pumpAndSettle(); + } + } + } finally { + semantics.dispose(); + } + }); + testWidgets('a lone event is not tappable', (t) async { - final m = dayMoments(timeline: { - 'day_start': _day, - 'events': [ - {'event_id': 15, 'ts': _at(9)}, - ], - }).single; - await t.pumpWidget(MaterialApp(home: Scaffold(body: MomentRow(m)))); - expect(find.byType(InkWell), findsNothing); + final semantics = t.ensureSemantics(); + try { + final m = dayMoments(timeline: { + 'day_start': _day, + 'events': [ + {'event_id': 15, 'ts': _at(9)}, + ], + }).single; + await t.pumpWidget(MaterialApp(home: Scaffold(body: MomentRow(m)))); + expect(find.byType(InkWell), findsNothing); + final node = t.getSemantics(find.bySemanticsLabel( + '${clockOfTs(m.at)}, ${m.title}. ${m.detail}')); + expect(node.getSemanticsData().hasAction(SemanticsAction.tap), isFalse); + expect(node.flagsCollection.isButton, isFalse); + expect(node.flagsCollection.isExpanded, Tristate.none); + } finally { + semantics.dispose(); + } }); test('a meal with no time is never placed, and is not lost either', () { From fe93410642c0baa4c7cc3ca1e6550014c8e5c89d Mon Sep 17 00:00:00 2001 From: MikenRafter Date: Thu, 19 Nov 2026 04:13:58 -0700 Subject: [PATCH 3/3] day timeline: keep an open run row open when an earlier moment is inserted MomentRow holds its open state. When a reload keeps the rows on screen (a locale change re-reads the day without clearing it) and adds an earlier moment, every later row shifts down and the open state stayed with the old position, on a different row. Key run rows by (title, first time); lone rows hold no state and stay unkeyed. --- lib/ui2/screens/day_timeline.dart | 7 +++++- test/day_timeline_test.dart | 36 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/lib/ui2/screens/day_timeline.dart b/lib/ui2/screens/day_timeline.dart index 576a85557..f3f75a704 100644 --- a/lib/ui2/screens/day_timeline.dart +++ b/lib/ui2/screens/day_timeline.dart @@ -1312,7 +1312,12 @@ List timelineBody(BuildContext c, TimelineData d, pad: const EdgeInsets.fromLTRB(S.x4, S.x2, S.x4, S.x2), child: Column( children: [ - for (final m in d.moments) MomentRow(m), + // A run row holds its open state, so it is keyed: a reload + // that adds an earlier moment must not hand that state to the + // row now at its old position. Lone rows hold none. + for (final m in d.moments) + MomentRow(m, + key: m.members.isEmpty ? null : ValueKey((m.title, m.at))), ], ), ), diff --git a/test/day_timeline_test.dart b/test/day_timeline_test.dart index bdd515c8d..a802a7bd6 100644 --- a/test/day_timeline_test.dart +++ b/test/day_timeline_test.dart @@ -323,6 +323,42 @@ void main() { } }); + // A reload that keeps the rows on screen (a locale change re-reads the + // day without clearing it) must not hand an open run's state to the row + // that now sits at its old position. + testWidgets('an open run stays open when an earlier moment is inserted', + (t) async { + List moments({required bool earlier}) => dayMoments(timeline: { + 'day_start': _day, + 'events': [ + for (final i in [0, 3, 6]) {'event_id': 15, 'ts': _at(9, i)}, + for (final i in [0, 9]) {'event_id': 57, 'ts': _at(7, i)}, + if (earlier) {'event_id': 7, 'ts': _at(6)}, + ], + }); + Future show(List m) => t.pumpWidget(MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: Builder( + builder: (c) => Column( + children: + timelineBody(c, TimelineData(moments: m)))))))); + + await show(moments(earlier: false)); + final restarts = clockOfTs(_at(9, 3)), alarm = clockOfTs(_at(7, 9)); + await t.tap(find.text('The band restarted')); + await t.pumpAndSettle(); + expect(find.text(restarts), findsOneWidget); + expect(find.text(alarm), findsNothing); + + await show(moments(earlier: true)); + await t.pumpAndSettle(); + expect(find.text(restarts), findsOneWidget, + reason: 'the restart run is still the open one'); + expect(find.text(alarm), findsNothing, + reason: 'the alarm run, now one position lower, stayed closed'); + }); + test('a meal with no time is never placed, and is not lost either', () { const timed = FoodEntry( id: 'a', date: '2026-08-14', meal: 'Lunch', label: 'Soup', kcal: 300);