summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/asynctask
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-08-03 19:48:59 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2012-08-03 19:48:59 +0200
commite170605ebc8c6cc1574054074481bb778902b409 (patch)
tree7a8d25bc44a34876985bef6638a3529b4876cf37 /src/de/danoeh/antennapod/asynctask
parent93812142dafac72b773573f7474033ae241ae348 (diff)
downloadAntennaPod-e170605ebc8c6cc1574054074481bb778902b409.zip
Thumbnail download is now partly working
Diffstat (limited to 'src/de/danoeh/antennapod/asynctask')
-rw-r--r--src/de/danoeh/antennapod/asynctask/FeedImageLoader.java5
-rw-r--r--src/de/danoeh/antennapod/asynctask/MiroGuideThumbnailDownloader.java66
2 files changed, 41 insertions, 30 deletions
diff --git a/src/de/danoeh/antennapod/asynctask/FeedImageLoader.java b/src/de/danoeh/antennapod/asynctask/FeedImageLoader.java
index bed6a2fbb..ab750d4b3 100644
--- a/src/de/danoeh/antennapod/asynctask/FeedImageLoader.java
+++ b/src/de/danoeh/antennapod/asynctask/FeedImageLoader.java
@@ -19,6 +19,7 @@ import android.widget.ImageView;
import com.jakewharton.DiskLruCache;
import com.jakewharton.DiskLruCache.Snapshot;
+import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.PodcastApp;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.feed.FeedImage;
@@ -159,6 +160,7 @@ public class FeedImageLoader {
.getThumbnailUrl());
if (bitmap == null) {
boolean isInDiskCache = false;
+ /*
try {
isInDiskCache = isInThumbnailDiskCache(channel
.getThumbnailUrl());
@@ -166,10 +168,13 @@ public class FeedImageLoader {
e.printStackTrace();
Log.e(TAG, "Error when trying to read disk cache");
}
+ */
if (isInDiskCache) {
executor.submit(new MiroGuideDiskCacheLoader(handler,
target, channel, LENGTH_BASE_THUMBNAIL));
} else {
+ if (AppConfig.DEBUG) Log.d(TAG, "Starting new thumbnail download");
+
executor.submit(new MiroGuideThumbnailDownloader(handler,
target, channel, LENGTH_BASE_THUMBNAIL));
}
diff --git a/src/de/danoeh/antennapod/asynctask/MiroGuideThumbnailDownloader.java b/src/de/danoeh/antennapod/asynctask/MiroGuideThumbnailDownloader.java
index 87eca833b..557aac623 100644
--- a/src/de/danoeh/antennapod/asynctask/MiroGuideThumbnailDownloader.java
+++ b/src/de/danoeh/antennapod/asynctask/MiroGuideThumbnailDownloader.java
@@ -1,6 +1,7 @@
package de.danoeh.antennapod.asynctask;
import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -9,6 +10,7 @@ import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
+import java.net.URLConnection;
import com.jakewharton.DiskLruCache;
import com.jakewharton.DiskLruCache.Editor;
@@ -19,6 +21,7 @@ import de.danoeh.antennapod.miroguide.model.MiroChannel;
import de.danoeh.antennapod.util.BitmapDecoder;
import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.os.Handler;
import android.util.Log;
import android.widget.ImageView;
@@ -39,7 +42,7 @@ public class MiroGuideThumbnailDownloader extends BitmapDecodeWorkerTask {
@Override
protected void onPostExecute() {
- if (exception != null) {
+ if (exception == null) {
super.onPostExecute();
} else {
Log.e(TAG, "Failed to download thumbnail");
@@ -58,40 +61,43 @@ public class MiroGuideThumbnailDownloader extends BitmapDecodeWorkerTask {
File destination = new File(PodcastApp.getInstance().getCacheDir(),
Integer.toString(fileUrl.hashCode()));
try {
- DiskLruCache diskCache = FeedImageLoader.openThubmnailDiskCache();
- Editor editor = diskCache.edit(fileUrl);
- if (editor != null) {
- HttpURLConnection connection = (HttpURLConnection) url
- .openConnection();
- byte inputBuffer[] = new byte[10 * 1024];
- InputStream input = new BufferedInputStream(
- connection.getInputStream());
- FileOutputStream output = new FileOutputStream(destination);
+ /*
+ * DiskLruCache diskCache =
+ * FeedImageLoader.openThubmnailDiskCache(); Editor editor =
+ * diskCache.edit(fileUrl);
+ */
+ if (AppConfig.DEBUG) Log.d(TAG, "Downloading " + fileUrl);
+ URLConnection connection = url.openConnection();
+ connection.connect();
+ byte inputBuffer[] = new byte[1024];
+ BufferedInputStream input = new BufferedInputStream(
+ connection.getInputStream());
+ FileOutputStream output = new FileOutputStream(destination);
- int count = 0;
- while ((count = input.read(inputBuffer, 0, 10 * 1024)) != -1) {
- output.write(inputBuffer, 0, count);
- }
- output.close();
- connection.disconnect();
- if (AppConfig.DEBUG) Log.d(TAG, "MiroGuide thumbnail downloaded");
- // Get a smaller version of the bitmap and store it inside the
- // LRU
- // Cache
- Bitmap bitmap = BitmapDecoder.decodeBitmap(PREFERRED_LENGTH,
- fileUrl);
- if (bitmap != null) {
- OutputStream imageOut = editor.newOutputStream(0);
- bitmap.compress(Bitmap.CompressFormat.PNG, 80, imageOut);
- editor.commit();
- storeBitmapInCache(bitmap);
- }
- } else {
+ int count = 0;
+ while ((count = input.read(inputBuffer)) != -1) {
+ output.write(inputBuffer, 0, count);
if (AppConfig.DEBUG)
- Log.d(TAG, "No editor object available");
+ Log.d(TAG, "" + 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
+ Bitmap bitmap = BitmapDecoder.decodeBitmap(PREFERRED_LENGTH,
+ destination.getPath());
+ if (bitmap != null) {
+ // OutputStream imageOut = editor.newOutputStream(0);
+ // bitmap.compress(Bitmap.CompressFormat.PNG, 80, imageOut);
+ // editor.commit();
+ storeBitmapInCache(bitmap);
+ }
+
} catch (IOException e) {
e.printStackTrace();
+ miroChannel.setThumbnailUrl(null);
endBackgroundTask();
} finally {
if (destination.exists()) {