fixes #1215 replacing share menu by dialog

This commit is contained in:
Gerardo Vázquez 2020-06-23 17:15:41 -05:00
parent 65ec9e5f45
commit 020d585972
5 changed files with 111 additions and 110 deletions

View File

@ -18,16 +18,22 @@ import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import org.apache.commons.lang3.StringUtils;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.text.NumberFormat;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.arch.core.util.Function;
import androidx.core.app.ActivityCompat;
import androidx.core.app.ActivityOptionsCompat;
import androidx.core.content.ContextCompat;
import androidx.core.util.Consumer;
import androidx.core.util.Supplier;
import com.bumptech.glide.Glide;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.event.PlaybackPositionEvent;
import de.danoeh.antennapod.core.feed.FeedItem;
@ -39,7 +45,6 @@ import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.Flavors;
import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.ShareUtils;
import de.danoeh.antennapod.core.util.StorageUtils;
@ -51,18 +56,13 @@ import de.danoeh.antennapod.core.util.playback.Playable;
import de.danoeh.antennapod.core.util.playback.PlaybackController;
import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter;
import de.danoeh.antennapod.dialog.PlaybackControlsDialog;
import de.danoeh.antennapod.dialog.ShareDialog;
import de.danoeh.antennapod.dialog.SkipPreferenceDialog;
import de.danoeh.antennapod.dialog.SleepTimerDialog;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import org.apache.commons.lang3.StringUtils;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.text.NumberFormat;
/**
@ -313,13 +313,8 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
boolean isItemAndHasLink = isFeedMedia &&
ShareUtils.hasLinkToShare(((FeedMedia) media).getItem());
menu.findItem(R.id.share_link_item).setVisible(isItemAndHasLink);
menu.findItem(R.id.share_link_with_position_item).setVisible(isItemAndHasLink);
boolean isItemHasDownloadLink = isFeedMedia && ((FeedMedia) media).getDownload_url() != null;
menu.findItem(R.id.share_download_url_item).setVisible(isItemHasDownloadLink);
menu.findItem(R.id.share_download_url_with_position_item).setVisible(isItemHasDownloadLink);
menu.findItem(R.id.share_file).setVisible(isFeedMedia && ((FeedMedia) media).fileExists());
menu.findItem(R.id.share_item).setVisible(hasWebsiteLink || isItemAndHasLink || isItemHasDownloadLink);
@ -393,29 +388,10 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
case R.id.visit_website_item:
IntentUtils.openInBrowser(MediaplayerActivity.this, getWebsiteLinkWithFallback(media));
break;
case R.id.share_link_item:
case R.id.share_item:
if (feedItem != null) {
ShareUtils.shareFeedItemLink(this, feedItem);
}
break;
case R.id.share_download_url_item:
if (feedItem != null) {
ShareUtils.shareFeedItemDownloadLink(this, feedItem);
}
break;
case R.id.share_link_with_position_item:
if (feedItem != null) {
ShareUtils.shareFeedItemLink(this, feedItem, true);
}
break;
case R.id.share_download_url_with_position_item:
if (feedItem != null) {
ShareUtils.shareFeedItemDownloadLink(this, feedItem, true);
}
break;
case R.id.share_file:
if (media instanceof FeedMedia) {
ShareUtils.shareFeedItemFile(this, ((FeedMedia) media));
ShareDialog shareDialog = new ShareDialog(getApplicationContext(), feedItem);
shareDialog.createDialog().show();
}
break;
default:

View File

@ -0,0 +1,89 @@
package de.danoeh.antennapod.dialog;
import android.content.Context;
import android.content.DialogInterface;
import java.util.ArrayList;
import java.util.List;
import androidx.appcompat.app.AlertDialog;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.util.ShareUtils;
public class ShareDialog {
private static final String TAG = "ShareDialog";
private final Context context;
private AlertDialog dialog;
private List<String> shareDialogOptions;
private String[] arrayItems;
private FeedItem item;
public ShareDialog(Context context, FeedItem item) {
this.context = context;
this.item = item;
shareDialogOptions = new ArrayList<>();
}
public AlertDialog createDialog() {
setupOptions();
dialog = new AlertDialog.Builder(context)
.setTitle(R.string.share_label)
.setItems(arrayItems, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// The 'which' argument contains the index position
// of the selected item
if(arrayItems[which].equals(context.getString(R.string.share_link_label))){
ShareUtils.shareFeedItemLink(context, item);
} else if(arrayItems[which].equals(context.getString(R.string.share_item_url_label))) {
ShareUtils.shareFeedItemDownloadLink(context, item);
} else if(arrayItems[which].equals(context.getString(R.string.share_link_with_position_label))) {
ShareUtils.shareFeedItemLink(context, item, true);
} else if(arrayItems[which].equals(context.getString(R.string.share_item_url_with_position_label))) {
ShareUtils.shareFeedItemDownloadLink(context, item, true);
} else if(arrayItems[which].equals(context.getString(R.string.share_file_label))) {
ShareUtils.shareFeedItemFile(context, item.getMedia());
}
}
})
.create();
return dialog;
}
private void setupOptions(){
boolean hasMedia = item.getMedia() != null;
shareDialogOptions.add(context.getString(R.string.share_link_label));
shareDialogOptions.add(context.getString(R.string.share_link_with_position_label));
shareDialogOptions.add(context.getString(R.string.share_item_url_label));
shareDialogOptions.add(context.getString(R.string.share_item_url_with_position_label));
shareDialogOptions.add(context.getString(R.string.share_file_label));
if (!ShareUtils.hasLinkToShare(item)) {
shareDialogOptions.remove(context.getString(R.string.share_link_label));
shareDialogOptions.remove(context.getString(R.string.share_link_with_position_label));
}
if (!hasMedia || item.getMedia().getDownload_url() == null) {
shareDialogOptions.remove(context.getString(R.string.share_item_url_label));
shareDialogOptions.remove(context.getString(R.string.share_item_url_with_position_label));
}
if(!hasMedia || item.getMedia().getPosition() <= 0) {
shareDialogOptions.remove(context.getString(R.string.share_item_url_with_position_label));
shareDialogOptions.remove(context.getString(R.string.share_link_with_position_label));
}
boolean fileDownloaded = hasMedia && item.getMedia().fileExists();
if(!fileDownloaded){
shareDialogOptions.remove(context.getString(R.string.share_file_label));
}
// preparing the resulting shareOptions for dialog
arrayItems = new String[shareDialogOptions.size()];
shareDialogOptions.toArray(arrayItems);
}
}

View File

@ -2,13 +2,14 @@ package de.danoeh.antennapod.menuhandler;
import android.content.Context;
import android.os.Handler;
import androidx.annotation.NonNull;
import com.google.android.material.snackbar.Snackbar;
import androidx.fragment.app.Fragment;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import com.google.android.material.snackbar.Snackbar;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.core.feed.FeedItem;
@ -23,6 +24,7 @@ import de.danoeh.antennapod.core.sync.model.EpisodeAction;
import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.ShareUtils;
import de.danoeh.antennapod.dialog.ShareDialog;
/**
* Handles interactions with the FeedItemMenu.
@ -61,20 +63,9 @@ public class FeedItemMenuHandler {
}
if (!ShareUtils.hasLinkToShare(selectedItem)) {
setItemVisibility(menu, R.id.visit_website_item, false);
setItemVisibility(menu, R.id.share_link_item, false);
setItemVisibility(menu, R.id.share_link_with_position_item, false);
}
if (!hasMedia || selectedItem.getMedia().getDownload_url() == null) {
setItemVisibility(menu, R.id.share_download_url_item, false);
setItemVisibility(menu, R.id.share_download_url_with_position_item, false);
}
if(!hasMedia || selectedItem.getMedia().getPosition() <= 0) {
setItemVisibility(menu, R.id.share_download_url_with_position_item, false);
setItemVisibility(menu, R.id.share_link_with_position_item, false);
}
boolean fileDownloaded = hasMedia && selectedItem.getMedia().fileExists();
setItemVisibility(menu, R.id.share_file, fileDownloaded);
setItemVisibility(menu, R.id.remove_new_flag_item, selectedItem.isNew());
if (selectedItem.isPlayed()) {
@ -243,20 +234,9 @@ public class FeedItemMenuHandler {
case R.id.visit_website_item:
IntentUtils.openInBrowser(context, FeedItemUtil.getLinkWithFallback(selectedItem));
break;
case R.id.share_link_item:
ShareUtils.shareFeedItemLink(context, selectedItem);
break;
case R.id.share_download_url_item:
ShareUtils.shareFeedItemDownloadLink(context, selectedItem);
break;
case R.id.share_link_with_position_item:
ShareUtils.shareFeedItemLink(context, selectedItem, true);
break;
case R.id.share_download_url_with_position_item:
ShareUtils.shareFeedItemDownloadLink(context, selectedItem, true);
break;
case R.id.share_file:
ShareUtils.shareFeedItemFile(context, selectedItem.getMedia());
case R.id.share_item:
ShareDialog shareDialog = new ShareDialog(context, selectedItem);
shareDialog.createDialog().show();
break;
default:
Log.d(TAG, "Unknown menuItemId: " + menuItemId);

View File

@ -72,28 +72,6 @@
android:id="@+id/share_item"
android:menuCategory="container"
android:title="@string/share_label">
<menu>
<item
android:id="@+id/share_link_item"
android:menuCategory="container"
android:title="@string/share_link_label" />
<item
android:id="@+id/share_link_with_position_item"
android:menuCategory="container"
android:title="@string/share_link_with_position_label" />
<item
android:id="@+id/share_download_url_item"
android:menuCategory="container"
android:title="@string/share_item_url_label" />
<item
android:id="@+id/share_download_url_with_position_item"
android:menuCategory="container"
android:title="@string/share_item_url_with_position_label" />
<item
android:id="@+id/share_file"
android:menuCategory="container"
android:title="@string/share_file_label" />
</menu>
</item>
<item

View File

@ -63,27 +63,5 @@
android:menuCategory="container"
custom:showAsAction="never"
android:title="@string/share_label">
<menu>
<item
android:id="@+id/share_link_item"
android:menuCategory="container"
android:title="@string/share_link_label" />
<item
android:id="@+id/share_link_with_position_item"
android:menuCategory="container"
android:title="@string/share_link_with_position_label" />
<item
android:id="@+id/share_download_url_item"
android:menuCategory="container"
android:title="@string/share_item_url_label" />
<item
android:id="@+id/share_download_url_with_position_item"
android:menuCategory="container"
android:title="@string/share_item_url_with_position_label" />
<item
android:id="@+id/share_file"
android:menuCategory="container"
android:title="@string/share_file_label" />
</menu>
</item>
</menu>