Merge the rest alarm into the rest end alert setting

This commit is contained in:
Roland Geider
2026-10-25 16:33:46 +01:00
parent fc237bca15
commit fb3d6092d7
32 changed files with 233 additions and 87 deletions

View File

@@ -164,7 +164,7 @@ class WorkoutNotificationLabels extends Equatable {
: logSet = i18n.workoutNotificationLogSet,
skipRest = i18n.workoutNotificationSkipRest,
controlsChannel = i18n.workoutNotificationChannel,
alarmChannel = i18n.gymModeRestAlarm,
alarmChannel = i18n.workoutNotificationAlarmChannel,
notLoggedTitle = i18n.workoutNotificationNotLoggedTitle,
notLoggedBody = i18n.workoutNotificationNotLoggedBody;
@@ -247,7 +247,7 @@ WorkoutNotificationTarget buildWorkoutNotification(
final endsAt = state.restEndsAt;
final restRunning = endsAt != null && endsAt.isAfter(now);
final alarm = state.restAlarmEnabled && restRunning
final alarm = state.alertOnCountdownEnd && restRunning
? RestAlarm(
at: endsAt,
title: i18n.workoutNotificationRestOver,

View File

@@ -34,7 +34,6 @@ const PREFS_COUNTDOWN_DURATION = 'countdownDurationSecondsPrefs';
const PREFS_LOG_SCOPE_WEEKS = 'logScopeWeeksPrefs';
const PREFS_SHOW_DISTINCT_LOGS = 'showDistinctLogsPrefs';
const PREFS_SHOW_WORKOUT_DURATION = 'showWorkoutDurationPrefs';
const PREFS_REST_ALARM = 'restAlarmPrefs';
const PREFS_WORKOUT_NOTIFICATION = 'workoutNotificationPrefs';
/// In seconds
@@ -187,6 +186,9 @@ class GymModeState {
// User settings
final bool showExercisePages;
final bool showTimerPages;
/// Alert at the end of a rest: a vibration in gym mode, an OS notification
/// with the app in the background
final bool alertOnCountdownEnd;
final bool useCountdownBetweenSets;
final Duration countdownDuration;
@@ -194,9 +196,6 @@ class GymModeState {
final bool showDistinctLogs;
final bool showWorkoutDuration;
/// OS notification when the rest is over, also with the app in the background
final bool restAlarmEnabled;
/// Ongoing notification with the rest and the next set (Android)
final bool showWorkoutNotification;
@@ -220,7 +219,6 @@ class GymModeState {
this.logScopeWeeks,
this.showDistinctLogs = true,
this.showWorkoutDuration = true,
this.restAlarmEnabled = true,
this.showWorkoutNotification = true,
int? dayId,
int? iteration,
@@ -271,7 +269,6 @@ class GymModeState {
bool clearLogScopeWeeks = false,
bool? showDistinctLogs,
bool? showWorkoutDuration,
bool? restAlarmEnabled,
bool? showWorkoutNotification,
}) {
return GymModeState(
@@ -297,7 +294,6 @@ class GymModeState {
logScopeWeeks: clearLogScopeWeeks ? null : (logScopeWeeks ?? this.logScopeWeeks),
showDistinctLogs: showDistinctLogs ?? this.showDistinctLogs,
showWorkoutDuration: showWorkoutDuration ?? this.showWorkoutDuration,
restAlarmEnabled: restAlarmEnabled ?? this.restAlarmEnabled,
showWorkoutNotification: showWorkoutNotification ?? this.showWorkoutNotification,
);
}

View File

@@ -93,11 +93,6 @@ class GymStateNotifier extends _$GymStateNotifier {
state = state.copyWith(showWorkoutDuration: showWorkoutDuration);
}
final restAlarm = await prefs.getBool(PREFS_REST_ALARM);
if (restAlarm != null && restAlarm != state.restAlarmEnabled) {
state = state.copyWith(restAlarmEnabled: restAlarm);
}
final workoutNotification = await prefs.getBool(PREFS_WORKOUT_NOTIFICATION);
if (workoutNotification != null && workoutNotification != state.showWorkoutNotification) {
state = state.copyWith(showWorkoutNotification: workoutNotification);
@@ -113,7 +108,6 @@ class GymStateNotifier extends _$GymStateNotifier {
'logScopeWeeks=$logScopeWeeks '
'showDistinctLogs=$showDistinctLogs '
'showWorkoutDuration=$showWorkoutDuration '
'restAlarm=$restAlarm '
'workoutNotification=$workoutNotification ',
);
}
@@ -135,7 +129,6 @@ class GymStateNotifier extends _$GymStateNotifier {
}
await prefs.setBool(PREFS_SHOW_DISTINCT_LOGS, state.showDistinctLogs);
await prefs.setBool(PREFS_SHOW_WORKOUT_DURATION, state.showWorkoutDuration);
await prefs.setBool(PREFS_REST_ALARM, state.restAlarmEnabled);
await prefs.setBool(PREFS_WORKOUT_NOTIFICATION, state.showWorkoutNotification);
_logger.finer(
@@ -148,7 +141,6 @@ class GymStateNotifier extends _$GymStateNotifier {
'logScopeWeeks=${state.logScopeWeeks} '
'showDistinctLogs=${state.showDistinctLogs} '
'showWorkoutDuration=${state.showWorkoutDuration} '
'restAlarm=${state.restAlarmEnabled} '
'workoutNotification=${state.showWorkoutNotification} ',
);
}
@@ -471,11 +463,6 @@ class GymStateNotifier extends _$GymStateNotifier {
_savePrefs();
}
void setRestAlarmEnabled(bool value) {
state = state.copyWith(restAlarmEnabled: value);
_savePrefs();
}
void setShowWorkoutNotification(bool value) {
state = state.copyWith(showWorkoutNotification: value);
_savePrefs();

View File

@@ -127,7 +127,8 @@ class _GymModeState extends ConsumerState<GymMode> {
final gymState = ref.read(gymStateProvider);
final service = ref.read(workoutNotificationServiceProvider);
final wanted =
gymState.restAlarmEnabled || (service.supportsControls && gymState.showWorkoutNotification);
gymState.alertOnCountdownEnd ||
(service.supportsControls && gymState.showWorkoutNotification);
if (wanted && mounted) {
unawaited(
service.requestPermissions(WorkoutNotificationLabels.of(AppLocalizations.of(context))),

View File

@@ -169,27 +169,21 @@ class _GymModeOptionsState extends ConsumerState<GymModeOptions> {
),
),
// Enabled without the default countdown too, a set's rest time
// is always counted down
SwitchListTile(
key: const ValueKey('gym-mode-notify-countdown'),
title: Text(i18n.gymModeNotifyOnCountdownFinish),
title: Text(i18n.gymModeAlertOnRestEnd),
subtitle: Text(i18n.gymModeAlertOnRestEndHelp),
value: gymState.alertOnCountdownEnd,
onChanged: (gymState.showTimerPages && gymState.useCountdownBetweenSets)
? (value) => gymNotifier.setAlertOnCountdownEnd(value)
: null,
),
SwitchListTile(
key: const ValueKey('gym-mode-rest-alarm'),
title: Text(i18n.gymModeRestAlarm),
subtitle: Text(i18n.gymModeRestAlarmHelp),
value: gymState.restAlarmEnabled,
onChanged: gymState.showTimerPages
? (value) => gymNotifier.setRestAlarmEnabled(value)
? (value) => gymNotifier.setAlertOnCountdownEnd(value)
: null,
),
// Android delays alarms without the exact alarm permission
if (isAndroid &&
gymState.showTimerPages &&
gymState.restAlarmEnabled &&
gymState.alertOnCountdownEnd &&
ref.watch(exactAlarmsAllowedProvider).value == false)
ListTile(
key: const ValueKey('gym-mode-exact-alarm-hint'),

View File

@@ -823,7 +823,6 @@
"countdown": "عد تنازلي",
"stopwatch": "ساعة توقيت",
"gymModeDefaultCountdownTime": "وقت العد التنازلي الافتراضي، بالثواني",
"gymModeNotifyOnCountdownFinish": "إشعار عند انتهاء العد التنازلي",
"duration": "المدة",
"durationHoursMinutes": "{hours}سا {minutes}د",
"@durationHoursMinutes": {

View File

@@ -870,7 +870,6 @@
"countdown": "Compte enrere",
"stopwatch": "Cronometre",
"gymModeDefaultCountdownTime": "Temps de compte enrere per defecte, en segons",
"gymModeNotifyOnCountdownFinish": "Notifica en finalitzar el compte enrere",
"duration": "Duració",
"durationHoursMinutes": "{hours}h {minutes}m",
"@durationHoursMinutes": {

View File

@@ -873,7 +873,6 @@
"countdown": "Odpočet",
"stopwatch": "Stopky",
"gymModeDefaultCountdownTime": "Výchozí doba odpočítávání v sekundách",
"gymModeNotifyOnCountdownFinish": "Upozornit na konec odpočítávání",
"duration": "Doba trvání",
"durationHoursMinutes": "{hours}h {minutes}m",
"@durationHoursMinutes": {

View File

@@ -848,7 +848,6 @@
"countdown": "Herunterzählen",
"stopwatch": "Stoppuhr",
"gymModeDefaultCountdownTime": "Standard-Countdown-Zeit in Sekunden",
"gymModeNotifyOnCountdownFinish": "Benachrichtigung bei Ende des Countdowns",
"duration": "Dauer",
"durationHoursMinutes": "{hours}h {minutes}m",
"@durationHoursMinutes": {

View File

@@ -375,13 +375,12 @@
"countdown": "Countdown",
"stopwatch": "Stopwatch",
"gymModeDefaultCountdownTime": "Default countdown time, in seconds",
"gymModeNotifyOnCountdownFinish": "Notify on countdown end",
"gymModeRestAlarm": "Rest alarm",
"gymModeRestAlarmHelp": "System notification when the rest is over, also with the screen locked",
"gymModeAlertOnRestEnd": "Alert when rest ends",
"gymModeAlertOnRestEndHelp": "Vibrates in gym mode, or sends a notification when the app is in the background",
"gymModeWorkoutNotification": "Workout notification",
"gymModeExactAlarmMissing": "Without the exact alarm permission, the rest alarm can be a few minutes late",
"gymModeExactAlarmAllow": "Allow",
"gymModeWorkoutNotificationHelp": "Shows the rest and the next set, with buttons to log it or skip the rest",
"gymModeWorkoutNotificationHelp": "While the app is in the background: rest countdown and next set, with buttons to log or skip",
"workoutNotificationRestOver": "Rest is over",
"workoutNotificationNext": "Next: {set}",
"@workoutNotificationNext": {
@@ -411,6 +410,10 @@
"workoutNotificationSkipRest": "Skip rest",
"workoutNotificationNotLoggedTitle": "Set not logged",
"workoutNotificationNotLoggedBody": "Open gym mode to continue the workout",
"workoutNotificationAlarmChannel": "Rest alarm",
"@workoutNotificationAlarmChannel": {
"description": "Name of the Android notification channel for the alert at the end of a rest"
},
"workoutNotificationChannel": "Workout",
"@workoutNotificationChannel": {
"description": "Name of the Android notification channel for the ongoing workout notification"

View File

@@ -838,7 +838,6 @@
"countdown": "Cuenta regresiva",
"stopwatch": "Cronómetro",
"gymModeDefaultCountdownTime": "Tiempo predeterminado de cuenta regresiva, en segundos",
"gymModeNotifyOnCountdownFinish": "Notificar al terminar cuenta regresiva",
"duration": "Duración",
"volume": "Volumen",
"@volume": {

View File

@@ -840,7 +840,6 @@
"countdown": "Compte à rebours",
"stopwatch": "Chronomètre",
"gymModeDefaultCountdownTime": "Temps de compte à rebours par défaut, en secondes",
"gymModeNotifyOnCountdownFinish": "Notifier à la fin du compte à rebours",
"duration": "Durée",
"durationHoursMinutes": "{hours}h {minutes}m",
"@durationHoursMinutes": {

View File

@@ -992,7 +992,6 @@
"countdown": "Odbrojavanje",
"stopwatch": "Štoperica",
"gymModeDefaultCountdownTime": "Zadano vrijeme odbrojavanja, u sekundama",
"gymModeNotifyOnCountdownFinish": "Obavijesti pri kraju odbrojavanja",
"duration": "Trajanje",
"durationHoursMinutes": "{hours} h {minutes} min",
"@durationHoursMinutes": {

View File

@@ -406,7 +406,6 @@
"countdown": "Visszaszámláló",
"stopwatch": "Stopperóra",
"gymModeDefaultCountdownTime": "Alapértelmezett visszaszámlálási idő másodpercben",
"gymModeNotifyOnCountdownFinish": "Értesítés a visszaszámlálás végén",
"duration": "Időtartam",
"durationHoursMinutes": "{hours} ó {minutes} p",
"@durationHoursMinutes": {

View File

@@ -918,7 +918,6 @@
"gymModeTimerTypeHelText": "Jika set memiliki waktu jeda, hitung mundur akan selalu digunakan.",
"countdown": "Hitung Mundur",
"gymModeDefaultCountdownTime": "Waktu hitung mundur default, dalam detik",
"gymModeNotifyOnCountdownFinish": "Beri notifikasi saat hitung mundur selesai",
"duration": "Durasi",
"durationHoursMinutes": "{hours}j {minutes}m",
"@durationHoursMinutes": {

View File

@@ -943,7 +943,6 @@
"countdown": "Conto alla rovescia",
"stopwatch": "Cronometro",
"gymModeDefaultCountdownTime": "Conto alla rovescia di default, in secondi",
"gymModeNotifyOnCountdownFinish": "Notifica quando il conto alla rovescia finisce",
"duration": "Durata",
"durationHoursMinutes": "{hours}h {minutes}m",
"@durationHoursMinutes": {

View File

@@ -550,7 +550,6 @@
"countdown": "Одбројување",
"stopwatch": "Штоперица",
"gymModeDefaultCountdownTime": "Стандардно време на одбројување, во секунди",
"gymModeNotifyOnCountdownFinish": "Извести на крајот од одбројувањето",
"duration": "Времетраење",
"durationHoursMinutes": "{hours}ч {minutes}м",
"@durationHoursMinutes": {

View File

@@ -254,7 +254,6 @@
"countdown": "Afteller",
"stopwatch": "Stopwatch",
"gymModeDefaultCountdownTime": "Standaard afteltijd, in secondes",
"gymModeNotifyOnCountdownFinish": "Notificeer op einde aftelling",
"duration": "Duur",
"durationHoursMinutes": "{hours}u {minutes}m",
"@durationHoursMinutes": {

View File

@@ -834,7 +834,6 @@
"countdown": "Odliczanie",
"stopwatch": "Stoper",
"gymModeDefaultCountdownTime": "Domyślny czas timera, w sekundach",
"gymModeNotifyOnCountdownFinish": "Powiadom na koniec odliczania",
"duration": "Czas trwania",
"durationHoursMinutes": "{hours}h {minutes}m",
"@durationHoursMinutes": {

View File

@@ -850,7 +850,6 @@
"countdown": "Contagem regressiva",
"stopwatch": "Cronômetro",
"gymModeDefaultCountdownTime": "Tempo de contagem regressiva padrão, em segundos",
"gymModeNotifyOnCountdownFinish": "Notificar quando a contagem regressiva terminar",
"duration": "Duração",
"durationHoursMinutes": "{hours}h {minutes}m",
"@durationHoursMinutes": {

View File

@@ -902,7 +902,6 @@
"countdown": "Contagem regressiva",
"stopwatch": "cronômetro",
"gymModeDefaultCountdownTime": "Tempo de contagem regressiva padrão, em segundos",
"gymModeNotifyOnCountdownFinish": "Notificar no final da contagem regressiva",
"duration": "Duração",
"durationHoursMinutes": "{hours}h {minutes}m",
"@durationHoursMinutes": {

View File

@@ -365,7 +365,6 @@
"countdown": "Numărătoare inversă",
"stopwatch": "Cronometru",
"gymModeDefaultCountdownTime": "Timp implicit pentru numărătoare inversă, în secunde",
"gymModeNotifyOnCountdownFinish": "Notifică la finalul numărătorii inverse",
"duration": "Durată",
"durationHoursMinutes": "{hours}h {minutes}m",
"@durationHoursMinutes": {

View File

@@ -884,7 +884,6 @@
"countdown": "Обратный отсчёт",
"stopwatch": "Секундомер",
"gymModeDefaultCountdownTime": "Время обратного отсчёта по умолчанию (в секундах)",
"gymModeNotifyOnCountdownFinish": "Уведомлять об окончании отсчёта",
"duration": "Длительность",
"durationHoursMinutes": "{hours} ч {minutes} мин",
"@durationHoursMinutes": {

View File

@@ -328,7 +328,6 @@
"countdown": "Odštevanje",
"stopwatch": "Štoparica",
"gymModeDefaultCountdownTime": "Privzeti čas za odštevanje, v sekundah",
"gymModeNotifyOnCountdownFinish": "Opomnik ob koncu odštevanja",
"duration": "Trajanje",
"durationHoursMinutes": "{hours} h {minutes} min",
"@durationHoursMinutes": {

View File

@@ -920,7 +920,6 @@
"countdown": "Зворотний відлік",
"stopwatch": "Секундомір",
"gymModeDefaultCountdownTime": "Час зворотного відліку за замовчуванням, у секундах",
"gymModeNotifyOnCountdownFinish": "Повідомити про закінчення зворотного відліку",
"duration": "Тривалість",
"durationHoursMinutes": "{hours}год {minutes}хв",
"@durationHoursMinutes": {

View File

@@ -1021,7 +1021,6 @@
"countdown": "倒數計時",
"stopwatch": "碼表",
"gymModeDefaultCountdownTime": "預設倒數時間(秒)",
"gymModeNotifyOnCountdownFinish": "倒數結束時通知",
"personalRecords": "個人紀錄",
"errorViewDetails": "技術細節",
"errorInfoDescription": "不好意思,目前出了點問題。你可以前往 GitHub 提交問題以幫助我們修復此問題。",

View File

@@ -1472,12 +1472,155 @@ class MockAppLocalizations extends _i1.Mock implements _i2.AppLocalizations {
as String);
@override
String get gymModeNotifyOnCountdownFinish =>
String get gymModeAlertOnRestEnd =>
(super.noSuchMethod(
Invocation.getter(#gymModeNotifyOnCountdownFinish),
Invocation.getter(#gymModeAlertOnRestEnd),
returnValue: _i3.dummyValue<String>(
this,
Invocation.getter(#gymModeNotifyOnCountdownFinish),
Invocation.getter(#gymModeAlertOnRestEnd),
),
)
as String);
@override
String get gymModeAlertOnRestEndHelp =>
(super.noSuchMethod(
Invocation.getter(#gymModeAlertOnRestEndHelp),
returnValue: _i3.dummyValue<String>(
this,
Invocation.getter(#gymModeAlertOnRestEndHelp),
),
)
as String);
@override
String get gymModeWorkoutNotification =>
(super.noSuchMethod(
Invocation.getter(#gymModeWorkoutNotification),
returnValue: _i3.dummyValue<String>(
this,
Invocation.getter(#gymModeWorkoutNotification),
),
)
as String);
@override
String get gymModeExactAlarmMissing =>
(super.noSuchMethod(
Invocation.getter(#gymModeExactAlarmMissing),
returnValue: _i3.dummyValue<String>(
this,
Invocation.getter(#gymModeExactAlarmMissing),
),
)
as String);
@override
String get gymModeExactAlarmAllow =>
(super.noSuchMethod(
Invocation.getter(#gymModeExactAlarmAllow),
returnValue: _i3.dummyValue<String>(
this,
Invocation.getter(#gymModeExactAlarmAllow),
),
)
as String);
@override
String get gymModeWorkoutNotificationHelp =>
(super.noSuchMethod(
Invocation.getter(#gymModeWorkoutNotificationHelp),
returnValue: _i3.dummyValue<String>(
this,
Invocation.getter(#gymModeWorkoutNotificationHelp),
),
)
as String);
@override
String get workoutNotificationRestOver =>
(super.noSuchMethod(
Invocation.getter(#workoutNotificationRestOver),
returnValue: _i3.dummyValue<String>(
this,
Invocation.getter(#workoutNotificationRestOver),
),
)
as String);
@override
String get workoutNotificationInProgress =>
(super.noSuchMethod(
Invocation.getter(#workoutNotificationInProgress),
returnValue: _i3.dummyValue<String>(
this,
Invocation.getter(#workoutNotificationInProgress),
),
)
as String);
@override
String get workoutNotificationLogSet =>
(super.noSuchMethod(
Invocation.getter(#workoutNotificationLogSet),
returnValue: _i3.dummyValue<String>(
this,
Invocation.getter(#workoutNotificationLogSet),
),
)
as String);
@override
String get workoutNotificationSkipRest =>
(super.noSuchMethod(
Invocation.getter(#workoutNotificationSkipRest),
returnValue: _i3.dummyValue<String>(
this,
Invocation.getter(#workoutNotificationSkipRest),
),
)
as String);
@override
String get workoutNotificationNotLoggedTitle =>
(super.noSuchMethod(
Invocation.getter(#workoutNotificationNotLoggedTitle),
returnValue: _i3.dummyValue<String>(
this,
Invocation.getter(#workoutNotificationNotLoggedTitle),
),
)
as String);
@override
String get workoutNotificationNotLoggedBody =>
(super.noSuchMethod(
Invocation.getter(#workoutNotificationNotLoggedBody),
returnValue: _i3.dummyValue<String>(
this,
Invocation.getter(#workoutNotificationNotLoggedBody),
),
)
as String);
@override
String get workoutNotificationAlarmChannel =>
(super.noSuchMethod(
Invocation.getter(#workoutNotificationAlarmChannel),
returnValue: _i3.dummyValue<String>(
this,
Invocation.getter(#workoutNotificationAlarmChannel),
),
)
as String);
@override
String get workoutNotificationChannel =>
(super.noSuchMethod(
Invocation.getter(#workoutNotificationChannel),
returnValue: _i3.dummyValue<String>(
this,
Invocation.getter(#workoutNotificationChannel),
),
)
as String);
@@ -3687,6 +3830,17 @@ class MockAppLocalizations extends _i1.Mock implements _i2.AppLocalizations {
)
as String);
@override
String get authorHelpText =>
(super.noSuchMethod(
Invocation.getter(#authorHelpText),
returnValue: _i3.dummyValue<String>(
this,
Invocation.getter(#authorHelpText),
),
)
as String);
@override
String get imageDetailsAuthorLink =>
(super.noSuchMethod(
@@ -5554,6 +5708,28 @@ class MockAppLocalizations extends _i1.Mock implements _i2.AppLocalizations {
)
as String);
@override
String workoutNotificationNext(String? set) =>
(super.noSuchMethod(
Invocation.method(#workoutNotificationNext, [set]),
returnValue: _i3.dummyValue<String>(
this,
Invocation.method(#workoutNotificationNext, [set]),
),
)
as String);
@override
String workoutNotificationSetOf(int? current, int? total) =>
(super.noSuchMethod(
Invocation.method(#workoutNotificationSetOf, [current, total]),
returnValue: _i3.dummyValue<String>(
this,
Invocation.method(#workoutNotificationSetOf, [current, total]),
),
)
as String);
@override
String durationHoursMinutes(int? hours, int? minutes) =>
(super.noSuchMethod(

View File

@@ -91,7 +91,7 @@ void main() {
});
test('No alarm when the setting is off', () {
notifier.state = notifier.state.copyWith(restAlarmEnabled: false);
notifier.state = notifier.state.copyWith(alertOnCountdownEnd: false);
onPage(timers().first, restStartedAt: now, restEndsAt: now.add(const Duration(seconds: 90)));
final target = build();

View File

@@ -190,7 +190,7 @@ void main() {
test('Each setting only switches off its own notification', () async {
initGymMode();
gymState.state = gymState.state.copyWith(restAlarmEnabled: false);
gymState.state = gymState.state.copyWith(alertOnCountdownEnd: false);
await startRest();
verifyNever(service.scheduleRestAlarm(any, any));
verify(service.showControls(any, any));
@@ -198,7 +198,7 @@ void main() {
clearInteractions(service);
await withClock(Clock.fixed(now), () async {
gymState.state = gymState.state.copyWith(
restAlarmEnabled: true,
alertOnCountdownEnd: true,
showWorkoutNotification: false,
);
await settle();

View File

@@ -525,30 +525,30 @@ void main() {
test('Both are on without stored preferences', () async {
await notifier.loadPrefs();
expect(notifier.state.restAlarmEnabled, isTrue);
expect(notifier.state.alertOnCountdownEnd, isTrue);
expect(notifier.state.showWorkoutNotification, isTrue);
});
test('Stored values are loaded', () async {
await PreferenceHelper.asyncPref.setBool(PREFS_REST_ALARM, false);
await PreferenceHelper.asyncPref.setBool(PREFS_ALERT_COUNTDOWN, false);
await PreferenceHelper.asyncPref.setBool(PREFS_WORKOUT_NOTIFICATION, false);
await notifier.loadPrefs();
expect(notifier.state.restAlarmEnabled, isFalse);
expect(notifier.state.alertOnCountdownEnd, isFalse);
expect(notifier.state.showWorkoutNotification, isFalse);
});
test('The setters change only their own flag and persist it', () async {
notifier.setRestAlarmEnabled(false);
notifier.setAlertOnCountdownEnd(false);
await pumpEventQueue();
expect(notifier.state.restAlarmEnabled, isFalse);
expect(notifier.state.alertOnCountdownEnd, isFalse);
expect(notifier.state.showWorkoutNotification, isTrue);
expect(await PreferenceHelper.asyncPref.getBool(PREFS_REST_ALARM), false);
expect(await PreferenceHelper.asyncPref.getBool(PREFS_ALERT_COUNTDOWN), false);
notifier.setShowWorkoutNotification(false);
await pumpEventQueue();
expect(notifier.state.restAlarmEnabled, isFalse);
expect(notifier.state.alertOnCountdownEnd, isFalse);
expect(notifier.state.showWorkoutNotification, isFalse);
expect(await PreferenceHelper.asyncPref.getBool(PREFS_WORKOUT_NOTIFICATION), false);
});

View File

@@ -608,10 +608,10 @@ void main() {
testWidgets(
'no permission request with both notification settings off',
(WidgetTester tester) async {
await PreferenceHelper.asyncPref.setBool(PREFS_REST_ALARM, false);
await PreferenceHelper.asyncPref.setBool(PREFS_ALERT_COUNTDOWN, false);
await PreferenceHelper.asyncPref.setBool(PREFS_WORKOUT_NOTIFICATION, false);
addTearDown(() async {
await PreferenceHelper.asyncPref.remove(PREFS_REST_ALARM);
await PreferenceHelper.asyncPref.remove(PREFS_ALERT_COUNTDOWN);
await PreferenceHelper.asyncPref.remove(PREFS_WORKOUT_NOTIFICATION);
});

View File

@@ -63,7 +63,6 @@ void main() {
showTimerPages: true,
useCountdownBetweenSets: true,
countdownDuration: const Duration(seconds: DEFAULT_COUNTDOWN_DURATION),
alertOnCountdownEnd: false,
dayId: routine.days.first.id,
iteration: 1,
routine: routine,
@@ -102,18 +101,13 @@ void main() {
await tester.tap(optionsTile);
await tester.pumpAndSettle();
// Toggle notify countdown first (it is only enabled while timer/countdown are active)
// Toggle the rest end alert first (it is only enabled while timer pages are shown)
final notifySwitch = find.byKey(const ValueKey('gym-mode-notify-countdown'));
expect(notifySwitch, findsOneWidget);
await tester.ensureVisible(notifySwitch);
await tester.tap(notifySwitch);
await tester.pump();
// The rest alarm is only enabled while timer pages are shown
final restAlarmSwitch = find.byKey(const ValueKey('gym-mode-rest-alarm'));
await tester.ensureVisible(restAlarmSwitch);
await tester.tap(restAlarmSwitch);
await tester.pump();
final workoutNotificationSwitch = find.byKey(const ValueKey('gym-mode-workout-notification'));
await tester.ensureVisible(workoutNotificationSwitch);
await tester.tap(workoutNotificationSwitch);
@@ -143,12 +137,27 @@ void main() {
final notifier = container.read(gymStateProvider.notifier);
expect(notifier.state.showExercisePages, isFalse);
expect(notifier.state.showTimerPages, isFalse);
expect(notifier.state.alertOnCountdownEnd, isTrue);
expect(notifier.state.alertOnCountdownEnd, isFalse);
expect(notifier.state.showWorkoutDuration, isFalse);
expect(notifier.state.restAlarmEnabled, isFalse);
expect(notifier.state.showWorkoutNotification, isFalse);
});
testWidgets('The rest end alert works without the default countdown', (tester) async {
// A set's own rest time is counted down regardless of the setting
final notifier = container.read(gymStateProvider.notifier);
notifier.setUseCountdownBetweenSets(false);
await pumpGymModeOptions(tester);
await tester.tap(find.byKey(const ValueKey('gym-mode-options-tile')));
await tester.pumpAndSettle();
final alertSwitch = find.byKey(const ValueKey('gym-mode-notify-countdown'));
await tester.ensureVisible(alertSwitch);
await tester.tap(alertSwitch);
await tester.pump();
expect(notifier.state.alertOnCountdownEnd, isFalse);
});
testWidgets('The workout notification switch only shows on Android', (tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
addTearDown(() => debugDefaultTargetPlatformOverride = null);
@@ -157,7 +166,7 @@ void main() {
await tester.tap(find.byKey(const ValueKey('gym-mode-options-tile')));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('gym-mode-rest-alarm')), findsOneWidget);
expect(find.byKey(const ValueKey('gym-mode-notify-countdown')), findsOneWidget);
expect(find.byKey(const ValueKey('gym-mode-workout-notification')), findsNothing);
debugDefaultTargetPlatformOverride = null;
});
@@ -303,13 +312,13 @@ void main() {
expect(hint, findsNothing);
});
testWidgets('Not shown with the permission or with the rest alarm off', (tester) async {
testWidgets('Not shown with the permission or with the rest end alert off', (tester) async {
await openOptions(tester);
expect(hint, findsNothing);
when(notificationService.canScheduleExactAlarms()).thenAnswer((_) async => false);
container.invalidate(exactAlarmsAllowedProvider);
container.read(gymStateProvider.notifier).setRestAlarmEnabled(false);
container.read(gymStateProvider.notifier).setAlertOnCountdownEnd(false);
await tester.pumpAndSettle();
expect(hint, findsNothing);
});