From 1cdde3b6ce98e057193422f5ffbb9f83ff19bd5f Mon Sep 17 00:00:00 2001 From: hihihaha Date: Sat, 10 Jun 2023 19:50:32 +0200 Subject: [PATCH 1/9] add notification --- .idea/naplo.iml | 60 ++++++++++++- .../src/main/res/drawable/ic_notification.png | Bin 0 -> 12868 bytes .../lib/helpers/notification_helper.dart | 59 +++++++++++++ .../lib/helpers/notification_helper.i18n.dart | 24 ++++++ filcnaplo/lib/main.dart | 79 ++++++++++++++++++ .../flutter/generated_plugin_registrant.cc | 4 - .../linux/flutter/generated_plugins.cmake | 1 - .../Flutter/GeneratedPluginRegistrant.swift | 2 - 8 files changed, 221 insertions(+), 8 deletions(-) create mode 100644 filcnaplo/android/app/src/main/res/drawable/ic_notification.png create mode 100644 filcnaplo/lib/helpers/notification_helper.dart create mode 100644 filcnaplo/lib/helpers/notification_helper.i18n.dart diff --git a/.idea/naplo.iml b/.idea/naplo.iml index d6ebd480..ab2f4821 100644 --- a/.idea/naplo.iml +++ b/.idea/naplo.iml @@ -2,7 +2,65 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/filcnaplo/android/app/src/main/res/drawable/ic_notification.png b/filcnaplo/android/app/src/main/res/drawable/ic_notification.png new file mode 100644 index 0000000000000000000000000000000000000000..67fd37099efd5865fb8e1d9efb98e553081bc02d GIT binary patch literal 12868 zcmeAS@N?(olHy`uVBq!ia0y~yVB7%09Bd2>3@7{yv=|r|E~G|yrg?g5F>o+2FmN$2 zFtRW(GB7Y~U}RumL}D{BGBYqUFfg<+Ffa%)GK1BC)JZY2g4sO`3=Gmx_7nyN1`Vhh zCI$uuLq;YBUIqq+ISdR8MvP1hA`A=+s~8vQAiqGkxVo#j=Er)^g|0p9$NyH8zc2jG_rYAt$8@() z!>UL(wW%USKSdRPbjh_CG-w=CNqe<<(Tuj|KX$eEuP-m0_q6ui`HRa%eAs@lJYu=b z+g&lYqU!P`%lE?W5s^V1=R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u_%x3*egE8C?sotNt2T(=^m zw#@&v|B+BRgNZ@UjhXBJq)(Nroq0<4v zBDQOLcf42@esAg1tNX4^zkR7S!utBA=#w9|Dl>3wFf>nV7d#t(vSR*ZA0_JwX>SPz zMzeE_*DC(WX4w|Fr~N---w)224LNEJ*~U=T>q zGco+UqUU?{q`iS=m9nR~88|kG+`8ek;M1EW+xC5*mi{;Y{N68mu@?8IU1PJp-?_Bn zIk(KwsZ9(H4R3!3|6kQ(sWCgIzVv_T``?qoQcArxaZjq{J grades = + await database.userQuery.getGrades(userId: userProvider.id ?? ""); + DateTime lastSeenGrade = + await database.userQuery.lastSeenGrade(userId: userProvider.id ?? ""); + for (Grade grade in grades) { + if (grade.seenDate.isAfter(lastSeenGrade)) { + 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: 'ticker'); + const NotificationDetails notificationDetails = + NotificationDetails(android: androidNotificationDetails); + await flutterLocalNotificationsPlugin.show( + Random().nextInt(432234*2), "title".i18n, "body".i18n.fill([grade.value.value.toString(), grade.subject.name.toString()]), notificationDetails); + + } + } + } +} diff --git a/filcnaplo/lib/helpers/notification_helper.i18n.dart b/filcnaplo/lib/helpers/notification_helper.i18n.dart new file mode 100644 index 00000000..5c964882 --- /dev/null +++ b/filcnaplo/lib/helpers/notification_helper.i18n.dart @@ -0,0 +1,24 @@ +import 'package:i18n_extension/i18n_extension.dart'; + +extension Localization on String { + static final _t = Translations.byLocale("hu_hu") + + { + "en_en": { + "title": "New grade", + "body": "You got a %s in %s" + }, + "hu_hu": { + "title": "Új jegy", + "body": "%s-st kaptál %s tantárgyból" + }, + "de_de": { + "title": "Neue Note", + "body": "Du hast eine %s in %s" + }, + }; + + String get i18n => localize(this, _t); + String fill(List params) => localizeFill(this, params); + String plural(int value) => localizePlural(value, this, _t); + String version(Object modifier) => localizeVersion(modifier, this, _t); +} diff --git a/filcnaplo/lib/main.dart b/filcnaplo/lib/main.dart index 70323131..bd87738a 100644 --- a/filcnaplo/lib/main.dart +++ b/filcnaplo/lib/main.dart @@ -2,13 +2,16 @@ import 'package:background_fetch/background_fetch.dart'; import 'package:filcnaplo/api/providers/user_provider.dart'; import 'package:filcnaplo/api/providers/database_provider.dart'; import 'package:filcnaplo/database/init.dart'; +import 'package:filcnaplo/helpers/notification_helper.dart'; import 'package:filcnaplo/models/settings.dart'; +import 'package:filcnaplo_kreta_api/client/client.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:filcnaplo/app.dart'; import 'package:flutter/services.dart'; import 'package:filcnaplo_mobile_ui/screens/error_screen.dart'; import 'package:filcnaplo_mobile_ui/screens/error_report_screen.dart'; +import 'package:flutter_local_notifications/flutter_local_notifications.dart'; void main() async { // Initalize @@ -43,6 +46,53 @@ class Startup { await database.init(); settings = await database.query.getSettings(database); user = await database.query.getUsers(settings); + + // Notifications setup + initPlatformState(); + FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = + FlutterLocalNotificationsPlugin(); + + // Get permission to show notifications + flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + AndroidFlutterLocalNotificationsPlugin>()! + .requestPermission(); + await flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + IOSFlutterLocalNotificationsPlugin>() + ?.requestPermissions( + alert: false, + badge: true, + sound: true, + ); + await flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + MacOSFlutterLocalNotificationsPlugin>() + ?.requestPermissions( + alert: false, + badge: true, + sound: true, + ); + + // Platform specific settings + final DarwinInitializationSettings initializationSettingsDarwin = + DarwinInitializationSettings( + requestSoundPermission: true, + requestBadgePermission: true, + requestAlertPermission: false, + ); + const AndroidInitializationSettings initializationSettingsAndroid = + AndroidInitializationSettings('ic_notification'); + final InitializationSettings initializationSettings = InitializationSettings( + android: initializationSettingsAndroid, + iOS: initializationSettingsDarwin, + macOS: initializationSettingsDarwin + ); + + // Initialize notifications + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + ); } } @@ -71,9 +121,38 @@ Widget errorBuilder(FlutterErrorDetails details) { return Container(); }); } +// Platform messages are asynchronous, so we initialize in an async method. + Future initPlatformState() async { + // Configure BackgroundFetch. + int status = await BackgroundFetch.configure(BackgroundFetchConfig( + minimumFetchInterval: 15, + stopOnTerminate: false, + enableHeadless: true, + requiresBatteryNotLow: false, + requiresCharging: false, + requiresStorageNotLow: false, + requiresDeviceIdle: false, + requiredNetworkType: NetworkType.ANY + ), (String taskId) async { // <-- Event handler + // This is the fetch-event callback. + print("[BackgroundFetch] Event received $taskId"); + NotificationsHelper().backgroundJob(); + + // IMPORTANT: You must signal completion of your task or the OS can punish your app + // for taking too long in the background. + BackgroundFetch.finish(taskId); + }, (String taskId) async { // <-- Task timeout handler. + // This task has exceeded its allowed running-time. You must stop what you're doing and immediately .finish(taskId) + print("[BackgroundFetch] TASK TIMEOUT taskId: $taskId"); + BackgroundFetch.finish(taskId); + }); + print('[BackgroundFetch] configure success: $status'); + + } @pragma('vm:entry-point') void backgroundHeadlessTask(HeadlessTask task) { print('[BackgroundFetch] Headless event received.'); + NotificationsHelper().backgroundJob(); BackgroundFetch.finish(task.taskId); } diff --git a/filcnaplo/linux/flutter/generated_plugin_registrant.cc b/filcnaplo/linux/flutter/generated_plugin_registrant.cc index 0fcfb275..4894d346 100644 --- a/filcnaplo/linux/flutter/generated_plugin_registrant.cc +++ b/filcnaplo/linux/flutter/generated_plugin_registrant.cc @@ -7,7 +7,6 @@ #include "generated_plugin_registrant.h" #include -#include #include #include @@ -15,9 +14,6 @@ void fl_register_plugins(FlPluginRegistry* registry) { g_autoptr(FlPluginRegistrar) dynamic_color_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "DynamicColorPlugin"); dynamic_color_plugin_register_with_registrar(dynamic_color_registrar); - g_autoptr(FlPluginRegistrar) file_selector_linux_registrar = - fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin"); - file_selector_plugin_register_with_registrar(file_selector_linux_registrar); g_autoptr(FlPluginRegistrar) flutter_acrylic_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterAcrylicPlugin"); flutter_acrylic_plugin_register_with_registrar(flutter_acrylic_registrar); diff --git a/filcnaplo/linux/flutter/generated_plugins.cmake b/filcnaplo/linux/flutter/generated_plugins.cmake index c5541e6e..c8808fea 100644 --- a/filcnaplo/linux/flutter/generated_plugins.cmake +++ b/filcnaplo/linux/flutter/generated_plugins.cmake @@ -4,7 +4,6 @@ list(APPEND FLUTTER_PLUGIN_LIST dynamic_color - file_selector_linux flutter_acrylic url_launcher_linux ) diff --git a/filcnaplo/macos/Flutter/GeneratedPluginRegistrant.swift b/filcnaplo/macos/Flutter/GeneratedPluginRegistrant.swift index 53df988b..c6b190d7 100644 --- a/filcnaplo/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/filcnaplo/macos/Flutter/GeneratedPluginRegistrant.swift @@ -7,7 +7,6 @@ import Foundation import connectivity_plus import dynamic_color -import file_selector_macos import flutter_local_notifications import macos_window_utils import package_info_plus @@ -19,7 +18,6 @@ import url_launcher_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin")) DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin")) - FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin")) MacOSWindowUtilsPlugin.register(with: registry.registrar(forPlugin: "MacOSWindowUtilsPlugin")) FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin")) From 3eee2c7a55f23b756e53eb3c7067d813dd2de4d8 Mon Sep 17 00:00:00 2001 From: hihihaha Date: Sat, 10 Jun 2023 19:55:40 +0200 Subject: [PATCH 2/9] set grade as seen --- filcnaplo/lib/helpers/notification_helper.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/filcnaplo/lib/helpers/notification_helper.dart b/filcnaplo/lib/helpers/notification_helper.dart index a281b17a..2464fd2b 100644 --- a/filcnaplo/lib/helpers/notification_helper.dart +++ b/filcnaplo/lib/helpers/notification_helper.dart @@ -25,6 +25,7 @@ class NotificationsHelper { SettingsProvider settingsProvider = await database.query.getSettings(database); UserProvider userProvider = await database.query.getUsers(settingsProvider); + if(userProvider.id != null) { final status = StatusProvider(); final kretaClient = KretaClient( user: userProvider, settings: settingsProvider, status: status); @@ -52,8 +53,9 @@ class NotificationsHelper { NotificationDetails(android: androidNotificationDetails); await flutterLocalNotificationsPlugin.show( Random().nextInt(432234*2), "title".i18n, "body".i18n.fill([grade.value.value.toString(), grade.subject.name.toString()]), notificationDetails); - } } + gradeProvider.seenAll(); + } } } From 07bbafe7dd0811ec590b5d681fd27037a7d88251 Mon Sep 17 00:00:00 2001 From: hihihaha Date: Sat, 10 Jun 2023 20:34:01 +0200 Subject: [PATCH 3/9] add toggle for notifications in settings --- .../lib/helpers/notification_helper.dart | 80 +++++++++++-------- .../lib/screens/settings/settings_screen.dart | 43 +++++++++- 2 files changed, 89 insertions(+), 34 deletions(-) diff --git a/filcnaplo/lib/helpers/notification_helper.dart b/filcnaplo/lib/helpers/notification_helper.dart index 2464fd2b..acc3a875 100644 --- a/filcnaplo/lib/helpers/notification_helper.dart +++ b/filcnaplo/lib/helpers/notification_helper.dart @@ -7,16 +7,14 @@ 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/theme/colors/accent.dart'; import 'package:filcnaplo_kreta_api/client/client.dart'; -import 'package:filcnaplo_kreta_api/models/category.dart'; import 'package:filcnaplo_kreta_api/models/grade.dart'; -import 'package:filcnaplo_kreta_api/models/subject.dart'; import 'package:filcnaplo_kreta_api/providers/grade_provider.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; class NotificationsHelper { void backgroundJob() async { + // initialize providers FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); DatabaseProvider database = DatabaseProvider(); @@ -25,37 +23,53 @@ class NotificationsHelper { SettingsProvider settingsProvider = await database.query.getSettings(database); UserProvider userProvider = await database.query.getUsers(settingsProvider); - if(userProvider.id != null) { - final status = StatusProvider(); - final kretaClient = KretaClient( - user: userProvider, settings: settingsProvider, status: status); - kretaClient.refreshLogin(); - 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 ?? ""); - for (Grade grade in grades) { - if (grade.seenDate.isAfter(lastSeenGrade)) { - 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: 'ticker'); - const NotificationDetails notificationDetails = - NotificationDetails(android: androidNotificationDetails); - await flutterLocalNotificationsPlugin.show( - Random().nextInt(432234*2), "title".i18n, "body".i18n.fill([grade.value.value.toString(), grade.subject.name.toString()]), notificationDetails); + + if (userProvider.id != null && settingsProvider.notificationsEnabled) { + // refresh grades + final status = StatusProvider(); + final kretaClient = KretaClient( + user: userProvider, settings: settingsProvider, status: status); + kretaClient.refreshLogin(); + 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 ?? ""); + + // loop through grades and see which hasn't been seen yet + for (Grade grade in grades) { + if (grade.seenDate.isAfter(lastSeenGrade)) { + // 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); + await flutterLocalNotificationsPlugin.show( + // probably shouldn't use a random int + Random().nextInt(432234 * 2), + "title".i18n, + "body".i18n.fill([ + grade.value.value.toString(), + grade.subject.isRenamed && + settingsProvider.renamedSubjectsEnabled + ? grade.subject.renamedTo! + : grade.subject.name + ]), + notificationDetails); + } } - } - gradeProvider.seenAll(); + // set grade seen status + gradeProvider.seenAll(); } } } diff --git a/filcnaplo_mobile_ui/lib/screens/settings/settings_screen.dart b/filcnaplo_mobile_ui/lib/screens/settings/settings_screen.dart index 93410a80..0d1bcdde 100755 --- a/filcnaplo_mobile_ui/lib/screens/settings/settings_screen.dart +++ b/filcnaplo_mobile_ui/lib/screens/settings/settings_screen.dart @@ -153,7 +153,7 @@ class _SettingsScreenState extends State void initState() { super.initState(); Future.delayed(Duration.zero, () { - futureRelease = Provider.of(context).installedVersion(); + futureRelease = Provider.of(context, listen: false).installedVersion(); }); _hideContainersController = AnimationController( vsync: this, duration: const Duration(milliseconds: 200)); @@ -434,6 +434,47 @@ class _SettingsScreenState extends State activeColor: Theme.of(context).colorScheme.secondary, ), ), + PanelButton( + padding: const EdgeInsets.only(left: 14.0), + title: Row(children: [ + Text( + "notifications".i18n, + style: TextStyle( + color: AppColors.of(context).text.withOpacity( + settings.notificationsEnabled ? 1.0 : .5)), + ), + SizedBox( + width: 5, + ), + SizedBox( + height: 30, + child: AnimatedContainer( + duration: Duration(milliseconds: 200), + child: Padding( + padding: + const EdgeInsets.only(left: 10, right: 10), + child: Center( + child: Text("BETA", + style: TextStyle(fontSize: 9.1, color: AppColors.of(context).text.withOpacity(settings.notificationsEnabled ? 1.0 : .5), overflow: TextOverflow.ellipsis))), + ), + decoration: BoxDecoration( + color: AppColors.of(context).filc.withOpacity(settings.notificationsEnabled ? 1.0 : .5), + borderRadius: BorderRadius.circular(40)), + ), + ) + ]), + leading: settings.notificationsEnabled + ? const Icon(FeatherIcons.messageSquare) + : Icon(FeatherIcons.messageSquare, + color: + AppColors.of(context).text.withOpacity(.25)), + trailing: Switch( + onChanged: (v) => + settings.update(notificationsEnabled: v), + value: settings.notificationsEnabled, + activeColor: Theme.of(context).colorScheme.secondary, + ), + ), ], ), ), From cf81ca820746e62a2b346ea2537659f2762ab6cf Mon Sep 17 00:00:00 2001 From: hihihaha Date: Sat, 10 Jun 2023 20:39:06 +0200 Subject: [PATCH 4/9] add annotation to function --- filcnaplo/lib/helpers/notification_helper.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/filcnaplo/lib/helpers/notification_helper.dart b/filcnaplo/lib/helpers/notification_helper.dart index acc3a875..ec7ae412 100644 --- a/filcnaplo/lib/helpers/notification_helper.dart +++ b/filcnaplo/lib/helpers/notification_helper.dart @@ -13,6 +13,7 @@ import 'package:filcnaplo_kreta_api/providers/grade_provider.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; class NotificationsHelper { + @pragma('vm:entry-point') void backgroundJob() async { // initialize providers FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = From 8f85c6a33b34512880ac58a7790d508cf80dc8e0 Mon Sep 17 00:00:00 2001 From: hihihaha Date: Sat, 10 Jun 2023 20:41:31 +0200 Subject: [PATCH 5/9] add timeout safety to headless task --- filcnaplo/lib/main.dart | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/filcnaplo/lib/main.dart b/filcnaplo/lib/main.dart index bd87738a..fa2efe51 100644 --- a/filcnaplo/lib/main.dart +++ b/filcnaplo/lib/main.dart @@ -121,7 +121,6 @@ Widget errorBuilder(FlutterErrorDetails details) { return Container(); }); } -// Platform messages are asynchronous, so we initialize in an async method. Future initPlatformState() async { // Configure BackgroundFetch. int status = await BackgroundFetch.configure(BackgroundFetchConfig( @@ -134,15 +133,11 @@ Widget errorBuilder(FlutterErrorDetails details) { requiresDeviceIdle: false, requiredNetworkType: NetworkType.ANY ), (String taskId) async { // <-- Event handler - // This is the fetch-event callback. print("[BackgroundFetch] Event received $taskId"); NotificationsHelper().backgroundJob(); - // IMPORTANT: You must signal completion of your task or the OS can punish your app - // for taking too long in the background. BackgroundFetch.finish(taskId); }, (String taskId) async { // <-- Task timeout handler. - // This task has exceeded its allowed running-time. You must stop what you're doing and immediately .finish(taskId) print("[BackgroundFetch] TASK TIMEOUT taskId: $taskId"); BackgroundFetch.finish(taskId); }); @@ -152,6 +147,13 @@ Widget errorBuilder(FlutterErrorDetails details) { @pragma('vm:entry-point') void backgroundHeadlessTask(HeadlessTask task) { + String taskId = task.taskId; + bool isTimeout = task.timeout; + if (isTimeout) { + print("[BackgroundFetch] Headless task timed-out: $taskId"); + BackgroundFetch.finish(taskId); + return; + } print('[BackgroundFetch] Headless event received.'); NotificationsHelper().backgroundJob(); BackgroundFetch.finish(task.taskId); From 0274c2f07059545c05eb4a60404e720158901960 Mon Sep 17 00:00:00 2001 From: hihihaha Date: Sat, 10 Jun 2023 20:43:03 +0200 Subject: [PATCH 6/9] start on boot --- filcnaplo/lib/main.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/filcnaplo/lib/main.dart b/filcnaplo/lib/main.dart index fa2efe51..0d187947 100644 --- a/filcnaplo/lib/main.dart +++ b/filcnaplo/lib/main.dart @@ -131,7 +131,8 @@ Widget errorBuilder(FlutterErrorDetails details) { requiresCharging: false, requiresStorageNotLow: false, requiresDeviceIdle: false, - requiredNetworkType: NetworkType.ANY + requiredNetworkType: NetworkType.ANY, + startOnBoot: true ), (String taskId) async { // <-- Event handler print("[BackgroundFetch] Event received $taskId"); NotificationsHelper().backgroundJob(); From 8c2227df737546e5ad7ee33070adabaf922e7c18 Mon Sep 17 00:00:00 2001 From: hihihaha Date: Sat, 10 Jun 2023 21:03:01 +0200 Subject: [PATCH 7/9] update design --- .../lib/screens/settings/settings_screen.dart | 92 +++++++++++-------- 1 file changed, 55 insertions(+), 37 deletions(-) diff --git a/filcnaplo_mobile_ui/lib/screens/settings/settings_screen.dart b/filcnaplo_mobile_ui/lib/screens/settings/settings_screen.dart index 0d1bcdde..082c316b 100755 --- a/filcnaplo_mobile_ui/lib/screens/settings/settings_screen.dart +++ b/filcnaplo_mobile_ui/lib/screens/settings/settings_screen.dart @@ -434,45 +434,63 @@ class _SettingsScreenState extends State activeColor: Theme.of(context).colorScheme.secondary, ), ), - PanelButton( - padding: const EdgeInsets.only(left: 14.0), - title: Row(children: [ - Text( - "notifications".i18n, - style: TextStyle( - color: AppColors.of(context).text.withOpacity( - settings.notificationsEnabled ? 1.0 : .5)), - ), - SizedBox( - width: 5, - ), - SizedBox( - height: 30, - child: AnimatedContainer( - duration: Duration(milliseconds: 200), - child: Padding( - padding: - const EdgeInsets.only(left: 10, right: 10), - child: Center( - child: Text("BETA", - style: TextStyle(fontSize: 9.1, color: AppColors.of(context).text.withOpacity(settings.notificationsEnabled ? 1.0 : .5), overflow: TextOverflow.ellipsis))), - ), - decoration: BoxDecoration( - color: AppColors.of(context).filc.withOpacity(settings.notificationsEnabled ? 1.0 : .5), - borderRadius: BorderRadius.circular(40)), - ), - ) - ]), - leading: settings.notificationsEnabled - ? const Icon(FeatherIcons.messageSquare) - : Icon(FeatherIcons.messageSquare, - color: - AppColors.of(context).text.withOpacity(.25)), - trailing: Switch( - onChanged: (v) => - settings.update(notificationsEnabled: v), + Material( + type: MaterialType.transparency, + child: SwitchListTile( value: settings.notificationsEnabled, activeColor: Theme.of(context).colorScheme.secondary, + contentPadding: const EdgeInsets.only(left: 12.0), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12.0)), + title: Row(children: [ + Icon(FeatherIcons.messageSquare, + color: Theme.of(context) + .colorScheme + .secondary + .withOpacity( + settings.notificationsEnabled ? 1 : .25)), + const SizedBox(width: 14.0), + Text( + "notifications".i18n, + style: TextStyle( + color: AppColors.of(context).text.withOpacity( + settings.notificationsEnabled ? 1.0 : .5), + fontWeight: FontWeight.w600, + fontSize: 16.0, + ), + ), + SizedBox( + width: 5, + ), + SizedBox( + height: 30, + child: AnimatedContainer( + duration: Duration(milliseconds: 200), + child: Padding( + padding: + const EdgeInsets.only(left: 10, right: 10), + child: Center( + child: Text("BETA", + style: TextStyle( + fontSize: 9.1, + color: AppColors.of(context) + .text + .withOpacity( + settings.notificationsEnabled + ? 1.0 + : .5), + fontWeight: FontWeight.w600, + overflow: TextOverflow.ellipsis))), + ), + decoration: BoxDecoration( + color: AppColors.of(context).filc.withOpacity( + settings.notificationsEnabled ? 1.0 : .5), + borderRadius: BorderRadius.circular(40)), + ), + ) + ]), + onChanged: (value) => + settings.update(notificationsEnabled: value), ), ), ], From fe03554fbf50881cf475c28ddb516d1f6fa151d0 Mon Sep 17 00:00:00 2001 From: hihihaha Date: Sat, 10 Jun 2023 21:19:49 +0200 Subject: [PATCH 8/9] backend changes --- filcnaplo/lib/helpers/notification_helper.dart | 3 ++- filcnaplo/lib/ui/filter/widgets.dart | 1 + filcnaplo_kreta_api/lib/providers/grade_provider.dart | 1 - .../lib/screens/settings/settings_screen.dart | 6 +----- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/filcnaplo/lib/helpers/notification_helper.dart b/filcnaplo/lib/helpers/notification_helper.dart index ec7ae412..c1cfcb62 100644 --- a/filcnaplo/lib/helpers/notification_helper.dart +++ b/filcnaplo/lib/helpers/notification_helper.dart @@ -44,7 +44,8 @@ class NotificationsHelper { // loop through grades and see which hasn't been seen yet for (Grade grade in grades) { - if (grade.seenDate.isAfter(lastSeenGrade)) { + // 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', diff --git a/filcnaplo/lib/ui/filter/widgets.dart b/filcnaplo/lib/ui/filter/widgets.dart index 9632adfa..bce82ae0 100644 --- a/filcnaplo/lib/ui/filter/widgets.dart +++ b/filcnaplo/lib/ui/filter/widgets.dart @@ -89,6 +89,7 @@ Future> getFilterWidgets(FilterType activeData, // Grades case FilterType.grades: + gradeProvider.seenAll(); items = grade_filter.getWidgets( gradeProvider.grades, gradeProvider.lastSeenDate); if (settingsProvider.gradeOpeningFun) { diff --git a/filcnaplo_kreta_api/lib/providers/grade_provider.dart b/filcnaplo_kreta_api/lib/providers/grade_provider.dart index cc8e6ee3..68d8db9d 100644 --- a/filcnaplo_kreta_api/lib/providers/grade_provider.dart +++ b/filcnaplo_kreta_api/lib/providers/grade_provider.dart @@ -51,7 +51,6 @@ class GradeProvider with ChangeNotifier { final userStore = _database.userStore; userStore.storeLastSeenGrade(DateTime.now(), userId: userId); _lastSeen = DateTime.now(); - notifyListeners(); } } diff --git a/filcnaplo_mobile_ui/lib/screens/settings/settings_screen.dart b/filcnaplo_mobile_ui/lib/screens/settings/settings_screen.dart index 082c316b..1aebdf0b 100755 --- a/filcnaplo_mobile_ui/lib/screens/settings/settings_screen.dart +++ b/filcnaplo_mobile_ui/lib/screens/settings/settings_screen.dart @@ -444,11 +444,7 @@ class _SettingsScreenState extends State borderRadius: BorderRadius.circular(12.0)), title: Row(children: [ Icon(FeatherIcons.messageSquare, - color: Theme.of(context) - .colorScheme - .secondary - .withOpacity( - settings.notificationsEnabled ? 1 : .25)), + color: settings.notificationsEnabled ? Theme.of(context).colorScheme.secondary : AppColors.of(context).text.withOpacity(.25)), const SizedBox(width: 14.0), Text( "notifications".i18n, From 27ef942723d45b3c8b72631fcd23238f816ed8ec Mon Sep 17 00:00:00 2001 From: hihihaha Date: Sat, 10 Jun 2023 21:46:53 +0200 Subject: [PATCH 9/9] fix headless task --- filcnaplo/lib/main.dart | 10 ++++-- .../screens/navigation/navigation_screen.dart | 35 ------------------- 2 files changed, 8 insertions(+), 37 deletions(-) diff --git a/filcnaplo/lib/main.dart b/filcnaplo/lib/main.dart index 0d187947..1131ffb8 100644 --- a/filcnaplo/lib/main.dart +++ b/filcnaplo/lib/main.dart @@ -136,14 +136,20 @@ Widget errorBuilder(FlutterErrorDetails details) { ), (String taskId) async { // <-- Event handler print("[BackgroundFetch] Event received $taskId"); NotificationsHelper().backgroundJob(); - BackgroundFetch.finish(taskId); }, (String taskId) async { // <-- Task timeout handler. print("[BackgroundFetch] TASK TIMEOUT taskId: $taskId"); BackgroundFetch.finish(taskId); }); print('[BackgroundFetch] configure success: $status'); - + BackgroundFetch.scheduleTask(TaskConfig( + taskId: "com.transistorsoft.refilcnotification", + delay: 900000, // 15 minutes + periodic: true, + forceAlarmManager: true, + stopOnTerminate: false, + enableHeadless: true + )); } @pragma('vm:entry-point') diff --git a/filcnaplo_mobile_ui/lib/screens/navigation/navigation_screen.dart b/filcnaplo_mobile_ui/lib/screens/navigation/navigation_screen.dart index 4ceed6d9..9f865290 100755 --- a/filcnaplo_mobile_ui/lib/screens/navigation/navigation_screen.dart +++ b/filcnaplo_mobile_ui/lib/screens/navigation/navigation_screen.dart @@ -95,45 +95,10 @@ class NavigationScreenState extends State } } - // Platform messages are asynchronous, so we initialize in an async method. - Future initPlatformState() async { - // Configure BackgroundFetch. - int status = await BackgroundFetch.configure( - BackgroundFetchConfig( - minimumFetchInterval: 15, - stopOnTerminate: false, - enableHeadless: true, - requiresBatteryNotLow: false, - requiresCharging: false, - requiresStorageNotLow: false, - requiresDeviceIdle: false, - requiredNetworkType: NetworkType.ANY), (String taskId) async { - // <-- Event handler - // This is the fetch-event callback. - print("[BackgroundFetch] Event received $taskId"); - - // IMPORTANT: You must signal completion of your task or the OS can punish your app - // for taking too long in the background. - BackgroundFetch.finish(taskId); - }, (String taskId) async { - // <-- Task timeout handler. - // This task has exceeded its allowed running-time. You must stop what you're doing and immediately .finish(taskId) - print("[BackgroundFetch] TASK TIMEOUT taskId: $taskId"); - BackgroundFetch.finish(taskId); - }); - print('[BackgroundFetch] configure success: $status'); - - // If the widget was removed from the tree while the asynchronous platform - // message was in flight, we want to discard the reply rather than calling - // setState to update our non-existent appearance. - if (!mounted) return; - } - @override void initState() { super.initState(); - initPlatformState(); HomeWidget.setAppGroupId('hu.refilc.naplo.group');