diff --git a/CHANGELOG.md b/CHANGELOG.md index e1ef41d..c2d996b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.8.0 +- aktualizace závislostí +- předělání nastavení +- změna nastavení nyní nevyžaduje restart aplikace # 1.7.0 - Implementovat Material 3 (Android) - Upravit chování dle platformy diff --git a/lib/l10n/app_cs.arb b/lib/l10n/app_cs.arb index 7118de6..7c06d85 100644 --- a/lib/l10n/app_cs.arb +++ b/lib/l10n/app_cs.arb @@ -1 +1,82 @@ -{"about":"O Aplikaci","agree":"Souhlasím","appName":"OpenCanteen","balance":"Kredit: ","cannotOrder":"Toto jídlo není možné objednat.","close":"Zavřít","copyright":"© 2022 Matyáš Caras a přispěvatelé","disagree":"Nesouhlasím","errorContacting":"Nastala chyba při kontaktování serveru, zkontrolujte připojení","errorOrdering":"Jídlo se nepodařilo objednat","exchange":"Burza","exchangeError":"Nepodařilo se vložit jídlo na burzu","friday":"Pátek","home":"Domů","httpLogin":"Snažíte se přihlásit přes nešifrované spojení HTTP, jste si jisti, že tak chcete učinit?","iCanteenUrl":"iCanteen URL","inExchange":"V BURZE","license":"Vydáno pod licencí GNU GPLv3","loading":"Načítání...","logIn":"Přihlášení","loggingIn":"Přihlašuji vás...","loginFailed":"Přihlášení se nezdařilo","menu":"Jídelníček","monday":"Pondělí","mustLogout":"Online přejdete přetažením dolů.","no":"Ne","noChange":"Ne, změnit","noExchange":"Žádné jídlo v burze","noFood":"Žádné jídlo pro tento den","notOfficial":"Toto není oficiální aplikace k ovládání iCanteen. Autor neručí za ztráty nebo nefunkčnost v souvislosti s používáním této aplikace. Pokračováním souhlasíte.","offline":"JSTE OFFLINE","ok":"OK","order":"Objednat","orderSuccess":"Jídlo bylo úspěšně objednáno","ordered":"Objednáno","ordering":"Objednávám...","password":"Heslo","pullToReload":"Potáhněte zvrchu pro načtení","rememberMe":"Zapamatovat si mě","reportBugs":"Zpětná vazba","saturday":"Sobota","saveOffline":"Ukládat jídelníček na dnešní den offline","settings":"Nastavení","signOut":"Odhlásit se","skipWeekend":"Při procházení menu přeskočit víkend","sunday":"Neděle","thursday":"Čtvrtek","tuesday":"Úterý","username":"Uživatelské jméno","verifyExchange":"Opravdu chcete vložit jídlo na burzu?","warning":"Pozor!","wednesday":"Středa","yes":"Ano","aboutFromExch":"Žádné jídlo? Žádný problém!","aboutOrder":"Klepnutím objednáte","aboutToExch":"Nemáte chuť?","appDesc":"OpenCanteen je neoficiální aplikace pro přístup do obědového systému iCanteen","howFromExch":"Z vysunovacího menu přejděte do burzy a objednejte si z dostupných jídel","howOrder":"Jednoduše klepněte na jídlo s modrým políčkem a máte objednáno","howToExch":"Stačí dlouze podržet jméno objednaného jídla a můžete ho přesunout na nebo z burzy","welcome":"Vítejte v OpenCanteen","next":"Další","checkOrdered":"Kontrolovat, jestli mám objednáno na příští týden","noOrder":"Na přístí týden nemáte objednané žádné jídlo!","corrupted":"Nastal problém s dešifrováním uložených údajů, prosím zkuste vyčistit veškerá data této aplikace.","notifyAt":"Odeslat v","notifyLunch":"V určený čas odeslat notifikaci s informacemi o obědě","lunchNotif":"Dnes máte objednáno","error":"Chyba","needRemember":"Musíte své přihlašovací údaje uložit na přihlašovací obrazovce","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í.","signOutWarn":"Opravdu se chcete odhlásit?","jump":"Přeskočit","source":"Zdrojový kód","review":"Ohodnotit aplikaci","saveCount":"Počet dnů dostupných offline (Akt. limit je 7)","errorSaving":"Při ukládání offline nastala chyba, zkuste to znovu později.","todayTooltip":"Přejít na dnešní jídelníček"} \ No newline at end of file +{ + "about": "O Aplikaci", + "agree": "Souhlasím", + "appName": "OpenCanteen", + "balance": "Kredit: ", + "cannotOrder": "Toto jídlo není možné objednat.", + "close": "Zavřít", + "copyright": "© 2022 Matyáš Caras a přispěvatelé", + "disagree": "Nesouhlasím", + "errorContacting": "Nastala chyba při kontaktování serveru, zkontrolujte připojení", + "errorOrdering": "Jídlo se nepodařilo objednat", + "exchange": "Burza", + "exchangeError": "Nepodařilo se vložit jídlo na burzu", + "friday": "Pátek", + "home": "Domů", + "httpLogin": "Snažíte se přihlásit přes nešifrované spojení HTTP, jste si jisti, že tak chcete učinit?", + "iCanteenUrl": "iCanteen URL", + "inExchange": "V BURZE", + "license": "Vydáno pod licencí GNU GPLv3", + "loading": "Načítání...", + "logIn": "Přihlášení", + "loggingIn": "Přihlašuji vás...", + "loginFailed": "Přihlášení se nezdařilo", + "menu": "Jídelníček", + "monday": "Pondělí", + "mustLogout": "Online přejdete přetažením dolů.", + "no": "Ne", + "noChange": "Ne, změnit", + "noExchange": "Žádné jídlo v burze", + "noFood": "Žádné jídlo pro tento den", + "notOfficial": "Toto není oficiální aplikace k ovládání iCanteen. Autor neručí za ztráty nebo nefunkčnost v souvislosti s používáním této aplikace. Pokračováním souhlasíte.", + "offline": "JSTE OFFLINE", + "ok": "OK", + "order": "Objednat", + "orderSuccess": "Jídlo bylo úspěšně objednáno", + "ordered": "Objednáno", + "ordering": "Objednávám...", + "password": "Heslo", + "pullToReload": "Potáhněte zvrchu pro načtení", + "rememberMe": "Zapamatovat si mě", + "reportBugs": "Zpětná vazba", + "saturday": "Sobota", + "saveOffline": "Ukládat jídelníček offline", + "settings": "Nastavení", + "signOut": "Odhlásit se", + "skipWeekend": "Při procházení menu přeskočit víkend", + "sunday": "Neděle", + "thursday": "Čtvrtek", + "tuesday": "Úterý", + "username": "Uživatelské jméno", + "verifyExchange": "Opravdu chcete vložit jídlo na burzu?", + "warning": "Pozor!", + "wednesday": "Středa", + "yes": "Ano", + "aboutFromExch": "Žádné jídlo? Žádný problém!", + "aboutOrder": "Klepnutím objednáte", + "aboutToExch": "Nemáte chuť?", + "appDesc": "OpenCanteen je neoficiální aplikace pro přístup do obědového systému iCanteen", + "howFromExch": "Z vysunovacího menu přejděte do burzy a objednejte si z dostupných jídel", + "howOrder": "Jednoduše klepněte na jídlo s modrým políčkem a máte objednáno", + "howToExch": "Stačí dlouze podržet jméno objednaného jídla a můžete ho přesunout na nebo z burzy", + "welcome": "Vítejte v OpenCanteen", + "next": "Další", + "checkOrdered": "Kontrolovat, jestli mám objednáno na příští týden", + "noOrder": "Na přístí týden nemáte objednané žádné jídlo!", + "corrupted": "Nastal problém s dešifrováním uložených údajů, prosím zkuste vyčistit veškerá data této aplikace.", + "notifyAt": "Odeslat v", + "notifyLunch": "V určený čas odeslat notifikaci s informacemi o obědě", + "lunchNotif": "Dnes máte objednáno", + "error": "Chyba", + "needRemember": "Musíte své přihlašovací údaje uložit na přihlašovací obrazovce", + "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í.", + "signOutWarn": "Opravdu se chcete odhlásit?", + "jump": "Přeskočit", + "source": "Zdrojový kód", + "review": "Ohodnotit aplikaci", + "saveCount": "Počet dnů dostupných offline (Akt. limit je 7)", + "errorSaving": "Při ukládání offline nastala chyba, zkuste to znovu později.", + "todayTooltip": "Přejít na dnešní jídelníček", + "settingsExperience":"Zážitek", + "settingsFunctions":"Extra funkce" +} \ No newline at end of file diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 76ceadb..21ea1cb 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -1 +1,82 @@ -{"about":"About","agree":"I agree","appName":"OpenCanteen","balance":"Balance: ","cannotOrder":"This food cannot be ordered.","close":"Close","copyright":"© 2022 Matyáš Caras and contributors","disagree":"I disagree","errorContacting":"Failed to contact the server, check your connection.","errorOrdering":"Could not order food.","exchange":"Exchange","exchangeError":"Could not put food on exchange.","friday":"Friday","home":"Home","httpLogin":"You are trying to sign in using an insecure HTTP connection, are you sure you want to continue?","iCanteenUrl":"iCanteen URL","inExchange":"ON EXCHANGE","license":"Released under the GNU GPLv3","loading":"Loading...","logIn":"Sign in","loggingIn":"Signing you in...","loginFailed":"Sign in failed","menu":"Food Menu","monday":"Monday","mustLogout":"To go online, pull down.","no":"No","noChange":"No, change","noExchange":"No meal in exchange","noFood":"No meal for this day","notOfficial":"This is not an official app for accessing iCanteen. The author is not responsible for non-functionality or losses while using this app. By continuing you agree.","offline":"YOU ARE OFFLINE","ok":"OK","order":"Order","orderSuccess":"Meal ordered succesfully","ordered":"Ordered","ordering":"Ordering...","password":"Password","pullToReload":"Pull to reload","rememberMe":"Remember me","reportBugs":"Feedback","saturday":"Saturday","saveOffline":"Save today's menu offline","settings":"Settings","signOut":"Sign out","skipWeekend":"Skip weekends when browsing menu","sunday":"Sunday","thursday":"Thursday","tuesday":"Tuesday","username":"Username","verifyExchange":"Are you sure you want to put this meal on exchange?","warning":"Warning!","wednesday":"Wednesday","yes":"Yes","appDesc":"OpenCanteen is a mobile app for accessing iCanteen.","welcome":"Welcome to OpenCanteen","aboutOrder":"Order with a tap","howOrder":"Simply tap on a meal with a blue checkbox next to it and it's done!","aboutToExch":"Don't want your food?","howToExch":"If you cannot cancel your order, simply long-tap on the ordered food and put it into the exchange.","aboutFromExch":"No food? No problem!","howFromExch":"Simply check the exchange from the sidebar and order when a meal is available.","next":"Next","checkOrdered":"Check if I have ordered food for the next week","noOrder":"You did not order any food for the next week!","corrupted":"The saved credentials seem to be corrupted, please try clearing the application's data.","notifyAt":"Send notification at","notifyLunch":"Send a notification with meal info","lunchNotif":"Today's ordered meal","error":"Error","needRemember":"You need to save your login details on the login screen first","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.","signOutWarn":"Do you really want to sign out?","jump":"Jump","source":"Source code","review":"Review the app","saveCount":"Number of days to save offline (Current limit is 7)","errorSaving":"An error occured while trying to save menu offline, try again later.","todayTooltip":"Go to today's meal"} \ No newline at end of file +{ + "about": "About", + "agree": "I agree", + "appName": "OpenCanteen", + "balance": "Balance: ", + "cannotOrder": "This food cannot be ordered.", + "close": "Close", + "copyright": "© 2022 Matyáš Caras and contributors", + "disagree": "I disagree", + "errorContacting": "Failed to contact the server, check your connection.", + "errorOrdering": "Could not order food.", + "exchange": "Exchange", + "exchangeError": "Could not put food on exchange.", + "friday": "Friday", + "home": "Home", + "httpLogin": "You are trying to sign in using an insecure HTTP connection, are you sure you want to continue?", + "iCanteenUrl": "iCanteen URL", + "inExchange": "ON EXCHANGE", + "license": "Released under the GNU GPLv3", + "loading": "Loading...", + "logIn": "Sign in", + "loggingIn": "Signing you in...", + "loginFailed": "Sign in failed", + "menu": "Food Menu", + "monday": "Monday", + "mustLogout": "To go online, pull down.", + "no": "No", + "noChange": "No, change", + "noExchange": "No meal in exchange", + "noFood": "No meal for this day", + "notOfficial": "This is not an official app for accessing iCanteen. The author is not responsible for non-functionality or losses while using this app. By continuing you agree.", + "offline": "YOU ARE OFFLINE", + "ok": "OK", + "order": "Order", + "orderSuccess": "Meal ordered succesfully", + "ordered": "Ordered", + "ordering": "Ordering...", + "password": "Password", + "pullToReload": "Pull to reload", + "rememberMe": "Remember me", + "reportBugs": "Feedback", + "saturday": "Saturday", + "saveOffline": "Save menu offline", + "settings": "Settings", + "signOut": "Sign out", + "skipWeekend": "Skip weekends when browsing menu", + "sunday": "Sunday", + "thursday": "Thursday", + "tuesday": "Tuesday", + "username": "Username", + "verifyExchange": "Are you sure you want to put this meal on exchange?", + "warning": "Warning!", + "wednesday": "Wednesday", + "yes": "Yes", + "appDesc": "OpenCanteen is a mobile app for accessing iCanteen.", + "welcome": "Welcome to OpenCanteen", + "aboutOrder": "Order with a tap", + "howOrder": "Simply tap on a meal with a blue checkbox next to it and it's done!", + "aboutToExch": "Don't want your food?", + "howToExch": "If you cannot cancel your order, simply long-tap on the ordered food and put it into the exchange.", + "aboutFromExch": "No food? No problem!", + "howFromExch": "Simply check the exchange from the sidebar and order when a meal is available.", + "next": "Next", + "checkOrdered": "Check if I have ordered food for the next week", + "noOrder": "You did not order any food for the next week!", + "corrupted": "The saved credentials seem to be corrupted, please try clearing the application's data.", + "notifyAt": "Send notification at", + "notifyLunch": "Send a notification with meal info", + "lunchNotif": "Today's ordered meal", + "error": "Error", + "needRemember": "You need to save your login details on the login screen first", + "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.", + "signOutWarn": "Do you really want to sign out?", + "jump": "Jump", + "source": "Source code", + "review": "Review the app", + "saveCount": "Number of days to save offline (Current limit is 7)", + "errorSaving": "An error occured while trying to save menu offline, try again later.", + "todayTooltip": "Go to today's meal", + "settingsExperience":"App Experience", + "settingsFunctions":"Extra Functions" +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 07f8b37..7b41181 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -35,6 +35,7 @@ Copyright (C) 2022 Matyáš Caras a přispěvatelé final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); +final settings = SettingsManager(); /// Used to setup notifications about ordered food void setupNotification(SharedPreferences prefs, tz.Location l) async { @@ -104,6 +105,9 @@ void main() async { if (prefs.getBool("oznamit") ?? false) { setupNotification(prefs, l); } + settings.checkOrdered = prefs.getBool("tyden") ?? false; + settings.saveOffline = prefs.getBool("oznamit") ?? false; + settings.skipWeekend = prefs.getBool("skip") ?? false; // notif library setup const AndroidInitializationSettings initializationSettingsAndroid = diff --git a/lib/okna/jidelnicek.dart b/lib/okna/jidelnicek.dart index a13b9b5..c83bdf3 100644 --- a/lib/okna/jidelnicek.dart +++ b/lib/okna/jidelnicek.dart @@ -4,6 +4,7 @@ import 'dart:io'; import 'package:canteenlib/canteenlib.dart'; import 'package:flutter/material.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; +import 'package:opencanteen/main.dart'; import 'package:opencanteen/okna/login.dart'; import 'package:opencanteen/okna/nastaveni.dart'; import 'package:opencanteen/pw/platformbutton.dart'; @@ -28,11 +29,9 @@ class _MealViewState extends State { DateTime day = DateTime.now(); String dayOWeek = ""; double balance = 0.0; - bool _skipWeekend = false; void checkWeek(BuildContext context) async { - var prefs = await SharedPreferences.getInstance(); - if (prefs.getBool("tyden") ?? false) { + if (settings.checkOrdered) { // Check if user has ordered a meal in the next week var pristi = day.add(const Duration(days: 6)); for (var i = 0; i < 5; i++) { @@ -87,15 +86,16 @@ class _MealViewState extends State { default: dayOWeek = AppLocalizations.of(context)!.monday; } - var uzivatel = await widget.canteen.ziskejUzivatele().catchError( - (o) { - if (!widget.canteen.prihlasen) { - Navigator.pushReplacement( - context, platformRouter((c) => const LoginPage())); - } - return Uzivatel(kredit: 0); - }, - ); + Uzivatel uzivatel; + try { + uzivatel = await widget.canteen.ziskejUzivatele(); + } catch (e) { + if (!widget.canteen.prihlasen) { + Navigator.pushReplacement( + context, platformRouter((c) => const LoginPage())); + } + return; + } balance = uzivatel.kredit; var jd = await widget.canteen.jidelnicekDen(den: day).catchError((_) { showInfo(context, AppLocalizations.of(context)!.errorContacting); @@ -386,58 +386,54 @@ class _MealViewState extends State { } void loadSettings() async { - var prefs = await SharedPreferences.getInstance(); - _skipWeekend = prefs.getBool("skip") ?? false; if (!mounted) return; checkWeek(context); } void saveOffline() async { + if (!settings.saveOffline) return; + // clear offline storage + Directory appDocDir = await getApplicationDocumentsDirectory(); + for (var f in appDocDir.listSync()) { + if (f.path.contains("jidelnicek")) { + f.deleteSync(); + } + } var prefs = await SharedPreferences.getInstance(); - if (prefs.getBool("offline") ?? false) { - // clear offline storage - Directory appDocDir = await getApplicationDocumentsDirectory(); - for (var f in appDocDir.listSync()) { - if (f.path.contains("jidelnicek")) { - f.deleteSync(); + // save X meal lists + var pocet = prefs.getInt("offline_pocet") ?? 1; + if (pocet > 7) pocet = 7; + for (var i = 0; i < pocet; i++) { + var d = day.add(Duration(days: i)); + Jidelnicek? j; + try { + j = await widget.canteen.jidelnicekDen(den: d); + } catch (e) { + if (!widget.canteen.prihlasen) { + if (!mounted) return; + ScaffoldMessenger.of(context).hideCurrentSnackBar(); + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + content: Text(AppLocalizations.of(context)!.errorSaving), + duration: const Duration(seconds: 5), + )); + break; } } - - // save X meal lists - var pocet = prefs.getInt("offline_pocet") ?? 1; - if (pocet > 7) pocet = 7; - for (var i = 0; i < pocet; i++) { - var d = day.add(Duration(days: i)); - Jidelnicek? j; - try { - j = await widget.canteen.jidelnicekDen(den: d); - } catch (e) { - if (!widget.canteen.prihlasen) { - if (!mounted) return; - ScaffoldMessenger.of(context).hideCurrentSnackBar(); - ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text(AppLocalizations.of(context)!.errorSaving), - duration: const Duration(seconds: 5), - )); - break; - } - } - var soubor = File( - "${appDocDir.path}/jidelnicek_${d.year}-${d.month}-${d.day}.json"); - soubor.createSync(); - var jidla = []; - for (var jidlo in j!.jidla) { - jidla.add({ - "nazev": jidlo.nazev, - "varianta": jidlo.varianta, - "objednano": jidlo.objednano, - "cena": jidlo.cena, - "naBurze": jidlo.naBurze, - "den": d.toString() - }); - } - await soubor.writeAsString(json.encode(jidla)); + var soubor = File( + "${appDocDir.path}/jidelnicek_${d.year}-${d.month}-${d.day}.json"); + soubor.createSync(); + var jidla = []; + for (var jidlo in j!.jidla) { + jidla.add({ + "nazev": jidlo.nazev, + "varianta": jidlo.varianta, + "objednano": jidlo.objednano, + "cena": jidlo.cena, + "naBurze": jidlo.naBurze, + "den": d.toString() + }); } + await soubor.writeAsString(json.encode(jidla)); } } @@ -491,7 +487,7 @@ class _MealViewState extends State { onPressed: () { setState(() { day = day.subtract(const Duration(days: 1)); - if (day.weekday == 7 && _skipWeekend) { + if (day.weekday == 7 && settings.skipWeekend) { day = day.subtract(const Duration(days: 2)); } loadMeals(); @@ -519,7 +515,7 @@ class _MealViewState extends State { onPressed: () { setState(() { day = day.add(const Duration(days: 1)); - if (day.weekday == 6 && _skipWeekend) { + if (day.weekday == 6 && settings.skipWeekend) { day = day.add(const Duration(days: 2)); } loadMeals(); @@ -556,7 +552,7 @@ class _MealViewState extends State { if (details.primaryVelocity?.compareTo(0) == -1) { setState(() { day = day.add(const Duration(days: 1)); - if (day.weekday == 6 && _skipWeekend) { + if (day.weekday == 6 && settings.skipWeekend) { day = day.add(const Duration(days: 2)); } loadMeals(); @@ -565,7 +561,7 @@ class _MealViewState extends State { setState( () { day = day.subtract(const Duration(days: 1)); - if (day.weekday == 7 && _skipWeekend) { + if (day.weekday == 7 && settings.skipWeekend) { day = day.subtract(const Duration(days: 2)); } loadMeals(); diff --git a/lib/okna/nastaveni.dart b/lib/okna/nastaveni.dart index ba645d8..6d19ad6 100644 --- a/lib/okna/nastaveni.dart +++ b/lib/okna/nastaveni.dart @@ -10,6 +10,7 @@ import 'package:opencanteen/pw/platformdialog.dart'; import 'package:opencanteen/pw/platformfield.dart'; import 'package:opencanteen/pw/platformswitch.dart'; import 'package:path_provider/path_provider.dart'; +import 'package:settings_ui/settings_ui.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:timezone/timezone.dart' as tz; @@ -76,167 +77,177 @@ class _AndroidNastaveniState extends State { appBar: AppBar( title: Text(AppLocalizations.of(context)!.settings), ), - body: Center( - child: SizedBox( - width: MediaQuery.of(context).size.width / 1.1, - child: Column( - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text(AppLocalizations.of(context)!.saveOffline), - PlatformSwitch( - value: _saveOffline, - onChanged: (value) { - setState(() { - _saveOffline = value; - clear(value); - changeSetting("offline", value); - }); - }, - ) - ], - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text(AppLocalizations.of(context)!.saveCount), - SizedBox( - width: 35, - child: PlatformField( - controller: _countController, - enabled: _saveOffline, - keyboardType: TextInputType.number, - inputFormatters: [FilteringTextInputFormatter.digitsOnly], - onChanged: (c) { - var cislo = int.tryParse(c); - if (cislo != null) { - preferences!.setInt("offline_pocet", cislo); - } - }, - ), - ) - ], - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text(AppLocalizations.of(context)!.skipWeekend), - PlatformSwitch( - value: _skipWeekend, - onChanged: (value) { - setState( - () { - _skipWeekend = value; - changeSetting("skip", value); - }, - ); - }, - ) - ], - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Flexible( - child: Text(AppLocalizations.of(context)!.checkOrdered)), - PlatformSwitch( - value: _checkWeek, - onChanged: (value) { - setState( - () { - _checkWeek = value; - changeSetting("tyden", value); - }, - ); - }, - ) - ], - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Flexible( - child: Text(AppLocalizations.of(context)!.notifyLunch)), - PlatformSwitch( - value: _notifyMeal, - thumbColor: (!_remember ? Colors.grey : null), - onChanged: (value) { - if (!_remember) { - showDialog( - context: context, - builder: (bc) => PlatformDialog( - title: AppLocalizations.of(context)!.error, - content: AppLocalizations.of(context)!.needRemember, - actions: [ - PlatformButton( - text: AppLocalizations.of(context)!.ok, - onPressed: () { - Navigator.of(context).pop(); - }, - ) - ], - ), - ); - } else { - setState(() { - _notifyMeal = value; - if (_notifyMeal) { - showDialog( - context: context, - builder: (context) => PlatformDialog( - title: AppLocalizations.of(context)!.warning, - content: - AppLocalizations.of(context)!.notifyWarning, - actions: [ - PlatformButton( - text: AppLocalizations.of(context)!.ok, - onPressed: () { - Navigator.of(context).pop(); - }, - ) - ], - ), - ); - createNotif(timeToDate(_notifTime)); - } - changeSetting("oznamit", value); - }); - } - }, - ) - ], - ), - Text(AppLocalizations.of(context)!.notifyAt), - PlatformButton( - onPressed: () async { - if (_notifyMeal) { - var cas = await showTimePicker( - context: context, initialTime: _notifTime); - if (cas != null) { - var prefs = await SharedPreferences.getInstance(); - prefs.setString( - "oznameni_cas", - timeToDate(cas) - .toString()); // aktualizovat vybraný čas - var den = timeToDate(cas); - debugPrint(den.isAfter(DateTime.now()).toString()); - if (den.isAfter(DateTime.now())) { - // znovu vytvořit oznámení POUZE když je čas v budoucnosti - createNotif(den); - } - } - setState(() { - _notifTime = cas ?? _notifTime; - }); - } + body: SettingsList( + platform: DevicePlatform.device, + sections: [ + SettingsSection( + tiles: [ + SettingsTile.switchTile( + initialValue: _saveOffline, + onToggle: (value) { + _saveOffline = value; + settings.saveOffline = value; + changeSetting("offline", value); + setState(() {}); }, - text: - "${(_notifTime.hour < 10 ? "0" : "") + _notifTime.hour.toString()}:${(_notifTime.minute < 10 ? "0" : "") + _notifTime.minute.toString()}", + title: Text(AppLocalizations.of(context)!.saveOffline), + ), + CustomSettingsTile( + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SizedBox( + width: MediaQuery.of(context).size.width * 0.76, + child: Text( + AppLocalizations.of(context)!.saveCount, + softWrap: true, + style: TextStyle( + fontSize: (Platform.isAndroid) ? 18 : 17, + fontWeight: + (Platform.isAndroid) ? FontWeight.w400 : null, + ), + ), + ), + const SizedBox( + width: 10, + ), + SizedBox( + width: 35, + child: PlatformField( + controller: _countController, + enabled: _saveOffline, + keyboardType: TextInputType.number, + inputFormatters: [ + FilteringTextInputFormatter.digitsOnly + ], + onChanged: (c) { + var cislo = int.tryParse(c); + if (cislo != null) { + preferences!.setInt("offline_pocet", cislo); + } + }, + ), + ) + ], + ), + ), + SettingsTile.switchTile( + initialValue: _skipWeekend, + onToggle: (value) { + _skipWeekend = value; + settings.skipWeekend = value; + changeSetting("skip", value); + setState(() {}); + }, + title: Text(AppLocalizations.of(context)!.skipWeekend), + ), + SettingsTile.switchTile( + initialValue: _checkWeek, + onToggle: (value) { + _checkWeek = value; + settings.checkOrdered = value; + changeSetting("tyden", value); + setState(() {}); + }, + title: Text(AppLocalizations.of(context)!.checkOrdered), ), ], + title: Text(AppLocalizations.of(context)!.settingsExperience), ), - ), + SettingsSection( + tiles: [ + SettingsTile.switchTile( + initialValue: _notifyMeal, + enabled: _remember, + onToggle: (value) { + if (!_remember) { + showDialog( + context: context, + builder: (bc) => PlatformDialog( + title: AppLocalizations.of(context)!.error, + content: AppLocalizations.of(context)!.needRemember, + actions: [ + PlatformButton( + text: AppLocalizations.of(context)!.ok, + onPressed: () { + Navigator.of(bc).pop(); + }, + ) + ], + ), + ); + } else { + _notifyMeal = value; + if (_notifyMeal) { + showDialog( + context: context, + builder: (context) => PlatformDialog( + title: AppLocalizations.of(context)!.warning, + content: AppLocalizations.of(context)!.notifyWarning, + actions: [ + PlatformButton( + text: AppLocalizations.of(context)!.ok, + onPressed: () { + Navigator.of(context).pop(); + }, + ) + ], + ), + ); + createNotif(timeToDate(_notifTime)); + } + changeSetting("oznamit", value); + setState(() {}); + } + }, + title: Text( + AppLocalizations.of(context)!.notifyLunch, + ), + ), + CustomSettingsTile( + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + AppLocalizations.of(context)!.notifyAt, + style: TextStyle( + fontSize: (Platform.isAndroid) ? 18 : 17, + fontWeight: + (Platform.isAndroid) ? FontWeight.w400 : null, + ), + ), + PlatformButton( + textStyle: + TextStyle(fontSize: (Platform.isAndroid ? 18 : 17)), + text: _notifTime.format(context), + onPressed: () async { + if (!_notifyMeal) return; + var cas = await showTimePicker( + context: context, initialTime: _notifTime); + if (cas == null) return; + var prefs = await SharedPreferences.getInstance(); + prefs.setString( + "oznameni_cas", + timeToDate(cas) + .toString()); // aktualizovat vybraný čas + var den = timeToDate(cas); + debugPrint(den.isAfter(DateTime.now()).toString()); + if (den.isAfter(DateTime.now())) { + // znovu vytvořit oznámení POUZE když je čas v budoucnosti + createNotif(den); + } + + _notifTime = cas; + setState(() {}); + }, + ) + ], + ), + ) + ], + title: Text(AppLocalizations.of(context)!.settingsFunctions), + ) + ], ), ); } diff --git a/lib/pw/platformbutton.dart b/lib/pw/platformbutton.dart index 4377da9..c2aaeb8 100644 --- a/lib/pw/platformbutton.dart +++ b/lib/pw/platformbutton.dart @@ -5,14 +5,23 @@ import 'package:opencanteen/pw/platformwidget.dart'; class PlatformButton extends PlatformWidget { final String text; final void Function()? onPressed; + + final TextStyle? textStyle; const PlatformButton( - {super.key, required this.text, required this.onPressed}); + {super.key, required this.text, required this.onPressed, this.textStyle}); @override - TextButton createAndroidWidget(BuildContext context) => - TextButton(onPressed: onPressed, child: Text(text)); + TextButton createAndroidWidget(BuildContext context) => TextButton( + onPressed: onPressed, + child: Text( + text, + style: textStyle, + ), + ); @override - CupertinoButton createIosWidget(BuildContext context) => - CupertinoButton(onPressed: onPressed, child: Text(text)); + CupertinoButton createIosWidget(BuildContext context) => CupertinoButton( + onPressed: onPressed, + child: Text(text, style: textStyle), + ); } diff --git a/lib/util.dart b/lib/util.dart index 8785e06..98d893f 100644 --- a/lib/util.dart +++ b/lib/util.dart @@ -123,3 +123,9 @@ Route platformRouter(Widget Function(BuildContext context) builder) => (Platform.isAndroid) ? MaterialPageRoute(builder: builder) : CupertinoPageRoute(builder: builder); + +class SettingsManager { + bool skipWeekend = false; + bool checkOrdered = false; + bool saveOffline = false; +} diff --git a/pubspec.yaml b/pubspec.yaml index 971e646..209a99b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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.7.1+28 +version: 1.8.0+28 environment: sdk: ">=2.18.2 <3.0.0"