Some Improvements

This commit is contained in:
brausjonas
2024-09-17 20:53:56 +02:00
parent 46063af653
commit 54eb6814da
6 changed files with 74 additions and 19 deletions
+30 -9
View File
@@ -11,9 +11,24 @@ import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'dart:math';
String formatMinutes(int minutes) {
int hours = minutes ~/ 60;
int remainingMinutes = minutes % 60;
String hoursString = "";
String minutesString = "";
if (hours > 0) {
hoursString = "$hours h";
}
minutesString = "$remainingMinutes min";
return "$hoursString $minutesString";
}
@pragma('vm:entry-point')
void callbackDispatcher() async {
Map content = await FileHandler.fileContent;
int id = 15;
for (String key in content.keys) {
@@ -23,16 +38,24 @@ void callbackDispatcher() async {
DateTime dueTime = DateTime.parse(current["dueTime"]);
bool checked = current["checked"];
DateTime currentTime = DateTime.now();
int timeDiff = dueTime
.difference(currentTime)
.inMinutes;
if (timeDiff <= 45 && timeDiff >= 0 && !checked) {
bool notifiedDay = current["notifiedDay"];
bool notifiedHour = current["notifiedHour"];
int timeDiff = dueTime.difference(currentTime).inMinutes;
if ((timeDiff <= 90 && !notifiedHour ||
timeDiff > 23*60 && timeDiff <= 25 * 60 && !notifiedDay) &&
timeDiff >= 0 &&
!checked) {
String notifyType = timeDiff <= 90 ? "notifiedHour" : "notifiedDay";
await FileHandler.saveNotified(key, title, notifyType, true);
AwesomeNotifications().createNotification(
content: NotificationContent(
id: id,
channelKey: "reminder_channel",
title: "Task due!",
body: "Task $title due in $timeDiff minutes!"));
body:
"Task $title due in ${formatMinutes(timeDiff)} !"));
}
id++;
}
@@ -55,9 +78,7 @@ Future<void> initService() async {
onStart: onStart,
isForegroundMode: false,
autoStart: true,
autoStartOnBoot: true
)
);
autoStartOnBoot: true));
service.startService();
}