diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2011-11-01 15:49:53 +0100 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2011-11-01 15:49:53 +0100 |
| commit | c23a416a47f0581db2a40cf5f43e3eb8f8d9b3b4 (patch) | |
| tree | f880ef9ccc0db9674db2e4e62d40c0d91363679b /main/src | |
| parent | a4e77231246031d1614929334453c5c9299bca17 (diff) | |
| download | cgeo-c23a416a47f0581db2a40cf5f43e3eb8f8d9b3b4.zip cgeo-c23a416a47f0581db2a40cf5f43e3eb8f8d9b3b4.tar.gz cgeo-c23a416a47f0581db2a40cf5f43e3eb8f8d9b3b4.tar.bz2 | |
Cache images systematically
See discussion in #742.
Diffstat (limited to 'main/src')
| -rw-r--r-- | main/src/cgeo/geocaching/cgBase.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgeoimages.java | 13 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/network/HtmlImage.java | 25 |
3 files changed, 9 insertions, 31 deletions
diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java index 053119f..df34930 100644 --- a/main/src/cgeo/geocaching/cgBase.java +++ b/main/src/cgeo/geocaching/cgBase.java @@ -1653,7 +1653,7 @@ public class cgBase { final String profile = BaseUtils.replaceWhitespace(getResponseData(request("http://www.geocaching.com/my/", null, false))); final String avatarURL = BaseUtils.getMatch(profile, GCConstants.PATTERN_AVATAR_IMAGE, false, null); if (null != avatarURL) { - final HtmlImage imgGetter = new HtmlImage(context, "", false, 0, false, false); + final HtmlImage imgGetter = new HtmlImage(context, "", false, 0, false); return imgGetter.getDrawable(avatarURL); } // No match? There may be no avatar set by user. diff --git a/main/src/cgeo/geocaching/cgeoimages.java b/main/src/cgeo/geocaching/cgeoimages.java index ef3f1f8..48b7985 100644 --- a/main/src/cgeo/geocaching/cgeoimages.java +++ b/main/src/cgeo/geocaching/cgeoimages.java @@ -47,7 +47,7 @@ public class cgeoimages extends AbstractActivity { static private Collection<Bitmap> bitmaps = Collections.synchronizedCollection(new ArrayList<Bitmap>()); - private void loadImages(final List<cgImage> images, final int progressMessage, final boolean save, final boolean offline) { + private void loadImages(final List<cgImage> images, final int progressMessage, final boolean offline) { count = images.size(); progressDialog = new ProgressDialog(cgeoimages.this); @@ -69,7 +69,7 @@ public class cgeoimages extends AbstractActivity { descView.setVisibility(View.VISIBLE); } - new AsyncImgLoader(rowView, img, save, offline).execute(); + new AsyncImgLoader(rowView, img, offline).execute(); imagesView.addView(rowView); } } @@ -78,19 +78,17 @@ public class cgeoimages extends AbstractActivity { final private LinearLayout view; final private cgImage img; - final private boolean save; final boolean offline; - public AsyncImgLoader(final LinearLayout view, final cgImage img, final boolean save, final boolean offline) { + public AsyncImgLoader(final LinearLayout view, final cgImage img, final boolean offline) { this.view = view; this.img = img; - this.save = save; this.offline = offline; } @Override protected BitmapDrawable doInBackground(Void... params) { - final HtmlImage imgGetter = new HtmlImage(cgeoimages.this, geocode, true, offline ? 1 : 0, false, save); + final HtmlImage imgGetter = new HtmlImage(cgeoimages.this, geocode, true, offline ? 1 : 0, false); return imgGetter.getDrawable(img.url); } @@ -188,9 +186,8 @@ public class cgeoimages extends AbstractActivity { final int message = img_type == SPOILER_IMAGES ? R.string.cache_spoiler_images_loading : R.string.cache_log_images_loading; final boolean offline = app.isOffline(geocode, null) && (img_type == SPOILER_IMAGES || Settings.isStoreLogImages()); - final boolean save = img_type == SPOILER_IMAGES ? true : Settings.isStoreLogImages(); - loadImages(images, message, save, offline); + loadImages(images, message, offline); } @Override diff --git a/main/src/cgeo/geocaching/network/HtmlImage.java b/main/src/cgeo/geocaching/network/HtmlImage.java index b3511e3..7f4bc1b 100644 --- a/main/src/cgeo/geocaching/network/HtmlImage.java +++ b/main/src/cgeo/geocaching/network/HtmlImage.java @@ -22,8 +22,6 @@ import android.view.Display; import android.view.WindowManager; import java.io.File; -import java.io.IOException; -import java.io.InputStream; import java.util.Date; public class HtmlImage implements Html.ImageGetter { @@ -45,22 +43,16 @@ public class HtmlImage implements Html.ImageGetter { final private boolean returnErrorImage; final private int reason; final private boolean onlySave; - final private boolean save; final private BitmapFactory.Options bfOptions; final private int maxWidth; final private int maxHeight; - public HtmlImage(final Context context, final String geocode, final boolean returnErrorImage, final int reason, final boolean onlySave) { - this(context, geocode, returnErrorImage, reason, onlySave, true); - } - - public HtmlImage(final Context contextIn, final String geocode, final boolean returnErrorImage, final int reason, final boolean onlySave, final boolean save) { + public HtmlImage(final Context contextIn, final String geocode, final boolean returnErrorImage, final int reason, final boolean onlySave) { this.context = contextIn; this.geocode = geocode; this.returnErrorImage = returnErrorImage; this.reason = reason; this.onlySave = onlySave; - this.save = save; bfOptions = new BitmapFactory.Options(); bfOptions.inTempStorage = new byte[16 * 1024]; @@ -100,19 +92,8 @@ public class HtmlImage implements Html.ImageGetter { } } - if (save) { - final File file = LocalStorage.getStorageFile(geocode, url, true); - LocalStorage.saveEntityToFile(bufferedEntity, file); - } else { - setSampleSize(bufferedEntity.getContentLength()); - InputStream is; - try { - is = bufferedEntity.getContent(); - imagePre = BitmapFactory.decodeStream(is, null, bfOptions); - } catch (IOException e) { - Log.e(Settings.tag, "HtmlImage.getDrawable (decoding image)", e); - } - } + final File file = LocalStorage.getStorageFile(geocode, url, true); + LocalStorage.saveEntityToFile(bufferedEntity, file); } if (onlySave) { |
