Implemented miroguide thumbnail download in FeedImageLoader

This commit is contained in:
daniel oeh 2012-08-03 15:11:55 +02:00
parent 24775b9163
commit a0cedbcbed
2 changed files with 28 additions and 1 deletions

View File

@ -133,6 +133,28 @@ public class FeedImageLoader {
target.setImageResource(R.drawable.default_cover);
}
}
public void loadMiroGuideThumbnail(MiroChannel channel, ImageView target) {
if (channel.getThumbnailUrl() != null) {
Bitmap bitmap = getBitmapFromThumbnailCache(channel.getThumbnailUrl());
if (bitmap != null) {
boolean isInDiskCache = false;
try {
isInDiskCache = isInThumbnailDiskCache(channel.getThumbnailUrl());
} catch (IOException e) {
e.printStackTrace();
Log.e(TAG, "Error when trying to read disk cache");
}
if (isInDiskCache) {
new MiroGuideDiskCacheLoader(target, channel, LENGTH_BASE_THUMBNAIL).executeAsync();
} else {
new MiroGuideThumbnailDownloader(target, channel, LENGTH_BASE_THUMBNAIL).executeAsync();
}
}
} else {
target.setImageResource(R.drawable.default_cover);
}
}
public void wipeImageCache() {
coverCache.evictAll();
@ -162,6 +184,11 @@ public class FeedImageLoader {
public void addBitmapToCoverCache(String key, Bitmap bitmap) {
coverCache.put(key, bitmap);
}
public boolean isInThumbnailDiskCache(String key) throws IOException {
DiskLruCache cache = openThubmnailDiskCache();
return cache.get(key) != null;
}
class FeedImageDecodeWorkerTask extends BitmapDecodeWorkerTask {

View File

@ -73,7 +73,7 @@ public class MiroGuideThumbnailDownloader extends BitmapDecodeWorkerTask {
output.write(inputBuffer, 0, count);
}
output.close();
if (AppConfig.DEBUG) Log.d(TAG, "MiroGuide thumbnail downloaded");
// Get a smaller version of the bitmap and store it inside the
// LRU
// Cache