Merge pull request #4721 from tonytamsf/share-by-timecode
share by timecode
This commit is contained in:
commit
d20557c1b0
|
@ -19,74 +19,77 @@ import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
|
|
||||||
/** Utility methods for sharing data */
|
/** Utility methods for sharing data */
|
||||||
public class ShareUtils {
|
public class ShareUtils {
|
||||||
private static final String TAG = "ShareUtils";
|
private static final String TAG = "ShareUtils";
|
||||||
|
|
||||||
private ShareUtils() {}
|
|
||||||
|
|
||||||
public static void shareLink(Context context, String text) {
|
|
||||||
Intent i = new Intent(Intent.ACTION_SEND);
|
|
||||||
i.setType("text/plain");
|
|
||||||
i.putExtra(Intent.EXTRA_TEXT, text);
|
|
||||||
context.startActivity(Intent.createChooser(i, context.getString(R.string.share_url_label)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void shareFeedlink(Context context, Feed feed) {
|
private ShareUtils() {
|
||||||
shareLink(context, feed.getTitle() + ": " + feed.getLink());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void shareFeedDownloadLink(Context context, Feed feed) {
|
|
||||||
shareLink(context, feed.getTitle() + ": " + feed.getDownload_url());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void shareFeedItemLink(Context context, FeedItem item) {
|
|
||||||
shareFeedItemLink(context, item, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void shareFeedItemDownloadLink(Context context, FeedItem item) {
|
|
||||||
shareFeedItemDownloadLink(context, item, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getItemShareText(FeedItem item) {
|
|
||||||
return item.getFeed().getTitle() + ": " + item.getTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasLinkToShare(FeedItem item) {
|
|
||||||
return FeedItemUtil.getLinkWithFallback(item) != null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void shareFeedItemLink(Context context, FeedItem item, boolean withPosition) {
|
public static void shareLink(Context context, String text) {
|
||||||
String text = getItemShareText(item) + " " + FeedItemUtil.getLinkWithFallback(item);
|
Intent i = new Intent(Intent.ACTION_SEND);
|
||||||
if(withPosition) {
|
i.setType("text/plain");
|
||||||
int pos = item.getMedia().getPosition();
|
i.putExtra(Intent.EXTRA_TEXT, text);
|
||||||
text += " [" + Converter.getDurationStringLong(pos) + "]";
|
context.startActivity(Intent.createChooser(i, context.getString(R.string.share_url_label)));
|
||||||
}
|
}
|
||||||
shareLink(context, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void shareFeedItemDownloadLink(Context context, FeedItem item, boolean withPosition) {
|
public static void shareFeedlink(Context context, Feed feed) {
|
||||||
String text = getItemShareText(item) + " " + item.getMedia().getDownload_url();
|
shareLink(context, feed.getTitle() + ": " + feed.getLink());
|
||||||
if(withPosition) {
|
}
|
||||||
int pos = item.getMedia().getPosition();
|
|
||||||
text += " [" + Converter.getDurationStringLong(pos) + "]";
|
|
||||||
}
|
|
||||||
shareLink(context, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void shareFeedItemFile(Context context, FeedMedia media) {
|
public static void shareFeedDownloadLink(Context context, Feed feed) {
|
||||||
Intent i = new Intent(Intent.ACTION_SEND);
|
shareLink(context, feed.getTitle() + ": " + feed.getDownload_url());
|
||||||
i.setType(media.getMime_type());
|
}
|
||||||
Uri fileUri = FileProvider.getUriForFile(context, context.getString(R.string.provider_authority),
|
|
||||||
new File(media.getLocalMediaUrl()));
|
public static void shareFeedItemLink(Context context, FeedItem item) {
|
||||||
i.putExtra(Intent.EXTRA_STREAM, fileUri);
|
shareFeedItemLink(context, item, false);
|
||||||
i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
}
|
||||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
|
|
||||||
List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY);
|
public static void shareFeedItemDownloadLink(Context context, FeedItem item) {
|
||||||
for (ResolveInfo resolveInfo : resInfoList) {
|
shareFeedItemDownloadLink(context, item, false);
|
||||||
String packageName = resolveInfo.activityInfo.packageName;
|
}
|
||||||
context.grantUriPermission(packageName, fileUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
||||||
}
|
private static String getItemShareText(FeedItem item) {
|
||||||
}
|
return item.getFeed().getTitle() + ": " + item.getTitle();
|
||||||
context.startActivity(Intent.createChooser(i, context.getString(R.string.share_file_label)));
|
}
|
||||||
Log.e(TAG, "shareFeedItemFile called");
|
|
||||||
}
|
public static boolean hasLinkToShare(FeedItem item) {
|
||||||
|
return FeedItemUtil.getLinkWithFallback(item) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void shareFeedItemLink(Context context, FeedItem item, boolean withPosition) {
|
||||||
|
String text = getItemShareText(item) + " " + FeedItemUtil.getLinkWithFallback(item);
|
||||||
|
if (withPosition) {
|
||||||
|
int pos = item.getMedia().getPosition();
|
||||||
|
text += " [" + Converter.getDurationStringLong(pos) + "]";
|
||||||
|
}
|
||||||
|
shareLink(context, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void shareFeedItemDownloadLink(Context context, FeedItem item, boolean withPosition) {
|
||||||
|
String text = getItemShareText(item) + " " + item.getMedia().getDownload_url();
|
||||||
|
if (withPosition) {
|
||||||
|
int pos = item.getMedia().getPosition();
|
||||||
|
text += "#t=" + pos / 1000;
|
||||||
|
text += " [" + Converter.getDurationStringLong(pos) + "]";
|
||||||
|
}
|
||||||
|
shareLink(context, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void shareFeedItemFile(Context context, FeedMedia media) {
|
||||||
|
Intent i = new Intent(Intent.ACTION_SEND);
|
||||||
|
i.setType(media.getMime_type());
|
||||||
|
Uri fileUri = FileProvider.getUriForFile(context, context.getString(R.string.provider_authority),
|
||||||
|
new File(media.getLocalMediaUrl()));
|
||||||
|
i.putExtra(Intent.EXTRA_STREAM, fileUri);
|
||||||
|
i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
|
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
|
||||||
|
List<ResolveInfo> resInfoList = context.getPackageManager()
|
||||||
|
.queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY);
|
||||||
|
for (ResolveInfo resolveInfo : resInfoList) {
|
||||||
|
String packageName = resolveInfo.activityInfo.packageName;
|
||||||
|
context.grantUriPermission(packageName, fileUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
context.startActivity(Intent.createChooser(i, context.getString(R.string.share_file_label)));
|
||||||
|
Log.e(TAG, "shareFeedItemFile called");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue