diff options
author | Bananeweizen <bananeweizen@gmx.de> | 2012-05-08 07:39:23 +0200 |
---|---|---|
committer | Bananeweizen <bananeweizen@gmx.de> | 2012-05-08 07:39:23 +0200 |
commit | 5120799c665d1023a8f81c205d59b9474eb83e88 (patch) | |
tree | 2c852886fd3630eb5670f1a712bfefda2f1585bc /main/src/cgeo/geocaching/ui | |
parent | 323ebe30c12e8f6f6c22ba132832befbb81e24c0 (diff) | |
download | cgeo-5120799c665d1023a8f81c205d59b9474eb83e88.zip cgeo-5120799c665d1023a8f81c205d59b9474eb83e88.tar.gz cgeo-5120799c665d1023a8f81c205d59b9474eb83e88.tar.bz2 |
#1478: Lists don't stay sorted
Diffstat (limited to 'main/src/cgeo/geocaching/ui')
-rw-r--r-- | main/src/cgeo/geocaching/ui/CacheListAdapter.java | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java index d83b119..ea7fc38 100644 --- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java +++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java @@ -125,7 +125,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { */ public void setComparator(final CacheComparator comparator) { cacheComparator = comparator; - forceSort(coords); + forceSort(); } public CacheComparator getCacheComparator() { @@ -222,16 +222,14 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { notifyDataSetChanged(); } - public void forceSort(final Geopoint coordsIn) { + public void forceSort() { if (CollectionUtils.isEmpty(list) || selectMode) { return; } if (isSortedByDistance()) { - if (coordsIn == null) { - return; - } - Collections.sort(list, new DistanceComparator(coordsIn, list)); + lastSort = 0; + updateSortByDistance(); } else { Collections.sort(list, cacheComparator); @@ -246,22 +244,36 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { } coords = coordsIn; - - if (CollectionUtils.isNotEmpty(list) && (System.currentTimeMillis() - lastSort) > PAUSE_BETWEEN_LIST_SORT && !selectMode && isSortedByDistance()) { - Collections.sort(list, new DistanceComparator(coordsIn, list)); - notifyDataSetChanged(); - lastSort = System.currentTimeMillis(); - } + updateSortByDistance(); for (final DistanceView distance : distances) { distance.update(coordsIn); } - for (final CompassMiniView compass : compasses) { compass.updateCurrentCoords(coordsIn); } } + private void updateSortByDistance() { + if (CollectionUtils.isEmpty(list)) { + return; + } + if (selectMode) { + return; + } + if ((System.currentTimeMillis() - lastSort) <= PAUSE_BETWEEN_LIST_SORT) { + return; + } + if (!isSortedByDistance()) { + return; + } + + Log.w(System.currentTimeMillis() + ": " + coords.toString()); + Collections.sort(list, new DistanceComparator(coords, list)); + notifyDataSetChanged(); + lastSort = System.currentTimeMillis(); + } + private boolean isSortedByDistance() { return cacheComparator == null || cacheComparator instanceof DistanceComparator; } |