mirror of
https://github.com/wger-project/flutter.git
synced 2026-11-30 01:41:05 +01:00
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.
This commit is contained in:
@@ -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<Object?> 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<String> 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 <String>[];
|
||||
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),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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']);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<Object?> inputsOfLogSet(Map<Object?, Object?> details) =>
|
||||
((details['actions'] as List).cast<Map<Object?, Object?>>().singleWhere(
|
||||
|
||||
Reference in New Issue
Block a user