Restore episode sharing that only includes a media URL (#5835)
This commit is contained in:
parent
1dd6636a61
commit
a01c24984e
|
@ -74,13 +74,13 @@ public class ShareDialogTest {
|
|||
|
||||
@Test
|
||||
public void testShareDialogDisplayed() throws InterruptedException {
|
||||
onView(withText(R.string.share_label_with_ellipses)).perform(click());
|
||||
onView(withText(R.string.share_label)).perform(click());
|
||||
onView(allOf(isDisplayed(), withText(R.string.share_label)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShareDialogCancelButton() {
|
||||
onView(withText(R.string.share_label_with_ellipses)).perform(scrollTo()).perform(click());
|
||||
onView(withText(R.string.share_label)).perform(scrollTo()).perform(click());
|
||||
onView(withText(R.string.cancel_label)).check(matches(isDisplayed())).perform(scrollTo()).perform(click());
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()))));
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/share_link_to_episode_radio"
|
||||
android:id="@+id/share_social_radio"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/share_dialog_link_to_episode"
|
||||
android:text="@string/share_dialog_for_social"
|
||||
android:checked="true" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/share_media_receiver_radio"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/share_dialog_media_address" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/share_media_file_radio"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -29,13 +34,14 @@
|
|||
|
||||
</RadioGroup>
|
||||
|
||||
<TextView
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/share_dialog_include_label" />
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginVertical="8dp"
|
||||
android:background="?android:attr/listDivider" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/share_start_at_timer_dialog"
|
||||
android:id="@+id/share_position_checkbox"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/share_playback_position_dialog_label" />
|
||||
|
|
|
@ -8,22 +8,11 @@
|
|||
android:title="@string/visit_website_label"
|
||||
android:visible="true"/>
|
||||
<item
|
||||
android:id="@+id/share_parent"
|
||||
android:id="@+id/share_item"
|
||||
custom:showAsAction="ifRoom"
|
||||
android:title="@string/share_label_with_ellipses"
|
||||
android:title="@string/share_label"
|
||||
android:icon="@drawable/ic_share"
|
||||
android:visible="true">
|
||||
<menu android:id="@+id/share_submenu">
|
||||
<item
|
||||
android:id="@+id/share_link_item"
|
||||
custom:showAsAction="collapseActionView"
|
||||
android:title="@string/share_website_url_label"/>
|
||||
<item
|
||||
android:id="@+id/share_download_url_item"
|
||||
custom:showAsAction="collapseActionView"
|
||||
android:title="@string/share_feed_url_label"/>
|
||||
</menu>
|
||||
</item>
|
||||
android:visible="true" />
|
||||
<item
|
||||
android:id="@+id/reconnect_local_folder"
|
||||
custom:showAsAction="collapseActionView"
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
<item
|
||||
android:id="@+id/share_item"
|
||||
android:menuCategory="container"
|
||||
android:title="@string/share_label_with_ellipses">
|
||||
android:title="@string/share_label">
|
||||
</item>
|
||||
|
||||
<item
|
||||
|
|
|
@ -49,19 +49,7 @@
|
|||
android:id="@+id/share_item"
|
||||
android:menuCategory="container"
|
||||
custom:showAsAction="never"
|
||||
android:title="@string/share_label_with_ellipses">
|
||||
<menu>
|
||||
<item
|
||||
android:id="@+id/share_link_item"
|
||||
android:title="@string/share_website_url_label">
|
||||
</item>
|
||||
<item
|
||||
android:id="@+id/share_download_url_item"
|
||||
android:title="@string/share_feed_url_label">
|
||||
</item>
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
android:title="@string/share_label" />
|
||||
|
||||
<item
|
||||
android:id="@+id/rename_item"
|
||||
|
|
|
@ -62,6 +62,6 @@
|
|||
android:id="@+id/share_item"
|
||||
android:menuCategory="container"
|
||||
custom:showAsAction="never"
|
||||
android:title="@string/share_label_with_ellipses">
|
||||
android:title="@string/share_label">
|
||||
</item>
|
||||
</menu>
|
|
@ -32,24 +32,26 @@ public class ShareUtils {
|
|||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
public static void shareFeedlink(Context context, Feed feed) {
|
||||
shareLink(context, feed.getTitle() + ": " + feed.getLink());
|
||||
}
|
||||
|
||||
public static void shareFeedDownloadLink(Context context, Feed feed) {
|
||||
shareLink(context, feed.getTitle() + ": " + feed.getDownload_url());
|
||||
}
|
||||
|
||||
private static String getItemShareText(FeedItem item) {
|
||||
return item.getFeed().getTitle() + ": " + item.getTitle();
|
||||
public static void shareFeedLink(Context context, Feed feed) {
|
||||
String text = feed.getTitle();
|
||||
if (feed.getLink() != null) {
|
||||
text += "\n" + feed.getLink();
|
||||
}
|
||||
text += "\n\n" + context.getResources().getString(R.string.share_rss_address_label)
|
||||
+ " " + feed.getDownload_url();
|
||||
shareLink(context, text);
|
||||
}
|
||||
|
||||
public static boolean hasLinkToShare(FeedItem item) {
|
||||
return FeedItemUtil.getLinkWithFallback(item) != null;
|
||||
}
|
||||
|
||||
public static void shareMediaDownloadLink(Context context, FeedMedia media) {
|
||||
shareLink(context, media.getDownload_url());
|
||||
}
|
||||
|
||||
public static void shareFeedItemLinkWithDownloadLink(Context context, FeedItem item, boolean withPosition) {
|
||||
String text = getItemShareText(item);
|
||||
String text = item.getFeed().getTitle() + ": " + item.getTitle();
|
||||
int pos = 0;
|
||||
if (item.getMedia() != null && withPosition) {
|
||||
text += "\n" + context.getResources().getString(R.string.share_starting_position_label) + ": ";
|
||||
|
|
|
@ -167,10 +167,8 @@
|
|||
<string name="rename_feed_label">Rename podcast</string>
|
||||
<string name="remove_feed_label">Remove podcast</string>
|
||||
<string name="share_label">Share</string>
|
||||
<string name="share_label_with_ellipses">Share…</string>
|
||||
<string name="share_file_label">Share File</string>
|
||||
<string name="share_website_url_label">Website address</string>
|
||||
<string name="share_feed_url_label">Podcast feed URL</string>
|
||||
<string name="share_rss_address_label">RSS address:</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_batch">Please confirm that you want to remove the selected podcasts and ALL their 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>
|
||||
|
@ -777,10 +775,10 @@
|
|||
<string name="rating_now_label" tools:ignore="UnusedResources">Sure, let\'s do this!</string>
|
||||
|
||||
<!-- Share episode dialog -->
|
||||
<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">Include playback position</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_for_social">Social message</string>
|
||||
<string name="share_dialog_media_address">Media address</string>
|
||||
<string name="share_dialog_media_file_label">Media file</string>
|
||||
<string name="share_starting_position_label">Starting from</string>
|
||||
|
||||
|
|
Loading…
Reference in New Issue