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();
|
||||
|
||||
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) {
|
||||
Log.d("error", e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE);
|
||||
String lastModifiedOld = sharedpreferences.getString(getString(R.string.saved_last_modified_key), "");
|
||||
|
||||
|
||||
|
|
|
@ -27,12 +27,15 @@ public class 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()));
|
||||
List<VeventString> veventStrings=new ArrayList<>();
|
||||
List<VeventString> veventStrings = new ArrayList<>();
|
||||
try {
|
||||
|
||||
ICalendar ical;
|
||||
|
@ -44,21 +47,21 @@ public class IcalToStr {
|
|||
DateStart dtstart = event.getDateStart();
|
||||
|
||||
TimeZone timezone;
|
||||
if (tzinfo.isFloating(dtstart)){
|
||||
if (tzinfo.isFloating(dtstart)) {
|
||||
timezone = TimeZone.getDefault();
|
||||
} else {
|
||||
TimezoneAssignment dtstartTimezone = tzinfo.getTimezone(dtstart);
|
||||
timezone = (dtstartTimezone == null) ? TimeZone.getTimeZone("UTC") : dtstartTimezone.getTimeZone();
|
||||
}
|
||||
|
||||
veventStrings.addAll(buildList(ical.getEvents(),timezone));
|
||||
veventStrings.addAll(buildList(ical.getEvents(), timezone, classes_to_ignore));
|
||||
|
||||
}
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
|
||||
Collections.sort(veventStrings, new Comparator<VeventString>(){
|
||||
Collections.sort(veventStrings, new Comparator<VeventString>() {
|
||||
public int compare(VeventString event1, VeventString event2) {
|
||||
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 relevent;
|
||||
boolean future;
|
||||
boolean isTest;
|
||||
Date today=new Date();
|
||||
Date today = new Date();
|
||||
today.setHours(0);
|
||||
String category;
|
||||
Date dateStartVal;
|
||||
Date dateEndVal;
|
||||
for (VEvent event : events) {
|
||||
|
||||
dateStartVal=event.getDateStart().getValue();
|
||||
dateStartVal = event.getDateStart().getValue();
|
||||
|
||||
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");
|
||||
Summary summary = event.getSummary();
|
||||
String summaryStr = (summary == null) ? "" : summary.getValue();
|
||||
|
||||
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);
|
||||
Date current;
|
||||
Date end;
|
||||
while(it.hasNext()){
|
||||
while (it.hasNext()) {
|
||||
|
||||
current =it.next();
|
||||
end=new Date();
|
||||
current = it.next();
|
||||
end = new Date();
|
||||
end.setHours(dateEndVal.getHours());
|
||||
end.setMinutes(dateEndVal.getMinutes());
|
||||
end.setDate(current.getDate());
|
||||
end.setYear(current.getYear());
|
||||
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;
|
||||
Date today=new Date();
|
||||
Date today = new Date();
|
||||
boolean sameDay;
|
||||
boolean sameMonth;
|
||||
Date previousDate=today;
|
||||
Date previousDate = today;
|
||||
boolean isTest;
|
||||
String dateEndStr;
|
||||
String dateStartStr;
|
||||
Date dateStartVal;
|
||||
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");
|
||||
|
||||
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) {
|
||||
|
||||
dateStartVal=e.getStartdate();
|
||||
dateEndVal=e.getEnddate();
|
||||
future= dateEndVal.compareTo(today)>=0;
|
||||
if (future && counter<25){
|
||||
dateStartVal = e.getStartdate();
|
||||
dateEndVal = e.getEnddate();
|
||||
future = dateEndVal.compareTo(today) >= 0;
|
||||
if (future && counter < 50) {
|
||||
|
||||
sameDay= dateStartVal.getDay()==previousDate.getDay();
|
||||
sameMonth=dateStartVal.getMonth()==previousDate.getMonth();
|
||||
sameDay = dateStartVal.getDay() == previousDate.getDay();
|
||||
sameMonth = dateStartVal.getMonth() == previousDate.getMonth();
|
||||
|
||||
dateEndStr = dfEnd.format(dateEndVal);
|
||||
dateEndStr = dfEnd.format(dateEndVal);
|
||||
dateStartStr = df.format(dateStartVal);
|
||||
|
||||
previousDate=dateStartVal;
|
||||
previousDate = dateStartVal;
|
||||
|
||||
isTest=e.isTest();
|
||||
isTest = e.isTest();
|
||||
|
||||
stringBuilder.append(
|
||||
(sameDay? "\n":"\n[s=0.3]################################################\n[/s]")+
|
||||
(sameMonth? "":"[s=0.3]################################################\n[/s]")+
|
||||
(isTest? "[c=testc]":"[c=datec]") +dateStartStr +" - " + dateEndStr + (isTest ? "":"[/c]") + ": "
|
||||
+ (isTest ? "":"[c=namec]") +e.getDescription()+"[/c]");
|
||||
(sameDay ? "\n" : "\n[s=0.3]################################################\n[/s]") +
|
||||
(sameMonth ? "" : "[s=0.3]################################################\n[/s]") +
|
||||
(isTest ? "[c=testc]" : "[c=datec]") + dateStartStr + " - " + dateEndStr + (isTest ? "" : "[/c]") + ": "
|
||||
+ (isTest ? "" : "[c=namec]") + e.getDescription() + "[/c]");
|
||||
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,8 +5,10 @@
|
|||
|
||||
|
||||
<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="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"
|
||||
/>
|
||||
|
||||
<EditTextPreference
|
||||
app:key="ignore_classes"
|
||||
app:title="@string/ignore_classes"
|
||||
app:useSimpleSummaryProvider="true"
|
||||
app:defaultValue="ERP-Systeme,Kommunikations und Netztechnik II"
|
||||
/>
|
||||
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue