-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: todo notifications that now work for real
# Upcoming Implement a way to ensure that todos will happen at 8AM on a daily basis
- Loading branch information
Showing
6 changed files
with
77 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export 'todo_model.dart'; | ||
export 'todo_model_helper.dart'; | ||
export 'services/todo_background_service.dart'; |
33 changes: 33 additions & 0 deletions
33
lib/tools/todo/models/services/todo_background_service.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'package:academia/exports/barrel.dart'; | ||
import 'package:academia/notifier/local_notification_channel.dart'; | ||
import 'package:academia/notifier/local_notification_status_manager.dart'; | ||
import 'package:academia/notifier/local_notifier_service.dart'; | ||
|
||
class TodoBackgroundService { | ||
static final TodoBackgroundService _instance = | ||
TodoBackgroundService._internal(); | ||
|
||
factory TodoBackgroundService() { | ||
return _instance; | ||
} | ||
|
||
/// Private named constructor that prevents external instantiation. | ||
TodoBackgroundService._internal(); | ||
|
||
void notifyPendingTasks() { | ||
TodoModelHelper().queryAll().then((value) { | ||
value.map((e) { | ||
final todo = Todo.fromJson(e); | ||
|
||
if ((!todo.complete) && todo.notify == true) { | ||
LocalNotifierService().showNotification( | ||
id: LocalNotificationStatusManager().getNextId(), | ||
title: "Todos ${Emojis.smile_skull}", | ||
body: "Todo ${todo.name} requires your attention", | ||
channelKey: LocalNotificationChannelType.reminders.channelKey, | ||
); | ||
} | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,52 @@ | ||
import 'package:academia/exports/barrel.dart'; | ||
import 'package:academia/notifier/local_notification_channel.dart'; | ||
import 'package:academia/notifier/local_notification_status_manager.dart'; | ||
import 'package:academia/notifier/local_notifier_service.dart'; | ||
|
||
// background services | ||
@pragma('vm:entry-point') | ||
void callbackDispatcher() { | ||
Workmanager().executeTask((task, inputData) { | ||
switch (task) { | ||
case BackgroundConfig.refresh: | ||
debugPrint("hey"); | ||
case BackgroundConfig.todosIDentifier: | ||
TodoBackgroundService().notifyPendingTasks(); | ||
break; | ||
default: | ||
} | ||
// notificationsController.createInstantNotification( | ||
// "Hello there", | ||
// "Hello again son", | ||
// ); | ||
// notificationsController.scheduleNotification( | ||
// DateTime.now().add(Duration(minutes: 1)), | ||
// "Test", | ||
// "This is a mF big text notification", | ||
// notificationLayout: NotificationLayout.BigText, | ||
// ); | ||
LocalNotifierService().showNotification( | ||
id: LocalNotificationStatusManager().getNextId(), | ||
title: "Dick", | ||
body: "How are you doing pussy", | ||
channelKey: LocalNotificationChannelType.general.channelKey, | ||
); | ||
return Future.value(true); | ||
}); | ||
} | ||
|
||
class BackgroundWorker { | ||
static final BackgroundWorker _instance = BackgroundWorker._internal(); | ||
|
||
factory BackgroundWorker() { | ||
return _instance; | ||
} | ||
|
||
/// Private named constructor that prevents external instantiation. | ||
BackgroundWorker._internal(); | ||
|
||
Future<void> initialize() async { | ||
if (Platform.isAndroid || Platform.isIOS) { | ||
await Workmanager().initialize( | ||
callbackDispatcher, | ||
isInDebugMode: true, | ||
); | ||
|
||
/// Todos task that is suppossed to run after every 24 hours at 8 am | ||
Workmanager().registerPeriodicTask( | ||
BackgroundConfig.todosIDentifier, | ||
BackgroundConfig.todosIDentifier, | ||
initialDelay: const Duration(seconds: 10), | ||
frequency: const Duration(minutes: 15), | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters