diff --git a/lib/methods_vars/notifications.dart b/lib/methods_vars/notifications.dart index 39fdb40..8b8c838 100644 --- a/lib/methods_vars/notifications.dart +++ b/lib/methods_vars/notifications.dart @@ -143,16 +143,14 @@ Future initAwesome() async { Future doNotifications({bool force = false}) async { LoggedInCanteen loggedInCanteen = LoggedInCanteen(); LoginDataAutojidelna loginData = await loggedInCanteen.getLoginDataFromSecureStorage(); - if (kDebugMode) { - AwesomeNotifications().createNotification( - content: NotificationContent( - id: -1, - channelKey: 'else_channel', - actionType: ActionType.Default, - title: 'Spouštím notifikace', - body: DateTime.now().toString(), - )); - } + AwesomeNotifications().createNotification( + content: NotificationContent( + id: 588, + locked: true, + channelKey: 'else_channel', + actionType: ActionType.Default, + title: 'Získávám data pro notifikace...', + )); // Don't send notifications before 9 and after 22 if ((DateTime.now().hour < 9 || DateTime.now().hour > 22) && !force) { return; @@ -175,8 +173,8 @@ Future doNotifications({bool force = false}) async { if ((await loggedInCanteen.readData('lastJidloDneCheck-${loginData.users[i].username}') == nowString || await loggedInCanteen.readData('sendFoodInfo-${loginData.users[i].username}') != '1' || - difference > 80 || - difference < -80) && + difference > 120 || + difference < -120) && !force) { jidloDne = false; } else { @@ -191,6 +189,7 @@ Future doNotifications({bool force = false}) async { objednavka = false; } if (kDebugMode) { + /* AwesomeNotifications().createNotification( content: NotificationContent( id: -1, @@ -198,7 +197,7 @@ Future doNotifications({bool force = false}) async { actionType: ActionType.Default, title: 'Notifikace Info', body: 'jidloDne: $jidloDne, kredit: $kredit, objednavka: $objednavka', - )); + ));*/ } if (!jidloDne && !kredit && !objednavka) { continue; @@ -214,6 +213,23 @@ Future doNotifications({bool force = false}) async { if (!jidelnicek.jidla[k].objednano) { continue; } + if (difference > 0) { + AwesomeNotifications().createNotification( + content: NotificationContent( + id: 1024 - i, + channelKey: 'jidlo_channel_${loginData.users[i].username}', + actionType: ActionType.Default, + title: 'Dnešní jídlo', + payload: { + 'user': loginData.users[i].username, + 'index': k.toString(), + 'indexDne': jidelnicek.den.difference(minimalDate).inDays.toString(), + }, + body: jidelnicek.jidla[0].nazev, + ), + schedule: NotificationCalendar.fromDate(date: time)); + break; + } AwesomeNotifications().createNotification( content: NotificationContent( id: 1024 - i, @@ -364,6 +380,7 @@ Future doNotifications({bool force = false}) async { } } } + AwesomeNotifications().cancel(588); return; } diff --git a/pubspec.lock b/pubspec.lock index 3a10a92..27b14a3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -93,10 +93,10 @@ packages: dependency: "direct main" description: name: canteenlib - sha256: "3eb27864eecd2aa180ebf611da1bf7730cdedff9f2eb60018b4e0584e75e418f" + sha256: "81ec5d583a8a962662d01f968d11ae1093949d6338445d11ab921a6ede35dc6c" url: "https://pub.dev" source: hosted - version: "3.0.4" + version: "3.0.5" characters: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index bc08735..e48583c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -32,7 +32,7 @@ dependencies: sdk: flutter shared_preferences: ^2.0.0 flutter_secure_storage: ^8.0.0 - canteenlib: ^3.0.4 + canteenlib: ^3.0.5 http: ^1.1.0 flutter_widget_from_html: ^0.10.2 fluttertoast: ^8.0.8