From 919e978f8d3a76a145e12412b581897544ea2c29 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Tue, 10 Jul 2012 17:40:35 +0200 Subject: [PATCH] Implemented sharing menus --- res/menu/feeditem.xml | 3 +- res/menu/feedlist.xml | 2 ++ res/values/strings.xml | 2 ++ .../podfetcher/util/FeedItemMenuHandler.java | 5 +++ src/de/podfetcher/util/FeedMenuHandler.java | 9 +++++ src/de/podfetcher/util/ShareUtils.java | 34 +++++++++++++++++++ 6 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/de/podfetcher/util/ShareUtils.java diff --git a/res/menu/feeditem.xml b/res/menu/feeditem.xml index 20509ac39..9b80593a5 100644 --- a/res/menu/feeditem.xml +++ b/res/menu/feeditem.xml @@ -9,7 +9,8 @@ - + + \ No newline at end of file diff --git a/res/menu/feedlist.xml b/res/menu/feedlist.xml index 16a7f9dd1..8e9a84011 100644 --- a/res/menu/feedlist.xml +++ b/res/menu/feedlist.xml @@ -3,6 +3,8 @@ + + diff --git a/res/values/strings.xml b/res/values/strings.xml index fa33ea012..60d066aff 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -94,5 +94,7 @@ All downloads completed Refresh No external storage is available. Please make sure that external storage is mounted so that the app can work properly. + Share link... + Share source link... \ No newline at end of file diff --git a/src/de/podfetcher/util/FeedItemMenuHandler.java b/src/de/podfetcher/util/FeedItemMenuHandler.java index 59d46de0f..83c2fcb3e 100644 --- a/src/de/podfetcher/util/FeedItemMenuHandler.java +++ b/src/de/podfetcher/util/FeedItemMenuHandler.java @@ -38,6 +38,8 @@ public class FeedItemMenuHandler { } else { menu.findItem(R.id.add_to_queue_item).setVisible(true); } + + menu.findItem(R.id.share_link_item).setVisible(selectedItem.getLink() != null); } if (selectedItem.isRead()) { @@ -100,6 +102,9 @@ public class FeedItemMenuHandler { Uri supportUri = Uri.parse(selectedItem.getPaymentLink()); context.startActivity(new Intent(Intent.ACTION_VIEW, supportUri)); break; + case R.id.share_link_item: + ShareUtils.shareFeedItemLink(context, selectedItem); + break; default: return false; } diff --git a/src/de/podfetcher/util/FeedMenuHandler.java b/src/de/podfetcher/util/FeedMenuHandler.java index 10fdcb2ab..1f0667be5 100644 --- a/src/de/podfetcher/util/FeedMenuHandler.java +++ b/src/de/podfetcher/util/FeedMenuHandler.java @@ -40,6 +40,9 @@ public class FeedMenuHandler { } else { refresh.setVisible(true); } + + menu.findItem(R.id.share_link_item).setVisible(selectedFeed.getLink() != null); + return true; } @@ -68,6 +71,12 @@ public class FeedMenuHandler { Uri supportUri = Uri.parse(selectedFeed.getPaymentLink()); context.startActivity(new Intent(Intent.ACTION_VIEW, supportUri)); break; + case R.id.share_link_item: + ShareUtils.shareFeedlink(context, selectedFeed); + break; + case R.id.share_source_item: + ShareUtils.shareFeedDownloadLink(context, selectedFeed); + break; default: return false; } diff --git a/src/de/podfetcher/util/ShareUtils.java b/src/de/podfetcher/util/ShareUtils.java new file mode 100644 index 000000000..f9230b311 --- /dev/null +++ b/src/de/podfetcher/util/ShareUtils.java @@ -0,0 +1,34 @@ +package de.podfetcher.util; + +import de.podfetcher.feed.Feed; +import de.podfetcher.feed.FeedItem; +import android.content.Context; +import android.content.Intent; + +/** Utility methods for sharing data */ +public class ShareUtils { + private static final String TAG = "ShareUtils"; + + private ShareUtils() {} + + private static void shareLink(Context context, String link) { + Intent i = new Intent(Intent.ACTION_SEND); + i.setType("text/plain"); + i.putExtra(Intent.EXTRA_SUBJECT, "Sharing URL"); + i.putExtra(Intent.EXTRA_TEXT, link); + context.startActivity(Intent.createChooser(i, "Share URL")); + } + + public static void shareFeedItemLink(Context context, FeedItem item) { + shareLink(context, item.getLink()); + } + + public static void shareFeedDownloadLink(Context context, Feed feed) { + shareLink(context, feed.getDownload_url()); + } + + public static void shareFeedlink(Context context, Feed feed) { + shareLink(context, feed.getLink()); + } + +}