feat: výběr z kompatibilních instancí a lepší oznámení o chybějícím obědu
Merge pull request #24 from hernikplays/urlpicker
This commit is contained in:
commit
acb2d91497
6 changed files with 84 additions and 50 deletions
|
@ -91,6 +91,8 @@ abstract class Languages {
|
|||
|
||||
String get signOutWarn;
|
||||
|
||||
String get jump;
|
||||
|
||||
// Uvítací obrazovka
|
||||
|
||||
String get welcome;
|
||||
|
|
|
@ -231,4 +231,7 @@ class LanguageCz extends Languages {
|
|||
|
||||
@override
|
||||
String get signOutWarn => "Opravdu se chcete odhlásit?";
|
||||
|
||||
@override
|
||||
String get jump => "Přeskočit";
|
||||
}
|
||||
|
|
|
@ -229,4 +229,7 @@ class LanguageEn extends Languages {
|
|||
|
||||
@override
|
||||
String get signOutWarn => "Do you really want to sign out?";
|
||||
|
||||
@override
|
||||
String get jump => "Jump";
|
||||
}
|
||||
|
|
|
@ -179,6 +179,8 @@ class _LoginPageState extends State<LoginPage> {
|
|||
TextEditingController passControl = TextEditingController();
|
||||
TextEditingController canteenControl = TextEditingController();
|
||||
bool rememberMe = false;
|
||||
bool _showUrl = false;
|
||||
String dropdownUrl = instance.first["url"] ?? "";
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
@ -301,13 +303,40 @@ class _LoginPageState extends State<LoginPage> {
|
|||
controller: passControl,
|
||||
obscureText: true,
|
||||
),
|
||||
TextField(
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
DropdownButton(
|
||||
isExpanded: true,
|
||||
value: dropdownUrl,
|
||||
items: instance.map<DropdownMenuItem<String>>((e) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: e["url"],
|
||||
child: Text(e["name"]!),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (String? value) {
|
||||
setState(() {
|
||||
if (value == "") {
|
||||
_showUrl = true;
|
||||
} else {
|
||||
_showUrl = false;
|
||||
}
|
||||
dropdownUrl = value!;
|
||||
});
|
||||
},
|
||||
),
|
||||
AnimatedOpacity(
|
||||
opacity: _showUrl ? 1.0 : 0.0,
|
||||
duration: const Duration(milliseconds: 300),
|
||||
child: TextField(
|
||||
autofillHints: const [AutofillHints.url],
|
||||
decoration: InputDecoration(
|
||||
labelText: Languages.of(context)!.iCanteenUrl),
|
||||
keyboardType: TextInputType.url,
|
||||
controller: canteenControl,
|
||||
),
|
||||
),
|
||||
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
|
||||
Switch(
|
||||
value: rememberMe,
|
||||
|
@ -320,36 +349,14 @@ class _LoginPageState extends State<LoginPage> {
|
|||
]),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
if (canteenControl.text.contains("http://")) {
|
||||
// kontrolujeme šifrované spojení
|
||||
var d = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (c) => AlertDialog(
|
||||
title: Text(Languages.of(context)!.warning),
|
||||
content: SingleChildScrollView(
|
||||
child: Text(
|
||||
Languages.of(context)!.httpLogin)),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
Navigator.pop(c, true),
|
||||
child:
|
||||
Text(Languages.of(context)!.yes)),
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
Navigator.pop(c, false),
|
||||
child: Text(
|
||||
Languages.of(context)!.noChange))
|
||||
],
|
||||
));
|
||||
if (!d!) return;
|
||||
var canteenUrl = (dropdownUrl == "")
|
||||
? canteenControl.text
|
||||
: dropdownUrl;
|
||||
if (!canteenUrl.startsWith("https://") &&
|
||||
!canteenUrl.startsWith("http://")) {
|
||||
canteenUrl = "https://$canteenUrl";
|
||||
}
|
||||
if (!canteenControl.text.startsWith("https://") &&
|
||||
!canteenControl.text.startsWith("http://")) {
|
||||
canteenControl.text =
|
||||
"https://${canteenControl.text}";
|
||||
}
|
||||
var canteen = Canteen(canteenControl.text);
|
||||
var canteen = Canteen(canteenUrl);
|
||||
try {
|
||||
var l = await canteen.login(
|
||||
userControl.text, passControl.text);
|
||||
|
@ -365,8 +372,8 @@ class _LoginPageState extends State<LoginPage> {
|
|||
return;
|
||||
}
|
||||
if (rememberMe) {
|
||||
LoginManager.setDetails(userControl.text,
|
||||
passControl.text, canteenControl.text);
|
||||
LoginManager.setDetails(
|
||||
userControl.text, passControl.text, canteenUrl);
|
||||
}
|
||||
// souhlas
|
||||
const storage = FlutterSecureStorage();
|
||||
|
|
|
@ -35,18 +35,31 @@ class _JidelnicekPageState extends State<JidelnicekPage> {
|
|||
var prefs = await SharedPreferences.getInstance();
|
||||
if (prefs.getBool("tyden") ?? false) {
|
||||
// Zjistit jestli je objednáno na přístí týden
|
||||
var pristi = den.add(const Duration(days: 7));
|
||||
var jidelnicek = await widget.canteen.jidelnicekDen(den: pristi);
|
||||
var pristi = den.add(const Duration(days: 6));
|
||||
for (var i = 0; i < 5; i++) {
|
||||
var jidelnicek = await widget.canteen
|
||||
.jidelnicekDen(den: pristi.add(Duration(days: i + 1)));
|
||||
if (jidelnicek.jidla.isNotEmpty &&
|
||||
!jidelnicek.jidla.any((element) => element.objednano == true)) {
|
||||
if (!mounted) return;
|
||||
if (!mounted) break;
|
||||
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(Languages.of(context)!.noOrder),
|
||||
duration: const Duration(seconds: 5),
|
||||
action: SnackBarAction(
|
||||
onPressed: () => setState(
|
||||
() {
|
||||
den = pristi.add(Duration(days: i + 1));
|
||||
nactiJidlo();
|
||||
},
|
||||
),
|
||||
label: Languages.of(context)!.jump,
|
||||
),
|
||||
),
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -294,7 +307,6 @@ class _JidelnicekPageState extends State<JidelnicekPage> {
|
|||
);
|
||||
}
|
||||
}
|
||||
kontrolaTyden(context);
|
||||
});
|
||||
});
|
||||
}).catchError((o) {
|
||||
|
@ -343,6 +355,8 @@ class _JidelnicekPageState extends State<JidelnicekPage> {
|
|||
void nactiNastaveni() async {
|
||||
var prefs = await SharedPreferences.getInstance();
|
||||
_skipWeekend = prefs.getBool("skip") ?? false;
|
||||
if (!mounted) return;
|
||||
kontrolaTyden(context);
|
||||
}
|
||||
|
||||
/// uložení jídelníčku pro dnešek offline
|
||||
|
|
|
@ -90,3 +90,8 @@ DateTime casNaDate(TimeOfDay c) {
|
|||
return DateTime.parse(
|
||||
"${now.year}-${(now.month < 10 ? "0" : "") + now.month.toString()}-${(now.day < 10 ? "0" : "") + now.day.toString()} ${(c.hour < 10 ? "0" : "") + c.hour.toString()}:${(c.minute < 10 ? "0" : "") + c.minute.toString()}:00");
|
||||
}
|
||||
|
||||
List<Map<String, String>> instance = [
|
||||
{"name": "SŠTE Brno, Olomoucká", "url": "https://stravovani.sstebrno.cz"},
|
||||
{"name": "Jiné", "url": ""}
|
||||
];
|
||||
|
|
Reference in a new issue