Do not display duplicate share menu

This commit is contained in:
ByteHamster 2020-10-29 21:07:29 +01:00
parent 4a4392e797
commit 96e68f69de
4 changed files with 49 additions and 65 deletions

View File

@ -18,21 +18,21 @@ import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.util.ShareUtils; import de.danoeh.antennapod.core.util.ShareUtils;
public class ShareDialog extends DialogFragment { public class ShareDialog extends DialogFragment {
private static final String ARGUMENT_FEED_ITEM = "feedItem"; private static final String ARGUMENT_FEED_ITEM = "feedItem";
private static final String PREF_NAME = "ShareDialog";
private static final String TAG = "ShareDialog";
private Context ctx;
private FeedItem item;
private static final String PREF_SHARE_DIALOG_OPTION = "prefShareDialogOption"; private static final String PREF_SHARE_DIALOG_OPTION = "prefShareDialogOption";
private static final String PREF_SHARE_EPISODE_START_AT = "prefShareEpisodeStartAt"; 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 RadioGroup radioGroup;
private RadioButton radioEpisodeWebsite; private RadioButton radioEpisodeWebsite;
private RadioButton radioMediaFileUrl;
private RadioButton radioMediaFile; private RadioButton radioMediaFile;
private CheckBox checkBoxStartAt; private CheckBox checkBoxStartAt;
private SharedPreferences prefs;
public ShareDialog() { public ShareDialog() {
// Empty constructor required for DialogFragment // Empty constructor required for DialogFragment
@ -52,7 +52,7 @@ public class ShareDialog extends DialogFragment {
if (getArguments() != null) { if (getArguments() != null) {
ctx = getActivity(); ctx = getActivity();
item = (FeedItem) getArguments().getSerializable(ARGUMENT_FEED_ITEM); item = (FeedItem) getArguments().getSerializable(ARGUMENT_FEED_ITEM);
prefs = getActivity().getSharedPreferences("ShareDialog", Context.MODE_PRIVATE); prefs = getActivity().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
} }
View content = View.inflate(ctx, R.layout.share_episode_dialog, null); View content = View.inflate(ctx, R.layout.share_episode_dialog, null);
@ -60,8 +60,12 @@ public class ShareDialog extends DialogFragment {
builder.setTitle(R.string.share_label); builder.setTitle(R.string.share_label);
builder.setView(content); builder.setView(content);
radioGroup = content.findViewById(R.id.share_dialog_radio_group); RadioGroup radioGroup = content.findViewById(R.id.share_dialog_radio_group);
radioGroup.setOnCheckedChangeListener((group, checkedId) ->
checkBoxStartAt.setEnabled(checkedId != R.id.share_media_file_radio));
radioEpisodeWebsite = content.findViewById(R.id.share_episode_website_radio); radioEpisodeWebsite = content.findViewById(R.id.share_episode_website_radio);
radioMediaFileUrl = content.findViewById(R.id.share_media_file_url_radio);
radioMediaFile = content.findViewById(R.id.share_media_file_radio); radioMediaFile = content.findViewById(R.id.share_media_file_radio);
checkBoxStartAt = content.findViewById(R.id.share_start_at_timer_dialog); checkBoxStartAt = content.findViewById(R.id.share_start_at_timer_dialog);
@ -71,10 +75,14 @@ public class ShareDialog extends DialogFragment {
boolean includePlaybackPosition = checkBoxStartAt.isChecked(); boolean includePlaybackPosition = checkBoxStartAt.isChecked();
if (radioEpisodeWebsite.isChecked()) { if (radioEpisodeWebsite.isChecked()) {
ShareUtils.shareFeedItemLink(ctx, item, includePlaybackPosition); ShareUtils.shareFeedItemLink(ctx, item, includePlaybackPosition);
prefs.edit().putString(PREF_SHARE_DIALOG_OPTION, "website").apply(); prefs.edit().putString(PREF_SHARE_DIALOG_OPTION, PREF_VALUE_WEBSITE).apply();
} else { } else if (radioMediaFileUrl.isChecked()) {
ShareUtils.shareFeedItemDownloadLink(ctx, item, includePlaybackPosition); ShareUtils.shareFeedItemDownloadLink(ctx, item, includePlaybackPosition);
prefs.edit().putString(PREF_SHARE_DIALOG_OPTION, "media").apply(); prefs.edit().putString(PREF_SHARE_DIALOG_OPTION, PREF_VALUE_MEDIA_URL).apply();
} else if (radioMediaFile.isChecked()) {
ShareUtils.shareFeedItemFile(ctx, item.getMedia());
} else {
throw new IllegalStateException("Unknown share method");
} }
prefs.edit().putBoolean(PREF_SHARE_EPISODE_START_AT, includePlaybackPosition).apply(); prefs.edit().putBoolean(PREF_SHARE_EPISODE_START_AT, includePlaybackPosition).apply();
}).setNegativeButton(R.string.cancel_label, (dialog, id) -> dialog.dismiss()); }).setNegativeButton(R.string.cancel_label, (dialog, id) -> dialog.dismiss());
@ -85,26 +93,23 @@ public class ShareDialog extends DialogFragment {
private void setupOptions() { private void setupOptions() {
final boolean hasMedia = item.getMedia() != null; final boolean hasMedia = item.getMedia() != null;
if (!ShareUtils.hasLinkToShare(item)) { boolean downloaded = hasMedia && item.getMedia().isDownloaded();
radioEpisodeWebsite.setVisibility(View.GONE); radioMediaFile.setVisibility(downloaded ? View.VISIBLE : View.GONE);
radioMediaFile.setChecked(true);
}
if (!hasMedia || item.getMedia().getDownload_url() == null) { radioEpisodeWebsite.setVisibility(ShareUtils.hasLinkToShare(item) ? View.VISIBLE : View.GONE);
radioMediaFile.setVisibility(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); radioEpisodeWebsite.setChecked(true);
radioMediaFileUrl.setChecked(false);
} else {
radioEpisodeWebsite.setChecked(false);
radioMediaFileUrl.setChecked(true);
} }
radioMediaFile.setChecked(false);
if (radioEpisodeWebsite.getVisibility() == View.VISIBLE && radioMediaFile.getVisibility() == View.VISIBLE) {
String option = prefs.getString(PREF_SHARE_DIALOG_OPTION, "website");
if (option.equals("website")) {
radioEpisodeWebsite.setChecked(true);
radioMediaFile.setChecked(false);
} else {
radioEpisodeWebsite.setChecked(false);
radioMediaFile.setChecked(true);
}
}
boolean switchIsChecked = prefs.getBoolean(PREF_SHARE_EPISODE_START_AT, false); boolean switchIsChecked = prefs.getBoolean(PREF_SHARE_EPISODE_START_AT, false);
checkBoxStartAt.setChecked(switchIsChecked); checkBoxStartAt.setChecked(switchIsChecked);

View File

@ -13,17 +13,22 @@
android:layout_marginBottom="16dp" android:layout_marginBottom="16dp"
android:orientation="vertical"> android:orientation="vertical">
<RadioButton android:id="@+id/share_episode_website_radio" <RadioButton
android:id="@+id/share_episode_website_radio"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/share_dialog_episode_website_label" android:text="@string/share_dialog_episode_website_label"
android:checked="true" android:checked="true" />
/> <RadioButton
<RadioButton android:id="@+id/share_media_file_radio" android:id="@+id/share_media_file_url_radio"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/share_dialog_media_file_label" 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> </RadioGroup>
<TextView <TextView

View File

@ -64,28 +64,5 @@
<item <item
android:id="@+id/share_item" android:id="@+id/share_item"
android:menuCategory="container" android:menuCategory="container"
android:title="@string/share_label"> android:title="@string/share_label" />
<menu>
<item
android:id="@+id/share_link_item"
android:menuCategory="container"
android:title="@string/share_link_label" />
<item
android:id="@+id/share_link_with_position_item"
android:menuCategory="container"
android:title="@string/share_link_with_position_label" />
<item
android:id="@+id/share_download_url_item"
android:menuCategory="container"
android:title="@string/share_item_url_label" />
<item
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>
</menu> </menu>

View File

@ -143,13 +143,9 @@
<string name="remove_feed_label">Remove podcast</string> <string name="remove_feed_label">Remove podcast</string>
<string name="share_label">Share</string> <string name="share_label">Share</string>
<string name="share_label_with_ellipses">Share…</string> <string name="share_label_with_ellipses">Share…</string>
<string name="share_link_label">Share Episode URL</string>
<string name="share_link_with_position_label">Share Episode URL with Position</string>
<string name="share_file_label">Share File</string> <string name="share_file_label">Share File</string>
<string name="share_website_url_label">Website address</string> <string name="share_website_url_label">Website address</string>
<string name="share_feed_url_label">Podcast feed URL</string> <string name="share_feed_url_label">Podcast feed URL</string>
<string name="share_item_url_label">Share Media File URL</string>
<string name="share_item_url_with_position_label">Share Media File URL with Position</string>
<string name="feed_delete_confirmation_msg">Please confirm that you want to delete the podcast \"%1$s\" and ALL its episodes (including downloaded episodes).</string> <string name="feed_delete_confirmation_msg">Please confirm that you want to delete the podcast \"%1$s\" and ALL its episodes (including downloaded episodes).</string>
<string name="feed_delete_confirmation_local_msg">Please confirm that you want to remove the podcast \"%1$s\". The files in the local source folder will not be deleted.</string> <string name="feed_delete_confirmation_local_msg">Please confirm that you want to remove the podcast \"%1$s\". The files in the local source folder will not be deleted.</string>
<string name="feed_remover_msg">Removing podcast</string> <string name="feed_remover_msg">Removing podcast</string>
@ -808,8 +804,9 @@
<!-- Share episode dialog --> <!-- Share episode dialog -->
<string name="share_dialog_include_label">Include:</string> <string name="share_dialog_include_label">Include:</string>
<string name="share_playback_position_dialog_label">Playback position</string> <string name="share_playback_position_dialog_label">Playback position</string>
<string name="share_dialog_media_file_label">Media file URL</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_episode_website_label">Episode webpage</string>
<string name="share_dialog_media_file_label">Media file</string>
<!-- Audio controls --> <!-- Audio controls -->
<string name="audio_controls">Audio controls</string> <string name="audio_controls">Audio controls</string>