DateSortedList Sorting bug fix

This commit is contained in:
Caesar2011
2018-11-17 11:52:08 +01:00
parent 7679135af1
commit 8e3360549f

View File

@@ -7,6 +7,7 @@ import java.util.Iterator;
public abstract class DateSortedList<T> extends ArrayList<T> { public abstract class DateSortedList<T> extends ArrayList<T> {
private int split = -1; private int split = -1;
private boolean mSorting = false;
public T getPast(int index) { public T getPast(int index) {
if (split < 0) if (split < 0)
@@ -30,6 +31,7 @@ public abstract class DateSortedList<T> extends ArrayList<T> {
@Override @Override
public T get(int index) { public T get(int index) {
if (mSorting) return super.get(index);
if (split < 0) if (split < 0)
sort(); sort();
if (reversed()) if (reversed())
@@ -55,6 +57,7 @@ public abstract class DateSortedList<T> extends ArrayList<T> {
} }
public void sort() { public void sort() {
mSorting = true;
Collections.sort(this, ((e1, e2) -> Long.compare(getDateByItem(e1), getDateByItem(e2)))); Collections.sort(this, ((e1, e2) -> Long.compare(getDateByItem(e1), getDateByItem(e2))));
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
split = 0; split = 0;
@@ -64,6 +67,7 @@ public abstract class DateSortedList<T> extends ArrayList<T> {
else else
break; break;
} }
mSorting = false;
} }
public Iterator<T> getEventsOfMonth(int year, int month) { public Iterator<T> getEventsOfMonth(int year, int month) {