Skip to content

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

Keep two decimals for quarter-kilo weights

InlitXed6d247f4e95
diff --git a/lib/screens/routine_edit_screen.dart b/lib/screens/routine_edit_screen.dart
index edcdf17..b05cf96 100644
--- a/lib/screens/routine_edit_screen.dart
+++ b/lib/screens/routine_edit_screen.dart
@@ -967,7 +967,7 @@ class _RoutineEditScreenState extends State<RoutineEditScreen> {
t.weightTitle(fit.units.toUpperCase()),
p.weightKg == null ? (fit.isLb ? 45 : 20) : fit.toDisplayWeight(p.weightKg!),
fit.isLb ? 660 : 300,
- fit.isLb ? 1 : 0.5,
+ fit.rulerStep,
10,
fit.units,
(v) => edit(i, v <= 0 ? p.copyWith(autoWeight: true) : p.copyWith(weightKg: fit.fromDisplayWeight(v)))),
diff --git a/lib/screens/session_screen.dart b/lib/screens/session_screen.dart
index d434304..b6caca4 100644
--- a/lib/screens/session_screen.dart
+++ b/lib/screens/session_screen.dart
@@ -1299,7 +1299,7 @@ class SessionScreen extends StatelessWidget {
title: t.weightTitle(fit.units.toUpperCase()),
value: fit.toDisplayWeight(st.weight),
max: fit.isLb ? 660 : 300,
- step: fit.isLb ? 1 : 0.5,
+ step: fit.rulerStep,
majorEvery: 10,
unit: fit.units,
onSave: (v) => fit.setSessionWeightShown(exIdx, j, v),
diff --git a/lib/state/fit_core.dart b/lib/state/fit_core.dart
index 2bcdd7e..f9db515 100644
--- a/lib/state/fit_core.dart
+++ b/lib/state/fit_core.dart
@@ -6,6 +6,10 @@ String fmt(num n) {
}
double _round1(double n) => (n * 10).round() / 10;
+double _roundWeight(double n) {
+ final quarter = (n * 4).round() / 4;
+ return (n - quarter).abs() < 0.005 ? quarter : _round1(n);
+}
double _round3(double n) => (n * 1000).round() / 1000;
double _roundTo(double n, double step) => (n / step).round() * step;
DateTime _dayKey(DateTime d) => DateTime(d.year, d.month, d.day);
@@ -207,11 +211,13 @@ abstract class FitCore extends ChangeNotifier {
double fromDisplayWeight(double shown) => isLb ? shown / _lbPerKg : shown;
- String weightLabel(double kg) => '${fmt(_round1(toDisplayWeight(kg)))} $units';
+ String weightLabel(double kg) => '${fmt(_roundWeight(toDisplayWeight(kg)))} $units';
- String weightValue(double kg) => fmt(_round1(toDisplayWeight(kg)));
+ String weightValue(double kg) => fmt(_roundWeight(toDisplayWeight(kg)));
double get weightStep => isLb ? stepLb : stepKg;
+
+ double get rulerStep => isLb ? (stepLb == 2.5 ? 0.5 : 1) : (stepKg == 1.25 ? 0.25 : 0.5);
double get plateStep => isLb ? 5 : 2.5;
String get volumeUnit => isLb ? 'k lb' : 't';
diff --git a/lib/state/tools_state.dart b/lib/state/tools_state.dart
index 89c5dd7..4d05c63 100644
--- a/lib/state/tools_state.dart
+++ b/lib/state/tools_state.dart
@@ -136,16 +136,16 @@ mixin ToolsState on FitCore {
double get defaultBar {
final placeBar = placeBarKg;
- if (placeBar != null) return _round1(toDisplayWeight(placeBar));
+ if (placeBar != null) return _roundWeight(toDisplayWeight(placeBar));
final own = plateBar;
- if (own != null) return _round1(toDisplayWeight(own));
+ if (own != null) return _roundWeight(toDisplayWeight(own));
return isLb ? 45 : 20;
}
Map<double, int>? get plateStockDisplay {
final stock = plateStockKg;
if (stock == null) return null;
- return {for (final e in stock.entries) _round1(toDisplayWeight(e.key)): e.value};
+ return {for (final e in stock.entries) _roundWeight(toDisplayWeight(e.key)): e.value};
}
List<({double weight, int count})> platesPerSide(double displayTarget, double displayBar) {
@@ -175,7 +175,7 @@ mixin ToolsState on FitCore {
double barFor(String id, {String equipment = 'Barbell'}) {
final kg = exerciseBar[id];
- if (kg != null) return _round1(toDisplayWeight(kg));
+ if (kg != null) return _roundWeight(toDisplayWeight(kg));
return equipment == 'Barbell' ? defaultBar : 0;
}
@@ -192,7 +192,7 @@ mixin ToolsState on FitCore {
String? plateHint(String equipment, double weightKg, {String id = ''}) {
if (equipment != 'Barbell' && !hasOwnBar(id)) return null;
final bar = barFor(id, equipment: equipment);
- final target = _round1(toDisplayWeight(weightKg));
+ final target = _roundWeight(toDisplayWeight(weightKg));
if (target <= bar) return null;
final parts = platesPerSide(target, bar);
if (parts.isEmpty) return null;
@@ -271,7 +271,7 @@ mixin ToolsState on FitCore {
double get plateBarDisplay {
final own = plateBar;
- return own == null ? (isLb ? 45 : 20) : _round1(toDisplayWeight(own));
+ return own == null ? (isLb ? 45 : 20) : _roundWeight(toDisplayWeight(own));
}
static double _effortShare(int reps, double rpe) => rpePercent(reps, rpe) ?? 1 / (1 + reps / 30);