feat: vylepšit offline užívání
Merge pull request #34 from hernikplays/lepsi-offline
1
.flutter
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 52b3dc25f6471c27b2144594abb11c741cb88f57
|
4
.gitmodules
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[submodule ".flutter"]
|
||||||
|
path = .flutter
|
||||||
|
url = https://github.com/flutter/flutter.git
|
||||||
|
branch = stable
|
3
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"dart.flutterSdkPath": ".flutter",
|
||||||
|
}
|
|
@ -1,3 +1,7 @@
|
||||||
|
# 1.5.0
|
||||||
|
- umožnit ukládat více dnů offline
|
||||||
|
- chyba při ukládání offline vás nyní již nevyhodí ale zobrazí pouze zprávu
|
||||||
|
- "Přihlašování" pop-up zmizí, když není přihlášení úspěšné
|
||||||
# 1.4.2
|
# 1.4.2
|
||||||
- aktualizace knihovny flutter_local_notifications
|
- aktualizace knihovny flutter_local_notifications
|
||||||
- lepší podpora pro Android 13
|
- lepší podpora pro Android 13
|
||||||
|
|
113
flutterw
Executable file
|
@ -0,0 +1,113 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
##
|
||||||
|
## Flutter start up script for UN*X
|
||||||
|
## Version: v1.3.1
|
||||||
|
## Date: 2022-11-21 17:25:38
|
||||||
|
##
|
||||||
|
## Use this flutter wrapper to bundle Flutter within your project to make
|
||||||
|
## sure everybody builds with the same version.
|
||||||
|
##
|
||||||
|
## Read about the install and uninstall process in the README on GitHub
|
||||||
|
## https://github.com/passsy/flutter_wrapper
|
||||||
|
##
|
||||||
|
## Inspired by gradle-wrapper.
|
||||||
|
##
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
echoerr() { echo "$@" 1>&2; }
|
||||||
|
|
||||||
|
# Attempt to set APP_HOME
|
||||||
|
# Resolve links: $0 may be a link
|
||||||
|
PRG="$0"
|
||||||
|
# Need this for relative symlinks.
|
||||||
|
while [ -h "$PRG" ]; do
|
||||||
|
ls=$(ls -ld "$PRG")
|
||||||
|
link=$(expr "$ls" : '.*-> \(.*\)$')
|
||||||
|
if expr "$link" : '/.*' >/dev/null; then
|
||||||
|
PRG="$link"
|
||||||
|
else
|
||||||
|
PRG=$(dirname "$PRG")"/$link"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
SAVED="$(pwd)"
|
||||||
|
cd "$(dirname "$PRG")/" >/dev/null
|
||||||
|
APP_HOME="$(pwd -P)"
|
||||||
|
cd "$SAVED" >/dev/null
|
||||||
|
|
||||||
|
FLUTTER_SUBMODULE_NAME='.flutter'
|
||||||
|
GIT_HOME=$(git -C "${APP_HOME}" rev-parse --show-toplevel)
|
||||||
|
FLUTTER_DIR="${GIT_HOME}/${FLUTTER_SUBMODULE_NAME}"
|
||||||
|
|
||||||
|
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||||
|
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Fix not initialized flutter submodule
|
||||||
|
if [ ! -f "${FLUTTER_DIR}/bin/flutter" ]; then
|
||||||
|
echoerr "$FLUTTER_SUBMODULE_NAME submodule not initialized. Initializing..."
|
||||||
|
git submodule update --init "${FLUTTER_DIR}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Detect detach HEAD and fix it. commands like upgrade expect a valid branch, not a detached HEAD
|
||||||
|
FLUTTER_SYMBOLIC_REF=$(git -C "${FLUTTER_DIR}" symbolic-ref -q HEAD)
|
||||||
|
if [ -z "${FLUTTER_SYMBOLIC_REF}" ]; then
|
||||||
|
FLUTTER_REV=$(git -C "${FLUTTER_DIR}" rev-parse HEAD)
|
||||||
|
FLUTTER_CHANNEL=$(git -C "${GIT_HOME}" config -f .gitmodules submodule.${FLUTTER_SUBMODULE_NAME}.branch)
|
||||||
|
|
||||||
|
if [ -z "${FLUTTER_CHANNEL}" ]; then
|
||||||
|
echoerr "Warning: Submodule '$FLUTTER_SUBMODULE_NAME' doesn't point to an official Flutter channel \
|
||||||
|
(one of stable|beta|dev|master). './flutterw upgrade' will fail without a channel."
|
||||||
|
echoerr "Fix this by adding a specific channel with:"
|
||||||
|
echoerr " - './flutterw channel <channel>' or"
|
||||||
|
echoerr " - Add 'branch = <channel>' to '$FLUTTER_SUBMODULE_NAME' submodule in .gitmodules"
|
||||||
|
else
|
||||||
|
echoerr "Fixing detached HEAD: '$FLUTTER_SUBMODULE_NAME' submodule points to a specific commit $FLUTTER_REV, not channel '$FLUTTER_CHANNEL' (as defined in .gitmodules)."
|
||||||
|
# Make sure channel is fetched
|
||||||
|
# Remove old channel branch because it might be moved to an unrelated commit where fast-forward pull isn't possible
|
||||||
|
git -C "${FLUTTER_DIR}" branch -q -D "${FLUTTER_CHANNEL}" 2> /dev/null || true
|
||||||
|
git -C "${FLUTTER_DIR}" fetch -q origin
|
||||||
|
|
||||||
|
# bind current HEAD to channel defined in .gitmodules
|
||||||
|
git -C "${FLUTTER_DIR}" checkout -q -b "${FLUTTER_CHANNEL}" "${FLUTTER_REV}"
|
||||||
|
git -C "${FLUTTER_DIR}" branch -q -u "origin/${FLUTTER_CHANNEL}" "${FLUTTER_CHANNEL}"
|
||||||
|
echoerr "Fixed! Migrated to channel '$FLUTTER_CHANNEL' while staying at commit $FLUTTER_REV. './flutterw upgrade' now works without problems!"
|
||||||
|
git -C "${FLUTTER_DIR}" status -bs
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Wrapper tasks done, call flutter binary with all args
|
||||||
|
set -e
|
||||||
|
"$FLUTTER_DIR/bin/flutter" "$@"
|
||||||
|
set +e
|
||||||
|
|
||||||
|
# Post flutterw tasks. exit code from /bin/flutterw will be used as final exit
|
||||||
|
FLUTTER_EXIT_STATUS=$?
|
||||||
|
if [ ${FLUTTER_EXIT_STATUS} -eq 0 ]; then
|
||||||
|
|
||||||
|
# ./flutterw channel CHANNEL
|
||||||
|
if echo "$@" | grep -q "channel"; then
|
||||||
|
if [ -n "$2" ]; then
|
||||||
|
# make sure .gitmodules is updated as well
|
||||||
|
CHANNEL=${2} # second arg
|
||||||
|
git config -f "${GIT_HOME}/.gitmodules" "submodule.${FLUTTER_SUBMODULE_NAME}.branch" "${CHANNEL}"
|
||||||
|
# makes sure nobody forgets to do commit all changed files
|
||||||
|
git add "${GIT_HOME}/.gitmodules"
|
||||||
|
git add "${FLUTTER_DIR}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ./flutterw upgrade
|
||||||
|
if echo "$@" | grep -q "upgrade"; then
|
||||||
|
# makes sure nobody forgets to do commit the changed submodule
|
||||||
|
git add "${FLUTTER_DIR}"
|
||||||
|
# flutter packages get runs automatically. Stage those changes as well
|
||||||
|
if [ -f pubspec.lock ]; then
|
||||||
|
git add pubspec.lock
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit ${FLUTTER_EXIT_STATUS}
|
|
@ -147,6 +147,8 @@ abstract class Languages {
|
||||||
|
|
||||||
String get saveOffline;
|
String get saveOffline;
|
||||||
|
|
||||||
|
String get saveCount;
|
||||||
|
|
||||||
String get skipWeekend;
|
String get skipWeekend;
|
||||||
|
|
||||||
String get checkOrdered;
|
String get checkOrdered;
|
||||||
|
@ -162,6 +164,8 @@ abstract class Languages {
|
||||||
|
|
||||||
String get mustLogout;
|
String get mustLogout;
|
||||||
|
|
||||||
|
String get errorSaving;
|
||||||
|
|
||||||
// Oznámit před obědem
|
// Oznámit před obědem
|
||||||
String get lunchNotif;
|
String get lunchNotif;
|
||||||
|
|
||||||
|
|
|
@ -237,4 +237,11 @@ class LanguageCz extends Languages {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get review => "Ohodnotit aplikaci";
|
String get review => "Ohodnotit aplikaci";
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get saveCount => "Počet dnů dostupných offline (Akt. limit je 7)";
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get errorSaving =>
|
||||||
|
"Při ukládání offline nastala chyba, zkuste to znovu později.";
|
||||||
}
|
}
|
||||||
|
|
|
@ -235,4 +235,11 @@ class LanguageEn extends Languages {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get review => "Review the app";
|
String get review => "Review the app";
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get saveCount => "Number of days to save offline (Current limit is 7)";
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get errorSaving =>
|
||||||
|
"An error occured while trying to save menu offline, try again later.";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
@ -13,7 +12,6 @@ import 'package:canteenlib/canteenlib.dart';
|
||||||
import 'package:opencanteen/okna/offline_jidelnicek.dart';
|
import 'package:opencanteen/okna/offline_jidelnicek.dart';
|
||||||
import 'package:opencanteen/okna/welcome.dart';
|
import 'package:opencanteen/okna/welcome.dart';
|
||||||
import 'package:opencanteen/util.dart';
|
import 'package:opencanteen/util.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:timezone/data/latest_all.dart' as tz;
|
import 'package:timezone/data/latest_all.dart' as tz;
|
||||||
|
@ -237,6 +235,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
}
|
}
|
||||||
} on PlatformException {
|
} on PlatformException {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
|
Navigator.of(context).pop();
|
||||||
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
|
@ -245,6 +244,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
);
|
);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
|
Navigator.of(context).pop();
|
||||||
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
|
@ -418,32 +418,12 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
|
|
||||||
/// Získá offline soubor a zobrazí údaje
|
/// Získá offline soubor a zobrazí údaje
|
||||||
void goOffline() async {
|
void goOffline() async {
|
||||||
Directory appDocDir = await getApplicationDocumentsDirectory();
|
|
||||||
var den = DateTime.now();
|
|
||||||
var soubor = File(
|
|
||||||
"${appDocDir.path}/jidelnicek_${den.year}-${den.month}-${den.day}.json");
|
|
||||||
if (soubor.existsSync()) {
|
|
||||||
// načteme offline jídelníček
|
|
||||||
var input = await soubor.readAsString();
|
|
||||||
var r = jsonDecode(input);
|
|
||||||
List<OfflineJidlo> jidla = [];
|
|
||||||
for (var j in r) {
|
|
||||||
jidla.add(OfflineJidlo(
|
|
||||||
nazev: j["nazev"],
|
|
||||||
varianta: j["varianta"],
|
|
||||||
objednano: j["objednano"],
|
|
||||||
cena: j["cena"],
|
|
||||||
naBurze: j["naBurze"],
|
|
||||||
den: DateTime.parse(j["den"])));
|
|
||||||
}
|
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
Navigator.pushAndRemoveUntil(
|
Navigator.pushAndRemoveUntil(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(builder: ((context) => const OfflineJidelnicek())),
|
||||||
builder: ((context) => OfflineJidelnicek(jidla: jidla))),
|
|
||||||
(route) => false);
|
(route) => false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class AppLocalizationsDelegate extends LocalizationsDelegate<Languages> {
|
class AppLocalizationsDelegate extends LocalizationsDelegate<Languages> {
|
||||||
|
|
|
@ -382,52 +382,60 @@ class _JidelnicekPageState extends State<JidelnicekPage> {
|
||||||
kontrolaTyden(context);
|
kontrolaTyden(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// uložení jídelníčku pro dnešek offline
|
void ulozitDoOffline() async {
|
||||||
void ulozitDnesekOffline() async {
|
|
||||||
var prefs = await SharedPreferences.getInstance();
|
var prefs = await SharedPreferences.getInstance();
|
||||||
if (prefs.getBool("offline") != null && prefs.getBool("offline")!) {
|
if (prefs.getBool("offline") ?? false) {
|
||||||
|
// vyčistit offline
|
||||||
Directory appDocDir = await getApplicationDocumentsDirectory();
|
Directory appDocDir = await getApplicationDocumentsDirectory();
|
||||||
for (var f in appDocDir.listSync()) {
|
for (var f in appDocDir.listSync()) {
|
||||||
// Vymažeme obsah
|
|
||||||
if (f.path.contains("jidelnicek")) {
|
if (f.path.contains("jidelnicek")) {
|
||||||
f.deleteSync();
|
f.deleteSync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uložíme nová data
|
// uložit *pocet* jídelníčků pro offline použití
|
||||||
Jidelnicek j = Jidelnicek(DateTime.now(), []);
|
var pocet = prefs.getInt("offline_pocet") ?? 1;
|
||||||
|
if (pocet > 7) pocet = 7;
|
||||||
|
for (var i = 0; i < pocet; i++) {
|
||||||
|
var d = den.add(Duration(days: i));
|
||||||
|
Jidelnicek? j;
|
||||||
try {
|
try {
|
||||||
j = await widget.canteen.jidelnicekDen();
|
j = await widget.canteen.jidelnicekDen(den: d);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!widget.canteen.prihlasen) {
|
if (!widget.canteen.prihlasen) {
|
||||||
if (!mounted) return; // ! Přidat chybu, pokud není mounted
|
if (!mounted) return; // ! Přidat chybu, pokud není mounted
|
||||||
Navigator.pushReplacement(
|
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||||
context, MaterialPageRoute(builder: (c) => const LoginPage()));
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
|
content: Text(Languages.of(context)!.errorSaving),
|
||||||
|
duration: const Duration(seconds: 5),
|
||||||
|
));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var soubor = File(
|
var soubor = File(
|
||||||
"${appDocDir.path}/jidelnicek_${den.year}-${den.month}-${den.day}.json");
|
"${appDocDir.path}/jidelnicek_${d.year}-${d.month}-${d.day}.json");
|
||||||
soubor.createSync();
|
soubor.createSync();
|
||||||
var jidla = [];
|
var jidla = [];
|
||||||
for (var jidlo in j.jidla) {
|
for (var jidlo in j!.jidla) {
|
||||||
jidla.add({
|
jidla.add({
|
||||||
"nazev": jidlo.nazev,
|
"nazev": jidlo.nazev,
|
||||||
"varianta": jidlo.varianta,
|
"varianta": jidlo.varianta,
|
||||||
"objednano": jidlo.objednano,
|
"objednano": jidlo.objednano,
|
||||||
"cena": jidlo.cena,
|
"cena": jidlo.cena,
|
||||||
"naBurze": jidlo.naBurze,
|
"naBurze": jidlo.naBurze,
|
||||||
"den": den.toString()
|
"den": d.toString()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
await soubor.writeAsString(json.encode(jidla));
|
await soubor.writeAsString(json.encode(jidla));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
nactiNastaveni();
|
nactiNastaveni();
|
||||||
ulozitDnesekOffline();
|
ulozitDoOffline();
|
||||||
nactiJidlo();
|
nactiJidlo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ import 'dart:io';
|
||||||
|
|
||||||
import 'package:canteenlib/canteenlib.dart';
|
import 'package:canteenlib/canteenlib.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||||
import 'package:flutter_native_timezone/flutter_native_timezone.dart';
|
import 'package:flutter_native_timezone/flutter_native_timezone.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
@ -28,21 +29,25 @@ class _NastaveniState extends State<Nastaveni> {
|
||||||
bool _oznameniObed = false;
|
bool _oznameniObed = false;
|
||||||
bool _zapamatovany = false;
|
bool _zapamatovany = false;
|
||||||
TimeOfDay _oznameniCas = TimeOfDay.now();
|
TimeOfDay _oznameniCas = TimeOfDay.now();
|
||||||
|
final TextEditingController _countController =
|
||||||
|
TextEditingController(text: "1");
|
||||||
|
SharedPreferences? preferences;
|
||||||
void najitNastaveni() async {
|
void najitNastaveni() async {
|
||||||
var preferences = await SharedPreferences.getInstance();
|
preferences = await SharedPreferences.getInstance();
|
||||||
_zapamatovany = await LoginManager.zapamatovat();
|
_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;
|
||||||
_kontrolovatTyden = preferences.getBool("tyden") ?? false;
|
_kontrolovatTyden = preferences!.getBool("tyden") ?? false;
|
||||||
_oznameniObed = preferences.getBool("oznamit") ?? false;
|
_oznameniObed = preferences!.getBool("oznamit") ?? false;
|
||||||
var casStr = preferences.getString("oznameni_cas");
|
_countController.text =
|
||||||
|
(preferences!.getInt("offline_pocet") ?? 1).toString();
|
||||||
|
var casStr = preferences!.getString("oznameni_cas");
|
||||||
if (casStr == null) {
|
if (casStr == null) {
|
||||||
var now = DateTime.now();
|
var now = DateTime.now();
|
||||||
_oznameniCas = TimeOfDay.fromDateTime(
|
_oznameniCas = TimeOfDay.fromDateTime(
|
||||||
DateTime.now().add(const Duration(hours: 1)));
|
DateTime.now().add(const Duration(hours: 1)));
|
||||||
preferences.setString("oznameni_cas", now.toString());
|
preferences!.setString("oznameni_cas", now.toString());
|
||||||
} else {
|
} else {
|
||||||
_oznameniCas = TimeOfDay.fromDateTime(DateTime.parse(casStr));
|
_oznameniCas = TimeOfDay.fromDateTime(DateTime.parse(casStr));
|
||||||
}
|
}
|
||||||
|
@ -50,8 +55,7 @@ class _NastaveniState extends State<Nastaveni> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void zmenitNastaveni(String key, bool value) async {
|
void zmenitNastaveni(String key, bool value) async {
|
||||||
var preferences = await SharedPreferences.getInstance();
|
preferences!.setBool(key, value);
|
||||||
preferences.setBool(key, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -86,6 +90,27 @@ class _NastaveniState extends State<Nastaveni> {
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Text(Languages.of(context)!.saveCount),
|
||||||
|
SizedBox(
|
||||||
|
width: 35,
|
||||||
|
child: TextField(
|
||||||
|
controller: _countController,
|
||||||
|
enabled: _ukladatOffline,
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
|
||||||
|
onChanged: (c) {
|
||||||
|
var cislo = int.tryParse(c);
|
||||||
|
if (cislo != null) {
|
||||||
|
preferences!.setInt("offline_pocet", cislo);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
|
|
|
@ -1,27 +1,57 @@
|
||||||
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
import 'package:opencanteen/util.dart';
|
import 'package:opencanteen/util.dart';
|
||||||
import 'package:package_info_plus/package_info_plus.dart';
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
import '../lang/lang.dart';
|
import '../lang/lang.dart';
|
||||||
import '../main.dart';
|
import '../main.dart';
|
||||||
|
|
||||||
class OfflineJidelnicek extends StatefulWidget {
|
class OfflineJidelnicek extends StatefulWidget {
|
||||||
const OfflineJidelnicek({Key? key, required this.jidla}) : super(key: key);
|
const OfflineJidelnicek({Key? key}) : super(key: key);
|
||||||
final List<OfflineJidlo> jidla;
|
|
||||||
@override
|
@override
|
||||||
State<OfflineJidelnicek> createState() => _OfflineJidelnicekState();
|
State<OfflineJidelnicek> createState() => _OfflineJidelnicekState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _OfflineJidelnicekState extends State<OfflineJidelnicek> {
|
class _OfflineJidelnicekState extends State<OfflineJidelnicek> {
|
||||||
List<Widget> obsah = [const CircularProgressIndicator()];
|
List<Widget> obsah = [const CircularProgressIndicator()];
|
||||||
|
var _skipWeekend = false;
|
||||||
DateTime den = DateTime.now();
|
DateTime den = DateTime.now();
|
||||||
String denTydne = "";
|
String denTydne = "";
|
||||||
|
List<List<OfflineJidlo>> data = [];
|
||||||
|
var jidloIndex = 0;
|
||||||
|
|
||||||
|
void nactiZeSouboru() async {
|
||||||
|
Directory appDocDir = await getApplicationDocumentsDirectory();
|
||||||
|
for (var f in appDocDir.listSync()) {
|
||||||
|
if (f.path.contains("jidelnicek")) {
|
||||||
|
var soubor = File(f.path);
|
||||||
|
var input = await soubor.readAsString();
|
||||||
|
var r = jsonDecode(input);
|
||||||
|
List<OfflineJidlo> jidla = [];
|
||||||
|
for (var j in r) {
|
||||||
|
jidla.add(OfflineJidlo(
|
||||||
|
nazev: j["nazev"],
|
||||||
|
varianta: j["varianta"],
|
||||||
|
objednano: j["objednano"],
|
||||||
|
cena: j["cena"],
|
||||||
|
naBurze: j["naBurze"],
|
||||||
|
den: DateTime.parse(j["den"])));
|
||||||
|
}
|
||||||
|
data.add(jidla);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nactiJidlo();
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> nactiJidlo() async {
|
Future<void> nactiJidlo() async {
|
||||||
den = widget.jidla[0].den;
|
var jidelnicek = data[jidloIndex];
|
||||||
|
den = jidelnicek[0].den;
|
||||||
switch (den.weekday) {
|
switch (den.weekday) {
|
||||||
case 2:
|
case 2:
|
||||||
denTydne = Languages.of(context)!.tuesday;
|
denTydne = Languages.of(context)!.tuesday;
|
||||||
|
@ -45,7 +75,7 @@ class _OfflineJidelnicekState extends State<OfflineJidelnicek> {
|
||||||
denTydne = Languages.of(context)!.monday;
|
denTydne = Languages.of(context)!.monday;
|
||||||
}
|
}
|
||||||
obsah = [];
|
obsah = [];
|
||||||
for (OfflineJidlo j in widget.jidla) {
|
for (OfflineJidlo j in jidelnicek) {
|
||||||
obsah.add(
|
obsah.add(
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(top: 15),
|
padding: const EdgeInsets.only(top: 15),
|
||||||
|
@ -70,7 +100,8 @@ class _OfflineJidelnicekState extends State<OfflineJidelnicek> {
|
||||||
return;
|
return;
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
)),
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -116,7 +147,14 @@ class _OfflineJidelnicekState extends State<OfflineJidelnicek> {
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
nactiJidlo();
|
nactiNastaveni();
|
||||||
|
}
|
||||||
|
|
||||||
|
void nactiNastaveni() async {
|
||||||
|
var prefs = await SharedPreferences.getInstance();
|
||||||
|
_skipWeekend = prefs.getBool("skip") ?? false;
|
||||||
|
if (!mounted) return;
|
||||||
|
nactiZeSouboru();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -157,11 +195,61 @@ class _OfflineJidelnicekState extends State<OfflineJidelnicek> {
|
||||||
),
|
),
|
||||||
Text(Languages.of(context)!.mustLogout),
|
Text(Languages.of(context)!.mustLogout),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
|
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
|
||||||
|
IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
if (data.length <= 1) return;
|
||||||
|
obsah = [const CircularProgressIndicator()];
|
||||||
|
setState(() {
|
||||||
|
if (den.weekday == 1 && _skipWeekend) {
|
||||||
|
// pokud je pondělí a chceme přeskočit víkend
|
||||||
|
if (jidloIndex - 2 >= 0) {
|
||||||
|
jidloIndex -= data.length - 3;
|
||||||
|
} else {
|
||||||
|
jidloIndex = data.length - 1;
|
||||||
|
}
|
||||||
|
} else if (jidloIndex == 0) {
|
||||||
|
jidloIndex = data.length - 1;
|
||||||
|
} else {
|
||||||
|
jidloIndex -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
nactiJidlo();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.arrow_left)),
|
||||||
TextButton(
|
TextButton(
|
||||||
child:
|
onPressed: () async {},
|
||||||
Text("${den.day}. ${den.month}. ${den.year} - $denTydne"),
|
child: Text(
|
||||||
onPressed: () => {},
|
"${den.day}. ${den.month}. ${den.year} - $denTydne")),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
if (data.length <= 1) return;
|
||||||
|
obsah = [const CircularProgressIndicator()];
|
||||||
|
setState(() {
|
||||||
|
if (den.weekday == 5 && _skipWeekend) {
|
||||||
|
// pokud je pondělí a chceme přeskočit víkend
|
||||||
|
if (jidloIndex + 2 <= data.length - 1) {
|
||||||
|
jidloIndex += 2;
|
||||||
|
} else {
|
||||||
|
jidloIndex = 0;
|
||||||
|
}
|
||||||
|
} else if (jidloIndex == data.length) {
|
||||||
|
jidloIndex = 0;
|
||||||
|
} else {
|
||||||
|
jidloIndex += 1;
|
||||||
|
}
|
||||||
|
nactiJidlo();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.arrow_right),
|
||||||
),
|
),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
jidloIndex = 0;
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.today))
|
||||||
|
]),
|
||||||
SingleChildScrollView(
|
SingleChildScrollView(
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
child: Column(
|
child: Column(
|
||||||
|
|
3
metadata/cs-CZ/changelogs/23.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
- Umožnit ukládat více dnů offline
|
||||||
|
- Pop-up "Přihlašování" nyní zmizí v případě neúspěšného přihlášení
|
||||||
|
- chyba při ukládání offline vás nyní již nevyhodí ale zobrazí pouze zprávu
|
Before Width: | Height: | Size: 165 KiB After Width: | Height: | Size: 165 KiB |
Before Width: | Height: | Size: 172 KiB After Width: | Height: | Size: 172 KiB |
Before Width: | Height: | Size: 119 KiB After Width: | Height: | Size: 119 KiB |
Before Width: | Height: | Size: 156 KiB After Width: | Height: | Size: 156 KiB |
Before Width: | Height: | Size: 147 KiB After Width: | Height: | Size: 147 KiB |
3
metadata/en-US/changelogs/23.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
- Support downloading multiple days of meal lists offline
|
||||||
|
- "Signing in" pop-up disappears when not signed in succesfully
|
||||||
|
- Error while saving menu offline no longer throws you to the log-in screen, but shows just an error message
|
|
@ -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.4.2+22
|
version: 1.5.0+23
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.16.1 <3.0.0"
|
sdk: ">=2.16.1 <3.0.0"
|
||||||
|
|