fix: Optimalizovat kód, přidat varování před odhlášením
Merge pull request #19 from hernikplays/oznameni-qf
This commit is contained in:
commit
19380a9ee8
9 changed files with 117 additions and 47 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
# 1.3.1
|
||||||
|
- Odstranit zbytečné podmínky
|
||||||
|
- Přidat oznámení o optimalizaci baterie
|
||||||
|
- Změnit ID kanálu pro android oznámení
|
||||||
|
- Změnit ikonu pro přesunutí na aktuální den
|
||||||
|
- Přidat varování před odhlášením
|
||||||
|
- Při prvním zapnutí nastavovat výchozí čas pro oznámení o hodinu dopředu
|
||||||
|
- V oznámení zobrazit nejdřív variantu a pak název jídla
|
||||||
# 1.3.0
|
# 1.3.0
|
||||||
- Odstranit connectivity_plus
|
- Odstranit connectivity_plus
|
||||||
- Přidat možnost oznámení s info o obědu v daný čas
|
- Přidat možnost oznámení s info o obědu v daný čas
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
# OpenCanteen
|
# OpenCanteen
|
||||||
Open-Source **neoficiální** iCanteen klient
|
Open-Source **neoficiální** aplikace pro přístup do iCanteen
|
||||||
|
|
||||||
[![wakatime](https://wakatime.com/badge/user/17178fab-a33c-430f-a764-7b3f26c7b966/project/e3ff9994-0026-4041-a529-1cb2041bdf4b.svg)](https://wakatime.com/badge/user/17178fab-a33c-430f-a764-7b3f26c7b966/project/e3ff9994-0026-4041-a529-1cb2041bdf4b)
|
[![wakatime](https://wakatime.com/badge/user/17178fab-a33c-430f-a764-7b3f26c7b966/project/e3ff9994-0026-4041-a529-1cb2041bdf4b.svg)](https://wakatime.com/badge/user/17178fab-a33c-430f-a764-7b3f26c7b966/project/e3ff9994-0026-4041-a529-1cb2041bdf4b)
|
||||||
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fhernikplays%2Fopencanteen.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fhernikplays%2Fopencanteen?ref=badge_shield) [![Codemagic build status](https://api.codemagic.io/apps/62863e4c96304ce0518a1694/62863e4c96304ce0518a1693/status_badge.svg)](https://codemagic.io/apps/62863e4c96304ce0518a1694/62863e4c96304ce0518a1693/latest_build) [![Commit Style: Conventional Commits](https://img.shields.io/badge/commit%20style-conventional%20commits-pink)](https://www.conventionalcommits.org/en/v1.0.0/)
|
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fhernikplays%2Fopencanteen.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fhernikplays%2Fopencanteen?ref=badge_shield) [![Codemagic build status](https://api.codemagic.io/apps/62863e4c96304ce0518a1694/62863e4c96304ce0518a1693/status_badge.svg)](https://codemagic.io/apps/62863e4c96304ce0518a1694/62863e4c96304ce0518a1693/latest_build) [![Commit Style: Conventional Commits](https://img.shields.io/badge/commit%20style-conventional%20commits-pink)](https://www.conventionalcommits.org/en/v1.0.0/)
|
||||||
|
|
||||||
## Co umí
|
## Co umí
|
||||||
Aplikace vás přihlásí do instance iCanteen ***pokud ji podporuje [canteenlib](https://github.com/hernikplays/canteenlib/blob/main/COMPATIBILITY.md), jinak experimentálně***, a umožní vám zobrazit, objednávat obědy, objednávat nebo přidávat jídlo na burzu<sup>beta</sup>.
|
Aplikace vás přihlásí do vaší iCanteen ***pokud ji podporuje [canteenlib](https://github.com/hernikplays/canteenlib/blob/main/COMPATIBILITY.md), jinak experimentálně***, a umožní vám zobrazit, objednávat obědy, objednávat nebo přidávat jídlo na burzu<sup>beta</sup>.
|
||||||
|
|
||||||
## Co se plánuje
|
## Co se plánuje
|
||||||
- Offline ukládání jídelníčku a zakoupených jídel
|
- Offline ukládání jídelníčku a zakoupených jídel
|
||||||
|
|
|
@ -89,6 +89,8 @@ abstract class Languages {
|
||||||
|
|
||||||
String get noOrder;
|
String get noOrder;
|
||||||
|
|
||||||
|
String get signOutWarn;
|
||||||
|
|
||||||
// Uvítací obrazovka
|
// Uvítací obrazovka
|
||||||
|
|
||||||
String get welcome;
|
String get welcome;
|
||||||
|
@ -149,6 +151,8 @@ abstract class Languages {
|
||||||
|
|
||||||
String get notifyAt;
|
String get notifyAt;
|
||||||
|
|
||||||
|
String get notifyWarning;
|
||||||
|
|
||||||
// Offline
|
// Offline
|
||||||
String get offline;
|
String get offline;
|
||||||
|
|
||||||
|
|
|
@ -224,4 +224,11 @@ class LanguageCz extends Languages {
|
||||||
@override
|
@override
|
||||||
String get needRemember =>
|
String get needRemember =>
|
||||||
"Musíte své přihlašovací údaje uložit na přihlašovací obrazovce";
|
"Musíte své přihlašovací údaje uložit na přihlašovací obrazovce";
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get notifyWarning =>
|
||||||
|
"Vaše zařízení může mít povolenou optimalizaci baterie, což může způsobovat neodesílání oznámení. Zkontrolujte nastavení ve vašem zařízení.";
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get signOutWarn => "Opravdu se chcete odhlásit?";
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,4 +222,11 @@ class LanguageEn extends Languages {
|
||||||
@override
|
@override
|
||||||
String get needRemember =>
|
String get needRemember =>
|
||||||
"You need to save your login details on the login screen first";
|
"You need to save your login details on the login screen first";
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get notifyWarning =>
|
||||||
|
"Your device may have battery optimization enabled. This may cause notifications to not be sent. Check the application info in your device's settings.";
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get signOutWarn => "Do you really want to sign out?";
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,44 +55,50 @@ void oznamitPredem(SharedPreferences prefs, tz.Location l) async {
|
||||||
title = LanguageEn().lunchNotif;
|
title = LanguageEn().lunchNotif;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prefs.getBool("offline") ?? false) {
|
/*if (prefs.getBool("offline") ?? false) {
|
||||||
// TODO možnost brát z offline dat
|
// TODO možnost brát z offline dat
|
||||||
} else {
|
} else {*/
|
||||||
// bere online
|
// bere online
|
||||||
var d = await LoginManager.getDetails(); // získat údaje
|
var d = await LoginManager.getDetails(); // získat údaje
|
||||||
if (d != null) {
|
if (d != null) {
|
||||||
var c = Canteen(d["url"]!);
|
var c = Canteen(d["url"]!);
|
||||||
if (await c.login(d["user"]!, d["pass"]!)) {
|
if (await c.login(d["user"]!, d["pass"]!)) {
|
||||||
var jidla = await c.jidelnicekDen();
|
var jidla = await c.jidelnicekDen();
|
||||||
try {
|
try {
|
||||||
var jidlo = jidla.jidla.singleWhere((element) => element.objednano);
|
var jidlo = jidla.jidla.singleWhere(
|
||||||
var kdy = DateTime.parse(prefs.getString("oznameni_cas")!);
|
(element) => element.objednano); // získá objednané jídlo
|
||||||
const AndroidNotificationDetails androidSpec =
|
var kdy = DateTime.parse(prefs.getString(
|
||||||
AndroidNotificationDetails('opencanteen', 'predobjedem',
|
"oznameni_cas")!); // uložíme čas, kdy se má odeslat oznámení
|
||||||
channelDescription: 'Oznámení o dnešním jídle',
|
|
||||||
importance: Importance.max,
|
// data o oznámení
|
||||||
priority: Priority.high,
|
const AndroidNotificationDetails androidSpec =
|
||||||
ticker: 'today meal');
|
AndroidNotificationDetails('predobedem', 'Oznámení před obědem',
|
||||||
const IOSNotificationDetails iOSpec =
|
channelDescription: 'Oznámení o dnešním jídle',
|
||||||
IOSNotificationDetails(presentAlert: true, presentBadge: true);
|
importance: Importance.max,
|
||||||
await flutterLocalNotificationsPlugin.zonedSchedule(
|
priority: Priority.high,
|
||||||
0,
|
ticker: 'today meal');
|
||||||
title,
|
const IOSNotificationDetails iOSpec =
|
||||||
"${jidlo.nazev} - ${jidlo.varianta}",
|
IOSNotificationDetails(presentAlert: true, presentBadge: true);
|
||||||
tz.TZDateTime.from(
|
|
||||||
casNaDate(
|
// naplánovat
|
||||||
TimeOfDay(hour: kdy.hour, minute: kdy.minute),
|
await flutterLocalNotificationsPlugin.zonedSchedule(
|
||||||
),
|
0,
|
||||||
l),
|
title,
|
||||||
const NotificationDetails(android: androidSpec, iOS: iOSpec),
|
"${jidlo.varianta} - ${jidlo.nazev}",
|
||||||
androidAllowWhileIdle: true,
|
tz.TZDateTime.from(
|
||||||
uiLocalNotificationDateInterpretation:
|
casNaDate(
|
||||||
UILocalNotificationDateInterpretation.absoluteTime);
|
TimeOfDay(hour: kdy.hour, minute: kdy.minute),
|
||||||
} on StateError catch (_) {
|
),
|
||||||
// nenalezeno
|
l),
|
||||||
}
|
const NotificationDetails(android: androidSpec, iOS: iOSpec),
|
||||||
|
androidAllowWhileIdle: true,
|
||||||
|
uiLocalNotificationDateInterpretation:
|
||||||
|
UILocalNotificationDateInterpretation.absoluteTime);
|
||||||
|
} on StateError catch (_) {
|
||||||
|
// nenalezeno
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +113,7 @@ void main() async {
|
||||||
oznamitPredem(prefs, l);
|
oznamitPredem(prefs, l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nastavit oznámení
|
||||||
const AndroidInitializationSettings initializationSettingsAndroid =
|
const AndroidInitializationSettings initializationSettingsAndroid =
|
||||||
AndroidInitializationSettings('notif_icon');
|
AndroidInitializationSettings('notif_icon');
|
||||||
|
|
||||||
|
@ -130,6 +137,8 @@ void main() async {
|
||||||
debugPrint('notification payload: $payload');
|
debugPrint('notification payload: $payload');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// spustit aplikaci
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,6 +409,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Získá offline soubor a zobrazí údaje
|
||||||
void goOffline() async {
|
void goOffline() async {
|
||||||
Directory appDocDir = await getApplicationDocumentsDirectory();
|
Directory appDocDir = await getApplicationDocumentsDirectory();
|
||||||
var den = DateTime.now();
|
var den = DateTime.now();
|
||||||
|
|
|
@ -304,13 +304,29 @@ class _JidelnicekPageState extends State<JidelnicekPage> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void kliknuti(
|
Future<void> kliknuti(String value, BuildContext context,
|
||||||
String value, BuildContext context, FlutterLocalNotificationsPlugin n) {
|
FlutterLocalNotificationsPlugin n) async {
|
||||||
if (value == Languages.of(context)!.signOut) {
|
if (value == Languages.of(context)!.signOut) {
|
||||||
const storage = FlutterSecureStorage();
|
await showDialog<bool>(
|
||||||
storage.deleteAll();
|
context: context,
|
||||||
Navigator.pushReplacement(
|
builder: (c) => AlertDialog(
|
||||||
context, MaterialPageRoute(builder: (c) => const LoginPage()));
|
title: Text(Languages.of(context)!.warning),
|
||||||
|
content: Text(Languages.of(context)!.signOutWarn),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
|
child: Text(Languages.of(context)!.yes)),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
const storage = FlutterSecureStorage();
|
||||||
|
storage.deleteAll();
|
||||||
|
Navigator.pushReplacement(context,
|
||||||
|
MaterialPageRoute(builder: (c) => const LoginPage()));
|
||||||
|
},
|
||||||
|
child: Text(Languages.of(context)!.no))
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
} else if (value == Languages.of(context)!.reportBugs) {
|
} else if (value == Languages.of(context)!.reportBugs) {
|
||||||
launch("https://github.com/hernikplays/opencanteen/issues/new/choose");
|
launch("https://github.com/hernikplays/opencanteen/issues/new/choose");
|
||||||
} else if (value == Languages.of(context)!.about) {
|
} else if (value == Languages.of(context)!.about) {
|
||||||
|
@ -444,7 +460,7 @@ class _JidelnicekPageState extends State<JidelnicekPage> {
|
||||||
den = DateTime.now();
|
den = DateTime.now();
|
||||||
nactiJidlo();
|
nactiJidlo();
|
||||||
}),
|
}),
|
||||||
icon: const Icon(Icons.calendar_today))
|
icon: const Icon(Icons.today))
|
||||||
]),
|
]),
|
||||||
SingleChildScrollView(
|
SingleChildScrollView(
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
|
|
|
@ -40,7 +40,8 @@ class _NastaveniState extends State<Nastaveni> {
|
||||||
var _casStr = preferences.getString("oznameni_cas");
|
var _casStr = preferences.getString("oznameni_cas");
|
||||||
if (_casStr == null) {
|
if (_casStr == null) {
|
||||||
var now = DateTime.now();
|
var now = DateTime.now();
|
||||||
_oznameniCas = TimeOfDay.fromDateTime(DateTime.now());
|
_oznameniCas = TimeOfDay.fromDateTime(
|
||||||
|
DateTime.now().add(const Duration(hours: 1)));
|
||||||
preferences.setString("oznameni_cas", now.toString());
|
preferences.setString("oznameni_cas", now.toString());
|
||||||
} else {
|
} else {
|
||||||
_oznameniCas = TimeOfDay.fromDateTime(DateTime.parse(_casStr));
|
_oznameniCas = TimeOfDay.fromDateTime(DateTime.parse(_casStr));
|
||||||
|
@ -143,6 +144,23 @@ class _NastaveniState extends State<Nastaveni> {
|
||||||
setState(() {
|
setState(() {
|
||||||
_oznameniObed = value;
|
_oznameniObed = value;
|
||||||
if (_oznameniObed) {
|
if (_oznameniObed) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => AlertDialog(
|
||||||
|
title:
|
||||||
|
Text(Languages.of(context)!.warning),
|
||||||
|
content: Text(
|
||||||
|
Languages.of(context)!.notifyWarning),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
child:
|
||||||
|
Text(Languages.of(context)!.ok),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
));
|
||||||
vytvoritOznameni(casNaDate(_oznameniCas));
|
vytvoritOznameni(casNaDate(_oznameniCas));
|
||||||
}
|
}
|
||||||
zmenitNastaveni("oznamit", value);
|
zmenitNastaveni("oznamit", value);
|
||||||
|
@ -222,7 +240,7 @@ class _NastaveniState extends State<Nastaveni> {
|
||||||
// Vytvoří nové oznámení pro daný čas a datum
|
// Vytvoří nové oznámení pro daný čas a datum
|
||||||
0,
|
0,
|
||||||
Languages.of(context)!.lunchNotif,
|
Languages.of(context)!.lunchNotif,
|
||||||
"${jidlo.nazev} - ${jidlo.varianta}",
|
"${jidlo.varianta} - ${jidlo.nazev}",
|
||||||
tz.TZDateTime.from(den, l),
|
tz.TZDateTime.from(den, l),
|
||||||
const NotificationDetails(android: androidSpec, iOS: iOSpec),
|
const NotificationDetails(android: androidSpec, iOS: iOSpec),
|
||||||
androidAllowWhileIdle: true,
|
androidAllowWhileIdle: true,
|
||||||
|
|
|
@ -6,7 +6,7 @@ publish_to: 'none'
|
||||||
# The following defines the version and build number for your application.
|
# The following defines the version and build number for your application.
|
||||||
# A version number is three numbers separated by dots, like 1.2.43
|
# A version number is three numbers separated by dots, like 1.2.43
|
||||||
# followed by an optional build number separated by a +.
|
# followed by an optional build number separated by a +.
|
||||||
version: 1.3.0+15
|
version: 1.3.1+17
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.16.1 <3.0.0"
|
sdk: ">=2.16.1 <3.0.0"
|
||||||
|
|
Reference in a new issue