From 77fac0ce78692c8d56f9dfb75c47e204a056cb46 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sat, 3 Jan 2015 10:16:29 +0100 Subject: 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". --- main/src/cgeo/geocaching/DataStore.java | 3 ++ .../src/cgeo/geocaching/SelectMapfileActivity.java | 2 +- main/src/cgeo/geocaching/connector/gc/GCLogin.java | 2 +- main/src/cgeo/geocaching/files/LocalStorage.java | 34 +++++++++++----------- 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 ".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 { * * * @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 true if an error image should be returned in case of a problem, false 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 true if the image is present and fresh enough. */ @NonNull - private ImmutablePair loadImageFromStorage(final String url, final String pseudoGeocode, final boolean forceKeep) { + private ImmutablePair loadImageFromStorage(final String url, @NonNull final String pseudoGeocode, final boolean forceKeep) { try { final File file = LocalStorage.getStorageFile(pseudoGeocode, url, true, false); final ImmutablePair image = loadCachedImage(file, forceKeep); -- cgit v1.1