Skip to content

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

Watch app: crown scrolling, round-screen lists, dim mode and settings

InlitX78493abf082e
diff --git a/android/app/src/main/kotlin/com/gymmane/app/MainActivity.kt b/android/app/src/main/kotlin/com/gymmane/app/MainActivity.kt
index 8587e9c..ac74252 100644
--- a/android/app/src/main/kotlin/com/gymmane/app/MainActivity.kt
+++ b/android/app/src/main/kotlin/com/gymmane/app/MainActivity.kt
@@ -11,6 +11,9 @@ import android.os.VibrationEffect
import android.os.Vibrator
import android.os.VibratorManager
import android.provider.MediaStore
+import android.view.InputDevice
+import android.view.MotionEvent
+import android.view.ViewConfiguration
import android.view.WindowManager
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
@@ -20,6 +23,7 @@ import java.io.FileOutputStream
class MainActivity : FlutterActivity() {
private var incomingChannel: MethodChannel? = null
+ private var rotaryChannel: MethodChannel? = null
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
@@ -63,19 +67,29 @@ class MainActivity : FlutterActivity() {
}
MethodChannel(messenger, "gymmane/screen").setMethodCallHandler { call, result ->
- if (call.method != "keepOn") {
- result.notImplemented()
- return@setMethodCallHandler
- }
val on = call.argument<Boolean>("on") ?: false
- if (on) {
- window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
- } else {
- window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
+ when (call.method) {
+ "keepOn" -> {
+ if (on) {
+ window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
+ } else {
+ window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
+ }
+ result.success(null)
+ }
+ "dim" -> {
+ val params = window.attributes
+ params.screenBrightness =
+ if (on) 0.02f else WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
+ window.attributes = params
+ result.success(null)
+ }
+ else -> result.notImplemented()
}
- result.success(null)
}
+ rotaryChannel = MethodChannel(messenger, "gymmane/rotary")
+
val live = MethodChannel(messenger, "gymmane/live")
live.setMethodCallHandler { call, result ->
when (call.method) {
@@ -102,7 +116,25 @@ class MainActivity : FlutterActivity() {
}
}
+ override fun dispatchGenericMotionEvent(event: MotionEvent): Boolean {
+ val channel = rotaryChannel
+ if (channel != null &&
+ event.action == MotionEvent.ACTION_SCROLL &&
+ event.isFromSource(InputDevice.SOURCE_ROTARY_ENCODER)
+ ) {
+ val factor = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ ViewConfiguration.get(this).scaledVerticalScrollFactor
+ } else {
+ 64f
+ }
+ channel.invokeMethod("scroll", (-event.getAxisValue(MotionEvent.AXIS_SCROLL) * factor).toDouble())
+ return true
+ }
+ return super.dispatchGenericMotionEvent(event)
+ }
+
override fun cleanUpFlutterEngine(flutterEngine: FlutterEngine) {
+ rotaryChannel = null
LiveNotifier.dart = null
if (isFinishing) LiveNotifier.cancel(this)
super.cleanUpFlutterEngine(flutterEngine)
diff --git a/lib/main.dart b/lib/main.dart
index 477651b..0ad0941 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -35,6 +35,7 @@ Future<void> main() async {
fit.syncTrainReminder();
final watch = await DeviceKind.isWatch();
+ _onWatch = watch;
fit.addListener(_sessionSideEffects);
_sessionSideEffects();
@@ -49,8 +50,10 @@ Future<void> main() async {
WidgetsBinding.instance.addPostFrameCallback((_) => HomeWidgetBridge.update());
}
+bool _onWatch = false;
+
void _sessionSideEffects() {
- LiveWorkout.sync();
+ if (!_onWatch) LiveWorkout.sync();
final live = fit.isSessionActive && fit.session?.manual == false;
ScreenAwake.keepOn(fit.keepScreenOn && live);
}
diff --git a/lib/services/screen_awake.dart b/lib/services/screen_awake.dart
index 60c9ee1..d6ed26b 100644
--- a/lib/services/screen_awake.dart
+++ b/lib/services/screen_awake.dart
@@ -6,6 +6,18 @@ class ScreenAwake {
static const _channel = MethodChannel('gymmane/screen');
static bool? _last;
+ static bool? _dimmed;
+
+ static Future<void> dim(bool on) async {
+ if (kIsWeb || _dimmed == on) return;
+ _dimmed = on;
+ try {
+ await _channel.invokeMethod<void>('dim', {'on': on});
+ } catch (e) {
+ _dimmed = null;
+ debugPrint('ScreenAwake no disponible: $e');
+ }
+ }
static Future<void> keepOn(bool on) async {
if (kIsWeb || _last == on) return;
diff --git a/lib/wear/wear_shell.dart b/lib/wear/wear_shell.dart
index 45e2e7e..39c8385 100644
--- a/lib/wear/wear_shell.dart
+++ b/lib/wear/wear_shell.dart
@@ -1,3 +1,4 @@
+import 'dart:async';
import 'dart:math' as math;
import 'package:flutter/material.dart';
@@ -8,9 +9,46 @@ import '../catalog/program_templates.dart';
import '../l10n/l10n.dart';
import '../models/live_session.dart';
import '../models/workout.dart';
+import '../services/screen_awake.dart';
import '../state/fit_state.dart';
import '../theme/app_colors.dart';
import '../theme/app_theme.dart';
+import '../widgets/timer_panel.dart';
+import '../widgets/ui_kit.dart' show sentenceCase;
+
+class WearRotary {
+ WearRotary._();
+
+ static const _channel = MethodChannel('gymmane/rotary');
+ static final List<ScrollController> _stack = [];
+ static VoidCallback? onTurn;
+
+ static void init() {
+ _channel.setMethodCallHandler((call) async {
+ if (call.method != 'scroll') return;
+ turn((call.arguments as num).toDouble());
+ });
+ }
+
+ static void turn(double delta) {
+ onTurn?.call();
+ final c = _stack.isEmpty ? null : _stack.last;
+ if (c == null || !c.hasClients) return;
+ final p = c.position;
+ c.jumpTo((p.pixels + delta).clamp(p.minScrollExtent, p.maxScrollExtent));
+ }
+
+ static void attach(ScrollController c) => _stack.add(c);
+
+ static void detach(ScrollController c) => _stack.remove(c);
+}
+
+String _cap(String s) {
+ final out = sentenceCase(s);
+ final i = out.indexOf(RegExp(r'\p{L}', unicode: true));
+ if (i <= 0) return out;
+ return out.substring(0, i) + out[i].toUpperCase() + out.substring(i + 1);
+}
class WearShell extends StatefulWidget {
const WearShell({super.key});
@@ -20,19 +58,68 @@ class WearShell extends StatefulWidget {
}
class _WearShellState extends State<WearShell> with WidgetsBindingObserver {
+ static const idleAfter = Duration(seconds: 15);
+
+ Timer? _idle;
+ bool _dim = false;
+ int _restTick = 0;
+
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
+ WearRotary.init();
+ WearRotary.onTurn = _wake;
fit.refreshAlarmPermission();
+ fit.addListener(_onFit);
+ _restTick = fit.restDoneTick;
+ _arm();
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
+ WearRotary.onTurn = null;
+ fit.removeListener(_onFit);
+ _idle?.cancel();
+ ScreenAwake.dim(false);
super.dispose();
}
+ bool get _canDim => fit.isSessionActive && fit.keepScreenOn && !fit.sessionPaused;
+
+ void _onFit() {
+ if (fit.restDoneTick != _restTick) {
+ _restTick = fit.restDoneTick;
+ _wake();
+ return;
+ }
+ if (!_canDim) {
+ _idle?.cancel();
+ if (_dim) _setDim(false);
+ } else if (_idle?.isActive != true && !_dim) {
+ _arm();
+ }
+ }
+
+ void _wake() {
+ if (_dim) _setDim(false);
+ _arm();
+ }
+
+ void _arm() {
+ _idle?.cancel();
+ if (!_canDim) return;
+ _idle = Timer(idleAfter, () {
+ if (mounted && _canDim) _setDim(true);
+ });
+ }
+
+ void _setDim(bool on) {
+ ScreenAwake.dim(on);
+ if (mounted) setState(() => _dim = on);
+ }
+
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.inactive ||
@@ -40,7 +127,10 @@ class _WearShellState extends State<WearShell> with WidgetsBindingObserver {
state == AppLifecycleState.detached) {
fit.persistNow();
}
- if (state == AppLifecycleState.resumed) fit.syncRest();
+ if (state == AppLifecycleState.resumed) {
+ fit.syncRest();
+ _wake();
+ }
}
Future<void> _back() async {
@@ -52,6 +142,7 @@ class _WearShellState extends State<WearShell> with WidgetsBindingObserver {
fit.parkSession();
}
case 'routines':
+ case 'settings':
fit.popRoute();
default:
await SystemNavigator.pop();
@@ -67,13 +158,29 @@ class _WearShellState extends State<WearShell> with WidgetsBindingObserver {
return PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, _) {
+ if (_dim) {
+ _wake();
+ return;
+ }
if (!didPop) _back();
},
- child: Scaffold(
- backgroundColor: gc.bg,
- body: AnimatedSwitcher(
- duration: const Duration(milliseconds: 220),
- child: KeyedSubtree(key: ValueKey(fit.route), child: _screen()),
+ child: Listener(
+ behavior: HitTestBehavior.translucent,
+ onPointerDown: (_) => _wake(),
+ child: Scaffold(
+ backgroundColor: gc.bg,
+ body: Stack(
+ children: [
+ Positioned.fill(
+ child: AnimatedSwitcher(
+ duration: const Duration(milliseconds: 220),
+ child: KeyedSubtree(key: ValueKey(fit.route), child: _screen()),
+ ),
+ ),
+ const Positioned(top: 0, left: 0, right: 0, child: WearClock()),
+ if (_dim) Positioned.fill(child: WearDim(onWake: _wake)),
+ ],
+ ),
),
),
);
@@ -87,25 +194,151 @@ class _WearShellState extends State<WearShell> with WidgetsBindingObserver {
return WearSession();
case 'routines':
return WearRoutines();
+ case 'settings':
+ return WearSettings();
default:
return WearHome();
}
}
}
-class WearPage extends StatelessWidget {
+class WearClock extends StatefulWidget {
+ const WearClock({super.key, this.color});
+
+ final Color? color;
+
+ @override
+ State<WearClock> createState() => _WearClockState();
+}
+
+class _WearClockState extends State<WearClock> {
+ Timer? _timer;
+
+ @override
+ void initState() {
+ super.initState();
+ _schedule();
+ }
+
+ void _schedule() {
+ final now = DateTime.now();
+ _timer = Timer(Duration(seconds: 60 - now.second), () {
+ if (!mounted) return;
+ setState(() {});
+ _schedule();
+ });
+ }
+
+ @override
+ void dispose() {
+ _timer?.cancel();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ final size = MediaQuery.sizeOf(context);
+ return IgnorePointer(
+ child: Padding(
+ padding: EdgeInsets.only(top: size.height * 0.045),
+ child: Center(
+ child: Text(TimeOfDay.now().format(context),
+ style: AppTheme.f(12, weight: FontWeight.w700, color: widget.color ?? gc.textSecondary)),
+ ),
+ ),
+ );
+ }
+}
+
+class WearPage extends StatefulWidget {
const WearPage({super.key, required this.children});
final List<Widget> children;
+ @override
+ State<WearPage> createState() => _WearPageState();
+}
+
+class _WearPageState extends State<WearPage> {
+ final _scroll = ScrollController();
+
+ @override
+ void initState() {
+ super.initState();
+ WearRotary.attach(_scroll);
+ }
+
+ @override
+ void dispose() {
+ WearRotary.detach(_scroll);
+ _scroll.dispose();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
- final size = MediaQuery.sizeOf(context);
- final side = size.width * 0.13;
- return ListView(
- physics: const BouncingScrollPhysics(),
- padding: EdgeInsets.fromLTRB(side, size.height * 0.15, side, size.height * 0.18),
- children: children,
+ return LayoutBuilder(builder: (context, box) {
+ final side = box.maxWidth * 0.1;
+ return ShaderMask(
+ blendMode: BlendMode.dstIn,
+ shaderCallback: (r) => const LinearGradient(
+ begin: Alignment.topCenter,
+ end: Alignment.bottomCenter,
+ colors: [Color(0x00000000), Color(0xFF000000), Color(0xFF000000), Color(0x00000000)],
+ stops: [0.08, 0.2, 0.84, 0.98],
+ ).createShader(r),
+ child: ListView(
+ controller: _scroll,
+ physics: const BouncingScrollPhysics(),
+ padding: EdgeInsets.fromLTRB(side, box.maxHeight * 0.17, side, box.maxHeight * 0.24),
+ children: [for (final c in widget.children) _EdgeScale(child: c)],
+ ),
+ );
+ });
+ }
+}
+
+class _EdgeScale extends StatefulWidget {
+ const _EdgeScale({required this.child});
+
+ final Widget child;
+
+ @override
+ State<_EdgeScale> createState() => _EdgeScaleState();
+}
+
+class _EdgeScaleState extends State<_EdgeScale> {
+ @override
+ void initState() {
+ super.initState();
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (mounted) setState(() {});
+ });
+ }
+
+ double _depth() {
+ final box = context.findRenderObject() as RenderBox?;
+ final viewport = Scrollable.maybeOf(context)?.context.findRenderObject() as RenderBox?;
+ if (box == null || viewport == null || !box.hasSize || !box.attached || !viewport.hasSize) return 0;
+ final top = box.localToGlobal(Offset.zero, ancestor: viewport).dy;
+ final half = viewport.size.height / 2;
+ if (half <= 0) return 0;
+ final d = ((top + box.size.height / 2 - half).abs() / half).clamp(0.0, 1.0);
+ return Curves.easeIn.transform(((d - 0.4) / 0.6).clamp(0.0, 1.0));
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final position = Scrollable.maybeOf(context)?.position;
+ if (position == null) return widget.child;
+ return AnimatedBuilder(
+ animation: position,
+ child: widget.child,
+ builder: (context, child) {
+ final t = _depth();
+ return Transform.scale(scale: 1 - 0.22 * t, child: child);
+ },
);
}
}
@@ -120,27 +353,22 @@ class WearHome extends StatelessWidget {
final planned = fit.todayRoutine;
final canStart = planned != null && planned.exerciseIds.isNotEmpty;
return WearPage(children: [
- Center(
- child: Text('GYMMANE',
- style: AppTheme.f(10, weight: FontWeight.w600, color: gc.textTertiary, letterSpacing: 3)),
- ),
- const SizedBox(height: 10),
Center(child: _WeekRing(gc: gc, done: fit.sessionsThisWeek, goal: fit.weeklyTarget)),
const SizedBox(height: 8),
Center(
child: Row(mainAxisSize: MainAxisSize.min, children: [
- Icon(PhosphorIconsFill.fire, size: 13, color: gc.accent),
+ Icon(PhosphorIconsFill.fire, size: 14, color: gc.accent),
const SizedBox(width: 4),
- Text('${fit.currentStreak}',
- style: AppTheme.f(15, weight: FontWeight.w700, color: gc.text)),
+ Text('${fit.currentStreak}', style: AppTheme.f(15, weight: FontWeight.w700, color: gc.text)),
const SizedBox(width: 4),
Text(t.daysUnit(fit.currentStreak),
- style: AppTheme.s(11, weight: FontWeight.w500, color: gc.textSecondary)),
+ style: AppTheme.f(12, weight: FontWeight.w500, color: gc.textSecondary)),
]),
),
- const SizedBox(height: 14),
+ const SizedBox(height: 12),
WearButton(
label: live ? t.continueBtn : t.startWorkout,
+ icon: PhosphorIconsFill.play,
filled: true,
onTap: () {
if (live) {
@@ -153,8 +381,19 @@ class WearHome extends StatelessWidget {
}
},
),
+ if (canStart && !live) ...[
+ const SizedBox(height: 4),
+ Center(
+ child: Text(planned.name,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.f(11.5, weight: FontWeight.w600, color: gc.textSecondary)),
+ ),
+ ],
const SizedBox(height: 8),
- WearButton(label: t.routines, onTap: fit.goRoutines),
+ WearButton(label: t.routines, icon: PhosphorIconsRegular.listBullets, onTap: fit.goRoutines),
+ const SizedBox(height: 8),
+ WearButton(label: t.settings, icon: PhosphorIconsRegular.gearSix, onTap: () => fit.pushRoute('settings')),
]);
}
}
@@ -170,15 +409,15 @@ class _WeekRing extends StatelessWidget {
Widget build(BuildContext context) {
final pct = goal <= 0 ? 0.0 : (done / goal).clamp(0.0, 1.0);
return SizedBox(
- width: 84,
- height: 84,
+ width: 80,
+ height: 80,
child: CustomPaint(
painter: _RingPainter(track: gc.bgRaised2, fill: gc.accent, pct: pct),
child: Center(
child: Column(mainAxisSize: MainAxisSize.min, children: [
- Text('$done/$goal', style: AppTheme.f(19, weight: FontWeight.w700, color: gc.text)),
+ Text('$done/$goal', style: AppTheme.f(20, weight: FontWeight.w800, color: gc.text)),
Text(t.thisWeek,
- style: AppTheme.f(7.5, weight: FontWeight.w600, color: gc.textTertiary, letterSpacing: 1)),
+ style: AppTheme.f(9, weight: FontWeight.w700, color: gc.textTertiary, letterSpacing: 0.8)),
]),
),
),
@@ -209,8 +448,7 @@ class _RingPainter extends CustomPainter {
}
@override
- bool shouldRepaint(_RingPainter old) =>
- old.pct != pct || old.track != track || old.fill != fill;
+ bool shouldRepaint(_RingPainter old) => old.pct != pct || old.track != track || old.fill != fill;
}
class WearButton extends StatelessWidget {
@@ -219,7 +457,8 @@ class WearButton extends StatelessWidget {
required this.label,
required this.onTap,
this.filled = false,
- this.height = 44,
+ this.height = 48,
+ this.icon,
this.color,
});
@@ -227,6 +466,7 @@ class WearButton extends StatelessWidget {
final VoidCallback? onTap;
final bool filled;
final double height;
+ final IconData? icon;
final Color? color;
@override
@@ -241,19 +481,29 @@ class WearButton extends StatelessWidget {
label: label,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
- onTap: onTap,
+ onTap: onTap == null
+ ? null
+ : () {
+ HapticFeedback.selectionClick();
+ onTap!();
+ },
child: Opacity(
- opacity: enabled ? 1 : 0.4,
+ opacity: enabled ? 1 : 0.35,
child: Container(
height: height,
alignment: Alignment.center,
- padding: const EdgeInsets.symmetric(horizontal: 12),
+ padding: const EdgeInsets.symmetric(horizontal: 14),
decoration: BoxDecoration(color: bg, borderRadius: BorderRadius.circular(100)),
child: FittedBox(
fit: BoxFit.scaleDown,
- child: Text(label,
- maxLines: 1,
- style: AppTheme.f(12.5, weight: FontWeight.w700, color: fg, letterSpacing: 0.6)),
+ child: Row(mainAxisSize: MainAxisSize.min, children: [
+ if (icon != null) ...[
+ Icon(icon, size: 15, color: fg),
+ const SizedBox(width: 7),
+ ],
+ Text(_cap(label),
+ maxLines: 1, style: AppTheme.f(14, weight: FontWeight.w700, color: fg)),
+ ]),
),
),
),
@@ -262,6 +512,42 @@ class WearButton extends StatelessWidget {
}
}
+class WearIconButton extends StatelessWidget {
+ const WearIconButton({super.key, required this.icon, required this.label, required this.onTap});
+
+ final IconData icon;
+ final String label;
+ final VoidCallback? onTap;
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ return Semantics(
+ button: true,
+ enabled: onTap != null,
+ label: label,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onTap,
+ child: Opacity(
+ opacity: onTap == null ? 0.3 : 1,
+ child: Container(
+ height: 44,
+ alignment: Alignment.center,
+ decoration: BoxDecoration(color: gc.bgRaised, borderRadius: BorderRadius.circular(100)),
+ child: Icon(icon, size: 18, color: gc.text),
+ ),
+ ),
+ ),
+ );
+ }
+}
+
+Widget _heading(GymColors gc, String text) => Center(
+ child: Text(text.toUpperCase(),
+ style: AppTheme.f(11.5, weight: FontWeight.w700, color: gc.textSecondary, letterSpacing: 1.6)),
+ );
+
class WearRoutines extends StatelessWidget {
const WearRoutines({super.key});
@@ -272,102 +558,228 @@ class WearRoutines extends StatelessWidget {
final list = [...fit.routines]
..sort((a, b) => (a.id == planned?.id ? 0 : 1) - (b.id == planned?.id ? 0 : 1));
return WearPage(children: [
- Center(
- child: Text(t.routines,
- style: AppTheme.f(11, weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 2)),
- ),
+ _heading(gc, t.routines),
const SizedBox(height: 10),
if (list.isEmpty) ...[
Center(
child: Text(t.templates,
- style: AppTheme.f(9, weight: FontWeight.w700, color: gc.textTertiary, letterSpacing: 1.2)),
+ textAlign: TextAlign.center,
+ style: AppTheme.f(11.5, weight: FontWeight.w600, color: gc.textTertiary)),
),
- const SizedBox(height: 6),
- for (final p in kProgramTemplates) _templateRow(gc, p),
+ const SizedBox(height: 8),
+ for (final p in kProgramTemplates) _row(gc, p.name, t.perWeek(p.days.length), PhosphorIconsBold.plus, false, () {
+ fit.applyTemplate(p);
+ }),
],
- for (final r in list) _routineRow(gc, r, r.id == planned?.id),
+ for (final r in list)
+ _row(gc, r.name, t.exerciseCount(r.exerciseIds.length), PhosphorIconsFill.play, r.id == planned?.id,
+ r.exerciseIds.isEmpty
+ ? null
+ : () {
+ fit.startRoutine(r);
+ fit.endCountdown();
+ }),
]);
}
- Widget _templateRow(GymColors gc, ProgramTemplate p) {
+ Widget _row(GymColors gc, String title, String detail, IconData icon, bool today, VoidCallback? onTap) {
return Padding(
padding: const EdgeInsets.only(bottom: 6),
child: Semantics(
button: true,
+ enabled: onTap != null,
+ label: title,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
- onTap: () {
- HapticFeedback.selectionClick();
- fit.applyTemplate(p);
- },
- child: Container(
- padding: const EdgeInsets.fromLTRB(12, 9, 10, 9),
- decoration: BoxDecoration(color: gc.bgRaised, borderRadius: BorderRadius.circular(16)),
- child: Row(children: [
- Expanded(
- child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
- Text(p.name,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: AppTheme.f(12.5, weight: FontWeight.w600, color: gc.text)),
- const SizedBox(height: 1),
- Text(t.perWeek(p.days.length),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: AppTheme.s(10, weight: FontWeight.w500, color: gc.textSecondary)),
- ]),
+ onTap: onTap == null
+ ? null
+ : () {
+ HapticFeedback.selectionClick();
+ onTap();
+ },
+ child: Opacity(
+ opacity: onTap == null ? 0.4 : 1,
+ child: Container(
+ constraints: const BoxConstraints(minHeight: 52),
+ padding: const EdgeInsets.fromLTRB(16, 8, 14, 8),
+ decoration: BoxDecoration(
+ color: gc.bgRaised,
+ borderRadius: BorderRadius.circular(26),
+ border: Border.all(color: today ? gc.accent : Colors.transparent, width: 1.4),
),
- Icon(PhosphorIconsBold.plus, size: 12, color: gc.accent),
- ]),
+ child: Row(children: [
+ Expanded(
+ child: Column(crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [
+ Text(title,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.f(14, weight: FontWeight.w700, color: gc.text)),
+ Text(detail,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.f(11.5, weight: FontWeight.w500, color: gc.textSecondary)),
+ ]),
+ ),
+ Icon(icon, size: 14, color: today ? gc.accent : gc.textTertiary),
+ ]),
+ ),
),
),
),
);
}
+}
- Widget _routineRow(GymColors gc, Routine r, bool today) {
- final enabled = r.exerciseIds.isNotEmpty;
- return Padding(
- padding: const EdgeInsets.only(bottom: 6),
- child: Semantics(
+class WearSettings extends StatelessWidget {
+ const WearSettings({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ return WearPage(children: [
+ _heading(gc, t.settings),
+ const SizedBox(height: 12),
+ _label(gc, t.unitsLabel),
+ Row(children: [
+ for (final u in const ['kg', 'lb']) ...[
+ if (u == 'lb') const SizedBox(width: 6),
+ Expanded(
+ child: WearButton(
+ label: u,
+ height: 42,
+ filled: fit.units == u,
+ onTap: () => fit.setUnits(u),
+ ),
+ ),
+ ],
+ ]),
+ const SizedBox(height: 12),
+ _label(gc, t.restTimer),
+ _WearStepper(
+ value: durationLabel(fit.restSeconds),
+ onDec: () => fit.setRestSeconds(fit.restSeconds - 15),
+ onInc: () => fit.setRestSeconds(fit.restSeconds + 15),
+ ),
+ const SizedBox(height: 12),
+ _label(gc, t.weeklyGoal),
+ _WearStepper(
+ value: '${fit.profile.weeklyGoal}',
+ onDec: fit.profile.weeklyGoal > 1 ? () => fit.updateProfile(weeklyGoalDelta: -1) : null,
+ onInc: fit.profile.weeklyGoal < 7 ? () => fit.updateProfile(weeklyGoalDelta: 1) : null,
+ ),
+ const SizedBox(height: 12),
+ Semantics(
+ toggled: fit.keepScreenOn,
button: true,
- enabled: enabled,
+ label: t.keepScreenOn,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
- onTap: enabled
- ? () {
- fit.startRoutine(r);
- fit.endCountdown();
- }
- : null,
+ onTap: fit.toggleKeepScreenOn,
child: Container(
- padding: const EdgeInsets.fromLTRB(12, 9, 10, 9),
- decoration: BoxDecoration(
- color: gc.bgRaised,
- borderRadius: BorderRadius.circular(16),
- border: Border.all(color: today ? gc.accent : Colors.transparent),
- ),
+ padding: const EdgeInsets.fromLTRB(16, 10, 12, 10),
+ decoration: BoxDecoration(color: gc.bgRaised, borderRadius: BorderRadius.circular(24)),
child: Row(children: [
Expanded(
- child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
- Text(r.name,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: AppTheme.f(12.5, weight: FontWeight.w600, color: gc.text)),
- const SizedBox(height: 1),
- Text(t.exerciseCount(r.exerciseIds.length),
- style: AppTheme.s(10, weight: FontWeight.w500, color: gc.textSecondary)),
- ]),
+ child: Text(t.keepScreenOn,
+ maxLines: 3,
+ style: AppTheme.f(12.5, weight: FontWeight.w600, color: gc.text, height: 1.2)),
),
- Icon(PhosphorIconsFill.play, size: 12, color: today ? gc.accent : gc.textTertiary),
+ const SizedBox(width: 8),
+ _Switch(on: fit.keepScreenOn),
]),
),
),
),
+ ]);
+ }
+
+ Widget _label(GymColors gc, String text) => Padding(
+ padding: const EdgeInsets.only(bottom: 6),
+ child: Center(
+ child: Text(_cap(text),
+ style: AppTheme.f(11.5, weight: FontWeight.w600, color: gc.textSecondary)),
+ ),
+ );
+}
+
+class _Switch extends StatelessWidget {
+ const _Switch({required this.on});
+
+ final bool on;
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ return AnimatedContainer(
+ duration: const Duration(milliseconds: 180),
+ width: 38,
+ height: 22,
+ padding: const EdgeInsets.all(3),
+ alignment: on ? Alignment.centerRight : Alignment.centerLeft,
+ decoration: BoxDecoration(color: on ? gc.accent : gc.bgRaised2, borderRadius: BorderRadius.circular(100)),
+ child: Container(
+ width: 16,
+ height: 16,
+ decoration: BoxDecoration(color: on ? gc.bg : gc.textTertiary, shape: BoxShape.circle),
+ ),
);
}
}
+class _WearStepper extends StatelessWidget {
+ const _WearStepper({required this.value, required this.onDec, required this.onInc, this.label});
+
+ final String value;
+ final String? label;
+ final VoidCallback? onDec;
+ final VoidCallback? onInc;
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ Widget b(IconData icon, String semantic, VoidCallback? onTap) => Semantics(
+ button: true,
+ enabled: onTap != null,
+ label: semantic,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onTap == null
+ ? null
+ : () {
+ HapticFeedback.selectionClick();
+ onTap();
+ },
+ child: Opacity(
+ opacity: onTap == null ? 0.3 : 1,
+ child: Container(
+ width: 44,
+ height: 44,
+ alignment: Alignment.center,
+ decoration: BoxDecoration(color: gc.bgRaised2, shape: BoxShape.circle),
+ child: Icon(icon, size: 16, color: gc.text),
+ ),
+ ),
+ ),
+ );
+ return Row(children: [
+ b(PhosphorIconsBold.minus, t.decrease, onDec),
+ Expanded(
+ child: Column(mainAxisSize: MainAxisSize.min, children: [
+ FittedBox(
+ fit: BoxFit.scaleDown,
+ child: Text(value, maxLines: 1, style: AppTheme.f(20, weight: FontWeight.w800, color: gc.text, height: 1.1)),
+ ),
+ if (label != null)
+ Text(label!,
+ maxLines: 1,
+ style: AppTheme.f(10, weight: FontWeight.w700, color: gc.textTertiary, letterSpacing: 0.8)),
+ ]),
+ ),
+ b(PhosphorIconsBold.plus, t.increase, onInc),
+ ]);
+ }
+}
+
class WearSession extends StatelessWidget {
const WearSession({super.key});
@@ -385,126 +797,180 @@ class WearSession extends StatelessWidget {
final mode = ex == null ? '' : fit.modeOf(ex.id);
final pending = ex == null ? -1 : ex.sets.indexWhere((st) => !st.done);
final resting = s.restRemaining != null;
-
final holding = fit.holding && fit.holdEx == exIdx;
return WearPage(children: [
- Row(children: [
- Expanded(
- child: Text(fit.sessionProgressLabel,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: AppTheme.f(9.5, weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 0.6)),
- ),
- Semantics(
+ Center(
+ child: Semantics(
button: true,
label: fit.sessionPaused ? t.resumeWorkout : t.pauseWorkout,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: fit.toggleSessionPause,
- child: Row(mainAxisSize: MainAxisSize.min, children: [
- Icon(fit.sessionPaused ? PhosphorIconsFill.play : PhosphorIconsFill.pause,
- size: 10, color: fit.sessionPaused ? gc.warn : gc.textTertiary),
- const SizedBox(width: 3),
- Text(fit.elapsedLabel,
- style: AppTheme.f(11,
- weight: FontWeight.w700, color: fit.sessionPaused ? gc.warn : gc.textSecondary)),
- ]),
+ child: Padding(
+ padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 10),
+ child: Row(mainAxisSize: MainAxisSize.min, children: [
+ Text('${exIdx + 1}/${s.exercises.length}',
+ style: AppTheme.f(12, weight: FontWeight.w700, color: gc.textSecondary)),
+ Container(
+ width: 3,
+ height: 3,
+ margin: const EdgeInsets.symmetric(horizontal: 7),
+ decoration: BoxDecoration(color: gc.textTertiary, shape: BoxShape.circle),
+ ),
+ Icon(fit.sessionPaused ? PhosphorIconsFill.play : PhosphorIconsFill.pause,
+ size: 10, color: fit.sessionPaused ? gc.warn : gc.textTertiary),
+ const SizedBox(width: 4),
+ Text(fit.elapsedLabel,
+ style: AppTheme.f(12,
+ weight: FontWeight.w700, color: fit.sessionPaused ? gc.warn : gc.textSecondary)),
+ ]),
+ ),
),
),
- ]),
- const SizedBox(height: 3),
+ ),
_WearStage(
index: exIdx,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
- if (fit.inSuperset) ...[
- Row(children: [
- Icon(PhosphorIconsBold.link, size: 10, color: gc.brass),
+ if (fit.inSuperset)
+ Row(mainAxisAlignment: MainAxisAlignment.center, children: [
+ Icon(PhosphorIconsBold.link, size: 11, color: gc.brass),
const SizedBox(width: 4),
- Text(t.superset,
- style: AppTheme.f(9, weight: FontWeight.w700, color: gc.brass, letterSpacing: 0.5)),
+ Text(t.superset, style: AppTheme.f(11, weight: FontWeight.w700, color: gc.brass)),
]),
- const SizedBox(height: 2),
- ],
Text(ex == null ? '' : t.catalogName(ex.id, ex.name),
maxLines: 2,
+ textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
- style: AppTheme.f(16, weight: FontWeight.w700, color: gc.text, height: 1.1)),
- const SizedBox(height: 10),
- if (holding) ...[
- _holdCard(gc),
- const SizedBox(height: 10),
- ] else if (resting) ...[
- _restCard(gc, s),
- const SizedBox(height: 10),
- ],
- if (ex != null)
- for (int j = 0; j < ex.sets.length; j++) _setRow(gc, exIdx, j, ex.sets[j], repsOnly, j == pending),
+ style: AppTheme.f(16, weight: FontWeight.w800, color: gc.text, height: 1.15)),
],
),
),
- if (ex != null && pending >= 0 && mode == 'cardio') ...[
- const SizedBox(height: 8),
- _stepper(gc, fit.distanceUnit.toUpperCase(), fit.distanceValue(ex.sets[pending].km ?? 0),
- () => fit.bumpSessionDistance(exIdx, pending, -1), () => fit.bumpSessionDistance(exIdx, pending, 1)),
- const SizedBox(height: 6),
- _stepper(gc, t.timeCol, durationLabel(ex.sets[pending].sec ?? 0),
- () => fit.bumpSessionSeconds(exIdx, pending, -60), () => fit.bumpSessionSeconds(exIdx, pending, 60)),
- ] else if (ex != null && pending >= 0 && mode == 'time') ...[
+ const SizedBox(height: 10),
+ if (holding) ...[
+ _holdCard(gc),
const SizedBox(height: 8),
- _stepper(gc, t.timeCol, durationLabel(ex.sets[pending].sec ?? 0),
- () => fit.bumpSessionSeconds(exIdx, pending, -15), () => fit.bumpSessionSeconds(exIdx, pending, 15)),
- ] else if (ex != null && pending >= 0) ...[
+ ] else if (resting) ...[
+ _restCard(gc, s),
const SizedBox(height: 8),
- _stepper(gc, t.repsCol, '${ex.sets[pending].reps}',
- () => fit.bumpSessionReps(exIdx, pending, -1), () => fit.bumpSessionReps(exIdx, pending, 1)),
- if (!repsOnly) ...[
- const SizedBox(height: 6),
- _stepper(gc, fit.units.toUpperCase(), fit.weightValue(ex.sets[pending].weight),
- () => fit.bumpSessionWeight(exIdx, pending, -1), () => fit.bumpSessionWeight(exIdx, pending, 1)),
- ],
],
- const SizedBox(height: 12),
+ if (ex != null && pending >= 0) ...[
+ Center(
+ child: Text(_pendingLabel(ex.sets[pending], mode, repsOnly),
+ maxLines: 1,
+ style: AppTheme.f(15, weight: FontWeight.w800, color: gc.textSecondary)),
+ ),
+ const SizedBox(height: 6),
+ ],
_mainAction(gc, ex, exIdx, s.exercises.length, pending),
- const SizedBox(height: 8),
+ const SizedBox(height: 10),
+ if (ex != null && pending >= 0) ..._editors(gc, ex, exIdx, pending, mode, repsOnly),
+ const SizedBox(height: 4),
+ if (ex != null)
+ for (int j = 0; j < ex.sets.length; j++) _setRow(gc, exIdx, j, ex.sets[j], repsOnly, j == pending),
+ const SizedBox(height: 6),
Row(children: [
Expanded(
- child: WearButton(
- label: '‹',
- height: 36,
+ child: WearIconButton(
+ icon: PhosphorIconsBold.caretLeft,
+ label: t.back,
onTap: exIdx > 0 ? fit.prevExercise : null,
),
),
const SizedBox(width: 6),
Expanded(
- child: WearButton(
- label: '›',
- height: 36,
+ child: WearIconButton(
+ icon: PhosphorIconsBold.caretRight,
+ label: t.nextExercise,
onTap: exIdx < s.exercises.length - 1 ? fit.nextExercise : null,
),
),
]),
- const SizedBox(height: 8),
+ const SizedBox(height: 4),
_textAction(gc, t.addSet, () => fit.addSet(exIdx)),
_textAction(gc, t.finishSession, fit.finishSession),
]);
}
+ String _pendingLabel(SessionSet set, String mode, bool repsOnly) {
+ if (mode == 'cardio' || mode == 'time') return fit.loggedSetLabel(set.logged);
+ if (repsOnly) return '${set.reps}';
+ return '${set.reps} × ${fit.weightValue(set.weight)} ${fit.units}';
+ }
+
+ List<Widget> _editors(GymColors gc, SessionExercise ex, int exIdx, int pending, String mode, bool repsOnly) {
+ final set = ex.sets[pending];
+ final steppers = switch (mode) {
+ 'cardio' => [
+ _WearStepper(
+ label: fit.distanceUnit.toUpperCase(),
+ value: fit.distanceValue(set.km ?? 0),
+ onDec: () => fit.bumpSessionDistance(exIdx, pending, -1),
+ onInc: () => fit.bumpSessionDistance(exIdx, pending, 1),
+ ),
+ _WearStepper(
+ label: t.timeCol,
+ value: durationLabel(set.sec ?? 0),
+ onDec: () => fit.bumpSessionSeconds(exIdx, pending, -60),
+ onInc: () => fit.bumpSessionSeconds(exIdx, pending, 60),
+ ),
+ ],
+ 'time' => [
+ _WearStepper(
+ label: t.timeCol,
+ value: durationLabel(set.sec ?? 0),
+ onDec: () => fit.bumpSessionSeconds(exIdx, pending, -15),
+ onInc: () => fit.bumpSessionSeconds(exIdx, pending, 15),
+ ),
+ ],
+ _ => [
+ _WearStepper(
+ label: t.repsCol,
+ value: '${set.reps}',
+ onDec: () => fit.bumpSessionReps(exIdx, pending, -1),
+ onInc: () => fit.bumpSessionReps(exIdx, pending, 1),
+ ),
+ if (!repsOnly)
+ _WearStepper(
+ label: fit.units.toUpperCase(),
+ value: fit.weightValue(set.weight),
+ onDec: () => fit.bumpSessionWeight(exIdx, pending, -1),
+ onInc: () => fit.bumpSessionWeight(exIdx, pending, 1),
+ ),
+ ],
+ };
+ return [
+ for (final s in steppers) ...[s, const SizedBox(height: 6)],
+ const SizedBox(height: 4),
+ ];
+ }
+
Widget _restCard(GymColors gc, WorkoutSession s) {
+ final left = s.restRemaining ?? 0;
+ final total = fit.restTotal <= 0 ? 1 : fit.restTotal;
return Container(
- padding: const EdgeInsets.fromLTRB(10, 8, 10, 8),
- decoration: BoxDecoration(color: gc.bgRaised, borderRadius: BorderRadius.circular(18)),
+ padding: const EdgeInsets.fromLTRB(10, 10, 10, 10),
+ decoration: BoxDecoration(color: gc.bgRaised, borderRadius: BorderRadius.circular(24)),
child: Column(children: [
- Text(t.rest,
- style: AppTheme.f(8.5, weight: FontWeight.w700, color: gc.textTertiary, letterSpacing: 1.5)),
- Text('${s.restRemaining}s', style: AppTheme.f(30, weight: FontWeight.w800, color: gc.text)),
+ Text(_cap(t.rest), style: AppTheme.f(11.5, weight: FontWeight.w700, color: gc.textSecondary)),
+ Text(clockLabel(left), style: AppTheme.f(32, weight: FontWeight.w800, color: gc.text, height: 1.1)),
const SizedBox(height: 4),
+ ClipRRect(
+ borderRadius: BorderRadius.circular(3),
+ child: LinearProgressIndicator(
+ value: (1 - left / total).clamp(0.0, 1.0),
+ minHeight: 4,
+ backgroundColor: gc.bgRaised2,
+ valueColor: AlwaysStoppedAnimation(gc.accent),
+ ),
+ ),
+ const SizedBox(height: 8),
Row(children: [
Expanded(child: _tiny(gc, '−15', () => fit.nudgeRest(-15))),
const SizedBox(width: 4),
- Expanded(child: _tiny(gc, t.skip, fit.skipRest, strong: true)),
+ Expanded(child: _tiny(gc, _cap(t.skip), fit.skipRest, strong: true)),
const SizedBox(width: 4),
Expanded(child: _tiny(gc, '+15', () => fit.nudgeRest(15))),
]),
@@ -517,13 +983,13 @@ class WearSession extends StatelessWidget {
final left = fit.holdRemaining ?? 0;
final total = fit.holdTotal <= 0 ? 1 : fit.holdTotal;
return Container(
- padding: const EdgeInsets.fromLTRB(10, 8, 10, 10),
- decoration: BoxDecoration(color: gc.bgRaised, borderRadius: BorderRadius.circular(18)),
+ padding: const EdgeInsets.fromLTRB(10, 10, 10, 12),
+ decoration: BoxDecoration(color: gc.bgRaised, borderRadius: BorderRadius.circular(24)),
child: Column(children: [
- Text(lead > 0 ? t.getReady : t.timeCol,
- style: AppTheme.f(8.5, weight: FontWeight.w700, color: gc.textTertiary, letterSpacing: 1.5)),
+ Text(_cap(lead > 0 ? t.getReady : t.timeCol),
+ style: AppTheme.f(11.5, weight: FontWeight.w700, color: gc.textSecondary)),
Text(lead > 0 ? '$lead' : durationLabel(left),
- style: AppTheme.f(30, weight: FontWeight.w800, color: lead > 0 ? gc.accent : gc.text)),
+ style: AppTheme.f(32, weight: FontWeight.w800, color: lead > 0 ? gc.accent : gc.text, height: 1.1)),
const SizedBox(height: 4),
ClipRRect(
borderRadius: BorderRadius.circular(3),
@@ -541,9 +1007,12 @@ class WearSession extends StatelessWidget {
Widget _tiny(GymColors gc, String label, VoidCallback onTap, {bool strong = false}) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
- onTap: onTap,
+ onTap: () {
+ HapticFeedback.selectionClick();
+ onTap();
+ },
child: Container(
- height: 30,
+ height: 38,
alignment: Alignment.center,
decoration: BoxDecoration(
color: strong ? gc.bgRaised2 : Colors.transparent,
@@ -552,7 +1021,7 @@ class WearSession extends StatelessWidget {
),
child: FittedBox(
fit: BoxFit.scaleDown,
- child: Text(label, style: AppTheme.f(10.5, weight: FontWeight.w700, color: gc.text)),
+ child: Text(label, style: AppTheme.f(12, weight: FontWeight.w700, color: gc.text)),
),
),
);
@@ -565,41 +1034,46 @@ class WearSession extends StatelessWidget {
? '${st.reps}'
: '${st.reps} × ${fit.weightValue(st.weight)}';
return Padding(
- padding: const EdgeInsets.only(bottom: 4),
+ padding: const EdgeInsets.only(bottom: 5),
child: Semantics(
button: true,
checked: st.done,
label: t.markSet(j + 1),
child: GestureDetector(
behavior: HitTestBehavior.opaque,
- onTap: () => fit.toggleSet(exIdx, j),
+ onTap: () {
+ HapticFeedback.selectionClick();
+ fit.toggleSet(exIdx, j);
+ },
child: Container(
- padding: const EdgeInsets.fromLTRB(10, 6, 8, 6),
+ height: 44,
+ padding: const EdgeInsets.fromLTRB(14, 0, 10, 0),
decoration: BoxDecoration(
color: st.done ? gc.sageSoft : gc.bgRaised,
- borderRadius: BorderRadius.circular(14),
- border: Border.all(color: current ? gc.accent : Colors.transparent),
+ borderRadius: BorderRadius.circular(22),
+ border: Border.all(color: current ? gc.accent : Colors.transparent, width: 1.4),
),
child: Row(children: [
SizedBox(
- width: 18,
+ width: 20,
child: Text(st.kind == SetKind.warmup ? 'W' : '${j + 1}',
- style: AppTheme.f(12, weight: FontWeight.w700, color: gc.textSecondary)),
+ style: AppTheme.f(13, weight: FontWeight.w700, color: gc.textSecondary)),
),
Expanded(
child: Text(load,
maxLines: 1,
- style: AppTheme.f(13, weight: FontWeight.w600, color: gc.text)),
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.f(14, weight: FontWeight.w700, color: gc.text)),
),
Container(
- width: 20,
- height: 20,
+ width: 22,
+ height: 22,
decoration: BoxDecoration(
color: st.done ? gc.sage : Colors.transparent,
shape: BoxShape.circle,
- border: Border.all(color: st.done ? gc.sage : gc.textTertiary, width: 1.5),
+ border: Border.all(color: st.done ? gc.sage : gc.textTertiary, width: 1.6),
),
- child: st.done ? const Icon(Icons.check_rounded, size: 13, color: Colors.white) : null,
+ child: st.done ? const Icon(PhosphorIconsBold.check, size: 12, color: Colors.white) : null,
),
]),
),
@@ -608,56 +1082,33 @@ class WearSession extends StatelessWidget {
);
}
- Widget _stepper(GymColors gc, String label, String value, VoidCallback dec, VoidCallback inc) {
- Widget b(String g, String semantic, VoidCallback onTap) => Semantics(
- button: true,
- label: semantic,
- child: GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: onTap,
- child: Container(
- width: 36,
- height: 34,
- alignment: Alignment.center,
- decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(10)),
- child: Text(g, style: TextStyle(color: gc.text, fontSize: 18, height: 1)),
- ),
- ),
- );
- return Row(children: [
- b('–', t.decrease, dec),
- Expanded(
- child: Column(children: [
- Text(value, style: AppTheme.f(17, weight: FontWeight.w700, color: gc.text)),
- Text(label,
- style: AppTheme.f(7.5, weight: FontWeight.w600, color: gc.textTertiary, letterSpacing: 1)),
- ]),
- ),
- b('+', t.increase, inc),
- ]);
- }
-
Widget _mainAction(GymColors gc, SessionExercise? ex, int exIdx, int total, int pending) {
if (pending >= 0 && ex != null && fit.isTimed(ex.id)) {
if (fit.holding && fit.holdEx == exIdx) {
- return WearButton(label: t.stopLabel, filled: true, onTap: fit.stopHold);
+ return WearButton(label: t.stopLabel, icon: PhosphorIconsFill.stop, filled: true, onTap: fit.stopHold);
}
return WearButton(
label: t.startHold(durationLabel(ex.sets[pending].sec ?? 30)),
+ icon: PhosphorIconsFill.play,
filled: true,
onTap: () => fit.startHold(exIdx, pending),
);
}
if (pending >= 0) {
- return WearButton(label: t.setDone, filled: true, onTap: () => fit.toggleSet(exIdx, pending));
+ return WearButton(
+ label: t.setDone,
+ icon: PhosphorIconsBold.check,
+ filled: true,
+ onTap: () => fit.toggleSet(exIdx, pending),
+ );
}
if (fit.pendingAfter(exIdx) != null) {
- return WearButton(label: t.nextExercise, filled: true, onTap: fit.goNextPending);
+ return WearButton(label: t.nextExercise, icon: PhosphorIconsBold.caretRight, filled: true, onTap: fit.goNextPending);
}
if (exIdx < total - 1) {
- return WearButton(label: t.nextExercise, filled: true, onTap: fit.nextExercise);
+ return WearButton(label: t.nextExercise, icon: PhosphorIconsBold.caretRight, filled: true, onTap: fit.nextExercise);
}
- return WearButton(label: t.finishSession, filled: true, onTap: fit.finishSession);
+ return WearButton(label: t.finishSession, icon: PhosphorIconsBold.flagCheckered, filled: true, onTap: fit.finishSession);
}
Widget _textAction(GymColors gc, String label, VoidCallback onTap) => Semantics(
@@ -665,11 +1116,11 @@ class WearSession extends StatelessWidget {
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: onTap,
- child: Padding(
- padding: const EdgeInsets.symmetric(vertical: 9),
+ child: SizedBox(
+ height: 44,
child: Center(
- child: Text(label,
- style: AppTheme.f(10.5, weight: FontWeight.w600, color: gc.textTertiary, letterSpacing: 0.4)),
+ child: Text(_cap(label),
+ style: AppTheme.f(13, weight: FontWeight.w600, color: gc.textSecondary)),
),
),
),
@@ -677,24 +1128,25 @@ class WearSession extends StatelessWidget {
Widget _complete(GymColors gc) {
final s = fit.session!;
+ final prs = fit.gamification ? fit.summaryPrs : 0;
return WearPage(children: [
Center(
- child: Text(t.sessionComplete,
- textAlign: TextAlign.center,
- style: AppTheme.f(10.5, weight: FontWeight.w600, color: gc.brass, letterSpacing: 1.4)),
+ child: Icon(PhosphorIconsFill.checkCircle, size: 28, color: gc.sage),
),
- const SizedBox(height: 8),
+ const SizedBox(height: 6),
Center(
- child: Text(t.finishHeadline(prs: fit.summaryPrs, streak: fit.currentStreak, goalHit: fit.goalPct >= 100),
+ child: Text(t.finishHeadline(prs: prs, streak: fit.currentStreak, goalHit: fit.goalPct >= 100),
textAlign: TextAlign.center,
- style: AppTheme.f(17, weight: FontWeight.w700, color: gc.text, height: 1.1)),
+ style: AppTheme.f(16, weight: FontWeight.w800, color: gc.text, height: 1.15)),
),
const SizedBox(height: 12),
_stat(gc, t.duration, fit.summaryDurationLabel),
_stat(gc, t.setsCaps, '${s.summarySets ?? 0}'),
_stat(gc, t.volume, fit.volumeLabel(fit.summaryVolumeKg)),
- const SizedBox(height: 12),
- WearButton(label: t.saveAndExit, filled: true, onTap: fit.saveAndExit),
+ const SizedBox(height: 10),
+ WearButton(label: t.saveAndExit, icon: PhosphorIconsBold.check, filled: true, onTap: fit.saveAndExit),
+ const SizedBox(height: 8),
+ WearButton(label: t.keepTraining, icon: PhosphorIconsBold.arrowCounterClockwise, onTap: fit.continueSession),
]);
}
@@ -702,14 +1154,63 @@ class WearSession extends StatelessWidget {
return Padding(
padding: const EdgeInsets.only(bottom: 5),
child: Container(
- padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 7),
- decoration: BoxDecoration(color: gc.bgRaised, borderRadius: BorderRadius.circular(14)),
+ height: 44,
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ decoration: BoxDecoration(color: gc.bgRaised, borderRadius: BorderRadius.circular(22)),
child: Row(children: [
Expanded(
- child: Text(label,
- style: AppTheme.f(9, weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 0.6)),
+ child: Text(_cap(label),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.f(12, weight: FontWeight.w600, color: gc.textSecondary)),
+ ),
+ Text(value, style: AppTheme.f(15, weight: FontWeight.w800, color: gc.text)),
+ ]),
+ ),
+ );
+ }
+}
+
+class WearDim extends StatelessWidget {
+ const WearDim({super.key, required this.onWake});
+
+ final VoidCallback onWake;
+
+ @override
+ Widget build(BuildContext context) {
+ final s = fit.session;
+ final ex = fit.currentExercise;
+ final rest = s?.restRemaining;
+ final pending = ex == null ? -1 : ex.sets.indexWhere((st) => !st.done);
+ const dim = Color(0xFF8A8A8A);
+ const faint = Color(0xFF5A5A5A);
+ return GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onWake,
+ child: ColoredBox(
+ color: Colors.black,
+ child: Stack(children: [
+ const Positioned(top: 0, left: 0, right: 0, child: WearClock(color: faint)),
+ Center(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 34),
+ child: Column(mainAxisSize: MainAxisSize.min, children: [
+ Text(ex == null ? '' : t.catalogName(ex.id, ex.name),
+ maxLines: 2,
+ textAlign: TextAlign.center,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.f(14, weight: FontWeight.w700, color: dim, height: 1.15)),
+ const SizedBox(height: 8),
+ if (rest != null)
+ Text(clockLabel(rest), style: AppTheme.f(40, weight: FontWeight.w800, color: dim, height: 1))
+ else if (ex != null && pending >= 0)
+ Text('${pending + 1}/${ex.sets.length}',
+ style: AppTheme.f(34, weight: FontWeight.w800, color: dim, height: 1)),
+ const SizedBox(height: 6),
+ Text(fit.elapsedLabel, style: AppTheme.f(12, weight: FontWeight.w600, color: faint)),
+ ]),
+ ),
),
- Text(value, style: AppTheme.f(14, weight: FontWeight.w700, color: gc.text)),
]),
),
);
diff --git a/test/wear_test.dart b/test/wear_test.dart
index 1860949..6a26294 100644
--- a/test/wear_test.dart
+++ b/test/wear_test.dart
@@ -1,16 +1,25 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
+import 'package:gymmane/catalog/program_templates.dart';
import 'package:gymmane/l10n/l10n.dart';
import 'package:gymmane/state/fit_state.dart';
import 'package:gymmane/wear/wear_app.dart';
+import 'package:gymmane/wear/wear_shell.dart';
+import 'package:gymmane/widgets/ui_kit.dart' show sentenceCase;
void _reset() {
fit.saveAndExit();
fit.sessions.clear();
fit.routines.clear();
fit.weeklyPlan.clear();
+ fit.setUnits('kg');
+ fit.setRestSeconds(90);
+ fit.keepScreenOn = true;
+ fit.startCountdown = true;
}
+Finder _label(String text) => find.text(sentenceCase(text));
+
Future<void> _pump(WidgetTester tester) async {
tester.view.physicalSize = const Size(454, 454);
tester.view.devicePixelRatio = 2;
@@ -20,10 +29,35 @@ Future<void> _pump(WidgetTester tester) async {
}
Future<void> _reveal(WidgetTester tester, Finder finder, {double delta = 40}) async {
- await tester.scrollUntilVisible(finder, delta, scrollable: find.byType(Scrollable).last);
+ for (var i = 0; i < 60 && finder.evaluate().isEmpty; i++) {
+ final p = tester.state<ScrollableState>(find.byType(Scrollable).last).position;
+ p.jumpTo((p.pixels + delta).clamp(p.minScrollExtent, p.maxScrollExtent));
+ await tester.pump();
+ }
+ await tester.ensureVisible(finder.first);
await tester.pump();
}
+Future<void> _settle(WidgetTester tester) async {
+ for (var i = 0; i < 8; i++) {
+ await tester.pump(const Duration(milliseconds: 100));
+ }
+}
+
+String _push() {
+ final id = fit.createRoutine('Push');
+ fit.toggleRoutineExercise(id, 'EIeI8Vf');
+ return id;
+}
+
+Future<void> _openSession(WidgetTester tester) async {
+ await _reveal(tester, _label(t.routines));
+ await tester.tap(_label(t.routines));
+ await _settle(tester);
+ await tester.tap(find.text('Push'));
+ await _settle(tester);
+}
+
void main() {
setUp(_reset);
tearDown(_reset);
@@ -31,78 +65,152 @@ void main() {
testWidgets('the watch home offers to start and to browse routines', (tester) async {
await _pump(tester);
expect(tester.takeException(), isNull);
- expect(find.text(t.startWorkout), findsOneWidget);
+ expect(_label(t.startWorkout), findsOneWidget);
- await _reveal(tester, find.text(t.routines));
- await tester.tap(find.text(t.routines));
- await tester.pumpAndSettle();
+ await _reveal(tester, _label(t.routines));
+ await tester.tap(_label(t.routines));
+ await _settle(tester);
expect(fit.route, 'routines');
expect(find.text(t.templates), findsOneWidget);
await tester.tap(find.text('Push Pull Legs'));
- await tester.pumpAndSettle();
+ await _settle(tester);
expect(fit.routines, isNotEmpty);
expect(find.text(t.templates), findsNothing);
});
testWidgets('a routine runs on the wrist: sets, rest and finish', (tester) async {
- final id = fit.createRoutine('Push');
- fit.toggleRoutineExercise(id, 'EIeI8Vf');
+ _push();
await _pump(tester);
-
- await _reveal(tester, find.text(t.routines));
- await tester.tap(find.text(t.routines));
- await tester.pumpAndSettle();
- await tester.tap(find.text('Push'));
- await tester.pump();
- await tester.pump(const Duration(milliseconds: 400));
- await tester.pump();
+ await _openSession(tester);
expect(fit.route, 'session');
- expect(find.byType(Scrollable), findsOneWidget);
expect(fit.session, isNotNull);
expect(tester.takeException(), isNull);
- await _reveal(tester, find.text(t.setDone));
- await tester.tap(find.text(t.setDone));
+ expect(_label(t.setDone), findsOneWidget, reason: 'el botón principal se ve sin bajar');
+ await tester.tap(_label(t.setDone));
await tester.pump();
expect(fit.session!.exercises.first.sets.first.done, isTrue);
expect(fit.session!.restRemaining, isNotNull);
- await _reveal(tester, find.text(t.rest), delta: -40);
- expect(find.text(t.rest), findsOneWidget);
+ await _reveal(tester, _label(t.rest), delta: -40);
+ expect(_label(t.rest), findsOneWidget);
- await tester.tap(find.text(t.skip));
+ await tester.tap(_label(t.skip));
await tester.pump();
expect(fit.session!.restRemaining, isNull);
- await _reveal(tester, find.text(t.finishSession));
- await tester.tap(find.text(t.finishSession));
+ await _reveal(tester, _label(t.finishSession));
+ await tester.tap(_label(t.finishSession).last);
await tester.pump();
expect(fit.isSessionComplete, isTrue);
- await _reveal(tester, find.text(t.saveAndExit));
- await tester.tap(find.text(t.saveAndExit));
+ await _reveal(tester, _label(t.saveAndExit));
+ await tester.tap(_label(t.saveAndExit));
await tester.pump();
expect(fit.session, isNull);
expect(fit.sessions.length, 1);
expect(tester.takeException(), isNull);
});
+ testWidgets('a mistaken finish can be undone from the summary', (tester) async {
+ _push();
+ await _pump(tester);
+ await _openSession(tester);
+ await tester.tap(_label(t.setDone));
+ await tester.pump();
+ fit.finishSession();
+ await _settle(tester);
+ await _reveal(tester, find.text(t.keepTraining));
+ await tester.tap(find.text(t.keepTraining));
+ await _settle(tester);
+ expect(fit.isSessionActive, isTrue);
+ expect(fit.sessions, isEmpty);
+ fit.saveAndExit();
+ await _settle(tester);
+ });
+
testWidgets('backing out parks the workout and home offers to continue', (tester) async {
- final id = fit.createRoutine('Legs');
- fit.toggleRoutineExercise(id, 'EIeI8Vf');
+ _push();
fit.startRoutine(fit.routines.first);
await _pump(tester);
expect(fit.route, 'session');
fit.parkSession();
- await tester.pumpAndSettle();
+ await _settle(tester);
expect(fit.route, 'home');
expect(fit.session, isNotNull);
- expect(find.text(t.continueBtn), findsOneWidget);
+ expect(_label(t.continueBtn), findsOneWidget);
- await tester.tap(find.text(t.continueBtn));
- await tester.pumpAndSettle();
+ await tester.tap(_label(t.continueBtn));
+ await _settle(tester);
expect(fit.route, 'session');
fit.saveAndExit();
+ await _settle(tester);
+ });
+
+ testWidgets('settings on the watch change units, rest, goal and screen', (tester) async {
+ await _pump(tester);
+ await _reveal(tester, _label(t.settings));
+ await tester.tap(_label(t.settings));
+ await _settle(tester);
+ expect(fit.route, 'settings');
+
+ await tester.tap(find.text('lb'));
+ await tester.pump();
+ expect(fit.units, 'lb');
+
+ final rest = fit.restSeconds;
+ await tester.tap(find.bySemanticsLabel(t.increase).first);
+ await tester.pump();
+ expect(fit.restSeconds, rest + 15);
+
+ final goal = fit.profile.weeklyGoal;
+ await _reveal(tester, find.bySemanticsLabel(t.increase).last);
+ await tester.tap(find.bySemanticsLabel(t.increase).last);
+ await tester.pump();
+ expect(fit.profile.weeklyGoal, goal < 7 ? goal + 1 : goal);
+
+ await _reveal(tester, find.text(t.keepScreenOn));
+ await tester.tap(find.text(t.keepScreenOn));
+ await tester.pump();
+ expect(fit.keepScreenOn, isFalse);
+ await _settle(tester);
+ });
+
+ testWidgets('the crown scrolls the page', (tester) async {
+ await _pump(tester);
+ await tester.tap(_label(t.startWorkout));
+ await _settle(tester);
+ fit.applyTemplate(kProgramTemplates.firstWhere((p) => p.id == 'ppl'));
+ await _settle(tester);
+ final list = tester.state<ScrollableState>(find.byType(Scrollable).last);
+ final before = list.position.pixels;
+ WearRotary.turn(60);
+ await tester.pump();
+ expect(list.position.pixels, greaterThan(before));
+ });
+
+ testWidgets('the screen dims after a while and wakes on touch', (tester) async {
+ _push();
+ fit.startRoutine(fit.routines.first);
+ fit.endCountdown();
+ await _pump(tester);
+ expect(find.byType(WearDim), findsNothing);
+
+ await tester.pump(const Duration(seconds: 16));
+ expect(find.byType(WearDim), findsOneWidget);
+
+ await tester.tap(find.byType(WearDim));
+ await tester.pump();
+ expect(find.byType(WearDim), findsNothing);
+ fit.saveAndExit();
+ await _settle(tester);
+ });
+
+ test('a plan that repeats the same day makes a single routine', () {
+ fit.applyTemplate(kProgramTemplates.firstWhere((p) => p.id == 'fullbody'));
+ expect(fit.routines, hasLength(1));
+ expect(fit.weeklyPlan.values.toSet(), {fit.routines.single.id});
+ expect(fit.weeklyPlan.keys, containsAll([1, 3, 5]));
});
}