Merge pull request #5329 from ByteHamster/subscribe-deeplink
Add subscription deeplink
This commit is contained in:
commit
d3c020b8df
|
@ -301,6 +301,19 @@
|
||||||
<data android:scheme="https" />
|
<data android:scheme="https" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
|
||||||
|
<data android:host="antennapod.org" />
|
||||||
|
<data android:host="www.antennapod.org" />
|
||||||
|
<data android:pathPrefix="/deeplink/subscribe" />
|
||||||
|
<data android:scheme="http" />
|
||||||
|
<data android:scheme="https" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.SEND"/>
|
<action android:name="android.intent.action.SEND"/>
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,10 @@ import android.text.TextUtils;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.BuildConfig;
|
|
||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLDecoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -28,6 +29,7 @@ public final class URLChecker {
|
||||||
private static final String TAG = "URLChecker";
|
private static final String TAG = "URLChecker";
|
||||||
|
|
||||||
private static final String AP_SUBSCRIBE = "antennapod-subscribe://";
|
private static final String AP_SUBSCRIBE = "antennapod-subscribe://";
|
||||||
|
private static final String AP_SUBSCRIBE_DEEPLINK = "antennapod.org/deeplink/subscribe?url=";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if URL is valid and modifies it if necessary.
|
* Checks if URL is valid and modifies it if necessary.
|
||||||
|
@ -39,22 +41,30 @@ public final class URLChecker {
|
||||||
url = url.trim();
|
url = url.trim();
|
||||||
String lowerCaseUrl = url.toLowerCase(); // protocol names are case insensitive
|
String lowerCaseUrl = url.toLowerCase(); // protocol names are case insensitive
|
||||||
if (lowerCaseUrl.startsWith("feed://")) {
|
if (lowerCaseUrl.startsWith("feed://")) {
|
||||||
if (BuildConfig.DEBUG) Log.d(TAG, "Replacing feed:// with http://");
|
Log.d(TAG, "Replacing feed:// with http://");
|
||||||
return prepareURL(url.substring("feed://".length()));
|
return prepareURL(url.substring("feed://".length()));
|
||||||
} else if (lowerCaseUrl.startsWith("pcast://")) {
|
} else if (lowerCaseUrl.startsWith("pcast://")) {
|
||||||
if (BuildConfig.DEBUG) Log.d(TAG, "Removing pcast://");
|
Log.d(TAG, "Removing pcast://");
|
||||||
return prepareURL(url.substring("pcast://".length()));
|
return prepareURL(url.substring("pcast://".length()));
|
||||||
} else if (lowerCaseUrl.startsWith("pcast:")) {
|
} else if (lowerCaseUrl.startsWith("pcast:")) {
|
||||||
if (BuildConfig.DEBUG) Log.d(TAG, "Removing pcast:");
|
Log.d(TAG, "Removing pcast:");
|
||||||
return prepareURL(url.substring("pcast:".length()));
|
return prepareURL(url.substring("pcast:".length()));
|
||||||
} else if (lowerCaseUrl.startsWith("itpc")) {
|
} else if (lowerCaseUrl.startsWith("itpc")) {
|
||||||
if (BuildConfig.DEBUG) Log.d(TAG, "Replacing itpc:// with http://");
|
Log.d(TAG, "Replacing itpc:// with http://");
|
||||||
return prepareURL(url.substring("itpc://".length()));
|
return prepareURL(url.substring("itpc://".length()));
|
||||||
} else if (lowerCaseUrl.startsWith(AP_SUBSCRIBE)) {
|
} else if (lowerCaseUrl.startsWith(AP_SUBSCRIBE)) {
|
||||||
if (BuildConfig.DEBUG) Log.d(TAG, "Removing antennapod-subscribe://");
|
Log.d(TAG, "Removing antennapod-subscribe://");
|
||||||
return prepareURL(url.substring(AP_SUBSCRIBE.length()));
|
return prepareURL(url.substring(AP_SUBSCRIBE.length()));
|
||||||
|
} else if (lowerCaseUrl.contains(AP_SUBSCRIBE_DEEPLINK)) {
|
||||||
|
Log.d(TAG, "Removing " + AP_SUBSCRIBE_DEEPLINK);
|
||||||
|
String removedWebsite = url.substring(url.indexOf(AP_SUBSCRIBE_DEEPLINK) + AP_SUBSCRIBE_DEEPLINK.length());
|
||||||
|
try {
|
||||||
|
return prepareURL(URLDecoder.decode(removedWebsite, "UTF-8"));
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
return prepareURL(removedWebsite);
|
||||||
|
}
|
||||||
} else if (!(lowerCaseUrl.startsWith("http://") || lowerCaseUrl.startsWith("https://"))) {
|
} else if (!(lowerCaseUrl.startsWith("http://") || lowerCaseUrl.startsWith("https://"))) {
|
||||||
if (BuildConfig.DEBUG) Log.d(TAG, "Adding http:// at the beginning of the URL");
|
Log.d(TAG, "Adding http:// at the beginning of the URL");
|
||||||
return "http://" + url;
|
return "http://" + url;
|
||||||
} else {
|
} else {
|
||||||
return url;
|
return url;
|
||||||
|
|
|
@ -4,6 +4,9 @@ import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
@ -98,6 +101,19 @@ public class URLCheckerTest {
|
||||||
assertEquals("https://example.com", out);
|
assertEquals("https://example.com", out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAntennaPodSubscribeDeeplink() throws UnsupportedEncodingException {
|
||||||
|
final String feed = "http://example.org/podcast.rss";
|
||||||
|
assertEquals(feed, URLChecker.prepareURL("https://antennapod.org/deeplink/subscribe?url=" + feed));
|
||||||
|
assertEquals(feed, URLChecker.prepareURL("http://antennapod.org/deeplink/subscribe?url=" + feed));
|
||||||
|
assertEquals(feed, URLChecker.prepareURL("https://www.antennapod.org/deeplink/subscribe?url=" + feed));
|
||||||
|
assertEquals(feed, URLChecker.prepareURL("http://www.antennapod.org/deeplink/subscribe?url=" + feed));
|
||||||
|
assertEquals(feed, URLChecker.prepareURL("http://www.antennapod.org/deeplink/subscribe?url="
|
||||||
|
+ URLEncoder.encode(feed, "UTF-8")));
|
||||||
|
assertEquals(feed, URLChecker.prepareURL("http://www.antennapod.org/deeplink/subscribe?url="
|
||||||
|
+ "example.org/podcast.rss"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProtocolRelativeUrlIsAbsolute() {
|
public void testProtocolRelativeUrlIsAbsolute() {
|
||||||
final String in = "https://example.com";
|
final String in = "https://example.com";
|
||||||
|
|
Loading…
Reference in New Issue