From 696b9879576dfadb3f3a43988b0d8921198bd010 Mon Sep 17 00:00:00 2001 From: broodjeaap89 Date: Sun, 29 Aug 2021 13:12:00 +0200 Subject: [PATCH] recipe step now stores the dateTime when the step is to be completed, and a bool if it's completed --- lib/entities/PizzaEvent.dart | 1 + lib/entities/PizzaRecipe/RecipeStep.dart | 31 ++++++++++++---------- lib/entities/PizzaRecipe/RecipeStep.g.dart | 16 ++++++++--- lib/pages/PizzaEventNotificationPage.dart | 8 ++++-- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/lib/entities/PizzaEvent.dart b/lib/entities/PizzaEvent.dart index 197592c..9d75484 100644 --- a/lib/entities/PizzaEvent.dart +++ b/lib/entities/PizzaEvent.dart @@ -68,6 +68,7 @@ class PizzaEvent extends HiveObject{ UILocalNotificationDateInterpretation.absoluteTime ); recipeStep.notificationId = notificationId; + recipeStep.dateTime = stepTime; stepTime = stepTime.add(Duration(seconds: recipeStep.getCurrentWaitInSeconds())); stepId++; } diff --git a/lib/entities/PizzaRecipe/RecipeStep.dart b/lib/entities/PizzaRecipe/RecipeStep.dart index 7915693..b0af2bb 100644 --- a/lib/entities/PizzaRecipe/RecipeStep.dart +++ b/lib/entities/PizzaRecipe/RecipeStep.dart @@ -32,29 +32,32 @@ class RecipeStep extends HiveObject { @HiveField(7) List subSteps; - @HiveField(8) - DateTime? completedOn; - bool get completed => _completed(); - + @HiveField(8) + late DateTime dateTime; + @HiveField(9) + late bool _completed; + + bool get completed => _checkCompleted(); + + @HiveField(10) int notificationId = -1; - RecipeStep(this.name, this.description, this.waitDescription, this.waitUnit, this.waitMin, this.waitMax, this.subSteps) { + RecipeStep(this.name, this.description, this.waitDescription, this.waitUnit, this.waitMin, this.waitMax, this.subSteps, {DateTime? dateTime, bool completed=false}) { waitValue = waitMin; + this.dateTime = dateTime ?? DateTime.now(); + this._completed = completed; } - bool _completed(){ + bool _checkCompleted(){ return subSteps.length > 0 ? subSteps.every((subStep) => subStep.completed) : - completedOn != null; + this._completed; } - - void completeStepNow(){ - if (subSteps.isNotEmpty){ - subSteps.forEach((subStep) { subStep.completeNow(); }); - } else { - completedOn = DateTime.now(); - } + + void completeStepNow() { + this.subSteps.forEach((subStep) { subStep.completeNow();}); + this._completed = true; } int convertToSeconds(int value){ diff --git a/lib/entities/PizzaRecipe/RecipeStep.g.dart b/lib/entities/PizzaRecipe/RecipeStep.g.dart index 4d125d6..f3f4b5a 100644 --- a/lib/entities/PizzaRecipe/RecipeStep.g.dart +++ b/lib/entities/PizzaRecipe/RecipeStep.g.dart @@ -24,13 +24,17 @@ class RecipeStepAdapter extends TypeAdapter { fields[3] as int, fields[4] as int, (fields[7] as List).cast(), - )..waitValue = fields[5] as int?; + dateTime: fields[8] as DateTime?, + ) + ..waitValue = fields[5] as int? + .._completed = fields[9] as bool + ..notificationId = fields[10] as int; } @override void write(BinaryWriter writer, RecipeStep obj) { writer - ..writeByte(8) + ..writeByte(11) ..writeByte(0) ..write(obj.name) ..writeByte(1) @@ -46,7 +50,13 @@ class RecipeStepAdapter extends TypeAdapter { ..writeByte(6) ..write(obj.description) ..writeByte(7) - ..write(obj.subSteps); + ..write(obj.subSteps) + ..writeByte(8) + ..write(obj.dateTime) + ..writeByte(9) + ..write(obj._completed) + ..writeByte(10) + ..write(obj.notificationId); } @override diff --git a/lib/pages/PizzaEventNotificationPage.dart b/lib/pages/PizzaEventNotificationPage.dart index bad05f3..11f15f1 100644 --- a/lib/pages/PizzaEventNotificationPage.dart +++ b/lib/pages/PizzaEventNotificationPage.dart @@ -99,18 +99,22 @@ class PizzaEventNotificationState extends State { fullScreenIntent: true, ); const platformChannelSpecific = NotificationDetails(android: androidPlatformChannelSpecifics); - + + var newTime = DateTime.now().add(const Duration(minutes: 15)); + await flutterLocalNotificationsPlugin.zonedSchedule( recipeStep.notificationId, recipeStep.name, null, - tz.TZDateTime.from(DateTime.now().add(const Duration(minutes: 15)), tz.local), + tz.TZDateTime.from(newTime, tz.local), platformChannelSpecific, androidAllowWhileIdle: true, payload: this.widget.payload, uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime ); + recipeStep.dateTime = newTime; + pizzaEvent.save(); Navigator.pop(context); }, )