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:
Matyáš Caras 2022-09-12 15:22:45 +00:00 committed by GitHub
commit acb2d91497
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 84 additions and 50 deletions

View file

@ -91,6 +91,8 @@ abstract class Languages {
String get signOutWarn; String get signOutWarn;
String get jump;
// Uvítací obrazovka // Uvítací obrazovka
String get welcome; String get welcome;

View file

@ -231,4 +231,7 @@ class LanguageCz extends Languages {
@override @override
String get signOutWarn => "Opravdu se chcete odhlásit?"; String get signOutWarn => "Opravdu se chcete odhlásit?";
@override
String get jump => "Přeskočit";
} }

View file

@ -229,4 +229,7 @@ class LanguageEn extends Languages {
@override @override
String get signOutWarn => "Do you really want to sign out?"; String get signOutWarn => "Do you really want to sign out?";
@override
String get jump => "Jump";
} }

View file

@ -179,6 +179,8 @@ class _LoginPageState extends State<LoginPage> {
TextEditingController passControl = TextEditingController(); TextEditingController passControl = TextEditingController();
TextEditingController canteenControl = TextEditingController(); TextEditingController canteenControl = TextEditingController();
bool rememberMe = false; bool rememberMe = false;
bool _showUrl = false;
String dropdownUrl = instance.first["url"] ?? "";
@override @override
void initState() { void initState() {
@ -301,13 +303,40 @@ class _LoginPageState extends State<LoginPage> {
controller: passControl, controller: passControl,
obscureText: true, 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], autofillHints: const [AutofillHints.url],
decoration: InputDecoration( decoration: InputDecoration(
labelText: Languages.of(context)!.iCanteenUrl), labelText: Languages.of(context)!.iCanteenUrl),
keyboardType: TextInputType.url, keyboardType: TextInputType.url,
controller: canteenControl, controller: canteenControl,
), ),
),
Row(mainAxisAlignment: MainAxisAlignment.center, children: [ Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Switch( Switch(
value: rememberMe, value: rememberMe,
@ -320,36 +349,14 @@ class _LoginPageState extends State<LoginPage> {
]), ]),
TextButton( TextButton(
onPressed: () async { onPressed: () async {
if (canteenControl.text.contains("http://")) { var canteenUrl = (dropdownUrl == "")
// kontrolujeme šifrované spojení ? canteenControl.text
var d = await showDialog<bool>( : dropdownUrl;
context: context, if (!canteenUrl.startsWith("https://") &&
builder: (c) => AlertDialog( !canteenUrl.startsWith("http://")) {
title: Text(Languages.of(context)!.warning), canteenUrl = "https://$canteenUrl";
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;
} }
if (!canteenControl.text.startsWith("https://") && var canteen = Canteen(canteenUrl);
!canteenControl.text.startsWith("http://")) {
canteenControl.text =
"https://${canteenControl.text}";
}
var canteen = Canteen(canteenControl.text);
try { try {
var l = await canteen.login( var l = await canteen.login(
userControl.text, passControl.text); userControl.text, passControl.text);
@ -365,8 +372,8 @@ class _LoginPageState extends State<LoginPage> {
return; return;
} }
if (rememberMe) { if (rememberMe) {
LoginManager.setDetails(userControl.text, LoginManager.setDetails(
passControl.text, canteenControl.text); userControl.text, passControl.text, canteenUrl);
} }
// souhlas // souhlas
const storage = FlutterSecureStorage(); const storage = FlutterSecureStorage();

View file

@ -35,18 +35,31 @@ class _JidelnicekPageState extends State<JidelnicekPage> {
var prefs = await SharedPreferences.getInstance(); var prefs = await SharedPreferences.getInstance();
if (prefs.getBool("tyden") ?? false) { if (prefs.getBool("tyden") ?? false) {
// Zjistit jestli je objednáno na přístí týden // Zjistit jestli je objednáno na přístí týden
var pristi = den.add(const Duration(days: 7)); var pristi = den.add(const Duration(days: 6));
var jidelnicek = await widget.canteen.jidelnicekDen(den: pristi); for (var i = 0; i < 5; i++) {
var jidelnicek = await widget.canteen
.jidelnicekDen(den: pristi.add(Duration(days: i + 1)));
if (jidelnicek.jidla.isNotEmpty && if (jidelnicek.jidla.isNotEmpty &&
!jidelnicek.jidla.any((element) => element.objednano == true)) { !jidelnicek.jidla.any((element) => element.objednano == true)) {
if (!mounted) return; if (!mounted) break;
ScaffoldMessenger.of(context).hideCurrentSnackBar(); ScaffoldMessenger.of(context).hideCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
content: Text(Languages.of(context)!.noOrder), content: Text(Languages.of(context)!.noOrder),
duration: const Duration(seconds: 5), 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) { }).catchError((o) {
@ -343,6 +355,8 @@ class _JidelnicekPageState extends State<JidelnicekPage> {
void nactiNastaveni() async { void nactiNastaveni() async {
var prefs = await SharedPreferences.getInstance(); var prefs = await SharedPreferences.getInstance();
_skipWeekend = prefs.getBool("skip") ?? false; _skipWeekend = prefs.getBool("skip") ?? false;
if (!mounted) return;
kontrolaTyden(context);
} }
/// uložení jídelníčku pro dnešek offline /// uložení jídelníčku pro dnešek offline

View file

@ -90,3 +90,8 @@ DateTime casNaDate(TimeOfDay c) {
return DateTime.parse( 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"); "${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": ""}
];