diff options
author | Samuel Tardieu <sam@rfc1149.net> | 2015-01-03 10:16:29 +0100 |
---|---|---|
committer | Samuel Tardieu <sam@rfc1149.net> | 2015-01-03 10:23:08 +0100 |
commit | 77fac0ce78692c8d56f9dfb75c47e204a056cb46 (patch) | |
tree | 7801f37eadbcdcecc9c1e485e62501ccbca5d859 /main/src/cgeo | |
parent | 213ce4c0f819eb54d97e9ecc43a471b792b9372c (diff) | |
download | cgeo-77fac0ce78692c8d56f9dfb75c47e204a056cb46.zip cgeo-77fac0ce78692c8d56f9dfb75c47e204a056cb46.tar.gz cgeo-77fac0ce78692c8d56f9dfb75c47e204a056cb46.tar.bz2 |
Use only one shared images directory
The user avatar used to be stored under the "_others" pseudo-geocode
while other data not tied to a particular cache was stored under
"shared". Now, everything is now in "shared".
Diffstat (limited to 'main/src/cgeo')
-rw-r--r-- | main/src/cgeo/geocaching/DataStore.java | 3 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/SelectMapfileActivity.java | 2 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/connector/gc/GCLogin.java | 2 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/files/LocalStorage.java | 34 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/network/HtmlImage.java | 11 |
5 files changed, 28 insertions, 24 deletions
diff --git a/main/src/cgeo/geocaching/DataStore.java b/main/src/cgeo/geocaching/DataStore.java index b7b0576..b5a4a7a 100644 --- a/main/src/cgeo/geocaching/DataStore.java +++ b/main/src/cgeo/geocaching/DataStore.java @@ -2364,6 +2364,9 @@ public class DataStore { Log.d("Database clean: removing obsolete log images records"); database.delete(dbTableLogImages, "log_id NOT IN (SELECT _id FROM " + dbTableLogs + ")", null); + // Remove the obsolete "_others" directory where the user avatar used to be stored. + LocalStorage.deleteDirectory(LocalStorage.getStorageDir("_others")); + if (version > -1) { Settings.setVersion(version); } diff --git a/main/src/cgeo/geocaching/SelectMapfileActivity.java b/main/src/cgeo/geocaching/SelectMapfileActivity.java index 697f609..a506f16 100644 --- a/main/src/cgeo/geocaching/SelectMapfileActivity.java +++ b/main/src/cgeo/geocaching/SelectMapfileActivity.java @@ -87,7 +87,7 @@ public class SelectMapfileActivity extends AbstractFileListActivity<FileSelectio for (File dir : LocalStorage.getStorages()) { folders.add(new File(dir, "mfmaps")); folders.add(new File(new File(dir, "Locus"), "mapsVector")); - folders.add(new File(dir, LocalStorage.cache)); + folders.add(new File(dir, LocalStorage.CACHE_DIRNAME)); } return folders; } diff --git a/main/src/cgeo/geocaching/connector/gc/GCLogin.java b/main/src/cgeo/geocaching/connector/gc/GCLogin.java index 7b7351e..035176b 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCLogin.java +++ b/main/src/cgeo/geocaching/connector/gc/GCLogin.java @@ -257,7 +257,7 @@ public class GCLogin extends AbstractLogin { final String avatarURL = TextUtils.getMatch(profile, GCConstants.PATTERN_AVATAR_IMAGE_PROFILE_PAGE, false, null); if (avatarURL != null) { - final HtmlImage imgGetter = new HtmlImage("", false, 0, false); + final HtmlImage imgGetter = new HtmlImage(HtmlImage.SHARED, false, 0, false); return imgGetter.fetchDrawable(avatarURL.replace("avatar", "user/large")).cast(Drawable.class); } // No match? There may be no avatar set by user. diff --git a/main/src/cgeo/geocaching/files/LocalStorage.java b/main/src/cgeo/geocaching/files/LocalStorage.java index 8896833..7fce27d 100644 --- a/main/src/cgeo/geocaching/files/LocalStorage.java +++ b/main/src/cgeo/geocaching/files/LocalStorage.java @@ -45,7 +45,7 @@ public final class LocalStorage { public static final String HEADER_ETAG = "etag"; /** Name of the local private directory used to hold cached information */ - public final static String cache = ".cgeo"; + public final static String CACHE_DIRNAME = ".cgeo"; private static File internalStorageBase; @@ -74,7 +74,7 @@ public final class LocalStorage { private static File getStorageSpecific(final boolean secondary) { return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) ^ secondary ? getExternalStorageBase() : - new File(getInternalStorageBase(), LocalStorage.cache); + new File(getInternalStorageBase(), LocalStorage.CACHE_DIRNAME); } public static File getExternalDbDirectory() { @@ -86,7 +86,7 @@ public final class LocalStorage { } private static File getExternalStorageBase() { - return new File(Environment.getExternalStorageDirectory(), LocalStorage.cache); + return new File(Environment.getExternalStorageDirectory(), LocalStorage.CACHE_DIRNAME); } private static File getInternalStorageBase() { @@ -105,7 +105,7 @@ public final class LocalStorage { * @return the file extension, including the leading dot, or the empty string if none could be determined */ static String getExtension(final String url) { - String urlExt; + final String urlExt; if (url.startsWith("data:")) { // "data:image/png;base64,i53…" -> ".png" urlExt = StringUtils.substringAfter(StringUtils.substringBefore(url, ";"), "/"); @@ -124,7 +124,7 @@ public final class LocalStorage { * the geocode * @return the cache directory */ - public static File getStorageDir(@Nullable final String geocode) { + public static File getStorageDir(@NonNull final String geocode) { return storageDir(getStorage(), geocode); } @@ -136,12 +136,12 @@ public final class LocalStorage { * the geocode * @return the cache directory */ - private static File getStorageSecDir(@Nullable final String geocode) { + private static File getStorageSecDir(@NonNull final String geocode) { return storageDir(getStorageSec(), geocode); } - private static File storageDir(final File base, @Nullable final String geocode) { - return new File(base, StringUtils.defaultIfEmpty(geocode, "_others")); + private static File storageDir(final File base, @NonNull final String geocode) { + return new File(base, geocode); } /** @@ -157,7 +157,7 @@ public final class LocalStorage { * true if an url was given, false if a file name was given * @return the file */ - public static File getStorageFile(@Nullable final String geocode, final String fileNameOrUrl, final boolean isUrl, final boolean createDirs) { + public static File getStorageFile(@NonNull final String geocode, final String fileNameOrUrl, final boolean isUrl, final boolean createDirs) { return buildFile(getStorageDir(geocode), fileNameOrUrl, isUrl, createDirs); } @@ -244,14 +244,14 @@ public final class LocalStorage { public static String getSavedHeader(final File baseFile, final String name) { try { final File file = filenameForHeader(baseFile, name); - final Reader f = new InputStreamReader(new FileInputStream(file), CharEncoding.UTF_8); + final Reader reader = new InputStreamReader(new FileInputStream(file), CharEncoding.UTF_8); try { // No header will be more than 256 bytes final char[] value = new char[256]; - final int count = f.read(value); + final int count = reader.read(value); return new String(value, 0, count); } finally { - f.close(); + reader.close(); } } catch (final FileNotFoundException ignored) { // Do nothing, the file does not exist @@ -442,10 +442,10 @@ public final class LocalStorage { try { fr = new InputStreamReader(new FileInputStream(file), CharEncoding.UTF_8); br = new BufferedReader(fr); - String s = br.readLine(); - while (s != null) { - if (s.startsWith("dev_mount")) { - final String[] tokens = StringUtils.split(s); + String str = br.readLine(); + while (str != null) { + if (str.startsWith("dev_mount")) { + final String[] tokens = StringUtils.split(str); if (tokens.length >= 3) { final String path = tokens[2]; // mountpoint if (!extStorage.equals(path)) { @@ -456,7 +456,7 @@ public final class LocalStorage { } } } - s = br.readLine(); + str = br.readLine(); } } catch (final IOException e) { Log.e("Could not get additional mount points for user content. " + diff --git a/main/src/cgeo/geocaching/network/HtmlImage.java b/main/src/cgeo/geocaching/network/HtmlImage.java index 61606ab..97e0e45 100644 --- a/main/src/cgeo/geocaching/network/HtmlImage.java +++ b/main/src/cgeo/geocaching/network/HtmlImage.java @@ -69,7 +69,7 @@ public class HtmlImage implements Html.ImageGetter { }; public static final String SHARED = "shared"; - final private String geocode; + @NonNull final private String geocode; /** * on error: return large error image, if {@code true}, otherwise empty 1x1 image */ @@ -112,7 +112,8 @@ public class HtmlImage implements Html.ImageGetter { * </ul> * * @param geocode - * the geocode of the item for which we are requesting the image + * the geocode of the item for which we are requesting the image, or {@link #SHARED} to use the shared + * cache directory * @param returnErrorImage * set to <tt>true</tt> if an error image should be returned in case of a problem, <tt>false</tt> to get * a transparent 1x1 image instead @@ -127,7 +128,7 @@ public class HtmlImage implements Html.ImageGetter { * redrawn when * the image is ready through an invalidation of the given view */ - public HtmlImage(final String geocode, final boolean returnErrorImage, final int listId, final boolean onlySave, final TextView view) { + public HtmlImage(@NonNull final String geocode, final boolean returnErrorImage, final int listId, final boolean onlySave, final TextView view) { this.geocode = geocode; this.returnErrorImage = returnErrorImage; this.listId = listId; @@ -146,7 +147,7 @@ public class HtmlImage implements Html.ImageGetter { * * For documentation, see {@link #HtmlImage(String, boolean, int, boolean, TextView)}. */ - public HtmlImage(final String geocode, final boolean returnErrorImage, final int listId, final boolean onlySave) { + public HtmlImage(@NonNull final String geocode, final boolean returnErrorImage, final int listId, final boolean onlySave) { this(geocode, returnErrorImage, listId, onlySave, null); } @@ -347,7 +348,7 @@ public class HtmlImage implements Html.ImageGetter { * @return A pair whose first element is the bitmap if available, and the second one is <code>true</code> if the image is present and fresh enough. */ @NonNull - private ImmutablePair<Bitmap, Boolean> loadImageFromStorage(final String url, final String pseudoGeocode, final boolean forceKeep) { + private ImmutablePair<Bitmap, Boolean> loadImageFromStorage(final String url, @NonNull final String pseudoGeocode, final boolean forceKeep) { try { final File file = LocalStorage.getStorageFile(pseudoGeocode, url, true, false); final ImmutablePair<Bitmap, Boolean> image = loadCachedImage(file, forceKeep); |