diff --git a/refilc/lib/helpers/notification_helper.dart b/refilc/lib/helpers/notification_helper.dart index f99ebfe..3916df0 100644 --- a/refilc/lib/helpers/notification_helper.dart +++ b/refilc/lib/helpers/notification_helper.dart @@ -1,25 +1,25 @@ -import 'package:flutter/foundation.dart'; -import 'package:refilc/api/providers/database_provider.dart'; -import 'package:refilc/api/providers/status_provider.dart'; -import 'package:refilc/api/providers/user_provider.dart'; -import 'package:refilc/models/settings.dart'; -import 'package:refilc/helpers/notification_helper.i18n.dart'; -import 'package:refilc/models/user.dart'; -import 'package:refilc/utils/navigation_service.dart'; -import 'package:refilc/utils/service_locator.dart'; -import 'package:refilc_kreta_api/client/api.dart'; -import 'package:refilc_kreta_api/client/client.dart'; -import 'package:refilc_kreta_api/models/absence.dart'; -import 'package:refilc_kreta_api/models/grade.dart'; -import 'package:refilc_kreta_api/models/lesson.dart'; -import 'package:refilc_kreta_api/models/week.dart'; -import 'package:refilc_kreta_api/providers/grade_provider.dart'; -import 'package:refilc_kreta_api/providers/timetable_provider.dart'; -import 'package:flutter_local_notifications/flutter_local_notifications.dart' - hide Message; -import 'package:i18n_extension/i18n_extension.dart'; -import 'package:intl/intl.dart'; -import 'package:refilc_kreta_api/models/message.dart'; +// import 'package:flutter/foundation.dart'; +// import 'package:refilc/api/providers/database_provider.dart'; +// import 'package:refilc/api/providers/status_provider.dart'; +// import 'package:refilc/api/providers/user_provider.dart'; +// import 'package:refilc/models/settings.dart'; +// import 'package:refilc/helpers/notification_helper.i18n.dart'; +// import 'package:refilc/models/user.dart'; +// import 'package:refilc/utils/navigation_service.dart'; +// import 'package:refilc/utils/service_locator.dart'; +// import 'package:refilc_kreta_api/client/api.dart'; +// import 'package:refilc_kreta_api/client/client.dart'; +// import 'package:refilc_kreta_api/models/absence.dart'; +// import 'package:refilc_kreta_api/models/grade.dart'; +// import 'package:refilc_kreta_api/models/lesson.dart'; +// import 'package:refilc_kreta_api/models/week.dart'; +// import 'package:refilc_kreta_api/providers/grade_provider.dart'; +// import 'package:refilc_kreta_api/providers/timetable_provider.dart'; +// import 'package:flutter_local_notifications/flutter_local_notifications.dart' +// hide Message; +// import 'package:i18n_extension/i18n_extension.dart'; +// import 'package:intl/intl.dart'; +// import 'package:refilc_kreta_api/models/message.dart'; // if you want to add a new category, also add it to the DB or else the app will probably crash enum LastSeenCategory { @@ -30,690 +30,690 @@ enum LastSeenCategory { lesson } // didn't know a better place for this -class NotificationsHelper { - late DatabaseProvider database; - late SettingsProvider settingsProvider; - late UserProvider userProvider; - late KretaClient kretaClient; - FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = - FlutterLocalNotificationsPlugin(); +// class NotificationsHelper { +// late DatabaseProvider database; +// late SettingsProvider settingsProvider; +// late UserProvider userProvider; +// late KretaClient kretaClient; +// FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = +// FlutterLocalNotificationsPlugin(); - String dayTitle(DateTime date) { - try { - String dayTitle = - DateFormat("EEEE", I18n.locale.languageCode).format(date); - dayTitle = dayTitle[0].toUpperCase() + - dayTitle.substring(1); // capitalize string - return dayTitle; - } catch (e) { - return "Unknown"; - } - } +// String dayTitle(DateTime date) { +// try { +// String dayTitle = +// DateFormat("EEEE", I18n.locale.languageCode).format(date); +// dayTitle = dayTitle[0].toUpperCase() + +// dayTitle.substring(1); // capitalize string +// return dayTitle; +// } catch (e) { +// return "Unknown"; +// } +// } - @pragma('vm:entry-point') - void backgroundJob() async { - // initialize providers - database = DatabaseProvider(); - await database.init(); - settingsProvider = await database.query.getSettings(database); - userProvider = await database.query.getUsers(settingsProvider); +// @pragma('vm:entry-point') +// void backgroundJob() async { +// // initialize providers +// database = DatabaseProvider(); +// await database.init(); +// settingsProvider = await database.query.getSettings(database); +// userProvider = await database.query.getUsers(settingsProvider); - if (userProvider.id != null && settingsProvider.notificationsEnabled) { - List users = userProvider.getUsers(); +// if (userProvider.id != null && settingsProvider.notificationsEnabled) { +// List users = userProvider.getUsers(); - // Process notifications for each user asynchronously - await Future.forEach(users, (User user) async { - // Create a new instance of userProvider for each user - UserProvider userProviderForUser = - await database.query.getUsers(settingsProvider); - userProviderForUser.setUser(user.id); +// // Process notifications for each user asynchronously +// await Future.forEach(users, (User user) async { +// // Create a new instance of userProvider for each user +// UserProvider userProviderForUser = +// await database.query.getUsers(settingsProvider); +// userProviderForUser.setUser(user.id); - // Refresh kreta login for current user - final status = StatusProvider(); - KretaClient kretaClientForUser = KretaClient( - user: userProviderForUser, - settings: settingsProvider, - database: database, - status: status, - ); - await kretaClientForUser.refreshLogin(); +// // Refresh kreta login for current user +// final status = StatusProvider(); +// KretaClient kretaClientForUser = KretaClient( +// user: userProviderForUser, +// settings: settingsProvider, +// database: database, +// status: status, +// ); +// await kretaClientForUser.refreshLogin(); - // Process notifications for current user - if (settingsProvider.notificationsGradesEnabled) { - await gradeNotification(userProviderForUser, kretaClientForUser); - } - if (settingsProvider.notificationsAbsencesEnabled) { - await absenceNotification(userProviderForUser, kretaClientForUser); - } - if (settingsProvider.notificationsMessagesEnabled) { - await messageNotification(userProviderForUser, kretaClientForUser); - } - if (settingsProvider.notificationsLessonsEnabled) { - await lessonNotification(userProviderForUser, kretaClientForUser); - } - }); - } - } +// // Process notifications for current user +// if (settingsProvider.notificationsGradesEnabled) { +// await gradeNotification(userProviderForUser, kretaClientForUser); +// } +// if (settingsProvider.notificationsAbsencesEnabled) { +// await absenceNotification(userProviderForUser, kretaClientForUser); +// } +// if (settingsProvider.notificationsMessagesEnabled) { +// await messageNotification(userProviderForUser, kretaClientForUser); +// } +// if (settingsProvider.notificationsLessonsEnabled) { +// await lessonNotification(userProviderForUser, kretaClientForUser); +// } +// }); +// } +// } -/* +// /* -ezt a kódot nagyon szépen megírta az AI, picit szerkesztgettem is rajta //pearoo what did you do - zypherift -nem lesz tőle használhatatlan az app, de kikommenteltem, mert még a végén kima bántani fog +// ezt a kódot nagyon szépen megírta az AI, picit szerkesztgettem is rajta //pearoo what did you do - zypherift +// nem lesz tőle használhatatlan az app, de kikommenteltem, mert még a végén kima bántani fog - Future liveNotification(UserProvider currentuserProvider, KretaClient currentKretaClient) async { - // create a permanent live notification that has a progress bar on how much is left from the current lesson, the title is the name of the class - // get current lesson - TimetableProvider timetableProvider = TimetableProvider( - user: currentuserProvider, - database: database, - kreta: currentKretaClient); - await timetableProvider.restoreUser(); - await timetableProvider.fetch(week: Week.current()); - List apilessons = timetableProvider.getWeek(Week.current()) ?? []; - Lesson? currentLesson; - for (Lesson lesson in apilessons) { - if (lesson.date.isBefore(DateTime.now()) && - lesson.end.isAfter(DateTime.now())) { - currentLesson = lesson; - break; - } - } - if (currentLesson == null) { - return; - } - final elapsedTime = DateTime.now() - .difference(currentLesson.start) - .inSeconds - .toDouble(); - final maxTime = currentLesson.end - .difference(currentLesson.start) - .inSeconds - .toDouble(); +// Future liveNotification(UserProvider currentuserProvider, KretaClient currentKretaClient) async { +// // create a permanent live notification that has a progress bar on how much is left from the current lesson, the title is the name of the class +// // get current lesson +// TimetableProvider timetableProvider = TimetableProvider( +// user: currentuserProvider, +// database: database, +// kreta: currentKretaClient); +// await timetableProvider.restoreUser(); +// await timetableProvider.fetch(week: Week.current()); +// List apilessons = timetableProvider.getWeek(Week.current()) ?? []; +// Lesson? currentLesson; +// for (Lesson lesson in apilessons) { +// if (lesson.date.isBefore(DateTime.now()) && +// lesson.end.isAfter(DateTime.now())) { +// currentLesson = lesson; +// break; +// } +// } +// if (currentLesson == null) { +// return; +// } +// final elapsedTime = DateTime.now() +// .difference(currentLesson.start) +// .inSeconds +// .toDouble(); +// final maxTime = currentLesson.end +// .difference(currentLesson.start) +// .inSeconds +// .toDouble(); - final showMinutes = maxTime - elapsedTime > 60; - // create a live notification - AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails( - 'LIVE', - 'Élő óra', - channelDescription: 'Értesítés az aktuális óráról', - importance: Importance.max, - priority: Priority.max, - color: settingsProvider.customAccentColor, - ticker: 'Élő óra', - maxProgress: maxTime.toInt(), - progress: elapsedTime.toInt(), - ); - NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); - await flutterLocalNotificationsPlugin.show( - currentLesson.id.hashCode, - currentLesson.name, - "body_live".i18n.fill( - [ - currentLesson.lessonIndex, - currentLesson.name, - dayTitle(currentLesson.date), - DateFormat("HH:mm").format(currentLesson.start), - DateFormat("HH:mm").format(currentLesson.end), - ], - ), - notificationDetails, - payload: "timetable", - ); +// final showMinutes = maxTime - elapsedTime > 60; +// // create a live notification +// AndroidNotificationDetails androidNotificationDetails = +// AndroidNotificationDetails( +// 'LIVE', +// 'Élő óra', +// channelDescription: 'Értesítés az aktuális óráról', +// importance: Importance.max, +// priority: Priority.max, +// color: settingsProvider.customAccentColor, +// ticker: 'Élő óra', +// maxProgress: maxTime.toInt(), +// progress: elapsedTime.toInt(), +// ); +// NotificationDetails notificationDetails = +// NotificationDetails(android: androidNotificationDetails); +// await flutterLocalNotificationsPlugin.show( +// currentLesson.id.hashCode, +// currentLesson.name, +// "body_live".i18n.fill( +// [ +// currentLesson.lessonIndex, +// currentLesson.name, +// dayTitle(currentLesson.date), +// DateFormat("HH:mm").format(currentLesson.start), +// DateFormat("HH:mm").format(currentLesson.end), +// ], +// ), +// notificationDetails, +// payload: "timetable", +// ); - } - */ - Future gradeNotification( - UserProvider currentuserProvider, KretaClient currentKretaClient) async { - // fetch grades - GradeProvider gradeProvider = GradeProvider( - settings: settingsProvider, - user: currentuserProvider, - database: database, - kreta: currentKretaClient); - await gradeProvider.fetch(); - database.userQuery - .getGrades(userId: currentuserProvider.id!) - .then((grades) async { - DateTime lastSeenGrade = await database.userQuery.lastSeen( - userId: currentuserProvider.id!, category: LastSeenCategory.grade); +// } +// */ +// Future gradeNotification( +// UserProvider currentuserProvider, KretaClient currentKretaClient) async { +// // fetch grades +// GradeProvider gradeProvider = GradeProvider( +// settings: settingsProvider, +// user: currentuserProvider, +// database: database, +// kreta: currentKretaClient); +// await gradeProvider.fetch(); +// database.userQuery +// .getGrades(userId: currentuserProvider.id!) +// .then((grades) async { +// DateTime lastSeenGrade = await database.userQuery.lastSeen( +// userId: currentuserProvider.id!, category: LastSeenCategory.grade); - // loop through grades and see which hasn't been seen yet - for (Grade grade in grades) { - // if grade is not a normal grade (1-5), don't show it - if ([1, 2, 3, 4, 5].contains(grade.value.value)) { - // if the grade was added over a week ago, don't show it to avoid notification spam - if (grade.date.isAfter(lastSeenGrade) && - DateTime.now().difference(grade.date).inDays < 7) { - // send notificiation about new grade - AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails( - 'GRADES', - 'Jegyek', - channelDescription: 'Értesítés jegyek beírásakor', - importance: Importance.max, - priority: Priority.max, - color: settingsProvider.customAccentColor, - ticker: 'Jegyek', - ); - NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); - if (currentuserProvider.getUsers().length == 1) { - await flutterLocalNotificationsPlugin.show( - grade.id.hashCode, - "title_grade".i18n, - "body_grade".i18n.fill( - [ - grade.subject.isRenamed && - settingsProvider.renamedSubjectsEnabled - ? grade.subject.renamedTo! - : grade.subject.name, - grade.value.value.toString() - ], - ), - notificationDetails, - payload: "grades"); - } else if (settingsProvider.gradeOpeningFun) { - // if surprise grades are enabled, show a notification without the grade - await flutterLocalNotificationsPlugin.show( - grade.id.hashCode, - "title_grade".i18n, - "body_grade_surprise".i18n.fill( - [ - grade.subject.isRenamed && - settingsProvider.renamedSubjectsEnabled - ? grade.subject.renamedTo! - : grade.subject.name, - grade.value.value.toString() - ], - ), - notificationDetails, - payload: "grades"); - } else { - // multiple users are added, also display student name - await flutterLocalNotificationsPlugin.show( - grade.id.hashCode, - "title_grade".i18n, - "body_grade_multiuser".i18n.fill( - [ - currentuserProvider.displayName!, - grade.subject.isRenamed && - settingsProvider.renamedSubjectsEnabled - ? grade.subject.renamedTo! - : grade.subject.name, - grade.value.value.toString() - ], - ), - notificationDetails, - payload: "grades"); - } - } - } - } - // set grade seen status - database.userStore.storeLastSeen(DateTime.now(), - userId: currentuserProvider.id!, category: LastSeenCategory.grade); - }); - } +// // loop through grades and see which hasn't been seen yet +// for (Grade grade in grades) { +// // if grade is not a normal grade (1-5), don't show it +// if ([1, 2, 3, 4, 5].contains(grade.value.value)) { +// // if the grade was added over a week ago, don't show it to avoid notification spam +// if (grade.date.isAfter(lastSeenGrade) && +// DateTime.now().difference(grade.date).inDays < 7) { +// // send notificiation about new grade +// AndroidNotificationDetails androidNotificationDetails = +// AndroidNotificationDetails( +// 'GRADES', +// 'Jegyek', +// channelDescription: 'Értesítés jegyek beírásakor', +// importance: Importance.max, +// priority: Priority.max, +// color: settingsProvider.customAccentColor, +// ticker: 'Jegyek', +// ); +// NotificationDetails notificationDetails = +// NotificationDetails(android: androidNotificationDetails); +// if (currentuserProvider.getUsers().length == 1) { +// await flutterLocalNotificationsPlugin.show( +// grade.id.hashCode, +// "title_grade".i18n, +// "body_grade".i18n.fill( +// [ +// grade.subject.isRenamed && +// settingsProvider.renamedSubjectsEnabled +// ? grade.subject.renamedTo! +// : grade.subject.name, +// grade.value.value.toString() +// ], +// ), +// notificationDetails, +// payload: "grades"); +// } else if (settingsProvider.gradeOpeningFun) { +// // if surprise grades are enabled, show a notification without the grade +// await flutterLocalNotificationsPlugin.show( +// grade.id.hashCode, +// "title_grade".i18n, +// "body_grade_surprise".i18n.fill( +// [ +// grade.subject.isRenamed && +// settingsProvider.renamedSubjectsEnabled +// ? grade.subject.renamedTo! +// : grade.subject.name, +// grade.value.value.toString() +// ], +// ), +// notificationDetails, +// payload: "grades"); +// } else { +// // multiple users are added, also display student name +// await flutterLocalNotificationsPlugin.show( +// grade.id.hashCode, +// "title_grade".i18n, +// "body_grade_multiuser".i18n.fill( +// [ +// currentuserProvider.displayName!, +// grade.subject.isRenamed && +// settingsProvider.renamedSubjectsEnabled +// ? grade.subject.renamedTo! +// : grade.subject.name, +// grade.value.value.toString() +// ], +// ), +// notificationDetails, +// payload: "grades"); +// } +// } +// } +// } +// // set grade seen status +// database.userStore.storeLastSeen(DateTime.now(), +// userId: currentuserProvider.id!, category: LastSeenCategory.grade); +// }); +// } - Future absenceNotification( - UserProvider currentuserProvider, KretaClient currentKretaClient) async { - // get absences from api - List? absenceJson = await currentKretaClient - .getAPI(KretaAPI.absences(currentuserProvider.instituteCode ?? "")); - if (absenceJson == null) { - return; - } - DateTime lastSeenAbsence = await database.userQuery.lastSeen( - userId: currentuserProvider.id!, category: LastSeenCategory.absence); - // format api absences - List absences = - absenceJson.map((e) => Absence.fromJson(e)).toList(); - for (Absence absence in absences) { - if (absence.date.isAfter(lastSeenAbsence)) { - AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails( - 'ABSENCES', - 'Hiányzások', - channelDescription: 'Értesítés hiányzások beírásakor', - importance: Importance.max, - priority: Priority.max, - color: settingsProvider.customAccentColor, - ticker: 'Hiányzások', - ); - NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); - if (currentuserProvider.getUsers().length == 1) { - await flutterLocalNotificationsPlugin.show( - absence.id.hashCode, - "title_absence" - .i18n, // https://discord.com/channels/1111649116020285532/1153273625206591528 - "body_absence".i18n.fill( - [ - DateFormat("yyyy-MM-dd").format(absence.date), - absence.subject.isRenamed && - settingsProvider.renamedSubjectsEnabled - ? absence.subject.renamedTo! - : absence.subject.name - ], - ), - notificationDetails, - payload: "absences"); - } else { - await flutterLocalNotificationsPlugin.show( - absence.id.hashCode, - "title_absence" - .i18n, // https://discord.com/channels/1111649116020285532/1153273625206591528 - "body_absence_multiuser".i18n.fill( - [ - currentuserProvider.displayName!, - DateFormat("yyyy-MM-dd").format(absence.date), - absence.subject.isRenamed && - settingsProvider.renamedSubjectsEnabled - ? absence.subject.renamedTo! - : absence.subject.name - ], - ), - notificationDetails, - payload: "absences"); - } - } - } - await database.userStore.storeLastSeen(DateTime.now(), - userId: currentuserProvider.id!, category: LastSeenCategory.absence); - } +// Future absenceNotification( +// UserProvider currentuserProvider, KretaClient currentKretaClient) async { +// // get absences from api +// List? absenceJson = await currentKretaClient +// .getAPI(KretaAPI.absences(currentuserProvider.instituteCode ?? "")); +// if (absenceJson == null) { +// return; +// } +// DateTime lastSeenAbsence = await database.userQuery.lastSeen( +// userId: currentuserProvider.id!, category: LastSeenCategory.absence); +// // format api absences +// List absences = +// absenceJson.map((e) => Absence.fromJson(e)).toList(); +// for (Absence absence in absences) { +// if (absence.date.isAfter(lastSeenAbsence)) { +// AndroidNotificationDetails androidNotificationDetails = +// AndroidNotificationDetails( +// 'ABSENCES', +// 'Hiányzások', +// channelDescription: 'Értesítés hiányzások beírásakor', +// importance: Importance.max, +// priority: Priority.max, +// color: settingsProvider.customAccentColor, +// ticker: 'Hiányzások', +// ); +// NotificationDetails notificationDetails = +// NotificationDetails(android: androidNotificationDetails); +// if (currentuserProvider.getUsers().length == 1) { +// await flutterLocalNotificationsPlugin.show( +// absence.id.hashCode, +// "title_absence" +// .i18n, // https://discord.com/channels/1111649116020285532/1153273625206591528 +// "body_absence".i18n.fill( +// [ +// DateFormat("yyyy-MM-dd").format(absence.date), +// absence.subject.isRenamed && +// settingsProvider.renamedSubjectsEnabled +// ? absence.subject.renamedTo! +// : absence.subject.name +// ], +// ), +// notificationDetails, +// payload: "absences"); +// } else { +// await flutterLocalNotificationsPlugin.show( +// absence.id.hashCode, +// "title_absence" +// .i18n, // https://discord.com/channels/1111649116020285532/1153273625206591528 +// "body_absence_multiuser".i18n.fill( +// [ +// currentuserProvider.displayName!, +// DateFormat("yyyy-MM-dd").format(absence.date), +// absence.subject.isRenamed && +// settingsProvider.renamedSubjectsEnabled +// ? absence.subject.renamedTo! +// : absence.subject.name +// ], +// ), +// notificationDetails, +// payload: "absences"); +// } +// } +// } +// await database.userStore.storeLastSeen(DateTime.now(), +// userId: currentuserProvider.id!, category: LastSeenCategory.absence); +// } - Future messageNotification( - UserProvider currentuserProvider, KretaClient currentKretaClient) async { - // get messages from api - List? messageJson = - await currentKretaClient.getAPI(KretaAPI.messages("beerkezett")); - if (messageJson == null) { - return; - } - // format api messages to correct format - // Parse messages - List messages = []; - await Future.wait(List.generate(messageJson.length, (index) { - return () async { - Map message = messageJson.cast()[index]; - Map? innerMessageJson = await currentKretaClient - .getAPI(KretaAPI.message(message["azonosito"].toString())); - await Future.delayed(const Duration(seconds: 1)); - if (innerMessageJson != null) { - messages.add( - Message.fromJson(innerMessageJson, forceType: MessageType.inbox)); - } - }(); - })); +// Future messageNotification( +// UserProvider currentuserProvider, KretaClient currentKretaClient) async { +// // get messages from api +// List? messageJson = +// await currentKretaClient.getAPI(KretaAPI.messages("beerkezett")); +// if (messageJson == null) { +// return; +// } +// // format api messages to correct format +// // Parse messages +// List messages = []; +// await Future.wait(List.generate(messageJson.length, (index) { +// return () async { +// Map message = messageJson.cast()[index]; +// Map? innerMessageJson = await currentKretaClient +// .getAPI(KretaAPI.message(message["azonosito"].toString())); +// await Future.delayed(const Duration(seconds: 1)); +// if (innerMessageJson != null) { +// messages.add( +// Message.fromJson(innerMessageJson, forceType: MessageType.inbox)); +// } +// }(); +// })); - DateTime lastSeenMessage = await database.userQuery.lastSeen( - userId: currentuserProvider.id!, category: LastSeenCategory.message); +// DateTime lastSeenMessage = await database.userQuery.lastSeen( +// userId: currentuserProvider.id!, category: LastSeenCategory.message); - for (Message message in messages) { - if (message.date.isAfter(lastSeenMessage)) { - AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails( - 'MESSAGES', - 'Üzenetek', - channelDescription: 'Értesítés kapott üzenetekkor', - importance: Importance.max, - priority: Priority.max, - color: settingsProvider.customAccentColor, - ticker: 'Üzenetek', - ); - NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); - if (currentuserProvider.getUsers().length == 1) { - await flutterLocalNotificationsPlugin.show( - message.id.hashCode, - message.author, - message.content.replaceAll(RegExp(r'<[^>]*>'), ''), - notificationDetails, - payload: "messages", - ); - } else { - await flutterLocalNotificationsPlugin.show( - message.id.hashCode, - "(${currentuserProvider.displayName!}) ${message.author}", - message.content.replaceAll(RegExp(r'<[^>]*>'), ''), - notificationDetails, - payload: "messages", - ); - } - } - } - await database.userStore.storeLastSeen(DateTime.now(), - userId: currentuserProvider.id!, category: LastSeenCategory.message); - } +// for (Message message in messages) { +// if (message.date.isAfter(lastSeenMessage)) { +// AndroidNotificationDetails androidNotificationDetails = +// AndroidNotificationDetails( +// 'MESSAGES', +// 'Üzenetek', +// channelDescription: 'Értesítés kapott üzenetekkor', +// importance: Importance.max, +// priority: Priority.max, +// color: settingsProvider.customAccentColor, +// ticker: 'Üzenetek', +// ); +// NotificationDetails notificationDetails = +// NotificationDetails(android: androidNotificationDetails); +// if (currentuserProvider.getUsers().length == 1) { +// await flutterLocalNotificationsPlugin.show( +// message.id.hashCode, +// message.author, +// message.content.replaceAll(RegExp(r'<[^>]*>'), ''), +// notificationDetails, +// payload: "messages", +// ); +// } else { +// await flutterLocalNotificationsPlugin.show( +// message.id.hashCode, +// "(${currentuserProvider.displayName!}) ${message.author}", +// message.content.replaceAll(RegExp(r'<[^>]*>'), ''), +// notificationDetails, +// payload: "messages", +// ); +// } +// } +// } +// await database.userStore.storeLastSeen(DateTime.now(), +// userId: currentuserProvider.id!, category: LastSeenCategory.message); +// } - Future lessonNotification( - UserProvider currentuserProvider, KretaClient currentKretaClient) async { - // get lessons from api - TimetableProvider timetableProvider = TimetableProvider( - user: currentuserProvider, - database: database, - kreta: currentKretaClient); - await timetableProvider.restoreUser(); - await timetableProvider.fetch(week: Week.current()); - List apilessons = timetableProvider.getWeek(Week.current()) ?? []; +// Future lessonNotification( +// UserProvider currentuserProvider, KretaClient currentKretaClient) async { +// // get lessons from api +// TimetableProvider timetableProvider = TimetableProvider( +// user: currentuserProvider, +// database: database, +// kreta: currentKretaClient); +// await timetableProvider.restoreUser(); +// await timetableProvider.fetch(week: Week.current()); +// List apilessons = timetableProvider.getWeek(Week.current()) ?? []; - DateTime lastSeenLesson = await database.userQuery.lastSeen( - userId: currentuserProvider.id!, category: LastSeenCategory.lesson); - Lesson? latestLesson; +// DateTime lastSeenLesson = await database.userQuery.lastSeen( +// userId: currentuserProvider.id!, category: LastSeenCategory.lesson); +// Lesson? latestLesson; - for (Lesson lesson in apilessons) { - if ((lesson.status?.name != "Elmaradt" || - lesson.substituteTeacher?.name != "") && - lesson.date.isAfter(latestLesson?.start ?? DateTime(1970))) { - latestLesson = lesson; - } - if (lesson.date.isAfter(lastSeenLesson)) { - AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails( - 'LESSONS', - 'Órák', - channelDescription: 'Értesítés órák elmaradásáról, helyettesítésről', - importance: Importance.max, - priority: Priority.max, - color: settingsProvider.customAccentColor, - ticker: 'Órák', - ); - NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); - if (currentuserProvider.getUsers().length == 1) { - if (lesson.status?.name == "Elmaradt") { - switch (I18n.localeStr) { - case "en_en": - { - await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_canceled".i18n.fill( - [ - lesson.lessonIndex, - lesson.name, - dayTitle(lesson.date) - ], - ), - notificationDetails, - payload: "timetable"); - break; - } - case "hu_hu": - { - await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_canceled".i18n.fill( - [ - dayTitle(lesson.date), - lesson.lessonIndex, - lesson.name - ], - ), - notificationDetails, - payload: "timetable"); - break; - } - default: - { - await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_canceled".i18n.fill( - [ - lesson.lessonIndex, - lesson.name, - dayTitle(lesson.date) - ], - ), - notificationDetails, - payload: "timetable"); - break; - } - } - } else if (lesson.substituteTeacher?.name != "" && - lesson.substituteTeacher != null) { - switch (I18n.localeStr) { - case "en_en": - { - await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_substituted".i18n.fill( - [ - lesson.lessonIndex, - lesson.name, - dayTitle(lesson.date), - ((lesson.substituteTeacher?.isRenamed ?? false) - ? lesson.substituteTeacher?.renamedTo! - : lesson.substituteTeacher?.name) ?? - '', - ], - ), - notificationDetails, - payload: "timetable", - ); - break; - } - case "hu_hu": - { - await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_substituted".i18n.fill( - [ - dayTitle(lesson.date), - lesson.lessonIndex, - lesson.name, - ((lesson.substituteTeacher?.isRenamed ?? false) - ? lesson.substituteTeacher?.renamedTo! - : lesson.substituteTeacher?.name) ?? - '', - ], - ), - notificationDetails, - payload: "timetable", - ); - break; - } - default: - { - await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_substituted".i18n.fill( - [ - lesson.lessonIndex, - lesson.name, - dayTitle(lesson.date), - ((lesson.substituteTeacher?.isRenamed ?? false) - ? lesson.substituteTeacher?.renamedTo! - : lesson.substituteTeacher?.name) ?? - '', - ], - ), - notificationDetails, - payload: "timetable", - ); - break; - } - } - } - } else { - if (lesson.status?.name == "Elmaradt") { - switch (I18n.localeStr) { - case "en_en": - { - await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_canceled_multiuser".i18n.fill( - [ - currentuserProvider.displayName!, - lesson.lessonIndex, - lesson.name, - dayTitle(lesson.date) - ], - ), - notificationDetails, - payload: "timetable", - ); - break; - } - case "hu_hu": - { - await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_canceled_multiuser".i18n.fill( - [ - currentuserProvider.displayName!, - dayTitle(lesson.date), - lesson.lessonIndex, - lesson.name - ], - ), - notificationDetails, - payload: "timetable", - ); - break; - } - default: - { - await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_canceled_multiuser".i18n.fill( - [ - currentuserProvider.displayName!, - lesson.lessonIndex, - lesson.name, - dayTitle(lesson.date) - ], - ), - notificationDetails, - payload: "timetable", - ); - break; - } - } - } else if (lesson.substituteTeacher?.name != "") { - switch (I18n.localeStr) { - case "en_en": - { - await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_substituted_multiuser".i18n.fill( - [ - currentuserProvider.displayName!, - lesson.lessonIndex, - lesson.name, - dayTitle(lesson.date), - ((lesson.substituteTeacher?.isRenamed ?? false) - ? lesson.substituteTeacher?.renamedTo! - : lesson.substituteTeacher?.name) ?? - '', - ], - ), - notificationDetails, - payload: "timetable", - ); - break; - } - case "hu_hu": - { - await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_substituted_multiuser".i18n.fill( - [ - currentuserProvider.displayName!, - dayTitle(lesson.date), - lesson.lessonIndex, - lesson.name, - ((lesson.substituteTeacher?.isRenamed ?? false) - ? lesson.substituteTeacher?.renamedTo! - : lesson.substituteTeacher?.name) ?? - '', - ], - ), - notificationDetails, - payload: "timetable", - ); - break; - } - default: - { - await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_substituted_multiuser".i18n.fill( - [ - currentuserProvider.displayName!, - lesson.lessonIndex, - lesson.name, - dayTitle(lesson.date), - (lesson.substituteTeacher?.isRenamed ?? false) - ? lesson.substituteTeacher!.renamedTo! - : lesson.substituteTeacher!.name - ], - ), - notificationDetails, - payload: "timetable", - ); - break; - } - } - } - } - } - } - // lesson.date does not contain time, only the date - await database.userStore.storeLastSeen( - latestLesson?.start ?? DateTime.now(), - userId: currentuserProvider.id!, - category: LastSeenCategory.lesson); - } +// for (Lesson lesson in apilessons) { +// if ((lesson.status?.name != "Elmaradt" || +// lesson.substituteTeacher?.name != "") && +// lesson.date.isAfter(latestLesson?.start ?? DateTime(1970))) { +// latestLesson = lesson; +// } +// if (lesson.date.isAfter(lastSeenLesson)) { +// AndroidNotificationDetails androidNotificationDetails = +// AndroidNotificationDetails( +// 'LESSONS', +// 'Órák', +// channelDescription: 'Értesítés órák elmaradásáról, helyettesítésről', +// importance: Importance.max, +// priority: Priority.max, +// color: settingsProvider.customAccentColor, +// ticker: 'Órák', +// ); +// NotificationDetails notificationDetails = +// NotificationDetails(android: androidNotificationDetails); +// if (currentuserProvider.getUsers().length == 1) { +// if (lesson.status?.name == "Elmaradt") { +// switch (I18n.localeStr) { +// case "en_en": +// { +// await flutterLocalNotificationsPlugin.show( +// lesson.id.hashCode, +// "title_lesson".i18n, +// "body_lesson_canceled".i18n.fill( +// [ +// lesson.lessonIndex, +// lesson.name, +// dayTitle(lesson.date) +// ], +// ), +// notificationDetails, +// payload: "timetable"); +// break; +// } +// case "hu_hu": +// { +// await flutterLocalNotificationsPlugin.show( +// lesson.id.hashCode, +// "title_lesson".i18n, +// "body_lesson_canceled".i18n.fill( +// [ +// dayTitle(lesson.date), +// lesson.lessonIndex, +// lesson.name +// ], +// ), +// notificationDetails, +// payload: "timetable"); +// break; +// } +// default: +// { +// await flutterLocalNotificationsPlugin.show( +// lesson.id.hashCode, +// "title_lesson".i18n, +// "body_lesson_canceled".i18n.fill( +// [ +// lesson.lessonIndex, +// lesson.name, +// dayTitle(lesson.date) +// ], +// ), +// notificationDetails, +// payload: "timetable"); +// break; +// } +// } +// } else if (lesson.substituteTeacher?.name != "" && +// lesson.substituteTeacher != null) { +// switch (I18n.localeStr) { +// case "en_en": +// { +// await flutterLocalNotificationsPlugin.show( +// lesson.id.hashCode, +// "title_lesson".i18n, +// "body_lesson_substituted".i18n.fill( +// [ +// lesson.lessonIndex, +// lesson.name, +// dayTitle(lesson.date), +// ((lesson.substituteTeacher?.isRenamed ?? false) +// ? lesson.substituteTeacher?.renamedTo! +// : lesson.substituteTeacher?.name) ?? +// '', +// ], +// ), +// notificationDetails, +// payload: "timetable", +// ); +// break; +// } +// case "hu_hu": +// { +// await flutterLocalNotificationsPlugin.show( +// lesson.id.hashCode, +// "title_lesson".i18n, +// "body_lesson_substituted".i18n.fill( +// [ +// dayTitle(lesson.date), +// lesson.lessonIndex, +// lesson.name, +// ((lesson.substituteTeacher?.isRenamed ?? false) +// ? lesson.substituteTeacher?.renamedTo! +// : lesson.substituteTeacher?.name) ?? +// '', +// ], +// ), +// notificationDetails, +// payload: "timetable", +// ); +// break; +// } +// default: +// { +// await flutterLocalNotificationsPlugin.show( +// lesson.id.hashCode, +// "title_lesson".i18n, +// "body_lesson_substituted".i18n.fill( +// [ +// lesson.lessonIndex, +// lesson.name, +// dayTitle(lesson.date), +// ((lesson.substituteTeacher?.isRenamed ?? false) +// ? lesson.substituteTeacher?.renamedTo! +// : lesson.substituteTeacher?.name) ?? +// '', +// ], +// ), +// notificationDetails, +// payload: "timetable", +// ); +// break; +// } +// } +// } +// } else { +// if (lesson.status?.name == "Elmaradt") { +// switch (I18n.localeStr) { +// case "en_en": +// { +// await flutterLocalNotificationsPlugin.show( +// lesson.id.hashCode, +// "title_lesson".i18n, +// "body_lesson_canceled_multiuser".i18n.fill( +// [ +// currentuserProvider.displayName!, +// lesson.lessonIndex, +// lesson.name, +// dayTitle(lesson.date) +// ], +// ), +// notificationDetails, +// payload: "timetable", +// ); +// break; +// } +// case "hu_hu": +// { +// await flutterLocalNotificationsPlugin.show( +// lesson.id.hashCode, +// "title_lesson".i18n, +// "body_lesson_canceled_multiuser".i18n.fill( +// [ +// currentuserProvider.displayName!, +// dayTitle(lesson.date), +// lesson.lessonIndex, +// lesson.name +// ], +// ), +// notificationDetails, +// payload: "timetable", +// ); +// break; +// } +// default: +// { +// await flutterLocalNotificationsPlugin.show( +// lesson.id.hashCode, +// "title_lesson".i18n, +// "body_lesson_canceled_multiuser".i18n.fill( +// [ +// currentuserProvider.displayName!, +// lesson.lessonIndex, +// lesson.name, +// dayTitle(lesson.date) +// ], +// ), +// notificationDetails, +// payload: "timetable", +// ); +// break; +// } +// } +// } else if (lesson.substituteTeacher?.name != "") { +// switch (I18n.localeStr) { +// case "en_en": +// { +// await flutterLocalNotificationsPlugin.show( +// lesson.id.hashCode, +// "title_lesson".i18n, +// "body_lesson_substituted_multiuser".i18n.fill( +// [ +// currentuserProvider.displayName!, +// lesson.lessonIndex, +// lesson.name, +// dayTitle(lesson.date), +// ((lesson.substituteTeacher?.isRenamed ?? false) +// ? lesson.substituteTeacher?.renamedTo! +// : lesson.substituteTeacher?.name) ?? +// '', +// ], +// ), +// notificationDetails, +// payload: "timetable", +// ); +// break; +// } +// case "hu_hu": +// { +// await flutterLocalNotificationsPlugin.show( +// lesson.id.hashCode, +// "title_lesson".i18n, +// "body_lesson_substituted_multiuser".i18n.fill( +// [ +// currentuserProvider.displayName!, +// dayTitle(lesson.date), +// lesson.lessonIndex, +// lesson.name, +// ((lesson.substituteTeacher?.isRenamed ?? false) +// ? lesson.substituteTeacher?.renamedTo! +// : lesson.substituteTeacher?.name) ?? +// '', +// ], +// ), +// notificationDetails, +// payload: "timetable", +// ); +// break; +// } +// default: +// { +// await flutterLocalNotificationsPlugin.show( +// lesson.id.hashCode, +// "title_lesson".i18n, +// "body_lesson_substituted_multiuser".i18n.fill( +// [ +// currentuserProvider.displayName!, +// lesson.lessonIndex, +// lesson.name, +// dayTitle(lesson.date), +// (lesson.substituteTeacher?.isRenamed ?? false) +// ? lesson.substituteTeacher!.renamedTo! +// : lesson.substituteTeacher!.name +// ], +// ), +// notificationDetails, +// payload: "timetable", +// ); +// break; +// } +// } +// } +// } +// } +// } +// // lesson.date does not contain time, only the date +// await database.userStore.storeLastSeen( +// latestLesson?.start ?? DateTime.now(), +// userId: currentuserProvider.id!, +// category: LastSeenCategory.lesson); +// } - // Called when the user taps a notification - void onDidReceiveNotificationResponse( - NotificationResponse notificationResponse) async { - final String? payload = notificationResponse.payload; - if (notificationResponse.payload != null) { - debugPrint('notification payload: $payload'); - } - switch (payload) { - case "timetable": - locator().navigateTo("timetable"); - break; - case "grades": - locator().navigateTo("grades"); - break; - case "messages": - locator().navigateTo("messages"); - break; - case "absences": - locator().navigateTo("absences"); - break; - case "settings": - locator().navigateTo("settings"); - break; - default: - break; - } - } +// // Called when the user taps a notification +// void onDidReceiveNotificationResponse( +// NotificationResponse notificationResponse) async { +// final String? payload = notificationResponse.payload; +// if (notificationResponse.payload != null) { +// debugPrint('notification payload: $payload'); +// } +// switch (payload) { +// case "timetable": +// locator().navigateTo("timetable"); +// break; +// case "grades": +// locator().navigateTo("grades"); +// break; +// case "messages": +// locator().navigateTo("messages"); +// break; +// case "absences": +// locator().navigateTo("absences"); +// break; +// case "settings": +// locator().navigateTo("settings"); +// break; +// default: +// break; +// } +// } - // Set all notification categories to seen - Future setAllCategoriesSeen(UserProvider userProvider) async { - if (userProvider.id != null) { - for (LastSeenCategory category in LastSeenCategory.values) { - await database.userStore.storeLastSeen(DateTime.now(), - userId: userProvider.id!, category: category); - } - } - } -} +// // Set all notification categories to seen +// Future setAllCategoriesSeen(UserProvider userProvider) async { +// if (userProvider.id != null) { +// for (LastSeenCategory category in LastSeenCategory.values) { +// await database.userStore.storeLastSeen(DateTime.now(), +// userId: userProvider.id!, category: category); +// } +// } +// } +// } diff --git a/refilc/lib/main.dart b/refilc/lib/main.dart index 5b0a3f4..6185a4c 100644 --- a/refilc/lib/main.dart +++ b/refilc/lib/main.dart @@ -104,7 +104,7 @@ class Startup { user = await database.query.getUsers(settings); // Set all notification categories to seen to avoid having notifications that the user has already seen in the app - NotificationsHelper().setAllCategoriesSeen(user); + // NotificationsHelper().setAllCategoriesSeen(user); late FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin; // Notifications setup @@ -165,11 +165,11 @@ class Startup { ); // Initialize notifications - await flutterLocalNotificationsPlugin.initialize( - initializationSettings, - onDidReceiveNotificationResponse: - NotificationsHelper().onDidReceiveNotificationResponse, - ); + // await flutterLocalNotificationsPlugin.initialize( + // initializationSettings, + // onDidReceiveNotificationResponse: + // NotificationsHelper().onDidReceiveNotificationResponse, + // ); } // if (Platform.isAndroid || Platform.isIOS) { @@ -239,7 +239,7 @@ Future initPlatformState() async { if (!Platform.isIOS) return; LiveActivityHelper().backgroundJob(); } else { - NotificationsHelper().backgroundJob(); + // NotificationsHelper().backgroundJob(); } BackgroundFetch.finish(taskId); }, (String taskId) async { @@ -279,7 +279,7 @@ void backgroundHeadlessTask(HeadlessTask task) { if (!Platform.isIOS) return; LiveActivityHelper().backgroundJob(); } else { - NotificationsHelper().backgroundJob(); + // NotificationsHelper().backgroundJob(); } BackgroundFetch.finish(task.taskId); } diff --git a/refilc_kreta_api/lib/providers/grade_provider.dart b/refilc_kreta_api/lib/providers/grade_provider.dart index 804b1e9..b608dd8 100644 --- a/refilc_kreta_api/lib/providers/grade_provider.dart +++ b/refilc_kreta_api/lib/providers/grade_provider.dart @@ -153,7 +153,7 @@ class GradeProvider with ChangeNotifier { for (Grade grade in grs) { if (grade.value.value == 5) { gradeStreak++; - } else if (grade.value.value !=0) { + } else if (grade.value.value != 0) { break; } } diff --git a/refilc_mobile_ui/lib/screens/settings/notifications_screen.dart b/refilc_mobile_ui/lib/screens/settings/notifications_screen.dart index 514515e..06581b5 100644 --- a/refilc_mobile_ui/lib/screens/settings/notifications_screen.dart +++ b/refilc_mobile_ui/lib/screens/settings/notifications_screen.dart @@ -1,277 +1,277 @@ -import 'package:flutter/foundation.dart'; -import 'package:refilc/api/providers/database_provider.dart'; -import 'package:refilc/api/providers/user_provider.dart'; -import 'package:refilc/helpers/notification_helper.dart'; -import 'package:refilc/models/settings.dart'; -import 'package:refilc/models/user.dart'; -import 'package:refilc/theme/colors/colors.dart'; -// import 'package:refilc_mobile_ui/common/beta_chip.dart'; -import 'package:refilc_mobile_ui/common/panel/panel_button.dart'; -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_feather_icons/flutter_feather_icons.dart'; -import 'package:provider/provider.dart'; -import 'package:refilc_mobile_ui/common/splitted_panel/splitted_panel.dart'; -import 'notifications_screen.i18n.dart'; +// import 'package:flutter/foundation.dart'; +// import 'package:refilc/api/providers/database_provider.dart'; +// import 'package:refilc/api/providers/user_provider.dart'; +// import 'package:refilc/helpers/notification_helper.dart'; +// import 'package:refilc/models/settings.dart'; +// import 'package:refilc/models/user.dart'; +// import 'package:refilc/theme/colors/colors.dart'; +// // import 'package:refilc_mobile_ui/common/beta_chip.dart'; +// import 'package:refilc_mobile_ui/common/panel/panel_button.dart'; +// import 'package:flutter/cupertino.dart'; +// import 'package:flutter/material.dart'; +// import 'package:flutter_feather_icons/flutter_feather_icons.dart'; +// import 'package:provider/provider.dart'; +// import 'package:refilc_mobile_ui/common/splitted_panel/splitted_panel.dart'; +// import 'notifications_screen.i18n.dart'; -class MenuNotifications extends StatelessWidget { - const MenuNotifications({ - super.key, - this.borderRadius = const BorderRadius.vertical( - top: Radius.circular(4.0), bottom: Radius.circular(4.0)), - }); +// class MenuNotifications extends StatelessWidget { +// const MenuNotifications({ +// super.key, +// this.borderRadius = const BorderRadius.vertical( +// top: Radius.circular(4.0), bottom: Radius.circular(4.0)), +// }); - final BorderRadius borderRadius; +// final BorderRadius borderRadius; - @override - Widget build(BuildContext context) { - return PanelButton( - onPressed: () => Navigator.of(context, rootNavigator: true).push( - CupertinoPageRoute(builder: (context) => const NotificationsScreen()), - ), - title: Row( - children: [ - Text( - "notifications_screen".i18n, - ), - // const SizedBox(width: 5.0), - // const BetaChip( - // disabled: false, - // ), - ], - ), - leading: Icon( - FeatherIcons.messageCircle, - size: 22.0, - color: AppColors.of(context).text.withOpacity(0.95), - ), - trailing: Icon( - FeatherIcons.chevronRight, - size: 22.0, - color: AppColors.of(context).text.withOpacity(0.95), - ), - borderRadius: borderRadius, - ); - } -} +// @override +// Widget build(BuildContext context) { +// return PanelButton( +// onPressed: () => Navigator.of(context, rootNavigator: true).push( +// CupertinoPageRoute(builder: (context) => const NotificationsScreen()), +// ), +// title: Row( +// children: [ +// Text( +// "notifications_screen".i18n, +// ), +// // const SizedBox(width: 5.0), +// // const BetaChip( +// // disabled: false, +// // ), +// ], +// ), +// leading: Icon( +// FeatherIcons.messageCircle, +// size: 22.0, +// color: AppColors.of(context).text.withOpacity(0.95), +// ), +// trailing: Icon( +// FeatherIcons.chevronRight, +// size: 22.0, +// color: AppColors.of(context).text.withOpacity(0.95), +// ), +// borderRadius: borderRadius, +// ); +// } +// } -class NotificationsScreen extends StatelessWidget { - const NotificationsScreen({super.key}); +// class NotificationsScreen extends StatelessWidget { +// const NotificationsScreen({super.key}); - // Set all notification categories as seen to avoid spamming the user with notifications when they turn on notifications - void setAll(BuildContext context, DateTime date) { - DatabaseProvider database = - Provider.of(context, listen: false); - User? user = Provider.of(context, listen: false).user; - if (user != null) { - for (LastSeenCategory category in LastSeenCategory.values) { - database.userStore - .storeLastSeen(date, userId: user.id, category: category); - } - } - } +// Set all notification categories as seen to avoid spamming the user with notifications when they turn on notifications +// void setAll(BuildContext context, DateTime date) { +// DatabaseProvider database = +// Provider.of(context, listen: false); +// User? user = Provider.of(context, listen: false).user; +// if (user != null) { +// for (LastSeenCategory category in LastSeenCategory.values) { +// database.userStore +// .storeLastSeen(date, userId: user.id, category: category); +// } +// } +// } - @override - Widget build(BuildContext context) { - SettingsProvider settings = Provider.of(context); +// @override +// Widget build(BuildContext context) { +// SettingsProvider settings = Provider.of(context); - return Scaffold( - appBar: AppBar( - surfaceTintColor: Theme.of(context).scaffoldBackgroundColor, - leading: BackButton(color: AppColors.of(context).text), - title: Text( - "notifications_screen".i18n, - style: TextStyle(color: AppColors.of(context).text), - ), - ), - body: SingleChildScrollView( - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0), - child: Column( - children: [ - SplittedPanel( - padding: const EdgeInsets.only(top: 8.0), - cardPadding: const EdgeInsets.all(4.0), - isSeparated: true, - children: [ - PanelButton( - padding: const EdgeInsets.only(left: 14.0, right: 6.0), - onPressed: () { - settings.update( - notificationsGradesEnabled: - !settings.notificationsGradesEnabled); - setAll(context, DateTime.now()); - }, - title: Text( - "grades".i18n, - style: TextStyle( - color: AppColors.of(context).text.withOpacity( - settings.notificationsGradesEnabled ? .95 : .25), - ), - ), - leading: Icon( - FeatherIcons.bookmark, - size: 22.0, - color: AppColors.of(context).text.withOpacity( - settings.notificationsGradesEnabled ? .95 : .25), - ), - trailing: Switch( - onChanged: (v) => - settings.update(notificationsGradesEnabled: v), - value: settings.notificationsGradesEnabled, - activeColor: Theme.of(context).colorScheme.secondary, - ), - borderRadius: const BorderRadius.vertical( - top: Radius.circular(12.0), - bottom: Radius.circular(12.0), - ), - ), - ], - ), - SplittedPanel( - padding: const EdgeInsets.only(top: 8.0), - cardPadding: const EdgeInsets.all(4.0), - isSeparated: true, - children: [ - PanelButton( - padding: const EdgeInsets.only(left: 14.0, right: 6.0), - onPressed: () { - settings.update( - notificationsAbsencesEnabled: - !settings.notificationsAbsencesEnabled); - setAll(context, DateTime.now()); - }, - title: Text( - "absences".i18n, - style: TextStyle( - color: AppColors.of(context).text.withOpacity( - settings.notificationsAbsencesEnabled ? .95 : .25), - ), - ), - leading: Icon( - FeatherIcons.clock, - size: 22.0, - color: AppColors.of(context).text.withOpacity( - settings.notificationsAbsencesEnabled ? .95 : .25), - ), - trailing: Switch( - onChanged: (v) => - settings.update(notificationsAbsencesEnabled: v), - value: settings.notificationsAbsencesEnabled, - activeColor: Theme.of(context).colorScheme.secondary, - ), - borderRadius: const BorderRadius.vertical( - top: Radius.circular(12.0), - bottom: Radius.circular(12.0), - ), - ), - ], - ), - SplittedPanel( - padding: const EdgeInsets.only(top: 8.0), - cardPadding: const EdgeInsets.all(4.0), - isSeparated: true, - children: [ - PanelButton( - padding: const EdgeInsets.only(left: 14.0, right: 6.0), - onPressed: () { - settings.update( - notificationsMessagesEnabled: - !settings.notificationsMessagesEnabled); - setAll(context, DateTime.now()); - }, - title: Text( - "messages".i18n, - style: TextStyle( - color: AppColors.of(context).text.withOpacity( - settings.notificationsMessagesEnabled ? .95 : .25), - ), - ), - leading: Icon( - FeatherIcons.messageSquare, - size: 22.0, - color: AppColors.of(context).text.withOpacity( - settings.notificationsMessagesEnabled ? .95 : .25), - ), - trailing: Switch( - onChanged: (v) => - settings.update(notificationsMessagesEnabled: v), - value: settings.notificationsMessagesEnabled, - activeColor: Theme.of(context).colorScheme.secondary, - ), - borderRadius: const BorderRadius.vertical( - top: Radius.circular(12.0), - bottom: Radius.circular(12.0), - ), - ), - ], - ), - SplittedPanel( - padding: const EdgeInsets.only(top: 8.0), - cardPadding: const EdgeInsets.all(4.0), - isSeparated: true, - children: [ - PanelButton( - padding: const EdgeInsets.only(left: 14.0, right: 6.0), - onPressed: () { - settings.update( - notificationsLessonsEnabled: - !settings.notificationsLessonsEnabled); - setAll(context, DateTime.now()); - }, - title: Text( - "lessons".i18n, - style: TextStyle( - color: AppColors.of(context).text.withOpacity( - settings.notificationsLessonsEnabled ? .95 : .25), - ), - ), - leading: Icon( - FeatherIcons.bookmark, - size: 22.0, - color: AppColors.of(context).text.withOpacity( - settings.notificationsLessonsEnabled ? .95 : .25), - ), - trailing: Switch( - onChanged: (v) => - settings.update(notificationsLessonsEnabled: v), - value: settings.notificationsLessonsEnabled, - activeColor: Theme.of(context).colorScheme.secondary, - ), - borderRadius: const BorderRadius.vertical( - top: Radius.circular(12.0), - bottom: Radius.circular(12.0), - ), - ), - ], - ), - // only used for debugging, pressing **will** cause notification spam - kDebugMode - ? SplittedPanel( - padding: const EdgeInsets.only(top: 9.0), - cardPadding: const EdgeInsets.all(4.0), - isSeparated: true, - children: [ - PanelButton( - onPressed: () => setAll( - context, DateTime(1970, 1, 1, 0, 0, 0, 0, 0)), - title: Text("set_all_as_unseen".i18n), - leading: Icon( - FeatherIcons.mail, - size: 22.0, - color: AppColors.of(context).text.withOpacity(0.95), - ), - borderRadius: const BorderRadius.vertical( - top: Radius.circular(12.0), - bottom: Radius.circular(12.0)), - ) - ], - ) - : const SizedBox.shrink(), - ], - ), - ), - ), - ); - } -} +// return Scaffold( +// appBar: AppBar( +// surfaceTintColor: Theme.of(context).scaffoldBackgroundColor, +// leading: BackButton(color: AppColors.of(context).text), +// title: Text( +// "notifications_screen".i18n, +// style: TextStyle(color: AppColors.of(context).text), +// ), +// ), +// body: SingleChildScrollView( +// child: Padding( +// padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0), +// child: Column( +// children: [ +// SplittedPanel( +// padding: const EdgeInsets.only(top: 8.0), +// cardPadding: const EdgeInsets.all(4.0), +// isSeparated: true, +// children: [ +// PanelButton( +// padding: const EdgeInsets.only(left: 14.0, right: 6.0), +// onPressed: () { +// settings.update( +// notificationsGradesEnabled: +// !settings.notificationsGradesEnabled); +// setAll(context, DateTime.now()); +// }, +// title: Text( +// "grades".i18n, +// style: TextStyle( +// color: AppColors.of(context).text.withOpacity( +// settings.notificationsGradesEnabled ? .95 : .25), +// ), +// ), +// leading: Icon( +// FeatherIcons.bookmark, +// size: 22.0, +// color: AppColors.of(context).text.withOpacity( +// settings.notificationsGradesEnabled ? .95 : .25), +// ), +// trailing: Switch( +// onChanged: (v) => +// settings.update(notificationsGradesEnabled: v), +// value: settings.notificationsGradesEnabled, +// activeColor: Theme.of(context).colorScheme.secondary, +// ), +// borderRadius: const BorderRadius.vertical( +// top: Radius.circular(12.0), +// bottom: Radius.circular(12.0), +// ), +// ), +// ], +// ), +// SplittedPanel( +// padding: const EdgeInsets.only(top: 8.0), +// cardPadding: const EdgeInsets.all(4.0), +// isSeparated: true, +// children: [ +// PanelButton( +// padding: const EdgeInsets.only(left: 14.0, right: 6.0), +// onPressed: () { +// settings.update( +// notificationsAbsencesEnabled: +// !settings.notificationsAbsencesEnabled); +// setAll(context, DateTime.now()); +// }, +// title: Text( +// "absences".i18n, +// style: TextStyle( +// color: AppColors.of(context).text.withOpacity( +// settings.notificationsAbsencesEnabled ? .95 : .25), +// ), +// ), +// leading: Icon( +// FeatherIcons.clock, +// size: 22.0, +// color: AppColors.of(context).text.withOpacity( +// settings.notificationsAbsencesEnabled ? .95 : .25), +// ), +// trailing: Switch( +// onChanged: (v) => +// settings.update(notificationsAbsencesEnabled: v), +// value: settings.notificationsAbsencesEnabled, +// activeColor: Theme.of(context).colorScheme.secondary, +// ), +// borderRadius: const BorderRadius.vertical( +// top: Radius.circular(12.0), +// bottom: Radius.circular(12.0), +// ), +// ), +// ], +// ), +// SplittedPanel( +// padding: const EdgeInsets.only(top: 8.0), +// cardPadding: const EdgeInsets.all(4.0), +// isSeparated: true, +// children: [ +// PanelButton( +// padding: const EdgeInsets.only(left: 14.0, right: 6.0), +// onPressed: () { +// settings.update( +// notificationsMessagesEnabled: +// !settings.notificationsMessagesEnabled); +// setAll(context, DateTime.now()); +// }, +// title: Text( +// "messages".i18n, +// style: TextStyle( +// color: AppColors.of(context).text.withOpacity( +// settings.notificationsMessagesEnabled ? .95 : .25), +// ), +// ), +// leading: Icon( +// FeatherIcons.messageSquare, +// size: 22.0, +// color: AppColors.of(context).text.withOpacity( +// settings.notificationsMessagesEnabled ? .95 : .25), +// ), +// trailing: Switch( +// onChanged: (v) => +// settings.update(notificationsMessagesEnabled: v), +// value: settings.notificationsMessagesEnabled, +// activeColor: Theme.of(context).colorScheme.secondary, +// ), +// borderRadius: const BorderRadius.vertical( +// top: Radius.circular(12.0), +// bottom: Radius.circular(12.0), +// ), +// ), +// ], +// ), +// SplittedPanel( +// padding: const EdgeInsets.only(top: 8.0), +// cardPadding: const EdgeInsets.all(4.0), +// isSeparated: true, +// children: [ +// PanelButton( +// padding: const EdgeInsets.only(left: 14.0, right: 6.0), +// onPressed: () { +// settings.update( +// notificationsLessonsEnabled: +// !settings.notificationsLessonsEnabled); +// setAll(context, DateTime.now()); +// }, +// title: Text( +// "lessons".i18n, +// style: TextStyle( +// color: AppColors.of(context).text.withOpacity( +// settings.notificationsLessonsEnabled ? .95 : .25), +// ), +// ), +// leading: Icon( +// FeatherIcons.bookmark, +// size: 22.0, +// color: AppColors.of(context).text.withOpacity( +// settings.notificationsLessonsEnabled ? .95 : .25), +// ), +// trailing: Switch( +// onChanged: (v) => +// settings.update(notificationsLessonsEnabled: v), +// value: settings.notificationsLessonsEnabled, +// activeColor: Theme.of(context).colorScheme.secondary, +// ), +// borderRadius: const BorderRadius.vertical( +// top: Radius.circular(12.0), +// bottom: Radius.circular(12.0), +// ), +// ), +// ], +// ), +// // only used for debugging, pressing **will** cause notification spam +// kDebugMode +// ? SplittedPanel( +// padding: const EdgeInsets.only(top: 9.0), +// cardPadding: const EdgeInsets.all(4.0), +// isSeparated: true, +// children: [ +// PanelButton( +// onPressed: () => setAll( +// context, DateTime(1970, 1, 1, 0, 0, 0, 0, 0)), +// title: Text("set_all_as_unseen".i18n), +// leading: Icon( +// FeatherIcons.mail, +// size: 22.0, +// color: AppColors.of(context).text.withOpacity(0.95), +// ), +// borderRadius: const BorderRadius.vertical( +// top: Radius.circular(12.0), +// bottom: Radius.circular(12.0)), +// ) +// ], +// ) +// : const SizedBox.shrink(), +// ], +// ), +// ), +// ), +// ); +// } +// } diff --git a/refilc_mobile_ui/lib/screens/settings/settings_screen.dart b/refilc_mobile_ui/lib/screens/settings/settings_screen.dart index c312771..15f2970 100644 --- a/refilc_mobile_ui/lib/screens/settings/settings_screen.dart +++ b/refilc_mobile_ui/lib/screens/settings/settings_screen.dart @@ -945,18 +945,18 @@ class SettingsScreenState extends State ), // notifications - const SplittedPanel( - padding: EdgeInsets.only(top: 8.0), - cardPadding: EdgeInsets.all(4.0), - children: [ - MenuNotifications( - borderRadius: BorderRadius.vertical( - top: Radius.circular(12.0), - bottom: Radius.circular(12.0), - ), - ), - ], - ), + // const SplittedPanel( + // padding: EdgeInsets.only(top: 8.0), + // cardPadding: EdgeInsets.all(4.0), + // children: [ + // MenuNotifications( + // borderRadius: BorderRadius.vertical( + // top: Radius.circular(12.0), + // bottom: Radius.circular(12.0), + // ), + // ), + // ], + // ), // extras const SplittedPanel(