summaryrefslogtreecommitdiff
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
parent93812142dafac72b773573f7474033ae241ae348 (diff)
downloadAntennaPod-e170605ebc8c6cc1574054074481bb778902b409.zip
Thumbnail download is now partly working
-rw-r--r--res/layout/miroguide_channellist_item.xml7
-rw-r--r--src/de/danoeh/antennapod/asynctask/FeedImageLoader.java5
-rw-r--r--src/de/danoeh/antennapod/asynctask/MiroGuideThumbnailDownloader.java66
-rw-r--r--src/de/danoeh/antennapod/fragment/MiroGuideChannellistFragment.java2
-rw-r--r--src/de/danoeh/antennapod/miroguide/con/MiroGuideConnector.java6
-rw-r--r--src/de/danoeh/antennapod/miroguide/con/MiroGuideService.java2
-rw-r--r--src/de/danoeh/antennapod/miroguide/model/MiroChannel.java8
-rw-r--r--src/de/danoeh/antennapod/util/BitmapDecoder.java28
8 files changed, 73 insertions, 51 deletions
diff --git a/res/layout/miroguide_channellist_item.xml b/res/layout/miroguide_channellist_item.xml
index e5f444ebd..1d52ff695 100644
--- a/res/layout/miroguide_channellist_item.xml
+++ b/res/layout/miroguide_channellist_item.xml
@@ -6,14 +6,13 @@
<ImageView
android:id="@+id/imgvChannelimage"
- android:src="@drawable/default_cover"
- android:layout_width="55dip"
- android:layout_height="55dip"
+ android:layout_width="40dip"
+ android:layout_height="40dip"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="1dip"
android:layout_marginRight="4dip"
- android:cropToPadding="true" />
+ android:src="@drawable/default_cover" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
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()) {
diff --git a/src/de/danoeh/antennapod/fragment/MiroGuideChannellistFragment.java b/src/de/danoeh/antennapod/fragment/MiroGuideChannellistFragment.java
index c0f25cc9b..e3aeff64a 100644
--- a/src/de/danoeh/antennapod/fragment/MiroGuideChannellistFragment.java
+++ b/src/de/danoeh/antennapod/fragment/MiroGuideChannellistFragment.java
@@ -228,7 +228,7 @@ public class MiroGuideChannellistFragment extends SherlockListFragment {
exception = e;
e.printStackTrace();
} finally {
- service.close();
+ //service.close();
}
return null;
}
diff --git a/src/de/danoeh/antennapod/miroguide/con/MiroGuideConnector.java b/src/de/danoeh/antennapod/miroguide/con/MiroGuideConnector.java
index 4d137a56f..92076d948 100644
--- a/src/de/danoeh/antennapod/miroguide/con/MiroGuideConnector.java
+++ b/src/de/danoeh/antennapod/miroguide/con/MiroGuideConnector.java
@@ -19,7 +19,7 @@ import android.net.http.AndroidHttpClient;
/** Executes HTTP requests and returns the results. */
public class MiroGuideConnector {
- private AndroidHttpClient httpClient;
+ private HttpClient httpClient;
private static final String HOST_URL = "https://www.miroguide.com/api/";
private static final String PATH_GET_CHANNELS = "get_channels";
@@ -27,11 +27,11 @@ public class MiroGuideConnector {
private static final String PATH_GET_CHANNEL = "get_channel";
public MiroGuideConnector() {
- httpClient = AndroidHttpClient.newInstance(null);
+ httpClient = new DefaultHttpClient();
}
public void shutdown() {
- httpClient.close();
+ httpClient.getConnectionManager().shutdown();
}
private Uri.Builder getBaseURIBuilder(String path) {
diff --git a/src/de/danoeh/antennapod/miroguide/con/MiroGuideService.java b/src/de/danoeh/antennapod/miroguide/con/MiroGuideService.java
index be2679229..8779207eb 100644
--- a/src/de/danoeh/antennapod/miroguide/con/MiroGuideService.java
+++ b/src/de/danoeh/antennapod/miroguide/con/MiroGuideService.java
@@ -17,6 +17,8 @@ import de.danoeh.antennapod.miroguide.model.MiroItem;
/** Provides methods to communicate with the Miroguide API on an abstract level. */
public class MiroGuideService {
+ private static final String TAG = "MiroGuideService";
+
public static final int DEFAULT_CHANNEL_LIMIT = 20;
public static final String FILTER_CATEGORY = "category";
diff --git a/src/de/danoeh/antennapod/miroguide/model/MiroChannel.java b/src/de/danoeh/antennapod/miroguide/model/MiroChannel.java
index 97b9946df..87812052b 100644
--- a/src/de/danoeh/antennapod/miroguide/model/MiroChannel.java
+++ b/src/de/danoeh/antennapod/miroguide/model/MiroChannel.java
@@ -34,8 +34,6 @@ public class MiroChannel {
this.description = description;
this.items = items;
}
-
-
@Override
public String toString() {
@@ -69,7 +67,9 @@ public class MiroChannel {
public ArrayList<MiroItem> getItems() {
return items;
}
-
-
+
+ public void setThumbnailUrl(String thumbnailUrl) {
+ this.thumbnailUrl = thumbnailUrl;
+ }
}
diff --git a/src/de/danoeh/antennapod/util/BitmapDecoder.java b/src/de/danoeh/antennapod/util/BitmapDecoder.java
index 8cd0bd910..f4b902c6f 100644
--- a/src/de/danoeh/antennapod/util/BitmapDecoder.java
+++ b/src/de/danoeh/antennapod/util/BitmapDecoder.java
@@ -6,8 +6,9 @@ import android.util.Log;
public class BitmapDecoder {
private static final String TAG = "BitmapDecoder";
-
- private static int calculateSampleSize(int preferredLength, int width, int height) {
+
+ private static int calculateSampleSize(int preferredLength, int width,
+ int height) {
int max = Math.max(width, height);
if (max < preferredLength) {
return 1;
@@ -27,18 +28,23 @@ public class BitmapDecoder {
}
}
}
-
+
public static Bitmap decodeBitmap(int preferredLength, String fileUrl) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(fileUrl, options);
- int sampleSize = calculateSampleSize(preferredLength, options.outWidth,
- options.outHeight);
+ int srcWidth = options.outWidth;
+ int srcHeight = options.outHeight;
+ int sampleSize = calculateSampleSize(preferredLength, srcWidth,
+ srcHeight);
options.inJustDecodeBounds = false;
options.inSampleSize = sampleSize;
- Bitmap decodedBitmap = BitmapFactory.decodeFile(fileUrl,
- options);
+ options.inPreferredConfig = Bitmap.Config.ARGB_8888;
+ options.inDither = false;
+ options.inScaled = false;
+
+ Bitmap decodedBitmap = BitmapFactory.decodeFile(fileUrl, options);
if (decodedBitmap == null) {
Log.i(TAG,
"Bitmap could not be decoded in custom sample size. Trying default sample size (path was "
@@ -46,8 +52,12 @@ public class BitmapDecoder {
decodedBitmap = BitmapFactory.decodeFile(fileUrl);
}
if (decodedBitmap != null) {
- return Bitmap.createScaledBitmap(decodedBitmap,
- preferredLength, preferredLength, false);
+ if (preferredLength > srcWidth || preferredLength > srcHeight) {
+ return decodedBitmap;
+ } else {
+ return Bitmap.createScaledBitmap(decodedBitmap,
+ preferredLength, preferredLength, false);
+ }
} else {
return null;
}