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
|
||||
- Odstranit connectivity_plus
|
||||
- Přidat možnost oznámení s info o obědu v daný čas
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
# 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)
|
||||
[![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í
|
||||
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
|
||||
- Offline ukládání jídelníčku a zakoupených jídel
|
||||
|
|
|
@ -89,6 +89,8 @@ abstract class Languages {
|
|||
|
||||
String get noOrder;
|
||||
|
||||
String get signOutWarn;
|
||||
|
||||
// Uvítací obrazovka
|
||||
|
||||
String get welcome;
|
||||
|
@ -149,6 +151,8 @@ abstract class Languages {
|
|||
|
||||
String get notifyAt;
|
||||
|
||||
String get notifyWarning;
|
||||
|
||||
// Offline
|
||||
String get offline;
|
||||
|
||||
|
|
|
@ -224,4 +224,11 @@ class LanguageCz extends Languages {
|
|||
@override
|
||||
String get needRemember =>
|
||||
"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
|
||||
String get needRemember =>
|
||||
"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;
|
||||
}
|
||||
|
||||
if (prefs.getBool("offline") ?? false) {
|
||||
/*if (prefs.getBool("offline") ?? false) {
|
||||
// TODO možnost brát z offline dat
|
||||
} else {
|
||||
// bere online
|
||||
var d = await LoginManager.getDetails(); // získat údaje
|
||||
if (d != null) {
|
||||
var c = Canteen(d["url"]!);
|
||||
if (await c.login(d["user"]!, d["pass"]!)) {
|
||||
var jidla = await c.jidelnicekDen();
|
||||
try {
|
||||
var jidlo = jidla.jidla.singleWhere((element) => element.objednano);
|
||||
var kdy = DateTime.parse(prefs.getString("oznameni_cas")!);
|
||||
const AndroidNotificationDetails androidSpec =
|
||||
AndroidNotificationDetails('opencanteen', 'predobjedem',
|
||||
channelDescription: 'Oznámení o dnešním jídle',
|
||||
importance: Importance.max,
|
||||
priority: Priority.high,
|
||||
ticker: 'today meal');
|
||||
const IOSNotificationDetails iOSpec =
|
||||
IOSNotificationDetails(presentAlert: true, presentBadge: true);
|
||||
await flutterLocalNotificationsPlugin.zonedSchedule(
|
||||
0,
|
||||
title,
|
||||
"${jidlo.nazev} - ${jidlo.varianta}",
|
||||
tz.TZDateTime.from(
|
||||
casNaDate(
|
||||
TimeOfDay(hour: kdy.hour, minute: kdy.minute),
|
||||
),
|
||||
l),
|
||||
const NotificationDetails(android: androidSpec, iOS: iOSpec),
|
||||
androidAllowWhileIdle: true,
|
||||
uiLocalNotificationDateInterpretation:
|
||||
UILocalNotificationDateInterpretation.absoluteTime);
|
||||
} on StateError catch (_) {
|
||||
// nenalezeno
|
||||
}
|
||||
} else {*/
|
||||
// bere online
|
||||
var d = await LoginManager.getDetails(); // získat údaje
|
||||
if (d != null) {
|
||||
var c = Canteen(d["url"]!);
|
||||
if (await c.login(d["user"]!, d["pass"]!)) {
|
||||
var jidla = await c.jidelnicekDen();
|
||||
try {
|
||||
var jidlo = jidla.jidla.singleWhere(
|
||||
(element) => element.objednano); // získá objednané jídlo
|
||||
var kdy = DateTime.parse(prefs.getString(
|
||||
"oznameni_cas")!); // uložíme čas, kdy se má odeslat oznámení
|
||||
|
||||
// data o oznámení
|
||||
const AndroidNotificationDetails androidSpec =
|
||||
AndroidNotificationDetails('predobedem', 'Oznámení před obědem',
|
||||
channelDescription: 'Oznámení o dnešním jídle',
|
||||
importance: Importance.max,
|
||||
priority: Priority.high,
|
||||
ticker: 'today meal');
|
||||
const IOSNotificationDetails iOSpec =
|
||||
IOSNotificationDetails(presentAlert: true, presentBadge: true);
|
||||
|
||||
// naplánovat
|
||||
await flutterLocalNotificationsPlugin.zonedSchedule(
|
||||
0,
|
||||
title,
|
||||
"${jidlo.varianta} - ${jidlo.nazev}",
|
||||
tz.TZDateTime.from(
|
||||
casNaDate(
|
||||
TimeOfDay(hour: kdy.hour, minute: kdy.minute),
|
||||
),
|
||||
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);
|
||||
}
|
||||
|
||||
// nastavit oznámení
|
||||
const AndroidInitializationSettings initializationSettingsAndroid =
|
||||
AndroidInitializationSettings('notif_icon');
|
||||
|
||||
|
@ -130,6 +137,8 @@ void main() async {
|
|||
debugPrint('notification payload: $payload');
|
||||
}
|
||||
});
|
||||
|
||||
// spustit aplikaci
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
|
@ -400,6 +409,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||
));
|
||||
}
|
||||
|
||||
/// Získá offline soubor a zobrazí údaje
|
||||
void goOffline() async {
|
||||
Directory appDocDir = await getApplicationDocumentsDirectory();
|
||||
var den = DateTime.now();
|
||||
|
|
|
@ -304,13 +304,29 @@ class _JidelnicekPageState extends State<JidelnicekPage> {
|
|||
});
|
||||
}
|
||||
|
||||
void kliknuti(
|
||||
String value, BuildContext context, FlutterLocalNotificationsPlugin n) {
|
||||
Future<void> kliknuti(String value, BuildContext context,
|
||||
FlutterLocalNotificationsPlugin n) async {
|
||||
if (value == Languages.of(context)!.signOut) {
|
||||
const storage = FlutterSecureStorage();
|
||||
storage.deleteAll();
|
||||
Navigator.pushReplacement(
|
||||
context, MaterialPageRoute(builder: (c) => const LoginPage()));
|
||||
await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (c) => AlertDialog(
|
||||
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) {
|
||||
launch("https://github.com/hernikplays/opencanteen/issues/new/choose");
|
||||
} else if (value == Languages.of(context)!.about) {
|
||||
|
@ -444,7 +460,7 @@ class _JidelnicekPageState extends State<JidelnicekPage> {
|
|||
den = DateTime.now();
|
||||
nactiJidlo();
|
||||
}),
|
||||
icon: const Icon(Icons.calendar_today))
|
||||
icon: const Icon(Icons.today))
|
||||
]),
|
||||
SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
|
|
|
@ -40,7 +40,8 @@ class _NastaveniState extends State<Nastaveni> {
|
|||
var _casStr = preferences.getString("oznameni_cas");
|
||||
if (_casStr == null) {
|
||||
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());
|
||||
} else {
|
||||
_oznameniCas = TimeOfDay.fromDateTime(DateTime.parse(_casStr));
|
||||
|
@ -143,6 +144,23 @@ class _NastaveniState extends State<Nastaveni> {
|
|||
setState(() {
|
||||
_oznameniObed = value;
|
||||
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));
|
||||
}
|
||||
zmenitNastaveni("oznamit", value);
|
||||
|
@ -222,7 +240,7 @@ class _NastaveniState extends State<Nastaveni> {
|
|||
// Vytvoří nové oznámení pro daný čas a datum
|
||||
0,
|
||||
Languages.of(context)!.lunchNotif,
|
||||
"${jidlo.nazev} - ${jidlo.varianta}",
|
||||
"${jidlo.varianta} - ${jidlo.nazev}",
|
||||
tz.TZDateTime.from(den, l),
|
||||
const NotificationDetails(android: androidSpec, iOS: iOSpec),
|
||||
androidAllowWhileIdle: true,
|
||||
|
|
|
@ -6,7 +6,7 @@ publish_to: 'none'
|
|||
# The following defines the version and build number for your application.
|
||||
# A version number is three numbers separated by dots, like 1.2.43
|
||||
# followed by an optional build number separated by a +.
|
||||
version: 1.3.0+15
|
||||
version: 1.3.1+17
|
||||
|
||||
environment:
|
||||
sdk: ">=2.16.1 <3.0.0"
|
||||
|
|
Reference in a new issue