From c908381d01468614a652b7487420c1fe2ae84818 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Sun, 25 Oct 2026 18:30:57 +0100 Subject: [PATCH] Improve notification ux We now show the next set only once the rest is over, which makes more sense and is the way the app behaves. --- .../workout_notification_content.dart | 130 +++++++++++------- .../workout_notification_service.dart | 3 + lib/l10n/app_de.arb | 5 +- lib/l10n/app_en.arb | 9 +- lib/l10n/app_es.arb | 5 +- lib/l10n/app_fr.arb | 5 +- .../workout_notification_content_test.dart | 27 +++- .../workout_notification_controller_test.dart | 12 +- .../workout_notification_service_test.dart | 15 ++ 9 files changed, 139 insertions(+), 72 deletions(-) diff --git a/lib/features/routines/notifications/workout_notification_content.dart b/lib/features/routines/notifications/workout_notification_content.dart index b5775e694..dfe87494f 100644 --- a/lib/features/routines/notifications/workout_notification_content.dart +++ b/lib/features/routines/notifications/workout_notification_content.dart @@ -99,6 +99,9 @@ class WorkoutControls extends Equatable { final String title; final String body; + /// Shown next to the app name, e.g. that the rest is over + final String? subtitle; + /// Reference time of the chronometer, none if null final DateTime? chronometerAt; final bool chronometerCountsDown; @@ -118,6 +121,7 @@ class WorkoutControls extends Equatable { required this.title, required this.body, required this.payload, + this.subtitle, this.chronometerAt, this.chronometerCountsDown = false, this.canLogSet = false, @@ -131,6 +135,7 @@ class WorkoutControls extends Equatable { List get props => [ title, body, + subtitle, chronometerAt, chronometerCountsDown, canLogSet, @@ -147,6 +152,7 @@ class RestAlarm extends Equatable { final DateTime at; final String title; final String body; + final String? subtitle; final bool canLogSet; final bool canExtendRest; final WorkoutNotificationPayload payload; @@ -160,6 +166,7 @@ class RestAlarm extends Equatable { required this.title, required this.body, required this.payload, + this.subtitle, this.canLogSet = false, this.canExtendRest = false, this.quickLogs = const [], @@ -171,6 +178,7 @@ class RestAlarm extends Equatable { at, title, body, + subtitle, canLogSet, canExtendRest, payload, @@ -303,13 +311,33 @@ WorkoutNotificationTarget buildWorkoutNotification( return '${config.exercise.getTranslation(languageCode).name} ${config.textRepr}'; } - bool plannedComplete(SlotPageEntry page) => isWorkoutLogComplete( - repetitions: page.setConfigData!.repetitions, - weight: page.setConfigData!.weight, - ); + String exerciseName(SlotPageEntry page) => + page.setConfigData!.exercise.getTranslation(languageCode).name; + + /// "Set 2 of 3 · 10 × 60 kg", counted within the exercise + String setOf(SlotPageEntry page) { + final sameExercise = state + .getPageByIndex(page.pageIndex)! + .slotPages + .where( + (p) => + p.type == SlotPageType.log && + p.setConfigData!.exerciseId == page.setConfigData!.exerciseId, + ) + .toList(); + return '${i18n.workoutNotificationSetOf(sameExercise.indexOf(page) + 1, sameExercise.length)}' + ' · ${page.setConfigData!.textRepr}'; + } + + bool canLog(SlotPageEntry page) => + !page.logDone && + isWorkoutLogComplete( + repetitions: page.setConfigData!.repetitions, + weight: page.setConfigData!.weight, + ); List quickLogs(SlotPageEntry page) => - quickLogChoices(page.setConfigData!, recentLogs).keys.toList(); + canLog(page) ? quickLogChoices(page.setConfigData!, recentLogs).keys.toList() : const []; Uri? image(SlotPageEntry? page) => page == null ? null : mediaUrl?.call(page.setConfigData!.exercise.getMainImage?.image); @@ -325,51 +353,60 @@ WorkoutNotificationTarget buildWorkoutNotification( ); if (current?.type == SlotPageType.timer) { - final next = slotPages.firstWhereOrNull( + final following = slotPages.firstWhereOrNull( (p) => p.type == SlotPageType.log && p.pageIndex > current!.pageIndex, ); - final body = next == null ? '' : i18n.workoutNotificationNext(setText(next)); - // "Log set" only works from the rest right before the set - final canLogSet = - next != null && - next.pageIndex == current!.pageIndex + 1 && - !next.logDone && - plannedComplete(next); - final actionPayload = payload(logSlotUuid: next?.uuid, restSlotUuid: current!.uuid); - final nextQuickLogs = canLogSet ? quickLogs(next) : const []; - final nextImage = image(next); + // The set right after the rest, the one the rest end is about + final next = following?.pageIndex == current!.pageIndex + 1 ? following : null; + final actionPayload = payload(logSlotUuid: next?.uuid, restSlotUuid: current.uuid); + final nextText = following == null ? '' : i18n.workoutNotificationNext(setText(following)); final endsAt = state.restEndsAt; final restRunning = endsAt != null && endsAt.isAfter(now); + // Once the rest is over the notification shows the set, like the page + // after the rest. Logging during the rest is left to the set itself. final alarm = state.alertOnCountdownEnd && restRunning ? RestAlarm( at: endsAt, - title: i18n.workoutNotificationRestOver, - body: body, - canLogSet: canLogSet, - // Starts another short countdown once the rest is over + title: next == null ? i18n.workoutNotificationRestOver : exerciseName(next), + body: next == null ? nextText : setOf(next), + subtitle: next == null ? null : i18n.workoutNotificationRestOver, + canLogSet: next != null && canLog(next), + // Starts another short countdown canExtendRest: true, payload: actionPayload, - quickLogs: nextQuickLogs, - image: nextImage, + quickLogs: next == null ? const [] : quickLogs(next), + image: image(next ?? following), ) : null; - final controls = withControls - ? WorkoutControls( - title: endsAt != null && !restRunning ? i18n.workoutNotificationRestOver : i18n.pause, - body: body, - chronometerAt: endsAt == null ? state.restStartedAt : (restRunning ? endsAt : null), - chronometerCountsDown: restRunning, - canLogSet: canLogSet, - canSkipRest: true, - canExtendRest: endsAt != null, - payload: actionPayload, - quickLogs: nextQuickLogs, - image: nextImage, - ) - : null; + final WorkoutControls? controls; + if (!withControls) { + controls = null; + } else if (endsAt != null && !restRunning && next != null) { + controls = WorkoutControls( + title: exerciseName(next), + body: setOf(next), + subtitle: i18n.workoutNotificationRestOver, + canLogSet: canLog(next), + canExtendRest: true, + payload: actionPayload, + quickLogs: quickLogs(next), + image: image(next), + ); + } else { + controls = WorkoutControls( + title: endsAt != null && !restRunning ? i18n.workoutNotificationRestOver : i18n.pause, + body: nextText, + chronometerAt: endsAt == null ? state.restStartedAt : (restRunning ? endsAt : null), + chronometerCountsDown: restRunning, + canSkipRest: true, + canExtendRest: endsAt != null, + payload: actionPayload, + image: image(following), + ); + } return WorkoutNotificationTarget(controls: controls, alarm: alarm); } @@ -379,26 +416,13 @@ WorkoutNotificationTarget buildWorkoutNotification( } if (current?.type == SlotPageType.log) { - final page = state.getPageByIndex(current!.pageIndex)!; - final sameExercise = page.slotPages - .where( - (p) => - p.type == SlotPageType.log && - p.setConfigData!.exerciseId == current.setConfigData!.exerciseId, - ) - .toList(); - final config = current.setConfigData!; - final canLogSet = !current.logDone && plannedComplete(current); - return WorkoutNotificationTarget( controls: WorkoutControls( - title: config.exercise.getTranslation(languageCode).name, - body: - '${i18n.workoutNotificationSetOf(sameExercise.indexOf(current) + 1, sameExercise.length)}' - ' · ${config.textRepr}', - canLogSet: canLogSet, + title: exerciseName(current!), + body: setOf(current), + canLogSet: canLog(current), payload: payload(logSlotUuid: current.uuid), - quickLogs: canLogSet ? quickLogs(current) : const [], + quickLogs: quickLogs(current), image: image(current), ), ); diff --git a/lib/features/routines/notifications/workout_notification_service.dart b/lib/features/routines/notifications/workout_notification_service.dart index def182fed..6b4efb006 100644 --- a/lib/features/routines/notifications/workout_notification_service.dart +++ b/lib/features/routines/notifications/workout_notification_service.dart @@ -214,6 +214,7 @@ class LocalWorkoutNotificationService implements WorkoutNotificationService { priority: Priority.high, category: AndroidNotificationCategory.alarm, visibility: NotificationVisibility.public, + subText: alarm.subtitle, largeIcon: await _cachedImage(alarm.image), actions: [ if (alarm.canExtendRest) @@ -222,6 +223,7 @@ class LocalWorkoutNotificationService implements WorkoutNotificationService { ], ), iOS: DarwinNotificationDetails( + subtitle: alarm.subtitle, presentSound: true, categoryIdentifier: alarm.canLogSet ? _restEndCategory : null, ), @@ -251,6 +253,7 @@ class LocalWorkoutNotificationService implements WorkoutNotificationService { enableVibration: false, category: AndroidNotificationCategory.workout, visibility: NotificationVisibility.public, + subText: controls.subtitle, showWhen: chronometerAt != null, when: chronometerAt?.millisecondsSinceEpoch, usesChronometer: chronometerAt != null, diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index 3e28f5c39..98094dc07 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -1187,8 +1187,9 @@ "workoutNotificationNext": "Als Nächstes: {set}", "workoutNotificationSetOf": "Satz {current} von {total}", "workoutNotificationInProgress": "Training läuft", - "workoutNotificationLogSet": "Satz eintragen", - "workoutNotificationSkipRest": "Pause überspringen", + "workoutNotificationLogSet": "Wie geplant eintragen", + "workoutNotificationSkipRest": "Überspringen", + "workoutNotificationExtendRest": "+{seconds} s", "workoutNotificationNotLoggedTitle": "Satz nicht eingetragen", "workoutNotificationNotLoggedBody": "Öffne den Studiomodus, um das Training fortzusetzen", "workoutNotificationAlarmChannel": "Pausenalarm", diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index a2e77a281..7fbbcd337 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -405,12 +405,15 @@ "workoutNotificationInProgress": "Workout in progress", "workoutNotificationLogSet": "Log planned set", "@workoutNotificationLogSet": { - "description": "Notification button that logs the next set with its planned values" + "description": "Notification button that logs the next set with its planned values. Shown next to up to two other buttons in a single row, so keep it very short; translate the meaning, not word for word" + }, + "workoutNotificationSkipRest": "Skip", + "@workoutNotificationSkipRest": { + "description": "Notification button that ends the running rest. Shown next to up to two other buttons in a single row, so keep it very short; translate the meaning, not word for word" }, - "workoutNotificationSkipRest": "Skip rest", "workoutNotificationExtendRest": "+{seconds} s", "@workoutNotificationExtendRest": { - "description": "Notification button that makes the running rest longer", + "description": "Notification button that makes the running rest longer. Shown next to up to two other buttons in a single row, so keep it very short; translate the meaning, not word for word", "placeholders": { "seconds": { "type": "int" diff --git a/lib/l10n/app_es.arb b/lib/l10n/app_es.arb index 306bea7ae..800eb7074 100644 --- a/lib/l10n/app_es.arb +++ b/lib/l10n/app_es.arb @@ -1204,8 +1204,9 @@ "workoutNotificationNext": "Siguiente: {set}", "workoutNotificationSetOf": "Serie {current} de {total}", "workoutNotificationInProgress": "Entrenamiento en curso", - "workoutNotificationLogSet": "Registrar serie", - "workoutNotificationSkipRest": "Saltar descanso", + "workoutNotificationLogSet": "Registrar según plan", + "workoutNotificationSkipRest": "Saltar", + "workoutNotificationExtendRest": "+{seconds} s", "workoutNotificationNotLoggedTitle": "Serie no registrada", "workoutNotificationNotLoggedBody": "Abre el modo gimnasio para continuar el entrenamiento", "workoutNotificationAlarmChannel": "Alarma de descanso", diff --git a/lib/l10n/app_fr.arb b/lib/l10n/app_fr.arb index aff18c46f..52e8190f5 100644 --- a/lib/l10n/app_fr.arb +++ b/lib/l10n/app_fr.arb @@ -1196,8 +1196,9 @@ "workoutNotificationNext": "Ensuite : {set}", "workoutNotificationSetOf": "Série {current} sur {total}", "workoutNotificationInProgress": "Entraînement en cours", - "workoutNotificationLogSet": "Enregistrer la série", - "workoutNotificationSkipRest": "Passer le repos", + "workoutNotificationLogSet": "Noter comme prévu", + "workoutNotificationSkipRest": "Passer", + "workoutNotificationExtendRest": "+{seconds} s", "workoutNotificationNotLoggedTitle": "Série non enregistrée", "workoutNotificationNotLoggedBody": "Ouvrez le mode entraînement pour poursuivre la séance", "workoutNotificationAlarmChannel": "Alarme de repos", diff --git a/test/features/routines/notifications/workout_notification_content_test.dart b/test/features/routines/notifications/workout_notification_content_test.dart index b9c35a4f1..2c3e30d25 100644 --- a/test/features/routines/notifications/workout_notification_content_test.dart +++ b/test/features/routines/notifications/workout_notification_content_test.dart @@ -88,11 +88,15 @@ void main() { final target = build(); + // The alarm already shows the set, like the page after the rest expect(target.alarm!.at, endsAt); - expect(target.alarm!.title, 'Rest is over'); - expect(target.alarm!.body, 'Next: Bench press 3x100kg'); + expect(target.alarm!.title, 'Bench press'); + expect(target.alarm!.subtitle, 'Rest is over'); + expect(target.alarm!.body, 'Set 2 of 3 · 3x100kg'); expect(target.alarm!.canLogSet, isTrue); expect(target.alarm!.payload.logSlotUuid, logs()[1].uuid); + expect(target.controls!.title, 'Pause'); + expect(target.controls!.body, 'Next: Bench press 3x100kg'); expect(target.controls!.chronometerAt, endsAt); expect(target.controls!.chronometerCountsDown, isTrue); expect(target.controls!.canSkipRest, isTrue); @@ -119,8 +123,12 @@ void main() { final target = build(); expect(target.alarm, isNull); - expect(target.controls!.title, 'Rest is over'); + expect(target.controls!.title, 'Bench press'); + expect(target.controls!.subtitle, 'Rest is over'); + expect(target.controls!.body, 'Set 2 of 3 · 3x100kg'); expect(target.controls!.chronometerAt, isNull); + expect(target.controls!.canLogSet, isTrue); + expect(target.controls!.canSkipRest, isFalse); }); test('A rest that counts up shows the time since its start', () { @@ -141,6 +149,7 @@ void main() { final target = build(); + expect(target.alarm!.title, 'Rest is over'); expect(target.alarm!.body, 'Next: Side raises 12x10kg'); expect(target.alarm!.canLogSet, isFalse); expect(target.controls!.canLogSet, isFalse); @@ -267,15 +276,23 @@ void main() { expect(choices, isEmpty); }); - test('The rest before a set and the set page offer them with "log set"', () { + test('The rest end and the set page offer them with "log set", the rest not', () { final recent = [logOf(repetitions: 9, weight: 60)]; final endsAt = now.add(const Duration(seconds: 90)); onPage(timers().first, restStartedAt: now, restEndsAt: endsAt); var target = build(recentLogs: recent); - expect(target.controls!.quickLogs, ['9 × 60 kg']); + expect(target.controls!.quickLogs, isEmpty); + expect(target.controls!.canLogSet, isFalse); expect(target.alarm!.quickLogs, ['9 × 60 kg']); + onPage( + timers().first, + restStartedAt: now, + restEndsAt: now.subtract(const Duration(seconds: 1)), + ); + expect(build(recentLogs: recent).controls!.quickLogs, ['9 × 60 kg']); + onPage(logs()[1]); target = build(recentLogs: recent); expect(target.controls!.quickLogs, ['9 × 60 kg']); diff --git a/test/features/routines/notifications/workout_notification_controller_test.dart b/test/features/routines/notifications/workout_notification_controller_test.dart index fcbf48605..c2ee5fe20 100644 --- a/test/features/routines/notifications/workout_notification_controller_test.dart +++ b/test/features/routines/notifications/workout_notification_controller_test.dart @@ -316,11 +316,12 @@ void main() { verify(logRepo.addLocalDrift(captureAny, dayId: anyNamed('dayId'))).captured.single as Log; - test('The notification offers earlier logs of the next set', () async { + test('The rest end offers earlier logs of the next set', () async { await startRest(); - final controls = verify(service.showControls(captureAny, any)).captured; - expect((controls.last as WorkoutControls).quickLogs, ['9 × 60 kg']); + // The rest end shows them, the running rest not + final alarms = verify(service.scheduleRestAlarm(captureAny, any)).captured; + expect((alarms.last as RestAlarm).quickLogs, ['9 × 60 kg']); }); test('Also when the log page already loaded the earlier logs', () async { @@ -341,8 +342,9 @@ void main() { await startRest(); - final controls = verify(service.showControls(captureAny, any)).captured; - expect((controls.last as WorkoutControls).quickLogs, ['9 × 60 kg']); + // The rest end shows them, the running rest not + final alarms = verify(service.scheduleRestAlarm(captureAny, any)).captured; + expect((alarms.last as RestAlarm).quickLogs, ['9 × 60 kg']); }); test('A picked quick log arrives through the port and logs its values', () async { diff --git a/test/features/routines/notifications/workout_notification_service_test.dart b/test/features/routines/notifications/workout_notification_service_test.dart index a73a0b603..e5a87e085 100644 --- a/test/features/routines/notifications/workout_notification_service_test.dart +++ b/test/features/routines/notifications/workout_notification_service_test.dart @@ -172,6 +172,21 @@ void main() { ]); }); + test('The alarm says next to the app name that the rest is over', () async { + await LocalWorkoutNotificationService().scheduleRestAlarm( + RestAlarm( + at: DateTime.now().add(const Duration(minutes: 2)), + title: 'Bench press', + body: 'Set 2 of 3 · 3x100kg', + subtitle: 'Rest is over', + payload: payload, + ), + labels, + ); + + expect(scheduled()['subText'], 'Rest is over'); + }); + group('Log set', () { List inputsOfLogSet(Map details) => ((details['actions'] as List).cast>().singleWhere(