Added antennapod-subscribe:// subscription scheme

This commit is contained in:
daniel oeh 2014-10-08 21:05:01 +02:00
parent a0365969a0
commit e121e98234
3 changed files with 32 additions and 10 deletions

View File

@ -293,6 +293,7 @@
<data android:scheme="itpc"/> <data android:scheme="itpc"/>
<data android:scheme="pcast"/> <data android:scheme="pcast"/>
<data android:scheme="feed"/> <data android:scheme="feed"/>
<data android:scheme="antennapod-subscribe"/>
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>

View File

@ -22,6 +22,8 @@ public final class URLChecker {
*/ */
private static final String TAG = "URLChecker"; private static final String TAG = "URLChecker";
private static final String AP_SUBSCRIBE = "antennapod-subscribe://";
/** /**
* Checks if URL is valid and modifies it if necessary. * Checks if URL is valid and modifies it if necessary.
* *
@ -29,23 +31,24 @@ public final class URLChecker {
* @return The prepared url * @return The prepared url
*/ */
public static String prepareURL(String url) { public static String prepareURL(String url) {
StringBuilder builder = new StringBuilder();
url = StringUtils.trim(url); url = StringUtils.trim(url);
if (url.startsWith("feed://")) { if (url.startsWith("feed://")) {
if (BuildConfig.DEBUG) Log.d(TAG, "Replacing feed:// with http://"); if (BuildConfig.DEBUG) Log.d(TAG, "Replacing feed:// with http://");
url = url.replaceFirst("feed://", "http://"); return url.replaceFirst("feed://", "http://");
} else if (url.startsWith("pcast://")) { } else if (url.startsWith("pcast://")) {
if (BuildConfig.DEBUG) Log.d(TAG, "Replacing pcast:// with http://"); if (BuildConfig.DEBUG) Log.d(TAG, "Removing pcast://");
url = url.replaceFirst("pcast://", "http://"); return prepareURL(StringUtils.removeStart(url, "pcast://"));
} else if (url.startsWith("itpc")) { } else if (url.startsWith("itpc")) {
if (BuildConfig.DEBUG) Log.d(TAG, "Replacing itpc:// with http://"); if (BuildConfig.DEBUG) Log.d(TAG, "Replacing itpc:// with http://");
url = url.replaceFirst("itpc://", "http://"); return url.replaceFirst("itpc://", "http://");
} else if (url.startsWith(AP_SUBSCRIBE)) {
if (BuildConfig.DEBUG) Log.d(TAG, "Removing antennapod-subscribe://");
return prepareURL(StringUtils.removeStart(url, AP_SUBSCRIBE));
} else if (!(url.startsWith("http://") || url.startsWith("https://"))) { } else if (!(url.startsWith("http://") || url.startsWith("https://"))) {
if (BuildConfig.DEBUG) Log.d(TAG, "Adding http:// at the beginning of the URL"); if (BuildConfig.DEBUG) Log.d(TAG, "Adding http:// at the beginning of the URL");
builder.append("http://"); return "http://" + url;
} else {
return url;
} }
builder.append(url);
return builder.toString();
} }
} }

View File

@ -32,7 +32,7 @@ public class URLCheckerTest extends AndroidTestCase {
assertEquals("http://example.com", out); assertEquals("http://example.com", out);
} }
public void testPcastProtocol() { public void testPcastProtocolNoScheme() {
final String in = "pcast://example.com"; final String in = "pcast://example.com";
final String out = URLChecker.prepareURL(in); final String out = URLChecker.prepareURL(in);
assertEquals("http://example.com", out); assertEquals("http://example.com", out);
@ -55,4 +55,22 @@ public class URLCheckerTest extends AndroidTestCase {
final String out = URLChecker.prepareURL(in); final String out = URLChecker.prepareURL(in);
assertEquals("http://example.com", out); assertEquals("http://example.com", out);
} }
public void testAntennaPodSubscribeProtocolNoScheme() throws Exception {
final String in = "antennapod-subscribe://example.com";
final String out = URLChecker.prepareURL(in);
assertEquals("http://example.com", out);
}
public void testPcastProtocolWithScheme() {
final String in = "pcast://https://example.com";
final String out = URLChecker.prepareURL(in);
assertEquals("https://example.com", out);
}
public void testAntennaPodSubscribeProtocolWithScheme() throws Exception {
final String in = "antennapod-subscribe://https://example.com";
final String out = URLChecker.prepareURL(in);
assertEquals("https://example.com", out);
}
} }