Added buttons to FeedItemDialog and the episode lists for items without an episode.

fixes #470, fixes #464
This commit is contained in:
daniel oeh 2014-07-13 10:31:13 +02:00
parent af4929728f
commit b87db68419
4 changed files with 99 additions and 45 deletions

View File

@ -27,8 +27,8 @@ public class ActionButtonUtils {
this.context = context;
drawables = context.obtainStyledAttributes(new int[]{
R.attr.av_play, R.attr.navigation_cancel, R.attr.av_download, R.attr.navigation_chapters});
labels = new int[]{R.string.play_label, R.string.cancel_download_label, R.string.download_label};
R.attr.av_play, R.attr.navigation_cancel, R.attr.av_download, R.attr.navigation_chapters, R.attr.navigation_accept});
labels = new int[]{R.string.play_label, R.string.cancel_download_label, R.string.download_label, R.string.mark_read_label};
}
/**
@ -66,7 +66,13 @@ public class ActionButtonUtils {
butSecondary.setContentDescription(context.getString(labels[0]));
}
} else {
butSecondary.setVisibility(View.INVISIBLE);
if (item.isRead()) {
butSecondary.setVisibility(View.INVISIBLE);
} else {
butSecondary.setVisibility(View.VISIBLE);
butSecondary.setImageDrawable(drawables.getDrawable(4));
butSecondary.setContentDescription(context.getString(labels[3]));
}
}
}
}

View File

@ -10,6 +10,7 @@ import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator;
import de.danoeh.antennapod.feed.FeedItem;
import de.danoeh.antennapod.feed.FeedMedia;
import de.danoeh.antennapod.storage.DBTasks;
import de.danoeh.antennapod.storage.DBWriter;
import de.danoeh.antennapod.storage.DownloadRequestException;
import de.danoeh.antennapod.storage.DownloadRequester;
@ -28,25 +29,29 @@ public class DefaultActionButtonCallback implements ActionButtonCallback {
@Override
public void onActionButtonPressed(final FeedItem item) {
final FeedMedia media = item.getMedia();
if (media == null) {
return;
}
boolean isDownloading = DownloadRequester.getInstance().isDownloadingFile(media);
if (!isDownloading && !media.isDownloaded()) {
try {
DBTasks.downloadFeedItems(context, item);
Toast.makeText(context, R.string.status_downloading_label, Toast.LENGTH_SHORT).show();
} catch (DownloadRequestException e) {
e.printStackTrace();
DownloadRequestErrorDialogCreator.newRequestErrorDialog(context, e.getMessage());
if (item.hasMedia()) {
final FeedMedia media = item.getMedia();
boolean isDownloading = DownloadRequester.getInstance().isDownloadingFile(media);
if (!isDownloading && !media.isDownloaded()) {
try {
DBTasks.downloadFeedItems(context, item);
Toast.makeText(context, R.string.status_downloading_label, Toast.LENGTH_SHORT).show();
} catch (DownloadRequestException e) {
e.printStackTrace();
DownloadRequestErrorDialogCreator.newRequestErrorDialog(context, e.getMessage());
}
} else if (isDownloading) {
DownloadRequester.getInstance().cancelDownload(context, media);
Toast.makeText(context, R.string.download_cancelled_msg, Toast.LENGTH_SHORT).show();
} else { // media is downloaded
DBTasks.playMedia(context, media, true, true, false);
}
} else {
if (!item.isRead()) {
DBWriter.markItemRead(context, item, true, true);
}
} else if (isDownloading) {
DownloadRequester.getInstance().cancelDownload(context, media);
Toast.makeText(context, R.string.download_cancelled_msg, Toast.LENGTH_SHORT).show();
} else { // media is downloaded
DBTasks.playMedia(context, media, true, true, false);
}
}
}

View File

@ -22,6 +22,14 @@ import android.webkit.WebViewClient;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.Validate;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;
import de.danoeh.antennapod.BuildConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.adapter.DefaultActionButtonCallback;
@ -35,12 +43,6 @@ import de.danoeh.antennapod.storage.DownloadRequester;
import de.danoeh.antennapod.util.QueueAccess;
import de.danoeh.antennapod.util.ShownotesProvider;
import de.danoeh.antennapod.util.menuhandler.FeedItemMenuHandler;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.Validate;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;
/**
* Shows information about a specific FeedItem and provides actions like playing, downloading, etc.
@ -150,12 +152,9 @@ public class FeedItemDialog extends Dialog {
@Override
public void onClick(View v) {
FeedMedia media = item.getMedia();
if (media == null) {
return;
}
actionButtonCallback.onActionButtonPressed(item);
if (media.isDownloaded()) {
FeedMedia media = item.getMedia();
if (media != null && media.isDownloaded()) {
// playback was started, dialog should close itself
dismiss();
}
@ -169,16 +168,17 @@ public class FeedItemDialog extends Dialog {
{
@Override
public void onClick(View v) {
FeedMedia media = item.getMedia();
if (media == null) {
return;
}
if (!media.isDownloaded()) {
DBTasks.playMedia(getContext(), media, true, true, true);
dismiss();
} else {
DBWriter.deleteFeedMediaOfItem(getContext(), media.getId());
if (item.hasMedia()) {
FeedMedia media = item.getMedia();
if (!media.isDownloaded()) {
DBTasks.playMedia(getContext(), media, true, true, true);
dismiss();
} else {
DBWriter.deleteFeedMediaOfItem(getContext(), media.getId());
}
} else if (item.getLink() != null) {
Uri uri = Uri.parse(item.getLink());
getContext().startActivity(new Intent(Intent.ACTION_VIEW, uri));
}
}
}
@ -189,7 +189,13 @@ public class FeedItemDialog extends Dialog {
public void onClick(View v) {
popupMenu.getMenu().clear();
popupMenu.inflate(R.menu.feeditem_dialog);
FeedItemMenuHandler.onPrepareMenu(popupMenuInterface, item, true, queue);
if (item.hasMedia()) {
FeedItemMenuHandler.onPrepareMenu(popupMenuInterface, item, true, queue);
} else {
// these are already available via button1 and button2
FeedItemMenuHandler.onPrepareMenu(popupMenuInterface, item, true, queue,
R.id.mark_read_item, R.id.visit_website_item);
}
popupMenu.show();
}
}
@ -231,9 +237,26 @@ public class FeedItemDialog extends Dialog {
}
FeedMedia media = item.getMedia();
if (media == null) {
header.setVisibility(View.GONE);
TypedArray drawables = getContext().obtainStyledAttributes(new int[]{R.attr.navigation_accept,
R.attr.location_web_site});
if (!item.isRead()) {
butAction1.setImageDrawable(drawables.getDrawable(0));
butAction1.setContentDescription(getContext().getString(R.string.mark_read_label));
butAction1.setVisibility(View.VISIBLE);
} else {
butAction1.setVisibility(View.INVISIBLE);
}
if (item.getLink() != null) {
butAction2.setImageDrawable(drawables.getDrawable(1));
butAction2.setContentDescription(getContext().getString(R.string.visit_website_label));
} else {
butAction2.setEnabled(false);
}
drawables.recycle();
} else {
header.setVisibility(View.VISIBLE);
boolean isDownloading = DownloadRequester.getInstance().isDownloadingFile(media);
TypedArray drawables = getContext().obtainStyledAttributes(new int[]{R.attr.av_play,
R.attr.av_download, R.attr.action_stream, R.attr.content_discard, R.attr.navigation_cancel});
@ -390,7 +413,7 @@ public class FeedItemDialog extends Dialog {
/**
* Used to save the FeedItemDialog's state across configuration changes
* */
*/
public static class FeedItemDialogSavedInstance {
final FeedItem item;
final QueueAccess queueAccess;

View File

@ -3,6 +3,7 @@ package de.danoeh.antennapod.util.menuhandler;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import de.danoeh.antennapod.BuildConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.feed.FeedItem;
@ -113,6 +114,25 @@ public class FeedItemMenuHandler {
return true;
}
/**
* The same method as onPrepareMenu(MenuInterface, FeedItem, boolean, QueueAccess), but lets the
* caller also specify a list of menu items that should not be shown.
*
* @param excludeIds Menu item that should be excluded
* @return true if selectedItem is not null.
*/
public static boolean onPrepareMenu(MenuInterface mi,
FeedItem selectedItem, boolean showExtendedMenu, QueueAccess queueAccess, int... excludeIds) {
boolean rc = onPrepareMenu(mi, selectedItem, showExtendedMenu, queueAccess);
if (rc && excludeIds != null) {
for (int id : excludeIds) {
mi.setItemVisibility(id, false);
}
}
return rc;
}
public static boolean onMenuItemClicked(Context context, int menuItemId,
FeedItem selectedItem) throws DownloadRequestException {
DownloadRequester requester = DownloadRequester.getInstance();