Implemented miroguide thumbnail download in FeedImageLoader
This commit is contained in:
parent
24775b9163
commit
a0cedbcbed
|
@ -134,6 +134,28 @@ public class FeedImageLoader {
|
|||
}
|
||||
}
|
||||
|
||||
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();
|
||||
thumbnailCache.evictAll();
|
||||
|
@ -163,6 +185,11 @@ public class FeedImageLoader {
|
|||
coverCache.put(key, bitmap);
|
||||
}
|
||||
|
||||
public boolean isInThumbnailDiskCache(String key) throws IOException {
|
||||
DiskLruCache cache = openThubmnailDiskCache();
|
||||
return cache.get(key) != null;
|
||||
}
|
||||
|
||||
class FeedImageDecodeWorkerTask extends BitmapDecodeWorkerTask {
|
||||
|
||||
private static final String TAG = "FeedImageDecodeWorkerTask";
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue