aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/cgeo/geocaching/cgeocaches.java11
-rw-r--r--main/src/cgeo/geocaching/ui/CacheListAdapter.java38
2 files changed, 27 insertions, 22 deletions
diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java
index f3ec695..356dce3 100644
--- a/main/src/cgeo/geocaching/cgeocaches.java
+++ b/main/src/cgeo/geocaching/cgeocaches.java
@@ -149,7 +149,6 @@ public class cgeocaches extends AbstractListActivity {
private LoadFromWebThread threadWeb = null;
private RemoveFromHistoryThread threadH = null;
private int listId = StoredList.TEMPORARY_LIST_ID;
- private GeocodeComparator gcComparator = new GeocodeComparator();
private UpdateHandler updateHandler = new UpdateHandler();
private Handler loadCachesHandler = new Handler() {
@@ -163,7 +162,6 @@ public class cgeocaches extends AbstractListActivity {
final Set<cgCache> caches = search.getCachesFromSearchResult(LoadFlags.LOAD_CACHE_OR_DB);
if (CollectionUtils.isNotEmpty(caches)) {
cacheList.addAll(caches);
- Collections.sort(cacheList, gcComparator);
}
} else {
setTitle(title);
@@ -251,7 +249,6 @@ public class cgeocaches extends AbstractListActivity {
if (CollectionUtils.isNotEmpty(caches)) {
cacheList.addAll(caches);
caches.clear();
- Collections.sort(cacheList, gcComparator);
}
if (adapter != null) {
adapter.reFilter();
@@ -333,7 +330,6 @@ public class cgeocaches extends AbstractListActivity {
cacheList.clear();
cacheList.addAll(cacheListTmp);
cacheListTmp.clear();
- Collections.sort(cacheList, gcComparator);
}
}
@@ -389,8 +385,6 @@ public class cgeocaches extends AbstractListActivity {
if (CollectionUtils.isNotEmpty(cacheListTmp)) {
cacheList.addAll(cacheListTmp);
cacheListTmp.clear();
-
- Collections.sort(cacheList, gcComparator);
}
progress.dismiss();
@@ -414,8 +408,6 @@ public class cgeocaches extends AbstractListActivity {
if (CollectionUtils.isNotEmpty(cacheListTmp)) {
cacheList.addAll(cacheListTmp);
cacheListTmp.clear();
-
- Collections.sort(cacheList, gcComparator);
}
progress.dismiss();
@@ -657,7 +649,7 @@ public class cgeocaches extends AbstractListActivity {
if (coordsNow != null) {
adapter.setActualCoordinates(coordsNow);
adapter.setActualHeading(northHeading);
- adapter.forceSort(coordsNow);
+ adapter.forceSort();
}
}
@@ -1200,6 +1192,7 @@ public class cgeocaches extends AbstractListActivity {
} else {
adapter.notifyDataSetChanged();
}
+ adapter.forceSort();
adapter.reFilter();
}
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;
}