Merge pull request #890 from mfietz/issue/880-link-typo
Handle malformed URLs
This commit is contained in:
commit
e1b494ba05
|
@ -2,6 +2,8 @@ package de.danoeh.antennapod.activity;
|
||||||
|
|
||||||
import android.content.ClipData;
|
import android.content.ClipData;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
|
@ -30,6 +32,7 @@ import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
import de.danoeh.antennapod.core.storage.DBReader;
|
import de.danoeh.antennapod.core.storage.DBReader;
|
||||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||||
import de.danoeh.antennapod.core.storage.DownloadRequestException;
|
import de.danoeh.antennapod.core.storage.DownloadRequestException;
|
||||||
|
import de.danoeh.antennapod.core.util.IntentUtils;
|
||||||
import de.danoeh.antennapod.core.util.LangUtils;
|
import de.danoeh.antennapod.core.util.LangUtils;
|
||||||
import de.danoeh.antennapod.menuhandler.FeedMenuHandler;
|
import de.danoeh.antennapod.menuhandler.FeedMenuHandler;
|
||||||
|
|
||||||
|
@ -205,7 +208,8 @@ public class FeedInfoActivity extends ActionBarActivity {
|
||||||
menu.findItem(R.id.support_item).setVisible(
|
menu.findItem(R.id.support_item).setVisible(
|
||||||
feed != null && feed.getPaymentLink() != null);
|
feed != null && feed.getPaymentLink() != null);
|
||||||
menu.findItem(R.id.share_link_item).setVisible(feed != null && feed.getLink() != null);
|
menu.findItem(R.id.share_link_item).setVisible(feed != null && feed.getLink() != null);
|
||||||
menu.findItem(R.id.visit_website_item).setVisible(feed != null && feed.getLink() != null);
|
menu.findItem(R.id.visit_website_item).setVisible(feed != null && feed.getLink() != null &&
|
||||||
|
IntentUtils.isCallable(this, new Intent(Intent.ACTION_VIEW, Uri.parse(feed.getLink()))));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ package de.danoeh.antennapod.activity;
|
||||||
|
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ResolveInfo;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -18,11 +17,10 @@ import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import de.danoeh.antennapod.BuildConfig;
|
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
|
import de.danoeh.antennapod.core.util.IntentUtils;
|
||||||
import de.danoeh.antennapod.core.util.LangUtils;
|
import de.danoeh.antennapod.core.util.LangUtils;
|
||||||
import de.danoeh.antennapod.core.util.StorageUtils;
|
import de.danoeh.antennapod.core.util.StorageUtils;
|
||||||
|
|
||||||
|
@ -72,13 +70,10 @@ public class OpmlImportFromPathActivity extends OpmlImportBaseActivity {
|
||||||
int nextOption = 1;
|
int nextOption = 1;
|
||||||
intentPickAction = new Intent(Intent.ACTION_PICK);
|
intentPickAction = new Intent(Intent.ACTION_PICK);
|
||||||
intentPickAction.setData(Uri.parse("file://"));
|
intentPickAction.setData(Uri.parse("file://"));
|
||||||
List<ResolveInfo> intentActivities = getPackageManager()
|
|
||||||
.queryIntentActivities(intentPickAction, CHOOSE_OPML_FILE);
|
if(false == IntentUtils.isCallable(getApplicationContext(), intentPickAction)) {
|
||||||
if(intentActivities.size() == 0) {
|
|
||||||
intentPickAction.setData(null);
|
intentPickAction.setData(null);
|
||||||
intentActivities = getPackageManager()
|
if(false == IntentUtils.isCallable(getApplicationContext(), intentPickAction)) {
|
||||||
.queryIntentActivities(intentPickAction, CHOOSE_OPML_FILE);
|
|
||||||
if(intentActivities.size() == 0) {
|
|
||||||
txtvHeaderExplanation1.setVisibility(View.GONE);
|
txtvHeaderExplanation1.setVisibility(View.GONE);
|
||||||
txtvExplanation1.setVisibility(View.GONE);
|
txtvExplanation1.setVisibility(View.GONE);
|
||||||
findViewById(R.id.divider1).setVisibility(View.GONE);
|
findViewById(R.id.divider1).setVisibility(View.GONE);
|
||||||
|
@ -93,9 +88,7 @@ public class OpmlImportFromPathActivity extends OpmlImportBaseActivity {
|
||||||
intentGetContentAction = new Intent(Intent.ACTION_GET_CONTENT);
|
intentGetContentAction = new Intent(Intent.ACTION_GET_CONTENT);
|
||||||
intentGetContentAction.addCategory(Intent.CATEGORY_OPENABLE);
|
intentGetContentAction.addCategory(Intent.CATEGORY_OPENABLE);
|
||||||
intentGetContentAction.setType("*/*");
|
intentGetContentAction.setType("*/*");
|
||||||
intentActivities = getPackageManager()
|
if(false == IntentUtils.isCallable(getApplicationContext(), intentGetContentAction)) {
|
||||||
.queryIntentActivities(intentGetContentAction, CHOOSE_OPML_FILE);
|
|
||||||
if(intentActivities.size() == 0) {
|
|
||||||
txtvHeaderExplanation2.setVisibility(View.GONE);
|
txtvHeaderExplanation2.setVisibility(View.GONE);
|
||||||
txtvExplanation2.setVisibility(View.GONE);
|
txtvExplanation2.setVisibility(View.GONE);
|
||||||
findViewById(R.id.divider2).setVisibility(View.GONE);
|
findViewById(R.id.divider2).setVisibility(View.GONE);
|
||||||
|
@ -137,7 +130,7 @@ public class OpmlImportFromPathActivity extends OpmlImportBaseActivity {
|
||||||
try {
|
try {
|
||||||
mReader = new InputStreamReader(new FileInputStream(file),
|
mReader = new InputStreamReader(new FileInputStream(file),
|
||||||
LangUtils.UTF_8);
|
LangUtils.UTF_8);
|
||||||
if (BuildConfig.DEBUG) Log.d(TAG, "Parsing " + file.toString());
|
Log.d(TAG, "Parsing " + file.toString());
|
||||||
startImport(mReader);
|
startImport(mReader);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
Log.d(TAG, "File not found which really should be there");
|
Log.d(TAG, "File not found which really should be there");
|
||||||
|
|
|
@ -341,7 +341,7 @@ public class AllEpisodesFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
contextMenu = menu;
|
contextMenu = menu;
|
||||||
FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item, true, queuedItemsIds);
|
FeedItemMenuHandler.onPrepareMenu(getActivity(), contextMenuInterface, item, true, queuedItemsIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,12 +25,12 @@ import android.webkit.WebView;
|
||||||
import android.webkit.WebViewClient;
|
import android.webkit.WebViewClient;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import de.danoeh.antennapod.BuildConfig;
|
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
import de.danoeh.antennapod.core.storage.DBReader;
|
import de.danoeh.antennapod.core.storage.DBReader;
|
||||||
import de.danoeh.antennapod.core.util.Converter;
|
import de.danoeh.antennapod.core.util.Converter;
|
||||||
|
import de.danoeh.antennapod.core.util.IntentUtils;
|
||||||
import de.danoeh.antennapod.core.util.ShareUtils;
|
import de.danoeh.antennapod.core.util.ShareUtils;
|
||||||
import de.danoeh.antennapod.core.util.ShownotesProvider;
|
import de.danoeh.antennapod.core.util.ShownotesProvider;
|
||||||
import de.danoeh.antennapod.core.util.playback.Playable;
|
import de.danoeh.antennapod.core.util.playback.Playable;
|
||||||
|
@ -104,7 +104,6 @@ public class ItemDescriptionFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
if (BuildConfig.DEBUG)
|
|
||||||
Log.d(TAG, "Creating view");
|
Log.d(TAG, "Creating view");
|
||||||
webvDescription = new WebView(getActivity());
|
webvDescription = new WebView(getActivity());
|
||||||
if (UserPreferences.getTheme() == R.style.Theme_AntennaPod_Dark) {
|
if (UserPreferences.getTheme() == R.style.Theme_AntennaPod_Dark) {
|
||||||
|
@ -141,7 +140,6 @@ public class ItemDescriptionFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public void onPageFinished(WebView view, String url) {
|
public void onPageFinished(WebView view, String url) {
|
||||||
super.onPageFinished(view, url);
|
super.onPageFinished(view, url);
|
||||||
if (BuildConfig.DEBUG)
|
|
||||||
Log.d(TAG, "Page finished");
|
Log.d(TAG, "Page finished");
|
||||||
// Restoring the scroll position might not always work
|
// Restoring the scroll position might not always work
|
||||||
view.postDelayed(new Runnable() {
|
view.postDelayed(new Runnable() {
|
||||||
|
@ -163,14 +161,12 @@ public class ItemDescriptionFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
if (BuildConfig.DEBUG)
|
|
||||||
Log.d(TAG, "Fragment attached");
|
Log.d(TAG, "Fragment attached");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDetach() {
|
public void onDetach() {
|
||||||
super.onDetach();
|
super.onDetach();
|
||||||
if (BuildConfig.DEBUG)
|
|
||||||
Log.d(TAG, "Fragment detached");
|
Log.d(TAG, "Fragment detached");
|
||||||
if (webViewLoader != null) {
|
if (webViewLoader != null) {
|
||||||
webViewLoader.cancel(true);
|
webViewLoader.cancel(true);
|
||||||
|
@ -180,7 +176,6 @@ public class ItemDescriptionFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
if (BuildConfig.DEBUG)
|
|
||||||
Log.d(TAG, "Fragment destroyed");
|
Log.d(TAG, "Fragment destroyed");
|
||||||
if (webViewLoader != null) {
|
if (webViewLoader != null) {
|
||||||
webViewLoader.cancel(true);
|
webViewLoader.cancel(true);
|
||||||
|
@ -195,7 +190,6 @@ public class ItemDescriptionFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (BuildConfig.DEBUG)
|
|
||||||
Log.d(TAG, "Creating fragment");
|
Log.d(TAG, "Creating fragment");
|
||||||
Bundle args = getArguments();
|
Bundle args = getArguments();
|
||||||
saveState = args.getBoolean(ARG_SAVE_STATE, false);
|
saveState = args.getBoolean(ARG_SAVE_STATE, false);
|
||||||
|
@ -258,11 +252,7 @@ public class ItemDescriptionFragment extends Fragment {
|
||||||
WebView.HitTestResult r = webvDescription.getHitTestResult();
|
WebView.HitTestResult r = webvDescription.getHitTestResult();
|
||||||
if (r != null
|
if (r != null
|
||||||
&& r.getType() == WebView.HitTestResult.SRC_ANCHOR_TYPE) {
|
&& r.getType() == WebView.HitTestResult.SRC_ANCHOR_TYPE) {
|
||||||
if (BuildConfig.DEBUG)
|
Log.d(TAG, "Link of webview was long-pressed. Extra: " + r.getExtra());
|
||||||
Log.d(TAG,
|
|
||||||
"Link of webview was long-pressed. Extra: "
|
|
||||||
+ r.getExtra()
|
|
||||||
);
|
|
||||||
selectedURL = r.getExtra();
|
selectedURL = r.getExtra();
|
||||||
webvDescription.showContextMenu();
|
webvDescription.showContextMenu();
|
||||||
return true;
|
return true;
|
||||||
|
@ -281,8 +271,10 @@ public class ItemDescriptionFragment extends Fragment {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.open_in_browser_item:
|
case R.id.open_in_browser_item:
|
||||||
Uri uri = Uri.parse(selectedURL);
|
Uri uri = Uri.parse(selectedURL);
|
||||||
getActivity()
|
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||||
.startActivity(new Intent(Intent.ACTION_VIEW, uri));
|
if(IntentUtils.isCallable(getActivity(), intent)) {
|
||||||
|
getActivity().startActivity(intent);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case R.id.share_url_item:
|
case R.id.share_url_item:
|
||||||
ShareUtils.shareLink(getActivity(), selectedURL);
|
ShareUtils.shareLink(getActivity(), selectedURL);
|
||||||
|
@ -331,8 +323,12 @@ public class ItemDescriptionFragment extends Fragment {
|
||||||
R.string.go_to_position_label);
|
R.string.go_to_position_label);
|
||||||
menu.setHeaderTitle(Converter.getDurationStringLong(Timeline.getTimecodeLinkTime(selectedURL)));
|
menu.setHeaderTitle(Converter.getDurationStringLong(Timeline.getTimecodeLinkTime(selectedURL)));
|
||||||
} else {
|
} else {
|
||||||
|
Uri uri = Uri.parse(selectedURL);
|
||||||
|
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||||
|
if(IntentUtils.isCallable(getActivity(), intent)) {
|
||||||
menu.add(Menu.NONE, R.id.open_in_browser_item, Menu.NONE,
|
menu.add(Menu.NONE, R.id.open_in_browser_item, Menu.NONE,
|
||||||
R.string.open_in_browser_label);
|
R.string.open_in_browser_label);
|
||||||
|
}
|
||||||
menu.add(Menu.NONE, R.id.copy_url_item, Menu.NONE,
|
menu.add(Menu.NONE, R.id.copy_url_item, Menu.NONE,
|
||||||
R.string.copy_url_label);
|
R.string.copy_url_label);
|
||||||
menu.add(Menu.NONE, R.id.share_url_item, Menu.NONE,
|
menu.add(Menu.NONE, R.id.share_url_item, Menu.NONE,
|
||||||
|
@ -358,7 +354,6 @@ public class ItemDescriptionFragment extends Fragment {
|
||||||
// /webvDescription.loadData(url, "text/html", "utf-8");
|
// /webvDescription.loadData(url, "text/html", "utf-8");
|
||||||
webvDescription.loadDataWithBaseURL(null, data, "text/html",
|
webvDescription.loadDataWithBaseURL(null, data, "text/html",
|
||||||
"utf-8", "about:blank");
|
"utf-8", "about:blank");
|
||||||
if (BuildConfig.DEBUG)
|
|
||||||
Log.d(TAG, "Webview loaded");
|
Log.d(TAG, "Webview loaded");
|
||||||
webViewLoader = null;
|
webViewLoader = null;
|
||||||
}
|
}
|
||||||
|
@ -370,7 +365,6 @@ public class ItemDescriptionFragment extends Fragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
if (BuildConfig.DEBUG)
|
|
||||||
Log.d(TAG, "Loading Webview");
|
Log.d(TAG, "Loading Webview");
|
||||||
try {
|
try {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
|
@ -397,24 +391,17 @@ public class ItemDescriptionFragment extends Fragment {
|
||||||
|
|
||||||
private void savePreference() {
|
private void savePreference() {
|
||||||
if (saveState) {
|
if (saveState) {
|
||||||
if (BuildConfig.DEBUG)
|
|
||||||
Log.d(TAG, "Saving preferences");
|
Log.d(TAG, "Saving preferences");
|
||||||
SharedPreferences prefs = getActivity().getSharedPreferences(PREF,
|
SharedPreferences prefs = getActivity().getSharedPreferences(PREF,
|
||||||
Activity.MODE_PRIVATE);
|
Activity.MODE_PRIVATE);
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
if (media != null && webvDescription != null) {
|
if (media != null && webvDescription != null) {
|
||||||
if (BuildConfig.DEBUG)
|
Log.d(TAG, "Saving scroll position: " + webvDescription.getScrollY());
|
||||||
Log.d(TAG,
|
|
||||||
"Saving scroll position: "
|
|
||||||
+ webvDescription.getScrollY()
|
|
||||||
);
|
|
||||||
editor.putInt(PREF_SCROLL_Y, webvDescription.getScrollY());
|
editor.putInt(PREF_SCROLL_Y, webvDescription.getScrollY());
|
||||||
editor.putString(PREF_PLAYABLE_ID, media.getIdentifier()
|
editor.putString(PREF_PLAYABLE_ID, media.getIdentifier()
|
||||||
.toString());
|
.toString());
|
||||||
} else {
|
} else {
|
||||||
if (BuildConfig.DEBUG)
|
Log.d(TAG, "savePreferences was called while media or webview was null");
|
||||||
Log.d(TAG,
|
|
||||||
"savePreferences was called while media or webview was null");
|
|
||||||
editor.putInt(PREF_SCROLL_Y, -1);
|
editor.putInt(PREF_SCROLL_Y, -1);
|
||||||
editor.putString(PREF_PLAYABLE_ID, "");
|
editor.putString(PREF_PLAYABLE_ID, "");
|
||||||
}
|
}
|
||||||
|
@ -424,7 +411,6 @@ public class ItemDescriptionFragment extends Fragment {
|
||||||
|
|
||||||
private boolean restoreFromPreference() {
|
private boolean restoreFromPreference() {
|
||||||
if (saveState) {
|
if (saveState) {
|
||||||
if (BuildConfig.DEBUG)
|
|
||||||
Log.d(TAG, "Restoring from preferences");
|
Log.d(TAG, "Restoring from preferences");
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
|
@ -435,7 +421,6 @@ public class ItemDescriptionFragment extends Fragment {
|
||||||
if (scrollY != -1 && media != null
|
if (scrollY != -1 && media != null
|
||||||
&& id.equals(media.getIdentifier().toString())
|
&& id.equals(media.getIdentifier().toString())
|
||||||
&& webvDescription != null) {
|
&& webvDescription != null) {
|
||||||
if (BuildConfig.DEBUG)
|
|
||||||
Log.d(TAG, "Restored scroll Position: " + scrollY);
|
Log.d(TAG, "Restored scroll Position: " + scrollY);
|
||||||
webvDescription.scrollTo(webvDescription.getScrollX(),
|
webvDescription.scrollTo(webvDescription.getScrollX(),
|
||||||
scrollY);
|
scrollY);
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
package de.danoeh.antennapod.fragment;
|
package de.danoeh.antennapod.fragment;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ClipData;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
@ -18,7 +19,9 @@ import android.support.v7.widget.Toolbar;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.ContextMenu;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -53,7 +56,9 @@ import de.danoeh.antennapod.core.storage.DBWriter;
|
||||||
import de.danoeh.antennapod.core.storage.DownloadRequestException;
|
import de.danoeh.antennapod.core.storage.DownloadRequestException;
|
||||||
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
||||||
import de.danoeh.antennapod.core.util.Converter;
|
import de.danoeh.antennapod.core.util.Converter;
|
||||||
|
import de.danoeh.antennapod.core.util.IntentUtils;
|
||||||
import de.danoeh.antennapod.core.util.LongList;
|
import de.danoeh.antennapod.core.util.LongList;
|
||||||
|
import de.danoeh.antennapod.core.util.ShareUtils;
|
||||||
import de.danoeh.antennapod.core.util.playback.Timeline;
|
import de.danoeh.antennapod.core.util.playback.Timeline;
|
||||||
import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler;
|
import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler;
|
||||||
import de.greenrobot.event.EventBus;
|
import de.greenrobot.event.EventBus;
|
||||||
|
@ -107,6 +112,11 @@ public class ItemFragment extends Fragment implements LoaderManager.LoaderCallba
|
||||||
private ImageButton butMore;
|
private ImageButton butMore;
|
||||||
private PopupMenu popupMenu;
|
private PopupMenu popupMenu;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL that was selected via long-press.
|
||||||
|
*/
|
||||||
|
private String selectedURL;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -194,20 +204,19 @@ public class ItemFragment extends Fragment implements LoaderManager.LoaderCallba
|
||||||
webvDescription.getSettings().setLayoutAlgorithm(
|
webvDescription.getSettings().setLayoutAlgorithm(
|
||||||
WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
|
WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
|
||||||
webvDescription.getSettings().setLoadWithOverviewMode(true);
|
webvDescription.getSettings().setLoadWithOverviewMode(true);
|
||||||
|
webvDescription.setOnLongClickListener(webViewLongClickListener);
|
||||||
webvDescription.setWebViewClient(new WebViewClient() {
|
webvDescription.setWebViewClient(new WebViewClient() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||||
try {
|
if(IntentUtils.isCallable(getActivity(), intent)) {
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
} catch (ActivityNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
registerForContextMenu(webvDescription);
|
||||||
|
|
||||||
imgvCover = (ImageView) header.findViewById(R.id.imgvCover);
|
imgvCover = (ImageView) header.findViewById(R.id.imgvCover);
|
||||||
progbarDownload = (ProgressBar) header.findViewById(R.id.progbarDownload);
|
progbarDownload = (ProgressBar) header.findViewById(R.id.progbarDownload);
|
||||||
|
@ -272,10 +281,10 @@ public class ItemFragment extends Fragment implements LoaderManager.LoaderCallba
|
||||||
popupMenu.getMenu().clear();
|
popupMenu.getMenu().clear();
|
||||||
popupMenu.inflate(R.menu.feeditem_options);
|
popupMenu.inflate(R.menu.feeditem_options);
|
||||||
if (item.hasMedia()) {
|
if (item.hasMedia()) {
|
||||||
FeedItemMenuHandler.onPrepareMenu(popupMenuInterface, item, true, queue);
|
FeedItemMenuHandler.onPrepareMenu(getActivity(), popupMenuInterface, item, true, queue);
|
||||||
} else {
|
} else {
|
||||||
// these are already available via button1 and button2
|
// these are already available via button1 and button2
|
||||||
FeedItemMenuHandler.onPrepareMenu(popupMenuInterface, item, true, queue,
|
FeedItemMenuHandler.onPrepareMenu(getActivity(), popupMenuInterface, item, true, queue,
|
||||||
R.id.mark_read_item, R.id.visit_website_item);
|
R.id.mark_read_item, R.id.visit_website_item);
|
||||||
}
|
}
|
||||||
popupMenu.show();
|
popupMenu.show();
|
||||||
|
@ -398,6 +407,83 @@ public class ItemFragment extends Fragment implements LoaderManager.LoaderCallba
|
||||||
getLoaderManager().restartLoader(0, null, ItemFragment.this);
|
getLoaderManager().restartLoader(0, null, ItemFragment.this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private View.OnLongClickListener webViewLongClickListener = new View.OnLongClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
|
WebView.HitTestResult r = webvDescription.getHitTestResult();
|
||||||
|
if (r != null
|
||||||
|
&& r.getType() == WebView.HitTestResult.SRC_ANCHOR_TYPE) {
|
||||||
|
Log.d(TAG, "Link of webview was long-pressed. Extra: " + r.getExtra());
|
||||||
|
selectedURL = r.getExtra();
|
||||||
|
webvDescription.showContextMenu();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
selectedURL = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onContextItemSelected(MenuItem item) {
|
||||||
|
boolean handled = selectedURL != null;
|
||||||
|
if (selectedURL != null) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.open_in_browser_item:
|
||||||
|
Uri uri = Uri.parse(selectedURL);
|
||||||
|
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||||
|
if(IntentUtils.isCallable(getActivity(), intent)) {
|
||||||
|
getActivity().startActivity(intent);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case R.id.share_url_item:
|
||||||
|
ShareUtils.shareLink(getActivity(), selectedURL);
|
||||||
|
break;
|
||||||
|
case R.id.copy_url_item:
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= 11) {
|
||||||
|
ClipData clipData = ClipData.newPlainText(selectedURL,
|
||||||
|
selectedURL);
|
||||||
|
android.content.ClipboardManager cm = (android.content.ClipboardManager) getActivity()
|
||||||
|
.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
cm.setPrimaryClip(clipData);
|
||||||
|
} else {
|
||||||
|
android.text.ClipboardManager cm = (android.text.ClipboardManager) getActivity()
|
||||||
|
.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
cm.setText(selectedURL);
|
||||||
|
}
|
||||||
|
Toast t = Toast.makeText(getActivity(),
|
||||||
|
R.string.copied_url_msg, Toast.LENGTH_SHORT);
|
||||||
|
t.show();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
handled = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
selectedURL = null;
|
||||||
|
}
|
||||||
|
return handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreateContextMenu(ContextMenu menu, View v,
|
||||||
|
ContextMenu.ContextMenuInfo menuInfo) {
|
||||||
|
if (selectedURL != null) {
|
||||||
|
super.onCreateContextMenu(menu, v, menuInfo);
|
||||||
|
Uri uri = Uri.parse(selectedURL);
|
||||||
|
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||||
|
if(IntentUtils.isCallable(getActivity(), intent)) {
|
||||||
|
menu.add(Menu.NONE, R.id.open_in_browser_item, Menu.NONE,
|
||||||
|
R.string.open_in_browser_label);
|
||||||
|
}
|
||||||
|
menu.add(Menu.NONE, R.id.copy_url_item, Menu.NONE,
|
||||||
|
R.string.copy_url_label);
|
||||||
|
menu.add(Menu.NONE, R.id.share_url_item, Menu.NONE,
|
||||||
|
R.string.share_url_label);
|
||||||
|
menu.setHeaderTitle(selectedURL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Loader<Pair<FeedItem,LongList>> onCreateLoader(int id, Bundle args) {
|
public Loader<Pair<FeedItem,LongList>> onCreateLoader(int id, Bundle args) {
|
||||||
return new DBTaskLoader<Pair<FeedItem,LongList>>(getActivity()) {
|
return new DBTaskLoader<Pair<FeedItem,LongList>>(getActivity()) {
|
||||||
|
|
|
@ -302,7 +302,7 @@ public class ItemlistFragment extends ListFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
contextMenu = menu;
|
contextMenu = menu;
|
||||||
FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item, true, queuedItemsIds);
|
FeedItemMenuHandler.onPrepareMenu(getActivity(), contextMenuInterface, item, true, queuedItemsIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -329,7 +329,7 @@ public class QueueFragment extends Fragment {
|
||||||
for(FeedItem queueItem : queue) {
|
for(FeedItem queueItem : queue) {
|
||||||
queueIds.add(queueItem.getId());
|
queueIds.add(queueItem.getId());
|
||||||
}
|
}
|
||||||
FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item, true, queueIds);
|
FeedItemMenuHandler.onPrepareMenu(getActivity(), contextMenuInterface, item, true, queueIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||||
|
@ -16,7 +17,7 @@ import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||||
import de.danoeh.antennapod.core.storage.DBTasks;
|
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||||
import de.danoeh.antennapod.core.storage.DownloadRequestException;
|
import de.danoeh.antennapod.core.storage.DownloadRequestException;
|
||||||
import de.danoeh.antennapod.core.storage.DownloadRequester;
|
import de.danoeh.antennapod.core.util.IntentUtils;
|
||||||
import de.danoeh.antennapod.core.util.LongList;
|
import de.danoeh.antennapod.core.util.LongList;
|
||||||
import de.danoeh.antennapod.core.util.ShareUtils;
|
import de.danoeh.antennapod.core.util.ShareUtils;
|
||||||
|
|
||||||
|
@ -56,7 +57,7 @@ public class FeedItemMenuHandler {
|
||||||
* @param queueAccess Used for testing if the queue contains the selected item
|
* @param queueAccess Used for testing if the queue contains the selected item
|
||||||
* @return Returns true if selectedItem is not null.
|
* @return Returns true if selectedItem is not null.
|
||||||
*/
|
*/
|
||||||
public static boolean onPrepareMenu(MenuInterface mi, FeedItem selectedItem,
|
public static boolean onPrepareMenu(Context context, MenuInterface mi, FeedItem selectedItem,
|
||||||
boolean showExtendedMenu, LongList queueAccess) {
|
boolean showExtendedMenu, LongList queueAccess) {
|
||||||
if (selectedItem == null) {
|
if (selectedItem == null) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -108,7 +109,9 @@ public class FeedItemMenuHandler {
|
||||||
mi.setItemVisibility(R.id.deactivate_auto_download, false);
|
mi.setItemVisibility(R.id.deactivate_auto_download, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!showExtendedMenu || selectedItem.getLink() == null) {
|
if (!showExtendedMenu || selectedItem.getLink() == null ||
|
||||||
|
false == IntentUtils.isCallable(context, new Intent(Intent.ACTION_VIEW, Uri.parse(selectedItem.getLink()))))
|
||||||
|
{
|
||||||
mi.setItemVisibility(R.id.visit_website_item, false);
|
mi.setItemVisibility(R.id.visit_website_item, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,21 +128,19 @@ public class FeedItemMenuHandler {
|
||||||
* @param excludeIds Menu item that should be excluded
|
* @param excludeIds Menu item that should be excluded
|
||||||
* @return true if selectedItem is not null.
|
* @return true if selectedItem is not null.
|
||||||
*/
|
*/
|
||||||
public static boolean onPrepareMenu(MenuInterface mi,
|
public static boolean onPrepareMenu(Context context, MenuInterface mi, FeedItem selectedItem,
|
||||||
FeedItem selectedItem, boolean showExtendedMenu, LongList queueAccess, int... excludeIds) {
|
boolean showExtendedMenu, LongList queueAccess, int... excludeIds) {
|
||||||
boolean rc = onPrepareMenu(mi, selectedItem, showExtendedMenu, queueAccess);
|
boolean rc = onPrepareMenu(context, mi, selectedItem, showExtendedMenu, queueAccess);
|
||||||
if (rc && excludeIds != null) {
|
if (rc && excludeIds != null) {
|
||||||
for (int id : excludeIds) {
|
for (int id : excludeIds) {
|
||||||
mi.setItemVisibility(id, false);
|
mi.setItemVisibility(id, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean onMenuItemClicked(Context context, int menuItemId,
|
public static boolean onMenuItemClicked(Context context, int menuItemId,
|
||||||
FeedItem selectedItem) throws DownloadRequestException {
|
FeedItem selectedItem) throws DownloadRequestException {
|
||||||
DownloadRequester requester = DownloadRequester.getInstance();
|
|
||||||
switch (menuItemId) {
|
switch (menuItemId) {
|
||||||
case R.id.skip_episode_item:
|
case R.id.skip_episode_item:
|
||||||
context.sendBroadcast(new Intent(PlaybackService.ACTION_SKIP_CURRENT_EPISODE));
|
context.sendBroadcast(new Intent(PlaybackService.ACTION_SKIP_CURRENT_EPISODE));
|
||||||
|
@ -198,7 +199,13 @@ public class FeedItemMenuHandler {
|
||||||
break;
|
break;
|
||||||
case R.id.visit_website_item:
|
case R.id.visit_website_item:
|
||||||
Uri uri = Uri.parse(selectedItem.getLink());
|
Uri uri = Uri.parse(selectedItem.getLink());
|
||||||
context.startActivity(new Intent(Intent.ACTION_VIEW, uri));
|
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||||
|
if(IntentUtils.isCallable(context, intent)) {
|
||||||
|
context.startActivity(intent);
|
||||||
|
} else {
|
||||||
|
Toast.makeText(context, context.getString(R.string.download_error_malformed_url),
|
||||||
|
Toast.LENGTH_SHORT);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case R.id.support_item:
|
case R.id.support_item:
|
||||||
DBTasks.flattrItemIfLoggedIn(context, selectedItem);
|
DBTasks.flattrItemIfLoggedIn(context, selectedItem);
|
||||||
|
|
|
@ -9,6 +9,7 @@ import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -20,6 +21,7 @@ import de.danoeh.antennapod.core.feed.Feed;
|
||||||
import de.danoeh.antennapod.core.storage.DBTasks;
|
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||||
import de.danoeh.antennapod.core.storage.DownloadRequestException;
|
import de.danoeh.antennapod.core.storage.DownloadRequestException;
|
||||||
|
import de.danoeh.antennapod.core.util.IntentUtils;
|
||||||
import de.danoeh.antennapod.core.util.ShareUtils;
|
import de.danoeh.antennapod.core.util.ShareUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,7 +85,13 @@ public class FeedMenuHandler {
|
||||||
break;
|
break;
|
||||||
case R.id.visit_website_item:
|
case R.id.visit_website_item:
|
||||||
Uri uri = Uri.parse(selectedFeed.getLink());
|
Uri uri = Uri.parse(selectedFeed.getLink());
|
||||||
context.startActivity(new Intent(Intent.ACTION_VIEW, uri));
|
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||||
|
if(IntentUtils.isCallable(context, intent)) {
|
||||||
|
context.startActivity(intent);
|
||||||
|
} else {
|
||||||
|
Toast.makeText(context, context.getString(R.string.download_error_malformed_url),
|
||||||
|
Toast.LENGTH_SHORT);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case R.id.support_item:
|
case R.id.support_item:
|
||||||
DBTasks.flattrFeedIfLoggedIn(context, selectedFeed);
|
DBTasks.flattrFeedIfLoggedIn(context, selectedFeed);
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package de.danoeh.antennapod.core.util;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.ResolveInfo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class IntentUtils {
|
||||||
|
|
||||||
|
public static boolean isCallable(final Context context, final Intent intent) {
|
||||||
|
List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
|
||||||
|
PackageManager.MATCH_DEFAULT_ONLY);
|
||||||
|
return list.size() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue