Skip to content

Commit

Permalink
Allow multi deleting of plans - 1.0.70 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonp2412 committed May 1, 2024
1 parent e21a8fb commit 1063c7f
Show file tree
Hide file tree
Showing 23 changed files with 242 additions and 153 deletions.
6 changes: 6 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/77.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- Allow multi deleting of plans
- Rename "Enter weight" as "Weight" on graphs page
- Add edit button to graphs page dropdown
- Focus distance after submitting duration
- Fix crashes with inconsistent cardio types
- Remove history suffix from graph_history
Binary file modified fastlane/metadata/android/en-US/images/phoneScreenshots/1_en-US.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/graph_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GraphTile extends StatelessWidget {
final DateTime created;
final String unit;
final Set<String> selected;
final Function onSelect;
final Function(String) onSelect;

const GraphTile(
{super.key,
Expand Down
86 changes: 20 additions & 66 deletions lib/plan_tile.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'package:flexify/database.dart';
import 'package:flexify/edit_plan_page.dart';
import 'package:flexify/main.dart';
import 'package:flexify/settings_state.dart';
import 'package:flexify/start_plan_page.dart';
import 'package:flutter/material.dart';
Expand All @@ -14,33 +12,43 @@ class PlanTile extends StatelessWidget {
required this.index,
required this.navigatorKey,
required this.refresh,
required this.onSelect,
required this.selected,
});

final Plan plan;
final String weekday;
final int index;
final GlobalKey<NavigatorState> navigatorKey;
final Future<void> Function() refresh;
final Function(int) onSelect;
final Set<int> selected;

List<InlineSpan> getChildren(BuildContext context) {
List<InlineSpan> result = [];

var color = Theme.of(context).textTheme.bodyLarge!.color;
if (selected.contains(plan.id))
color = Theme.of(context).colorScheme.primary;

final split = plan.days.split(',');
for (int index = 0; index < split.length; index++) {
final day = split[index];
result.add(
TextSpan(
text: day.trim(),
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
fontWeight: weekday == day.trim() ? FontWeight.bold : null,
decoration:
weekday == day.trim() ? TextDecoration.underline : null,
),
fontWeight: weekday == day.trim() ? FontWeight.bold : null,
decoration:
weekday == day.trim() ? TextDecoration.underline : null,
color: color),
),
);
if (index < split.length - 1)
result.add(
TextSpan(text: ", ", style: Theme.of(context).textTheme.bodyLarge));
result.add(TextSpan(
text: ", ",
style: Theme.of(context).textTheme.bodyLarge,
));
}
return result;
}
Expand All @@ -62,7 +70,10 @@ class PlanTile extends StatelessWidget {
child: ReorderableDragStartListener(
index: index, child: const Icon(Icons.drag_handle)),
),
selected: selected.contains(plan.id),
onTap: () async {
if (selected.isNotEmpty) return onSelect(plan.id);

await navigatorKey.currentState!.push(
MaterialPageRoute(
builder: (context) => StartPlanPage(
Expand All @@ -74,64 +85,7 @@ class PlanTile extends StatelessWidget {
refresh();
},
onLongPress: () {
showModalBottomSheet(
context: context,
builder: (context) {
return Wrap(
children: <Widget>[
ListTile(
leading: const Icon(Icons.edit),
title: const Text('Edit'),
onTap: () async {
Navigator.pop(context);
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => EditPlanPage(
plan: plan.toCompanion(false),
),
),
);
await refresh();
},
),
ListTile(
leading: const Icon(Icons.delete),
title: const Text('Delete'),
onTap: () {
Navigator.pop(context);
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Confirm Delete'),
content: const Text(
'Are you sure you want to delete this plan?'),
actions: <Widget>[
TextButton(
child: const Text('Cancel'),
onPressed: () {
Navigator.pop(context);
},
),
TextButton(
child: const Text('Delete'),
onPressed: () async {
Navigator.pop(context);
await db.delete(db.plans).delete(plan);
await refresh();
},
),
],
);
},
);
},
),
],
);
},
);
onSelect(plan.id);
},
);
}
Expand Down
73 changes: 73 additions & 0 deletions lib/plans_list.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import 'dart:async';
import 'package:drift/drift.dart' as drift;
import 'package:flexify/constants.dart';
import 'package:flexify/database.dart';
import 'package:flexify/main.dart';
import 'package:flexify/plan_tile.dart';
import 'package:flutter/material.dart';

class PlansList extends StatelessWidget {
final String searchText;
final List<Plan> plans;
final Future<void> Function({List<Plan>? plans}) updatePlans;
final GlobalKey<NavigatorState> navigatorKey;
final Set<int> selected;
final Function(int) onSelect;

const PlansList({
super.key,
required this.plans,
required this.searchText,
required this.updatePlans,
required this.navigatorKey,
required this.selected,
required this.onSelect,
});

@override
Widget build(BuildContext context) {
final weekday = weekdays[DateTime.now().weekday - 1];

if (plans.isEmpty)
return const ListTile(
title: Text("No plans yet."),
subtitle: Text("Tap the plus button in the bottom right to add plans."),
);

return ReorderableListView.builder(
itemCount: plans.length,
itemBuilder: (context, index) {
final plan = plans[index];
return PlanTile(
key: Key(plan.id.toString()),
plan: plan,
weekday: weekday,
index: index,
navigatorKey: navigatorKey,
refresh: updatePlans,
selected: selected,
onSelect: (id) => onSelect(id),
);
},
onReorder: (int oldIndex, int newIndex) async {
if (oldIndex < newIndex) {
newIndex--;
}

final temp = plans[oldIndex];
plans.removeAt(oldIndex);
plans.insert(newIndex, temp);

await updatePlans(plans: plans);
await db.transaction(() async {
for (int i = 0; i < plans.length; i++) {
final plan = plans[i];
final updatedPlan =
plan.toCompanion(false).copyWith(sequence: drift.Value(i));
await db.update(db.plans).replace(updatedPlan);
}
});
},
);
}
}
Loading

0 comments on commit 1063c7f

Please sign in to comment.