Combine 'Episode webpage' & 'Media file address' share options (#5626)
This commit is contained in:
parent
63cd326aa0
commit
67bdb80d97
|
@ -20,18 +20,14 @@ import de.danoeh.antennapod.core.util.ShareUtils;
|
|||
public class ShareDialog extends DialogFragment {
|
||||
private static final String ARGUMENT_FEED_ITEM = "feedItem";
|
||||
private static final String PREF_NAME = "ShareDialog";
|
||||
private static final String PREF_SHARE_DIALOG_OPTION = "prefShareDialogOption";
|
||||
private static final String PREF_SHARE_EPISODE_START_AT = "prefShareEpisodeStartAt";
|
||||
private static final String PREF_VALUE_WEBSITE = "website";
|
||||
private static final String PREF_VALUE_MEDIA_URL = "media";
|
||||
|
||||
private Context ctx;
|
||||
private FeedItem item;
|
||||
private SharedPreferences prefs;
|
||||
|
||||
private RadioButton radioEpisodeWebsite;
|
||||
private RadioButton radioMediaFileUrl;
|
||||
private RadioButton radioMediaFile;
|
||||
private RadioButton radioLinkToEpisode;
|
||||
private CheckBox checkBoxStartAt;
|
||||
|
||||
public ShareDialog() {
|
||||
|
@ -64,8 +60,7 @@ public class ShareDialog extends DialogFragment {
|
|||
radioGroup.setOnCheckedChangeListener((group, checkedId) ->
|
||||
checkBoxStartAt.setEnabled(checkedId != R.id.share_media_file_radio));
|
||||
|
||||
radioEpisodeWebsite = content.findViewById(R.id.share_episode_website_radio);
|
||||
radioMediaFileUrl = content.findViewById(R.id.share_media_file_url_radio);
|
||||
radioLinkToEpisode = content.findViewById(R.id.share_link_to_episode_radio);
|
||||
radioMediaFile = content.findViewById(R.id.share_media_file_radio);
|
||||
checkBoxStartAt = content.findViewById(R.id.share_start_at_timer_dialog);
|
||||
|
||||
|
@ -73,12 +68,8 @@ public class ShareDialog extends DialogFragment {
|
|||
|
||||
builder.setPositiveButton(R.string.share_label, (dialog, id) -> {
|
||||
boolean includePlaybackPosition = checkBoxStartAt.isChecked();
|
||||
if (radioEpisodeWebsite.isChecked()) {
|
||||
ShareUtils.shareFeedItemLink(ctx, item, includePlaybackPosition);
|
||||
prefs.edit().putString(PREF_SHARE_DIALOG_OPTION, PREF_VALUE_WEBSITE).apply();
|
||||
} else if (radioMediaFileUrl.isChecked()) {
|
||||
ShareUtils.shareFeedItemDownloadLink(ctx, item, includePlaybackPosition);
|
||||
prefs.edit().putString(PREF_SHARE_DIALOG_OPTION, PREF_VALUE_MEDIA_URL).apply();
|
||||
if (radioLinkToEpisode.isChecked()) {
|
||||
ShareUtils.shareFeedItemLinkWithDownloadLink(ctx, item, includePlaybackPosition);
|
||||
} else if (radioMediaFile.isChecked()) {
|
||||
ShareUtils.shareFeedItemFile(ctx, item.getMedia());
|
||||
} else {
|
||||
|
@ -96,19 +87,11 @@ public class ShareDialog extends DialogFragment {
|
|||
boolean downloaded = hasMedia && item.getMedia().isDownloaded();
|
||||
radioMediaFile.setVisibility(downloaded ? View.VISIBLE : View.GONE);
|
||||
|
||||
radioEpisodeWebsite.setVisibility(ShareUtils.hasLinkToShare(item) ? View.VISIBLE : View.GONE);
|
||||
|
||||
boolean hasDownloadUrl = hasMedia && item.getMedia().getDownload_url() != null;
|
||||
radioMediaFileUrl.setVisibility(hasDownloadUrl ? View.VISIBLE : View.GONE);
|
||||
|
||||
String option = prefs.getString(PREF_SHARE_DIALOG_OPTION, PREF_VALUE_WEBSITE);
|
||||
if (option.equals(PREF_VALUE_WEBSITE)) {
|
||||
radioEpisodeWebsite.setChecked(true);
|
||||
radioMediaFileUrl.setChecked(false);
|
||||
} else {
|
||||
radioEpisodeWebsite.setChecked(false);
|
||||
radioMediaFileUrl.setChecked(true);
|
||||
if (!ShareUtils.hasLinkToShare(item) && !hasDownloadUrl) {
|
||||
radioLinkToEpisode.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
radioMediaFile.setChecked(false);
|
||||
|
||||
boolean switchIsChecked = prefs.getBoolean(PREF_SHARE_EPISODE_START_AT, false);
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:padding="16dp">
|
||||
|
||||
|
@ -14,27 +15,24 @@
|
|||
android:orientation="vertical">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/share_episode_website_radio"
|
||||
android:id="@+id/share_link_to_episode_radio"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/share_dialog_episode_website_label"
|
||||
android:text="@string/share_dialog_link_to_episode"
|
||||
android:checked="true" />
|
||||
<RadioButton
|
||||
android:id="@+id/share_media_file_url_radio"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/share_dialog_media_file_url_label" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/share_media_file_radio"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/share_dialog_media_file_label" />
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/share_dialog_include_label"/>
|
||||
android:text="@string/share_dialog_include_label" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/share_start_at_timer_dialog"
|
||||
|
@ -42,4 +40,4 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:text="@string/share_playback_position_dialog_label" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -43,14 +43,6 @@ public class ShareUtils {
|
|||
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();
|
||||
}
|
||||
|
@ -59,21 +51,26 @@ public class ShareUtils {
|
|||
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) + "]";
|
||||
public static void shareFeedItemLinkWithDownloadLink(Context context, FeedItem item, boolean withPosition) {
|
||||
String text = getItemShareText(item);
|
||||
int pos = 0;
|
||||
if (item.getMedia() != null && withPosition) {
|
||||
text += "\n" + context.getResources().getString(R.string.share_starting_position_label) + ": ";
|
||||
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) + "]";
|
||||
if (hasLinkToShare(item)) {
|
||||
text += "\n\n" + context.getResources().getString(R.string.share_dialog_episode_website_label) + ": ";
|
||||
text += FeedItemUtil.getLinkWithFallback(item);
|
||||
}
|
||||
|
||||
if (item.getMedia() != null && item.getMedia().getDownload_url() != null) {
|
||||
text += "\n\n" + context.getResources().getString(R.string.share_dialog_media_file_label) + ": ";
|
||||
text += item.getMedia().getDownload_url();
|
||||
if (withPosition) {
|
||||
text += "#t=" + pos / 1000;
|
||||
}
|
||||
}
|
||||
shareLink(context, text);
|
||||
}
|
||||
|
|
|
@ -779,9 +779,10 @@
|
|||
<!-- Share episode dialog -->
|
||||
<string name="share_dialog_include_label">Include:</string>
|
||||
<string name="share_playback_position_dialog_label">Playback position</string>
|
||||
<string name="share_dialog_media_file_url_label">Media file address</string>
|
||||
<string name="share_dialog_episode_website_label">Episode webpage</string>
|
||||
<string name="share_dialog_link_to_episode">Link to episode</string>
|
||||
<string name="share_dialog_media_file_label">Media file</string>
|
||||
<string name="share_starting_position_label">Starting from</string>
|
||||
|
||||
<!-- Audio controls -->
|
||||
<string name="audio_controls">Audio controls</string>
|
||||
|
|
Loading…
Reference in New Issue