From a01c24984e90434924efb1199a1f39a99cb2f226 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Fri, 22 Apr 2022 20:11:37 +0200 Subject: Restore episode sharing that only includes a media URL (#5835) --- .../de/danoeh/antennapod/dialog/ShareDialog.java | 60 ++++++++++++---------- .../antennapod/fragment/FeedInfoFragment.java | 9 +--- .../antennapod/fragment/FeedItemlistFragment.java | 1 - .../antennapod/menuhandler/FeedMenuHandler.java | 7 +-- app/src/main/res/layout/share_episode_dialog.xml | 20 +++++--- app/src/main/res/menu/feedinfo.xml | 17 ++---- app/src/main/res/menu/feeditem_options.xml | 2 +- app/src/main/res/menu/feedlist.xml | 14 +---- app/src/main/res/menu/mediaplayer.xml | 2 +- 9 files changed, 55 insertions(+), 77 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/ShareDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/ShareDialog.java index 699e40e71..dbd4cdb59 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/ShareDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/ShareDialog.java @@ -5,15 +5,13 @@ import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.view.View; -import android.widget.CheckBox; -import android.widget.RadioButton; -import android.widget.RadioGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.DialogFragment; import de.danoeh.antennapod.R; +import de.danoeh.antennapod.databinding.ShareEpisodeDialogBinding; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.core.util.ShareUtils; @@ -21,14 +19,13 @@ 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_EPISODE_START_AT = "prefShareEpisodeStartAt"; + private static final String PREF_SHARE_EPISODE_TYPE = "prefShareEpisodeType"; private Context ctx; private FeedItem item; private SharedPreferences prefs; - private RadioButton radioMediaFile; - private RadioButton radioLinkToEpisode; - private CheckBox checkBoxStartAt; + ShareEpisodeDialogBinding viewBinding; public ShareDialog() { // Empty constructor required for DialogFragment @@ -51,31 +48,34 @@ public class ShareDialog extends DialogFragment { prefs = getActivity().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); } - View content = View.inflate(ctx, R.layout.share_episode_dialog, null); + viewBinding = ShareEpisodeDialogBinding.inflate(getLayoutInflater()); + viewBinding.shareDialogRadioGroup.setOnCheckedChangeListener((group, checkedId) -> + viewBinding.sharePositionCheckbox.setEnabled(checkedId == viewBinding.shareSocialRadio.getId())); + AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setTitle(R.string.share_label); - builder.setView(content); - - RadioGroup radioGroup = content.findViewById(R.id.share_dialog_radio_group); - radioGroup.setOnCheckedChangeListener((group, checkedId) -> - checkBoxStartAt.setEnabled(checkedId != R.id.share_media_file_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); - + builder.setView(viewBinding.getRoot()); setupOptions(); builder.setPositiveButton(R.string.share_label, (dialog, id) -> { - boolean includePlaybackPosition = checkBoxStartAt.isChecked(); - if (radioLinkToEpisode.isChecked()) { + boolean includePlaybackPosition = viewBinding.sharePositionCheckbox.isChecked(); + int position; + if (viewBinding.shareSocialRadio.isChecked()) { ShareUtils.shareFeedItemLinkWithDownloadLink(ctx, item, includePlaybackPosition); - } else if (radioMediaFile.isChecked()) { + position = 1; + } else if (viewBinding.shareMediaReceiverRadio.isChecked()) { + ShareUtils.shareMediaDownloadLink(ctx, item.getMedia()); + position = 2; + } else if (viewBinding.shareMediaFileRadio.isChecked()) { ShareUtils.shareFeedItemFile(ctx, item.getMedia()); + position = 3; } 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) + .putInt(PREF_SHARE_EPISODE_TYPE, position) + .apply(); }).setNegativeButton(R.string.cancel_label, (dialog, id) -> dialog.dismiss()); return builder.create(); @@ -83,18 +83,22 @@ public class ShareDialog extends DialogFragment { private void setupOptions() { final boolean hasMedia = item.getMedia() != null; - boolean downloaded = hasMedia && item.getMedia().isDownloaded(); - radioMediaFile.setVisibility(downloaded ? View.VISIBLE : View.GONE); + viewBinding.shareMediaFileRadio.setVisibility(downloaded ? View.VISIBLE : View.GONE); boolean hasDownloadUrl = hasMedia && item.getMedia().getDownload_url() != null; - if (!ShareUtils.hasLinkToShare(item) && !hasDownloadUrl) { - radioLinkToEpisode.setVisibility(View.GONE); + if (!hasDownloadUrl) { + viewBinding.shareMediaReceiverRadio.setVisibility(View.GONE); } - - radioMediaFile.setChecked(false); + int type = prefs.getInt(PREF_SHARE_EPISODE_TYPE, 1); + if ((type == 2 && !hasDownloadUrl) || (type == 3 && !downloaded)) { + type = 1; + } + viewBinding.shareSocialRadio.setChecked(type == 1); + viewBinding.shareMediaReceiverRadio.setChecked(type == 2); + viewBinding.shareMediaFileRadio.setChecked(type == 3); boolean switchIsChecked = prefs.getBoolean(PREF_SHARE_EPISODE_START_AT, false); - checkBoxStartAt.setChecked(switchIsChecked); + viewBinding.sharePositionCheckbox.setChecked(switchIsChecked); } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedInfoFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedInfoFragment.java index d396a3cd4..f070baebf 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedInfoFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedInfoFragment.java @@ -124,7 +124,7 @@ public class FeedInfoFragment extends Fragment implements Toolbar.OnMenuItemClic protected void doTint(Context themedContext) { toolbar.getMenu().findItem(R.id.visit_website_item) .setIcon(AppCompatResources.getDrawable(themedContext, R.drawable.ic_web)); - toolbar.getMenu().findItem(R.id.share_parent) + toolbar.getMenu().findItem(R.id.share_item) .setIcon(AppCompatResources.getDrawable(themedContext, R.drawable.ic_share)); } }; @@ -261,13 +261,8 @@ public class FeedInfoFragment extends Fragment implements Toolbar.OnMenuItemClic } private void refreshToolbarState() { - boolean shareLinkVisible = feed != null && feed.getLink() != null; - boolean downloadUrlVisible = feed != null && !feed.isLocalFeed(); - toolbar.getMenu().findItem(R.id.reconnect_local_folder).setVisible(feed != null && feed.isLocalFeed()); - toolbar.getMenu().findItem(R.id.share_download_url_item).setVisible(downloadUrlVisible); - toolbar.getMenu().findItem(R.id.share_link_item).setVisible(shareLinkVisible); - toolbar.getMenu().findItem(R.id.share_parent).setVisible(downloadUrlVisible || shareLinkVisible); + toolbar.getMenu().findItem(R.id.share_item).setVisible(feed != null && !feed.isLocalFeed()); toolbar.getMenu().findItem(R.id.visit_website_item).setVisible(feed != null && feed.getLink() != null && IntentUtils.isCallable(getContext(), new Intent(Intent.ACTION_VIEW, Uri.parse(feed.getLink())))); } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java index fbba99663..111664262 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java @@ -279,7 +279,6 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem if (feed == null) { return; } - toolbar.getMenu().findItem(R.id.share_link_item).setVisible(feed.getLink() != null); toolbar.getMenu().findItem(R.id.visit_website_item).setVisible(feed.getLink() != null); isUpdatingFeed = MenuItemUtils.updateRefreshMenuItem(toolbar.getMenu(), diff --git a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedMenuHandler.java b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedMenuHandler.java index f59be601c..3396040f9 100644 --- a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedMenuHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedMenuHandler.java @@ -42,7 +42,6 @@ public class FeedMenuHandler { menu.findItem(R.id.refresh_complete_item).setVisible(selectedFeed.isPaged()); if (StringUtils.isBlank(selectedFeed.getLink())) { menu.findItem(R.id.visit_website_item).setVisible(false); - menu.findItem(R.id.share_link_item).setVisible(false); } if (selectedFeed.isLocalFeed()) { // hide complete submenu "Share..." as both sub menu items are not visible @@ -80,10 +79,8 @@ public class FeedMenuHandler { conDialog.createNewDialog().show(); } else if (itemId == R.id.visit_website_item) { IntentUtils.openInBrowser(context, selectedFeed.getLink()); - } else if (itemId == R.id.share_link_item) { - ShareUtils.shareFeedlink(context, selectedFeed); - } else if (itemId == R.id.share_download_url_item) { - ShareUtils.shareFeedDownloadLink(context, selectedFeed); + } else if (itemId == R.id.share_item) { + ShareUtils.shareFeedLink(context, selectedFeed); } else { return false; } diff --git a/app/src/main/res/layout/share_episode_dialog.xml b/app/src/main/res/layout/share_episode_dialog.xml index d79854972..f03899671 100644 --- a/app/src/main/res/layout/share_episode_dialog.xml +++ b/app/src/main/res/layout/share_episode_dialog.xml @@ -11,16 +11,21 @@ android:id="@+id/share_dialog_radio_group" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginBottom="16dp" android:orientation="vertical"> + + - + android:layout_height="1dp" + android:layout_marginVertical="8dp" + android:background="?android:attr/listDivider" /> diff --git a/app/src/main/res/menu/feedinfo.xml b/app/src/main/res/menu/feedinfo.xml index 83ad079b4..254e1834b 100644 --- a/app/src/main/res/menu/feedinfo.xml +++ b/app/src/main/res/menu/feedinfo.xml @@ -8,22 +8,11 @@ android:title="@string/visit_website_label" android:visible="true"/> - - - - - + android:visible="true" /> + android:title="@string/share_label"> - - - - - - - - + android:title="@string/share_label" /> + android:title="@string/share_label"> \ No newline at end of file -- cgit v1.2.3