diff options
| author | Bananeweizen <Bananeweizen@gmx.de> | 2012-05-13 08:30:52 -0700 |
|---|---|---|
| committer | Bananeweizen <Bananeweizen@gmx.de> | 2012-05-13 08:30:52 -0700 |
| commit | eee60ac9a2ef926f26997f9883b0f86f99c3e352 (patch) | |
| tree | 268af4a14225774a50fe902f73fd771bbf3490a4 /main/src | |
| parent | ad29a58af38d7987a1b0b3bab7dc70548a5b78b1 (diff) | |
| parent | 40dc697c274b86d45793c80eb85aa730c5327a5a (diff) | |
| download | cgeo-eee60ac9a2ef926f26997f9883b0f86f99c3e352.zip cgeo-eee60ac9a2ef926f26997f9883b0f86f99c3e352.tar.gz cgeo-eee60ac9a2ef926f26997f9883b0f86f99c3e352.tar.bz2 | |
Merge pull request #1559 from marco-jacob/issue#1512-deleteWpStaticMapsOnRefresh
fixes #1512 : deletes all static maps for waypoints of a cache on refresh
Diffstat (limited to 'main/src')
| -rw-r--r-- | main/src/cgeo/geocaching/StaticMapsProvider.java | 4 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/files/LocalStorage.java | 45 |
2 files changed, 48 insertions, 1 deletions
diff --git a/main/src/cgeo/geocaching/StaticMapsProvider.java b/main/src/cgeo/geocaching/StaticMapsProvider.java index 691516f..f34d8fa 100644 --- a/main/src/cgeo/geocaching/StaticMapsProvider.java +++ b/main/src/cgeo/geocaching/StaticMapsProvider.java @@ -88,6 +88,8 @@ public class StaticMapsProvider { // download static map for current waypoints if (Settings.isStoreOfflineWpMaps() && CollectionUtils.isNotEmpty(cache.getWaypoints())) { + // remove all waypoint static map files due to origin cache waypoint id changed on saveCache + LocalStorage.deleteFilesWithPrefix(cache.getGeocode(), "map_wp"); for (cgWaypoint waypoint : cache.getWaypoints()) { storeWaypointStaticMap(cache.getGeocode(), edge, waypoint, false); } @@ -181,7 +183,7 @@ public class StaticMapsProvider { return MARKERS_URL + "marker_waypoint_" + type + ".png"; } - public static void removeWpStaticMaps(int wp_id, String geocode) { + public static void removeWpStaticMaps(int wp_id, final String geocode) { for (int level = 1; level <= 5; level++) { try { if (wp_id > 0) { diff --git a/main/src/cgeo/geocaching/files/LocalStorage.java b/main/src/cgeo/geocaching/files/LocalStorage.java index eea761b..f1daded 100644 --- a/main/src/cgeo/geocaching/files/LocalStorage.java +++ b/main/src/cgeo/geocaching/files/LocalStorage.java @@ -15,6 +15,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; +import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -320,4 +321,48 @@ public class LocalStorage { return path.delete(); } + /** + * Deletes all files from directory geocode with the given prefix. + * + * @param geocode + * The geocode identifying the cache directory + * @param prefix + * The filename prefix + */ + public static void deleteFilesWithPrefix(final String geocode, final String prefix) { + final File[] filesToDelete = getFilesWithPrefix(geocode, prefix); + for (final File file : filesToDelete) { + try { + if (!file.delete()) { + Log.w("LocalStorage.deleteFilesPrefix: Can't delete file " + file.getName()); + } + } catch (Exception e) { + Log.e("LocalStorage.deleteFilesPrefix: " + e.toString()); + } + } + } + + /** + * Get an array of all files of the geocode directory starting with + * the given filenamePrefix. + * + * @param geocode + * The geocode identifying the cache data directory + * @param filenamePrefix + * The prefix of the files + * @return File[] the array of files starting with filenamePrefix in geocode directory + */ + public static File[] getFilesWithPrefix(final String geocode, final String filenamePrefix) { + final FilenameFilter filter = new FilenameFilter() { + public boolean accept(File dir, String filename) { + if (filename.startsWith(filenamePrefix)) { + return true; + } + return false; + } + }; + final File gcDir = LocalStorage.getStorageDir(geocode); + final File[] found = gcDir.listFiles(filter); + return found; + } } |
