X-Git-Url: http://git.pk910.de/?p=DHBWCampusApp.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fde%2Fdhbwloe%2Fcampusapp%2Fvorlesungen%2FCourseEvent.java;h=0e5a1cb1717ca17c3700d26ffdf156dfc8fd5151;hp=71a49cab5487321599a9c01356880b1428fbce39;hb=9a28e7b4c1520f629721693a04b4978fec9692e7;hpb=89252e3c22caf6dcccd0c50ad3a9282a53b5a890 diff --git a/app/src/main/java/de/dhbwloe/campusapp/vorlesungen/CourseEvent.java b/app/src/main/java/de/dhbwloe/campusapp/vorlesungen/CourseEvent.java index 71a49ca..0e5a1cb 100644 --- a/app/src/main/java/de/dhbwloe/campusapp/vorlesungen/CourseEvent.java +++ b/app/src/main/java/de/dhbwloe/campusapp/vorlesungen/CourseEvent.java @@ -1,24 +1,38 @@ package de.dhbwloe.campusapp.vorlesungen; +import net.fortuna.ical4j.model.Component; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import de.dhbwloe.campusapp.database.DatabaseManager; /** * Created by pk910 on 20.01.2016. */ -public class CourseEvent { +public class CourseEvent implements Comparable { + public enum CourseType { + COURSETYPE_NORMAL, + COURSETYPE_SPECIAL, + COURSETYPE_KLAUSUR, + } + private int iEventId; private String sCourseName; private String sUniqueId; private int iSequenceId; private long iEventFrom, iEventTo; - private String sEventTitle, sEventLocation, sEventStatus; + private String sEventTitle, sEventTitleShort, sEventTitleAuthor, sEventLocation, sEventStatus; private String sRecurRule, sExcludeDates; private CourseGroup oCourseGroup; + private CourseType oCourseType = null; private boolean bMustUpdate = false; private boolean bIsNew = false; - public CourseEvent(int id, String coursename, String uniqueid, int sequenceid, long eventfrom, long eventto, String title, String location, String status, String rrule, String exdates, CourseGroup group) { + private boolean bIsKlausurPraesi = false; + + public CourseEvent(int id, String coursename, String uniqueid, int sequenceid, long eventfrom, long eventto, String title, String location, String status, String rrule, String exdates, CourseGroup group, int eventtype) { iEventId = id; sCourseName = coursename; sUniqueId = uniqueid; @@ -32,8 +46,14 @@ public class CourseEvent { sExcludeDates = exdates; oCourseGroup = group; - if(group != null) + if(group != null) { group.addCourseEvent(this); + try { + oCourseType = CourseType.values()[eventtype]; + } catch(Exception e) {} + } + + ParseEventTitle(); } public CourseEvent(String coursename, String uniqueid, int sequenceid, boolean isNew) { @@ -44,6 +64,37 @@ public class CourseEvent { bMustUpdate = isNew; } + public void ParseEventTitle() { + Pattern pattern = Pattern.compile("^((Klausur|Tutorium|Pr(ä|ae)sentation)[ :]+)?(.*?)( - ([a-zA-Z., -]+))?$"); + Matcher m = pattern.matcher(sEventTitle); + CourseType oldtype = oCourseType; + boolean typeisset = (oCourseType != null); + if (m.matches()) { + String eventType = m.group(2); + if (!typeisset && eventType != null && !eventType.isEmpty()) { + if(eventType.equalsIgnoreCase("Klausur")) + oCourseType = CourseType.COURSETYPE_KLAUSUR; + else if(eventType.equalsIgnoreCase("Präsentation") || eventType.equalsIgnoreCase("Praesentation")) { + oCourseType = CourseType.COURSETYPE_KLAUSUR; + bIsKlausurPraesi = true; + } else if(eventType.equalsIgnoreCase("Tutorium")) + oCourseType = CourseType.COURSETYPE_SPECIAL; + + typeisset = true; + } + sEventTitleShort = m.group(4); + sEventTitleAuthor = m.group(6); + } else { + sEventTitleShort = sEventTitle; + sEventTitleAuthor = ""; + } + if(!typeisset) + oCourseType = CourseType.COURSETYPE_NORMAL; + + if(oldtype != oCourseType) + bMustUpdate = true; + } + public void setEventId(int id) { iEventId = id; } @@ -57,11 +108,11 @@ public class CourseEvent { bMustUpdate = false; } - public void update(DatabaseManager dbm) { + public void update(DatabaseManager dbm, Component event) { if(!bMustUpdate) return; - dbm.updateCourseCalendar(this); + dbm.updateCourseCalendar(this, event); resetUpdateFlag(); } @@ -69,6 +120,22 @@ public class CourseEvent { return oCourseGroup; } + public void setCourseType(CourseType type) { + oCourseType = type; + } + + public CourseType getCourseType() { + return oCourseType; + } + + public int getCourseTypeId() { + for(int i = 0; i < CourseType.values().length; i++) { + if(oCourseType == CourseType.values()[i]) + return i; + } + return 0; + } + public void setCourseGroup(CourseGroup group) { group.addCourseEvent(this); oCourseGroup = group; @@ -108,11 +175,18 @@ public class CourseEvent { return sEventTitle; } public String getGroupTitle() { - return sEventTitle; // maybe cut prof name? + return sEventTitleShort + (sEventTitleAuthor == null ? "" : " - " + sEventTitleAuthor); + } + public String getEventShortTitle() { + return sEventTitleShort; + } + public String getEventDozent() { + return sEventTitleAuthor; } public void setEventTitle(String sEventTitle) { this.sEventTitle = sEventTitle; + ParseEventTitle(); bMustUpdate = true; } @@ -164,4 +238,13 @@ public class CourseEvent { this.sExcludeDates = exrules; bMustUpdate = true; } + + public boolean getIsKlausurPraesi() { + return bIsKlausurPraesi; + } + + @Override + public int compareTo(CourseEvent another) { + return (int)(another.getEventFrom() - iEventFrom); + } }