-
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: courses background task to notify users upcoming classes daily
- Loading branch information
Showing
7 changed files
with
159 additions
and
13 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
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 +1,2 @@ | ||
export 'courses_page.dart'; | ||
export 'service/courses_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,37 @@ | ||
import 'package:academia/exports/barrel.dart'; | ||
import 'package:academia/models/core/course/course.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 CoursesBackgroundService { | ||
static final CoursesBackgroundService _instance = | ||
CoursesBackgroundService._internal(); | ||
|
||
factory CoursesBackgroundService() { | ||
return _instance; | ||
} | ||
|
||
/// Private named constructor that prevents external instantiation. | ||
CoursesBackgroundService._internal(); | ||
|
||
void notifyTodaysCourses() { | ||
CourseModelHelper().queryAll().then((value) { | ||
int coursestoday = 0; | ||
value.map((e) { | ||
final course = Course.fromJson(e); | ||
if (course.dayOfWeek == DateTime.now().weekdayToString()) { | ||
coursestoday++; | ||
} | ||
}); | ||
|
||
LocalNotifierService().showNotification( | ||
id: LocalNotificationStatusManager().getNextId(), | ||
title: "Class! Class! Class! ${Emojis.building_school}", | ||
body: | ||
"Hey, you have $coursestoday classes today ${Emojis.smile_face_screaming_in_fear}", | ||
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
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