diff --git a/clients/android/NewsBlur/src/com/newsblur/util/ImageLoader.java b/clients/android/NewsBlur/src/com/newsblur/util/ImageLoader.java index ef883a2df..6986d56fb 100644 --- a/clients/android/NewsBlur/src/com/newsblur/util/ImageLoader.java +++ b/clients/android/NewsBlur/src/com/newsblur/util/ImageLoader.java @@ -85,7 +85,7 @@ public class ImageLoader { url = buildUrlIfNeeded(url); // try from memory - Bitmap bitmap = memoryCache.get(url); + Bitmap bitmap = memoryCache.get(url, false); if (bitmap != null) { remoteViews.setImageViewBitmap(imageViewId, bitmap); remoteViews.setViewVisibility(imageViewId, View.VISIBLE); @@ -100,7 +100,7 @@ public class ImageLoader { } if (bitmap != null) { - memoryCache.put(url, bitmap); + memoryCache.put(url, bitmap, false); remoteViews.setImageViewBitmap(imageViewId, bitmap); remoteViews.setViewVisibility(imageViewId, View.VISIBLE); } else { @@ -155,8 +155,7 @@ public class ImageLoader { if (photoToLoad.cancel) return; // try from memory - //TODO: revisit memory cache - Bitmap bitmap = null; + Bitmap bitmap = memoryCache.get(photoToLoad.url, photoToLoad.roundCorners); if (bitmap != null) { setViewImage(bitmap, photoToLoad); @@ -194,7 +193,7 @@ public class ImageLoader { } if (bitmap != null) { - memoryCache.put(photoToLoad.url, bitmap); + memoryCache.put(photoToLoad.url, bitmap, photoToLoad.roundCorners); } if (photoToLoad.cancel) return; setViewImage(bitmap, photoToLoad); diff --git a/clients/android/NewsBlur/src/com/newsblur/util/MemoryCache.java b/clients/android/NewsBlur/src/com/newsblur/util/MemoryCache.java index ecc34e07b..d179699f6 100644 --- a/clients/android/NewsBlur/src/com/newsblur/util/MemoryCache.java +++ b/clients/android/NewsBlur/src/com/newsblur/util/MemoryCache.java @@ -18,8 +18,9 @@ public class MemoryCache { this.limit = limitBytes; } - public Bitmap get(String id){ + public Bitmap get(String url, boolean hasRoundCorners){ try { + String id = getPhotoCacheId(url, hasRoundCorners); if (cache == null || !cache.containsKey(id)) { return null; } else { @@ -30,9 +31,10 @@ public class MemoryCache { } } - public void put(String id, Bitmap bitmap) { + public void put(String url, Bitmap bitmap, boolean hasRoundCorners) { synchronized (this) { - if (cache.containsKey(id)) { + String id = getPhotoCacheId(url, hasRoundCorners); + if (cache.containsKey(id)) { size -= getSizeInBytes(cache.get(id)); } cache.put(id, bitmap); @@ -41,6 +43,10 @@ public class MemoryCache { } } + public String getPhotoCacheId(String url, boolean hasRoundCorners) { + return hasRoundCorners ? url + "-rounded" : url; + } + private void checkSize() { if (size > limit) { final Iterator> iter = cache.entrySet().iterator();