diff options
author | Samuel Tardieu <sam@rfc1149.net> | 2013-09-15 14:15:40 +0200 |
---|---|---|
committer | Samuel Tardieu <sam@rfc1149.net> | 2013-09-15 14:20:40 +0200 |
commit | 60836c9e3ed719569544993e98ad1864b319827c (patch) | |
tree | 410645162e347a085e2742d2b2e9f42a419e4334 | |
parent | f52afc22db9c8fb6543ff999ecdea4ea16277c83 (diff) | |
download | cgeo-60836c9e3ed719569544993e98ad1864b319827c.zip cgeo-60836c9e3ed719569544993e98ad1864b319827c.tar.gz cgeo-60836c9e3ed719569544993e98ad1864b319827c.tar.bz2 |
refactoring: do not duplicate code path, partition list instead
-rw-r--r-- | main/src/cgeo/geocaching/CacheListActivity.java | 25 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/Geocache.java | 8 |
2 files changed, 17 insertions, 16 deletions
diff --git a/main/src/cgeo/geocaching/CacheListActivity.java b/main/src/cgeo/geocaching/CacheListActivity.java index 7465e91..848518d 100644 --- a/main/src/cgeo/geocaching/CacheListActivity.java +++ b/main/src/cgeo/geocaching/CacheListActivity.java @@ -45,8 +45,8 @@ import cgeo.geocaching.utils.Log; import cgeo.geocaching.utils.RunnableWithArgument; import ch.boye.httpclientandroidlib.HttpResponse; - import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.ListUtils; import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.NonNull; @@ -1219,21 +1219,14 @@ public class CacheListActivity extends AbstractListActivity implements FilteredA @Override public void run() { removeGeoAndDir(); - - final List<Geocache> cachesWithStaticMaps = new ArrayList<Geocache>(this.caches.size()); - for (final Geocache cache : this.caches) { - if (Settings.isStoreOfflineMaps() && cache.hasStaticMap()) { - cachesWithStaticMaps.add(cache); - continue; - } - if (!refreshCache(cache)) { - // in case of interruption avoid the second loop - cachesWithStaticMaps.clear(); - break; - } - } - - for (final Geocache cache : cachesWithStaticMaps) { + // First refresh caches that do not yet have static maps to get them a chance to get a copy + // before the limit expires, unless we do not want to store offline maps. + final List<Geocache> allCaches = Settings.isStoreOfflineMaps() ? + ListUtils.union(ListUtils.selectRejected(caches, Geocache.hasStaticMap), + ListUtils.select(caches, Geocache.hasStaticMap)) : + caches; + + for (final Geocache cache : allCaches) { if (!refreshCache(cache)) { break; } diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java index 222bb44..1fb1e0c 100644 --- a/main/src/cgeo/geocaching/Geocache.java +++ b/main/src/cgeo/geocaching/Geocache.java @@ -33,6 +33,7 @@ import cgeo.geocaching.utils.MatcherWrapper; import cgeo.geocaching.utils.UncertainProperty; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.Predicate; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; @@ -1747,6 +1748,13 @@ public class Geocache implements ICache, IWaypoint { return StaticMapsProvider.hasStaticMap(this); } + public static Predicate<Geocache> hasStaticMap = new Predicate<Geocache>() { + @Override + public boolean evaluate(final Geocache cache) { + return cache.hasStaticMap(); + } + }; + public List<Image> getImages() { final List<Image> result = new ArrayList<Image>(); result.addAll(getSpoilers()); |