Skip to content

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

Quick Settings tiles for today's workout and the gym pass

InlitXe2fd54b0f616
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 c10412a..44460f3 100644
--- a/android/app/src/main/kotlin/com/gymmane/app/MainActivity.kt
+++ b/android/app/src/main/kotlin/com/gymmane/app/MainActivity.kt
@@ -30,6 +30,7 @@ class MainActivity : FlutterActivity() {
override fun getFlutterShellArgs(): FlutterShellArgs {
val args = super.getFlutterShellArgs()
+ GraphicsMode.starting(this)
if (GraphicsMode.compat(this)) args.add(GraphicsMode.DISABLE_IMPELLER)
return args
}
@@ -43,6 +44,10 @@ class MainActivity : FlutterActivity() {
"state" -> result.success(
mapOf("compat" to GraphicsMode.compat(this), "detected" to GraphicsMode.detected(this)),
)
+ "ready" -> {
+ GraphicsMode.ready(this)
+ result.success(null)
+ }
"set" -> {
result.success(null)
val on = call.argument<Boolean>("compat") ?: false
@@ -174,6 +179,8 @@ class MainActivity : FlutterActivity() {
NfcBridge.attach(this, MethodChannel(messenger, NfcBridge.CHANNEL))
VoiceBridge.attach(this, MethodChannel(messenger, VoiceBridge.CHANNEL))
WearSurfaces.attach(this, MethodChannel(messenger, WearSurfaces.CHANNEL))
+ WatchLinkBridge.attach(this, MethodChannel(messenger, WatchLinkBridge.CHANNEL))
+ QuickTiles.attach(this, MethodChannel(messenger, QuickTiles.CHANNEL))
}
private fun currentDisplay(): android.view.Display? =
@@ -270,6 +277,7 @@ class MainActivity : FlutterActivity() {
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
if (HealthBridge.onPermissionResult(requestCode, grantResults)) return
+ if (WatchLinkBridge.onPermissionResult(requestCode, grantResults)) return
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
}
@@ -294,6 +302,7 @@ class MainActivity : FlutterActivity() {
rotaryChannel = null
openChannel = null
NfcBridge.detach(this)
+ WatchLinkBridge.detach()
LiveNotifier.dart = null
HealthBridge.channel = null
if (isFinishing) LiveNotifier.cancel(this)
diff --git a/android/app/src/main/kotlin/com/gymmane/app/QuickTiles.kt b/android/app/src/main/kotlin/com/gymmane/app/QuickTiles.kt
new file mode 100644
index 0000000..e9d3e2e
--- /dev/null
+++ b/android/app/src/main/kotlin/com/gymmane/app/QuickTiles.kt
@@ -0,0 +1,127 @@
+package com.gymmane.app
+
+import android.app.Activity
+import android.app.PendingIntent
+import android.app.StatusBarManager
+import android.content.ComponentName
+import android.content.Context
+import android.content.Intent
+import android.graphics.drawable.Icon
+import android.os.Build
+import android.service.quicksettings.Tile
+import android.service.quicksettings.TileService
+import io.flutter.plugin.common.MethodChannel
+
+object QuickTiles {
+ const val CHANNEL = "gymmane/qs"
+ private const val PREFS = "gymmane_qs"
+
+ fun attach(activity: Activity, ch: MethodChannel) {
+ ch.setMethodCallHandler { call, result ->
+ when (call.method) {
+ "update" -> {
+ activity.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit()
+ .putString("today", call.argument<String>("today") ?: "")
+ .putString("pass", call.argument<String>("pass") ?: "")
+ .putString("todayLabel", call.argument<String>("todayLabel") ?: "")
+ .putString("passLabel", call.argument<String>("passLabel") ?: "")
+ .apply()
+ refresh(activity)
+ result.success(null)
+ }
+ "canAdd" -> result.success(Build.VERSION.SDK_INT >= 33)
+ "add" -> add(activity, call.argument<String>("tile") ?: "today", result)
+ else -> result.notImplemented()
+ }
+ }
+ }
+
+ fun refresh(context: Context) {
+ for (c in listOf(TodayTileService::class.java, PassTileService::class.java)) {
+ runCatching { TileService.requestListeningState(context, ComponentName(context, c)) }
+ }
+ }
+
+ fun text(context: Context, key: String): String =
+ context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).getString(key, "") ?: ""
+
+ private fun add(activity: Activity, tile: String, result: MethodChannel.Result) {
+ if (Build.VERSION.SDK_INT < 33) {
+ result.success("unsupported")
+ return
+ }
+ val pass = tile == "pass"
+ val service = if (pass) PassTileService::class.java else TodayTileService::class.java
+ val label = text(activity, if (pass) "passLabel" else "todayLabel").ifEmpty { "GymMane" }
+ val icon = Icon.createWithResource(activity, if (pass) R.drawable.ic_qs_pass else R.drawable.ic_qs_today)
+ val manager = activity.getSystemService(StatusBarManager::class.java)
+ if (manager == null) {
+ result.success("unsupported")
+ return
+ }
+ runCatching {
+ manager.requestAddTileService(ComponentName(activity, service), label, icon, activity.mainExecutor) { code ->
+ result.success(
+ when (code) {
+ StatusBarManager.TILE_ADD_REQUEST_RESULT_TILE_ADDED -> "added"
+ StatusBarManager.TILE_ADD_REQUEST_RESULT_TILE_ALREADY_ADDED -> "already"
+ else -> "no"
+ },
+ )
+ }
+ }.onFailure { result.success("unsupported") }
+ }
+}
+
+abstract class OpenTile : TileService() {
+ abstract val route: String
+ abstract val labelKey: String
+ abstract val subtitleKey: String
+
+ override fun onStartListening() {
+ super.onStartListening()
+ val tile = qsTile ?: return
+ tile.state = Tile.STATE_INACTIVE
+ val label = QuickTiles.text(this, labelKey)
+ if (label.isNotEmpty()) tile.label = label
+ if (Build.VERSION.SDK_INT >= 29) {
+ tile.subtitle = QuickTiles.text(this, subtitleKey).ifEmpty { null }
+ }
+ tile.updateTile()
+ }
+
+ override fun onClick() {
+ super.onClick()
+ val intent = Intent(this, MainActivity::class.java).apply {
+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP)
+ putExtra(OPEN_EXTRA, route)
+ }
+ val open = Runnable {
+ if (Build.VERSION.SDK_INT >= 34) {
+ val pending = PendingIntent.getActivity(
+ this,
+ route.hashCode(),
+ intent,
+ PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
+ )
+ startActivityAndCollapse(pending)
+ } else {
+ @Suppress("DEPRECATION")
+ startActivityAndCollapse(intent)
+ }
+ }
+ if (isLocked) unlockAndRun(open) else open.run()
+ }
+}
+
+class TodayTileService : OpenTile() {
+ override val route = "today"
+ override val labelKey = "todayLabel"
+ override val subtitleKey = "today"
+}
+
+class PassTileService : OpenTile() {
+ override val route = "pass"
+ override val labelKey = "passLabel"
+ override val subtitleKey = "pass"
+}
diff --git a/android/app/src/main/res/drawable/ic_qs_pass.xml b/android/app/src/main/res/drawable/ic_qs_pass.xml
new file mode 100644
index 0000000..a231e8b
--- /dev/null
+++ b/android/app/src/main/res/drawable/ic_qs_pass.xml
@@ -0,0 +1,11 @@
+<?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="#FFFFFFFF"
+ android:fillType="evenOdd"
+ android:pathData="M5,4.5h14a3,3 0,0 1,3 3v9a3,3 0,0 1,-3 3h-14a3,3 0,0 1,-3 -3v-9a3,3 0,0 1,3 -3zM5,6.5a1,1 0,0 0,-1 1v9a1,1 0,0 0,1 1h14a1,1 0,0 0,1 -1v-9a1,1 0,0 0,-1 -1zM6,9h2v6h-2zM9.5,9h1v6h-1zM12,9h2v6h-2zM15.5,9h1v6h-1zM17.5,9h0.5v6h-0.5z" />
+</vector>
diff --git a/android/app/src/main/res/drawable/ic_qs_today.xml b/android/app/src/main/res/drawable/ic_qs_today.xml
new file mode 100644
index 0000000..2321dbc
--- /dev/null
+++ b/android/app/src/main/res/drawable/ic_qs_today.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="#FFFFFFFF"
+ android:pathData="M5,8.5a1.5,1.5 0,0 1,1.5 -1.5h0a1.5,1.5 0,0 1,1.5 1.5v7a1.5,1.5 0,0 1,-1.5 1.5h0a1.5,1.5 0,0 1,-1.5 -1.5zM16,8.5a1.5,1.5 0,0 1,1.5 -1.5h0a1.5,1.5 0,0 1,1.5 1.5v7a1.5,1.5 0,0 1,-1.5 1.5h0a1.5,1.5 0,0 1,-1.5 -1.5zM2,10.5a1,1 0,0 1,1 -1h0a1,1 0,0 1,1 1v3a1,1 0,0 1,-1 1h0a1,1 0,0 1,-1 -1zM20,10.5a1,1 0,0 1,1 -1h0a1,1 0,0 1,1 1v3a1,1 0,0 1,-1 1h0a1,1 0,0 1,-1 -1zM8.5,11h7v2h-7z" />
+</vector>
diff --git a/android/app/src/main/res/values-es/shortcuts.xml b/android/app/src/main/res/values-es/shortcuts.xml
index a6451c2..84c1b2a 100644
--- a/android/app/src/main/res/values-es/shortcuts.xml
+++ b/android/app/src/main/res/values-es/shortcuts.xml
@@ -2,4 +2,6 @@
<resources>
<string name="shortcut_start_short">Empezar entreno</string>
<string name="shortcut_start_long">Empezar entreno</string>
+ <string name="qs_today">Entreno de hoy</string>
+ <string name="qs_pass">Pase del gimnasio</string>
</resources>
diff --git a/android/app/src/main/res/values/shortcuts.xml b/android/app/src/main/res/values/shortcuts.xml
index 8c2495c..4012e6c 100644
--- a/android/app/src/main/res/values/shortcuts.xml
+++ b/android/app/src/main/res/values/shortcuts.xml
@@ -2,4 +2,6 @@
<resources>
<string name="shortcut_start_short">Start workout</string>
<string name="shortcut_start_long">Start workout</string>
+ <string name="qs_today">Today\'s workout</string>
+ <string name="qs_pass">Gym pass</string>
</resources>
diff --git a/lib/screens/gym_pass_screen.dart b/lib/screens/gym_pass_screen.dart
index 59b16e4..ba743f1 100644
--- a/lib/screens/gym_pass_screen.dart
+++ b/lib/screens/gym_pass_screen.dart
@@ -10,6 +10,7 @@ import '../models/gym_pass.dart';
import '../services/media_store.dart';
import '../services/pass_scan.dart';
import '../services/screen_awake.dart';
+import '../services/quick_tiles.dart';
import '../state/fit_state.dart';
import '../theme/app_colors.dart';
import '../theme/app_theme.dart';
@@ -642,6 +643,42 @@ class _PassEditorState extends State<_PassEditor> {
style: AppTheme.f(13, weight: FontWeight.w700, color: gc.textSecondary)),
),
),
+ if (widget.pass != null && fit.gymPasses.length > 1 && QuickTiles.available) ...[
+ const SizedBox(height: 8),
+ AnimatedBuilder(
+ animation: fit,
+ builder: (context, _) {
+ final on = fit.quickPass?.id == widget.pass!.id;
+ return Semantics(
+ toggled: on,
+ child: Pressable(
+ onTap: () {
+ HapticFeedback.selectionClick();
+ if (!on) fit.setQuickPass(widget.pass!.id);
+ },
+ child: Container(
+ constraints: const BoxConstraints(minHeight: 58),
+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
+ decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(20)),
+ child: Row(children: [
+ Expanded(
+ child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ Text(t.qsPassUse, style: AppTheme.f(14.5, weight: FontWeight.w600, color: gc.text)),
+ const SizedBox(height: 3),
+ Text(t.qsPassUseHint,
+ style: AppTheme.f(11.5,
+ weight: FontWeight.w500, color: gc.textSecondary, height: 1.3)),
+ ]),
+ ),
+ const SizedBox(width: 12),
+ TinySwitch(on: on),
+ ]),
+ ),
+ ),
+ );
+ },
+ ),
+ ],
const SizedBox(height: 18),
AnimatedOpacity(
duration: const Duration(milliseconds: 200),
diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart
index cf8b268..554acdd 100644
--- a/lib/screens/settings_screen.dart
+++ b/lib/screens/settings_screen.dart
@@ -31,9 +31,13 @@ import '../theme/app_colors.dart';
import '../theme/app_theme.dart';
import '../services/app_icon.dart';
import '../services/nfc_tags.dart';
+import '../services/quick_tiles.dart';
+import '../services/watch_link.dart';
import 'help_topics.dart';
import '../widgets/app_icon_sheet.dart';
import '../widgets/nfc_sheet.dart';
+import '../widgets/quick_tiles_sheet.dart';
+import '../widgets/watch_sheet.dart';
import '../widgets/auto_backup_sheet.dart';
import '../widgets/body_rulers.dart';
import '../widgets/dialogs.dart';
@@ -504,6 +508,18 @@ class SettingsScreen extends StatelessWidget {
hint: t.nfcRowHint,
),
),
+ if (QuickTiles.available)
+ GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => showQuickTilesSheet(context),
+ child: _prefRow(
+ gc,
+ PhosphorIconsRegular.squaresFour,
+ t.qsRow,
+ Icon(PhosphorIconsRegular.caretRight, size: 15, color: gc.textTertiary),
+ hint: t.qsRowHint,
+ ),
+ ),
]),
_subhead(gc, t.routines),
_card(gc, [
@@ -804,10 +820,11 @@ class SettingsScreen extends StatelessWidget {
(PhosphorIconsRegular.downloadSimple, t.importBackup, () => _importBackup(context)),
if (AutoBackup.instance.supported)
(PhosphorIconsRegular.clockCounterClockwise, t.autoBackup, () => showAutoBackupSheet(context)),
+ if (WatchLink.instance.available) (PhosphorIconsRegular.watch, t.watchRow, () => showWatchSheet(context)),
(PhosphorIconsRegular.export, t.stravaRow, () => showStravaSheet(context)),
(PhosphorIconsRegular.barbell, t.clearWorkouts, () => _clearWorkouts(context)),
(PhosphorIconsRegular.trash, t.resetData, () => _resetAll(context)),
- ], danger: AutoBackup.instance.supported ? 6 : 5),
+ ], danger: (AutoBackup.instance.supported ? 6 : 5) + (WatchLink.instance.available ? 1 : 0)),
];
default:
return [
@@ -900,6 +917,7 @@ class SettingsScreen extends StatelessWidget {
(t.deloadSetting, PhosphorIconsRegular.feather),
(t.voiceSetting, PhosphorIconsRegular.waveform),
if (NfcTags.available) (t.nfcRow, PhosphorIconsRegular.contactlessPayment),
+ if (QuickTiles.available) (t.qsRow, PhosphorIconsRegular.squaresFour),
(t.autoAdvance, PhosphorIconsRegular.skipForward),
(t.countdownSetting, PhosphorIconsRegular.timer),
(t.keepScreenOn, PhosphorIconsRegular.sun),
@@ -947,6 +965,7 @@ class SettingsScreen extends StatelessWidget {
(t.exportBackup, PhosphorIconsRegular.fileZip),
(t.importBackup, PhosphorIconsRegular.downloadSimple),
(t.autoBackup, PhosphorIconsRegular.clockCounterClockwise),
+ if (WatchLink.instance.available) (t.watchRow, PhosphorIconsRegular.watch),
(t.importFromApp, PhosphorIconsRegular.arrowSquareIn),
(t.stravaRow, PhosphorIconsRegular.export),
(t.clearWorkouts, PhosphorIconsRegular.barbell),
diff --git a/lib/services/quick_tiles.dart b/lib/services/quick_tiles.dart
new file mode 100644
index 0000000..c490454
--- /dev/null
+++ b/lib/services/quick_tiles.dart
@@ -0,0 +1,62 @@
+import 'dart:async';
+import 'dart:convert';
+import 'dart:io';
+
+import 'package:flutter/foundation.dart';
+import 'package:flutter/services.dart';
+
+import '../l10n/l10n.dart';
+import '../state/fit_state.dart';
+
+class QuickTiles {
+ QuickTiles._();
+
+ static const _ch = MethodChannel('gymmane/qs');
+ static bool canAdd = false;
+ static String _sent = '';
+
+ static bool get available => !kIsWeb && Platform.isAndroid;
+
+ static Future<void> init() async {
+ if (!available) return;
+ try {
+ canAdd = await _ch.invokeMethod<bool>('canAdd') ?? false;
+ } catch (_) {}
+ push();
+ fit.addListener(push);
+ }
+
+ static Map<String, String> state() {
+ final now = DateTime.now();
+ final names = [
+ for (final r in fit.routinesOn(now))
+ if (r.exerciseIds.isNotEmpty) r.name,
+ ];
+ final pass = fit.quickPass;
+ return {
+ 'todayLabel': t.qsToday,
+ 'today': names.isNotEmpty ? names.join(' · ') : (fit.restingToday ? t.qsRest : ''),
+ 'passLabel': pass?.name ?? t.qsPass,
+ 'pass': pass == null ? '' : t.qsPass,
+ };
+ }
+
+ static void push() {
+ if (!available) return;
+ final s = state();
+ final sig = jsonEncode(s);
+ if (sig == _sent) return;
+ _sent = sig;
+ unawaited(_ch.invokeMethod<void>('update', s).catchError((_) {}));
+ }
+
+ static Future<String> add(String tile) async {
+ if (!available) return 'unsupported';
+ push();
+ try {
+ return await _ch.invokeMethod<String>('add', {'tile': tile}) ?? 'no';
+ } catch (_) {
+ return 'unsupported';
+ }
+ }
+}
diff --git a/lib/state/gym_pass_state.dart b/lib/state/gym_pass_state.dart
index 1c3c914..ed53490 100644
--- a/lib/state/gym_pass_state.dart
+++ b/lib/state/gym_pass_state.dart
@@ -3,6 +3,19 @@ part of 'fit_state.dart';
mixin GymPassState on FitCore {
final List<GymPass> gymPasses = [];
String lastPassId = '';
+ String quickPassId = '';
+
+ GymPass? get quickPass {
+ if (gymPasses.isEmpty) return null;
+ return gymPasses.firstWhere((p) => p.id == quickPassId, orElse: () => gymPasses.first);
+ }
+
+ void setQuickPass(String id) {
+ if (quickPassId == id) return;
+ quickPassId = id;
+ _persist();
+ notifyListeners();
+ }
GymPass? get lastPass {
if (gymPasses.isEmpty) return null;
@@ -73,5 +86,6 @@ mixin GymPassState on FitCore {
.where((p) => p.code.isNotEmpty));
}
lastPassId = data['lastPass'] as String? ?? '';
+ quickPassId = data['quickPass'] as String? ?? '';
}
}
diff --git a/lib/widgets/nfc_sheet.dart b/lib/widgets/nfc_sheet.dart
index 10836cd..d134b8b 100644
--- a/lib/widgets/nfc_sheet.dart
+++ b/lib/widgets/nfc_sheet.dart
@@ -29,8 +29,8 @@ void showNfcSheet(BuildContext context) {
DateTime? _lastTag;
-void openTodayFromTag(BuildContext context) {
- if (!fit.nfcTag || !fit.onboarded || _TodaySheetState.open != null) return;
+void openTodayFromTag(BuildContext context, {bool tag = true}) {
+ if ((tag && !fit.nfcTag) || !fit.onboarded || _TodaySheetState.open != null) return;
final now = DateTime.now();
final last = _lastTag;
if (last != null && now.difference(last) < const Duration(milliseconds: 1500)) return;
diff --git a/lib/widgets/quick_tiles_sheet.dart b/lib/widgets/quick_tiles_sheet.dart
new file mode 100644
index 0000000..8e91354
--- /dev/null
+++ b/lib/widgets/quick_tiles_sheet.dart
@@ -0,0 +1,150 @@
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:phosphoricons_flutter/phosphoricons_flutter.dart';
+
+import '../l10n/l10n.dart';
+import '../services/quick_tiles.dart';
+import '../state/fit_state.dart';
+import '../theme/app_colors.dart';
+import '../theme/app_theme.dart';
+import 'glass.dart';
+import 'ui_kit.dart';
+
+void showQuickTilesSheet(BuildContext context) {
+ showAppSheet<void>(
+ context: context,
+ isScrollControlled: true,
+ backgroundColor: Colors.transparent,
+ builder: (_) => const _QuickTilesSheet(),
+ );
+}
+
+class _QuickTilesSheet extends StatefulWidget {
+ const _QuickTilesSheet();
+
+ @override
+ State<_QuickTilesSheet> createState() => _QuickTilesSheetState();
+}
+
+class _QuickTilesSheetState extends State<_QuickTilesSheet> {
+ final Set<String> _added = {};
+
+ Future<void> _add(String tile) async {
+ HapticFeedback.selectionClick();
+ final r = await QuickTiles.add(tile);
+ if (!mounted) return;
+ if (r == 'added' || r == 'already') setState(() => _added.add(tile));
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ final pass = fit.quickPass;
+ return Container(
+ padding: sheetPad(context),
+ constraints: BoxConstraints(maxHeight: MediaQuery.sizeOf(context).height * 0.92),
+ decoration: sheetDecoration(gc),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ const SheetHandle(),
+ const SizedBox(height: 16),
+ Flexible(
+ child: SingleChildScrollView(
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ SheetTitle(t.qsTitle, subtitle: t.qsSubtitle),
+ const SizedBox(height: 18),
+ _Tile(
+ icon: PhosphorIconsRegular.barbell,
+ title: t.qsToday,
+ body: t.qsTodayHint,
+ added: _added.contains('today'),
+ onAdd: QuickTiles.canAdd ? () => _add('today') : null,
+ ),
+ const SizedBox(height: 10),
+ _Tile(
+ icon: PhosphorIconsRegular.identificationCard,
+ title: pass?.name ?? t.qsPass,
+ body: pass == null ? t.qsPassNone : t.qsPassHint(pass.name),
+ added: _added.contains('pass'),
+ onAdd: QuickTiles.canAdd && pass != null ? () => _add('pass') : null,
+ ),
+ if (!QuickTiles.canAdd) ...[
+ const SizedBox(height: 14),
+ Text(t.qsManual,
+ textAlign: TextAlign.center,
+ style: AppTheme.f(12, weight: FontWeight.w500, color: gc.textTertiary, height: 1.4)),
+ ],
+ ],
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+class _Tile extends StatelessWidget {
+ const _Tile({required this.icon, required this.title, required this.body, required this.added, this.onAdd});
+
+ final IconData icon;
+ final String title;
+ final String body;
+ final bool added;
+ final VoidCallback? onAdd;
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ return Container(
+ padding: const EdgeInsets.fromLTRB(14, 14, 12, 14),
+ decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(20)),
+ child: Row(children: [
+ Container(
+ width: 44,
+ height: 44,
+ alignment: Alignment.center,
+ decoration: BoxDecoration(color: gc.bgRaised, shape: BoxShape.circle),
+ child: Icon(icon, size: 21, color: gc.text),
+ ),
+ const SizedBox(width: 14),
+ Expanded(
+ child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ Text(title,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.f(14.5, weight: FontWeight.w600, color: gc.text)),
+ const SizedBox(height: 3),
+ Text(body, style: AppTheme.f(12, weight: FontWeight.w500, color: gc.textSecondary, height: 1.35)),
+ ]),
+ ),
+ if (onAdd != null || added) ...[
+ const SizedBox(width: 10),
+ AnimatedSwitcher(
+ duration: const Duration(milliseconds: 220),
+ child: added
+ ? Row(key: const ValueKey('done'), mainAxisSize: MainAxisSize.min, children: [
+ Icon(PhosphorIconsBold.check, size: 14, color: gc.sage),
+ const SizedBox(width: 4),
+ Text(t.qsAdded, style: AppTheme.f(12.5, weight: FontWeight.w700, color: gc.sage)),
+ ])
+ : Pressable(
+ key: const ValueKey('add'),
+ onTap: onAdd,
+ child: Container(
+ padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
+ decoration: BoxDecoration(color: gc.ember, borderRadius: BorderRadius.circular(100)),
+ child: Text(t.qsAdd, style: AppTheme.f(12.5, weight: FontWeight.w700, color: gc.onEmber)),
+ ),
+ ),
+ ),
+ ],
+ ]),
+ );
+ }
+}
diff --git a/test/gym_pass_test.dart b/test/gym_pass_test.dart
index a5f5d4c..d6f652c 100644
--- a/test/gym_pass_test.dart
+++ b/test/gym_pass_test.dart
@@ -137,4 +137,20 @@ void main() {
expect((turned.width, turned.height), (200, 400));
expect(await cropToPng(image, const Rect.fromLTRB(0.5, 0.5, 0.5, 0.5)), isNull);
});
+ test('the Quick Settings tile opens the chosen pass and remembers it (#403)', () async {
+ SharedPreferences.setMockInitialValues({});
+ await Store.instance.init();
+ fit.resetAllData();
+ expect(fit.quickPass, isNull);
+ final gym = fit.addGymPass(name: 'Gym', code: '123');
+ final pool = fit.addGymPass(name: 'Pool', code: '456');
+ expect(fit.quickPass!.id, gym);
+ fit.setQuickPass(pool);
+ expect(fit.quickPass!.id, pool);
+ fit.persistNow();
+ fit.loadFromStore();
+ expect(fit.quickPass!.id, pool);
+ fit.removeGymPass(pool);
+ expect(fit.quickPass!.id, gym);
+ });
}