diff options
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/cgeo/geocaching/network/HtmlImage.java | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/main/src/cgeo/geocaching/network/HtmlImage.java b/main/src/cgeo/geocaching/network/HtmlImage.java index b9ce732..288336d 100644 --- a/main/src/cgeo/geocaching/network/HtmlImage.java +++ b/main/src/cgeo/geocaching/network/HtmlImage.java @@ -96,7 +96,9 @@ public class HtmlImage implements Html.ImageGetter { if (statusCode == 200) { LocalStorage.saveEntityToFile(httpResponse, file); } else if (statusCode == 304) { - file.setLastModified(System.currentTimeMillis()); + if (!file.setLastModified(System.currentTimeMillis())) { + makeFreshCopy(file); + } } } } catch (Exception e) { @@ -128,6 +130,21 @@ public class HtmlImage implements Html.ImageGetter { return imagePre != null ? ImageHelper.scaleBitmapToFitDisplay(imagePre) : null; } + /** + * Make a fresh copy of the file to reset its timestamp. On some storage, it is impossible + * to modify the modified time after the fact, in which case a brand new file must be + * created if we want to be able to use the time as validity hint. + * + * See Android issue 1699. + * + * @param file the file to refresh + */ + private static void makeFreshCopy(final File file) { + final File tempFile = new File(file.getParentFile(), file.getName() + "-temp"); + file.renameTo(tempFile); + LocalStorage.copy(tempFile, file); + tempFile.delete(); + } private Bitmap getTransparent1x1Image() { return BitmapFactory.decodeResource(resources, R.drawable.image_no_placement); |