diff --git a/app/src/main/java/de/danoeh/antennapod/ui/share/ShareDialog.java b/app/src/main/java/de/danoeh/antennapod/ui/share/ShareDialog.java
index 963c0b14b..610732d7a 100644
--- a/app/src/main/java/de/danoeh/antennapod/ui/share/ShareDialog.java
+++ b/app/src/main/java/de/danoeh/antennapod/ui/share/ShareDialog.java
@@ -16,13 +16,6 @@ public class ShareDialog extends BottomSheetDialogFragment {
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 ShareEpisodeDialogBinding viewBinding;
public ShareDialog() {
// Empty constructor required for DialogFragment
@@ -40,60 +33,46 @@ public class ShareDialog extends BottomSheetDialogFragment {
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
- if (getArguments() != null) {
- ctx = getActivity();
- item = (FeedItem) getArguments().getSerializable(ARGUMENT_FEED_ITEM);
- prefs = getActivity().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
+ if (getArguments() == null) {
+ return null;
+ }
+ FeedItem item = (FeedItem) getArguments().getSerializable(ARGUMENT_FEED_ITEM);
+ ShareEpisodeDialogBinding viewBinding = ShareEpisodeDialogBinding.inflate(inflater);
+
+ if (item.getMedia() != null && item.getMedia().isDownloaded()) {
+ viewBinding.mediaFileCardCard.setOnClickListener(v -> {
+ ShareUtils.shareFeedItemFile(getContext(), item.getMedia());
+ dismiss();
+ });
+ } else {
+ viewBinding.mediaFileCardCard.setVisibility(View.GONE);
}
- viewBinding = ShareEpisodeDialogBinding.inflate(inflater);
- viewBinding.shareDialogRadioGroup.setOnCheckedChangeListener((group, checkedId) ->
- viewBinding.sharePositionCheckbox.setEnabled(checkedId == viewBinding.shareSocialRadio.getId()));
+ if (item.getMedia() != null && item.getMedia().getDownloadUrl() != null) {
+ viewBinding.mediaAddressText.setText(item.getMedia().getDownloadUrl());
+ viewBinding.mediaAddressCard.setOnClickListener(v -> {
+ ShareUtils.shareLink(getContext(), item.getMedia().getDownloadUrl());
+ dismiss();
+ });
+ } else {
+ viewBinding.mediaAddressCard.setVisibility(View.GONE);
+ }
- setupOptions();
-
- viewBinding.shareButton.setOnClickListener((v) -> {
- boolean includePlaybackPosition = viewBinding.sharePositionCheckbox.isChecked();
- int position;
- if (viewBinding.shareSocialRadio.isChecked()) {
- ShareUtils.shareFeedItemLinkWithDownloadLink(ctx, item, includePlaybackPosition);
- 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)
- .putInt(PREF_SHARE_EPISODE_TYPE, position)
- .apply();
+ SharedPreferences prefs = getContext().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
+ viewBinding.sharePositionCheckbox.setChecked(prefs.getBoolean(PREF_SHARE_EPISODE_START_AT, false));
+ viewBinding.socialMessageText.setText(ShareUtils.getSocialFeedItemShareText(
+ getContext(), item, viewBinding.sharePositionCheckbox.isChecked(), true));
+ viewBinding.sharePositionCheckbox.setOnCheckedChangeListener((buttonView, isChecked) -> {
+ prefs.edit().putBoolean(PREF_SHARE_EPISODE_START_AT, isChecked).apply();
+ viewBinding.socialMessageText.setText(
+ ShareUtils.getSocialFeedItemShareText(getContext(), item, isChecked, true));
+ });
+ viewBinding.socialMessageCard.setOnClickListener(v -> {
+ ShareUtils.shareLink(getContext(), ShareUtils.getSocialFeedItemShareText(
+ getContext(), item, viewBinding.sharePositionCheckbox.isChecked(), false));
dismiss();
});
+
return viewBinding.getRoot();
}
-
- private void setupOptions() {
- final boolean hasMedia = item.getMedia() != null;
- boolean downloaded = hasMedia && item.getMedia().isDownloaded();
- viewBinding.shareMediaFileRadio.setVisibility(downloaded ? View.VISIBLE : View.GONE);
-
- boolean hasDownloadUrl = hasMedia && item.getMedia().getDownloadUrl() != null;
- if (!hasDownloadUrl) {
- viewBinding.shareMediaReceiverRadio.setVisibility(View.GONE);
- }
- 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);
- viewBinding.sharePositionCheckbox.setChecked(switchIsChecked);
- }
}
diff --git a/app/src/main/java/de/danoeh/antennapod/ui/share/ShareUtils.java b/app/src/main/java/de/danoeh/antennapod/ui/share/ShareUtils.java
index 1a2614227..e149a49a9 100644
--- a/app/src/main/java/de/danoeh/antennapod/ui/share/ShareUtils.java
+++ b/app/src/main/java/de/danoeh/antennapod/ui/share/ShareUtils.java
@@ -21,6 +21,7 @@ import de.danoeh.antennapod.model.feed.FeedMedia;
/** Utility methods for sharing data */
public class ShareUtils {
private static final String TAG = "ShareUtils";
+ private static final int ABBREVIATE_MAX_LENGTH = 50;
private ShareUtils() {
}
@@ -47,32 +48,48 @@ public class ShareUtils {
return item.getLinkWithFallback() != null;
}
- public static void shareMediaDownloadLink(Context context, FeedMedia media) {
- shareLink(context, media.getDownloadUrl());
- }
+ public static String getSocialFeedItemShareText(Context context, FeedItem item,
+ boolean withPosition, boolean abbreviate) {
+ String text = item.getFeed().getTitle() + ": ";
+
+ if (abbreviate && item.getTitle().length() > ABBREVIATE_MAX_LENGTH) {
+ text += item.getTitle().substring(0, ABBREVIATE_MAX_LENGTH) + "…";
+ } else {
+ text += item.getTitle();
+ }
- public static void shareFeedItemLinkWithDownloadLink(Context context, FeedItem item, boolean withPosition) {
- 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) + ": ";
- pos = item.getMedia().getPosition();
- text += Converter.getDurationStringLong(pos);
+ text += Converter.getDurationStringLong(item.getMedia().getPosition());
}
if (hasLinkToShare(item)) {
- text += "\n\n" + context.getResources().getString(R.string.share_dialog_episode_website_label) + ": ";
- text += item.getLinkWithFallback();
+ if (!abbreviate) {
+ text += "\n";
+ }
+ text += "\n" + context.getResources().getString(R.string.share_dialog_episode_website_label) + ": ";
+ if (abbreviate && item.getLinkWithFallback().length() > ABBREVIATE_MAX_LENGTH) {
+ text += item.getLinkWithFallback().substring(0, ABBREVIATE_MAX_LENGTH) + "…";
+ } else {
+ text += item.getLinkWithFallback();
+ }
}
if (item.getMedia() != null && item.getMedia().getDownloadUrl() != null) {
- text += "\n\n" + context.getResources().getString(R.string.share_dialog_media_file_label) + ": ";
- text += item.getMedia().getDownloadUrl();
+ if (!abbreviate) {
+ text += "\n";
+ }
+ text += "\n" + context.getResources().getString(R.string.share_dialog_media_file_label) + ": ";
+ if (abbreviate && item.getMedia().getDownloadUrl().length() > ABBREVIATE_MAX_LENGTH) {
+ text += item.getMedia().getDownloadUrl().substring(0, ABBREVIATE_MAX_LENGTH) + "…";
+ } else {
+ text += item.getMedia().getDownloadUrl();
+ }
if (withPosition) {
- text += "#t=" + pos / 1000;
+ text += "#t=" + item.getMedia().getPosition() / 1000;
}
}
- shareLink(context, text);
+ return text;
}
public static void shareFeedItemFile(Context context, FeedMedia media) {
diff --git a/app/src/main/res/layout/share_episode_dialog.xml b/app/src/main/res/layout/share_episode_dialog.xml
index 7be941599..02d17a8f8 100644
--- a/app/src/main/res/layout/share_episode_dialog.xml
+++ b/app/src/main/res/layout/share_episode_dialog.xml
@@ -1,63 +1,172 @@
+ android:layout_marginBottom="16dp"
+ style="@style/TextAppearance.Material3.TitleLarge" />
-
+ android:elevation="1dp"
+ android:foreground="?attr/selectableItemBackground"
+ android:layout_marginBottom="16dp"
+ app:cardBackgroundColor="?attr/colorSurfaceContainer"
+ app:cardCornerRadius="4dp">
-
+ android:orientation="horizontal">
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ android:elevation="1dp"
+ android:foreground="?attr/selectableItemBackground"
+ android:layout_marginBottom="16dp"
+ app:cardBackgroundColor="?attr/colorSurfaceContainer"
+ app:cardCornerRadius="4dp">
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ android:elevation="1dp"
+ android:foreground="?attr/selectableItemBackground"
+ app:cardBackgroundColor="?attr/colorSurfaceContainer"
+ app:cardCornerRadius="4dp">
-
+
+
+
+
+
+
+
+
+
+
+
+
+