Better event listing
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
package de.sebse.fuplanner.fragments.moddetails;
|
package de.sebse.fuplanner.fragments.moddetails;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -81,19 +83,20 @@ class ModDetailEventAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
|||||||
for (Map.Entry<String, GroupedEvents> value: listsGrouped.entrySet()) {
|
for (Map.Entry<String, GroupedEvents> value: listsGrouped.entrySet()) {
|
||||||
if (value.getValue().getGroups().size() > 0) {
|
if (value.getValue().getGroups().size() > 0) {
|
||||||
mPositionalData.add(new Pair<>(TYPE_HEADER, value.getKey()));
|
mPositionalData.add(new Pair<>(TYPE_HEADER, value.getKey()));
|
||||||
boolean showAsGrouped = true;
|
ArrayList<GroupedEvents.Group> ungroupedGroups = new ArrayList<>();
|
||||||
for (GroupedEvents.Group group: value.getValue().getGroups()) {
|
for (GroupedEvents.Group group: value.getValue().getGroups()) {
|
||||||
if (group.getSkippedDates().size() > 2) {
|
boolean showAsGrouped = true;
|
||||||
|
if (group.getSkippedDates().size() > 3 || group.size() < 3) {
|
||||||
showAsGrouped = false;
|
showAsGrouped = false;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (showAsGrouped) {
|
if (showAsGrouped) {
|
||||||
for (GroupedEvents.Group group : value.getValue().getGroups()) {
|
|
||||||
mPositionalData.add(new Pair<>(TYPE_GROUPED, group));
|
mPositionalData.add(new Pair<>(TYPE_GROUPED, group));
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
for (Event event : value.getValue()) {
|
ungroupedGroups.add(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (GroupedEvents.Group ungroupedGroup : ungroupedGroups) {
|
||||||
|
for (Event event: ungroupedGroup) {
|
||||||
mPositionalData.add(new Pair<>(TYPE_UNGROUPED, event));
|
mPositionalData.add(new Pair<>(TYPE_UNGROUPED, event));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,9 +189,30 @@ class ModDetailEventAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
|||||||
excepts.append(", ").append(UtilsDate.getModifiedDate(skippedDate));
|
excepts.append(", ").append(UtilsDate.getModifiedDate(skippedDate));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ig.mTitle.setText(context.getString(R.string.event_scale, weekday, startTime, endTime));
|
String groupTitle = context.getString(R.string.event_scale, weekday, startTime, endTime);
|
||||||
|
if (!TextUtils.isEmpty(group.getTitle()) && !group.getTitle().equals(mValue.title))
|
||||||
|
groupTitle += " ("+group.getTitle()+")";
|
||||||
|
ig.mTitle.setText(groupTitle);
|
||||||
ig.mSubLeft.setText(context.getString(R.string.date_scale, start, end));
|
ig.mSubLeft.setText(context.getString(R.string.date_scale, start, end));
|
||||||
ig.mSubRight.setText(excepts != null ? context.getString(R.string.except_list, excepts.toString()) : "");
|
ig.mSubRight.setText(excepts != null ? context.getString(R.string.except_list, excepts.toString()) : "");
|
||||||
|
String moduleName = mValue.title;
|
||||||
|
StringBuilder finalExcepts = excepts;
|
||||||
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ig.mView.getContext());
|
||||||
|
ig.mView.setOnClickListener(v -> {
|
||||||
|
alertDialogBuilder
|
||||||
|
.setTitle(R.string.events)
|
||||||
|
.setMessage(
|
||||||
|
ig.mView.getResources().getString(R.string.module_name, moduleName) + "\n" +
|
||||||
|
ig.mView.getResources().getString(R.string.location_name, group.getLocation()) + "\n" +
|
||||||
|
context.getString(R.string.event_scale, weekday, startTime, endTime) + "\n" +
|
||||||
|
context.getString(R.string.date_scale, start, end) + "\n" +
|
||||||
|
(finalExcepts != null ? context.getString(R.string.except_list, finalExcepts.toString()) : "")
|
||||||
|
)
|
||||||
|
.setCancelable(true)
|
||||||
|
.setNeutralButton(R.string.close, (dialog, id) -> dialog.cancel());
|
||||||
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
||||||
|
alertDialog.show();
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
case TYPE_UNGROUPED:
|
case TYPE_UNGROUPED:
|
||||||
ItemViewHolder iu = (ItemViewHolder) holder;
|
ItemViewHolder iu = (ItemViewHolder) holder;
|
||||||
@@ -205,7 +229,23 @@ class ModDetailEventAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
|||||||
date = context.getString(R.string.date_scale, start, end);
|
date = context.getString(R.string.date_scale, start, end);
|
||||||
iu.mTitle.setText(event.getTitle());
|
iu.mTitle.setText(event.getTitle());
|
||||||
iu.mSubLeft.setText(date);
|
iu.mSubLeft.setText(date);
|
||||||
iu.mSubRight.setText("");
|
iu.mSubRight.setText(event.getLocation());
|
||||||
|
String moduleName1 = mValue.title;
|
||||||
|
AlertDialog.Builder alertDialogBuilder1 = new AlertDialog.Builder(iu.mView.getContext());
|
||||||
|
iu.mView.setOnClickListener(v -> {
|
||||||
|
alertDialogBuilder1
|
||||||
|
.setTitle(moduleName1)
|
||||||
|
.setMessage(
|
||||||
|
iu.mView.getResources().getString(R.string.module_name, moduleName1) + "\n" +
|
||||||
|
iu.mView.getResources().getString(R.string.location_name, event.getLocation()) + "\n" +
|
||||||
|
date
|
||||||
|
)
|
||||||
|
.setCancelable(true)
|
||||||
|
.setNeutralButton(R.string.close, (dialog, id) -> dialog.cancel());
|
||||||
|
|
||||||
|
AlertDialog alertDialog = alertDialogBuilder1.create();
|
||||||
|
alertDialog.show();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -94,6 +94,11 @@ public class ModulesEvents extends PartModules<EventList> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.mList.find(ID, module -> {
|
this.mList.find(ID, module -> {
|
||||||
|
if (module.lvNumber.size() == 0) {
|
||||||
|
// Events not available
|
||||||
|
callback.onResponse(new EventList());
|
||||||
|
return;
|
||||||
|
}
|
||||||
super.head(String.format("https://www.fu-berlin.de/vv/de/search?utf8=✓&query=%s", module.lvNumber.iterator().next()), null, response -> {
|
super.head(String.format("https://www.fu-berlin.de/vv/de/search?utf8=✓&query=%s", module.lvNumber.iterator().next()), null, response -> {
|
||||||
String location = response.getHeaders().get("Location");
|
String location = response.getHeaders().get("Location");
|
||||||
if (location == null) {
|
if (location == null) {
|
||||||
@@ -110,6 +115,12 @@ public class ModulesEvents extends PartModules<EventList> {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// 462854, 465661, 462126, 463782, 437050, 433843, 471614, 464205
|
||||||
|
//String[] tests = {"462854", "465661", "462126", "463782", "437050", "433843", "471614", "464205"};
|
||||||
|
//String[] tests = {"461459", "424564", "459494", "429737", "463765", "476477", "464082", "459577", "459743", "464318", "449358", "454327", "461784", "468081", "485919"};
|
||||||
|
//group = tests[new Random().nextInt(tests.length)];
|
||||||
|
//log.d("LAAAAAAST", group);
|
||||||
|
//group = "462126";
|
||||||
super.get(String.format("https://www.fu-berlin.de/vv/de/lv/%s", group), null, response1 -> {
|
super.get(String.format("https://www.fu-berlin.de/vv/de/lv/%s", group), null, response1 -> {
|
||||||
String body = response1.getParsed();
|
String body = response1.getParsed();
|
||||||
if (body == null) {
|
if (body == null) {
|
||||||
@@ -129,7 +140,7 @@ public class ModulesEvents extends PartModules<EventList> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
title = Regex.regex("<div class=\"course_title\">([^<]*?)</div>", entry, 0);
|
title = Regex.regex("<div class=\"course_title\">([^<]*?)</div>", entry, 1);
|
||||||
} catch (NoSuchFieldException ignored) {}
|
} catch (NoSuchFieldException ignored) {}
|
||||||
if (TextUtils.isEmpty(title))
|
if (TextUtils.isEmpty(title))
|
||||||
title = module.title;
|
title = module.title;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import android.annotation.SuppressLint;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -36,15 +37,17 @@ public class GroupedEvents extends EventList {
|
|||||||
return skippedDayCount;
|
return skippedDayCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Group {
|
public class Group implements Iterable<Event> {
|
||||||
private long firstDate;
|
private long firstDate;
|
||||||
private long lastDate;
|
private long lastDate;
|
||||||
private final ArrayList<Long> skippedDates;
|
private final ArrayList<Long> skippedDates;
|
||||||
|
private final ArrayList<Event> allEvents = new ArrayList<>();
|
||||||
|
|
||||||
private final int dayOfWeek;
|
private final int dayOfWeek;
|
||||||
private final long startTime;
|
private final long startTime;
|
||||||
private final long duration;
|
private final long duration;
|
||||||
private final String location;
|
private final String location;
|
||||||
|
private final String title;
|
||||||
|
|
||||||
private Group(Event event) {
|
private Group(Event event) {
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
@@ -53,6 +56,7 @@ public class GroupedEvents extends EventList {
|
|||||||
startTime = calendar.get(Calendar.HOUR_OF_DAY)*3600000+calendar.get(Calendar.MINUTE)*60000+calendar.get(Calendar.SECOND)*1000+calendar.get(Calendar.MILLISECOND);
|
startTime = calendar.get(Calendar.HOUR_OF_DAY)*3600000+calendar.get(Calendar.MINUTE)*60000+calendar.get(Calendar.SECOND)*1000+calendar.get(Calendar.MILLISECOND);
|
||||||
duration = event.getEndDate()-event.getStartDate();
|
duration = event.getEndDate()-event.getStartDate();
|
||||||
location = event.getLocation();
|
location = event.getLocation();
|
||||||
|
title = event.getTitle();
|
||||||
|
|
||||||
skippedDates = new ArrayList<>();
|
skippedDates = new ArrayList<>();
|
||||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
@@ -61,6 +65,7 @@ public class GroupedEvents extends EventList {
|
|||||||
calendar.set(Calendar.MILLISECOND, 0);
|
calendar.set(Calendar.MILLISECOND, 0);
|
||||||
firstDate = calendar.getTimeInMillis();
|
firstDate = calendar.getTimeInMillis();
|
||||||
lastDate = firstDate;
|
lastDate = firstDate;
|
||||||
|
allEvents.add(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean add(Event event) {
|
private boolean add(Event event) {
|
||||||
@@ -70,7 +75,7 @@ public class GroupedEvents extends EventList {
|
|||||||
int startTime = calendar.get(Calendar.HOUR_OF_DAY)*3600000+calendar.get(Calendar.MINUTE)*60000+calendar.get(Calendar.SECOND)*1000+calendar.get(Calendar.MILLISECOND);
|
int startTime = calendar.get(Calendar.HOUR_OF_DAY)*3600000+calendar.get(Calendar.MINUTE)*60000+calendar.get(Calendar.SECOND)*1000+calendar.get(Calendar.MILLISECOND);
|
||||||
long length = event.getEndDate()-event.getStartDate();
|
long length = event.getEndDate()-event.getStartDate();
|
||||||
String location = event.getLocation();
|
String location = event.getLocation();
|
||||||
if (this.dayOfWeek != dayOfWeek || this.startTime != startTime || this.duration != length || this.location.equals(location))
|
if (this.dayOfWeek != dayOfWeek || this.startTime != startTime || this.duration != length || !this.location.equals(location))
|
||||||
return false;
|
return false;
|
||||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
calendar.set(Calendar.MINUTE, 0);
|
calendar.set(Calendar.MINUTE, 0);
|
||||||
@@ -95,6 +100,7 @@ public class GroupedEvents extends EventList {
|
|||||||
skippedDates.remove(date);
|
skippedDates.remove(date);
|
||||||
skippedDayCount -= 1;
|
skippedDayCount -= 1;
|
||||||
}
|
}
|
||||||
|
allEvents.add(event);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,11 +135,29 @@ public class GroupedEvents extends EventList {
|
|||||||
return duration;
|
return duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("DefaultLocale")
|
@SuppressLint("DefaultLocale")
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("%d - %d - %d - %s", dayOfWeek, startTime, duration, skippedDates);
|
return String.format("%d - %d - %d - %s", dayOfWeek, startTime, duration, skippedDates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Iterator<Event> iterator() {
|
||||||
|
return Collections.unmodifiableList(allEvents).iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return allEvents.size();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user