From c05b358b4954b0a7c26d79cbc628c565d469ec34 Mon Sep 17 00:00:00 2001 From: Kima Date: Wed, 30 Aug 2023 01:22:41 +0200 Subject: [PATCH] fixed notification minden is --- filcnaplo/lib/database/init.dart | 6 +- .../lib/helpers/notification_helper.dart | 541 ++++++++++-------- .../settings/notifications_screen.dart | 303 ++++++---- .../lib/screens/settings/settings_screen.dart | 10 +- .../settings/settings_screen.i18n.dart | 3 + .../screens/summary/pages/allsum_page.dart | 2 +- 6 files changed, 499 insertions(+), 366 deletions(-) diff --git a/filcnaplo/lib/database/init.dart b/filcnaplo/lib/database/init.dart index b256cdc..4f7d1ed 100644 --- a/filcnaplo/lib/database/init.dart +++ b/filcnaplo/lib/database/init.dart @@ -20,7 +20,11 @@ const settingsDB = DatabaseStruct("settings", { "grade_color4": int, "grade_color5": int, // grade colors "vibration_strength": int, "ab_weeks": int, "swap_ab_weeks": int, "notifications": int, "notifications_bitfield": int, - "notification_poll_interval": int, "notifications_grades":int, "notifications_absences":int, "notifications_messages": int, "notifications_lessons":int, // notifications + "notification_poll_interval": int, + "notifications_grades": int, + "notifications_absences": int, + "notifications_messages": int, + "notifications_lessons": int, // notifications "x_filc_id": String, "graph_class_avg": int, "presentation_mode": int, "bell_delay": int, "bell_delay_enabled": int, "grade_opening_fun": int, "icon_pack": String, "premium_scopes": String, diff --git a/filcnaplo/lib/helpers/notification_helper.dart b/filcnaplo/lib/helpers/notification_helper.dart index 7ee3a39..fd70e10 100644 --- a/filcnaplo/lib/helpers/notification_helper.dart +++ b/filcnaplo/lib/helpers/notification_helper.dart @@ -1,9 +1,6 @@ -import 'dart:ui'; - import 'package:filcnaplo/api/providers/database_provider.dart'; import 'package:filcnaplo/api/providers/status_provider.dart'; import 'package:filcnaplo/api/providers/user_provider.dart'; -import 'package:filcnaplo/database/init.dart'; import 'package:filcnaplo/models/settings.dart'; import 'package:filcnaplo/helpers/notification_helper.i18n.dart'; import 'package:filcnaplo_kreta_api/client/api.dart'; @@ -14,7 +11,8 @@ import 'package:filcnaplo_kreta_api/models/lesson.dart'; import 'package:filcnaplo_kreta_api/models/week.dart'; import 'package:filcnaplo_kreta_api/providers/grade_provider.dart'; import 'package:filcnaplo_kreta_api/providers/timetable_provider.dart'; -import 'package:flutter_local_notifications/flutter_local_notifications.dart' hide Message; +import 'package:flutter_local_notifications/flutter_local_notifications.dart' + hide Message; import 'package:i18n_extension/i18n_widget.dart'; import 'package:intl/intl.dart'; import 'package:filcnaplo_kreta_api/models/message.dart'; @@ -24,10 +22,15 @@ class NotificationsHelper { late SettingsProvider settingsProvider; late UserProvider userProvider; late KretaClient kretaClient; - FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); + FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = + FlutterLocalNotificationsPlugin(); - List combineLists(List list1, List list2, K Function(T) keyExtractor,) { - Set uniqueKeys = Set(); + List combineLists( + List list1, + List list2, + K Function(T) keyExtractor, + ) { + Set uniqueKeys = {}; List combinedList = []; for (T item in list1) { @@ -48,10 +51,10 @@ class NotificationsHelper { return combinedList; } + String dayTitle(DateTime date) { try { - return DateFormat("EEEE", I18n.locale.languageCode) - .format(date); + return DateFormat("EEEE", I18n.locale.languageCode).format(date); } catch (e) { return "Unknown"; } @@ -60,13 +63,9 @@ class NotificationsHelper { @pragma('vm:entry-point') void backgroundJob() async { // initialize providers - FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = - FlutterLocalNotificationsPlugin(); database = DatabaseProvider(); - var db = await initDB(database); await database.init(); - settingsProvider = - await database.query.getSettings(database); + settingsProvider = await database.query.getSettings(database); userProvider = await database.query.getUsers(settingsProvider); if (userProvider.id != null && settingsProvider.notificationsEnabled) { @@ -75,78 +74,93 @@ class NotificationsHelper { kretaClient = KretaClient( user: userProvider, settings: settingsProvider, status: status); kretaClient.refreshLogin(); - if(settingsProvider.notificationsGradesEnabled) gradeNotification(); - if(settingsProvider.notificationsAbsencesEnabled) absenceNotification(); - if(settingsProvider.notificationsMessagesEnabled) messageNotification(); - if(settingsProvider.notificationsLessonsEnabled) lessonNotification(); + if (settingsProvider.notificationsGradesEnabled) gradeNotification(); + if (settingsProvider.notificationsAbsencesEnabled) absenceNotification(); + if (settingsProvider.notificationsMessagesEnabled) messageNotification(); + if (settingsProvider.notificationsLessonsEnabled) lessonNotification(); } } - + void gradeNotification() async { // fetch grades GradeProvider gradeProvider = GradeProvider( - settings: settingsProvider, - user: userProvider, - database: database, - kreta: kretaClient); - gradeProvider.fetch(); - List grades = - await database.userQuery.getGrades(userId: userProvider.id ?? ""); - DateTime lastSeenGrade = - await database.userQuery.lastSeenGrade(userId: userProvider.id ?? ""); + settings: settingsProvider, + user: userProvider, + database: database, + kreta: kretaClient); + gradeProvider.fetch(); + List grades = + await database.userQuery.getGrades(userId: userProvider.id ?? ""); + DateTime lastSeenGrade = + await database.userQuery.lastSeenGrade(userId: userProvider.id ?? ""); - // 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.seenDate.isAfter(lastSeenGrade) && grade.date.difference(DateTime.now()).inDays * -1 < 7) { - // send notificiation about new grade - const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('GRADES', 'Jegyek', - channelDescription: 'Értesítés jegyek beírásakor', - importance: Importance.max, - priority: Priority.max, - color: const Color(0xFF3D7BF4), - ticker: 'Jegyek'); - const NotificationDetails notificationDetails = NotificationDetails(android: androidNotificationDetails); - if(userProvider.getUsers().length == 1) { - await flutterLocalNotificationsPlugin.show( - grade.id.hashCode, - "title_grade".i18n, - "body_grade".i18n.fill([ - grade.value.value.toString(), - grade.subject.isRenamed && - settingsProvider.renamedSubjectsEnabled - ? grade.subject.renamedTo! - : grade.subject.name - ]), - notificationDetails); - } else { // multiple users are added, also display student name - await flutterLocalNotificationsPlugin.show( - grade.id.hashCode, - "title_grade".i18n, - "body_grade_multiuser".i18n.fill([ - userProvider.displayName!, - grade.value.value.toString(), - grade.subject.isRenamed && - settingsProvider.renamedSubjectsEnabled - ? grade.subject.renamedTo! - : grade.subject.name - ]), - notificationDetails); - } - } + // 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.seenDate.isAfter(lastSeenGrade) && + grade.date.difference(DateTime.now()).inDays * -1 < 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 (userProvider.getUsers().length == 1) { + await flutterLocalNotificationsPlugin.show( + grade.id.hashCode, + "title_grade".i18n, + "body_grade".i18n.fill( + [ + grade.value.value.toString(), + grade.subject.isRenamed && + settingsProvider.renamedSubjectsEnabled + ? grade.subject.renamedTo! + : grade.subject.name + ], + ), + notificationDetails, + ); + } else { + // multiple users are added, also display student name + await flutterLocalNotificationsPlugin.show( + grade.id.hashCode, + "title_grade".i18n, + "body_grade_multiuser".i18n.fill( + [ + userProvider.displayName!, + grade.value.value.toString(), + grade.subject.isRenamed && + settingsProvider.renamedSubjectsEnabled + ? grade.subject.renamedTo! + : grade.subject.name + ], + ), + notificationDetails, + ); + } + } } - } - // set grade seen status - gradeProvider.seenAll(); + } + // set grade seen status + gradeProvider.seenAll(); } + void absenceNotification() async { // get absences from api - List? absenceJson = await kretaClient.getAPI(KretaAPI.absences(userProvider.instituteCode ?? "")); - List storedAbsences = await database.userQuery.getAbsences(userId: userProvider.id!); - if(absenceJson == null) { + List? absenceJson = await kretaClient + .getAPI(KretaAPI.absences(userProvider.instituteCode ?? "")); + List storedAbsences = + await database.userQuery.getAbsences(userId: userProvider.id!); + if (absenceJson == null) { return; } // format api absences to correct format while preserving isSeen value @@ -159,64 +173,77 @@ class NotificationsHelper { return apiAbsence; }).toList(); List modifiedAbsences = []; - if(absences != storedAbsences) { + if (absences != storedAbsences) { // remove absences that are not new absences.removeWhere((element) => storedAbsences.contains(element)); - for(Absence absence in absences) { - if(!absence.isSeen) { + for (Absence absence in absences) { + if (!absence.isSeen) { absence.isSeen = true; modifiedAbsences.add(absence); - const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('ABSENCES', 'Hiányzások', - channelDescription: 'Értesítés hiányzások beírásakor', - importance: Importance.max, - priority: Priority.max, - color: const Color(0xFF3D7BF4), - ticker: 'Hiányzások'); - const NotificationDetails notificationDetails = NotificationDetails(android: androidNotificationDetails); - if(userProvider.getUsers().length == 1) { - await flutterLocalNotificationsPlugin.show( - absence.id.hashCode, - "title_absence".i18n, - "body_absence".i18n.fill([ - DateFormat("yyyy-MM-dd").format(absence.date), - absence.subject.isRenamed && - settingsProvider.renamedSubjectsEnabled - ? absence.subject.renamedTo! - : absence.subject.name - ]), - notificationDetails); - } else { - await flutterLocalNotificationsPlugin.show( - absence.id.hashCode, - "title_absence".i18n, - "body_absence_multiuser".i18n.fill([ - userProvider.displayName!, - DateFormat("yyyy-MM-dd").format(absence.date), - absence.subject.isRenamed && - settingsProvider.renamedSubjectsEnabled - ? absence.subject.renamedTo! - : absence.subject.name - ]), - notificationDetails); - } + 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 (userProvider.getUsers().length == 1) { + await flutterLocalNotificationsPlugin.show( + absence.id.hashCode, + "title_absence".i18n, + "body_absence".i18n.fill( + [ + DateFormat("yyyy-MM-dd").format(absence.date), + absence.subject.isRenamed && + settingsProvider.renamedSubjectsEnabled + ? absence.subject.renamedTo! + : absence.subject.name + ], + ), + notificationDetails, + ); + } else { + await flutterLocalNotificationsPlugin.show( + absence.id.hashCode, + "title_absence".i18n, + "body_absence_multiuser".i18n.fill( + [ + userProvider.displayName!, + DateFormat("yyyy-MM-dd").format(absence.date), + absence.subject.isRenamed && + settingsProvider.renamedSubjectsEnabled + ? absence.subject.renamedTo! + : absence.subject.name + ], + ), + notificationDetails, + ); + } } } } - // combine modified absences and storedabsences list and save them to the database - List combinedAbsences = combineLists( - modifiedAbsences, - storedAbsences, - (Absence absence) => absence.id, - ); - await database.userStore.storeAbsences(combinedAbsences, userId: userProvider.id!); + // combine modified absences and storedabsences list and save them to the database + List combinedAbsences = combineLists( + modifiedAbsences, + storedAbsences, + (Absence absence) => absence.id, + ); + await database.userStore + .storeAbsences(combinedAbsences, userId: userProvider.id!); } - + void messageNotification() async { // get messages from api - List? messageJson = await kretaClient.getAPI(KretaAPI.messages("beerkezett")); - List storedmessages = await database.userQuery.getMessages(userId: userProvider.id!); - if(messageJson == null) { + List? messageJson = + await kretaClient.getAPI(KretaAPI.messages("beerkezett")); + List storedmessages = + await database.userQuery.getMessages(userId: userProvider.id!); + if (messageJson == null) { return; } // format api messages to correct format while preserving isSeen value @@ -224,60 +251,71 @@ class NotificationsHelper { List messages = []; await Future.wait(List.generate(messageJson.length, (index) { return () async { - Map message = messageJson!.cast()[index]; - Map? innerMessageJson = await kretaClient.getAPI(KretaAPI.message(message["azonosito"].toString())); - if (innerMessageJson != null) messages.add(Message.fromJson(innerMessageJson, forceType: MessageType.inbox)); + Map message = messageJson.cast()[index]; + Map? innerMessageJson = await kretaClient + .getAPI(KretaAPI.message(message["azonosito"].toString())); + if (innerMessageJson != null) { + messages.add( + Message.fromJson(innerMessageJson, forceType: MessageType.inbox)); + } }(); })); - for(Message message in messages) { - for(Message storedMessage in storedmessages) { - if(message.id == storedMessage.id) { + for (Message message in messages) { + for (Message storedMessage in storedmessages) { + if (message.id == storedMessage.id) { message.isSeen = storedMessage.isSeen; } } } List modifiedmessages = []; - if(messages != storedmessages) { + if (messages != storedmessages) { // remove messages that are not new messages.removeWhere((element) => storedmessages.contains(element)); - for(Message message in messages) { - if(!message.isSeen) { + for (Message message in messages) { + if (!message.isSeen) { message.isSeen = true; modifiedmessages.add(message); - const AndroidNotificationDetails androidNotificationDetails = - AndroidNotificationDetails('MESSAGES', 'Üzenetek', - channelDescription: 'Értesítés kapott üzenetekkor', - importance: Importance.max, - priority: Priority.max, - color: const Color(0xFF3D7BF4), - ticker: 'Üzenetek'); - const NotificationDetails notificationDetails = NotificationDetails(android: androidNotificationDetails); - if(userProvider.getUsers().length == 1) { - await flutterLocalNotificationsPlugin.show( - message.id.hashCode, - message.author, - message.content.replaceAll(RegExp(r'<[^>]*>'), ''), - notificationDetails); - } else { - await flutterLocalNotificationsPlugin.show( - message.id.hashCode, - "(${userProvider.displayName!}) ${message.author}", - message.content.replaceAll(RegExp(r'<[^>]*>'), ''), - notificationDetails); - } + 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 (userProvider.getUsers().length == 1) { + await flutterLocalNotificationsPlugin.show( + message.id.hashCode, + message.author, + message.content.replaceAll(RegExp(r'<[^>]*>'), ''), + notificationDetails, + ); + } else { + await flutterLocalNotificationsPlugin.show( + message.id.hashCode, + "(${userProvider.displayName!}) ${message.author}", + message.content.replaceAll(RegExp(r'<[^>]*>'), ''), + notificationDetails, + ); + } } } } - // combine modified messages and storedmessages list and save them to the database - List combinedmessages = combineLists( - modifiedmessages, - storedmessages, - (Message message) => message.id, - ); - await database.userStore.storeMessages(combinedmessages, userId: userProvider.id!); + // combine modified messages and storedmessages list and save them to the database + List combinedmessages = combineLists( + modifiedmessages, + storedmessages, + (Message message) => message.id, + ); + await database.userStore + .storeMessages(combinedmessages, userId: userProvider.id!); } - + void lessonNotification() async { // get lesson from api TimetableProvider timetableProvider = TimetableProvider( @@ -300,15 +338,18 @@ class NotificationsHelper { if (!lesson.isSeen && lesson.isChanged) { lesson.isSeen = true; modifiedlessons.add(lesson); - const 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: const Color(0xFF3D7BF4), - ticker: 'Órák'); - const NotificationDetails notificationDetails = + 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 (userProvider.getUsers().length == 1) { if (lesson.status?.name == "Elmaradt") { @@ -316,40 +357,49 @@ class NotificationsHelper { case "en_en": { await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_canceled".i18n.fill([ + lesson.id.hashCode, + "title_lesson".i18n, + "body_lesson_canceled".i18n.fill( + [ lesson.lessonIndex, lesson.name, dayTitle(lesson.date) - ]), - notificationDetails); + ], + ), + notificationDetails, + ); break; } case "hu_hu": { await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_canceled".i18n.fill([ + lesson.id.hashCode, + "title_lesson".i18n, + "body_lesson_canceled".i18n.fill( + [ dayTitle(lesson.date), lesson.lessonIndex, lesson.name - ]), - notificationDetails); + ], + ), + notificationDetails, + ); break; } default: { await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_canceled".i18n.fill([ + lesson.id.hashCode, + "title_lesson".i18n, + "body_lesson_canceled".i18n.fill( + [ lesson.lessonIndex, lesson.name, dayTitle(lesson.date) - ]), - notificationDetails); + ], + ), + notificationDetails, + ); break; } } @@ -358,49 +408,58 @@ class NotificationsHelper { case "en_en": { await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_substituted".i18n.fill([ + lesson.id.hashCode, + "title_lesson".i18n, + "body_lesson_substituted".i18n.fill( + [ lesson.lessonIndex, lesson.name, dayTitle(lesson.date), lesson.substituteTeacher!.isRenamed ? lesson.substituteTeacher!.renamedTo! : lesson.substituteTeacher!.name - ]), - notificationDetails); + ], + ), + notificationDetails, + ); break; } case "hu_hu": { await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_substituted".i18n.fill([ + lesson.id.hashCode, + "title_lesson".i18n, + "body_lesson_substituted".i18n.fill( + [ dayTitle(lesson.date), lesson.lessonIndex, lesson.name, lesson.substituteTeacher!.isRenamed ? lesson.substituteTeacher!.renamedTo! : lesson.substituteTeacher!.name - ]), - notificationDetails); + ], + ), + notificationDetails, + ); break; } default: { await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_substituted".i18n.fill([ + lesson.id.hashCode, + "title_lesson".i18n, + "body_lesson_substituted".i18n.fill( + [ lesson.lessonIndex, lesson.name, dayTitle(lesson.date), lesson.substituteTeacher!.isRenamed ? lesson.substituteTeacher!.renamedTo! : lesson.substituteTeacher!.name - ]), - notificationDetails); + ], + ), + notificationDetails, + ); break; } } @@ -411,43 +470,52 @@ class NotificationsHelper { case "en_en": { await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_canceled".i18n.fill([ + lesson.id.hashCode, + "title_lesson".i18n, + "body_lesson_canceled".i18n.fill( + [ userProvider.displayName!, lesson.lessonIndex, lesson.name, dayTitle(lesson.date) - ]), - notificationDetails); + ], + ), + notificationDetails, + ); break; } case "hu_hu": { await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_canceled".i18n.fill([ + lesson.id.hashCode, + "title_lesson".i18n, + "body_lesson_canceled".i18n.fill( + [ userProvider.displayName!, dayTitle(lesson.date), lesson.lessonIndex, lesson.name - ]), - notificationDetails); + ], + ), + notificationDetails, + ); break; } default: { await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_canceled".i18n.fill([ + lesson.id.hashCode, + "title_lesson".i18n, + "body_lesson_canceled".i18n.fill( + [ userProvider.displayName!, lesson.lessonIndex, lesson.name, dayTitle(lesson.date) - ]), - notificationDetails); + ], + ), + notificationDetails, + ); break; } } @@ -456,9 +524,10 @@ class NotificationsHelper { case "en_en": { await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_substituted".i18n.fill([ + lesson.id.hashCode, + "title_lesson".i18n, + "body_lesson_substituted".i18n.fill( + [ userProvider.displayName!, lesson.lessonIndex, lesson.name, @@ -466,16 +535,19 @@ class NotificationsHelper { lesson.substituteTeacher!.isRenamed ? lesson.substituteTeacher!.renamedTo! : lesson.substituteTeacher!.name - ]), - notificationDetails); + ], + ), + notificationDetails, + ); break; } case "hu_hu": { await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_substituted".i18n.fill([ + lesson.id.hashCode, + "title_lesson".i18n, + "body_lesson_substituted".i18n.fill( + [ userProvider.displayName!, dayTitle(lesson.date), lesson.lessonIndex, @@ -483,16 +555,19 @@ class NotificationsHelper { lesson.substituteTeacher!.isRenamed ? lesson.substituteTeacher!.renamedTo! : lesson.substituteTeacher!.name - ]), - notificationDetails); + ], + ), + notificationDetails, + ); break; } default: { await flutterLocalNotificationsPlugin.show( - lesson.id.hashCode, - "title_lesson".i18n, - "body_lesson_substituted".i18n.fill([ + lesson.id.hashCode, + "title_lesson".i18n, + "body_lesson_substituted".i18n.fill( + [ userProvider.displayName!, lesson.lessonIndex, lesson.name, @@ -500,8 +575,10 @@ class NotificationsHelper { lesson.substituteTeacher!.isRenamed ? lesson.substituteTeacher!.renamedTo! : lesson.substituteTeacher!.name - ]), - notificationDetails); + ], + ), + notificationDetails, + ); break; } } @@ -521,4 +598,4 @@ class NotificationsHelper { .storeLessons(timetableLessons, userId: userProvider.id!); } } -} \ No newline at end of file +} diff --git a/filcnaplo_mobile_ui/lib/screens/settings/notifications_screen.dart b/filcnaplo_mobile_ui/lib/screens/settings/notifications_screen.dart index c8a2f49..5c60a9d 100644 --- a/filcnaplo_mobile_ui/lib/screens/settings/notifications_screen.dart +++ b/filcnaplo_mobile_ui/lib/screens/settings/notifications_screen.dart @@ -1,7 +1,6 @@ import 'package:filcnaplo/models/settings.dart'; import 'package:filcnaplo/theme/colors/colors.dart'; -import 'package:filcnaplo/ui/widgets/grade/grade_tile.dart'; -import 'package:filcnaplo_kreta_api/models/grade.dart'; +import 'package:filcnaplo_mobile_ui/common/beta_chip.dart'; import 'package:filcnaplo_mobile_ui/common/panel/panel.dart'; import 'package:filcnaplo_mobile_ui/common/panel/panel_button.dart'; import 'package:flutter/cupertino.dart'; @@ -21,15 +20,23 @@ class MenuNotifications extends StatelessWidget { padding: const EdgeInsets.only(left: 14.0), onPressed: () { Navigator.of(context, rootNavigator: true).push( - CupertinoPageRoute(builder: (context) => NotificationsScreen()), + CupertinoPageRoute(builder: (context) => const NotificationsScreen()), ); }, - title: Text( - "notifications_screen".i18n, - style: TextStyle( - color: AppColors.of(context) - .text - .withOpacity(settings.notificationsEnabled ? 1.0 : .5)), + title: Row( + children: [ + Text( + "notifications_screen".i18n, + style: TextStyle( + color: AppColors.of(context) + .text + .withOpacity(settings.notificationsEnabled ? 1.0 : .5)), + ), + const SizedBox(width: 5.0), + BetaChip( + disabled: !settings.notificationsEnabled, + ), + ], ), leading: settings.notificationsEnabled ? const Icon(FeatherIcons.messageSquare) @@ -48,128 +55,172 @@ class MenuNotifications extends StatelessWidget { } class NotificationsScreen extends StatelessWidget { - NotificationsScreen({super.key}); - late SettingsProvider settings; + const NotificationsScreen({super.key}); @override Widget build(BuildContext context) { - settings = Provider.of(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), + 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: Panel( + child: Column( + children: [ + Material( + type: MaterialType.transparency, + child: SwitchListTile( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12.0)), + value: settings.notificationsGradesEnabled, + onChanged: (v) => + settings.update(notificationsGradesEnabled: v), + title: Row( + children: [ + Icon( + FeatherIcons.bookmark, + color: settings.notificationsGradesEnabled + ? Theme.of(context).colorScheme.secondary + : AppColors.of(context).text.withOpacity(.25), + ), + const SizedBox(width: 14.0), + Expanded( + child: Text( + "grades".i18n, + style: TextStyle( + fontWeight: FontWeight.w600, + fontSize: 16.0, + color: AppColors.of(context).text.withOpacity( + settings.notificationsGradesEnabled + ? 1.0 + : .5, + ), + ), + ), + ), + ], + ), + ), + ), + Material( + type: MaterialType.transparency, + child: SwitchListTile( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12.0)), + value: settings.notificationsAbsencesEnabled, + onChanged: (v) => + settings.update(notificationsAbsencesEnabled: v), + title: Row( + children: [ + Icon( + FeatherIcons.clock, + color: settings.notificationsAbsencesEnabled + ? Theme.of(context).colorScheme.secondary + : AppColors.of(context).text.withOpacity(.25), + ), + const SizedBox(width: 14.0), + Expanded( + child: Text( + "absences".i18n, + style: TextStyle( + fontWeight: FontWeight.w600, + fontSize: 16.0, + color: AppColors.of(context).text.withOpacity( + settings.notificationsAbsencesEnabled + ? 1.0 + : .5, + ), + ), + ), + ), + ], + ), + ), + ), + Material( + type: MaterialType.transparency, + child: SwitchListTile( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12.0)), + value: settings.notificationsMessagesEnabled, + onChanged: (v) => + settings.update(notificationsMessagesEnabled: v), + title: Row( + children: [ + Icon( + FeatherIcons.messageSquare, + color: settings.notificationsMessagesEnabled + ? Theme.of(context).colorScheme.secondary + : AppColors.of(context).text.withOpacity(.25), + ), + const SizedBox(width: 14.0), + Expanded( + child: Text( + "messages".i18n, + style: TextStyle( + fontWeight: FontWeight.w600, + fontSize: 16.0, + color: AppColors.of(context).text.withOpacity( + settings.notificationsMessagesEnabled + ? 1.0 + : .5, + ), + ), + ), + ), + ], + ), + ), + ), + Material( + type: MaterialType.transparency, + child: SwitchListTile( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12.0)), + value: settings.notificationsLessonsEnabled, + onChanged: (v) => + settings.update(notificationsLessonsEnabled: v), + title: Row( + children: [ + Icon( + FeatherIcons.calendar, + color: settings.notificationsLessonsEnabled + ? Theme.of(context).colorScheme.secondary + : AppColors.of(context).text.withOpacity(.25), + ), + const SizedBox(width: 14.0), + Expanded( + child: Text( + "lessons".i18n, + style: TextStyle( + fontWeight: FontWeight.w600, + fontSize: 16.0, + color: AppColors.of(context).text.withOpacity( + settings.notificationsLessonsEnabled + ? 1.0 + : .5, + ), + ), + ), + ), + ], + ), + ), + ), + ], + ), ), ), - body: Padding( - padding: - const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0), - child: SingleChildScrollView( - child: Panel( - child: Column(children: [ - SwitchListTile( - value: settings.notificationsGradesEnabled, - onChanged: (v) => {settings.update(notificationsGradesEnabled: v)}, - title: Row( - children: [ - GradeValueWidget(GradeValue(5, "", "", 100), fill: true, size: 30, color: settings.gradeColors[4].withOpacity( - settings.notificationsGradesEnabled ? 1.0 : .5)), - const SizedBox(width: 14.0), - Expanded( - child: Text( - "grades".i18n, - style: TextStyle( - fontWeight: FontWeight.w600, - fontSize: 16.0, - color: AppColors.of(context).text.withOpacity( - settings.notificationsGradesEnabled ? 1.0 : .5), - ), - ), - ), - ], - ), - ), - SwitchListTile( - value: settings.notificationsAbsencesEnabled, - onChanged: (v) => {settings.update(notificationsAbsencesEnabled: v)}, - title: Row( - children: [ - const SizedBox(width: 8), - settings.notificationsAbsencesEnabled - ? const Icon(FeatherIcons.clock) - : Icon(FeatherIcons.clock, - color: - AppColors.of(context).text.withOpacity(.25)), - const SizedBox(width: 23.0), - Expanded( - child: Text( - "absences".i18n, - style: TextStyle( - fontWeight: FontWeight.w600, - fontSize: 16.0, - color: AppColors.of(context).text.withOpacity( - settings.notificationsAbsencesEnabled ? 1.0 : .5), - ), - ), - ), - ], - ), - ), - SwitchListTile( - value: settings.notificationsMessagesEnabled, - onChanged: (v) => {settings.update(notificationsMessagesEnabled: v)}, - title: Row( - children: [ - const SizedBox(width: 8), - settings.notificationsMessagesEnabled - ? const Icon(FeatherIcons.messageSquare) - : Icon(FeatherIcons.messageSquare, - color: - AppColors.of(context).text.withOpacity(.25)), - const SizedBox(width: 23.0), - Expanded( - child: Text( - "messages".i18n, - style: TextStyle( - fontWeight: FontWeight.w600, - fontSize: 16.0, - color: AppColors.of(context).text.withOpacity( - settings.notificationsMessagesEnabled ? 1.0 : .5), - ), - ), - ), - ], - ), - ), - SwitchListTile( - value: settings.notificationsLessonsEnabled, - onChanged: (v) => {settings.update(notificationsLessonsEnabled: v)}, - title: Row( - children: [ - const SizedBox(width: 8), - settings.notificationsLessonsEnabled - ? const Icon(FeatherIcons.calendar) - : Icon(FeatherIcons.calendar, - color: - AppColors.of(context).text.withOpacity(.25)), - const SizedBox(width: 23.0), - Expanded( - child: Text( - "lessons".i18n, - style: TextStyle( - fontWeight: FontWeight.w600, - fontSize: 16.0, - color: AppColors.of(context).text.withOpacity( - settings.notificationsLessonsEnabled ? 1.0 : .5), - ), - ), - ), - ], - ), - ) - ]), - )))); + ), + ); } } diff --git a/filcnaplo_mobile_ui/lib/screens/settings/settings_screen.dart b/filcnaplo_mobile_ui/lib/screens/settings/settings_screen.dart index d0f7774..6a6339c 100755 --- a/filcnaplo_mobile_ui/lib/screens/settings/settings_screen.dart +++ b/filcnaplo_mobile_ui/lib/screens/settings/settings_screen.dart @@ -15,7 +15,6 @@ import 'package:filcnaplo/models/user.dart'; import 'package:filcnaplo/theme/colors/colors.dart'; import 'package:filcnaplo_kreta_api/client/client.dart'; import 'package:filcnaplo_mobile_ui/common/action_button.dart'; -import 'package:filcnaplo_mobile_ui/common/beta_chip.dart'; import 'package:filcnaplo_mobile_ui/common/bottom_sheet_menu/bottom_sheet_menu.dart'; import 'package:filcnaplo_mobile_ui/common/bottom_sheet_menu/bottom_sheet_menu_item.dart'; import 'package:filcnaplo_mobile_ui/common/panel/panel.dart'; @@ -453,9 +452,8 @@ class _SettingsScreenState extends State ), ), Material( - type: MaterialType.transparency, - child: MenuNotifications(settings: settings) - ), + type: MaterialType.transparency, + child: MenuNotifications(settings: settings)), ], ), ), @@ -681,7 +679,7 @@ class _SettingsScreenState extends State const PremiumIconPackSelector(), // If iOS, show the iOS specific settings - if (defaultTargetPlatform == TargetPlatform.iOS) + if (defaultTargetPlatform == TargetPlatform.iOS) PanelButton( onPressed: () { SettingsHelper.liveActivityColor(context); @@ -708,7 +706,7 @@ class _SettingsScreenState extends State padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 24.0), child: Panel( - title: Text("notifications".i18n), + title: Text("popups".i18n), child: Material( type: MaterialType.transparency, child: SwitchListTile( diff --git a/filcnaplo_mobile_ui/lib/screens/settings/settings_screen.i18n.dart b/filcnaplo_mobile_ui/lib/screens/settings/settings_screen.i18n.dart index 3a63ac7..3ff52aa 100755 --- a/filcnaplo_mobile_ui/lib/screens/settings/settings_screen.i18n.dart +++ b/filcnaplo_mobile_ui/lib/screens/settings/settings_screen.i18n.dart @@ -27,6 +27,7 @@ extension SettingsLocalization on String { "grade_colors": "Grade Colors", "live_activity_color": "Live Activity Color", "notifications": "Notifications", + "popups": "Pop-up Alerts", "news": "News", "extras": "Extras", "about": "About", @@ -97,6 +98,7 @@ extension SettingsLocalization on String { "grade_colors": "Jegyek színei", "live_activity_color": "Live Activity színe", "notifications": "Értesítések", + "popups": "Pop-up értesítések", "news": "Hírek", "extras": "Extrák", "about": "Névjegy", @@ -167,6 +169,7 @@ extension SettingsLocalization on String { "grade_colors": "Grad Farben", "live_activity_color": "Live Activity Farben", "notifications": "Mitteilung", + "popups": "Popup-Nachrichten", "news": "Nachrichten", "extras": "Extras", "about": "Informationen", diff --git a/filcnaplo_mobile_ui/lib/screens/summary/pages/allsum_page.dart b/filcnaplo_mobile_ui/lib/screens/summary/pages/allsum_page.dart index e5132c2..b14a215 100644 --- a/filcnaplo_mobile_ui/lib/screens/summary/pages/allsum_page.dart +++ b/filcnaplo_mobile_ui/lib/screens/summary/pages/allsum_page.dart @@ -172,7 +172,7 @@ class _AllSumBodyState extends State { ], ); - // TODO: az orakat es a hazikat szarul keri le, de majd meg lesz csinalva + // TO-DO: az orakat es a hazikat szarul keri le, de majd meg lesz csinalva if (firstSixTiles.length < 6) { firstSixTiles.add(w); } else if (lastSixTiles.length < 6) {