From 24775b9163326e01ffc7c5114597e579b4134ad7 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Fri, 3 Aug 2012 15:02:48 +0200 Subject: Created AsyncTask for loading miroguide thumbnails from the disk cache --- .../asynctask/MiroGuideThumbnailDownloader.java | 34 ++++++---------------- 1 file changed, 9 insertions(+), 25 deletions(-) (limited to 'src/de/danoeh/antennapod/asynctask/MiroGuideThumbnailDownloader.java') diff --git a/src/de/danoeh/antennapod/asynctask/MiroGuideThumbnailDownloader.java b/src/de/danoeh/antennapod/asynctask/MiroGuideThumbnailDownloader.java index c1a87b1ec..00776c4a2 100644 --- a/src/de/danoeh/antennapod/asynctask/MiroGuideThumbnailDownloader.java +++ b/src/de/danoeh/antennapod/asynctask/MiroGuideThumbnailDownloader.java @@ -18,10 +18,7 @@ import de.danoeh.antennapod.PodcastApp; import de.danoeh.antennapod.miroguide.model.MiroChannel; import de.danoeh.antennapod.util.BitmapDecoder; -import android.content.Context; -import android.content.pm.PackageManager.NameNotFoundException; import android.graphics.Bitmap; -import android.os.AsyncTask; import android.util.Log; import android.widget.ImageView; @@ -29,12 +26,8 @@ import android.widget.ImageView; public class MiroGuideThumbnailDownloader extends BitmapDecodeWorkerTask { private static final String TAG = "MiroGuideThumbnailDownloader"; - private static final String CACHE_DIR = "miroguide_thumbnails"; - private static final int CACHE_SIZE = 20 * 1024 * 1024; - private static final int VALUE_SIZE = 500 * 1024; - private Exception exception; - + private MiroChannel miroChannel; public MiroGuideThumbnailDownloader(ImageView target, @@ -43,14 +36,13 @@ public class MiroGuideThumbnailDownloader extends BitmapDecodeWorkerTask { this.miroChannel = miroChannel; } - private static DiskLruCache openThubmnailDiskCache() - throws NameNotFoundException, IOException { - Context appContext = PodcastApp.getInstance(); - return DiskLruCache.open( - appContext.getExternalFilesDir(CACHE_DIR), - appContext.getPackageManager().getPackageInfo( - appContext.getPackageName(), 0).versionCode, - VALUE_SIZE, CACHE_SIZE); + @Override + protected void onPostExecute(Void result) { + if (exception != null) { + super.onPostExecute(result); + } else { + Log.e(TAG, "Failed to download thumbnail"); + } } @Override @@ -66,7 +58,7 @@ public class MiroGuideThumbnailDownloader extends BitmapDecodeWorkerTask { File destination = new File(PodcastApp.getInstance().getCacheDir(), Integer.toString(fileUrl.hashCode())); try { - DiskLruCache diskCache = openThubmnailDiskCache(); + DiskLruCache diskCache = FeedImageLoader.openThubmnailDiskCache(); Editor editor = diskCache.edit(fileUrl); if (editor != null) { HttpURLConnection connection = (HttpURLConnection) url @@ -100,9 +92,6 @@ public class MiroGuideThumbnailDownloader extends BitmapDecodeWorkerTask { } catch (IOException e) { e.printStackTrace(); return null; - } catch (NameNotFoundException e) { - e.printStackTrace(); - return null; } finally { if (destination.exists()) { destination.delete(); @@ -115,9 +104,4 @@ public class MiroGuideThumbnailDownloader extends BitmapDecodeWorkerTask { protected boolean tagsMatching(ImageView target) { return target.getTag() == null || target.getTag() == miroChannel; } - - @Override - protected void storeBitmapInCache(Bitmap bitmap) { - - } } -- cgit v1.2.3