From 14cf917ec8de0a628d49f15f62e33683d894555e Mon Sep 17 00:00:00 2001 From: Caesar2011 Date: Wed, 24 Oct 2018 00:14:25 +0200 Subject: [PATCH] Fixed DateSortedList --- .../fuplanner/services/KVV/types/EventList.java | 5 +++++ .../sebse/fuplanner/tools/DateSortedList.java | 17 ++++++++--------- build.gradle | 6 ++++++ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/de/sebse/fuplanner/services/KVV/types/EventList.java b/app/src/main/java/de/sebse/fuplanner/services/KVV/types/EventList.java index b89ee2d..5957c0e 100644 --- a/app/src/main/java/de/sebse/fuplanner/services/KVV/types/EventList.java +++ b/app/src/main/java/de/sebse/fuplanner/services/KVV/types/EventList.java @@ -8,4 +8,9 @@ public class EventList extends DateSortedList { public long getDateByItem(Event item) { return item.getEndDate(); } + + @Override + public boolean reversed() { + return false; + } } diff --git a/app/src/main/java/de/sebse/fuplanner/tools/DateSortedList.java b/app/src/main/java/de/sebse/fuplanner/tools/DateSortedList.java index 1391509..8e625e8 100644 --- a/app/src/main/java/de/sebse/fuplanner/tools/DateSortedList.java +++ b/app/src/main/java/de/sebse/fuplanner/tools/DateSortedList.java @@ -11,30 +11,29 @@ public abstract class DateSortedList extends ArrayList { public T getPast(int index) { if (split < 0) 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)); if (reversed()) - index = sizePast() - index - 1; + index += sizeUpcoming(); return this.get(index); } public T getUpcoming(int index) { if (split < 0) sort(); - index += split; - if (index >= this.size()) + if (index >= this.sizeUpcoming()) throw new ArrayIndexOutOfBoundsException(String.format("Index %d out of bounds! Only %d upcoming events found!", index-split, this.size()-split)); - if (reversed()) - index = sizeUpcoming() - index - 1; + if (!reversed()) + index += this.sizePast(); return this.get(index); } @Override public T get(int index) { - //if (split < 0) - // sort(); + if (split < 0) + sort(); if (reversed()) - index = size() - index - 1; + index = size() - 1 - index; return super.get(index); } diff --git a/build.gradle b/build.gradle index f0d24ff..fdbda7b 100644 --- a/build.gradle +++ b/build.gradle @@ -4,6 +4,9 @@ buildscript { repositories { google() jcenter() + maven { + url "https://jitpack.io" + } } dependencies { classpath 'com.android.tools.build:gradle:3.2.1' @@ -18,6 +21,9 @@ allprojects { repositories { google() jcenter() + maven { + url "https://jitpack.io" + } } gradle.projectsEvaluated {