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
|
# 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
|
||||||
|
- Přidat k jídelníčku tlačítko, které zobrazí dnešní jídelníček
|
||||||
# 1.2.0
|
# 1.2.0
|
||||||
- Přidat možnost zobrazení oznámení v případě neobjednaného jídla na příští týden
|
- 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
|
- 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:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||||
android:hardwareAccelerated="true"
|
android:hardwareAccelerated="true"
|
||||||
android:windowSoftInputMode="adjustResize"
|
android:windowSoftInputMode="adjustResize"
|
||||||
android:screenOrientation="portrait">
|
android:screenOrientation="portrait"
|
||||||
|
android:showWhenLocked="true">
|
||||||
<!-- Specifies an Android theme to apply to this Activity as soon as
|
<!-- Specifies an Android theme to apply to this Activity as soon as
|
||||||
the Android process has started. This theme is visible to the user
|
the Android process has started. This theme is visible to the user
|
||||||
while the Flutter UI initializes. After that, this theme continues
|
while the Flutter UI initializes. After that, this theme continues
|
||||||
|
|
|
@ -156,4 +156,8 @@ abstract class Languages {
|
||||||
|
|
||||||
// Oznámit před obědem
|
// Oznámit před obědem
|
||||||
String get lunchNotif;
|
String get lunchNotif;
|
||||||
|
|
||||||
|
String get error;
|
||||||
|
|
||||||
|
String get needRemember;
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,4 +217,11 @@ class LanguageCz extends Languages {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get lunchNotif => "Dnes máte objednáno";
|
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";
|
||||||
}
|
}
|
||||||
|
|
|
@ -212,7 +212,14 @@ class LanguageEn extends Languages {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get notifyLunch => "Send a notification with meal info";
|
String get notifyLunch => "Send a notification with meal info";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get lunchNotif => "Today's ordered meal";
|
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(
|
child: Text(
|
||||||
"${den.day}. ${den.month}. ${den.year} - $denTydne")),
|
"${den.day}. ${den.month}. ${den.year} - $denTydne")),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
den = den.add(const Duration(days: 1));
|
den = den.add(const Duration(days: 1));
|
||||||
if (den.weekday == 6 && _skipWeekend) {
|
if (den.weekday == 6 && _skipWeekend) {
|
||||||
den = den.add(const Duration(days: 2));
|
den = den.add(const Duration(days: 2));
|
||||||
}
|
}
|
||||||
nactiJidlo();
|
nactiJidlo();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
icon: const Icon(Icons.arrow_right)),
|
icon: const Icon(Icons.arrow_right),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () => setState(() {
|
||||||
|
den = DateTime.now();
|
||||||
|
nactiJidlo();
|
||||||
|
}),
|
||||||
|
icon: const Icon(Icons.calendar_today))
|
||||||
]),
|
]),
|
||||||
SingleChildScrollView(
|
SingleChildScrollView(
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
|
|
|
@ -27,10 +27,12 @@ class _NastaveniState extends State<Nastaveni> {
|
||||||
bool _preskakovatVikend = false;
|
bool _preskakovatVikend = false;
|
||||||
bool _kontrolovatTyden = false;
|
bool _kontrolovatTyden = false;
|
||||||
bool _oznameniObed = false;
|
bool _oznameniObed = false;
|
||||||
|
bool _zapamatovany = false;
|
||||||
TimeOfDay _oznameniCas = TimeOfDay.now();
|
TimeOfDay _oznameniCas = TimeOfDay.now();
|
||||||
|
|
||||||
void najitNastaveni() async {
|
void najitNastaveni() async {
|
||||||
var preferences = await SharedPreferences.getInstance();
|
var preferences = await SharedPreferences.getInstance();
|
||||||
|
_zapamatovany = await LoginManager.zapamatovat();
|
||||||
setState(() {
|
setState(() {
|
||||||
_ukladatOffline = preferences.getBool("offline") ?? false;
|
_ukladatOffline = preferences.getBool("offline") ?? false;
|
||||||
_preskakovatVikend = preferences.getBool("skip") ?? false;
|
_preskakovatVikend = preferences.getBool("skip") ?? false;
|
||||||
|
@ -118,79 +120,66 @@ class _NastaveniState extends State<Nastaveni> {
|
||||||
Flexible(child: Text(Languages.of(context)!.notifyLunch)),
|
Flexible(child: Text(Languages.of(context)!.notifyLunch)),
|
||||||
Switch(
|
Switch(
|
||||||
value: _oznameniObed,
|
value: _oznameniObed,
|
||||||
|
thumbColor: (!_zapamatovany
|
||||||
|
? MaterialStateProperty.all(Colors.grey)
|
||||||
|
: null),
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState(() {
|
if (!_zapamatovany) {
|
||||||
_oznameniObed = value;
|
showDialog(
|
||||||
zmenitNastaveni("oznamit",
|
context: context,
|
||||||
value); // TODO: změnit pouze s uloženými údaji
|
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),
|
Text(Languages.of(context)!.notifyAt),
|
||||||
TextButton(
|
TextButton(
|
||||||
style: ButtonStyle(
|
onPressed: () async {
|
||||||
textStyle: MaterialStateProperty.all(TextStyle(
|
if (_oznameniObed) {
|
||||||
color: (_oznameniObed) ? Colors.grey : Colors.purple))),
|
var cas = await showTimePicker(
|
||||||
onPressed: () async {
|
context: context, initialTime: _oznameniCas);
|
||||||
if (_oznameniObed) {
|
if (cas != null) {
|
||||||
var cas = await showTimePicker(
|
var prefs = await SharedPreferences.getInstance();
|
||||||
context: context, initialTime: _oznameniCas);
|
prefs.setString("oznameni_cas",
|
||||||
if (cas != null) {
|
casNaDate(cas).toString()); // aktualizovat vybraný čas
|
||||||
var prefs = await SharedPreferences.getInstance();
|
var den = casNaDate(cas);
|
||||||
prefs.setString(
|
debugPrint(den.isAfter(DateTime.now()).toString());
|
||||||
"oznameni_cas",
|
if (den.isAfter(DateTime.now())) {
|
||||||
casNaDate(cas)
|
// znovu vytvořit oznámení POUZE když je čas v budoucnosti
|
||||||
.toString()); // aktualizovat vybraný čas
|
vytvoritOznameni(den);
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
setState(() {
|
|
||||||
_oznameniCas = cas ?? _oznameniCas;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
setState(() {
|
||||||
child: Text(
|
_oznameniCas = cas ?? _oznameniCas;
|
||||||
"${(_oznameniCas.hour < 10 ? "0" : "") + _oznameniCas.hour.toString()}:${(_oznameniCas.minute < 10 ? "0" : "") + _oznameniCas.minute.toString()}")),
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
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.
|
# 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.2.0+14
|
version: 1.3.0+15
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.16.1 <3.0.0"
|
sdk: ">=2.16.1 <3.0.0"
|
||||||
|
|
Reference in a new issue