Skip to content

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

Plan several routines a day and create an exercise from a search

InlitXdbc9f8e27919
diff --git a/lib/screens/routine_edit_screen.dart b/lib/screens/routine_edit_screen.dart
index e19ebcf..313bad5 100644
--- a/lib/screens/routine_edit_screen.dart
+++ b/lib/screens/routine_edit_screen.dart
@@ -11,6 +11,7 @@ import '../theme/app_colors.dart';
import '../theme/app_theme.dart';
import '../widgets/dialogs.dart';
import '../widgets/exercise_media.dart';
+import '../widgets/exercise_preview.dart';
import '../widgets/ruler_picker.dart';
import '../widgets/glass.dart';
import '../widgets/routine_folder.dart';
@@ -50,6 +51,28 @@ class _RoutineEditScreenState extends State<RoutineEditScreen> {
setState(() => _q = '');
}
+ void _createExercise() => showCreateExerciseSheet(
+ context,
+ initialName: _q,
+ onCreated: (id) {
+ fit.toggleRoutineExercise(_id, id);
+ _clearSearch();
+ },
+ );
+
+ Widget _createLink(GymColors gc) => Center(
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: _createExercise,
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
+ child: Text(t.createNamed(_q.trim()),
+ textAlign: TextAlign.center,
+ style: AppTheme.f(13, weight: FontWeight.w600, color: gc.accent)),
+ ),
+ ),
+ );
+
@override
Widget build(BuildContext context) {
final gc = context.gc;
@@ -59,6 +82,7 @@ class _RoutineEditScreenState extends State<RoutineEditScreen> {
}
final list = _filtered;
final start = routine.exerciseIds.isNotEmpty;
+ final create = _q.trim().isNotEmpty && list.isNotEmpty;
return SafeArea(
bottom: false,
child: Stack(
@@ -66,10 +90,11 @@ class _RoutineEditScreenState extends State<RoutineEditScreen> {
Positioned.fill(
child: ListView.builder(
padding: EdgeInsets.fromLTRB(20, 12, 20, start ? 104 : 20),
- itemCount: (list.isEmpty ? 1 : list.length) + 1,
+ itemCount: (list.isEmpty ? 1 : list.length) + (create ? 2 : 1),
itemBuilder: (context, i) {
if (i == 0) return _header(gc, routine.exerciseIds.length);
if (list.isEmpty) return _noMatches(gc);
+ if (i > list.length) return _createLink(gc);
return _pickRow(gc, list[i - 1]);
},
),
@@ -297,11 +322,14 @@ class _RoutineEditScreenState extends State<RoutineEditScreen> {
(fit.exDifficultyFilter == null ? 0 : 1);
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
+ clipBehavior: Clip.none,
child: Row(children: [
chip(picked > 0 ? '${t.filters} · $picked' : t.filters, picked > 0,
() => showExerciseFilters(context, onClear: _clearSearch)),
chip(t.favouritesOnly, fit.exFavouritesOnly, fit.toggleFavouritesFilter),
chip(t.noGearOnly, fit.exNoGearOnly, fit.toggleNoGearFilter),
+ if (fit.customExercises.isNotEmpty || fit.exMineOnly)
+ chip(t.mineOnly, fit.exMineOnly, fit.toggleMineFilter),
for (final id in kFilterMuscles)
chip(muscleLabel(id), fit.exMuscleFilter == id, () => fit.setMuscleFilter(id)),
]),
@@ -332,10 +360,7 @@ class _RoutineEditScreenState extends State<RoutineEditScreen> {
label: t.newExercise,
bg: gc.bgRaised2,
fg: gc.textSecondary,
- onTap: () => showCreateExerciseSheet(
- context,
- onCreated: (id) => fit.toggleRoutineExercise(_id, id),
- ),
+ onTap: _createExercise,
),
],
),
@@ -345,10 +370,10 @@ class _RoutineEditScreenState extends State<RoutineEditScreen> {
}
Widget _dayToggle(GymColors gc, int i) {
- final weekday = i + 1;
- final on = fit.weeklyPlan[weekday] == _id;
+ final weekday = fit.weekdayAt(i);
+ final on = fit.plannedOn(weekday, _id);
return GestureDetector(
- onTap: () => fit.assignRoutineToDay(weekday, on ? null : _id),
+ onTap: () => fit.togglePlanDay(weekday, _id),
child: Container(
width: 38,
height: 38,
@@ -357,7 +382,7 @@ class _RoutineEditScreenState extends State<RoutineEditScreen> {
shape: BoxShape.circle,
),
alignment: Alignment.center,
- child: Text(t.weekdayInitial(i + 1),
+ child: Text(t.weekdayInitial(weekday),
style: AppTheme.f(14, weight: FontWeight.w700, color: on ? gc.onEmber : gc.textSecondary)),
),
);
@@ -637,6 +662,7 @@ class _RoutineEditScreenState extends State<RoutineEditScreen> {
final inRoutine = fit.routineHas(_id, ex.id);
return GestureDetector(
onTap: () => fit.toggleRoutineExercise(_id, ex.id),
+ onLongPress: () => showExercisePreview(context, ex),
behavior: HitTestBehavior.opaque,
child: Container(
margin: const EdgeInsets.only(bottom: 8),
@@ -647,7 +673,10 @@ class _RoutineEditScreenState extends State<RoutineEditScreen> {
borderRadius: BorderRadius.circular(14),
),
child: Row(children: [
- SizedBox(width: 44, child: ExerciseMedia(ex: ex, height: 44, radius: 10)),
+ GestureDetector(
+ onTap: () => showExercisePreview(context, ex),
+ child: SizedBox(width: 44, child: ExerciseMedia(ex: ex, height: 44, radius: 10)),
+ ),
const SizedBox(width: 12),
Expanded(
child: Column(
diff --git a/lib/screens/routines_screen.dart b/lib/screens/routines_screen.dart
index 8c9eccd..8b254d5 100644
--- a/lib/screens/routines_screen.dart
+++ b/lib/screens/routines_screen.dart
@@ -112,7 +112,7 @@ class RoutinesScreen extends StatelessWidget {
void _shareMenu(BuildContext context) {
final gc = context.gc;
- final planned = fit.routines.where((r) => fit.weeklyPlan.containsValue(r.id)).toList();
+ final planned = fit.routines.where((r) => [for (var d = 1; d <= 7; d++) ...fit.planIdsOn(d)].contains(r.id)).toList();
showAppSheet<void>(
context: context,
backgroundColor: Colors.transparent,
@@ -283,9 +283,9 @@ class RoutinesScreen extends StatelessWidget {
}
Widget _dayRow(BuildContext context, GymColors gc, int i) {
- final weekday = i + 1;
- final r = fit.routines.where((x) => x.id == fit.weeklyPlan[weekday]);
- final assigned = r.isNotEmpty ? r.first : null;
+ final weekday = fit.weekdayAt(i);
+ final day = fit.dateForWeekday(i);
+ final assigned = fit.routinesOn(day);
final isToday = DateTime.now().weekday == weekday;
return GestureDetector(
onTap: () => _pickRoutine(context, weekday),
@@ -300,11 +300,11 @@ class RoutinesScreen extends StatelessWidget {
style: AppTheme.f(14, weight: FontWeight.w600, color: isToday ? gc.ember : gc.text)),
const SizedBox(width: 14),
Expanded(
- child: Text(assigned == null ? t.restDayShort : fit.routineTitle(assigned),
+ child: Text(assigned.isEmpty ? t.restDayShort : assigned.map(fit.routineTitle).join(' + '),
textAlign: TextAlign.right,
maxLines: 1,
overflow: TextOverflow.ellipsis,
- style: AppTheme.f(14, weight: FontWeight.w500, color: assigned != null ? gc.text : gc.textTertiary)),
+ style: AppTheme.f(14, weight: FontWeight.w500, color: assigned.isNotEmpty ? gc.text : gc.textTertiary)),
),
const SizedBox(width: 8),
SvgPathIcon(Ic.chevronRight, size: 14, color: gc.textTertiary),
@@ -416,7 +416,9 @@ class RoutinesScreen extends StatelessWidget {
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
- builder: (sheet) => Container(
+ builder: (sheet) => AnimatedBuilder(
+ animation: fit,
+ builder: (sheet, _) => Container(
constraints: BoxConstraints(maxHeight: MediaQuery.sizeOf(sheet).height * 0.72),
padding: sheetPad(sheet),
decoration: BoxDecoration(
@@ -430,6 +432,10 @@ class RoutinesScreen extends StatelessWidget {
const SheetHandle(),
const SizedBox(height: 16),
SheetTitle(titleCase(t.setDay(t.weekday(weekday).toUpperCase()))),
+ if (fit.multiPlan) ...[
+ const SizedBox(height: 4),
+ Text(t.multiPlanHint, style: AppTheme.f(12.5, weight: FontWeight.w500, color: gc.textSecondary)),
+ ],
const SizedBox(height: 14),
Flexible(
child: OptionGroup(
@@ -438,7 +444,7 @@ class RoutinesScreen extends StatelessWidget {
OptionItem(
t.restDayShort,
icon: PhosphorIconsRegular.moonStars,
- selected: fit.weeklyPlan[weekday] == null,
+ selected: fit.planIdsOn(weekday).isEmpty,
onTap: () {
fit.assignRoutineToDay(weekday, null);
Navigator.pop(sheet);
@@ -448,8 +454,9 @@ class RoutinesScreen extends StatelessWidget {
OptionItem(
fit.routineTitle(r),
detail: r.group.isEmpty ? null : r.group,
- selected: fit.weeklyPlan[weekday] == r.id,
+ selected: fit.plannedOn(weekday, r.id),
onTap: () {
+ if (fit.multiPlan) return fit.togglePlanDay(weekday, r.id);
fit.assignRoutineToDay(weekday, r.id);
Navigator.pop(sheet);
},
@@ -460,6 +467,7 @@ class RoutinesScreen extends StatelessWidget {
],
),
),
+ ),
);
}
}
diff --git a/lib/state/routines_state.dart b/lib/state/routines_state.dart
index 546952e..8aa2e06 100644
--- a/lib/state/routines_state.dart
+++ b/lib/state/routines_state.dart
@@ -34,9 +34,52 @@ mixin RoutinesState on FitCore, LibraryState {
Routine? get todayRoutine => routineOn(DateTime.now());
+ List<String> planIdsOn(int weekday) => [
+ ?weeklyPlan[weekday],
+ if (multiPlan) ...?planExtras[weekday],
+ ];
+
+ List<Routine> routinesOn(DateTime day) => [for (final id in planIdsOn(day.weekday)) ?_routine(id)];
+
+ bool plannedOn(int weekday, String routineId) => planIdsOn(weekday).contains(routineId);
+
Routine? routineOn(DateTime day) {
- final id = weeklyPlan[day.weekday];
- return id == null ? null : _routine(id);
+ final list = routinesOn(day);
+ if (list.isEmpty) return null;
+ final key = _dayKey(day);
+ final done = sessions.where((s) => _dayKey(s.date) == key).length;
+ return list[math.min(done, list.length - 1)];
+ }
+
+ void toggleMultiPlan() {
+ multiPlan = !multiPlan;
+ _persist();
+ _refreshWidgets();
+ syncTrainReminder();
+ notifyListeners();
+ }
+
+ void togglePlanDay(int weekday, String routineId) {
+ if (!multiPlan) return assignRoutineToDay(weekday, plannedOn(weekday, routineId) ? null : routineId);
+ final extras = planExtras.putIfAbsent(weekday, () => []);
+ if (weeklyPlan[weekday] == routineId) {
+ if (extras.isEmpty) {
+ weeklyPlan.remove(weekday);
+ } else {
+ weeklyPlan[weekday] = extras.removeAt(0);
+ }
+ } else if (!extras.remove(routineId)) {
+ if (weeklyPlan[weekday] == null) {
+ weeklyPlan[weekday] = routineId;
+ } else {
+ extras.add(routineId);
+ }
+ }
+ if (extras.isEmpty) planExtras.remove(weekday);
+ _persist();
+ _refreshWidgets();
+ syncTrainReminder();
+ notifyListeners();
}
String createRoutine([String name = '']) {
@@ -102,6 +145,16 @@ mixin RoutinesState on FitCore, LibraryState {
void deleteRoutine(String id) {
routines.removeWhere((r) => r.id == id);
weeklyPlan.removeWhere((_, v) => v == id);
+ for (final extras in planExtras.values) {
+ extras.remove(id);
+ }
+ planExtras.removeWhere((_, v) => v.isEmpty);
+ for (final day in [...planExtras.keys]) {
+ if (weeklyPlan[day] != null) continue;
+ final extras = planExtras[day]!;
+ weeklyPlan[day] = extras.removeAt(0);
+ if (extras.isEmpty) planExtras.remove(day);
+ }
if (activeRoutineId == id) activeRoutineId = null;
_persist();
notifyListeners();
@@ -228,6 +281,7 @@ mixin RoutinesState on FitCore, LibraryState {
}
void assignRoutineToDay(int weekday, String? routineId) {
+ planExtras.remove(weekday);
if (routineId == null) {
weeklyPlan.remove(weekday);
} else {