Skip to content

Commit

Permalink
Handling both relative and absolute URLs as podcast thumbnails
Browse files Browse the repository at this point in the history
  • Loading branch information
tindandelion committed Aug 22, 2012
1 parent 6a3888d commit 253acef
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
@@ -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));
}
}
28 changes: 27 additions & 1 deletion Radio-T/src/org/dandelion/radiot/podcasts/core/RssFeedModel.java
Expand Up @@ -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;

Expand Down Expand Up @@ -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.