Merge pull request #2305 from ByteHamster/share-file

Allow sharing feed file, as suggested in #2236
This commit is contained in:
H. Lehmann 2017-06-04 14:38:20 +02:00 committed by GitHub
commit 341928b3ba
9 changed files with 48 additions and 6 deletions

View File

@ -309,10 +309,9 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
return false;
}
Playable media = controller.getMedia();
boolean isFeedMedia = media != null && (media instanceof FeedMedia);
menu.findItem(R.id.support_item).setVisible(
media != null && media.getPaymentLink() != null &&
(media instanceof FeedMedia) &&
menu.findItem(R.id.support_item).setVisible(isFeedMedia && media.getPaymentLink() != null &&
((FeedMedia) media).getItem() != null &&
((FeedMedia) media).getItem().getFlattrStatus().flattrable()
);
@ -320,20 +319,21 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
boolean hasWebsiteLink = media != null && media.getWebsiteLink() != null;
menu.findItem(R.id.visit_website_item).setVisible(hasWebsiteLink);
boolean isItemAndHasLink = media != null && (media instanceof FeedMedia) &&
boolean isItemAndHasLink = isFeedMedia &&
((FeedMedia) media).getItem() != null && ((FeedMedia) media).getItem().getLink() != null;
menu.findItem(R.id.share_link_item).setVisible(isItemAndHasLink);
menu.findItem(R.id.share_link_with_position_item).setVisible(isItemAndHasLink);
boolean isItemHasDownloadLink = media != null && (media instanceof FeedMedia) && ((FeedMedia) media).getDownload_url() != null;
boolean isItemHasDownloadLink = isFeedMedia && ((FeedMedia) media).getDownload_url() != null;
menu.findItem(R.id.share_download_url_item).setVisible(isItemHasDownloadLink);
menu.findItem(R.id.share_download_url_with_position_item).setVisible(isItemHasDownloadLink);
menu.findItem(R.id.share_file).setVisible(isFeedMedia && ((FeedMedia) media).fileExists());
menu.findItem(R.id.share_item).setVisible(hasWebsiteLink || isItemAndHasLink || isItemHasDownloadLink);
menu.findItem(R.id.add_to_favorites_item).setVisible(false);
menu.findItem(R.id.remove_from_favorites_item).setVisible(false);
if(media != null && media instanceof FeedMedia) {
if (isFeedMedia) {
menu.findItem(R.id.add_to_favorites_item).setVisible(!isFavorite);
menu.findItem(R.id.remove_from_favorites_item).setVisible(isFavorite);
}
@ -574,6 +574,11 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
ShareUtils.shareFeedItemDownloadLink(this, ((FeedMedia) media).getItem(), true);
}
break;
case R.id.share_file:
if (media instanceof FeedMedia) {
ShareUtils.shareFeedItemFile(this, ((FeedMedia) media));
}
break;
default:
return false;
}

View File

@ -101,6 +101,8 @@ public class FeedItemMenuHandler {
mi.setItemVisibility(R.id.share_download_url_with_position_item, false);
}
mi.setItemVisibility(R.id.share_file, hasMedia && selectedItem.getMedia().fileExists());
if (selectedItem.isPlayed()) {
mi.setItemVisibility(R.id.mark_read_item, false);
} else {
@ -239,6 +241,9 @@ public class FeedItemMenuHandler {
case R.id.share_download_url_with_position_item:
ShareUtils.shareFeedItemDownloadLink(context, selectedItem, true);
break;
case R.id.share_file:
ShareUtils.shareFeedItemFile(context, selectedItem.getMedia());
break;
default:
Log.d(TAG, "Unknown menuItemId: " + menuItemId);
return false;

View File

@ -71,6 +71,10 @@
android:id="@+id/share_download_url_with_position_item"
android:menuCategory="container"
android:title="@string/share_item_url_with_position_label" />
<item
android:id="@+id/share_file"
android:menuCategory="container"
android:title="@string/share_file_label" />
</menu>
</item>

View File

@ -84,6 +84,10 @@
android:id="@+id/share_download_url_with_position_item"
android:menuCategory="container"
android:title="@string/share_item_url_with_position_label" />
<item
android:id="@+id/share_file"
android:menuCategory="container"
android:title="@string/share_file_label" />
</menu>
</item>

View File

@ -73,6 +73,10 @@
android:id="@+id/share_download_url_with_position_item"
android:menuCategory="container"
android:title="@string/share_item_url_with_position_label" />
<item
android:id="@+id/share_file"
android:menuCategory="container"
android:title="@string/share_file_label" />
</menu>
</item>

View File

@ -64,6 +64,10 @@
android:id="@+id/share_download_url_with_position_item"
android:menuCategory="container"
android:title="@string/share_item_url_with_position_label" />
<item
android:id="@+id/share_file"
android:menuCategory="container"
android:title="@string/share_file_label" />
</menu>
</item>
<item

View File

@ -74,6 +74,10 @@
android:id="@+id/share_download_url_with_position_item"
android:menuCategory="container"
android:title="@string/share_item_url_with_position_label" />
<item
android:id="@+id/share_file"
android:menuCategory="container"
android:title="@string/share_file_label" />
</menu>
</item>
<item

View File

@ -3,9 +3,13 @@ package de.danoeh.antennapod.core.util;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.FeedMedia;
import java.io.File;
/** Utility methods for sharing data */
public class ShareUtils {
@ -58,4 +62,11 @@ public class ShareUtils {
shareLink(context, text);
}
public static void shareFeedItemFile(Context context, FeedMedia media) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType(media.getMime_type());
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(media.getLocalMediaUrl())));
i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(Intent.createChooser(i, context.getString(R.string.share_file_label)));
}
}

View File

@ -126,6 +126,7 @@
<string name="remove_feed_label">Remove Podcast</string>
<string name="share_label">Share&#8230;</string>
<string name="share_link_label">Share Link</string>
<string name="share_file_label">Share File</string>
<string name="share_link_with_position_label">Share Link with Position</string>
<string name="share_feed_url_label">Share Feed URL</string>
<string name="share_item_url_label">Share Episode File URL</string>