Show preview on share dialog (#7425)
This commit is contained in:
parent
f6bc8d2c51
commit
7309f8e8b2
|
@ -16,13 +16,6 @@ public class ShareDialog extends BottomSheetDialogFragment {
|
||||||
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 PREF_NAME = "ShareDialog";
|
||||||
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_SHARE_EPISODE_TYPE = "prefShareEpisodeType";
|
|
||||||
|
|
||||||
private Context ctx;
|
|
||||||
private FeedItem item;
|
|
||||||
private SharedPreferences prefs;
|
|
||||||
|
|
||||||
private ShareEpisodeDialogBinding viewBinding;
|
|
||||||
|
|
||||||
public ShareDialog() {
|
public ShareDialog() {
|
||||||
// Empty constructor required for DialogFragment
|
// Empty constructor required for DialogFragment
|
||||||
|
@ -40,60 +33,46 @@ public class ShareDialog extends BottomSheetDialogFragment {
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||||
@Nullable Bundle savedInstanceState) {
|
@Nullable Bundle savedInstanceState) {
|
||||||
if (getArguments() != null) {
|
if (getArguments() == null) {
|
||||||
ctx = getActivity();
|
return null;
|
||||||
item = (FeedItem) getArguments().getSerializable(ARGUMENT_FEED_ITEM);
|
|
||||||
prefs = getActivity().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
|
|
||||||
}
|
}
|
||||||
|
FeedItem item = (FeedItem) getArguments().getSerializable(ARGUMENT_FEED_ITEM);
|
||||||
|
ShareEpisodeDialogBinding viewBinding = ShareEpisodeDialogBinding.inflate(inflater);
|
||||||
|
|
||||||
viewBinding = ShareEpisodeDialogBinding.inflate(inflater);
|
if (item.getMedia() != null && item.getMedia().isDownloaded()) {
|
||||||
viewBinding.shareDialogRadioGroup.setOnCheckedChangeListener((group, checkedId) ->
|
viewBinding.mediaFileCardCard.setOnClickListener(v -> {
|
||||||
viewBinding.sharePositionCheckbox.setEnabled(checkedId == viewBinding.shareSocialRadio.getId()));
|
ShareUtils.shareFeedItemFile(getContext(), item.getMedia());
|
||||||
|
|
||||||
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();
|
|
||||||
dismiss();
|
dismiss();
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
viewBinding.mediaFileCardCard.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import de.danoeh.antennapod.model.feed.FeedMedia;
|
||||||
/** Utility methods for sharing data */
|
/** Utility methods for sharing data */
|
||||||
public class ShareUtils {
|
public class ShareUtils {
|
||||||
private static final String TAG = "ShareUtils";
|
private static final String TAG = "ShareUtils";
|
||||||
|
private static final int ABBREVIATE_MAX_LENGTH = 50;
|
||||||
|
|
||||||
private ShareUtils() {
|
private ShareUtils() {
|
||||||
}
|
}
|
||||||
|
@ -47,32 +48,48 @@ public class ShareUtils {
|
||||||
return item.getLinkWithFallback() != null;
|
return item.getLinkWithFallback() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void shareMediaDownloadLink(Context context, FeedMedia media) {
|
public static String getSocialFeedItemShareText(Context context, FeedItem item,
|
||||||
shareLink(context, media.getDownloadUrl());
|
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) {
|
if (item.getMedia() != null && withPosition) {
|
||||||
text += "\n" + context.getResources().getString(R.string.share_starting_position_label) + ": ";
|
text += "\n" + context.getResources().getString(R.string.share_starting_position_label) + ": ";
|
||||||
pos = item.getMedia().getPosition();
|
text += Converter.getDurationStringLong(item.getMedia().getPosition());
|
||||||
text += Converter.getDurationStringLong(pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasLinkToShare(item)) {
|
if (hasLinkToShare(item)) {
|
||||||
text += "\n\n" + context.getResources().getString(R.string.share_dialog_episode_website_label) + ": ";
|
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();
|
text += item.getLinkWithFallback();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (item.getMedia() != null && item.getMedia().getDownloadUrl() != null) {
|
if (item.getMedia() != null && item.getMedia().getDownloadUrl() != null) {
|
||||||
text += "\n\n" + context.getResources().getString(R.string.share_dialog_media_file_label) + ": ";
|
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();
|
text += item.getMedia().getDownloadUrl();
|
||||||
|
}
|
||||||
if (withPosition) {
|
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) {
|
public static void shareFeedItemFile(Context context, FeedMedia media) {
|
||||||
|
|
|
@ -1,63 +1,172 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
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_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
|
android:clipToPadding="false"
|
||||||
android:padding="16dp">
|
android:padding="16dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/share_label"
|
android:text="@string/share_label"
|
||||||
android:layout_marginBottom="8dp"
|
android:layout_marginBottom="16dp"
|
||||||
style="@style/AntennaPod.TextView.Heading" />
|
style="@style/TextAppearance.Material3.TitleLarge" />
|
||||||
|
|
||||||
<RadioGroup
|
<androidx.cardview.widget.CardView
|
||||||
android:id="@+id/share_dialog_radio_group"
|
android:id="@+id/socialMessageCard"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
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:orientation="horizontal">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_weight="1">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingEnd="0dp"
|
||||||
|
android:paddingTop="16dp"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<RadioButton
|
<TextView
|
||||||
android:id="@+id/share_social_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_for_social"
|
android:text="@string/share_dialog_for_social"
|
||||||
android:checked="true" />
|
style="@style/TextAppearance.Material3.TitleMedium" />
|
||||||
|
|
||||||
<RadioButton
|
<TextView
|
||||||
android:id="@+id/share_media_receiver_radio"
|
android:id="@+id/socialMessageText"
|
||||||
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_address" />
|
android:text="@string/share_dialog_for_social"
|
||||||
|
style="@style/TextAppearance.Material3.BodyMedium" />
|
||||||
|
|
||||||
<RadioButton
|
</LinearLayout>
|
||||||
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>
|
|
||||||
|
|
||||||
<com.google.android.material.divider.MaterialDivider
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginVertical="8dp" />
|
|
||||||
|
|
||||||
<CheckBox
|
<CheckBox
|
||||||
android:id="@+id/share_position_checkbox"
|
android:id="@+id/share_position_checkbox"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="8dp"
|
||||||
android:text="@string/share_playback_position_dialog_label" />
|
android:text="@string/share_playback_position_dialog_label" />
|
||||||
|
|
||||||
<Button
|
</LinearLayout>
|
||||||
android:id="@+id/shareButton"
|
|
||||||
android:layout_width="wrap_content"
|
<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_height="wrap_content"
|
||||||
android:layout_gravity="end"
|
android:elevation="1dp"
|
||||||
android:text="@string/share_label"
|
android:foreground="?attr/selectableItemBackground"
|
||||||
style="@style/Widget.MaterialComponents.Button.TextButton" />
|
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" />
|
||||||
|
|
||||||
|
<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:elevation="1dp"
|
||||||
|
android:foreground="?attr/selectableItemBackground"
|
||||||
|
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_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>
|
</LinearLayout>
|
||||||
|
|
Loading…
Reference in New Issue