From e121e98234507925650888e3867173f77f684d98 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Wed, 8 Oct 2014 21:05:01 +0200 Subject: Added antennapod-subscribe:// subscription scheme --- src/de/danoeh/antennapod/util/URLChecker.java | 21 ++++++++++++--------- .../de/test/antennapod/util/URLCheckerTest.java | 20 +++++++++++++++++++- 2 files changed, 31 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/de/danoeh/antennapod/util/URLChecker.java b/src/de/danoeh/antennapod/util/URLChecker.java index 9997daaf7..2352adddf 100644 --- a/src/de/danoeh/antennapod/util/URLChecker.java +++ b/src/de/danoeh/antennapod/util/URLChecker.java @@ -22,6 +22,8 @@ public final class 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. * @@ -29,23 +31,24 @@ public final class URLChecker { * @return The prepared url */ public static String prepareURL(String url) { - StringBuilder builder = new StringBuilder(); url = StringUtils.trim(url); if (url.startsWith("feed://")) { 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://")) { - if (BuildConfig.DEBUG) Log.d(TAG, "Replacing pcast:// with http://"); - url = url.replaceFirst("pcast://", "http://"); + if (BuildConfig.DEBUG) Log.d(TAG, "Removing pcast://"); + return prepareURL(StringUtils.removeStart(url, "pcast://")); } else if (url.startsWith("itpc")) { 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://"))) { 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(); } } diff --git a/src/instrumentationTest/de/test/antennapod/util/URLCheckerTest.java b/src/instrumentationTest/de/test/antennapod/util/URLCheckerTest.java index 08fd0d486..fa99303b1 100644 --- a/src/instrumentationTest/de/test/antennapod/util/URLCheckerTest.java +++ b/src/instrumentationTest/de/test/antennapod/util/URLCheckerTest.java @@ -32,7 +32,7 @@ public class URLCheckerTest extends AndroidTestCase { assertEquals("http://example.com", out); } - public void testPcastProtocol() { + public void testPcastProtocolNoScheme() { final String in = "pcast://example.com"; final String out = URLChecker.prepareURL(in); assertEquals("http://example.com", out); @@ -55,4 +55,22 @@ public class URLCheckerTest extends AndroidTestCase { final String out = URLChecker.prepareURL(in); 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); + } } -- cgit v1.2.3