Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
Muscle balance Week lines up; the status bar no longer covers the page on more phones (#573)
Duarte Santosf478f00dae33
diff --git a/frontend/android/app/src/main/java/ch/duartesantos/opengym/MainActivity.java b/frontend/android/app/src/main/java/ch/duartesantos/opengym/MainActivity.javaindex 49dff985c..94c6b1507 100644--- a/frontend/android/app/src/main/java/ch/duartesantos/opengym/MainActivity.java+++ b/frontend/android/app/src/main/java/ch/duartesantos/opengym/MainActivity.java@@ -11,10 +11,13 @@ import com.getcapacitor.BridgeActivity;import com.getcapacitor.WebViewListener;public class MainActivity extends BridgeActivity {- // Where the status bar (or the camera cutout) ends and the navigation bar starts, in CSS- // pixels; negative until the window has said.+ // How much of the status bar (or the camera cutout) and of the navigation bar lies over the+ // page, in CSS pixels, as last passed to it; and the bars themselves in window pixels,+ // negative until the window has said.private float barTop = -1;private float barBottom = -1;+ private int barTopPx = -1;+ private int barBottomPx = -1;// How much of the page the soft keyboard covers, in CSS pixels; 0 while it is down.private float keyboard = 0;@@ -44,11 +47,16 @@ public class MainActivity extends BridgeActivity {* env(safe-area-inset-*), and on some cold starts not even that, so the tab bar sat under the* navigation bar (with three buttons, a tap on a tab hit Home or Recents) and now and then the* header sat under the status bar. The window's own insets go to the page as --native-sat and- * --native-sab, which index.css takes over env() wherever they are larger. Before Android 15- * the window stops at the bars and there is nothing to pass.+ * --native-sab, which index.css takes over env() wherever they are larger.+ *+ * Only the part of a bar that actually lies over the WebView is passed (#573): some systems+ * (a Fairphone on Murena OS) draw the app under the status bar before Android 15 too, and on+ * a system that stops the window at the bars nothing overlaps and 0 goes to the page. Worked+ * out from where the WebView sits, after every layout, so an inset that arrives before the+ * first layout is not taken for an overlap.*/private void passSystemBarsToPage() {- if (Build.VERSION.SDK_INT < 35 || bridge == null) return;+ if (bridge == null) return;WebView web = bridge.getWebView();if (web == null || !(web.getParent() instanceof View)) return;// Read on the WebView's parent, which hands them on to the WebView untouched. A listener on@@ -57,9 +65,9 @@ public class MainActivity extends BridgeActivity {View holder = (View) web.getParent();ViewCompat.setOnApplyWindowInsetsListener(holder, (v, insets) -> {Insets bars = insets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout());+ barTopPx = bars.top;+ barBottomPx = bars.bottom;float density = v.getResources().getDisplayMetrics().density;- barTop = bars.top / density;- barBottom = bars.bottom / density;float kb = coveredByKeyboard(v, insets.getInsets(WindowInsetsCompat.Type.ime()).bottom) / density;boolean kbChanged = kb != keyboard;keyboard = kb;@@ -67,6 +75,7 @@ public class MainActivity extends BridgeActivity {if (kbChanged) web.evaluateJavascript(keyboardScript(keyboard), null);return ViewCompat.onApplyWindowInsets(v, insets);});+ holder.addOnLayoutChangeListener((v, l, t, r, b, ol, ot, or, ob) -> applyBars(web));// A page that loads (the first one, or a reload) starts without them.bridge.addWebViewListener(new WebViewListener() {@Override@@ -78,6 +87,16 @@ public class MainActivity extends BridgeActivity {ViewCompat.requestApplyInsets(holder);}+ /** How much of a top bar `barPx` tall lies over a view whose top is `viewTop` (window px). */+ static int overlapTop(int barPx, int viewTop) {+ return Math.max(0, barPx - Math.max(0, viewTop));+ }++ /** The same for a bottom bar, with the window `windowHeight` tall and the view ending at `viewBottom`. */+ static int overlapBottom(int barPx, int viewBottom, int windowHeight) {+ return Math.max(0, barPx - Math.max(0, windowHeight - viewBottom));+ }+/*** Edge to edge, adjustResize no longer shrinks the window for the soft keyboard: the WebView* keeps its full height, innerHeight and visualViewport do not move, and a bottom sheet stays@@ -95,7 +114,16 @@ public class MainActivity extends BridgeActivity {}private void applyBars(WebView web) {- if (barTop < 0 || barBottom < 0) return;+ if (barTopPx < 0 || barBottomPx < 0 || web == null) return;+ int[] at = new int[2];+ web.getLocationInWindow(at);+ int windowHeight = web.getRootView().getHeight();+ float density = web.getResources().getDisplayMetrics().density;+ float top = overlapTop(barTopPx, at[1]) / density;+ float bottom = windowHeight > 0 ? overlapBottom(barBottomPx, at[1] + web.getHeight(), windowHeight) / density : 0;+ if (top == barTop && bottom == barBottom) return;+ barTop = top;+ barBottom = bottom;web.evaluateJavascript(barsScript(barTop, barBottom), null);}diff --git a/frontend/android/app/src/test/java/ch/duartesantos/opengym/SystemBarsOverlapTest.java b/frontend/android/app/src/test/java/ch/duartesantos/opengym/SystemBarsOverlapTest.javanew file mode 100644index 000000000..1dc55e561--- /dev/null+++ b/frontend/android/app/src/test/java/ch/duartesantos/opengym/SystemBarsOverlapTest.java@@ -0,0 +1,27 @@+package ch.duartesantos.opengym;++import static org.junit.Assert.*;++import org.junit.Test;++/** How much of a system bar lies over the page (MainActivity.overlapTop/overlapBottom, #573). */+public class SystemBarsOverlapTest {+ @Test+ public void edgeToEdgeThePageIsUnderTheWholeBar() {+ assertEquals(84, MainActivity.overlapTop(84, 0));+ assertEquals(63, MainActivity.overlapBottom(63, 2400, 2400));+ }++ @Test+ public void aWindowThatStopsAtTheBarsHasNothingUnderThem() {+ assertEquals(0, MainActivity.overlapTop(84, 84));+ assertEquals(0, MainActivity.overlapBottom(63, 2337, 2400));+ }++ @Test+ public void partlyUnderPassesThePartOnly() {+ assertEquals(24, MainActivity.overlapTop(84, 60));+ assertEquals(13, MainActivity.overlapBottom(63, 2350, 2400));+ assertEquals(0, MainActivity.overlapTop(0, 0));+ }+}diff --git a/frontend/src/index.css b/frontend/src/index.cssindex 6517603db..c8656bb1d 100644--- a/frontend/src/index.css+++ b/frontend/src/index.css@@ -1698,6 +1698,9 @@ body.no-tabbar #timer.working{box-shadow:inset 0 var(--hair) 0 var(--acc),0 -10p.mrow .bar{width:74px;height:5px;border-radius:3px;background:var(--surface-2);flex:none;overflow:hidden}.mrow .bar i{display:block;height:100%;background:var(--acc);border-radius:3px}.mrow .v{font-size:12px;color:var(--label-2);min-width:52px;text-align: end;flex:none}+/* The Week view's "done/planned · %" (#573): wider than a set count, and as wide on every row, so+ the bars line up the way they do in 30d, 90d and All. */+.mrow .v.cmp{min-width:92px;font-variant-numeric:tabular-nums;white-space:nowrap}/* A headline number inside a card — tile weight without a tile around it, for the pair ofreadings at the top of the effort card. */.stat-v{font-size:26px;font-weight:600;letter-spacing:-.026em;line-height:1.1}diff --git a/frontend/src/views/Stats.jsx b/frontend/src/views/Stats.jsxindex 95607b554..0decc6ec2 100644--- a/frontend/src/views/Stats.jsx+++ b/frontend/src/views/Stats.jsx@@ -185,7 +185,7 @@ function MuscleBalance({ S }) {return <div className="mrow" data-muscle-volume={muscle} key={muscle}><span className="nm">{sel === muscle ? <b>{t(MUSCLE_NAME[muscle])}</b> : t(MUSCLE_NAME[muscle])}</span><span className="bar"><i style={{ width: fill + '%' }} /></span>- <span className="v" style={{ textAlign: 'end' }}+ <span className="v cmp"aria-label={`${t('Completed')} ${completedSets} · ${t('Planned')} ${plannedSets}`}>{fmtNum(completed)}/{fmtNum(target)}{percentage == null ? '' : ` · ${percentage}%`}</span>diff --git a/frontend/src/views/Stats.weekly-volume.test.jsx b/frontend/src/views/Stats.weekly-volume.test.jsxindex 4f2504ccd..34f412180 100644--- a/frontend/src/views/Stats.weekly-volume.test.jsx+++ b/frontend/src/views/Stats.weekly-volume.test.jsx@@ -71,6 +71,8 @@ describe('Stats — weekly planned vs completed volume', () => {expect([...comparison().querySelectorAll('[data-muscle-volume]')].map(item => item.dataset.muscleVolume)).toEqual(['chest', 'biceps', 'triceps'])expect(value('chest').textContent).toBe('8/12 · 67%')+ // #573: every row's figure is the same fixed-width kind, so the bars line up+ for (const m of ['chest', 'biceps', 'triceps']) expect(value(m).classList.contains('cmp'), m).toBe(true)expect(value('chest').getAttribute('aria-label')).toBe('Completed 8 sets · Planned 12 sets')expect(bar('chest').style.width).toBe('67%')expect(value('triceps').textContent).toBe('0/4.8 · 0%')