6ad143195a
- added A LOT, TLTD Settings menu, updated homepage tiles, added color settings... - TODO: - update README - update license & copyright info - cleanup code - merge code parts to server side - complete settings - fix 11/12 - add caching - muuuuuuuch more...
216 lines
6.9 KiB
Dart
216 lines
6.9 KiB
Dart
import 'package:MeinCantor/teacher_presets.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'subject_presets.dart';
|
|
|
|
import 'color_presets.dart';
|
|
|
|
class ClassTimetableBuilder {
|
|
final RefreshIndicator view;
|
|
ClassTimetableBuilder({required this.view});
|
|
factory ClassTimetableBuilder.buildView(Map<String, dynamic> json, BuildContext context) {
|
|
List<Widget> list = LessonsListBuilder.buildList(json).lessons;
|
|
String info = TimetableInfo.fromJson(json).info;
|
|
if(info.isNotEmpty) {
|
|
list.insert(0, ListTile(title: Text("Informationen"), leading: Icon(MdiIcons.information), onTap: () {
|
|
showModalBottomSheet<void>(
|
|
isScrollControlled: true,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(25.0),
|
|
),
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return Container(
|
|
height: 400,
|
|
child: ListView(
|
|
//mainAxisAlignment: MainAxisAlignment.center,
|
|
//mainAxisSize: MainAxisSize.min,
|
|
children: <Widget>[
|
|
ListTile(
|
|
title: Text("Informationen", style: TextStyle(fontWeight: FontWeight.bold)),
|
|
leading: Icon(Icons.arrow_back),
|
|
onTap: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.all(20),
|
|
child: Text(info),
|
|
),
|
|
/*ElevatedButton(
|
|
child: const Text('Close BottomSheet'),
|
|
onPressed: () => Navigator.pop(context),
|
|
)*/
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
)
|
|
);
|
|
}
|
|
return ClassTimetableBuilder(
|
|
view: RefreshIndicator(
|
|
onRefresh: () {
|
|
return Future.delayed(const Duration(seconds: 1));
|
|
},
|
|
child: ListView(
|
|
//shrinkWrap: true,
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
children: list,
|
|
),
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
class LessonsListBuilder {
|
|
final List<Widget> lessons;
|
|
LessonsListBuilder({required this.lessons});
|
|
factory LessonsListBuilder.buildList(Map<String, dynamic> json, {int count: 0}) {
|
|
List<Widget> children = [];
|
|
ClassTimetable.fromJson(json).timetable.forEach((element) {
|
|
List<Widget> cardChildren = [];
|
|
print(element.count.toString() + " " + count.toString());
|
|
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))));
|
|
}
|
|
Widget card = 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()));
|
|
}
|
|
},
|
|
);
|
|
children.add(card);
|
|
}
|
|
});
|
|
return LessonsListBuilder(lessons: children);
|
|
}
|
|
}
|
|
|
|
class TimetableInfo {
|
|
final String info;
|
|
TimetableInfo({required this.info});
|
|
factory TimetableInfo.fromJson(Map<String, dynamic> json) {
|
|
return TimetableInfo(info: json['info']);
|
|
}
|
|
}
|
|
|
|
class ClassTimetable {
|
|
final List timetable;
|
|
ClassTimetable({required this.timetable});
|
|
factory ClassTimetable.fromJson(Map<String, dynamic> json) {
|
|
print(json);
|
|
List<TimetableLesson> lessons = [];
|
|
json['courses'].forEach((value) {
|
|
var name;
|
|
var teacher;
|
|
var room;
|
|
|
|
if (value['Fa'].runtimeType != String) {
|
|
name = value['Fa']['#text'];
|
|
} else {
|
|
name = value['Fa'];
|
|
}
|
|
if (value['Le'].runtimeType != String) {
|
|
teacher = value['Le']['#text'];
|
|
} else {
|
|
teacher = value['Le'];
|
|
}
|
|
print(value['Ra']);
|
|
if (value['Ra'].runtimeType != String && value['Ra'].runtimeType != int) {
|
|
if (value['Ra']['#text'] == ' ') {
|
|
room = '';
|
|
} else if (value['Ra']['#text'] == null) {
|
|
room = '';
|
|
} else {
|
|
room = value['Ra']['#text'];
|
|
}
|
|
} else if (value['Ra'] == ' ') {
|
|
room = '';
|
|
} else {
|
|
room = value['Ra'];
|
|
}
|
|
Color fontColor;
|
|
if (name == '---') {
|
|
fontColor = Colors.red;
|
|
} else {
|
|
fontColor = Colors.white;
|
|
}
|
|
var info;
|
|
if (value['If'].runtimeType != String) {
|
|
info = '';
|
|
} else {
|
|
info = value['If'];
|
|
}
|
|
|
|
Future<Color> lessonColor = buildLessonColor(name);
|
|
|
|
lessons.add(TimetableLesson(
|
|
value['St'],
|
|
names[name] ?? name.toString(),
|
|
teachers[teacher] ?? teacher.toString(),
|
|
room.toString(),
|
|
value['If'].toString(),
|
|
lessonColor,
|
|
fontColor,
|
|
info));
|
|
});
|
|
|
|
return ClassTimetable(timetable: lessons);
|
|
}
|
|
}
|
|
|
|
class TimetableLesson {
|
|
final int count;
|
|
final String name;
|
|
final String teacher;
|
|
final String room;
|
|
final String comment;
|
|
final Future<Color> color;
|
|
final Color fontColor;
|
|
final String info;
|
|
const TimetableLesson(this.count, this.name, this.teacher, this.room,
|
|
this.comment, this.color, this.fontColor, this.info);
|
|
}
|