diff --git a/lib/entities/pizza_event.dart b/lib/entities/pizza_event.dart index b92ae15..913aef6 100644 --- a/lib/entities/pizza_event.dart +++ b/lib/entities/pizza_event.dart @@ -79,4 +79,10 @@ class PizzaEvent extends HiveObject{ stepId++; } } + + Future cancelNotifications() async { + for(final recipeStep in recipe.recipeSteps){ + flutterLocalNotificationsPlugin.cancel(recipeStep.notificationId); + } + } } \ No newline at end of file diff --git a/lib/pages/pizza_events_page.dart b/lib/pages/pizza_events_page.dart index 62bf5b6..79fe02c 100644 --- a/lib/pages/pizza_events_page.dart +++ b/lib/pages/pizza_events_page.dart @@ -22,15 +22,88 @@ class PizzaEventsState extends State { title: const Text("Pizza Events"), body: ValueListenableBuilder( valueListenable: Hive.box("PizzaEvents").listenable(), - builder: (context, Box box, widget) { - if (box.isEmpty){ + builder: (context, Box pizzaEventBox, widget) { + if (pizzaEventBox.isEmpty){ return Container(); } return ListView.separated( padding: const EdgeInsets.all(8), - itemCount: box.length, - itemBuilder: (BuildContext context, int i) => PizzaEventWidget(box.getAt(i)!), - separatorBuilder: (BuildContext context, int i) => const Divider(), + itemCount: pizzaEventBox.length, + itemBuilder: (BuildContext context, int i) { + final pizzaEvent = pizzaEventBox.get(i); + if (pizzaEvent == null || pizzaEvent.archived || pizzaEvent.deleted){ + return const SizedBox(); + } + return InkWell( + onTap: () { + Navigator.pushNamed(context, "/event/view", arguments: pizzaEvent); + }, + onLongPress: () { + showDialog(context: context, builder: (BuildContext context) { + return AlertDialog( + title: Text(pizzaEvent.name), + content: const Text("What do you want to do?"), + actions: [ + TextButton( + onPressed: () { + Navigator.pop(context); + Navigator.pushNamed(context, "/event/view", arguments: pizzaEvent); + }, + child: const Text("View"), + ), + TextButton( + onPressed: () { + Navigator.pop(context); + pizzaEvent.archived = true; + pizzaEvent.save(); + }, + child: const Text("Archive"), + ), + TextButton( + onPressed: () { + Navigator.pop(context); + showDialog(context: context, builder: (BuildContext context) { + return AlertDialog( + title: const Text("Delete?"), + content: const Text("Are you sure?"), + actions: [ + TextButton( + onPressed: () { + Navigator.pop(context); + }, + child: const Text("Back"), + ), + TextButton( + onPressed: () async { + if (pizzaEvent.isInBox){ + pizzaEvent.cancelNotifications(); + pizzaEvent.deleted = true; + pizzaEvent.save(); + } + Navigator.pop(context); + }, + child: const Text("Delete", style: TextStyle(color: Colors.redAccent)), + ), + ] + ); + }); + }, + child: const Text("Delete", style: TextStyle(color: Colors.redAccent)), + ), + ] + ); + }); + }, + child: PizzaEventWidget(pizzaEvent), + ); + }, + separatorBuilder: (BuildContext context, int i) { + final pizzaEvent = pizzaEventBox.get(i); + if (pizzaEvent == null || pizzaEvent.archived || pizzaEvent.deleted){ + return const SizedBox(); + } + return const Divider(); + }, ); } ), diff --git a/todo.md b/todo.md index c933eab..28ce9fd 100644 --- a/todo.md +++ b/todo.md @@ -9,8 +9,6 @@ - add settings page - option for type of notification, full screen or just in the appbar - pick alarm sound -- deleting scheduled pizza events -- archiving past pizza events - foto mode for pizza event - push to instagram ?