diff --git a/CHANGELOG.md b/CHANGELOG.md index fe32586..ad3df00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,5 +4,6 @@ - Domovská obrazovka nyní zobrazuje zprávu, pokud na dnešní den není žádné jídlo v jídelníčku - Upgrade knihovny - Odhlášení přesunuto do textového menu +- Odstraněna stránka domů, hlavní stránka je nyní jídelníček # 0.1.0 - První verze \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index f5026b8..4d010da 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,9 +3,27 @@ import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:opencanteen/loginmanager.dart'; import 'package:connectivity_plus/connectivity_plus.dart'; -import 'package:opencanteen/okna/home.dart'; import 'package:canteenlib/canteenlib.dart'; +import 'okna/jidelnicek.dart'; + +/* +Copyright (C) 2022 Matyáš Caras a přispěvatelé + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + void main() { runApp(const MyApp()); } @@ -88,7 +106,7 @@ class _LoginPageState extends State { Navigator.pushReplacement( context, MaterialPageRoute( - builder: (context) => HomePage( + builder: (context) => JidelnicekPage( user: r["user"]!, canteen: canteen, )), @@ -213,7 +231,7 @@ class _LoginPageState extends State { Navigator.pushReplacement( context, MaterialPageRoute( - builder: (context) => HomePage( + builder: (context) => JidelnicekPage( user: userControl.text, canteen: canteen, )), diff --git a/lib/okna/home.dart b/lib/okna/home.dart deleted file mode 100644 index 9d8e907..0000000 --- a/lib/okna/home.dart +++ /dev/null @@ -1,161 +0,0 @@ -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/util.dart'; -import 'package:url_launcher/url_launcher.dart'; - -class HomePage extends StatefulWidget { - const HomePage({Key? key, required this.user, required this.canteen}) - : super(key: key); - - final String user; - final Canteen canteen; - - @override - State createState() => _HomePageState(); -} - -class _HomePageState extends State { - double kredit = 0.0; - Jidelnicek? dnes; - Jidlo? jidloDnes; - List obsah = []; - - Future nactiJidlo() async { - obsah = []; - widget.canteen.ziskejUzivatele().then((kr) { - widget.canteen.jidelnicekDen().then((jd) { - setState(() { - kredit = kr.kredit; - dnes = jd; - if (jd.jidla.isEmpty) { - obsah = [ - const Text( - "Žádné jídlo pro dnešní den", - style: TextStyle(fontSize: 20), - ) - ]; - } - for (var j in jd.jidla) { - if (j.objednano) jidloDnes = j; - obsah.add( - Padding( - padding: const EdgeInsets.only(top: 15), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text(j.varianta), - const SizedBox(width: 10), - Flexible( - child: Text( - j.nazev, - ), - ), - Text("${j.cena} Kč"), - Checkbox( - value: j.objednano, - fillColor: (j.lzeObjednat) - ? MaterialStateProperty.all(Colors.blue) - : MaterialStateProperty.all(Colors.grey), - onChanged: (v) => setState(() { - // TODO exception handling - if (!j.lzeObjednat) return; - widget.canteen.objednat(j); - nactiJidlo(); - })) - ], - ), - ), - ); - } - }); - }); - }).catchError((o) { - if (!widget.canteen.prihlasen) { - Navigator.pushReplacement( - context, MaterialPageRoute(builder: (c) => const LoginPage())); - } - }); - } - - void kliknuti(String value) { - switch (value) { - case 'Odhlásit se': - const storage = FlutterSecureStorage(); - storage.deleteAll(); - Navigator.pushReplacement( - context, MaterialPageRoute(builder: (c) => const LoginPage())); - break; - case 'Nahlásit chybu': - launch("https://github.com/hernikplays/opencanteen/issues/new/choose"); - break; - } - } - - @override - void initState() { - super.initState(); - nactiJidlo(); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - drawer: drawerGenerator(context, widget.canteen, widget.user, 1), - appBar: AppBar( - title: const Text("Domů"), - actions: [ - PopupMenuButton( - onSelected: kliknuti, - itemBuilder: (BuildContext context) { - return {'Nahlásit chybu', 'Odhlásit se'}.map((String choice) { - return PopupMenuItem( - value: choice, - child: Text(choice), - ); - }).toList(); - }, - ), - ], - ), - body: RefreshIndicator( - onRefresh: nactiJidlo, - child: SingleChildScrollView( - physics: const AlwaysScrollableScrollPhysics(), - child: Center( - child: SizedBox( - child: SizedBox( - height: MediaQuery.of(context).size.height / 1.5, - child: Column( - children: [ - const SizedBox( - height: 5, - ), - Text( - "${widget.user} - $kredit kč", - style: const TextStyle(fontSize: 13), - ), - const SizedBox( - height: 10, - ), - Text( - "Dnes je ${DateTime.now().day}. ${DateTime.now().month}.", - style: const TextStyle( - fontSize: 20, fontWeight: FontWeight.bold), - ), - Padding( - padding: const EdgeInsets.only(top: 20), - child: Column(children: obsah), - ), - ], - ), - width: MediaQuery.of(context).size.width - 50, - ), - ), - ), - ), - ), - ); - } -} diff --git a/lib/okna/jidelnicek.dart b/lib/okna/jidelnicek.dart index 983ed1a..1322734 100644 --- a/lib/okna/jidelnicek.dart +++ b/lib/okna/jidelnicek.dart @@ -178,7 +178,7 @@ class _JidelnicekPageState extends State { @override Widget build(BuildContext context) { return Scaffold( - drawer: drawerGenerator(context, widget.canteen, widget.user, 2), + drawer: drawerGenerator(context, widget.canteen, widget.user, 1), appBar: AppBar( title: const Text('Jídelníček'), ), @@ -227,16 +227,23 @@ class _JidelnicekPageState extends State { SingleChildScrollView( physics: const AlwaysScrollableScrollPhysics(), child: GestureDetector( - child: Column(children: obsah), + child: Container( + color: Theme.of(context) + .colorScheme + .onPrimary + .withOpacity(0), + child: Column(children: obsah), + height: MediaQuery.of(context).size.height - 160, + ), onHorizontalDragEnd: (details) { if (details.primaryVelocity?.compareTo(0) == -1) { setState(() { - den = den.subtract(const Duration(days: 1)); + den = den.add(const Duration(days: 1)); nactiJidlo(); }); } else { setState(() { - den = den.add(const Duration(days: 1)); + den = den.subtract(const Duration(days: 1)); nactiJidlo(); }); } diff --git a/lib/util.dart b/lib/util.dart index 7602ade..027ca03 100644 --- a/lib/util.dart +++ b/lib/util.dart @@ -2,7 +2,6 @@ import 'package:canteenlib/canteenlib.dart'; import 'package:flutter/material.dart'; import 'package:opencanteen/okna/burza.dart'; -import 'okna/home.dart'; import 'okna/jidelnicek.dart'; Drawer drawerGenerator( @@ -23,17 +22,6 @@ Drawer drawerGenerator( leading: const Icon(Icons.home), onTap: () => Navigator.pop(context), ), - ListTile( - leading: const Icon(Icons.restaurant), - title: const Text('Jídelníček'), - onTap: () => Navigator.push( - context, - MaterialPageRoute( - builder: (context) => - JidelnicekPage(canteen: canteen, user: user), - ), - ), - ), ListTile( leading: const Icon(Icons.store), title: const Text('Burza'), @@ -48,42 +36,6 @@ Drawer drawerGenerator( ), ); - break; - case 2: - // Jidelnicek page - drawer = Drawer( - child: ListView( - children: [ - const DrawerHeader( - child: Text("OpenCanteen"), - ), - ListTile( - title: const Text("Domů"), - leading: const Icon(Icons.home), - onTap: () => Navigator.push( - context, - MaterialPageRoute( - builder: (c) => HomePage(canteen: canteen, user: user))), - ), - ListTile( - leading: const Icon(Icons.restaurant), - selected: true, - title: const Text('Jídelníček'), - onTap: () => Navigator.pop(context), - ), - ListTile( - leading: const Icon(Icons.store), - title: const Text('Burza'), - onTap: () => Navigator.push( - context, - MaterialPageRoute( - builder: (context) => BurzaPage(canteen: canteen, user: user), - ), - ), - ), - ], - ), - ); break; case 3: drawer = Drawer( @@ -98,18 +50,8 @@ Drawer drawerGenerator( onTap: () => Navigator.push( context, MaterialPageRoute( - builder: (c) => HomePage(canteen: canteen, user: user))), - ), - ListTile( - leading: const Icon(Icons.restaurant), - title: const Text('Jídelníček'), - onTap: () => Navigator.push( - context, - MaterialPageRoute( - builder: (context) => - JidelnicekPage(canteen: canteen, user: user), - ), - ), + builder: (c) => + JidelnicekPage(canteen: canteen, user: user))), ), ListTile( leading: const Icon(Icons.store),