fix: přidat info o baterii a odstranit zbytecny if

This commit is contained in:
Matyáš Caras 2022-06-15 20:04:30 +02:00
parent 6bbc9c2d0a
commit c95518c557
6 changed files with 63 additions and 36 deletions

View file

@ -149,6 +149,8 @@ abstract class Languages {
String get notifyAt;
String get notifyWarning;
// Offline
String get offline;

View file

@ -224,4 +224,8 @@ 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í.";
}

View file

@ -222,4 +222,8 @@ 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.";
}

View file

@ -55,44 +55,44 @@ 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);
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
}
}
// }
}
}

View file

@ -143,6 +143,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);

View file

@ -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+16
environment:
sdk: ">=2.16.1 <3.0.0"