diff options
| -rw-r--r-- | main/src/cgeo/geocaching/CacheCache.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/connector/gc/GCMap.java | 4 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/connector/gc/Tile.java | 37 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/maps/CGeoMap.java | 2 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/CgeoApplicationTest.java | 4 |
5 files changed, 18 insertions, 31 deletions
diff --git a/main/src/cgeo/geocaching/CacheCache.java b/main/src/cgeo/geocaching/CacheCache.java index b3c674c..cb4e14c 100644 --- a/main/src/cgeo/geocaching/CacheCache.java +++ b/main/src/cgeo/geocaching/CacheCache.java @@ -106,7 +106,7 @@ public class CacheCache { // FIXME: as above, we sometimes get caches with null coordinates, that may then provoke // a NullPointerException down the invocation chain. if (removed.getCoords() != null) { - Tile.Cache.removeFromTileCache(removed); + Tile.cache.removeFromTileCache(removed); } } } diff --git a/main/src/cgeo/geocaching/connector/gc/GCMap.java b/main/src/cgeo/geocaching/connector/gc/GCMap.java index 2782b64..ed17dfc 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCMap.java +++ b/main/src/cgeo/geocaching/connector/gc/GCMap.java @@ -305,7 +305,7 @@ public class GCMap { for (Tile tile : tiles) { - if (!Tile.Cache.contains(tile)) { + if (!Tile.cache.contains(tile)) { final Parameters params = new Parameters( "x", String.valueOf(tile.getX()), "y", String.valueOf(tile.getY()), @@ -351,7 +351,7 @@ public class GCMap { else { searchResult.addSearchResult(search); } - Tile.Cache.add(tile); + Tile.cache.add(tile); } // release native bitmap memory diff --git a/main/src/cgeo/geocaching/connector/gc/Tile.java b/main/src/cgeo/geocaching/connector/gc/Tile.java index 6a257cd..4a0d74a 100644 --- a/main/src/cgeo/geocaching/connector/gc/Tile.java +++ b/main/src/cgeo/geocaching/connector/gc/Tile.java @@ -5,11 +5,10 @@ import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.Viewport; import cgeo.geocaching.network.Network; import cgeo.geocaching.network.Parameters; -import cgeo.geocaching.utils.LeastRecentlyUsedMap; +import cgeo.geocaching.utils.LeastRecentlyUsedSet; import cgeo.geocaching.utils.Log; import ch.boye.httpclientandroidlib.HttpResponse; - import org.eclipse.jdt.annotation.NonNull; import android.graphics.Bitmap; @@ -17,7 +16,6 @@ import android.graphics.BitmapFactory; import java.io.IOException; import java.util.ArrayList; -import java.util.Collection; import java.util.HashSet; import java.util.Locale; import java.util.Set; @@ -45,6 +43,8 @@ public class Tile { } } + public static TileCache cache = new TileCache(); + private final int tileX; private final int tileY; private final int zoomLevel; @@ -301,31 +301,18 @@ public class Tile { return tiles; } - public static class Cache { - private final static LeastRecentlyUsedMap<Integer, Tile> tileCache = new LeastRecentlyUsedMap.LruCache<Integer, Tile>(64); - - public static void removeFromTileCache(final ICoordinates point) { - if (point != null) { - Collection<Tile> tiles = new ArrayList<Tile>(tileCache.values()); - for (Tile tile : tiles) { - if (tile.containsPoint(point)) { - tileCache.remove(tile.hashCode()); - } - } - } - } + public static class TileCache extends LeastRecentlyUsedSet<Tile> { - public static boolean contains(final Tile tile) { - return tileCache.containsKey(tile.hashCode()); + public TileCache() { + super(64); } - public static void add(final Tile tile) { - tileCache.put(tile.hashCode(), tile); - } - - public static void clear() { - tileCache.clear(); + public void removeFromTileCache(@NonNull final ICoordinates point) { + for (final Tile tile : new ArrayList<Tile>(this)) { + if (tile.containsPoint(point)) { + remove(tile); + } + } } } - } diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 6730ba9..e9ee8c2 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -675,7 +675,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto markersInvalidated = true; ActivityMixin.invalidateOptionsMenu(activity); if (!Settings.isExcludeMyCaches()) { - Tile.Cache.clear(); + Tile.cache.clear(); } return true; case R.id.menu_theme_mode: diff --git a/tests/src/cgeo/geocaching/CgeoApplicationTest.java b/tests/src/cgeo/geocaching/CgeoApplicationTest.java index af6bcaa..1dcd976 100644 --- a/tests/src/cgeo/geocaching/CgeoApplicationTest.java +++ b/tests/src/cgeo/geocaching/CgeoApplicationTest.java @@ -317,7 +317,7 @@ public class CgeoApplicationTest extends CGeoTestCase { // check update after switch strategy to FAST Settings.setLiveMapStrategy(Strategy.FAST); - Tile.Cache.removeFromTileCache(mockedCache); + Tile.cache.removeFromTileCache(mockedCache); search = ConnectorFactory.searchByViewport(viewport, tokens).toBlockingObservable().single(); assertNotNull(search); @@ -354,7 +354,7 @@ public class CgeoApplicationTest extends CGeoTestCase { // non premium cache MockedCache cache = new GC2CJPF(); deleteCacheFromDBAndLogout(cache.getGeocode()); - Tile.Cache.removeFromTileCache(cache); + Tile.cache.removeFromTileCache(cache); Settings.setCacheType(CacheType.ALL); Viewport viewport = new Viewport(cache, 0.003, 0.003); |
