Added holidays viewer
This commit is contained in:
140
lib/view/pages/holidays/holidays.dart
Normal file
140
lib/view/pages/holidays/holidays.dart
Normal file
@ -0,0 +1,140 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jiffy/jiffy.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../../api/holidays/getHolidaysResponse.dart';
|
||||
import '../../../model/holidays/holidaysProps.dart';
|
||||
import '../../../storage/base/settingsProvider.dart';
|
||||
import '../../../widget/confirmDialog.dart';
|
||||
import '../../../widget/loadingSpinner.dart';
|
||||
|
||||
class Holidays extends StatefulWidget {
|
||||
const Holidays({super.key});
|
||||
|
||||
@override
|
||||
State<Holidays> createState() => _HolidaysState();
|
||||
}
|
||||
|
||||
class _HolidaysState extends State<Holidays> {
|
||||
late SettingsProvider settings = Provider.of<SettingsProvider>(context, listen: false);
|
||||
late bool showPastEvents = settings.val().holidaysSettings.showPastEvents;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
Provider.of<HolidaysProps>(context, listen: false).run();
|
||||
if(!settings.val().holidaysSettings.dismissedDisclaimer) showDisclaimer();
|
||||
});
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
String parseString(String enDate) {
|
||||
return Jiffy.parse(enDate).format(pattern: "dd.MM.yyyy");
|
||||
}
|
||||
|
||||
void showDisclaimer() {
|
||||
showDialog(context: context, builder: (context) {
|
||||
return AlertDialog(
|
||||
title: const Text("Richtigkeit und Bereitstellung der Daten"),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text(""
|
||||
"Sämtliche Datumsangaben sind ohne Gewähr.\n"
|
||||
"Ich übernehme weder Verantwortung für die Richtigkeit der Daten noch hafte ich für wirtschaftliche Schäden die aus der Verwendung dieser Daten entstehen können.\n\n"
|
||||
"Die Daten stammen von https://ferien-api.de/"),
|
||||
const SizedBox(height: 30),
|
||||
ListTile(
|
||||
title: const Text("Diese Meldung nicht mehr anzeigen"),
|
||||
trailing: Checkbox(
|
||||
value: settings.val().holidaysSettings.dismissedDisclaimer,
|
||||
onChanged: (value) => settings.val(write: true).holidaysSettings.dismissedDisclaimer = value!,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(child: const Text("ferien-api.de öffnen"), onPressed: () => ConfirmDialog.openBrowser(context, "https://ferien-api.de/")),
|
||||
TextButton(child: const Text("Schlißen"), onPressed: () => Navigator.of(context).pop()),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Schulferien in Hessen"),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.warning_amber_outlined),
|
||||
onPressed: () => showDisclaimer(),
|
||||
),
|
||||
PopupMenuButton<bool>(
|
||||
initialValue: settings.val().holidaysSettings.showPastEvents,
|
||||
icon: const Icon(Icons.manage_history_outlined),
|
||||
itemBuilder: (context) {
|
||||
return [true, false].map((e) => PopupMenuItem<bool>(
|
||||
value: e,
|
||||
enabled: e != showPastEvents,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(e ? Icons.history_outlined : Icons.history_toggle_off_outlined, color: Theme.of(context).colorScheme.onSurface),
|
||||
const SizedBox(width: 15),
|
||||
Text(e ? "Alle anzeigen" : "Nur zukünftige anzeigen")
|
||||
],
|
||||
)
|
||||
)).toList();
|
||||
},
|
||||
onSelected: (e) {
|
||||
setState(() {
|
||||
showPastEvents = e;
|
||||
settings.val(write: true).holidaysSettings.showPastEvents = e;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Consumer<HolidaysProps>(builder: (context, value, child) {
|
||||
if(value.primaryLoading()) return const LoadingSpinner();
|
||||
|
||||
List<GetHolidaysResponseObject> holidays = value.getHolidaysResponse.data;
|
||||
if(!showPastEvents) holidays = holidays.where((element) => DateTime.parse(element.end).isAfter(DateTime.now())).toList();
|
||||
|
||||
return ListView.builder(
|
||||
itemCount: holidays.length,
|
||||
itemBuilder: (context, index) {
|
||||
GetHolidaysResponseObject holiday = holidays[index];
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.calendar_month),
|
||||
title: Text("${parseString(holiday.start)} bis ${parseString(holiday.end)}"),
|
||||
subtitle: Text("${holiday.name} - (${Jiffy.parse(holiday.start).fromNow()})"),
|
||||
onTap: () => showDialog(context: context, builder: (context) => SimpleDialog(
|
||||
title: Text("Ferien in Hessen | ${holiday.year}"),
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.signpost_outlined),
|
||||
title: Text(holiday.name),
|
||||
subtitle: Text(holiday.slug),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.event),
|
||||
title: Text("beginnend ${parseString(holiday.start)}"),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.event_busy_outlined),
|
||||
title: Text("endend ${parseString(holiday.end)}"),
|
||||
),
|
||||
],
|
||||
)),
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import 'package:persistent_bottom_nav_bar/persistent_tab_view.dart';
|
||||
|
||||
import '../../../widget/ListItem.dart';
|
||||
import '../../settings/settings.dart';
|
||||
import '../holidays/holidays.dart';
|
||||
import 'countdown/countdown.dart';
|
||||
import 'gradeAverages/gradeAverage.dart';
|
||||
import 'message/message.dart';
|
||||
@ -27,7 +28,7 @@ class Overhang extends StatelessWidget {
|
||||
ListItemNavigator(icon: Icons.newspaper, text: "Marianum Message", target: Message()),
|
||||
ListItemNavigator(icon: Icons.room, text: "Raumplan", target: Roomplan()),
|
||||
ListItemNavigator(icon: Icons.calculate, text: "Notendurschnitts rechner", target: GradeAverage()),
|
||||
if(!kReleaseMode) ListItemNavigator(icon: Icons.calendar_month, text: "Schulferien", target: Roomplan()),
|
||||
ListItemNavigator(icon: Icons.calendar_month, text: "Schulferien", target: Holidays()),
|
||||
if(!kReleaseMode) ListItemNavigator(icon: Icons.timer, text: "Countdown", target: Countdown()),
|
||||
],
|
||||
),
|
||||
|
Reference in New Issue
Block a user