Added event order
This commit is contained in:
@@ -142,23 +142,31 @@ public class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.
|
||||
Announcement announce = mValue.announcements.get(index);
|
||||
i.mTitle.setText(announce.getTitle());
|
||||
i.mSubLeft.setText(announce.getCreatedBy());
|
||||
i.mSubRight.setText(Conversion.getModifiedDate(announce.getCreatedOn()));
|
||||
i.mSubRight.setText(Conversion.getModifiedDateTime(announce.getCreatedOn()));
|
||||
i.mView.setOnClickListener(view -> log.d("Reference to:", SECTION_ANNOUNCEMENT, index));
|
||||
break;
|
||||
case SECTION_ASSIGNMENT:
|
||||
Assignment assignment = mValue.assignments.get(index);
|
||||
i.mTitle.setText(assignment.getTitle());
|
||||
i.mSubLeft.setText(assignment.getStatus());
|
||||
i.mSubRight.setText(Conversion.getModifiedDate(assignment.getDueDate()));
|
||||
i.mSubRight.setText(Conversion.getModifiedDateTime(assignment.getDueDate()));
|
||||
i.mView.setOnClickListener(view -> log.d("Reference to:", SECTION_ASSIGNMENT, index));
|
||||
break;
|
||||
case SECTION_EVENTS:
|
||||
Event event = mValue.events.get(index);
|
||||
Event event = mValue.events.getUpcoming(index);
|
||||
i.mTitle.setText(event.getTitle());
|
||||
i.mSubLeft.setText(event.getType());
|
||||
String start, end;
|
||||
if (Conversion.dateEquals(event.getStartDate(), System.currentTimeMillis()))
|
||||
start = Conversion.getModifiedTime(event.getStartDate());
|
||||
else
|
||||
start = Conversion.getModifiedDateTime(event.getStartDate());
|
||||
if (Conversion.dateEquals(event.getStartDate(), event.getEndDate()))
|
||||
end = Conversion.getModifiedTime(event.getEndDate());
|
||||
else
|
||||
end = Conversion.getModifiedDateTime(event.getEndDate());
|
||||
i.mSubRight.setText(i.mView.getResources().getString(R.string.date_scale,
|
||||
Conversion.getModifiedDate(event.getStartDate()),
|
||||
Conversion.getModifiedDate(event.getEndDate())
|
||||
start, end
|
||||
));
|
||||
i.mView.setOnClickListener(view -> log.d("Reference to:", SECTION_EVENTS, index));
|
||||
}
|
||||
@@ -187,7 +195,7 @@ public class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.
|
||||
|
||||
private int getEventsCount() {
|
||||
if (mValue.events != null)
|
||||
return mValue.events.size();
|
||||
return mValue.events.sizeUpcoming();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public class Assignment {
|
||||
|
||||
public String getStatus() {
|
||||
return "Assignment Status";
|
||||
}
|
||||
} // TODO Get status
|
||||
|
||||
public long getDueDate() {
|
||||
return dueTime;
|
||||
|
||||
@@ -9,11 +9,14 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.regex.MatchResult;
|
||||
|
||||
import de.sebse.fuplanner.tools.AsyncQueue;
|
||||
import de.sebse.fuplanner.tools.EventList;
|
||||
import de.sebse.fuplanner.tools.Regex;
|
||||
import de.sebse.fuplanner.tools.network.HTTPService;
|
||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||
@@ -247,7 +250,7 @@ public class KVVModuleList extends HTTPService {
|
||||
});
|
||||
}
|
||||
|
||||
private void getEventsUpgrade(String ID, final NetworkCallback<ArrayList<Event>> callback, final NetworkErrorCallback errorCallback) {
|
||||
private void getEventsUpgrade(String ID, final NetworkCallback<EventList> callback, final NetworkErrorCallback errorCallback) {
|
||||
//https://kvv.imp.fu-berlin.de/direct/calendar/site/91c6e9cc-58eb-486d-ab99-a22a40997d1b.json
|
||||
get(String.format("https://kvv.imp.fu-berlin.de/direct/calendar/site/%s.json", ID), token.getCookies(), response -> {
|
||||
String body = response.getParsed();
|
||||
@@ -255,7 +258,7 @@ public class KVVModuleList extends HTTPService {
|
||||
errorCallback.onError(new NetworkError(101401, 403, "No calendar retrieved!"));
|
||||
return;
|
||||
}
|
||||
ArrayList<Event> events = new ArrayList<>();
|
||||
EventList events = new EventList();
|
||||
try {
|
||||
JSONObject json = new JSONObject(body);
|
||||
JSONArray sites = json.getJSONArray("calendar_collection");
|
||||
@@ -274,6 +277,7 @@ public class KVVModuleList extends HTTPService {
|
||||
errorCallback.onError(new NetworkError(101402, 403, "Cannot parse calendar entries!"));
|
||||
return;
|
||||
}
|
||||
events.sort();
|
||||
callback.onResponse(events);
|
||||
}, error -> errorCallback.onError(new NetworkError(101403, error.networkResponse.statusCode, "Cannot get calendar entries!")));
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
import de.sebse.fuplanner.tools.Compare;
|
||||
import de.sebse.fuplanner.tools.EventList;
|
||||
import de.sebse.fuplanner.tools.Regex;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
|
||||
@@ -24,7 +25,10 @@ public class Modules /*extends EventEmitter<Triplet<Integer, Modules.UpgradeModu
|
||||
this.list = new SortedList<>(Module.class, new SortedList.Callback<Module>() {
|
||||
@Override
|
||||
public int compare(Module o1, Module o2) {
|
||||
return o1.semester.compareTo(o2.semester);
|
||||
int semester = o1.semester.compareTo(o2.semester);
|
||||
if (semester != 0)
|
||||
return semester;
|
||||
return o1.title.compareToIgnoreCase(o2.title);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -189,7 +193,7 @@ public class Modules /*extends EventEmitter<Triplet<Integer, Modules.UpgradeModu
|
||||
private final String ID;
|
||||
public ArrayList<Announcement> announcements;
|
||||
public ArrayList<Assignment> assignments;
|
||||
public ArrayList<Event> events;
|
||||
public EventList events;
|
||||
|
||||
/*private Module() {
|
||||
this(null, null, null, null, null);
|
||||
|
||||
@@ -10,28 +10,37 @@ import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
public class Conversion {
|
||||
public static String getModifiedDateTime(long modified) {
|
||||
return getModifiedDate(Locale.getDefault(), modified, "MM/dd/yy hh:mm");
|
||||
}
|
||||
|
||||
|
||||
public static String getModifiedTime(long modified) {
|
||||
return getModifiedDate(Locale.getDefault(), modified, "hh:mm");
|
||||
}
|
||||
|
||||
public static String getModifiedDate(long modified) {
|
||||
return getModifiedDate(Locale.getDefault(), modified);
|
||||
return getModifiedDate(Locale.getDefault(), modified, "MM/dd/yy");
|
||||
}
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
public static String getModifiedDate(Locale locale, long modified) {
|
||||
public static String getModifiedDate(Locale locale, long modified, String skeleton) {
|
||||
SimpleDateFormat dateFormat;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
dateFormat = new SimpleDateFormat(getDateFormat(locale));
|
||||
dateFormat = new SimpleDateFormat(getDateFormat(locale, skeleton));
|
||||
} else {
|
||||
dateFormat = new SimpleDateFormat("MMM/dd/yyyy hh:mm:ss aa", locale);
|
||||
dateFormat = new SimpleDateFormat(skeleton, locale);
|
||||
}
|
||||
|
||||
return dateFormat.format(new Date(modified));
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
|
||||
public static String getDateFormat(Locale locale) {
|
||||
return DateFormat.getBestDateTimePattern(locale, "MM/dd/yyyy hh:mm:ss aa");
|
||||
public static String getDateFormat(Locale locale, String skeleton) {
|
||||
return DateFormat.getBestDateTimePattern(locale, skeleton);
|
||||
}
|
||||
|
||||
public static boolean dateEquals(long a, long b) {
|
||||
return a / 86400000 == b / 86400000;
|
||||
}
|
||||
}
|
||||
|
||||
56
app/src/main/java/de/sebse/fuplanner/tools/EventList.java
Normal file
56
app/src/main/java/de/sebse/fuplanner/tools/EventList.java
Normal file
@@ -0,0 +1,56 @@
|
||||
package de.sebse.fuplanner.tools;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import de.sebse.fuplanner.services.KVV.Event;
|
||||
|
||||
public class EventList extends ArrayList<Event> {
|
||||
private int split = 0;
|
||||
|
||||
public Event getPast(int index) {
|
||||
if (split < 0)
|
||||
sort();
|
||||
if (index >= split)
|
||||
throw new ArrayIndexOutOfBoundsException(String.format("Index %d out of bounds! Only %d past events found!", index, split));
|
||||
return this.get(index);
|
||||
}
|
||||
|
||||
public Event getUpcoming(int index) {
|
||||
if (split < 0)
|
||||
sort();
|
||||
index += split;
|
||||
if (index >= this.size())
|
||||
throw new ArrayIndexOutOfBoundsException(String.format("Index %d out of bounds! Only %d upcoming events found!", index-split, this.size()-split));
|
||||
return this.get(index);
|
||||
}
|
||||
|
||||
public int sizePast() {
|
||||
if (split < 0)
|
||||
sort();
|
||||
return split;
|
||||
}
|
||||
|
||||
public int sizeUpcoming() {
|
||||
if (split < 0)
|
||||
sort();
|
||||
return this.size()-split;
|
||||
}
|
||||
|
||||
public boolean add(Event event) {
|
||||
split = -1;
|
||||
return super.add(event);
|
||||
}
|
||||
|
||||
public void sort() {
|
||||
Collections.sort(this, ((e1, e2) -> Long.compare(e1.getEndDate(), e2.getEndDate())));
|
||||
long now = System.currentTimeMillis();
|
||||
split = 0;
|
||||
for (Event event : this) {
|
||||
if (event.getEndDate() < now)
|
||||
split++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user