mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-31 21:41:33 +00:00
#1458 Re-enabled image memory caching
This commit is contained in:
parent
4a003d7678
commit
a0ef89604b
2 changed files with 13 additions and 8 deletions
|
@ -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);
|
||||
|
|
|
@ -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<Entry<String, Bitmap>> iter = cache.entrySet().iterator();
|
||||
|
|
Loading…
Add table
Reference in a new issue