Fixed DateSortedList

This commit is contained in:
Caesar2011
2018-10-24 00:14:25 +02:00
parent 9d5416ab9b
commit 14cf917ec8
3 changed files with 19 additions and 9 deletions

View File

@@ -8,4 +8,9 @@ public class EventList extends DateSortedList<Event> {
public long getDateByItem(Event item) { public long getDateByItem(Event item) {
return item.getEndDate(); return item.getEndDate();
} }
@Override
public boolean reversed() {
return false;
}
} }

View File

@@ -11,30 +11,29 @@ public abstract class DateSortedList<T> extends ArrayList<T> {
public T getPast(int index) { public T getPast(int index) {
if (split < 0) if (split < 0)
sort(); sort();
if (index >= split) if (index >= this.sizePast())
throw new ArrayIndexOutOfBoundsException(String.format("Index %d out of bounds! Only %d past events found!", index, split)); throw new ArrayIndexOutOfBoundsException(String.format("Index %d out of bounds! Only %d past events found!", index, split));
if (reversed()) if (reversed())
index = sizePast() - index - 1; index += sizeUpcoming();
return this.get(index); return this.get(index);
} }
public T getUpcoming(int index) { public T getUpcoming(int index) {
if (split < 0) if (split < 0)
sort(); sort();
index += split; if (index >= this.sizeUpcoming())
if (index >= this.size())
throw new ArrayIndexOutOfBoundsException(String.format("Index %d out of bounds! Only %d upcoming events found!", index-split, this.size()-split)); throw new ArrayIndexOutOfBoundsException(String.format("Index %d out of bounds! Only %d upcoming events found!", index-split, this.size()-split));
if (reversed()) if (!reversed())
index = sizeUpcoming() - index - 1; index += this.sizePast();
return this.get(index); return this.get(index);
} }
@Override @Override
public T get(int index) { public T get(int index) {
//if (split < 0) if (split < 0)
// sort(); sort();
if (reversed()) if (reversed())
index = size() - index - 1; index = size() - 1 - index;
return super.get(index); return super.get(index);
} }

View File

@@ -4,6 +4,9 @@ buildscript {
repositories { repositories {
google() google()
jcenter() jcenter()
maven {
url "https://jitpack.io"
}
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.2.1' classpath 'com.android.tools.build:gradle:3.2.1'
@@ -18,6 +21,9 @@ allprojects {
repositories { repositories {
google() google()
jcenter() jcenter()
maven {
url "https://jitpack.io"
}
} }
gradle.projectsEvaluated { gradle.projectsEvaluated {