fixed notification minden is

This commit is contained in:
Kima 2023-08-30 01:22:41 +02:00
parent 91255182d2
commit c05b358b49
6 changed files with 499 additions and 366 deletions

View File

@ -20,7 +20,11 @@ const settingsDB = DatabaseStruct("settings", {
"grade_color4": int, "grade_color5": int, // grade colors "grade_color4": int, "grade_color5": int, // grade colors
"vibration_strength": int, "ab_weeks": int, "swap_ab_weeks": int, "vibration_strength": int, "ab_weeks": int, "swap_ab_weeks": int,
"notifications": int, "notifications_bitfield": 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, "x_filc_id": String, "graph_class_avg": int, "presentation_mode": int,
"bell_delay": int, "bell_delay_enabled": int, "bell_delay": int, "bell_delay_enabled": int,
"grade_opening_fun": int, "icon_pack": String, "premium_scopes": String, "grade_opening_fun": int, "icon_pack": String, "premium_scopes": String,

View File

@ -1,9 +1,6 @@
import 'dart:ui';
import 'package:filcnaplo/api/providers/database_provider.dart'; import 'package:filcnaplo/api/providers/database_provider.dart';
import 'package:filcnaplo/api/providers/status_provider.dart'; import 'package:filcnaplo/api/providers/status_provider.dart';
import 'package:filcnaplo/api/providers/user_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/models/settings.dart';
import 'package:filcnaplo/helpers/notification_helper.i18n.dart'; import 'package:filcnaplo/helpers/notification_helper.i18n.dart';
import 'package:filcnaplo_kreta_api/client/api.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/models/week.dart';
import 'package:filcnaplo_kreta_api/providers/grade_provider.dart'; import 'package:filcnaplo_kreta_api/providers/grade_provider.dart';
import 'package:filcnaplo_kreta_api/providers/timetable_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:i18n_extension/i18n_widget.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:filcnaplo_kreta_api/models/message.dart'; import 'package:filcnaplo_kreta_api/models/message.dart';
@ -24,10 +22,15 @@ class NotificationsHelper {
late SettingsProvider settingsProvider; late SettingsProvider settingsProvider;
late UserProvider userProvider; late UserProvider userProvider;
late KretaClient kretaClient; late KretaClient kretaClient;
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
List<T> combineLists<T, K>(List<T> list1, List<T> list2, K Function(T) keyExtractor,) { List<T> combineLists<T, K>(
Set<K> uniqueKeys = Set<K>(); List<T> list1,
List<T> list2,
K Function(T) keyExtractor,
) {
Set<K> uniqueKeys = <K>{};
List<T> combinedList = []; List<T> combinedList = [];
for (T item in list1) { for (T item in list1) {
@ -48,10 +51,10 @@ class NotificationsHelper {
return combinedList; return combinedList;
} }
String dayTitle(DateTime date) { String dayTitle(DateTime date) {
try { try {
return DateFormat("EEEE", I18n.locale.languageCode) return DateFormat("EEEE", I18n.locale.languageCode).format(date);
.format(date);
} catch (e) { } catch (e) {
return "Unknown"; return "Unknown";
} }
@ -60,13 +63,9 @@ class NotificationsHelper {
@pragma('vm:entry-point') @pragma('vm:entry-point')
void backgroundJob() async { void backgroundJob() async {
// initialize providers // initialize providers
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
database = DatabaseProvider(); database = DatabaseProvider();
var db = await initDB(database);
await database.init(); await database.init();
settingsProvider = settingsProvider = await database.query.getSettings(database);
await database.query.getSettings(database);
userProvider = await database.query.getUsers(settingsProvider); userProvider = await database.query.getUsers(settingsProvider);
if (userProvider.id != null && settingsProvider.notificationsEnabled) { if (userProvider.id != null && settingsProvider.notificationsEnabled) {
@ -100,41 +99,53 @@ class NotificationsHelper {
// if grade is not a normal grade (1-5), don't show it // if grade is not a normal grade (1-5), don't show it
if ([1, 2, 3, 4, 5].contains(grade.value.value)) { 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 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) { if (grade.seenDate.isAfter(lastSeenGrade) &&
grade.date.difference(DateTime.now()).inDays * -1 < 7) {
// send notificiation about new grade // send notificiation about new grade
const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails androidNotificationDetails =
AndroidNotificationDetails('GRADES', 'Jegyek', AndroidNotificationDetails(
'GRADES',
'Jegyek',
channelDescription: 'Értesítés jegyek beírásakor', channelDescription: 'Értesítés jegyek beírásakor',
importance: Importance.max, importance: Importance.max,
priority: Priority.max, priority: Priority.max,
color: const Color(0xFF3D7BF4), color: settingsProvider.customAccentColor,
ticker: 'Jegyek'); ticker: 'Jegyek',
const NotificationDetails notificationDetails = NotificationDetails(android: androidNotificationDetails); );
NotificationDetails notificationDetails =
NotificationDetails(android: androidNotificationDetails);
if (userProvider.getUsers().length == 1) { if (userProvider.getUsers().length == 1) {
await flutterLocalNotificationsPlugin.show( await flutterLocalNotificationsPlugin.show(
grade.id.hashCode, grade.id.hashCode,
"title_grade".i18n, "title_grade".i18n,
"body_grade".i18n.fill([ "body_grade".i18n.fill(
[
grade.value.value.toString(), grade.value.value.toString(),
grade.subject.isRenamed && grade.subject.isRenamed &&
settingsProvider.renamedSubjectsEnabled settingsProvider.renamedSubjectsEnabled
? grade.subject.renamedTo! ? grade.subject.renamedTo!
: grade.subject.name : grade.subject.name
]), ],
notificationDetails); ),
} else { // multiple users are added, also display student name notificationDetails,
);
} else {
// multiple users are added, also display student name
await flutterLocalNotificationsPlugin.show( await flutterLocalNotificationsPlugin.show(
grade.id.hashCode, grade.id.hashCode,
"title_grade".i18n, "title_grade".i18n,
"body_grade_multiuser".i18n.fill([ "body_grade_multiuser".i18n.fill(
[
userProvider.displayName!, userProvider.displayName!,
grade.value.value.toString(), grade.value.value.toString(),
grade.subject.isRenamed && grade.subject.isRenamed &&
settingsProvider.renamedSubjectsEnabled settingsProvider.renamedSubjectsEnabled
? grade.subject.renamedTo! ? grade.subject.renamedTo!
: grade.subject.name : grade.subject.name
]), ],
notificationDetails); ),
notificationDetails,
);
} }
} }
} }
@ -142,10 +153,13 @@ class NotificationsHelper {
// set grade seen status // set grade seen status
gradeProvider.seenAll(); gradeProvider.seenAll();
} }
void absenceNotification() async { void absenceNotification() async {
// get absences from api // get absences from api
List? absenceJson = await kretaClient.getAPI(KretaAPI.absences(userProvider.instituteCode ?? "")); List? absenceJson = await kretaClient
List<Absence> storedAbsences = await database.userQuery.getAbsences(userId: userProvider.id!); .getAPI(KretaAPI.absences(userProvider.instituteCode ?? ""));
List<Absence> storedAbsences =
await database.userQuery.getAbsences(userId: userProvider.id!);
if (absenceJson == null) { if (absenceJson == null) {
return; return;
} }
@ -166,39 +180,49 @@ class NotificationsHelper {
if (!absence.isSeen) { if (!absence.isSeen) {
absence.isSeen = true; absence.isSeen = true;
modifiedAbsences.add(absence); modifiedAbsences.add(absence);
const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails androidNotificationDetails =
AndroidNotificationDetails('ABSENCES', 'Hiányzások', AndroidNotificationDetails(
'ABSENCES',
'Hiányzások',
channelDescription: 'Értesítés hiányzások beírásakor', channelDescription: 'Értesítés hiányzások beírásakor',
importance: Importance.max, importance: Importance.max,
priority: Priority.max, priority: Priority.max,
color: const Color(0xFF3D7BF4), color: settingsProvider.customAccentColor,
ticker: 'Hiányzások'); ticker: 'Hiányzások',
const NotificationDetails notificationDetails = NotificationDetails(android: androidNotificationDetails); );
NotificationDetails notificationDetails =
NotificationDetails(android: androidNotificationDetails);
if (userProvider.getUsers().length == 1) { if (userProvider.getUsers().length == 1) {
await flutterLocalNotificationsPlugin.show( await flutterLocalNotificationsPlugin.show(
absence.id.hashCode, absence.id.hashCode,
"title_absence".i18n, "title_absence".i18n,
"body_absence".i18n.fill([ "body_absence".i18n.fill(
[
DateFormat("yyyy-MM-dd").format(absence.date), DateFormat("yyyy-MM-dd").format(absence.date),
absence.subject.isRenamed && absence.subject.isRenamed &&
settingsProvider.renamedSubjectsEnabled settingsProvider.renamedSubjectsEnabled
? absence.subject.renamedTo! ? absence.subject.renamedTo!
: absence.subject.name : absence.subject.name
]), ],
notificationDetails); ),
notificationDetails,
);
} else { } else {
await flutterLocalNotificationsPlugin.show( await flutterLocalNotificationsPlugin.show(
absence.id.hashCode, absence.id.hashCode,
"title_absence".i18n, "title_absence".i18n,
"body_absence_multiuser".i18n.fill([ "body_absence_multiuser".i18n.fill(
[
userProvider.displayName!, userProvider.displayName!,
DateFormat("yyyy-MM-dd").format(absence.date), DateFormat("yyyy-MM-dd").format(absence.date),
absence.subject.isRenamed && absence.subject.isRenamed &&
settingsProvider.renamedSubjectsEnabled settingsProvider.renamedSubjectsEnabled
? absence.subject.renamedTo! ? absence.subject.renamedTo!
: absence.subject.name : absence.subject.name
]), ],
notificationDetails); ),
notificationDetails,
);
} }
} }
} }
@ -209,13 +233,16 @@ class NotificationsHelper {
storedAbsences, storedAbsences,
(Absence absence) => absence.id, (Absence absence) => absence.id,
); );
await database.userStore.storeAbsences(combinedAbsences, userId: userProvider.id!); await database.userStore
.storeAbsences(combinedAbsences, userId: userProvider.id!);
} }
void messageNotification() async { void messageNotification() async {
// get messages from api // get messages from api
List? messageJson = await kretaClient.getAPI(KretaAPI.messages("beerkezett")); List? messageJson =
List<Message> storedmessages = await database.userQuery.getMessages(userId: userProvider.id!); await kretaClient.getAPI(KretaAPI.messages("beerkezett"));
List<Message> storedmessages =
await database.userQuery.getMessages(userId: userProvider.id!);
if (messageJson == null) { if (messageJson == null) {
return; return;
} }
@ -224,9 +251,13 @@ class NotificationsHelper {
List<Message> messages = []; List<Message> messages = [];
await Future.wait(List.generate(messageJson.length, (index) { await Future.wait(List.generate(messageJson.length, (index) {
return () async { return () async {
Map message = messageJson!.cast<Map>()[index]; Map message = messageJson.cast<Map>()[index];
Map? innerMessageJson = await kretaClient.getAPI(KretaAPI.message(message["azonosito"].toString())); Map? innerMessageJson = await kretaClient
if (innerMessageJson != null) messages.add(Message.fromJson(innerMessageJson, forceType: MessageType.inbox)); .getAPI(KretaAPI.message(message["azonosito"].toString()));
if (innerMessageJson != null) {
messages.add(
Message.fromJson(innerMessageJson, forceType: MessageType.inbox));
}
}(); }();
})); }));
@ -245,26 +276,32 @@ class NotificationsHelper {
if (!message.isSeen) { if (!message.isSeen) {
message.isSeen = true; message.isSeen = true;
modifiedmessages.add(message); modifiedmessages.add(message);
const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails androidNotificationDetails =
AndroidNotificationDetails('MESSAGES', 'Üzenetek', AndroidNotificationDetails(
'MESSAGES',
'Üzenetek',
channelDescription: 'Értesítés kapott üzenetekkor', channelDescription: 'Értesítés kapott üzenetekkor',
importance: Importance.max, importance: Importance.max,
priority: Priority.max, priority: Priority.max,
color: const Color(0xFF3D7BF4), color: settingsProvider.customAccentColor,
ticker: 'Üzenetek'); ticker: 'Üzenetek',
const NotificationDetails notificationDetails = NotificationDetails(android: androidNotificationDetails); );
NotificationDetails notificationDetails =
NotificationDetails(android: androidNotificationDetails);
if (userProvider.getUsers().length == 1) { if (userProvider.getUsers().length == 1) {
await flutterLocalNotificationsPlugin.show( await flutterLocalNotificationsPlugin.show(
message.id.hashCode, message.id.hashCode,
message.author, message.author,
message.content.replaceAll(RegExp(r'<[^>]*>'), ''), message.content.replaceAll(RegExp(r'<[^>]*>'), ''),
notificationDetails); notificationDetails,
);
} else { } else {
await flutterLocalNotificationsPlugin.show( await flutterLocalNotificationsPlugin.show(
message.id.hashCode, message.id.hashCode,
"(${userProvider.displayName!}) ${message.author}", "(${userProvider.displayName!}) ${message.author}",
message.content.replaceAll(RegExp(r'<[^>]*>'), ''), message.content.replaceAll(RegExp(r'<[^>]*>'), ''),
notificationDetails); notificationDetails,
);
} }
} }
} }
@ -275,7 +312,8 @@ class NotificationsHelper {
storedmessages, storedmessages,
(Message message) => message.id, (Message message) => message.id,
); );
await database.userStore.storeMessages(combinedmessages, userId: userProvider.id!); await database.userStore
.storeMessages(combinedmessages, userId: userProvider.id!);
} }
void lessonNotification() async { void lessonNotification() async {
@ -300,15 +338,18 @@ class NotificationsHelper {
if (!lesson.isSeen && lesson.isChanged) { if (!lesson.isSeen && lesson.isChanged) {
lesson.isSeen = true; lesson.isSeen = true;
modifiedlessons.add(lesson); modifiedlessons.add(lesson);
const AndroidNotificationDetails androidNotificationDetails = AndroidNotificationDetails androidNotificationDetails =
AndroidNotificationDetails('LESSONS', 'Órák', AndroidNotificationDetails(
'LESSONS',
'Órák',
channelDescription: channelDescription:
'Értesítés órák elmaradásáról, helyettesítésről', 'Értesítés órák elmaradásáról, helyettesítésről',
importance: Importance.max, importance: Importance.max,
priority: Priority.max, priority: Priority.max,
color: const Color(0xFF3D7BF4), color: settingsProvider.customAccentColor,
ticker: 'Órák'); ticker: 'Órák',
const NotificationDetails notificationDetails = );
NotificationDetails notificationDetails =
NotificationDetails(android: androidNotificationDetails); NotificationDetails(android: androidNotificationDetails);
if (userProvider.getUsers().length == 1) { if (userProvider.getUsers().length == 1) {
if (lesson.status?.name == "Elmaradt") { if (lesson.status?.name == "Elmaradt") {
@ -318,12 +359,15 @@ class NotificationsHelper {
await flutterLocalNotificationsPlugin.show( await flutterLocalNotificationsPlugin.show(
lesson.id.hashCode, lesson.id.hashCode,
"title_lesson".i18n, "title_lesson".i18n,
"body_lesson_canceled".i18n.fill([ "body_lesson_canceled".i18n.fill(
[
lesson.lessonIndex, lesson.lessonIndex,
lesson.name, lesson.name,
dayTitle(lesson.date) dayTitle(lesson.date)
]), ],
notificationDetails); ),
notificationDetails,
);
break; break;
} }
case "hu_hu": case "hu_hu":
@ -331,12 +375,15 @@ class NotificationsHelper {
await flutterLocalNotificationsPlugin.show( await flutterLocalNotificationsPlugin.show(
lesson.id.hashCode, lesson.id.hashCode,
"title_lesson".i18n, "title_lesson".i18n,
"body_lesson_canceled".i18n.fill([ "body_lesson_canceled".i18n.fill(
[
dayTitle(lesson.date), dayTitle(lesson.date),
lesson.lessonIndex, lesson.lessonIndex,
lesson.name lesson.name
]), ],
notificationDetails); ),
notificationDetails,
);
break; break;
} }
default: default:
@ -344,12 +391,15 @@ class NotificationsHelper {
await flutterLocalNotificationsPlugin.show( await flutterLocalNotificationsPlugin.show(
lesson.id.hashCode, lesson.id.hashCode,
"title_lesson".i18n, "title_lesson".i18n,
"body_lesson_canceled".i18n.fill([ "body_lesson_canceled".i18n.fill(
[
lesson.lessonIndex, lesson.lessonIndex,
lesson.name, lesson.name,
dayTitle(lesson.date) dayTitle(lesson.date)
]), ],
notificationDetails); ),
notificationDetails,
);
break; break;
} }
} }
@ -360,15 +410,18 @@ class NotificationsHelper {
await flutterLocalNotificationsPlugin.show( await flutterLocalNotificationsPlugin.show(
lesson.id.hashCode, lesson.id.hashCode,
"title_lesson".i18n, "title_lesson".i18n,
"body_lesson_substituted".i18n.fill([ "body_lesson_substituted".i18n.fill(
[
lesson.lessonIndex, lesson.lessonIndex,
lesson.name, lesson.name,
dayTitle(lesson.date), dayTitle(lesson.date),
lesson.substituteTeacher!.isRenamed lesson.substituteTeacher!.isRenamed
? lesson.substituteTeacher!.renamedTo! ? lesson.substituteTeacher!.renamedTo!
: lesson.substituteTeacher!.name : lesson.substituteTeacher!.name
]), ],
notificationDetails); ),
notificationDetails,
);
break; break;
} }
case "hu_hu": case "hu_hu":
@ -376,15 +429,18 @@ class NotificationsHelper {
await flutterLocalNotificationsPlugin.show( await flutterLocalNotificationsPlugin.show(
lesson.id.hashCode, lesson.id.hashCode,
"title_lesson".i18n, "title_lesson".i18n,
"body_lesson_substituted".i18n.fill([ "body_lesson_substituted".i18n.fill(
[
dayTitle(lesson.date), dayTitle(lesson.date),
lesson.lessonIndex, lesson.lessonIndex,
lesson.name, lesson.name,
lesson.substituteTeacher!.isRenamed lesson.substituteTeacher!.isRenamed
? lesson.substituteTeacher!.renamedTo! ? lesson.substituteTeacher!.renamedTo!
: lesson.substituteTeacher!.name : lesson.substituteTeacher!.name
]), ],
notificationDetails); ),
notificationDetails,
);
break; break;
} }
default: default:
@ -392,15 +448,18 @@ class NotificationsHelper {
await flutterLocalNotificationsPlugin.show( await flutterLocalNotificationsPlugin.show(
lesson.id.hashCode, lesson.id.hashCode,
"title_lesson".i18n, "title_lesson".i18n,
"body_lesson_substituted".i18n.fill([ "body_lesson_substituted".i18n.fill(
[
lesson.lessonIndex, lesson.lessonIndex,
lesson.name, lesson.name,
dayTitle(lesson.date), dayTitle(lesson.date),
lesson.substituteTeacher!.isRenamed lesson.substituteTeacher!.isRenamed
? lesson.substituteTeacher!.renamedTo! ? lesson.substituteTeacher!.renamedTo!
: lesson.substituteTeacher!.name : lesson.substituteTeacher!.name
]), ],
notificationDetails); ),
notificationDetails,
);
break; break;
} }
} }
@ -413,13 +472,16 @@ class NotificationsHelper {
await flutterLocalNotificationsPlugin.show( await flutterLocalNotificationsPlugin.show(
lesson.id.hashCode, lesson.id.hashCode,
"title_lesson".i18n, "title_lesson".i18n,
"body_lesson_canceled".i18n.fill([ "body_lesson_canceled".i18n.fill(
[
userProvider.displayName!, userProvider.displayName!,
lesson.lessonIndex, lesson.lessonIndex,
lesson.name, lesson.name,
dayTitle(lesson.date) dayTitle(lesson.date)
]), ],
notificationDetails); ),
notificationDetails,
);
break; break;
} }
case "hu_hu": case "hu_hu":
@ -427,13 +489,16 @@ class NotificationsHelper {
await flutterLocalNotificationsPlugin.show( await flutterLocalNotificationsPlugin.show(
lesson.id.hashCode, lesson.id.hashCode,
"title_lesson".i18n, "title_lesson".i18n,
"body_lesson_canceled".i18n.fill([ "body_lesson_canceled".i18n.fill(
[
userProvider.displayName!, userProvider.displayName!,
dayTitle(lesson.date), dayTitle(lesson.date),
lesson.lessonIndex, lesson.lessonIndex,
lesson.name lesson.name
]), ],
notificationDetails); ),
notificationDetails,
);
break; break;
} }
default: default:
@ -441,13 +506,16 @@ class NotificationsHelper {
await flutterLocalNotificationsPlugin.show( await flutterLocalNotificationsPlugin.show(
lesson.id.hashCode, lesson.id.hashCode,
"title_lesson".i18n, "title_lesson".i18n,
"body_lesson_canceled".i18n.fill([ "body_lesson_canceled".i18n.fill(
[
userProvider.displayName!, userProvider.displayName!,
lesson.lessonIndex, lesson.lessonIndex,
lesson.name, lesson.name,
dayTitle(lesson.date) dayTitle(lesson.date)
]), ],
notificationDetails); ),
notificationDetails,
);
break; break;
} }
} }
@ -458,7 +526,8 @@ class NotificationsHelper {
await flutterLocalNotificationsPlugin.show( await flutterLocalNotificationsPlugin.show(
lesson.id.hashCode, lesson.id.hashCode,
"title_lesson".i18n, "title_lesson".i18n,
"body_lesson_substituted".i18n.fill([ "body_lesson_substituted".i18n.fill(
[
userProvider.displayName!, userProvider.displayName!,
lesson.lessonIndex, lesson.lessonIndex,
lesson.name, lesson.name,
@ -466,8 +535,10 @@ class NotificationsHelper {
lesson.substituteTeacher!.isRenamed lesson.substituteTeacher!.isRenamed
? lesson.substituteTeacher!.renamedTo! ? lesson.substituteTeacher!.renamedTo!
: lesson.substituteTeacher!.name : lesson.substituteTeacher!.name
]), ],
notificationDetails); ),
notificationDetails,
);
break; break;
} }
case "hu_hu": case "hu_hu":
@ -475,7 +546,8 @@ class NotificationsHelper {
await flutterLocalNotificationsPlugin.show( await flutterLocalNotificationsPlugin.show(
lesson.id.hashCode, lesson.id.hashCode,
"title_lesson".i18n, "title_lesson".i18n,
"body_lesson_substituted".i18n.fill([ "body_lesson_substituted".i18n.fill(
[
userProvider.displayName!, userProvider.displayName!,
dayTitle(lesson.date), dayTitle(lesson.date),
lesson.lessonIndex, lesson.lessonIndex,
@ -483,8 +555,10 @@ class NotificationsHelper {
lesson.substituteTeacher!.isRenamed lesson.substituteTeacher!.isRenamed
? lesson.substituteTeacher!.renamedTo! ? lesson.substituteTeacher!.renamedTo!
: lesson.substituteTeacher!.name : lesson.substituteTeacher!.name
]), ],
notificationDetails); ),
notificationDetails,
);
break; break;
} }
default: default:
@ -492,7 +566,8 @@ class NotificationsHelper {
await flutterLocalNotificationsPlugin.show( await flutterLocalNotificationsPlugin.show(
lesson.id.hashCode, lesson.id.hashCode,
"title_lesson".i18n, "title_lesson".i18n,
"body_lesson_substituted".i18n.fill([ "body_lesson_substituted".i18n.fill(
[
userProvider.displayName!, userProvider.displayName!,
lesson.lessonIndex, lesson.lessonIndex,
lesson.name, lesson.name,
@ -500,8 +575,10 @@ class NotificationsHelper {
lesson.substituteTeacher!.isRenamed lesson.substituteTeacher!.isRenamed
? lesson.substituteTeacher!.renamedTo! ? lesson.substituteTeacher!.renamedTo!
: lesson.substituteTeacher!.name : lesson.substituteTeacher!.name
]), ],
notificationDetails); ),
notificationDetails,
);
break; break;
} }
} }

View File

@ -1,7 +1,6 @@
import 'package:filcnaplo/models/settings.dart'; import 'package:filcnaplo/models/settings.dart';
import 'package:filcnaplo/theme/colors/colors.dart'; import 'package:filcnaplo/theme/colors/colors.dart';
import 'package:filcnaplo/ui/widgets/grade/grade_tile.dart'; import 'package:filcnaplo_mobile_ui/common/beta_chip.dart';
import 'package:filcnaplo_kreta_api/models/grade.dart';
import 'package:filcnaplo_mobile_ui/common/panel/panel.dart'; import 'package:filcnaplo_mobile_ui/common/panel/panel.dart';
import 'package:filcnaplo_mobile_ui/common/panel/panel_button.dart'; import 'package:filcnaplo_mobile_ui/common/panel/panel_button.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
@ -21,16 +20,24 @@ class MenuNotifications extends StatelessWidget {
padding: const EdgeInsets.only(left: 14.0), padding: const EdgeInsets.only(left: 14.0),
onPressed: () { onPressed: () {
Navigator.of(context, rootNavigator: true).push( Navigator.of(context, rootNavigator: true).push(
CupertinoPageRoute(builder: (context) => NotificationsScreen()), CupertinoPageRoute(builder: (context) => const NotificationsScreen()),
); );
}, },
title: Text( title: Row(
children: [
Text(
"notifications_screen".i18n, "notifications_screen".i18n,
style: TextStyle( style: TextStyle(
color: AppColors.of(context) color: AppColors.of(context)
.text .text
.withOpacity(settings.notificationsEnabled ? 1.0 : .5)), .withOpacity(settings.notificationsEnabled ? 1.0 : .5)),
), ),
const SizedBox(width: 5.0),
BetaChip(
disabled: !settings.notificationsEnabled,
),
],
),
leading: settings.notificationsEnabled leading: settings.notificationsEnabled
? const Icon(FeatherIcons.messageSquare) ? const Icon(FeatherIcons.messageSquare)
: Icon(FeatherIcons.messageSquare, : Icon(FeatherIcons.messageSquare,
@ -48,12 +55,12 @@ class MenuNotifications extends StatelessWidget {
} }
class NotificationsScreen extends StatelessWidget { class NotificationsScreen extends StatelessWidget {
NotificationsScreen({super.key}); const NotificationsScreen({super.key});
late SettingsProvider settings;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
settings = Provider.of<SettingsProvider>(context); SettingsProvider settings = Provider.of<SettingsProvider>(context);
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
surfaceTintColor: Theme.of(context).scaffoldBackgroundColor, surfaceTintColor: Theme.of(context).scaffoldBackgroundColor,
@ -63,19 +70,28 @@ class NotificationsScreen extends StatelessWidget {
style: TextStyle(color: AppColors.of(context).text), style: TextStyle(color: AppColors.of(context).text),
), ),
), ),
body: Padding( body: SingleChildScrollView(
padding: child: Padding(
const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0), padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
child: SingleChildScrollView(
child: Panel( child: Panel(
child: Column(children: [ child: Column(
SwitchListTile( children: [
Material(
type: MaterialType.transparency,
child: SwitchListTile(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0)),
value: settings.notificationsGradesEnabled, value: settings.notificationsGradesEnabled,
onChanged: (v) => {settings.update(notificationsGradesEnabled: v)}, onChanged: (v) =>
settings.update(notificationsGradesEnabled: v),
title: Row( title: Row(
children: [ children: [
GradeValueWidget(GradeValue(5, "", "", 100), fill: true, size: 30, color: settings.gradeColors[4].withOpacity( Icon(
settings.notificationsGradesEnabled ? 1.0 : .5)), FeatherIcons.bookmark,
color: settings.notificationsGradesEnabled
? Theme.of(context).colorScheme.secondary
: AppColors.of(context).text.withOpacity(.25),
),
const SizedBox(width: 14.0), const SizedBox(width: 14.0),
Expanded( Expanded(
child: Text( child: Text(
@ -84,25 +100,34 @@ class NotificationsScreen extends StatelessWidget {
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
fontSize: 16.0, fontSize: 16.0,
color: AppColors.of(context).text.withOpacity( color: AppColors.of(context).text.withOpacity(
settings.notificationsGradesEnabled ? 1.0 : .5), settings.notificationsGradesEnabled
? 1.0
: .5,
),
), ),
), ),
), ),
], ],
), ),
), ),
SwitchListTile( ),
Material(
type: MaterialType.transparency,
child: SwitchListTile(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0)),
value: settings.notificationsAbsencesEnabled, value: settings.notificationsAbsencesEnabled,
onChanged: (v) => {settings.update(notificationsAbsencesEnabled: v)}, onChanged: (v) =>
settings.update(notificationsAbsencesEnabled: v),
title: Row( title: Row(
children: [ children: [
const SizedBox(width: 8), Icon(
settings.notificationsAbsencesEnabled FeatherIcons.clock,
? const Icon(FeatherIcons.clock) color: settings.notificationsAbsencesEnabled
: Icon(FeatherIcons.clock, ? Theme.of(context).colorScheme.secondary
color: : AppColors.of(context).text.withOpacity(.25),
AppColors.of(context).text.withOpacity(.25)), ),
const SizedBox(width: 23.0), const SizedBox(width: 14.0),
Expanded( Expanded(
child: Text( child: Text(
"absences".i18n, "absences".i18n,
@ -110,25 +135,34 @@ class NotificationsScreen extends StatelessWidget {
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
fontSize: 16.0, fontSize: 16.0,
color: AppColors.of(context).text.withOpacity( color: AppColors.of(context).text.withOpacity(
settings.notificationsAbsencesEnabled ? 1.0 : .5), settings.notificationsAbsencesEnabled
? 1.0
: .5,
),
), ),
), ),
), ),
], ],
), ),
), ),
SwitchListTile( ),
Material(
type: MaterialType.transparency,
child: SwitchListTile(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0)),
value: settings.notificationsMessagesEnabled, value: settings.notificationsMessagesEnabled,
onChanged: (v) => {settings.update(notificationsMessagesEnabled: v)}, onChanged: (v) =>
settings.update(notificationsMessagesEnabled: v),
title: Row( title: Row(
children: [ children: [
const SizedBox(width: 8), Icon(
settings.notificationsMessagesEnabled FeatherIcons.messageSquare,
? const Icon(FeatherIcons.messageSquare) color: settings.notificationsMessagesEnabled
: Icon(FeatherIcons.messageSquare, ? Theme.of(context).colorScheme.secondary
color: : AppColors.of(context).text.withOpacity(.25),
AppColors.of(context).text.withOpacity(.25)), ),
const SizedBox(width: 23.0), const SizedBox(width: 14.0),
Expanded( Expanded(
child: Text( child: Text(
"messages".i18n, "messages".i18n,
@ -136,25 +170,34 @@ class NotificationsScreen extends StatelessWidget {
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
fontSize: 16.0, fontSize: 16.0,
color: AppColors.of(context).text.withOpacity( color: AppColors.of(context).text.withOpacity(
settings.notificationsMessagesEnabled ? 1.0 : .5), settings.notificationsMessagesEnabled
? 1.0
: .5,
),
), ),
), ),
), ),
], ],
), ),
), ),
SwitchListTile( ),
Material(
type: MaterialType.transparency,
child: SwitchListTile(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0)),
value: settings.notificationsLessonsEnabled, value: settings.notificationsLessonsEnabled,
onChanged: (v) => {settings.update(notificationsLessonsEnabled: v)}, onChanged: (v) =>
settings.update(notificationsLessonsEnabled: v),
title: Row( title: Row(
children: [ children: [
const SizedBox(width: 8), Icon(
settings.notificationsLessonsEnabled FeatherIcons.calendar,
? const Icon(FeatherIcons.calendar) color: settings.notificationsLessonsEnabled
: Icon(FeatherIcons.calendar, ? Theme.of(context).colorScheme.secondary
color: : AppColors.of(context).text.withOpacity(.25),
AppColors.of(context).text.withOpacity(.25)), ),
const SizedBox(width: 23.0), const SizedBox(width: 14.0),
Expanded( Expanded(
child: Text( child: Text(
"lessons".i18n, "lessons".i18n,
@ -162,14 +205,22 @@ class NotificationsScreen extends StatelessWidget {
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
fontSize: 16.0, fontSize: 16.0,
color: AppColors.of(context).text.withOpacity( color: AppColors.of(context).text.withOpacity(
settings.notificationsLessonsEnabled ? 1.0 : .5), settings.notificationsLessonsEnabled
? 1.0
: .5,
),
), ),
), ),
), ),
], ],
), ),
) ),
]), ),
)))); ],
),
),
),
),
);
} }
} }

View File

@ -15,7 +15,6 @@ import 'package:filcnaplo/models/user.dart';
import 'package:filcnaplo/theme/colors/colors.dart'; import 'package:filcnaplo/theme/colors/colors.dart';
import 'package:filcnaplo_kreta_api/client/client.dart'; import 'package:filcnaplo_kreta_api/client/client.dart';
import 'package:filcnaplo_mobile_ui/common/action_button.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.dart';
import 'package:filcnaplo_mobile_ui/common/bottom_sheet_menu/bottom_sheet_menu_item.dart'; import 'package:filcnaplo_mobile_ui/common/bottom_sheet_menu/bottom_sheet_menu_item.dart';
import 'package:filcnaplo_mobile_ui/common/panel/panel.dart'; import 'package:filcnaplo_mobile_ui/common/panel/panel.dart';
@ -454,8 +453,7 @@ class _SettingsScreenState extends State<SettingsScreen>
), ),
Material( Material(
type: MaterialType.transparency, type: MaterialType.transparency,
child: MenuNotifications(settings: settings) child: MenuNotifications(settings: settings)),
),
], ],
), ),
), ),
@ -708,7 +706,7 @@ class _SettingsScreenState extends State<SettingsScreen>
padding: padding:
const EdgeInsets.symmetric(vertical: 12.0, horizontal: 24.0), const EdgeInsets.symmetric(vertical: 12.0, horizontal: 24.0),
child: Panel( child: Panel(
title: Text("notifications".i18n), title: Text("popups".i18n),
child: Material( child: Material(
type: MaterialType.transparency, type: MaterialType.transparency,
child: SwitchListTile( child: SwitchListTile(

View File

@ -27,6 +27,7 @@ extension SettingsLocalization on String {
"grade_colors": "Grade Colors", "grade_colors": "Grade Colors",
"live_activity_color": "Live Activity Color", "live_activity_color": "Live Activity Color",
"notifications": "Notifications", "notifications": "Notifications",
"popups": "Pop-up Alerts",
"news": "News", "news": "News",
"extras": "Extras", "extras": "Extras",
"about": "About", "about": "About",
@ -97,6 +98,7 @@ extension SettingsLocalization on String {
"grade_colors": "Jegyek színei", "grade_colors": "Jegyek színei",
"live_activity_color": "Live Activity színe", "live_activity_color": "Live Activity színe",
"notifications": "Értesítések", "notifications": "Értesítések",
"popups": "Pop-up értesítések",
"news": "Hírek", "news": "Hírek",
"extras": "Extrák", "extras": "Extrák",
"about": "Névjegy", "about": "Névjegy",
@ -167,6 +169,7 @@ extension SettingsLocalization on String {
"grade_colors": "Grad Farben", "grade_colors": "Grad Farben",
"live_activity_color": "Live Activity Farben", "live_activity_color": "Live Activity Farben",
"notifications": "Mitteilung", "notifications": "Mitteilung",
"popups": "Popup-Nachrichten",
"news": "Nachrichten", "news": "Nachrichten",
"extras": "Extras", "extras": "Extras",
"about": "Informationen", "about": "Informationen",

View File

@ -172,7 +172,7 @@ class _AllSumBodyState extends State<AllSumBody> {
], ],
); );
// 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) { if (firstSixTiles.length < 6) {
firstSixTiles.add(w); firstSixTiles.add(w);
} else if (lastSixTiles.length < 6) { } else if (lastSixTiles.length < 6) {