summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorByteHamster <ByteHamster@users.noreply.github.com>2024-09-26 22:48:11 +0200
committerGitHub <noreply@github.com>2024-09-26 22:48:11 +0200
commit7309f8e8b285e492ce809cf506962a7ff76503fc (patch)
treec72b849850b0ed1300f6af854fea8b0010c033bb
parentf6bc8d2c515c9ca4b690a5cb9c7901e41b6739a3 (diff)
downloadAntennaPod-7309f8e8b285e492ce809cf506962a7ff76503fc.zip
Show preview on share dialog (#7425)
-rw-r--r--app/src/main/java/de/danoeh/antennapod/ui/share/ShareDialog.java89
-rw-r--r--app/src/main/java/de/danoeh/antennapod/ui/share/ShareUtils.java45
-rw-r--r--app/src/main/res/layout/share_episode_dialog.xml173
3 files changed, 206 insertions, 101 deletions
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);
- viewBinding = ShareEpisodeDialogBinding.inflate(inflater);
- viewBinding.shareDialogRadioGroup.setOnCheckedChangeListener((group, checkedId) ->
- viewBinding.sharePositionCheckbox.setEnabled(checkedId == viewBinding.shareSocialRadio.getId()));
+ if (item.getMedia() != null && item.getMedia().isDownloaded()) {
+ viewBinding.mediaFileCardCard.setOnClickListener(v -> {
+ ShareUtils.shareFeedItemFile(getContext(), item.getMedia());
+ dismiss();
+ });
+ } else {
+ viewBinding.mediaFileCardCard.setVisibility(View.GONE);
+ }
- setupOptions();
+ 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);
+ }
- 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);
+ return viewBinding.getRoot();
}
}
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 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
+ android:clipToPadding="false"
android:padding="16dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/share_label"
- android:layout_marginBottom="8dp"
- style="@style/AntennaPod.TextView.Heading" />
+ android:layout_marginBottom="16dp"
+ style="@style/TextAppearance.Material3.TitleLarge" />
- <RadioGroup
- android:id="@+id/share_dialog_radio_group"
+ <androidx.cardview.widget.CardView
+ android:id="@+id/socialMessageCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:orientation="vertical">
+ android:elevation="1dp"
+ android:foreground="?attr/selectableItemBackground"
+ android:layout_marginBottom="16dp"
+ app:cardBackgroundColor="?attr/colorSurfaceContainer"
+ app:cardCornerRadius="4dp">
- <RadioButton
- android:id="@+id/share_social_radio"
+ <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:text="@string/share_dialog_for_social"
- android:checked="true" />
+ android:orientation="horizontal">
- <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" />
+ <LinearLayout
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:layout_weight="1">
- <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" />
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingStart="16dp"
+ android:paddingEnd="0dp"
+ android:paddingTop="16dp"
+ android:orientation="vertical">
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/share_dialog_for_social"
+ style="@style/TextAppearance.Material3.TitleMedium" />
+
+ <TextView
+ android:id="@+id/socialMessageText"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/share_dialog_for_social"
+ style="@style/TextAppearance.Material3.BodyMedium" />
+
+ </LinearLayout>
+
+ <CheckBox
+ android:id="@+id/share_position_checkbox"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginHorizontal="8dp"
+ android:text="@string/share_playback_position_dialog_label" />
- </RadioGroup>
+ </LinearLayout>
- <com.google.android.material.divider.MaterialDivider
+ <ImageView
+ android:layout_width="24dp"
+ android:layout_height="24dp"
+ android:layout_margin="16dp"
+ android:layout_gravity="center_vertical"
+ app:srcCompat="@drawable/ic_share" />
+
+ </LinearLayout>
+
+ </androidx.cardview.widget.CardView>
+
+ <androidx.cardview.widget.CardView
+ android:id="@+id/mediaAddressCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_marginVertical="8dp" />
+ android:elevation="1dp"
+ android:foreground="?attr/selectableItemBackground"
+ android:layout_marginBottom="16dp"
+ app:cardBackgroundColor="?attr/colorSurfaceContainer"
+ app:cardCornerRadius="4dp">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:padding="16dp"
+ android:orientation="horizontal">
+
+ <LinearLayout
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:layout_weight="1">
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/share_dialog_media_address"
+ style="@style/TextAppearance.Material3.TitleMedium" />
- <CheckBox
- android:id="@+id/share_position_checkbox"
+ <TextView
+ android:id="@+id/mediaAddressText"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginEnd="16dp"
+ android:maxLines="2"
+ android:ellipsize="end"
+ android:text="@string/share_dialog_media_address"
+ style="@style/TextAppearance.Material3.BodyMedium" />
+
+ </LinearLayout>
+
+ <ImageView
+ android:layout_width="24dp"
+ android:layout_height="24dp"
+ android:layout_gravity="center_vertical"
+ app:srcCompat="@drawable/ic_share" />
+
+ </LinearLayout>
+
+ </androidx.cardview.widget.CardView>
+
+ <androidx.cardview.widget.CardView
+ android:id="@+id/mediaFileCardCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:text="@string/share_playback_position_dialog_label" />
+ android:elevation="1dp"
+ android:foreground="?attr/selectableItemBackground"
+ app:cardBackgroundColor="?attr/colorSurfaceContainer"
+ app:cardCornerRadius="4dp">
- <Button
- android:id="@+id/shareButton"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="end"
- android:text="@string/share_label"
- style="@style/Widget.MaterialComponents.Button.TextButton" />
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:padding="16dp"
+ android:orientation="horizontal">
+
+ <LinearLayout
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:layout_weight="1">
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/share_dialog_media_file_label"
+ style="@style/TextAppearance.Material3.TitleMedium" />
+
+ </LinearLayout>
+
+ <ImageView
+ android:layout_width="24dp"
+ android:layout_height="24dp"
+ android:layout_gravity="center_vertical"
+ app:srcCompat="@drawable/ic_share" />
+
+ </LinearLayout>
+
+ </androidx.cardview.widget.CardView>
</LinearLayout>