Skip to content

Commit

Permalink
oprava chyby u canteenlib + persistentní notifikace
Browse files Browse the repository at this point in the history
  • Loading branch information
tpkowastaken committed Nov 8, 2023
1 parent f0095ec commit cd0f443
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
43 changes: 30 additions & 13 deletions lib/methods_vars/notifications.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,14 @@ Future<bool> initAwesome() async {
Future<void> 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;
Expand All @@ -175,8 +173,8 @@ Future<void> 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 {
Expand All @@ -191,14 +189,15 @@ Future<void> doNotifications({bool force = false}) async {
objednavka = false;
}
if (kDebugMode) {
/*
AwesomeNotifications().createNotification(
content: NotificationContent(
id: -1,
channelKey: 'else_channel',
actionType: ActionType.Default,
title: 'Notifikace Info',
body: 'jidloDne: $jidloDne, kredit: $kredit, objednavka: $objednavka',
));
));*/
}
if (!jidloDne && !kredit && !objednavka) {
continue;
Expand All @@ -214,6 +213,23 @@ Future<void> 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,
Expand Down Expand Up @@ -364,6 +380,7 @@ Future<void> doNotifications({bool force = false}) async {
}
}
}
AwesomeNotifications().cancel(588);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cd0f443

Please sign in to comment.