fix: poupravit chování nastavení + tlačítko dnes
This commit is contained in:
parent
119f1000e2
commit
b712f0e815
8 changed files with 132 additions and 78 deletions
|
@ -1,6 +1,7 @@
|
|||
# 1.3.0
|
||||
- Odstranit connectivity_plus
|
||||
- Přidat možnost oznámení s info o obědu v daný čas
|
||||
- Přidat k jídelníčku tlačítko, které zobrazí dnešní jídelníček
|
||||
# 1.2.0
|
||||
- Přidat možnost zobrazení oznámení v případě neobjednaného jídla na příští týden
|
||||
- Přidat oznámení o rozbitých uložených údajích
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||
android:hardwareAccelerated="true"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:screenOrientation="portrait">
|
||||
android:screenOrientation="portrait"
|
||||
android:showWhenLocked="true">
|
||||
<!-- Specifies an Android theme to apply to this Activity as soon as
|
||||
the Android process has started. This theme is visible to the user
|
||||
while the Flutter UI initializes. After that, this theme continues
|
||||
|
|
|
@ -156,4 +156,8 @@ abstract class Languages {
|
|||
|
||||
// Oznámit před obědem
|
||||
String get lunchNotif;
|
||||
|
||||
String get error;
|
||||
|
||||
String get needRemember;
|
||||
}
|
||||
|
|
|
@ -217,4 +217,11 @@ class LanguageCz extends Languages {
|
|||
|
||||
@override
|
||||
String get lunchNotif => "Dnes máte objednáno";
|
||||
|
||||
@override
|
||||
String get error => "Chyba";
|
||||
|
||||
@override
|
||||
String get needRemember =>
|
||||
"Musíte své přihlašovací údaje uložit na přihlašovací obrazovce";
|
||||
}
|
||||
|
|
|
@ -215,4 +215,11 @@ class LanguageEn extends Languages {
|
|||
|
||||
@override
|
||||
String get lunchNotif => "Today's ordered meal";
|
||||
|
||||
@override
|
||||
String get error => "Error";
|
||||
|
||||
@override
|
||||
String get needRemember =>
|
||||
"You need to save your login details on the login screen first";
|
||||
}
|
||||
|
|
|
@ -428,16 +428,23 @@ class _JidelnicekPageState extends State<JidelnicekPage> {
|
|||
child: Text(
|
||||
"${den.day}. ${den.month}. ${den.year} - $denTydne")),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
den = den.add(const Duration(days: 1));
|
||||
if (den.weekday == 6 && _skipWeekend) {
|
||||
den = den.add(const Duration(days: 2));
|
||||
}
|
||||
nactiJidlo();
|
||||
});
|
||||
},
|
||||
icon: const Icon(Icons.arrow_right)),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
den = den.add(const Duration(days: 1));
|
||||
if (den.weekday == 6 && _skipWeekend) {
|
||||
den = den.add(const Duration(days: 2));
|
||||
}
|
||||
nactiJidlo();
|
||||
});
|
||||
},
|
||||
icon: const Icon(Icons.arrow_right),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () => setState(() {
|
||||
den = DateTime.now();
|
||||
nactiJidlo();
|
||||
}),
|
||||
icon: const Icon(Icons.calendar_today))
|
||||
]),
|
||||
SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
|
|
|
@ -27,10 +27,12 @@ class _NastaveniState extends State<Nastaveni> {
|
|||
bool _preskakovatVikend = false;
|
||||
bool _kontrolovatTyden = false;
|
||||
bool _oznameniObed = false;
|
||||
bool _zapamatovany = false;
|
||||
TimeOfDay _oznameniCas = TimeOfDay.now();
|
||||
|
||||
void najitNastaveni() async {
|
||||
var preferences = await SharedPreferences.getInstance();
|
||||
_zapamatovany = await LoginManager.zapamatovat();
|
||||
setState(() {
|
||||
_ukladatOffline = preferences.getBool("offline") ?? false;
|
||||
_preskakovatVikend = preferences.getBool("skip") ?? false;
|
||||
|
@ -118,79 +120,66 @@ class _NastaveniState extends State<Nastaveni> {
|
|||
Flexible(child: Text(Languages.of(context)!.notifyLunch)),
|
||||
Switch(
|
||||
value: _oznameniObed,
|
||||
thumbColor: (!_zapamatovany
|
||||
? MaterialStateProperty.all(Colors.grey)
|
||||
: null),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_oznameniObed = value;
|
||||
zmenitNastaveni("oznamit",
|
||||
value); // TODO: změnit pouze s uloženými údaji
|
||||
});
|
||||
if (!_zapamatovany) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (bc) => AlertDialog(
|
||||
title: Text(Languages.of(context)!.error),
|
||||
content:
|
||||
Text(Languages.of(context)!.needRemember),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(Languages.of(context)!.ok),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
)
|
||||
],
|
||||
));
|
||||
} else {
|
||||
setState(() {
|
||||
_oznameniObed = value;
|
||||
if (_oznameniObed) {
|
||||
vytvoritOznameni(casNaDate(_oznameniCas));
|
||||
}
|
||||
zmenitNastaveni("oznamit", value);
|
||||
});
|
||||
}
|
||||
})
|
||||
],
|
||||
),
|
||||
Text(Languages.of(context)!.notifyAt),
|
||||
TextButton(
|
||||
style: ButtonStyle(
|
||||
textStyle: MaterialStateProperty.all(TextStyle(
|
||||
color: (_oznameniObed) ? Colors.grey : Colors.purple))),
|
||||
onPressed: () async {
|
||||
if (_oznameniObed) {
|
||||
var cas = await showTimePicker(
|
||||
context: context, initialTime: _oznameniCas);
|
||||
if (cas != null) {
|
||||
var prefs = await SharedPreferences.getInstance();
|
||||
prefs.setString(
|
||||
"oznameni_cas",
|
||||
casNaDate(cas)
|
||||
.toString()); // aktualizovat vybraný čas
|
||||
var d = await LoginManager.getDetails(); // získat údaje
|
||||
if (d != null) {
|
||||
// Nové oznámení
|
||||
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);
|
||||
|
||||
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);
|
||||
debugPrint(casNaDate(cas).toString());
|
||||
var l = tz.getLocation(
|
||||
await FlutterNativeTimezone.getLocalTimezone());
|
||||
await widget.n.zonedSchedule(
|
||||
// Vytvoří nové oznámení pro daný čas a datum
|
||||
0,
|
||||
Languages.of(context)!.lunchNotif,
|
||||
"${jidlo.nazev} - ${jidlo.varianta}",
|
||||
tz.TZDateTime.from(casNaDate(cas), l),
|
||||
const NotificationDetails(
|
||||
android: androidSpec, iOS: iOSpec),
|
||||
androidAllowWhileIdle: true,
|
||||
uiLocalNotificationDateInterpretation:
|
||||
UILocalNotificationDateInterpretation
|
||||
.absoluteTime);
|
||||
} on StateError catch (_) {
|
||||
// nenalezeno
|
||||
}
|
||||
}
|
||||
}
|
||||
onPressed: () async {
|
||||
if (_oznameniObed) {
|
||||
var cas = await showTimePicker(
|
||||
context: context, initialTime: _oznameniCas);
|
||||
if (cas != null) {
|
||||
var prefs = await SharedPreferences.getInstance();
|
||||
prefs.setString("oznameni_cas",
|
||||
casNaDate(cas).toString()); // aktualizovat vybraný čas
|
||||
var den = casNaDate(cas);
|
||||
debugPrint(den.isAfter(DateTime.now()).toString());
|
||||
if (den.isAfter(DateTime.now())) {
|
||||
// znovu vytvořit oznámení POUZE když je čas v budoucnosti
|
||||
vytvoritOznameni(den);
|
||||
}
|
||||
setState(() {
|
||||
_oznameniCas = cas ?? _oznameniCas;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
"${(_oznameniCas.hour < 10 ? "0" : "") + _oznameniCas.hour.toString()}:${(_oznameniCas.minute < 10 ? "0" : "") + _oznameniCas.minute.toString()}")),
|
||||
setState(() {
|
||||
_oznameniCas = cas ?? _oznameniCas;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
"${(_oznameniCas.hour < 10 ? "0" : "") + _oznameniCas.hour.toString()}:${(_oznameniCas.minute < 10 ? "0" : "") + _oznameniCas.minute.toString()}",
|
||||
style: TextStyle(
|
||||
color: (!_oznameniObed) ? Colors.grey : Colors.purple),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)),
|
||||
|
@ -208,4 +197,42 @@ class _NastaveniState extends State<Nastaveni> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void vytvoritOznameni(DateTime den) async {
|
||||
await widget.n.cancelAll();
|
||||
var d = await LoginManager.getDetails(); // získat údaje
|
||||
if (d != null) {
|
||||
// Nové oznámení
|
||||
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);
|
||||
|
||||
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);
|
||||
var l =
|
||||
tz.getLocation(await FlutterNativeTimezone.getLocalTimezone());
|
||||
await widget.n.zonedSchedule(
|
||||
// Vytvoří nové oznámení pro daný čas a datum
|
||||
0,
|
||||
Languages.of(context)!.lunchNotif,
|
||||
"${jidlo.nazev} - ${jidlo.varianta}",
|
||||
tz.TZDateTime.from(den, l),
|
||||
const NotificationDetails(android: androidSpec, iOS: iOSpec),
|
||||
androidAllowWhileIdle: true,
|
||||
uiLocalNotificationDateInterpretation:
|
||||
UILocalNotificationDateInterpretation.absoluteTime);
|
||||
} on StateError catch (_) {
|
||||
// nenalezeno
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.2.0+14
|
||||
version: 1.3.0+15
|
||||
|
||||
environment:
|
||||
sdk: ">=2.16.1 <3.0.0"
|
||||
|
|
Reference in a new issue