Offline gym log for Android. No account, no ads, no internet.
Dart androidbodybuildingdartexercisesf-droidfitnessfluttergymgym-apphealthprivacyself-hostedworkoutworkout-appworkout-tracker
Keep the Today widget current and add a weekly widget
InlitXa7bd73aa543f
diff --git a/android/app/src/main/kotlin/com/gymmane/app/BodyWidgetProvider.kt b/android/app/src/main/kotlin/com/gymmane/app/BodyWidgetProvider.ktindex e180b95..57833f5 100644--- a/android/app/src/main/kotlin/com/gymmane/app/BodyWidgetProvider.kt+++ b/android/app/src/main/kotlin/com/gymmane/app/BodyWidgetProvider.kt@@ -1,11 +1,8 @@package com.gymmane.app-import android.app.PendingIntentimport android.appwidget.AppWidgetManagerimport android.content.Context-import android.content.Intentimport android.content.SharedPreferences-import android.graphics.BitmapFactoryimport android.widget.RemoteViewsimport es.antonborri.home_widget.HomeWidgetProvider@@ -18,18 +15,7 @@ class BodyWidgetProvider : HomeWidgetProvider() {) {appWidgetIds.forEach { widgetId ->val views = RemoteViews(context.packageName, R.layout.widget_body).apply {- val path = widgetData.getString("body_img", null)- if (path != null) {- val bmp = BitmapFactory.decodeFile(path)- if (bmp != null) setImageViewBitmap(R.id.widget_image, bmp)- }- val open = PendingIntent.getActivity(- context,- 0,- Intent(context, MainActivity::class.java),- PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT- )- setOnClickPendingIntent(R.id.widget_image, open)+ bindThemedImage(context, widgetData, "body_img")}appWidgetManager.updateAppWidget(widgetId, views)}diff --git a/android/app/src/main/kotlin/com/gymmane/app/HeatmapWidgetProvider.kt b/android/app/src/main/kotlin/com/gymmane/app/HeatmapWidgetProvider.ktindex d454418..abafd3a 100644--- a/android/app/src/main/kotlin/com/gymmane/app/HeatmapWidgetProvider.kt+++ b/android/app/src/main/kotlin/com/gymmane/app/HeatmapWidgetProvider.kt@@ -1,11 +1,8 @@package com.gymmane.app-import android.app.PendingIntentimport android.appwidget.AppWidgetManagerimport android.content.Context-import android.content.Intentimport android.content.SharedPreferences-import android.graphics.BitmapFactoryimport android.widget.RemoteViewsimport es.antonborri.home_widget.HomeWidgetProvider@@ -18,18 +15,7 @@ class HeatmapWidgetProvider : HomeWidgetProvider() {) {appWidgetIds.forEach { widgetId ->val views = RemoteViews(context.packageName, R.layout.widget_heatmap).apply {- val path = widgetData.getString("heatmap_img", null)- if (path != null) {- val bmp = BitmapFactory.decodeFile(path)- if (bmp != null) setImageViewBitmap(R.id.widget_image, bmp)- }- val open = PendingIntent.getActivity(- context,- 0,- Intent(context, MainActivity::class.java),- PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT- )- setOnClickPendingIntent(R.id.widget_image, open)+ bindThemedImage(context, widgetData, "heatmap_img")}appWidgetManager.updateAppWidget(widgetId, views)}diff --git a/android/app/src/main/kotlin/com/gymmane/app/StatsWidgetProvider.kt b/android/app/src/main/kotlin/com/gymmane/app/StatsWidgetProvider.ktindex 07c1450..628d49b 100644--- a/android/app/src/main/kotlin/com/gymmane/app/StatsWidgetProvider.kt+++ b/android/app/src/main/kotlin/com/gymmane/app/StatsWidgetProvider.kt@@ -1,11 +1,8 @@package com.gymmane.app-import android.app.PendingIntentimport android.appwidget.AppWidgetManagerimport android.content.Context-import android.content.Intentimport android.content.SharedPreferences-import android.graphics.BitmapFactoryimport android.widget.RemoteViewsimport es.antonborri.home_widget.HomeWidgetProvider@@ -18,18 +15,7 @@ class StatsWidgetProvider : HomeWidgetProvider() {) {appWidgetIds.forEach { widgetId ->val views = RemoteViews(context.packageName, R.layout.widget_stats).apply {- val path = widgetData.getString("stats_img", null)- if (path != null) {- val bmp = BitmapFactory.decodeFile(path)- if (bmp != null) setImageViewBitmap(R.id.widget_image, bmp)- }- val open = PendingIntent.getActivity(- context,- 0,- Intent(context, MainActivity::class.java),- PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT- )- setOnClickPendingIntent(R.id.widget_image, open)+ bindThemedImage(context, widgetData, "stats_img")}appWidgetManager.updateAppWidget(widgetId, views)}diff --git a/android/app/src/main/kotlin/com/gymmane/app/ThemedWidget.kt b/android/app/src/main/kotlin/com/gymmane/app/ThemedWidget.ktnew file mode 100644index 0000000..e7a0c8a--- /dev/null+++ b/android/app/src/main/kotlin/com/gymmane/app/ThemedWidget.kt@@ -0,0 +1,89 @@+package com.gymmane.app++import android.app.AlarmManager+import android.app.PendingIntent+import android.appwidget.AppWidgetManager+import android.content.ComponentName+import android.content.Context+import android.content.Intent+import android.content.SharedPreferences+import android.graphics.Bitmap+import android.graphics.BitmapFactory+import android.widget.RemoteViews+import es.antonborri.home_widget.HomeWidgetProvider+import java.util.Calendar+import java.util.Locale++fun RemoteViews.bindThemedImage(context: Context, widgetData: SharedPreferences, key: String) {+ val day = widgetData.getString(key, null)?.let { BitmapFactory.decodeFile(it) }+ val night = widgetData.getString("${key}_night", null)?.let { BitmapFactory.decodeFile(it) } ?: day+ bindThemedBitmaps(context, day, night)+}++fun RemoteViews.bindThemedBitmaps(context: Context, day: Bitmap?, night: Bitmap?) {+ day?.let { setImageViewBitmap(R.id.widget_image, it) }+ (night ?: day)?.let { setImageViewBitmap(R.id.widget_image_night, it) }+ val open = PendingIntent.getActivity(+ context,+ 0,+ Intent(context, MainActivity::class.java),+ PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT+ )+ setOnClickPendingIntent(R.id.widget_image, open)+ setOnClickPendingIntent(R.id.widget_image_night, open)+}++fun dayStamp(day: Calendar): String = String.format(+ Locale.ROOT,+ "%04d-%02d-%02d",+ day.get(Calendar.YEAR),+ day.get(Calendar.MONTH) + 1,+ day.get(Calendar.DAY_OF_MONTH)+)++fun weekdayIndex(day: Calendar) = (day.get(Calendar.DAY_OF_WEEK) + 5) % 7++abstract class DayWidgetProvider : HomeWidgetProvider() {+ override fun onReceive(context: Context, intent: Intent) {+ if (intent.action in rollover) {+ val manager = AppWidgetManager.getInstance(context)+ val ids = manager.getAppWidgetIds(ComponentName(context, javaClass))+ if (ids.isNotEmpty()) onUpdate(context, manager, ids)+ return+ }+ super.onReceive(context, intent)+ }++ override fun onDisabled(context: Context) {+ super.onDisabled(context)+ context.getSystemService(AlarmManager::class.java)?.cancel(newDayIntent(context))+ }++ protected fun scheduleNewDay(context: Context) {+ val alarms = context.getSystemService(AlarmManager::class.java) ?: return+ val next = Calendar.getInstance().apply {+ add(Calendar.DAY_OF_YEAR, 1)+ set(Calendar.HOUR_OF_DAY, 0)+ set(Calendar.MINUTE, 0)+ set(Calendar.SECOND, 5)+ set(Calendar.MILLISECOND, 0)+ }+ alarms.setAndAllowWhileIdle(AlarmManager.RTC, next.timeInMillis, newDayIntent(context))+ }++ private fun newDayIntent(context: Context): PendingIntent = PendingIntent.getBroadcast(+ context,+ javaClass.name.hashCode(),+ Intent(context, javaClass).setAction(ACTION_NEW_DAY),+ PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT+ )++ companion object {+ private const val ACTION_NEW_DAY = "com.gymmane.app.NEW_DAY"+ private val rollover = setOf(+ ACTION_NEW_DAY,+ Intent.ACTION_TIME_CHANGED,+ Intent.ACTION_TIMEZONE_CHANGED+ )+ }+}diff --git a/android/app/src/main/kotlin/com/gymmane/app/TodayWidgetProvider.kt b/android/app/src/main/kotlin/com/gymmane/app/TodayWidgetProvider.ktindex 7154525..a83468a 100644--- a/android/app/src/main/kotlin/com/gymmane/app/TodayWidgetProvider.kt+++ b/android/app/src/main/kotlin/com/gymmane/app/TodayWidgetProvider.kt@@ -1,37 +1,32 @@package com.gymmane.app-import android.app.PendingIntentimport android.appwidget.AppWidgetManagerimport android.content.Context-import android.content.Intentimport android.content.SharedPreferences-import android.graphics.BitmapFactoryimport android.widget.RemoteViews-import es.antonborri.home_widget.HomeWidgetProvider+import java.util.Calendar-class TodayWidgetProvider : HomeWidgetProvider() {+class TodayWidgetProvider : DayWidgetProvider() {override fun onUpdate(context: Context,appWidgetManager: AppWidgetManager,appWidgetIds: IntArray,widgetData: SharedPreferences) {+ val now = Calendar.getInstance()+ val saved = widgetData.getString("today_stamp", null)+ val key = when {+ saved == null || saved == dayStamp(now) -> "today_img"+ widgetData.getString("today_week", null)?.getOrNull(weekdayIndex(now)) == '1' -> "today_plan_img"+ else -> "today_idle_img"+ }+ val shown = if (widgetData.getString(key, null) == null) "today_img" else keyappWidgetIds.forEach { widgetId ->val views = RemoteViews(context.packageName, R.layout.widget_today).apply {- val path = widgetData.getString("today_img", null)- if (path != null) {- val bmp = BitmapFactory.decodeFile(path)- if (bmp != null) setImageViewBitmap(R.id.widget_image, bmp)- }- val open = PendingIntent.getActivity(- context,- 0,- Intent(context, MainActivity::class.java),- PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT- )- setOnClickPendingIntent(R.id.widget_image, open)+ bindThemedImage(context, widgetData, shown)}appWidgetManager.updateAppWidget(widgetId, views)}+ scheduleNewDay(context)}}diff --git a/android/app/src/main/kotlin/com/gymmane/app/WeekWidgetProvider.kt b/android/app/src/main/kotlin/com/gymmane/app/WeekWidgetProvider.ktnew file mode 100644index 0000000..67cc7e9--- /dev/null+++ b/android/app/src/main/kotlin/com/gymmane/app/WeekWidgetProvider.kt@@ -0,0 +1,54 @@+package com.gymmane.app++import android.appwidget.AppWidgetManager+import android.content.Context+import android.content.SharedPreferences+import android.graphics.Bitmap+import android.graphics.BitmapFactory+import android.graphics.Canvas+import android.graphics.Color+import android.graphics.Paint+import android.widget.RemoteViews+import java.util.Calendar++class WeekWidgetProvider : DayWidgetProvider() {+ override fun onUpdate(+ context: Context,+ appWidgetManager: AppWidgetManager,+ appWidgetIds: IntArray,+ widgetData: SharedPreferences+ ) {+ val now = Calendar.getInstance()+ val monday = (now.clone() as Calendar).apply { add(Calendar.DAY_OF_YEAR, -weekdayIndex(now)) }+ val saved = widgetData.getString("week_start", null)+ val fresh = saved != null && saved != dayStamp(monday)+ val key = if (fresh && widgetData.getString("week_fresh_img", null) != null) "week_fresh_img" else "week_img"+ val today = weekdayIndex(now)+ val doneToday = !fresh && widgetData.getString("week_done", null)?.getOrNull(today) == '1'+ val geo = widgetData.getString("week_geo", null)?.split(',')?.mapNotNull { it.toFloatOrNull() }++ fun image(suffix: String, ring: String?): Bitmap? {+ val base = widgetData.getString("$key$suffix", null)?.let { BitmapFactory.decodeFile(it) } ?: return null+ if (doneToday || geo == null || geo.size < 5) return base+ val out = base.copy(Bitmap.Config.ARGB_8888, true)+ val w = out.width.toFloat()+ val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {+ style = Paint.Style.STROKE+ strokeWidth = geo[4] * w+ color = runCatching { Color.parseColor(ring) }.getOrDefault(Color.WHITE)+ }+ Canvas(out).drawCircle((geo[0] + geo[1] * today) * w, geo[2] * out.height, geo[3] * w, paint)+ return out+ }++ val day = image("", widgetData.getString("week_ring", null))+ val night = image("_night", widgetData.getString("week_ring_night", null))+ appWidgetIds.forEach { widgetId ->+ val views = RemoteViews(context.packageName, R.layout.widget_week).apply {+ bindThemedBitmaps(context, day, night)+ }+ appWidgetManager.updateAppWidget(widgetId, views)+ }+ scheduleNewDay(context)+ }+}diff --git a/android/app/src/main/res/drawable/preview_today.png b/android/app/src/main/res/drawable/preview_today.pngindex 485cf70..fd69ed2 100644Binary files a/android/app/src/main/res/drawable/preview_today.png and b/android/app/src/main/res/drawable/preview_today.png differdiff --git a/android/app/src/main/res/drawable/preview_week.png b/android/app/src/main/res/drawable/preview_week.pngnew file mode 100644index 0000000..3107926Binary files /dev/null and b/android/app/src/main/res/drawable/preview_week.png differdiff --git a/android/app/src/main/res/layout-night/widget_body.xml b/android/app/src/main/res/layout-night/widget_body.xmlnew file mode 100644index 0000000..80f3587--- /dev/null+++ b/android/app/src/main/res/layout-night/widget_body.xml@@ -0,0 +1,23 @@+<?xml version="1.0" encoding="utf-8"?>+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"+ android:layout_width="match_parent"+ android:layout_height="match_parent">++ <ImageView+ android:id="@+id/widget_image"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:adjustViewBounds="true"+ android:scaleType="fitCenter"+ android:visibility="gone"+ android:contentDescription="GymMane" />++ <ImageView+ android:id="@+id/widget_image_night"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:adjustViewBounds="true"+ android:scaleType="fitCenter"+ android:visibility="visible"+ android:contentDescription="GymMane" />+</FrameLayout>diff --git a/android/app/src/main/res/layout-night/widget_heatmap.xml b/android/app/src/main/res/layout-night/widget_heatmap.xmlnew file mode 100644index 0000000..80f3587--- /dev/null+++ b/android/app/src/main/res/layout-night/widget_heatmap.xml@@ -0,0 +1,23 @@+<?xml version="1.0" encoding="utf-8"?>+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"+ android:layout_width="match_parent"+ android:layout_height="match_parent">++ <ImageView+ android:id="@+id/widget_image"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:adjustViewBounds="true"+ android:scaleType="fitCenter"+ android:visibility="gone"+ android:contentDescription="GymMane" />++ <ImageView+ android:id="@+id/widget_image_night"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:adjustViewBounds="true"+ android:scaleType="fitCenter"+ android:visibility="visible"+ android:contentDescription="GymMane" />+</FrameLayout>diff --git a/android/app/src/main/res/layout-night/widget_stats.xml b/android/app/src/main/res/layout-night/widget_stats.xmlnew file mode 100644index 0000000..80f3587--- /dev/null+++ b/android/app/src/main/res/layout-night/widget_stats.xml@@ -0,0 +1,23 @@+<?xml version="1.0" encoding="utf-8"?>+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"+ android:layout_width="match_parent"+ android:layout_height="match_parent">++ <ImageView+ android:id="@+id/widget_image"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:adjustViewBounds="true"+ android:scaleType="fitCenter"+ android:visibility="gone"+ android:contentDescription="GymMane" />++ <ImageView+ android:id="@+id/widget_image_night"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:adjustViewBounds="true"+ android:scaleType="fitCenter"+ android:visibility="visible"+ android:contentDescription="GymMane" />+</FrameLayout>diff --git a/android/app/src/main/res/layout-night/widget_today.xml b/android/app/src/main/res/layout-night/widget_today.xmlnew file mode 100644index 0000000..80f3587--- /dev/null+++ b/android/app/src/main/res/layout-night/widget_today.xml@@ -0,0 +1,23 @@+<?xml version="1.0" encoding="utf-8"?>+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"+ android:layout_width="match_parent"+ android:layout_height="match_parent">++ <ImageView+ android:id="@+id/widget_image"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:adjustViewBounds="true"+ android:scaleType="fitCenter"+ android:visibility="gone"+ android:contentDescription="GymMane" />++ <ImageView+ android:id="@+id/widget_image_night"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:adjustViewBounds="true"+ android:scaleType="fitCenter"+ android:visibility="visible"+ android:contentDescription="GymMane" />+</FrameLayout>diff --git a/android/app/src/main/res/layout-night/widget_week.xml b/android/app/src/main/res/layout-night/widget_week.xmlnew file mode 100644index 0000000..80f3587--- /dev/null+++ b/android/app/src/main/res/layout-night/widget_week.xml@@ -0,0 +1,23 @@+<?xml version="1.0" encoding="utf-8"?>+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"+ android:layout_width="match_parent"+ android:layout_height="match_parent">++ <ImageView+ android:id="@+id/widget_image"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:adjustViewBounds="true"+ android:scaleType="fitCenter"+ android:visibility="gone"+ android:contentDescription="GymMane" />++ <ImageView+ android:id="@+id/widget_image_night"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:adjustViewBounds="true"+ android:scaleType="fitCenter"+ android:visibility="visible"+ android:contentDescription="GymMane" />+</FrameLayout>diff --git a/android/app/src/main/res/layout/widget_body.xml b/android/app/src/main/res/layout/widget_body.xmlindex 815119c..8332aee 100644--- a/android/app/src/main/res/layout/widget_body.xml+++ b/android/app/src/main/res/layout/widget_body.xml@@ -9,5 +9,15 @@android:layout_height="match_parent"android:adjustViewBounds="true"android:scaleType="fitCenter"+ android:visibility="visible"+ android:contentDescription="GymMane" />++ <ImageView+ android:id="@+id/widget_image_night"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:adjustViewBounds="true"+ android:scaleType="fitCenter"+ android:visibility="gone"android:contentDescription="GymMane" /></FrameLayout>diff --git a/android/app/src/main/res/layout/widget_heatmap.xml b/android/app/src/main/res/layout/widget_heatmap.xmlindex 815119c..8332aee 100644--- a/android/app/src/main/res/layout/widget_heatmap.xml+++ b/android/app/src/main/res/layout/widget_heatmap.xml@@ -9,5 +9,15 @@android:layout_height="match_parent"android:adjustViewBounds="true"android:scaleType="fitCenter"+ android:visibility="visible"+ android:contentDescription="GymMane" />++ <ImageView+ android:id="@+id/widget_image_night"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:adjustViewBounds="true"+ android:scaleType="fitCenter"+ android:visibility="gone"android:contentDescription="GymMane" /></FrameLayout>diff --git a/android/app/src/main/res/layout/widget_stats.xml b/android/app/src/main/res/layout/widget_stats.xmlindex 815119c..8332aee 100644--- a/android/app/src/main/res/layout/widget_stats.xml+++ b/android/app/src/main/res/layout/widget_stats.xml@@ -9,5 +9,15 @@android:layout_height="match_parent"android:adjustViewBounds="true"android:scaleType="fitCenter"+ android:visibility="visible"+ android:contentDescription="GymMane" />++ <ImageView+ android:id="@+id/widget_image_night"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:adjustViewBounds="true"+ android:scaleType="fitCenter"+ android:visibility="gone"android:contentDescription="GymMane" /></FrameLayout>diff --git a/android/app/src/main/res/layout/widget_today.xml b/android/app/src/main/res/layout/widget_today.xmlindex 815119c..8332aee 100644--- a/android/app/src/main/res/layout/widget_today.xml+++ b/android/app/src/main/res/layout/widget_today.xml@@ -9,5 +9,15 @@android:layout_height="match_parent"android:adjustViewBounds="true"android:scaleType="fitCenter"+ android:visibility="visible"+ android:contentDescription="GymMane" />++ <ImageView+ android:id="@+id/widget_image_night"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:adjustViewBounds="true"+ android:scaleType="fitCenter"+ android:visibility="gone"android:contentDescription="GymMane" /></FrameLayout>diff --git a/android/app/src/main/res/layout/widget_week.xml b/android/app/src/main/res/layout/widget_week.xmlnew file mode 100644index 0000000..8332aee--- /dev/null+++ b/android/app/src/main/res/layout/widget_week.xml@@ -0,0 +1,23 @@+<?xml version="1.0" encoding="utf-8"?>+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"+ android:layout_width="match_parent"+ android:layout_height="match_parent">++ <ImageView+ android:id="@+id/widget_image"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:adjustViewBounds="true"+ android:scaleType="fitCenter"+ android:visibility="visible"+ android:contentDescription="GymMane" />++ <ImageView+ android:id="@+id/widget_image_night"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ android:adjustViewBounds="true"+ android:scaleType="fitCenter"+ android:visibility="gone"+ android:contentDescription="GymMane" />+</FrameLayout>diff --git a/android/app/src/main/res/xml/week_widget_info.xml b/android/app/src/main/res/xml/week_widget_info.xmlnew file mode 100644index 0000000..3d3b796--- /dev/null+++ b/android/app/src/main/res/xml/week_widget_info.xml@@ -0,0 +1,11 @@+<?xml version="1.0" encoding="utf-8"?>+<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"+ android:minWidth="250dp"+ android:minHeight="110dp"+ android:targetCellWidth="4"+ android:targetCellHeight="2"+ android:updatePeriodMillis="0"+ android:initialLayout="@layout/widget_week"+ android:resizeMode="horizontal|vertical"+ android:widgetCategory="home_screen"+ android:previewImage="@drawable/preview_week" />diff --git a/lib/services/home_widget_bridge.dart b/lib/services/home_widget_bridge.dartindex d98bdbf..f108984 100644--- a/lib/services/home_widget_bridge.dart+++ b/lib/services/home_widget_bridge.dart@@ -1,7 +1,7 @@import 'dart:io' show Platform;-import 'dart:ui';import 'package:flutter/foundation.dart';+import 'package:flutter/widgets.dart';import 'package:home_widget/home_widget.dart';import '../state/fit_state.dart';@@ -12,72 +12,165 @@ class HomeWidgetBridge {HomeWidgetBridge._();static const _pkg = 'com.gymmane.app';+ static const appGroup = 'group.com.gymmane.app';static const heatmapKey = 'heatmap_img';static const statsKey = 'stats_img';static const bodyKey = 'body_img';static const todayKey = 'today_img';+ static const todayIdleKey = 'today_idle_img';+ static const todayPlanKey = 'today_plan_img';+ static const weekKey = 'week_img';+ static const weekFreshKey = 'week_fresh_img';+ static const darkKey = 'widget_dark';+ static const themeKey = 'widget_theme';static const bodyDays = 7;- static bool get _supported => !kIsWeb && Platform.isAndroid;+ static bool get _ios => !kIsWeb && Platform.isIOS;+ static bool get _supported => !kIsWeb && (Platform.isAndroid || Platform.isIOS);+ static bool _groupReady = false;static Future<void> update() async {if (!_supported) return;try {- final gc = fit.dark ? GymColors.dark : GymColors.light;- await HomeWidget.renderFlutterWidget(- HeatmapWidgetView(- gc: gc,- levels: fit.heatmapLevelsFor(182),- streak: fit.currentStreak,- size: const Size(320, 150),+ if (_ios && !_groupReady) {+ await HomeWidget.setAppGroupId(appGroup);+ _groupReady = true;+ }+ final pref = fit.themePref;+ final day = pref == 'dark' ? GymColors.dark : GymColors.light;+ final night = pref == 'light' ? GymColors.light : GymColors.dark;+ final framed = !_ios;+ const heatmapSize = Size(320, 150);+ const statsSize = Size(155, 155);+ final bodySize = _ios ? const Size(320, 336) : const Size(320, 220);+ final todaySize = _ios ? const Size(155, 155) : const Size(120, 120);+ const weekSize = Size(320, 150);+ final week = [for (var i = 0; i < 7; i++) fit.isDayDone(i)];+ final levels = fit.heatmapLevelsFor(182);+ final heat = fit.muscleHeatOver(bodyDays);++ final views = <(String, Size, Widget Function(GymColors))>[+ (+ heatmapKey,+ heatmapSize,+ (gc) => HeatmapWidgetView(+ gc: gc,+ levels: levels,+ streak: fit.currentStreak,+ size: heatmapSize,+ framed: framed,+ ),),- key: heatmapKey,- logicalSize: const Size(320, 150),- pixelRatio: 3,- );- await HomeWidget.renderFlutterWidget(- StatsWidgetView(- gc: gc,- streak: fit.currentStreak,- sessionsThisWeek: fit.sessionsThisWeek,- goalPct: fit.goalPct,- size: const Size(155, 155),+ (+ statsKey,+ statsSize,+ (gc) => StatsWidgetView(+ gc: gc,+ streak: fit.currentStreak,+ sessionsThisWeek: fit.sessionsThisWeek,+ goalPct: fit.goalPct,+ size: statsSize,+ framed: framed,+ ),),- key: statsKey,- logicalSize: const Size(155, 155),- pixelRatio: 3,- );- await HomeWidget.renderFlutterWidget(- BodyWidgetView(- gc: gc,- intensity: fit.muscleHeatOver(bodyDays),- days: bodyDays,- size: const Size(320, 220),+ (+ bodyKey,+ bodySize,+ (gc) => BodyWidgetView(+ gc: gc,+ intensity: heat,+ days: bodyDays,+ size: bodySize,+ framed: framed,+ ),),- key: bodyKey,- logicalSize: const Size(320, 220),- pixelRatio: 3,- );- await HomeWidget.renderFlutterWidget(- TodayWidgetView(- gc: gc,- done: fit.isDayDone(fit.todayIndex),- planned: fit.todayRoutine != null,- streak: fit.currentStreak,- size: const Size(120, 120),+ (+ todayKey,+ todaySize,+ (gc) => TodayWidgetView(+ gc: gc,+ done: fit.isDayDone(fit.todayIndex),+ planned: fit.todayRoutine != null,+ streak: fit.currentStreak,+ size: todaySize,+ framed: framed,+ ),),- key: todayKey,- logicalSize: const Size(120, 120),- pixelRatio: 3,- );- await HomeWidget.updateWidget(- qualifiedAndroidName: '$_pkg.HeatmapWidgetProvider');- await HomeWidget.updateWidget(- qualifiedAndroidName: '$_pkg.BodyWidgetProvider');- await HomeWidget.updateWidget(qualifiedAndroidName: '$_pkg.TodayWidgetProvider');- await HomeWidget.updateWidget(- qualifiedAndroidName: '$_pkg.StatsWidgetProvider');+ for (final planned in [false, true])+ (+ planned ? todayPlanKey : todayIdleKey,+ todaySize,+ (gc) => TodayWidgetView(+ gc: gc,+ done: false,+ planned: planned,+ streak: 0,+ size: todaySize,+ framed: framed,+ ),+ ),+ (+ weekKey,+ weekSize,+ (gc) => WeekWidgetView(gc: gc, done: week, goal: fit.weeklyTarget, size: weekSize, framed: framed),+ ),+ (+ weekFreshKey,+ weekSize,+ (gc) => WeekWidgetView(+ gc: gc,+ done: List.filled(7, false),+ goal: fit.weeklyTarget,+ size: weekSize,+ framed: framed,+ ),+ ),+ ];+ for (final (key, size, build) in views) {+ await _render(build(day), key, size);+ if (!identical(day, night)) {+ await _render(build(night), '${key}_night', size);+ } else {+ final path = await HomeWidget.getWidgetData<String>(key);+ if (path != null) await HomeWidget.saveWidgetData<String>('${key}_night', path);+ }+ }+ final now = DateTime.now();+ await HomeWidget.saveWidgetData<String>('today_stamp', _stamp(now));+ final plan = [+ for (var d = 1; d <= 7; d++) fit.routineOn(now.add(Duration(days: d - now.weekday))) != null ? '1' : '0',+ ];+ await HomeWidget.saveWidgetData<String>('today_week', plan.join());+ await HomeWidget.saveWidgetData<String>('week_start', _stamp(fit.weekStartDate));+ await HomeWidget.saveWidgetData<String>('week_done', [for (final d in week) d ? '1' : '0'].join());+ await HomeWidget.saveWidgetData<String>(+ 'week_geo', WeekWidgetView.geometry(weekSize, framed: framed).map((v) => v.toStringAsFixed(5)).join(','));+ await HomeWidget.saveWidgetData<String>('week_ring', _hex(day.ember));+ await HomeWidget.saveWidgetData<String>('week_ring_night', _hex(night.ember));+ if (_ios) {+ await HomeWidget.saveWidgetData<bool>(darkKey, fit.dark);+ await HomeWidget.saveWidgetData<String>(themeKey, pref);+ }++ await _reload('HeatmapWidgetProvider', 'HeatmapWidget');+ await _reload('BodyWidgetProvider', 'BodyWidget');+ await _reload('TodayWidgetProvider', 'TodayWidget');+ await _reload('StatsWidgetProvider', 'StatsWidget');+ await _reload('WeekWidgetProvider', 'WeekWidget');} catch (e) {debugPrint('HomeWidgetBridge.update falló: $e');}}++ static String _stamp(DateTime d) =>+ '${d.year.toString().padLeft(4, '0')}-${d.month.toString().padLeft(2, '0')}-${d.day.toString().padLeft(2, '0')}';++ static String _hex(Color c) => '#${c.toARGB32().toRadixString(16).padLeft(8, '0').toUpperCase()}';++ static Future<void> _render(Widget view, String key, Size size) =>+ HomeWidget.renderFlutterWidget(view, key: key, logicalSize: size, pixelRatio: 3);++ static Future<void> _reload(String android, String ios) => HomeWidget.updateWidget(+ qualifiedAndroidName: '$_pkg.$android',+ iOSName: ios,+ );}diff --git a/lib/widgets/home_widget_views.dart b/lib/widgets/home_widget_views.dartindex 60525b3..c1b4432 100644--- a/lib/widgets/home_widget_views.dart+++ b/lib/widgets/home_widget_views.dart@@ -6,14 +6,21 @@ import '../l10n/l10n.dart';import '../state/fit_state.dart';import '../theme/app_colors.dart';import 'body_map.dart';+import 'ui_kit.dart';-const _kDisplay = 'Oswald';-const _kBody = 'IBM Plex Sans';+const _kDisplay = 'Nunito';+const _kBody = 'Nunito';const _kBorder = 1.0;Color _heat(int level, GymColors gc) =>level <= 0 ? gc.heatEmpty : heatLevelColor(gc, level);+BoxDecoration _card(GymColors gc, bool framed, double radius) => BoxDecoration(+ color: gc.bgRaised,+ borderRadius: framed ? BorderRadius.circular(radius) : null,+ border: framed ? Border.all(color: gc.border, width: _kBorder) : null,+ );+class HeatmapWidgetView extends StatelessWidget {const HeatmapWidgetView({super.key,@@ -21,12 +28,14 @@ class HeatmapWidgetView extends StatelessWidget {required this.levels,required this.streak,this.size = const Size(320, 150),+ this.framed = true,});final GymColors gc;final List<int> levels;final int streak;final Size size;+ final bool framed;@overrideWidget build(BuildContext context) {@@ -55,40 +64,39 @@ class HeatmapWidgetView extends StatelessWidget {width: size.width,height: size.height,padding: const EdgeInsets.all(pad),- decoration: BoxDecoration(- color: gc.bgRaised,- borderRadius: BorderRadius.circular(24),- border: Border.all(color: gc.border, width: _kBorder),- ),+ decoration: _card(gc, framed, 24),child: Column(crossAxisAlignment: CrossAxisAlignment.start,children: [- Row(- children: [- Flexible(- child: Text('GYMMANE',- maxLines: 1,- overflow: TextOverflow.clip,- softWrap: false,+ SizedBox(+ height: headerH - 10,+ child: Row(+ children: [+ Expanded(+ child: Text('GymMane',+ maxLines: 1,+ overflow: TextOverflow.clip,+ softWrap: false,+ style: TextStyle(+ fontFamily: _kDisplay,+ fontSize: 16,+ height: 1.2,+ fontWeight: FontWeight.w800,+ color: gc.text)),+ ),+ Icon(Icons.local_fire_department_rounded, size: 15, color: gc.accent),+ const SizedBox(width: 3),+ Text('$streak',style: TextStyle(fontFamily: _kDisplay,- fontSize: 13,- fontWeight: FontWeight.w600,- letterSpacing: 2,- color: gc.text)),- ),- const Spacer(),- Icon(Icons.local_fire_department_rounded, size: 15, color: gc.accent),- const SizedBox(width: 3),- Text('$streak',- style: TextStyle(- fontFamily: _kDisplay,- fontSize: 15,- fontWeight: FontWeight.w700,- color: gc.accent)),- ],+ fontSize: 15,+ height: 1.2,+ fontWeight: FontWeight.w700,+ color: gc.accent)),+ ],+ ),),- const SizedBox(height: 12),+ const SizedBox(height: 10),Expanded(child: Row(crossAxisAlignment: CrossAxisAlignment.start,@@ -128,6 +136,7 @@ class StatsWidgetView extends StatelessWidget {required this.sessionsThisWeek,required this.goalPct,this.size = const Size(155, 155),+ this.framed = true,});final GymColors gc;@@ -135,6 +144,7 @@ class StatsWidgetView extends StatelessWidget {final int sessionsThisWeek;final int goalPct;final Size size;+ final bool framed;@overrideWidget build(BuildContext context) {@@ -142,11 +152,7 @@ class StatsWidgetView extends StatelessWidget {width: size.width,height: size.height,padding: const EdgeInsets.all(16),- decoration: BoxDecoration(- color: gc.bgRaised,- borderRadius: BorderRadius.circular(24),- border: Border.all(color: gc.border, width: _kBorder),- ),+ decoration: _card(gc, framed, 24),child: Column(crossAxisAlignment: CrossAxisAlignment.start,children: [@@ -154,13 +160,12 @@ class StatsWidgetView extends StatelessWidget {children: [Icon(Icons.local_fire_department_rounded, size: 16, color: gc.accent),const SizedBox(width: 4),- Text(t.streakCaps,+ Text(titleCase(t.streakCaps),style: TextStyle(fontFamily: _kDisplay,- fontSize: 11,- fontWeight: FontWeight.w600,- letterSpacing: 2,- color: gc.textSecondary)),+ fontSize: 14,+ fontWeight: FontWeight.w800,+ color: gc.text)),],),const SizedBox(height: 14),@@ -242,6 +247,7 @@ class TodayWidgetView extends StatelessWidget {required this.planned,required this.streak,this.size = const Size(120, 120),+ this.framed = true,});final GymColors gc;@@ -249,42 +255,166 @@ class TodayWidgetView extends StatelessWidget {final bool planned;final int streak;final Size size;+ final bool framed;@overrideWidget build(BuildContext context) {- final ring = done ? gc.accent : (planned ? gc.brass : gc.border);+ final side = size.shortestSide;+ final tone = planned ? gc.brass : gc.textTertiary;return Container(width: size.width,height: size.height,- decoration: BoxDecoration(- color: gc.bgRaised,- borderRadius: BorderRadius.circular(size.width * 0.3),- border: Border.all(color: gc.border, width: _kBorder),- ),+ decoration: _card(gc, framed, side * 0.3),child: Center(child: Container(- width: size.width * 0.62,- height: size.width * 0.62,+ width: side * 0.62,+ height: side * 0.62,decoration: BoxDecoration(- color: done ? gc.accentSoft : Colors.transparent,+ color: done ? gc.accent : Colors.transparent,shape: BoxShape.circle,- border: Border.all(color: ring, width: size.width * 0.045),+ border: done ? null : Border.all(color: planned ? gc.brass : gc.border, width: side * 0.035),),child: Center(child: done- ? Icon(Icons.check_rounded, size: size.width * 0.3, color: gc.accent)- : Text(- '${DateTime.now().day}',- style: TextStyle(- fontFamily: _kDisplay,- fontSize: size.width * 0.26,- height: 1,- fontWeight: FontWeight.w700,- color: planned ? gc.text : gc.textSecondary,+ ? Icon(Icons.check_rounded, size: side * 0.34, color: gc.bgRaised)+ : Icon(Icons.fitness_center_rounded, size: side * 0.22, color: tone),+ ),+ ),+ ),+ );+ }+}++class WeekWidgetView extends StatelessWidget {+ const WeekWidgetView({+ super.key,+ required this.gc,+ required this.done,+ required this.goal,+ this.size = const Size(320, 150),+ this.framed = true,+ });++ final GymColors gc;+ final List<bool> done;+ final int goal;+ final Size size;+ final bool framed;++ static const pad = 18.0;+ static const dot = 32.0;++ static List<double> geometry(Size size, {bool framed = true}) {+ final inset = pad + (framed ? _kBorder : 0);+ final col = (size.width - inset * 2) / 7;+ return [+ (inset + col / 2) / size.width,+ col / size.width,+ (size.height - inset - dot / 2) / size.height,+ (dot / 2 - 1) / size.width,+ 2 / size.width,+ ];+ }++ @override+ Widget build(BuildContext context) {+ final count = done.where((d) => d).length;+ return Container(+ width: size.width,+ height: size.height,+ padding: const EdgeInsets.all(pad),+ decoration: _card(gc, framed, 24),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Row(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Expanded(+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(t.thisWeek.toUpperCase(),+ maxLines: 1,+ overflow: TextOverflow.clip,+ softWrap: false,+ style: TextStyle(+ fontFamily: _kBody,+ fontSize: 10.5,+ height: 1.2,+ fontWeight: FontWeight.w700,+ letterSpacing: 1.2,+ color: gc.textTertiary)),+ const SizedBox(height: 4),+ Row(+ crossAxisAlignment: CrossAxisAlignment.baseline,+ textBaseline: TextBaseline.alphabetic,+ children: [+ Text('$count',+ style: TextStyle(+ fontFamily: _kDisplay,+ fontSize: 30,+ height: 1,+ fontWeight: FontWeight.w800,+ color: gc.text)),+ Text('/$goal',+ style: TextStyle(+ fontFamily: _kDisplay,+ fontSize: 16,+ height: 1,+ fontWeight: FontWeight.w700,+ color: gc.textSecondary)),+ ],),+ ],+ ),+ ),+ SizedBox(+ width: 30,+ height: 30,+ child: CircularProgressIndicator(+ value: goal <= 0 ? 0 : (count / goal).clamp(0.0, 1.0),+ strokeWidth: 4,+ strokeCap: StrokeCap.round,+ backgroundColor: gc.bgRaised2,+ valueColor: AlwaysStoppedAnimation(gc.accent),+ ),+ ),+ ],+ ),+ const Spacer(),+ Row(+ children: [+ for (var i = 0; i < 7; i++)+ Expanded(+ child: Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ Text(t.weekdayInitial(i + 1),+ style: TextStyle(+ fontFamily: _kBody,+ fontSize: 10,+ height: 1.2,+ fontWeight: FontWeight.w700,+ color: gc.textTertiary)),+ const SizedBox(height: 6),+ Container(+ width: dot,+ height: dot,+ decoration: BoxDecoration(+ color: done[i] ? gc.ember : gc.bgRaised2,+ shape: BoxShape.circle,+ ),+ child: done[i]+ ? Icon(Icons.check_rounded, size: 17, color: gc.onEmber)+ : null,+ ),+ ],),+ ),+ ],),- ),+ ],),);}@@ -297,12 +427,14 @@ class BodyWidgetView extends StatelessWidget {required this.intensity,required this.days,this.size = const Size(320, 220),+ this.framed = true,});final GymColors gc;final Map<String, double> intensity;final int days;final Size size;+ final bool framed;@overrideWidget build(BuildContext context) {@@ -317,11 +449,7 @@ class BodyWidgetView extends StatelessWidget {width: size.width,height: size.height,padding: const EdgeInsets.all(pad),- decoration: BoxDecoration(- color: gc.bgRaised,- borderRadius: BorderRadius.circular(24),- border: Border.all(color: gc.border, width: _kBorder),- ),+ decoration: _card(gc, framed, 24),child: Column(crossAxisAlignment: CrossAxisAlignment.start,children: [@@ -329,19 +457,17 @@ class BodyWidgetView extends StatelessWidget {height: headerH - 8,child: Row(children: [- Flexible(- child: Text(t.muscleMap,+ Expanded(+ child: Text(titleCase(t.muscleMap),maxLines: 1,overflow: TextOverflow.clip,softWrap: false,style: TextStyle(fontFamily: _kDisplay,- fontSize: 12,- fontWeight: FontWeight.w600,- letterSpacing: 2,+ fontSize: 15,+ fontWeight: FontWeight.w800,color: gc.text)),),- const Spacer(),for (int i = 1; i <= heatLevels; i++) ...[if (i > 1) const SizedBox(width: 3),Container(diff --git a/test/home_widgets_test.dart b/test/home_widgets_test.dartindex beaff12..5bd8d93 100644--- a/test/home_widgets_test.dart+++ b/test/home_widgets_test.dart@@ -31,6 +31,27 @@ void main() {});}+ testWidgets('the iOS sizes draw without a frame and without overflowing', (tester) async {+ const gc = GymColors.dark;+ await draw(tester,+ HeatmapWidgetView(gc: gc, levels: List.filled(182, 3), streak: 40, framed: false));+ await draw(tester,+ const StatsWidgetView(gc: gc, streak: 120, sessionsThisWeek: 5, goalPct: 100, framed: false));+ await draw(+ tester,+ const BodyWidgetView(+ gc: gc,+ days: 7,+ intensity: {'chest': 1.0, 'back': 0.5, 'quads': 0.1},+ size: Size(320, 336),+ framed: false,+ ));+ await draw(+ tester,+ const TodayWidgetView(+ gc: gc, done: false, planned: true, streak: 3, size: Size(155, 155), framed: false));+ });+testWidgets('the muscle map widget survives an empty history', (tester) async {await draw(tester,const BodyWidgetView(gc: GymColors.dark, days: 7, intensity: {}));