add courses blacklist
This commit is contained in:
parent
e1a00d14de
commit
1ae16e5eb2
|
@ -105,17 +105,31 @@ public class ToKservice extends IntentService {
|
||||||
IcalToStr icalToStr = new IcalToStr();
|
IcalToStr icalToStr = new IcalToStr();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = icalToStr.icalToSting(url);
|
|
||||||
|
SharedPreferences sharedpreferences = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE);
|
||||||
|
|
||||||
|
String ignore_classes = sharedpreferences.getString("ignore_classes", "");
|
||||||
|
|
||||||
|
|
||||||
|
result = icalToStr.icalToSting(url, ignore_classes);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
Log.d("error", e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkLastModified(URL url) {
|
public boolean checkLastModified(URL url) {
|
||||||
|
|
||||||
|
SharedPreferences sharedpreferences = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE);
|
||||||
|
boolean disable_cache = sharedpreferences.getBoolean("disable_cache", true);
|
||||||
|
|
||||||
|
if (disable_cache) {
|
||||||
|
return disable_cache;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
SharedPreferences sharedpreferences = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE);
|
|
||||||
String lastModifiedOld = sharedpreferences.getString(getString(R.string.saved_last_modified_key), "");
|
String lastModifiedOld = sharedpreferences.getString(getString(R.string.saved_last_modified_key), "");
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,12 +27,15 @@ public class IcalToStr {
|
||||||
public IcalToStr() {
|
public IcalToStr() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String icalToSting(URL url) throws IOException {
|
public String icalToSting(URL url, String ignore_classes) throws IOException {
|
||||||
|
|
||||||
|
|
||||||
ICalReader reader = new ICalReader( new InputStreamReader(
|
String[] classes_to_ignore = ignore_classes.split(",");
|
||||||
|
|
||||||
|
|
||||||
|
ICalReader reader = new ICalReader(new InputStreamReader(
|
||||||
url.openStream()));
|
url.openStream()));
|
||||||
List<VeventString> veventStrings=new ArrayList<>();
|
List<VeventString> veventStrings = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ICalendar ical;
|
ICalendar ical;
|
||||||
|
@ -44,21 +47,21 @@ public class IcalToStr {
|
||||||
DateStart dtstart = event.getDateStart();
|
DateStart dtstart = event.getDateStart();
|
||||||
|
|
||||||
TimeZone timezone;
|
TimeZone timezone;
|
||||||
if (tzinfo.isFloating(dtstart)){
|
if (tzinfo.isFloating(dtstart)) {
|
||||||
timezone = TimeZone.getDefault();
|
timezone = TimeZone.getDefault();
|
||||||
} else {
|
} else {
|
||||||
TimezoneAssignment dtstartTimezone = tzinfo.getTimezone(dtstart);
|
TimezoneAssignment dtstartTimezone = tzinfo.getTimezone(dtstart);
|
||||||
timezone = (dtstartTimezone == null) ? TimeZone.getTimeZone("UTC") : dtstartTimezone.getTimeZone();
|
timezone = (dtstartTimezone == null) ? TimeZone.getTimeZone("UTC") : dtstartTimezone.getTimeZone();
|
||||||
}
|
}
|
||||||
|
|
||||||
veventStrings.addAll(buildList(ical.getEvents(),timezone));
|
veventStrings.addAll(buildList(ical.getEvents(), timezone, classes_to_ignore));
|
||||||
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
reader.close();
|
reader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(veventStrings, new Comparator<VeventString>(){
|
Collections.sort(veventStrings, new Comparator<VeventString>() {
|
||||||
public int compare(VeventString event1, VeventString event2) {
|
public int compare(VeventString event1, VeventString event2) {
|
||||||
return event1.getStartdate().compareTo(event2.getStartdate());
|
return event1.getStartdate().compareTo(event2.getStartdate());
|
||||||
}
|
}
|
||||||
|
@ -67,50 +70,53 @@ public class IcalToStr {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<VeventString> buildList(List<VEvent> events,TimeZone timeZone){
|
public List<VeventString> buildList(List<VEvent> events, TimeZone timeZone, String[] classes_to_ignore) {
|
||||||
|
|
||||||
List<VeventString> eventStrings =new ArrayList<VeventString>();
|
List<VeventString> eventStrings = new ArrayList<VeventString>();
|
||||||
boolean repeating;
|
boolean repeating;
|
||||||
boolean relevent;
|
boolean relevent;
|
||||||
boolean future;
|
boolean future;
|
||||||
boolean isTest;
|
boolean isTest;
|
||||||
Date today=new Date();
|
Date today = new Date();
|
||||||
today.setHours(0);
|
today.setHours(0);
|
||||||
String category;
|
String category;
|
||||||
Date dateStartVal;
|
Date dateStartVal;
|
||||||
Date dateEndVal;
|
Date dateEndVal;
|
||||||
for (VEvent event : events) {
|
for (VEvent event : events) {
|
||||||
|
|
||||||
dateStartVal=event.getDateStart().getValue();
|
dateStartVal = event.getDateStart().getValue();
|
||||||
|
|
||||||
future= dateStartVal.compareTo(new DateStart(today).getValue())>=0;
|
Summary summary = event.getSummary();
|
||||||
category=event.getCategories().get(0).getValues().get(0).toString();
|
String summaryStr = (summary == null) ? "" : summary.getValue();
|
||||||
repeating= event.getRecurrenceRule()!=null;
|
|
||||||
relevent= !category.equalsIgnoreCase("Sonstiger Termin");
|
|
||||||
|
|
||||||
if (relevent && (future || repeating )){
|
future = dateStartVal.compareTo(new DateStart(today).getValue()) >= 0;
|
||||||
|
category = event.getCategories().get(0).getValues().get(0).toString();
|
||||||
|
repeating = event.getRecurrenceRule() != null;
|
||||||
|
relevent = !category.equalsIgnoreCase("Sonstiger Termin")
|
||||||
|
&& !Arrays.asList(classes_to_ignore).contains(summaryStr);
|
||||||
|
|
||||||
dateEndVal=event.getDateEnd().getValue();
|
if (relevent && (future || repeating)) {
|
||||||
|
|
||||||
|
dateEndVal = event.getDateEnd().getValue();
|
||||||
|
|
||||||
|
isTest = category.equalsIgnoreCase("Prüfung");
|
||||||
|
|
||||||
isTest=category.equalsIgnoreCase("Prüfung");
|
|
||||||
|
|
||||||
Summary summary = event.getSummary();
|
|
||||||
String summaryStr = (summary == null) ? null : summary.getValue();
|
|
||||||
|
|
||||||
DateIterator it = event.getDateIterator(timeZone);
|
DateIterator it = event.getDateIterator(timeZone);
|
||||||
Date current;
|
Date current;
|
||||||
Date end;
|
Date end;
|
||||||
while(it.hasNext()){
|
while (it.hasNext()) {
|
||||||
|
|
||||||
current =it.next();
|
current = it.next();
|
||||||
end=new Date();
|
end = new Date();
|
||||||
end.setHours(dateEndVal.getHours());
|
end.setHours(dateEndVal.getHours());
|
||||||
end.setMinutes(dateEndVal.getMinutes());
|
end.setMinutes(dateEndVal.getMinutes());
|
||||||
end.setDate(current.getDate());
|
end.setDate(current.getDate());
|
||||||
end.setYear(current.getYear());
|
end.setYear(current.getYear());
|
||||||
end.setMonth(current.getMonth()); // @todo: horrible, but works to set time and day separably
|
end.setMonth(current.getMonth()); // @todo: horrible, but works to set time and day separably
|
||||||
|
|
||||||
eventStrings.add(new VeventString(current,end,summaryStr,isTest));
|
eventStrings.add(new VeventString(current, end, summaryStr, isTest));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,55 +124,54 @@ public class IcalToStr {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String buidSting(List<VeventString> events) {
|
||||||
public String buidSting(List<VeventString> events){
|
|
||||||
|
|
||||||
boolean future;
|
boolean future;
|
||||||
Date today=new Date();
|
Date today = new Date();
|
||||||
boolean sameDay;
|
boolean sameDay;
|
||||||
boolean sameMonth;
|
boolean sameMonth;
|
||||||
Date previousDate=today;
|
Date previousDate = today;
|
||||||
boolean isTest;
|
boolean isTest;
|
||||||
String dateEndStr;
|
String dateEndStr;
|
||||||
String dateStartStr;
|
String dateStartStr;
|
||||||
Date dateStartVal;
|
Date dateStartVal;
|
||||||
Date dateEndVal;
|
Date dateEndVal;
|
||||||
int counter=0;
|
int counter = 0;
|
||||||
|
|
||||||
DateFormat df = new SimpleDateFormat("EE: dd/MM/yyyy HH:mm",Locale.GERMANY);
|
DateFormat df = new SimpleDateFormat("EE: dd/MM/yyyy HH:mm", Locale.GERMANY);
|
||||||
|
|
||||||
DateFormat dfEnd = new SimpleDateFormat("HH:mm");
|
DateFormat dfEnd = new SimpleDateFormat("HH:mm");
|
||||||
|
|
||||||
StringBuilder stringBuilder=new StringBuilder( "Last update: " +new SimpleDateFormat("dd/MM HH:mm").format(Calendar.getInstance().getTime()));
|
StringBuilder stringBuilder = new StringBuilder("Last update: " + new SimpleDateFormat("dd/MM HH:mm").format(Calendar.getInstance().getTime()));
|
||||||
|
|
||||||
for (VeventString e:
|
for (VeventString e :
|
||||||
events) {
|
events) {
|
||||||
|
|
||||||
dateStartVal=e.getStartdate();
|
dateStartVal = e.getStartdate();
|
||||||
dateEndVal=e.getEnddate();
|
dateEndVal = e.getEnddate();
|
||||||
future= dateEndVal.compareTo(today)>=0;
|
future = dateEndVal.compareTo(today) >= 0;
|
||||||
if (future && counter<25){
|
if (future && counter < 50) {
|
||||||
|
|
||||||
sameDay= dateStartVal.getDay()==previousDate.getDay();
|
sameDay = dateStartVal.getDay() == previousDate.getDay();
|
||||||
sameMonth=dateStartVal.getMonth()==previousDate.getMonth();
|
sameMonth = dateStartVal.getMonth() == previousDate.getMonth();
|
||||||
|
|
||||||
dateEndStr = dfEnd.format(dateEndVal);
|
dateEndStr = dfEnd.format(dateEndVal);
|
||||||
dateStartStr = df.format(dateStartVal);
|
dateStartStr = df.format(dateStartVal);
|
||||||
|
|
||||||
previousDate=dateStartVal;
|
previousDate = dateStartVal;
|
||||||
|
|
||||||
isTest=e.isTest();
|
isTest = e.isTest();
|
||||||
|
|
||||||
stringBuilder.append(
|
stringBuilder.append(
|
||||||
(sameDay? "\n":"\n[s=0.3]################################################\n[/s]")+
|
(sameDay ? "\n" : "\n[s=0.3]################################################\n[/s]") +
|
||||||
(sameMonth? "":"[s=0.3]################################################\n[/s]")+
|
(sameMonth ? "" : "[s=0.3]################################################\n[/s]") +
|
||||||
(isTest? "[c=testc]":"[c=datec]") +dateStartStr +" - " + dateEndStr + (isTest ? "":"[/c]") + ": "
|
(isTest ? "[c=testc]" : "[c=datec]") + dateStartStr + " - " + dateEndStr + (isTest ? "" : "[/c]") + ": "
|
||||||
+ (isTest ? "":"[c=namec]") +e.getDescription()+"[/c]");
|
+ (isTest ? "" : "[c=namec]") + e.getDescription() + "[/c]");
|
||||||
|
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return stringBuilder.toString();
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,10 @@
|
||||||
|
|
||||||
|
|
||||||
<string name="rapla_url">The url of the rapla course.</string>
|
<string name="rapla_url">The url of the rapla course.</string>
|
||||||
|
<string name="ignore_classes">Comma separated List of classes to ignore.</string>
|
||||||
<string name="kustom_code">The forumla to put into kustom live wall paper.</string>
|
<string name="kustom_code">The forumla to put into kustom live wall paper.</string>
|
||||||
<string name="enable">Enable loading the information.</string>
|
<string name="enable">Enable loading the information.</string>
|
||||||
|
<string name="disable_cache">Force a refresh.</string>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,23 @@
|
||||||
app:defaultValue="https://rapla.dhbw-karlsruhe.de/rapla?page=ical&user=braun&file=TINF19B2&day=17&month=4&year=2020&today=Heute"
|
app:defaultValue="https://rapla.dhbw-karlsruhe.de/rapla?page=ical&user=braun&file=TINF19B2&day=17&month=4&year=2020&today=Heute"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<EditTextPreference
|
||||||
|
app:key="ignore_classes"
|
||||||
|
app:title="@string/ignore_classes"
|
||||||
|
app:useSimpleSummaryProvider="true"
|
||||||
|
app:defaultValue="ERP-Systeme,Kommunikations und Netztechnik II"
|
||||||
|
/>
|
||||||
|
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
<SwitchPreferenceCompat
|
||||||
app:key="sync"
|
app:key="sync"
|
||||||
app:title="@string/enable"/>
|
app:title="@string/enable"
|
||||||
|
app:defaultValue="true"/>
|
||||||
|
|
||||||
|
<SwitchPreferenceCompat
|
||||||
|
app:key="disable_cache"
|
||||||
|
app:title="@string/disable_cache"
|
||||||
|
app:defaultValue="false"/>
|
||||||
|
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
|
|
Loading…
Reference in a new issue