Offline gym log for Android. No account, no ads, no internet.
Dart androidbodybuildingdartexercisesf-droidfitnessfluttergymgym-apphealthprivacyself-hostedworkoutworkout-appworkout-tracker
Wear OS tile, complication and polish
InlitXbd8da28d0a34
diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.ktsindex 504df2b..071edeb 100644--- a/android/app/build.gradle.kts+++ b/android/app/build.gradle.kts@@ -77,6 +77,11 @@ android.applicationVariants.configureEach {dependencies {coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.5")+ implementation("androidx.wear.tiles:tiles:1.4.1")+ implementation("androidx.wear.protolayout:protolayout:1.2.1")+ implementation("androidx.wear.watchface:watchface-complications-data-source:1.2.1")+ implementation("androidx.concurrent:concurrent-futures:1.2.0")+ implementation("com.google.guava:guava:33.3.1-android")}flutter {diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xmlindex fe00f28..8ed02d3 100644--- a/android/app/src/main/AndroidManifest.xml+++ b/android/app/src/main/AndroidManifest.xml@@ -27,16 +27,40 @@<uses-permission android:name="android.permission.health.WRITE_EXERCISE"/><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" tools:node="remove"/>+ <uses-sdk tools:overrideLibrary="androidx.wear.tiles, androidx.wear.protolayout, androidx.wear.protolayout.expression, androidx.wear.protolayout.expression.pipeline,androidx.wear.protolayout.proto, androidx.wear.watchface.complications.datasource, androidx.wear.watchface.complications.data, androidx.wear.watchface.complications, androidx.wear.watchface.complications.data.source, androidx.wear.watchface.data, androidx.wear.watchface.style.data"/>+<uses-feature android:name="android.hardware.type.watch" android:required="false"/><uses-feature android:name="android.hardware.touchscreen" android:required="false"/><applicationandroid:label="GymMane"- android:name="${applicationName}"+ android:name=".GymManeApplication"android:allowBackup="false"android:icon="@mipmap/ic_launcher"android:enableOnBackInvokedCallback="true"><meta-data android:name="com.google.android.wearable.standalone" android:value="true"/>+ <service+ android:name=".GymTileService"+ android:exported="true"+ android:label="@string/tile_label"+ android:permission="com.google.android.wearable.permission.BIND_TILE_PROVIDER">+ <intent-filter>+ <action android:name="androidx.wear.tiles.action.BIND_TILE_PROVIDER"/>+ </intent-filter>+ <meta-data android:name="androidx.wear.tiles.PREVIEW" android:resource="@drawable/tile_preview"/>+ </service>+ <service+ android:name=".GymComplicationService"+ android:exported="true"+ android:icon="@drawable/ic_complication"+ android:label="@string/tile_label"+ android:permission="com.google.android.wearable.permission.BIND_COMPLICATION_PROVIDER">+ <intent-filter>+ <action android:name="android.support.wearable.complications.ACTION_COMPLICATION_UPDATE_REQUEST"/>+ </intent-filter>+ <meta-data android:name="android.support.wearable.complications.SUPPORTED_TYPES" android:value="RANGED_VALUE,SHORT_TEXT"/>+ <meta-data android:name="android.support.wearable.complications.UPDATE_PERIOD_SECONDS" android:value="0"/>+ </service><activityandroid:name=".MainActivity"android:exported="true"@@ -180,6 +204,9 @@android:name=".LiveActionReceiver"android:exported="false" />+ <receiver+ android:name="com.dexterous.flutterlocalnotifications.ActionBroadcastReceiver"+ android:exported="false" /><receiverandroid:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver"android:exported="false" />diff --git a/android/app/src/main/kotlin/com/gymmane/app/GymComplicationService.kt b/android/app/src/main/kotlin/com/gymmane/app/GymComplicationService.ktnew file mode 100644index 0000000..1fb0220--- /dev/null+++ b/android/app/src/main/kotlin/com/gymmane/app/GymComplicationService.kt@@ -0,0 +1,44 @@+package com.gymmane.app++import android.app.PendingIntent+import android.content.Intent+import android.graphics.drawable.Icon+import androidx.wear.watchface.complications.data.ComplicationData+import androidx.wear.watchface.complications.data.ComplicationType+import androidx.wear.watchface.complications.data.MonochromaticImage+import androidx.wear.watchface.complications.data.NoDataComplicationData+import androidx.wear.watchface.complications.data.PlainComplicationText+import androidx.wear.watchface.complications.data.RangedValueComplicationData+import androidx.wear.watchface.complications.data.ShortTextComplicationData+import androidx.wear.watchface.complications.datasource.ComplicationRequest+import androidx.wear.watchface.complications.datasource.ComplicationDataSourceService++class GymComplicationService : ComplicationDataSourceService() {+ override fun getPreviewData(type: ComplicationType): ComplicationData? = build(type, WearData(3, 4, 0, "", false))++ override fun onComplicationRequest(request: ComplicationRequest, listener: ComplicationRequestListener) {+ listener.onComplicationData(build(request.complicationType, WearSurfaces.read(this)))+ }++ private fun build(type: ComplicationType, d: WearData): ComplicationData? {+ val text = PlainComplicationText.Builder("${d.done}/${d.goal}").build()+ val description = PlainComplicationText.Builder(getString(R.string.tile_week)).build()+ val image = MonochromaticImage.Builder(Icon.createWithResource(this, R.drawable.ic_complication)).build()+ val tap = PendingIntent.getActivity(+ this,+ 0,+ Intent(this, MainActivity::class.java).putExtra("gymmane_open", "play"),+ PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT+ )+ return when (type) {+ ComplicationType.RANGED_VALUE -> RangedValueComplicationData.Builder(+ d.done.toFloat().coerceAtMost(d.goal.toFloat()), 0f, d.goal.toFloat(), description+ ).setText(text).setMonochromaticImage(image).setTapAction(tap).build()++ ComplicationType.SHORT_TEXT -> ShortTextComplicationData.Builder(text, description)+ .setMonochromaticImage(image).setTapAction(tap).build()++ else -> NoDataComplicationData()+ }+ }+}diff --git a/android/app/src/main/kotlin/com/gymmane/app/GymTileService.kt b/android/app/src/main/kotlin/com/gymmane/app/GymTileService.ktnew file mode 100644index 0000000..3229385--- /dev/null+++ b/android/app/src/main/kotlin/com/gymmane/app/GymTileService.kt@@ -0,0 +1,171 @@+package com.gymmane.app++import androidx.concurrent.futures.CallbackToFutureAdapter+import androidx.wear.protolayout.ActionBuilders+import androidx.wear.protolayout.ColorBuilders.argb+import androidx.wear.protolayout.DimensionBuilders.degrees+import androidx.wear.protolayout.DimensionBuilders.dp+import androidx.wear.protolayout.DimensionBuilders.expand+import androidx.wear.protolayout.DimensionBuilders.sp+import androidx.wear.protolayout.DimensionBuilders.wrap+import androidx.wear.protolayout.LayoutElementBuilders+import androidx.wear.protolayout.ModifiersBuilders+import androidx.wear.protolayout.ResourceBuilders+import androidx.wear.protolayout.TimelineBuilders+import androidx.wear.tiles.RequestBuilders+import androidx.wear.tiles.TileBuilders+import androidx.wear.tiles.TileService+import com.google.common.util.concurrent.ListenableFuture++class GymTileService : TileService() {+ private val accent = 0xFFD9A184.toInt()+ private val ink = 0xFF0A0A0A.toInt()+ private val track = 0xFF262626.toInt()+ private val white = 0xFFFFFFFF.toInt()+ private val grey = 0xFF9A9A9A.toInt()+ private val faint = 0xFF6A6A6A.toInt()++ override fun onTileRequest(requestParams: RequestBuilders.TileRequest): ListenableFuture<TileBuilders.Tile> =+ CallbackToFutureAdapter.getFuture { completer ->+ val data = WearSurfaces.read(this)+ val tile = TileBuilders.Tile.Builder()+ .setResourcesVersion("1")+ .setFreshnessIntervalMillis(0)+ .setTileTimeline(TimelineBuilders.Timeline.fromLayoutElement(layout(data)))+ .build()+ completer.set(tile)+ "gymmane-tile"+ }++ override fun onTileResourcesRequest(+ requestParams: RequestBuilders.ResourcesRequest+ ): ListenableFuture<ResourceBuilders.Resources> =+ CallbackToFutureAdapter.getFuture { completer ->+ completer.set(ResourceBuilders.Resources.Builder().setVersion("1").build())+ "gymmane-tile-resources"+ }++ private fun text(value: String, size: Float, color: Int, bold: Boolean): LayoutElementBuilders.Text =+ LayoutElementBuilders.Text.Builder()+ .setText(value)+ .setMaxLines(1)+ .setOverflow(LayoutElementBuilders.TEXT_OVERFLOW_ELLIPSIZE_END)+ .setFontStyle(+ LayoutElementBuilders.FontStyle.Builder()+ .setSize(sp(size))+ .setColor(argb(color))+ .setWeight(+ if (bold) LayoutElementBuilders.FONT_WEIGHT_BOLD else LayoutElementBuilders.FONT_WEIGHT_MEDIUM+ )+ .build()+ )+ .build()++ private fun line(sweep: Float, color: Int): LayoutElementBuilders.ArcLine =+ LayoutElementBuilders.ArcLine.Builder()+ .setLength(degrees(sweep))+ .setThickness(dp(6f))+ .setColor(argb(color))+ .build()++ private fun arc(sweep: Float, color: Int): LayoutElementBuilders.Arc =+ LayoutElementBuilders.Arc.Builder()+ .setAnchorAngle(degrees(0f))+ .setAnchorType(LayoutElementBuilders.ARC_ANCHOR_START)+ .addContent(line(sweep, color))+ .build()++ private fun spacer(height: Float): LayoutElementBuilders.Spacer =+ LayoutElementBuilders.Spacer.Builder().setHeight(dp(height)).build()++ private fun open(): ModifiersBuilders.Clickable =+ ModifiersBuilders.Clickable.Builder()+ .setId("open")+ .setOnClick(+ ActionBuilders.LaunchAction.Builder()+ .setAndroidActivity(+ ActionBuilders.AndroidActivity.Builder()+ .setPackageName(packageName)+ .setClassName(MainActivity::class.java.name)+ .addKeyToExtraMapping(+ "gymmane_open",+ ActionBuilders.AndroidStringExtra.Builder().setValue("play").build()+ )+ .build()+ )+ .build()+ )+ .build()++ private fun layout(d: WearData): LayoutElementBuilders.LayoutElement {+ val frac = (d.done.toFloat() / d.goal).coerceIn(0f, 1f)+ val edge = LayoutElementBuilders.Box.Builder()+ .setWidth(expand())+ .setHeight(expand())+ .setModifiers(+ ModifiersBuilders.Modifiers.Builder()+ .setPadding(ModifiersBuilders.Padding.Builder().setAll(dp(4f)).build())+ .build()+ )+ .addContent(arc(359.9f, track))+ .apply { if (frac > 0f) addContent(arc(if (frac >= 1f) 359.9f else 360f * frac, accent)) }+ .build()++ val score = LayoutElementBuilders.Row.Builder()+ .setVerticalAlignment(LayoutElementBuilders.VERTICAL_ALIGN_BOTTOM)+ .addContent(text("${d.done}", 44f, white, true))+ .addContent(text("/${d.goal}", 22f, faint, true))+ .build()++ val label = if (d.live) getString(R.string.tile_continue) else getString(R.string.tile_start)+ val pill = LayoutElementBuilders.Box.Builder()+ .setWidth(dp(118f))+ .setHeight(dp(44f))+ .setHorizontalAlignment(LayoutElementBuilders.HORIZONTAL_ALIGN_CENTER)+ .setVerticalAlignment(LayoutElementBuilders.VERTICAL_ALIGN_CENTER)+ .setModifiers(+ ModifiersBuilders.Modifiers.Builder()+ .setBackground(+ ModifiersBuilders.Background.Builder()+ .setColor(argb(white))+ .setCorner(ModifiersBuilders.Corner.Builder().setRadius(dp(22f)).build())+ .build()+ )+ .setClickable(open())+ .build()+ )+ .addContent(text(label, 15f, ink, true))+ .build()++ val column = LayoutElementBuilders.Column.Builder()+ .setWidth(wrap())+ .setHorizontalAlignment(LayoutElementBuilders.HORIZONTAL_ALIGN_CENTER)+ if (d.streak > 0) {+ column.addContent(text(resources.getQuantityString(R.plurals.tile_streak, d.streak, d.streak), 12f, accent, true))+ column.addContent(spacer(2f))+ }+ column.addContent(score)+ column.addContent(text(getString(R.string.tile_week), 12f, grey, false))+ column.addContent(spacer(12f))+ column.addContent(pill)+ if (d.next.isNotEmpty() && !d.live) {+ column.addContent(spacer(6f))+ column.addContent(+ LayoutElementBuilders.Box.Builder()+ .setWidth(dp(130f))+ .setHorizontalAlignment(LayoutElementBuilders.HORIZONTAL_ALIGN_CENTER)+ .addContent(text(d.next, 12f, grey, false))+ .build()+ )+ }++ return LayoutElementBuilders.Box.Builder()+ .setWidth(expand())+ .setHeight(expand())+ .setHorizontalAlignment(LayoutElementBuilders.HORIZONTAL_ALIGN_CENTER)+ .setVerticalAlignment(LayoutElementBuilders.VERTICAL_ALIGN_CENTER)+ .addContent(edge)+ .addContent(column.build())+ .build()+ }+}diff --git a/android/app/src/main/kotlin/com/gymmane/app/WearSurfaces.kt b/android/app/src/main/kotlin/com/gymmane/app/WearSurfaces.ktnew file mode 100644index 0000000..85a806f--- /dev/null+++ b/android/app/src/main/kotlin/com/gymmane/app/WearSurfaces.kt@@ -0,0 +1,63 @@+package com.gymmane.app++import android.content.ComponentName+import android.content.Context+import androidx.wear.tiles.TileService+import androidx.wear.watchface.complications.datasource.ComplicationDataSourceUpdateRequester+import io.flutter.plugin.common.MethodChannel++data class WearData(val done: Int, val goal: Int, val streak: Int, val next: String, val live: Boolean)++object WearSurfaces {+ const val CHANNEL = "gymmane/wear"+ private const val PREFS = "gymmane_wear"++ fun attach(context: Context, channel: MethodChannel) {+ channel.setMethodCallHandler { call, result ->+ if (call.method != "update") {+ result.notImplemented()+ return@setMethodCallHandler+ }+ val args = call.arguments as? Map<*, *>+ if (args != null) {+ save(context, args)+ refresh(context)+ }+ result.success(null)+ }+ }++ private fun save(context: Context, args: Map<*, *>) {+ context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit()+ .putInt("done", (args["done"] as? Number)?.toInt() ?: 0)+ .putInt("goal", (args["goal"] as? Number)?.toInt() ?: 1)+ .putInt("streak", (args["streak"] as? Number)?.toInt() ?: 0)+ .putString("next", args["next"] as? String ?: "")+ .putBoolean("live", args["live"] as? Boolean ?: false)+ .apply()+ }++ fun read(context: Context): WearData {+ val p = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)+ return WearData(+ done = p.getInt("done", 0),+ goal = p.getInt("goal", 1).coerceAtLeast(1),+ streak = p.getInt("streak", 0),+ next = p.getString("next", "") ?: "",+ live = p.getBoolean("live", false),+ )+ }++ private fun refresh(context: Context) {+ try {+ TileService.getUpdater(context).requestUpdate(GymTileService::class.java)+ } catch (_: Throwable) {+ }+ try {+ ComplicationDataSourceUpdateRequester+ .create(context, ComponentName(context, GymComplicationService::class.java))+ .requestUpdateAll()+ } catch (_: Throwable) {+ }+ }+}diff --git a/android/app/src/main/res/drawable/ic_complication.xml b/android/app/src/main/res/drawable/ic_complication.xmlnew file mode 100644index 0000000..decda28--- /dev/null+++ b/android/app/src/main/res/drawable/ic_complication.xml@@ -0,0 +1,10 @@+<?xml version="1.0" encoding="utf-8"?>+<vector xmlns:android="http://schemas.android.com/apk/res/android"+ android:width="24dp"+ android:height="24dp"+ android:viewportWidth="24"+ android:viewportHeight="24">+ <path+ android:fillColor="#FFFFFF"+ android:pathData="M3,9h2v6H3zM6,7h2v10H6zM16,7h2v10h-2zM19,9h2v6h-2zM8,11h8v2H8z" />+</vector>diff --git a/android/app/src/main/res/drawable/tile_preview.xml b/android/app/src/main/res/drawable/tile_preview.xmlnew file mode 100644index 0000000..9b0323d--- /dev/null+++ b/android/app/src/main/res/drawable/tile_preview.xml@@ -0,0 +1,34 @@+<?xml version="1.0" encoding="utf-8"?>+<vector xmlns:android="http://schemas.android.com/apk/res/android"+ android:width="200dp"+ android:height="200dp"+ android:viewportWidth="200"+ android:viewportHeight="200">+ <path+ android:fillColor="#0A0A0A"+ android:pathData="M100,100m-100,0a100,100 0,1 1,200 0a100,100 0,1 1,-200 0" />+ <path+ android:strokeColor="#262626"+ android:strokeWidth="6"+ android:pathData="M100,100m-93,0a93,93 0,1 1,186 0a93,93 0,1 1,-186 0" />+ <path+ android:strokeColor="#D9A184"+ android:strokeWidth="6"+ android:strokeLineCap="round"+ android:pathData="M100,7A93,93 0,1 1,7,100" />+ <path+ android:fillColor="#D9A184"+ android:pathData="M86,52h28a3,3 0,0 1,3 3v0a3,3 0,0 1,-3 3h-28a3,3 0,0 1,-3 -3v0a3,3 0,0 1,3 -3z" />+ <path+ android:fillColor="#FFFFFF"+ android:pathData="M84,66h20v32h-20z" />+ <path+ android:fillColor="#6A6A6A"+ android:pathData="M108,82h10v16h-10z" />+ <path+ android:fillColor="#9A9A9A"+ android:pathData="M78,106h44a3,3 0,0 1,3 3v0a3,3 0,0 1,-3 3h-44a3,3 0,0 1,-3 -3v0a3,3 0,0 1,3 -3z" />+ <path+ android:fillColor="#FFFFFF"+ android:pathData="M68,124h64a11,11 0,0 1,11 11v0a11,11 0,0 1,-11 11h-64a11,11 0,0 1,-11 -11v0a11,11 0,0 1,11 -11z" />+</vector>diff --git a/android/app/src/main/res/values-es/wear.xml b/android/app/src/main/res/values-es/wear.xmlnew file mode 100644index 0000000..7652ad8--- /dev/null+++ b/android/app/src/main/res/values-es/wear.xml@@ -0,0 +1,12 @@+<?xml version="1.0" encoding="utf-8"?>+<resources>+ <string name="tile_label">GymMane</string>+ <string name="tile_week">esta semana</string>+ <string name="tile_start">Empezar</string>+ <string name="tile_continue">Continuar</string>+ <plurals name="tile_streak">+ <item quantity="one">%d día seguido</item>+ <item quantity="many">%d días seguidos</item>+ <item quantity="other">%d días seguidos</item>+ </plurals>+</resources>diff --git a/android/app/src/main/res/values-watch-v31/styles.xml b/android/app/src/main/res/values-watch-v31/styles.xmlnew file mode 100644index 0000000..2c3b76a--- /dev/null+++ b/android/app/src/main/res/values-watch-v31/styles.xml@@ -0,0 +1,10 @@+<?xml version="1.0" encoding="utf-8"?>+<resources>+ <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">+ <item name="android:windowBackground">@android:color/black</item>+ <item name="android:windowSplashScreenBackground">@android:color/black</item>+ </style>+ <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">+ <item name="android:windowBackground">@android:color/black</item>+ </style>+</resources>diff --git a/android/app/src/main/res/values-watch/styles.xml b/android/app/src/main/res/values-watch/styles.xmlnew file mode 100644index 0000000..5cbdde9--- /dev/null+++ b/android/app/src/main/res/values-watch/styles.xml@@ -0,0 +1,9 @@+<?xml version="1.0" encoding="utf-8"?>+<resources>+ <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">+ <item name="android:windowBackground">@android:color/black</item>+ </style>+ <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">+ <item name="android:windowBackground">@android:color/black</item>+ </style>+</resources>diff --git a/android/app/src/main/res/values/wear.xml b/android/app/src/main/res/values/wear.xmlnew file mode 100644index 0000000..4142c74--- /dev/null+++ b/android/app/src/main/res/values/wear.xml@@ -0,0 +1,11 @@+<?xml version="1.0" encoding="utf-8"?>+<resources>+ <string name="tile_label">GymMane</string>+ <string name="tile_week">this week</string>+ <string name="tile_start">Start</string>+ <string name="tile_continue">Continue</string>+ <plurals name="tile_streak">+ <item quantity="one">%d day streak</item>+ <item quantity="other">%d day streak</item>+ </plurals>+</resources>diff --git a/lib/wear/wear_shell.dart b/lib/wear/wear_shell.dartindex 1fe2b66..2fff317 100644--- a/lib/wear/wear_shell.dart+++ b/lib/wear/wear_shell.dart@@ -74,6 +74,30 @@ class _WearShellState extends State<WearShell> with WidgetsBindingObserver {fit.addListener(_onFit);_restTick = fit.restDoneTick;_arm();+ _open.setMethodCallHandler((call) async {+ if (call.method == 'open') _openRoute(call.arguments as String?);+ });+ WidgetsBinding.instance.addPostFrameCallback((_) async {+ _openRoute(await _open.invokeMethod<String>('take'));+ });+ }++ static const _open = MethodChannel('gymmane/open');++ void _openRoute(String? route) {+ if (!mounted || route != 'play') return;+ final s = fit.session;+ if (s != null && !s.complete) {+ if (fit.route != 'session') fit.resumeSession();+ return;+ }+ final planned = fit.todayRoutine;+ if (planned != null && planned.exerciseIds.isNotEmpty) {+ fit.startRoutine(planned);+ fit.endCountdown();+ } else {+ fit.goRoutines();+ }}@override@@ -177,6 +201,16 @@ class _WearShellState extends State<WearShell> with WidgetsBindingObserver {child: KeyedSubtree(key: ValueKey(fit.route), child: _screen()),),),+ Positioned.fill(+ child: IgnorePointer(+ child: AnimatedSwitcher(+ duration: const Duration(milliseconds: 260),+ child: fit.route == 'session' && !_dim && _edgeValue() != null+ ? _EdgeRing(key: const ValueKey('edge'), value: _edgeValue()!)+ : const SizedBox.shrink(),+ ),+ ),+ ),const Positioned(top: 0, left: 0, right: 0, child: WearClock()),if (_dim) Positioned.fill(child: WearDim(onWake: _wake)),],@@ -188,6 +222,20 @@ class _WearShellState extends State<WearShell> with WidgetsBindingObserver {);}+ double? _edgeValue() {+ final s = fit.session;+ if (s == null || s.complete) return null;+ if (fit.holding && fit.holdEx == s.currentIndex) {+ if (fit.holdLead > 0) return 1;+ final total = fit.holdTotal <= 0 ? 1 : fit.holdTotal;+ return ((fit.holdRemaining ?? 0) / total).clamp(0.0, 1.0);+ }+ final left = s.restRemaining;+ if (left == null) return null;+ final total = fit.restTotal <= 0 ? 1 : fit.restTotal;+ return (left / total).clamp(0.0, 1.0);+ }+Widget _screen() {switch (fit.route) {case 'session':@@ -202,6 +250,51 @@ class _WearShellState extends State<WearShell> with WidgetsBindingObserver {}}+class _EdgeRing extends StatelessWidget {+ const _EdgeRing({super.key, required this.value});++ final double value;++ @override+ Widget build(BuildContext context) {+ final gc = context.gc;+ return TweenAnimationBuilder<double>(+ tween: Tween(end: value),+ duration: const Duration(milliseconds: 1000),+ curve: Curves.linear,+ builder: (context, v, _) => SizedBox.expand(+ child: RepaintBoundary(+ child: CustomPaint(painter: _EdgePainter(track: gc.bgRaised, fill: gc.accent, pct: v)),+ ),+ ),+ );+ }+}++class _EdgePainter extends CustomPainter {+ _EdgePainter({required this.track, required this.fill, required this.pct});++ final Color track;+ final Color fill;+ final double pct;++ @override+ void paint(Canvas canvas, Size size) {+ const stroke = 5.0;+ final side = math.min(size.width, size.height);+ final r = Rect.fromCenter(center: size.center(Offset.zero), width: side, height: side).deflate(stroke / 2 + 3);+ final paint = Paint()+ ..style = PaintingStyle.stroke+ ..strokeWidth = stroke+ ..strokeCap = StrokeCap.round;+ canvas.drawArc(r, 0, math.pi * 2, false, paint..color = track);+ if (pct > 0.002) canvas.drawArc(r, -math.pi / 2, math.pi * 2 * pct, false, paint..color = fill);+ }++ @override+ bool shouldRepaint(_EdgePainter old) => old.pct != pct || old.track != track || old.fill != fill;+}+class WearClock extends StatefulWidget {const WearClock({super.key, this.color});@@ -280,14 +373,22 @@ class _WearPageState extends State<WearPage> {Widget build(BuildContext context) {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),+ return AnimatedBuilder(+ animation: _scroll,+ builder: (context, child) {+ final p = _scroll.hasClients ? _scroll.position.pixels : 0.0;+ final top = Color.fromRGBO(0, 0, 0, 1 - (p / 40).clamp(0.0, 1.0));+ return ShaderMask(+ blendMode: BlendMode.dstIn,+ shaderCallback: (r) => LinearGradient(+ begin: Alignment.topCenter,+ end: Alignment.bottomCenter,+ colors: [top, top, const Color(0xFF000000), const Color(0xFF000000), const Color(0x00000000)],+ stops: const [0, 0.14, 0.29, 0.84, 0.98],+ ).createShader(r),+ child: child,+ );+ },child: ListView(controller: _scroll,physics: const BouncingScrollPhysics(),@@ -354,17 +455,19 @@ class WearHome extends StatelessWidget {final canStart = planned != null && planned.exerciseIds.isNotEmpty;return WearPage(children: [Center(child: _WeekRing(gc: gc, done: fit.daysDoneThisWeek, goal: fit.weeklyTarget)),- const SizedBox(height: 8),- Center(- child: Row(mainAxisSize: MainAxisSize.min, children: [- 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)),- const SizedBox(width: 4),- Text(t.daysUnit(fit.currentStreak),- style: AppTheme.f(12, weight: FontWeight.w500, color: gc.textSecondary)),- ]),- ),+ if (fit.currentStreak > 0) ...[+ const SizedBox(height: 8),+ Center(+ child: Row(mainAxisSize: MainAxisSize.min, children: [+ 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)),+ const SizedBox(width: 4),+ Text(t.daysUnit(fit.currentStreak),+ style: AppTheme.f(12, weight: FontWeight.w500, color: gc.textSecondary)),+ ]),+ ),+ ],const SizedBox(height: 12),WearButton(label: live ? t.continueBtn : t.startWorkout,@@ -473,8 +576,8 @@ class WearButton extends StatelessWidget {Widget build(BuildContext context) {final gc = context.gc;final enabled = onTap != null;- final bg = filled ? (color ?? gc.accent) : gc.bgRaised;- final fg = filled ? gc.bg : gc.text;+ final bg = filled ? (color ?? gc.ember) : gc.bgRaised;+ final fg = filled ? gc.onEmber : gc.text;return Semantics(button: true,enabled: enabled,@@ -544,8 +647,8 @@ class WearIconButton extends StatelessWidget {}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)),+ child: Text(_cap(text),+ style: AppTheme.f(17, weight: FontWeight.w800, color: gc.text, letterSpacing: -0.2)),);class WearRoutines extends StatelessWidget {@@ -716,7 +819,7 @@ class _Switch extends StatelessWidget {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)),+ decoration: BoxDecoration(color: on ? gc.text : gc.bgRaised2, borderRadius: BorderRadius.circular(100)),child: Container(width: 16,height: 16,@@ -905,8 +1008,8 @@ class WearSession extends StatelessWidget {final steppers = switch (mode) {'cardio' => [_WearStepper(- label: fit.distanceUnit.toUpperCase(),- value: fit.distanceValue(set.km ?? 0),+ label: fit.distanceUnitFor(ex.id).toUpperCase(),+ value: fit.distanceValueFor(ex.id, set.km ?? 0),onDec: () => fit.bumpSessionDistance(exIdx, pending, -1),onInc: () => fit.bumpSessionDistance(exIdx, pending, 1),),@@ -949,23 +1052,12 @@ class WearSession extends StatelessWidget {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, 10, 10, 10),decoration: BoxDecoration(color: gc.bgRaised, borderRadius: BorderRadius.circular(24)),child: Column(children: [- Text(_cap(t.rest), style: AppTheme.f(11.5, weight: FontWeight.w700, color: gc.textSecondary)),+ Text(_cap(s.restSwitch ? t.switchSides : 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))),@@ -981,7 +1073,6 @@ class WearSession extends StatelessWidget {Widget _holdCard(GymColors gc) {final lead = fit.holdLead;final left = fit.holdRemaining ?? 0;- final total = fit.holdTotal <= 0 ? 1 : fit.holdTotal;return Container(padding: const EdgeInsets.fromLTRB(10, 10, 10, 12),decoration: BoxDecoration(color: gc.bgRaised, borderRadius: BorderRadius.circular(24)),@@ -994,16 +1085,6 @@ class WearSession extends StatelessWidget {style: AppTheme.f(11.5, weight: FontWeight.w700, color: gc.textSecondary)),Text(lead > 0 ? '$lead' : durationLabel(left),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),- child: LinearProgressIndicator(- value: lead > 0 ? 0 : 1 - left / total,- minHeight: 4,- backgroundColor: gc.bgRaised2,- valueColor: AlwaysStoppedAnimation(gc.accent),- ),- ),]),);}diff --git a/lib/wear/wear_surfaces.dart b/lib/wear/wear_surfaces.dartnew file mode 100644index 0000000..fb12885--- /dev/null+++ b/lib/wear/wear_surfaces.dart@@ -0,0 +1,33 @@+import 'package:flutter/foundation.dart';+import 'package:flutter/services.dart';++import '../state/fit_state.dart';++class WearSurfaces {+ WearSurfaces._();++ static const _channel = MethodChannel('gymmane/wear');+ static String _last = '';++ static void watch() {+ fit.addListener(_push);+ _push();+ }++ static void _push() {+ final planned = fit.todayRoutine;+ final data = <String, Object>{+ 'done': fit.daysDoneThisWeek,+ 'goal': fit.weeklyTarget,+ 'streak': fit.currentStreak,+ 'next': planned != null && planned.exerciseIds.isNotEmpty ? planned.name : '',+ 'live': fit.session != null && !fit.session!.complete,+ };+ final signature = data.values.join('|');+ if (signature == _last) return;+ _last = signature;+ _channel.invokeMethod<void>('update', data).catchError((Object e) {+ debugPrint('WearSurfaces: $e');+ });+ }+}