Commit 6664b3e3 authored by wonko's avatar wonko

lecture cards werden nach vortragszeiten skaliert

parent 9bc54dee
......@@ -70,6 +70,8 @@ class Lectures {
String version;
List<Room> rooms = [];
static DateTime startTime = DateTime(2019, 6, 14, 17, 0);
Lectures(final this.version, final this.rooms);
Lectures.fromJSON(Map<String, dynamic> json) {
......@@ -115,17 +117,24 @@ class TimeSlot extends Comparable {
}
class Room {
String name;
List<TimeSlot> timeSlots = [];
final String name;
final List<TimeSlot> timeSlots;
final List<Lecture> lectures;
Room(final this.name, final this.timeSlots);
Room.fromJSON(Map<String, dynamic> json) {
name = json['name'];
Room(final this.name, final this.timeSlots, this.lectures);
factory Room.fromJSON(Map<String, dynamic> json) {
String name = json['name'];
List<TimeSlot> timeSlots = [];
List<Lecture> lectures = [];
for (var ti in json['times']) {
timeSlots.add(TimeSlot.fromJSON(ti));
TimeSlot ts = TimeSlot.fromJSON(ti);
timeSlots.add(ts);
if (ts.lecture != null) {
lectures.add(ts.lecture);
}
}
return Room(name, timeSlots, lectures);
}
String toString() {
......@@ -134,6 +143,7 @@ class Room {
}
class Lecture {
static const String _emptyID = 'placeholder';
final String fs, name, teaser, time, room, id;
final bool aufz;
bool _like = false;
......@@ -147,6 +157,10 @@ class Lecture {
saveBoolPref(id, _like);
}
bool isEmpy() {
return (id == Lecture._emptyID);
}
void readLike(String prefId, {bool valDefault = false}) {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
prefs.then((SharedPreferences p) {
......@@ -177,14 +191,32 @@ class Lecture {
final this.end,
final this.id);
factory Lecture.empty({DateTime start, DateTime end}) {
return Lecture(
null, null, null, null, null, null, start, end, Lecture._emptyID);
}
@override
String toString(){
return "Lecture $id ${start} ${end}";
}
static DateTime fromDateandTime(DateTime date, String timeString) {
timeString = timeString.trim();
List<String> timeHM = timeString.split('.');
int hours = int.parse(timeHM[0]);
int minutes = int.parse(timeHM[1]);
return DateTime(date.year, date.month, date.day, hours, minutes);
}
factory Lecture.fromJSON(Map<String, dynamic> json) {
if (json != null) {
String time = json['time'];
List<String> times = time.split('-');
String startTime = times[0].trim().replaceAll(".", ":");
String endTime = times[1].trim().replaceAll(".", ":");
DateTime start = DateTime.parse("2002-02-27T${startTime}:00Z");
DateTime end = DateTime.parse("2002-02-27T${endTime}:00Z");
DateTime start = fromDateandTime(Lectures.startTime, times[0]);
DateTime end = fromDateandTime(Lectures.startTime, times[1]);
String lectureID = json['id'];
if ((lectureID == null || lectureID == "") && json['teaser'] != null) {
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment