Offline gym log for Android. No account, no ads, no internet.
Dart androidbodybuildingdartexercisesf-droidfitnessfluttergymgym-apphealthprivacyself-hostedworkoutworkout-appworkout-tracker
Add common questions to the settings search
InlitXe398220c1d12
diff --git a/lib/screens/help_topics.dart b/lib/screens/help_topics.dartnew file mode 100644index 0000000..c5747ce--- /dev/null+++ b/lib/screens/help_topics.dart@@ -0,0 +1,74 @@+import 'dart:io' show Platform;++import 'package:flutter/foundation.dart' show kIsWeb;++import '../l10n/l10n.dart';+import '../services/nfc_tags.dart';+import '../state/fit_state.dart';+import '../widgets/ui_kit.dart';+import 'settings_screen.dart';++class HelpTopic {+ const HelpTopic(this.id, this.question, this.answer, {this.section, this.row, this.go});++ final String id;+ final String question;+ final String answer;+ final String? section;+ final String? row;+ final void Function()? go;++ bool get leads => section != null || go != null;++ bool matches(String query) {+ final words = helpPlain(query).split(RegExp(r'\s+')).where((w) => w.length > 1).toList();+ if (words.isEmpty) return false;+ final hay = helpPlain('$question $answer');+ return words.every(hay.contains);+ }+}++String helpPlain(String s) => s+ .toLowerCase()+ .replaceAll(RegExp('[áàäâ]'), 'a')+ .replaceAll(RegExp('[éèëê]'), 'e')+ .replaceAll(RegExp('[íìïî]'), 'i')+ .replaceAll(RegExp('[óòöô]'), 'o')+ .replaceAll(RegExp('[úùüû]'), 'u')+ .replaceAll(RegExp('[¿?¡!.,:;«»“”"()]'), ' ');++const kHelpCommon = ['superset', 'range', 'dayOff', 'lb', 'rest', 'import', 'phone', 'homeOrder', 'custom', 'steps', 'slow'];++List<HelpTopic> helpTopics() {+ String s(String id) => SettingsScreen.sectionTitleOf(id);+ return [+ HelpTopic('superset', t.helpSupersetQ, t.helpSupersetA, go: fit.goRoutines),+ HelpTopic('range', t.helpRangeQ, t.helpRangeA, go: fit.goRoutines),+ HelpTopic('dayOff', t.helpDayOffQ, t.helpDayOffA, go: fit.goHome),+ HelpTopic('lb', t.helpLbQ, t.helpLbA(t.exerciseUnitSwitch('lb'))),+ HelpTopic('import', t.helpImportQ, t.helpImportA(s('data'), t.importFromApp), section: 'data', row: t.importFromApp),+ HelpTopic('phone', t.helpPhoneQ, t.helpPhoneA(s('data'), t.importBackup), section: 'data', row: t.exportBackup),+ HelpTopic('slow', t.helpSlowQ, t.helpSlowA(s('general'), t.perfSetting, t.perfLite),+ section: 'general', row: t.perfSetting),+ HelpTopic('rest', t.helpRestQ, t.helpRestA(t.exerciseSettings, titleCase(t.restForExercise), s('training')),+ section: 'training', row: t.restTimer),+ HelpTopic('sides', t.helpSidesQ, t.helpSidesA(t.exerciseSettings, t.eachSide), go: fit.goExercises),+ HelpTopic('pair', t.helpPairQ, t.helpPairA(t.pairSetting), go: fit.goExercises),+ HelpTopic('keep', t.helpKeepQ, t.helpKeepA(t.keepCounting), go: fit.goExercises),+ HelpTopic('race', t.helpRaceQ, t.helpRaceA(t.raceTitle)),+ HelpTopic('plates', t.helpPlatesQ, t.helpPlatesA(t.toolNamePlate, t.placesLabel), go: () => fit.openTool('plate')),+ HelpTopic('homeOrder', t.helpHomeOrderQ, t.helpHomeOrderA(s('home'), t.homeOrderRow), section: 'home'),+ HelpTopic('custom', t.helpCustomQ, t.helpCustomA(titleCase(t.newExercise)), go: fit.goExercises),+ HelpTopic('warmup', t.helpWarmupQ, t.helpWarmupA(t.exerciseSettings, t.autoWarmup, t.toolNameWarmup),+ go: fit.goExercises),+ HelpTopic('pass', t.helpPassQ, t.helpPassA(t.gymPass, s('home')), section: 'home', row: t.gymPass),+ if (!kIsWeb && Platform.isAndroid)+ HelpTopic('steps', t.helpStepsQ, t.helpStepsA(health(t.stepsSetting), s('home')),+ section: 'home', row: health(t.stepsSetting)),+ if (NfcTags.available)+ HelpTopic('nfc', t.helpNfcQ, t.helpNfcA(t.nfcRow, s('training')), section: 'training', row: t.nfcRow),+ if (fit.nutritionBeta)+ HelpTopic('clean', t.helpCleanQ, t.helpCleanA(t.trackersTitle), go: () => fit.pushRoute('nutrition')),+ if (fit.nutritionBeta) HelpTopic('fast', t.helpFastQ, t.helpFastA(t.fastAdjust)),+ ];+}diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dartindex 3069969..cf8b268 100644--- a/lib/screens/settings_screen.dart+++ b/lib/screens/settings_screen.dart@@ -31,6 +31,7 @@ import '../theme/app_colors.dart';import '../theme/app_theme.dart';import '../services/app_icon.dart';import '../services/nfc_tags.dart';+import 'help_topics.dart';import '../widgets/app_icon_sheet.dart';import '../widgets/nfc_sheet.dart';import '../widgets/auto_backup_sheet.dart';@@ -868,6 +869,11 @@ class SettingsScreen extends StatelessWidget {static String sectionTitleOf(String id) => _sectionTitle(id);+ List<(String, String)> get searchRows => [+ for (final c in _categories())+ for (final r in c.rows) (c.id, r.$1),+ ];+List<_Category> _categories() {const r = PhosphorIconsRegular.gearSix;return [@@ -2618,6 +2624,7 @@ class _SettingsHomeState extends State<_SettingsHome> {final _query = TextEditingController();final _focus = FocusNode();final _scroll = ScrollController();+ String? _openHelp;static const _span = 96.0;static const _back = 36.0;static const _pill = 52.0;@@ -2678,6 +2685,10 @@ class _SettingsHomeState extends State<_SettingsHome> {for (final r in c.rows)if (_plain(r.$1).contains(q) || _plain(c.title).contains(q)) (c, r.$1, r.$2),];+ final topics = searching ? helpTopics() : const <HelpTopic>[];+ final asked = q.isEmpty+ ? [for (final id in kHelpCommon) ...topics.where((h) => h.id == id)]+ : topics.where((h) => h.matches(_query.text)).toList();final pad = MediaQuery.paddingOf(context).top;final titleTop = pad + 12 + _back + 18;@@ -2711,7 +2722,7 @@ class _SettingsHomeState extends State<_SettingsHome> {),),child: searching- ? _results(gc, hits, q.isEmpty)+ ? _results(gc, cats, hits, asked, q.isEmpty): Column(key: const ValueKey('cats'),crossAxisAlignment: CrossAxisAlignment.stretch,@@ -2933,17 +2944,138 @@ class _SettingsHomeState extends State<_SettingsHome> {);}- Widget _results(GymColors gc, List<(_Category, String, IconData)> hits, bool empty) {- if (empty) return const SizedBox(key: ValueKey('blank'), height: 200);- if (hits.isEmpty) {+ void _goHelp(List<_Category> cats, HelpTopic h) {+ final section = h.section;+ if (section != null) {+ final c = cats.where((c) => c.id == section).firstOrNull;+ if (c != null) _go(c, h.row);+ return;+ }+ _focus.unfocus();+ h.go?.call();+ }++ Widget _helpLabel(GymColors gc, String text) => Padding(+ padding: const EdgeInsets.fromLTRB(4, 6, 0, 10),+ child: Text(text.toUpperCase(),+ style: AppTheme.f(10.5, weight: FontWeight.w700, color: gc.textTertiary, letterSpacing: 1.4)),+ );++ Widget _helpGroup(GymColors gc, List<_Category> cats, List<HelpTopic> list) => Container(+ decoration: BoxDecoration(color: gc.bgRaised, borderRadius: BorderRadius.circular(22)),+ clipBehavior: Clip.antiAlias,+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ for (var i = 0; i < list.length; i++) _helpRow(gc, cats, list[i], last: i == list.length - 1),+ ],+ ),+ );++ Widget _helpRow(GymColors gc, List<_Category> cats, HelpTopic h, {required bool last}) {+ final open = _openHelp == h.id;+ return DecoratedBox(+ decoration: BoxDecoration(+ border: last ? null : Border(bottom: BorderSide(color: gc.border.withValues(alpha: 0.6))),+ ),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ Semantics(+ button: true,+ expanded: open,+ child: GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: () {+ HapticFeedback.selectionClick();+ setState(() => _openHelp = open ? null : h.id);+ },+ child: Padding(+ padding: const EdgeInsetsDirectional.fromSTEB(16, 15, 14, 15),+ child: Row(+ children: [+ Expanded(+ child: Text(h.question,+ style: AppTheme.f(14.5, weight: FontWeight.w600, color: gc.text, height: 1.3)),+ ),+ const SizedBox(width: 12),+ AnimatedRotation(+ turns: open ? 0.5 : 0,+ duration: const Duration(milliseconds: 220),+ curve: Curves.easeOutCubic,+ child: Icon(PhosphorIconsRegular.caretDown, size: 15, color: gc.textTertiary),+ ),+ ],+ ),+ ),+ ),+ ),+ AnimatedSize(+ duration: const Duration(milliseconds: 240),+ curve: Curves.easeOutCubic,+ alignment: Alignment.topCenter,+ child: !open+ ? const SizedBox(width: double.infinity)+ : Padding(+ padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 6),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(h.answer, style: AppTheme.s(13, color: gc.textSecondary, height: 1.45)),+ if (h.leads)+ Semantics(+ button: true,+ child: GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: () {+ HapticFeedback.selectionClick();+ _goHelp(cats, h);+ },+ child: Padding(+ padding: const EdgeInsets.symmetric(vertical: 12),+ child: Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ Text(t.helpGo, style: AppTheme.f(13, weight: FontWeight.w700, color: gc.accent)),+ const SizedBox(width: 4),+ Icon(PhosphorIconsBold.arrowUpRight, size: 13, color: gc.accent),+ ],+ ),+ ),+ ),+ )+ else+ const SizedBox(height: 10),+ ],+ ),+ ),+ ),+ ],+ ),+ );+ }++ Widget _results(GymColors gc, List<_Category> cats, List<(_Category, String, IconData)> hits,+ List<HelpTopic> asked, bool empty) {+ if (empty) {+ return Column(+ key: const ValueKey('common'),+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ _helpLabel(gc, t.helpCommon),+ _helpGroup(gc, cats, asked),+ ],+ );+ }+ if (hits.isEmpty && asked.isEmpty) {return Padding(key: const ValueKey('none'),padding: const EdgeInsets.fromLTRB(4, 12, 4, 12),- child: Text(t.settingsNoResults, style: AppTheme.f(15, weight: FontWeight.w500, color: gc.textSecondary)),+ child: Text(t.helpNoResults, style: AppTheme.f(15, weight: FontWeight.w500, color: gc.textSecondary)),);}return Column(- key: ValueKey('hits${hits.length}'),+ key: ValueKey('hits${hits.length}-${asked.length}'),crossAxisAlignment: CrossAxisAlignment.stretch,children: [for (var i = 0; i < hits.length; i++) ...[@@ -2976,6 +3108,11 @@ class _SettingsHomeState extends State<_SettingsHome> {),),],+ if (asked.isNotEmpty) ...[+ if (hits.isNotEmpty) const SizedBox(height: 22),+ _helpLabel(gc, t.helpQuestions),+ _helpGroup(gc, cats, asked),+ ],],);}diff --git a/test/settings_test.dart b/test/settings_test.dartindex 761eaf8..ac04a20 100644--- a/test/settings_test.dart+++ b/test/settings_test.dart@@ -1,6 +1,8 @@import 'package:flutter/material.dart';import 'package:flutter_test/flutter_test.dart';-import 'package:gymmane/l10n/app_localizations.dart';+import 'package:gymmane/l10n/l10n.dart';+import 'package:gymmane/screens/help_topics.dart';+import 'package:gymmane/screens/settings_screen.dart';import 'package:gymmane/services/local_store.dart';import 'package:gymmane/services/rest_alarm.dart';import 'package:gymmane/state/fit_state.dart';@@ -168,4 +170,52 @@ void main() {expect(star, greaterThan(coffee), reason: '$locale: la estrella va después del café');}});++ group('guía en el buscador', () {+ setUp(() async {+ SharedPreferences.setMockInitialValues({});+ await Store.instance.init();+ fit.resetAllData();+ fit.onboarded = true;+ fit.nutritionBeta = true;+ });++ for (final lang in ['en', 'es']) {+ test('cada respuesta que lleva a Ajustes apunta a una fila que existe ($lang)', () {+ setAppLanguage(lang);+ final rows = const SettingsScreen().searchRows.toSet();+ final topics = helpTopics();+ expect(topics.map((h) => h.id).toSet().length, topics.length, reason: 'ids repetidos');+ for (final h in topics) {+ if (h.section == null) continue;+ if (h.row == null) {+ expect(rows.any((r) => r.$1 == h.section), isTrue, reason: '${h.id} lleva a ${h.section}');+ continue;+ }+ expect(rows.contains((h.section!, h.row!)), isTrue, reason: '${h.id} lleva a ${h.section} › ${h.row}');+ }+ for (final id in kHelpCommon.where((id) => id != 'steps')) {+ expect(topics.any((h) => h.id == id), isTrue, reason: 'frecuente sin entrada: $id');+ }+ for (final h in topics) {+ expect(h.answer.contains('{'), isFalse, reason: '${h.id} con hueco sin rellenar');+ }+ });+ }++ test('se encuentra preguntando con palabras sueltas, sin tildes ni orden', () {+ setAppLanguage('es');+ final topics = helpTopics();+ List<String> find(String q) => [for (final h in topics) if (h.matches(q)) h.id];+ expect(find('superserie'), contains('superset'));+ expect(find('movil nuevo'), contains('phone'));+ expect(find('lenta'), contains('slow'));+ expect(find('lyfta'), contains('import'));+ expect(find('hevy'), contains('import'));+ expect(find('8-12'), contains('range'));+ expect(find('mancuernas'), contains('pair'));+ expect(find('x'), isEmpty);+ setAppLanguage('en');+ });+ });}