Added support for "pcast"-protocol, start FeedViewActivity immediately when clicking on a link. closes #425

This commit is contained in:
daniel oeh 2014-05-25 15:40:12 +02:00
parent eb0f48d3c3
commit dbff918e3a
6 changed files with 164 additions and 77 deletions

View File

@ -41,7 +41,8 @@
android:theme="@style/Theme.AntennaPod.Light">
<meta-data
android:name="com.google.android.backup.api_key"
android:value="AEdPqrEAAAAI3a05VToCTlqBymJrbFGaKQMvF-bBAuLsOdavBA" />
android:value="AEdPqrEAAAAI3a05VToCTlqBymJrbFGaKQMvF-bBAuLsOdavBA"/>
<activity
android:name=".activity.MainActivity"
android:configChanges="keyboardHidden|orientation"
@ -51,54 +52,6 @@
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</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:scheme="http"/>
<data android:scheme="https"/>
<data android:host="*"/>
<data android:pathPattern=".*\\.xml"/>
<data android:pathPattern=".*\\.rss"/>
</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:scheme="http"/>
<data android:scheme="https"/>
<data android:host="feeds.feedburner.com"/>
<data android:host="feedproxy.google.com"/>
<data android:host="feeds2.feedburner.com"/>
<data android:host="feedsproxy.google.com"/>
</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:scheme="http"/>
<data android:scheme="https"/>
<data android:mimeType="text/xml"/>
<data android:mimeType="application/rss+xml"/>
<data android:mimeType="application/atom+xml"/>
<data android:mimeType="application/xml"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
<activity
android:name=".activity.AudioplayerActivity"
@ -274,13 +227,86 @@
android:name="android.support.PARENT_ACTIVITY"
android:value="de.danoeh.antennapod.activity.PreferenceActivity"/>
</activity>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="de.danoeh.antennapod.activity.PreferenceActivity"/>
<activity
android:name=".activity.DefaultOnlineFeedViewActivity"
android:configChanges="orientation"/>
android:configChanges="orientation">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="de.danoeh.antennapod.activity.MainActivity"/>
<!-- URLs ending with '.xml' or '.rss' -->
<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:scheme="http"/>
<data android:scheme="https"/>
<data android:host="*"/>
<data android:pathPattern=".*\\.xml"/>
<data android:pathPattern=".*\\.rss"/>
</intent-filter>
<!-- Feedburner URLs -->
<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:scheme="http"/>
<data android:scheme="https"/>
<data android:host="feeds.feedburner.com"/>
<data android:host="feedproxy.google.com"/>
<data android:host="feeds2.feedburner.com"/>
<data android:host="feedsproxy.google.com"/>
</intent-filter>
<!-- Files with mimeType rss/xml/atom -->
<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:scheme="http"/>
<data android:scheme="https"/>
<data android:mimeType="text/xml"/>
<data android:mimeType="application/rss+xml"/>
<data android:mimeType="application/atom+xml"/>
<data android:mimeType="application/xml"/>
</intent-filter>
<!-- Podcast protocols -->
<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:scheme="pcast"/>
<data android:scheme="feed"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
<activity
android:name=".activity.gpoddernet.GpodnetAuthenticationActivity"

View File

@ -1,8 +1,10 @@
package de.danoeh.antennapod.activity;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
@ -44,7 +46,12 @@ public class DefaultOnlineFeedViewActivity extends OnlineFeedViewActivity {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
Intent destIntent = new Intent(this, MainActivity.class);
if (NavUtils.shouldUpRecreateTask(this, destIntent)) {
startActivity(destIntent);
} else {
NavUtils.navigateUpFromSameTask(this);
}
return true;
}
return super.onOptionsItemSelected(item);

View File

@ -28,7 +28,6 @@ import de.danoeh.antennapod.fragment.*;
import de.danoeh.antennapod.preferences.UserPreferences;
import de.danoeh.antennapod.storage.DBReader;
import de.danoeh.antennapod.util.StorageUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
@ -280,18 +279,7 @@ public class MainActivity extends ActionBarActivity {
EventDistributor.getInstance().register(contentUpdate);
Intent intent = getIntent();
if (StringUtils.equals(intent.getAction(), Intent.ACTION_SEND)
|| StringUtils.equals(intent.getAction(), Intent.ACTION_VIEW)) {
String extra = (StringUtils.equals(intent.getAction(), Intent.ACTION_SEND))
? intent.getStringExtra(Intent.EXTRA_TEXT) : intent.getDataString();
if (extra != null) {
Bundle args = new Bundle();
args.putString(AddFeedFragment.ARG_FEED_URL, extra);
loadFragment(NavListAdapter.VIEW_TYPE_NAV, POS_ADD, args);
selectedNavListIndex = POS_ADD;
navAdapter.notifyDataSetChanged();
}
} else if (feeds != null && intent.hasExtra(EXTRA_NAV_INDEX) && intent.hasExtra(EXTRA_NAV_TYPE)) {
if (feeds != null && intent.hasExtra(EXTRA_NAV_INDEX) && intent.hasExtra(EXTRA_NAV_TYPE)) {
handleNavIntent();
}

View File

@ -5,6 +5,7 @@ import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
@ -27,6 +28,7 @@ import de.danoeh.antennapod.util.DownloadError;
import de.danoeh.antennapod.util.FileNameGenerator;
import de.danoeh.antennapod.util.StorageUtils;
import de.danoeh.antennapod.util.URLChecker;
import org.apache.commons.lang3.StringUtils;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
@ -46,7 +48,9 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
private static final String TAG = "OnlineFeedViewActivity";
public static final String ARG_FEEDURL = "arg.feedurl";
/** Optional argument: specify a title for the actionbar. */
/**
* Optional argument: specify a title for the actionbar.
*/
public static final String ARG_TITLE = "title";
public static final int RESULT_ERROR = 2;
@ -64,11 +68,21 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
}
StorageUtils.checkStorageAvailability(this);
final String feedUrl = getIntent().getStringExtra(ARG_FEEDURL);
if (feedUrl == null) {
final String feedUrl;
if (getIntent().hasExtra(ARG_FEEDURL)) {
feedUrl = getIntent().getStringExtra(ARG_FEEDURL);
} else if (StringUtils.equals(getIntent().getAction(), Intent.ACTION_SEND)
|| StringUtils.equals(getIntent().getAction(), Intent.ACTION_VIEW)) {
feedUrl = (StringUtils.equals(getIntent().getAction(), Intent.ACTION_SEND))
? getIntent().getStringExtra(Intent.EXTRA_TEXT) : getIntent().getDataString();
getSupportActionBar().setTitle(R.string.add_new_feed_label);
} else {
throw new IllegalArgumentException(
"Activity must be started with feedurl argument!");
}
if (BuildConfig.DEBUG)
Log.d(TAG, "Activity was started with url " + feedUrl);
setLoadingLayout();
@ -244,7 +258,7 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
/**
* Can be used to load data asynchronously.
* */
*/
protected void loadData() {
}
@ -271,7 +285,8 @@ public abstract class OnlineFeedViewActivity extends ActionBarActivity {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
}
);
builder.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {

View File

@ -3,25 +3,36 @@ package de.danoeh.antennapod.util;
import android.util.Log;
import de.danoeh.antennapod.BuildConfig;
/** Provides methods for checking and editing a URL.*/
/**
* Provides methods for checking and editing a URL.
*/
public final class URLChecker {
/**Class shall not be instantiated.*/
/**
* Class shall not be instantiated.
*/
private URLChecker() {
}
/**Logging tag.*/
/**
* Logging tag.
*/
private static final String TAG = "URLChecker";
/** Checks if URL is valid and modifies it if necessary.
* @param url The url which is going to be prepared
* @return The prepared url
* */
/**
* Checks if URL is valid and modifies it if necessary.
*
* @param url The url which is going to be prepared
* @return The prepared url
*/
public static String prepareURL(String url) {
StringBuilder builder = new StringBuilder();
if (url.startsWith("feed://")) {
if (BuildConfig.DEBUG) Log.d(TAG, "Replacing feed:// with http://");
url = url.replace("feed://", "http://");
url = url.replaceFirst("feed://", "http://");
} else if (url.startsWith("pcast://")) {
if (BuildConfig.DEBUG) Log.d(TAG, "Replacing pcast:// with http://");
url = url.replaceFirst("pcast://", "http://");
} 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://");

View File

@ -0,0 +1,40 @@
package instrumentationTest.de.test.antennapod.util;
import android.test.AndroidTestCase;
import de.danoeh.antennapod.util.URLChecker;
/**
* Test class for URLChecker
*/
public class URLCheckerTest extends AndroidTestCase {
public void testCorrectURLHttp() {
final String in = "http://example.com";
final String out = URLChecker.prepareURL(in);
assertEquals(in, out);
}
public void testCorrectURLHttps() {
final String in = "https://example.com";
final String out = URLChecker.prepareURL(in);
assertEquals(in, out);
}
public void testMissingProtocol() {
final String in = "example.com";
final String out = URLChecker.prepareURL(in);
assertEquals("http://example.com", out);
}
public void testFeedProtocol() {
final String in = "feed://example.com";
final String out = URLChecker.prepareURL(in);
assertEquals("http://example.com", out);
}
public void testPcastProtocol() {
final String in = "pcast://example.com";
final String out = URLChecker.prepareURL(in);
assertEquals("http://example.com", out);
}
}