Skip to content

Offline gym log for Android. No account, no ads, no internet.

Ring the rest alarm in the background and leave the Now Bar at zero

InlitX9631c622660b
diff --git a/android/app/src/main/kotlin/com/gymmane/app/LiveNotifier.kt b/android/app/src/main/kotlin/com/gymmane/app/LiveNotifier.kt
index 061edbb..b6b9847 100644
--- a/android/app/src/main/kotlin/com/gymmane/app/LiveNotifier.kt
+++ b/android/app/src/main/kotlin/com/gymmane/app/LiveNotifier.kt
@@ -38,6 +38,7 @@ object LiveNotifier {
private var font: Typeface? = null
private var flashId = -1
private var flashUntil = 0L
+ private var endedRest = 0L
private val tick = Runnable { repost() }
fun update(ctx: Context, a: Map<*, *>) {
@@ -62,9 +63,10 @@ object LiveNotifier {
val detail = a["detail"] as? String ?: ""
val restLabel = a["restLabel"] as? String ?: ""
val next = a["next"] as? String
- val resting = a["resting"] as? Boolean ?: false
val paused = a["paused"] as? Boolean ?: false
val restEnd = (a["restEnd"] as? Number)?.toLong() ?: 0L
+ val restOver = (a["resting"] as? Boolean ?: false) && restEnd <= now
+ val resting = (a["resting"] as? Boolean ?: false) && !restOver
val startedAt = (a["startedAt"] as? Number)?.toLong() ?: 0L
val index = (a["index"] as? Number)?.toInt() ?: 0
val total = (a["total"] as? Number)?.toInt() ?: 0
@@ -72,8 +74,12 @@ object LiveNotifier {
val done = (a["done"] as? List<*>)?.map { it == true } ?: emptyList()
val progress = (a["progress"] as? Number)?.toInt() ?: 0
val chip = a["chip"] as? String
+ if (restOver && endedRest != restEnd) {
+ endedRest = restEnd
+ dart?.invokeMethod("action", "restEnd")
+ }
val flash = if (now < flashUntil) a["flash"] as? String else null
- val actions = (a["actions"] as? List<*>)?.mapNotNull { it as? Map<*, *> } ?: emptyList()
+ val actions = (a[if (restOver) "afterRest" else "actions"] as? List<*>)?.mapNotNull { it as? Map<*, *> } ?: emptyList()
val accent = ctx.getColor(if (paused) R.color.live_pause else R.color.live_accent)
val green = ctx.getColor(R.color.live_done)
val left = if (resting) ((restEnd - now + 999) / 1000).coerceAtLeast(0) else 0L
@@ -160,6 +166,7 @@ object LiveNotifier {
wait = 1000L - (now - startedAt).mod(1000L) + 15L
}
}
+ if (resting && !paused) wait = minOf(wait, restEnd - now + 15)
if (flashUntil > now) wait = minOf(wait, flashUntil - now + 15)
if (wait != Long.MAX_VALUE) main.postDelayed(tick, wait)
}
diff --git a/lib/services/live_workout.dart b/lib/services/live_workout.dart
index 599e2fd..ebe6455 100644
--- a/lib/services/live_workout.dart
+++ b/lib/services/live_workout.dart
@@ -93,20 +93,21 @@ class LiveWorkout {
: '${pendingIdx < 0 ? ex.sets.length : pendingIdx + 1}/${ex.sets.length}';
final finished = [for (final e in s.exercises) e.sets.isNotEmpty && e.sets.every((st) => st.done)];
final flashing = _flashAt != null && DateTime.now().difference(_flashAt!) < const Duration(seconds: 2);
- final actions = <(String, String)>[
- if (paused)
- ('pause', '▶ ${t.liveResume}')
- else ...[
- if (resting) ...[
- ('add', '+15 s'),
- ('skip', '${t.liveSkipRest} ›'),
- ] else if (pendingIdx >= 0)
- ('done', '✓ ${t.liveDoneSet}')
- else if (nextEx != null)
- ('next', '${t.liveNext} ›'),
- ('pause', '❚❚ ${t.livePause}'),
- ],
- ];
+ List<(String, String)> actionsFor(bool resting) => [
+ if (paused)
+ ('pause', '▶ ${t.liveResume}')
+ else ...[
+ if (resting) ...[
+ ('add', '+15 s'),
+ ('skip', '${t.liveSkipRest} ›'),
+ ] else if (pendingIdx >= 0)
+ ('done', '✓ ${t.liveDoneSet}')
+ else if (nextEx != null)
+ ('next', '${t.liveNext} ›'),
+ ('pause', '❚❚ ${t.livePause}'),
+ ],
+ ];
+ final actions = actionsFor(resting);
final key = [
name, detail, index, total, resting ? restEnd.millisecondsSinceEpoch : 0, paused, position,
@@ -151,6 +152,9 @@ class LiveWorkout {
'actions': [
for (final (id, label) in actions) {'id': id, 'label': label},
],
+ 'afterRest': [
+ for (final (id, label) in actionsFor(false)) {'id': id, 'label': label},
+ ],
});
} catch (e) {
_lastKey = '';
@@ -176,6 +180,8 @@ class LiveWorkout {
fit.skipRest();
case 'next':
fit.goNextPending();
+ case 'restEnd':
+ fit.restElapsed();
}
}
diff --git a/lib/services/rest_alarm.dart b/lib/services/rest_alarm.dart
index 04e4cc1..7cb0912 100644
--- a/lib/services/rest_alarm.dart
+++ b/lib/services/rest_alarm.dart
@@ -212,8 +212,13 @@ class RestAlarm {
}
Future<void> fireNow() async {
- await cancel();
final visible = WidgetsBinding.instance.lifecycleState == AppLifecycleState.resumed;
+ final custom = customSoundPath?.isNotEmpty ?? false;
+ if (_ready && !visible && !custom && Platform.isAndroid) {
+ _generation++;
+ return;
+ }
+ await cancel();
if (_ready && !visible) {
try {