Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Handling both relative and absolute URLs as podcast thumbnails

  • Loading branch information...
commit 253acef3f1499f85db61f87a1be2290822f50566 1 parent 6a3888d
@tindandelion authored
View
20 Radio-T-Test/src/org/dandelion/radiot/unittest/ThumbnailUriTestCase.java
@@ -0,0 +1,20 @@
+package org.dandelion.radiot.unittest;
+
+import junit.framework.TestCase;
+import org.dandelion.radiot.podcasts.core.RssFeedModel;
+
+public class ThumbnailUriTestCase extends TestCase {
+ public void testConstructFromCompleteUrl() throws Exception {
+ String url = RssFeedModel.ThumbnailUrl.construct("http://www.radio-t.com/thumbnail.jpg");
+ assertEquals("http://www.radio-t.com/thumbnail.jpg", url);
+ }
+
+ public void testConstructFromRelativeUrl() throws Exception {
+ String url = RssFeedModel.ThumbnailUrl.construct("/thumbnail.jpg");
+ assertEquals("http://www.radio-t.com/thumbnail.jpg", url);
+ }
+
+ public void testNoUrl() throws Exception {
+ assertNull(RssFeedModel.ThumbnailUrl.construct(null));
+ }
+}
View
28 Radio-T/src/org/dandelion/radiot/podcasts/core/RssFeedModel.java
@@ -6,6 +6,7 @@
import java.util.ArrayList;
import java.util.List;
+import android.net.Uri;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
@@ -107,6 +108,31 @@ protected InputStream openImageStream(String address) {
}
public Bitmap loadPodcastImage(PodcastItem item) {
- return BitmapFactory.decodeStream(openImageStream(item.getThumbnailUrl()));
+ return BitmapFactory.decodeStream(openImageStream(
+ fullyQualifiedUrl(item.getThumbnailUrl())));
}
+
+ private String fullyQualifiedUrl(String urlPart) {
+ return ThumbnailUrl.construct(urlPart);
+ }
+
+ public static class ThumbnailUrl {
+ private static final String HOST = "http://www.radio-t.com";
+
+ public static String construct(String urlPart) {
+ if (null == urlPart) {
+ return null;
+ }
+ return constructFullUrl(urlPart);
+ }
+
+ private static String constructFullUrl(String urlPart) {
+ Uri uri = Uri.parse(urlPart);
+ if (uri.isAbsolute()) {
+ return urlPart;
+ } else {
+ return HOST + urlPart;
+ }
+ }
+ }
}

0 comments on commit 253acef

Please sign in to comment.
Something went wrong with that request. Please try again.