2021-12-13 13:39:06 +01:00
|
|
|
import 'package:meincantor/presets/teachers.dart';
|
|
|
|
import 'package:meincantor/presets/subjects.dart';
|
|
|
|
import 'package:meincantor/presets/colors.dart';
|
2021-11-16 19:41:35 +01:00
|
|
|
|
2021-09-14 20:55:58 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
2021-11-06 11:01:44 +01:00
|
|
|
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2021-09-14 20:55:58 +02:00
|
|
|
|
2021-12-13 13:39:06 +01:00
|
|
|
import 'Settings/Pages/plan_settings.dart';
|
|
|
|
|
2021-09-14 20:55:58 +02:00
|
|
|
class ClassTimetableBuilder {
|
2021-11-06 11:01:44 +01:00
|
|
|
final RefreshIndicator view;
|
2021-09-14 20:55:58 +02:00
|
|
|
ClassTimetableBuilder({required this.view});
|
2021-11-16 19:41:35 +01:00
|
|
|
factory ClassTimetableBuilder.buildView(
|
|
|
|
Map<String, dynamic> json, BuildContext context) {
|
2021-11-06 11:01:44 +01:00
|
|
|
List<Widget> list = LessonsListBuilder.buildList(json).lessons;
|
|
|
|
String info = TimetableInfo.fromJson(json).info;
|
2021-11-16 19:41:35 +01:00
|
|
|
if (info.isNotEmpty) {
|
|
|
|
list.insert(
|
|
|
|
0,
|
|
|
|
ListTile(
|
|
|
|
title: const Text("Informationen"),
|
|
|
|
leading: const Icon(MdiIcons.information),
|
|
|
|
onTap: () {
|
|
|
|
showModalBottomSheet<void>(
|
|
|
|
isScrollControlled: true,
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(25.0),
|
|
|
|
),
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return SizedBox(
|
|
|
|
height: 400,
|
|
|
|
child: ListView(
|
|
|
|
children: <Widget>[
|
|
|
|
ListTile(
|
|
|
|
title: const Text("Informationen",
|
|
|
|
style: TextStyle(fontWeight: FontWeight.bold)),
|
|
|
|
leading: const Icon(Icons.arrow_back),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(20),
|
|
|
|
child: Text(info),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
));
|
2021-11-06 11:01:44 +01:00
|
|
|
}
|
2021-09-14 20:55:58 +02:00
|
|
|
return ClassTimetableBuilder(
|
2021-11-06 11:01:44 +01:00
|
|
|
view: RefreshIndicator(
|
2021-12-13 13:39:06 +01:00
|
|
|
onRefresh: () {
|
|
|
|
return Future.delayed(const Duration(seconds: 1));
|
|
|
|
},
|
|
|
|
child: ListView(
|
|
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
|
|
children: list,
|
|
|
|
),
|
|
|
|
));
|
2021-09-14 20:55:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-06 11:01:44 +01:00
|
|
|
Future<Color> buildLessonColor(String lesson) async {
|
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
if (!prefs.containsKey("color$lesson")) {
|
|
|
|
Color lessonPresetColor = colors[lesson] ?? Colors.grey[700];
|
|
|
|
prefs.setInt("color$lesson", lessonPresetColor.value);
|
|
|
|
}
|
|
|
|
Color lessonColor = Color(prefs.getInt("color$lesson")!);
|
|
|
|
return lessonColor;
|
|
|
|
}
|
|
|
|
|
2021-09-14 20:55:58 +02:00
|
|
|
class LessonsListBuilder {
|
|
|
|
final List<Widget> lessons;
|
|
|
|
LessonsListBuilder({required this.lessons});
|
2021-11-16 19:41:35 +01:00
|
|
|
factory LessonsListBuilder.buildList(Map<String, dynamic> json,
|
|
|
|
{int count = 0}) {
|
2021-09-14 20:55:58 +02:00
|
|
|
List<Widget> children = [];
|
2021-11-16 19:41:35 +01:00
|
|
|
for (var element in ClassTimetable.fromJson(json).timetable) {
|
2021-09-14 20:55:58 +02:00
|
|
|
List<Widget> cardChildren = [];
|
|
|
|
if (element.count.toString() == count.toString() || count == 0) {
|
|
|
|
cardChildren.add(ListTile(
|
|
|
|
title: Text(element.count.toString() + '.' + ' ' + element.name,
|
|
|
|
style: TextStyle(color: element.fontColor)),
|
|
|
|
subtitle: Row(children: [
|
|
|
|
Icon(CupertinoIcons.person, color: element.fontColor),
|
|
|
|
const SizedBox(width: 5),
|
|
|
|
Text(element.teacher, style: TextStyle(color: element.fontColor)),
|
|
|
|
const Spacer(),
|
|
|
|
Icon(CupertinoIcons.home, color: element.fontColor),
|
|
|
|
const SizedBox(width: 5),
|
|
|
|
Text(element.room, style: TextStyle(color: element.fontColor))
|
|
|
|
]),
|
|
|
|
leading: Icon(CupertinoIcons.time, color: element.fontColor)));
|
|
|
|
if (element.info != '') {
|
|
|
|
cardChildren.add(ListTile(
|
|
|
|
title: Text(element.info,
|
|
|
|
style: TextStyle(color: element.fontColor))));
|
|
|
|
}
|
2021-11-06 11:01:44 +01:00
|
|
|
Widget card = FutureBuilder(
|
2021-12-13 13:39:06 +01:00
|
|
|
future: buildBlacklist(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
if (!((snapshot.data as List<dynamic>).contains(element.id))) {
|
|
|
|
return FutureBuilder(
|
|
|
|
future: element.color,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
return Card(
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(15.0),
|
|
|
|
),
|
|
|
|
color: snapshot.data as Color,
|
|
|
|
child: Column(
|
|
|
|
children: cardChildren,
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
return (const Center(
|
|
|
|
child: CircularProgressIndicator()));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return const SizedBox.shrink();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return const LinearProgressIndicator();
|
|
|
|
}
|
|
|
|
});
|
2021-09-14 20:55:58 +02:00
|
|
|
children.add(card);
|
|
|
|
}
|
2021-11-16 19:41:35 +01:00
|
|
|
}
|
2021-09-14 20:55:58 +02:00
|
|
|
return LessonsListBuilder(lessons: children);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-06 11:01:44 +01:00
|
|
|
class TimetableInfo {
|
|
|
|
final String info;
|
|
|
|
TimetableInfo({required this.info});
|
|
|
|
factory TimetableInfo.fromJson(Map<String, dynamic> json) {
|
|
|
|
return TimetableInfo(info: json['info']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-14 20:55:58 +02:00
|
|
|
class ClassTimetable {
|
|
|
|
final List timetable;
|
|
|
|
ClassTimetable({required this.timetable});
|
|
|
|
factory ClassTimetable.fromJson(Map<String, dynamic> json) {
|
|
|
|
List<TimetableLesson> lessons = [];
|
|
|
|
json['courses'].forEach((value) {
|
2021-11-16 19:41:35 +01:00
|
|
|
String subject;
|
|
|
|
String teacher;
|
|
|
|
String room;
|
|
|
|
String info;
|
|
|
|
Color fontColor;
|
2021-11-06 11:01:44 +01:00
|
|
|
|
2021-09-14 20:55:58 +02:00
|
|
|
if (value['Fa'].runtimeType != String) {
|
2021-11-16 19:41:35 +01:00
|
|
|
subject = value['Fa']['#text'];
|
2021-09-14 20:55:58 +02:00
|
|
|
} else {
|
2021-11-16 19:41:35 +01:00
|
|
|
subject = value['Fa'];
|
2021-09-14 20:55:58 +02:00
|
|
|
}
|
2021-11-16 19:41:35 +01:00
|
|
|
|
2021-09-14 20:55:58 +02:00
|
|
|
if (value['Le'].runtimeType != String) {
|
|
|
|
teacher = value['Le']['#text'];
|
|
|
|
} else {
|
|
|
|
teacher = value['Le'];
|
|
|
|
}
|
2021-11-16 19:41:35 +01:00
|
|
|
|
2021-09-14 20:55:58 +02:00
|
|
|
if (value['Ra'].runtimeType != String && value['Ra'].runtimeType != int) {
|
2021-11-16 19:41:35 +01:00
|
|
|
if (value['Ra']['#text'] == ' ' || value['Ra']['#text'] == null) {
|
2021-09-14 20:55:58 +02:00
|
|
|
room = '';
|
|
|
|
} else {
|
2021-11-16 19:41:35 +01:00
|
|
|
room = value['Ra']['#text'].toString();
|
2021-09-14 20:55:58 +02:00
|
|
|
}
|
|
|
|
} else if (value['Ra'] == ' ') {
|
|
|
|
room = '';
|
|
|
|
} else {
|
2021-11-16 19:41:35 +01:00
|
|
|
room = value['Ra'].toString();
|
2021-09-14 20:55:58 +02:00
|
|
|
}
|
2021-11-16 19:41:35 +01:00
|
|
|
|
|
|
|
if (subject == '---') {
|
2021-09-14 20:55:58 +02:00
|
|
|
fontColor = Colors.red;
|
|
|
|
} else {
|
|
|
|
fontColor = Colors.white;
|
|
|
|
}
|
2021-11-16 19:41:35 +01:00
|
|
|
|
2021-09-14 20:55:58 +02:00
|
|
|
if (value['If'].runtimeType != String) {
|
|
|
|
info = '';
|
|
|
|
} else {
|
|
|
|
info = value['If'];
|
|
|
|
}
|
|
|
|
|
2021-11-16 19:41:35 +01:00
|
|
|
Future<Color> lessonColor = buildLessonColor(subject);
|
2021-09-14 20:55:58 +02:00
|
|
|
|
|
|
|
lessons.add(TimetableLesson(
|
|
|
|
value['St'],
|
2021-12-13 13:39:06 +01:00
|
|
|
value["Nr"],
|
2021-11-16 19:41:35 +01:00
|
|
|
subjects[subject] ?? subject.toString(),
|
2021-09-14 20:55:58 +02:00
|
|
|
teachers[teacher] ?? teacher.toString(),
|
|
|
|
room.toString(),
|
|
|
|
value['If'].toString(),
|
2021-11-06 11:01:44 +01:00
|
|
|
lessonColor,
|
2021-09-14 20:55:58 +02:00
|
|
|
fontColor,
|
|
|
|
info));
|
|
|
|
});
|
|
|
|
|
|
|
|
return ClassTimetable(timetable: lessons);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TimetableLesson {
|
|
|
|
final int count;
|
2021-12-13 13:39:06 +01:00
|
|
|
final int id;
|
2021-09-14 20:55:58 +02:00
|
|
|
final String name;
|
|
|
|
final String teacher;
|
|
|
|
final String room;
|
|
|
|
final String comment;
|
2021-11-06 11:01:44 +01:00
|
|
|
final Future<Color> color;
|
2021-09-14 20:55:58 +02:00
|
|
|
final Color fontColor;
|
|
|
|
final String info;
|
2021-12-13 13:39:06 +01:00
|
|
|
const TimetableLesson(this.count, this.id, this.name, this.teacher, this.room,
|
2021-09-14 20:55:58 +02:00
|
|
|
this.comment, this.color, this.fontColor, this.info);
|
|
|
|
}
|