diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2012-06-20 16:29:26 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2012-06-20 16:29:26 +0200 |
commit | 409fcee753d4cee83f67ff66d1ed85974825bc55 (patch) | |
tree | 13493f6570047d1ad84bfa6b61d8530580cfcde6 /src/de/podfetcher | |
parent | 8f9344fbe74a6922f949ddffbc1779f539fcef3f (diff) | |
download | AntennaPod-409fcee753d4cee83f67ff66d1ed85974825bc55.zip |
Made feeditem menu usable across different contexts
Diffstat (limited to 'src/de/podfetcher')
-rw-r--r-- | src/de/podfetcher/activity/ItemviewActivity.java | 19 | ||||
-rw-r--r-- | src/de/podfetcher/fragment/FeedItemlistFragment.java | 61 | ||||
-rw-r--r-- | src/de/podfetcher/syndication/util/FeedItemMenuHandler.java | 90 |
3 files changed, 105 insertions, 65 deletions
diff --git a/src/de/podfetcher/activity/ItemviewActivity.java b/src/de/podfetcher/activity/ItemviewActivity.java index dde014849..dd6bb05b4 100644 --- a/src/de/podfetcher/activity/ItemviewActivity.java +++ b/src/de/podfetcher/activity/ItemviewActivity.java @@ -28,6 +28,7 @@ import de.podfetcher.fragment.FeedItemlistFragment; import de.podfetcher.fragment.FeedlistFragment; import de.podfetcher.service.PlaybackService; import de.podfetcher.storage.DownloadRequester; +import de.podfetcher.syndication.util.FeedItemMenuHandler; /** Displays a single FeedItem and provides various actions */ public class ItemviewActivity extends SherlockActivity { @@ -158,20 +159,22 @@ public class ItemviewActivity extends SherlockActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = new MenuInflater(this); - inflater.inflate(R.menu.feeditemlist, menu); - getDownloadStatus(menu); - return true; + return FeedItemMenuHandler.onCreateMenu(new MenuInflater(this), menu); } @Override - public boolean onOptionsItemSelected(MenuItem item) { - // TODO Auto-generated method stub - return super.onOptionsItemSelected(item); + public boolean onOptionsItemSelected(MenuItem menuItem) { + FeedItemMenuHandler.onMenuItemClicked(this, menuItem, item); + invalidateOptionsMenu(); + return true; + } + + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + return FeedItemMenuHandler.onPrepareMenu(menu, item); } - private void setDownloadingState(Menu menu) { diff --git a/src/de/podfetcher/fragment/FeedItemlistFragment.java b/src/de/podfetcher/fragment/FeedItemlistFragment.java index a11966f53..9354934db 100644 --- a/src/de/podfetcher/fragment/FeedItemlistFragment.java +++ b/src/de/podfetcher/fragment/FeedItemlistFragment.java @@ -21,6 +21,7 @@ import de.podfetcher.adapter.FeedItemlistAdapter; import de.podfetcher.feed.FeedItem; import de.podfetcher.feed.FeedManager; import de.podfetcher.storage.DownloadRequester; +import de.podfetcher.syndication.util.FeedItemMenuHandler; public class FeedItemlistFragment extends SherlockListFragment { private static final String TAG = "FeedItemlistFragment"; @@ -96,7 +97,7 @@ public class FeedItemlistFragment extends SherlockListFragment { @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { - return false; + return FeedItemMenuHandler.onPrepareMenu(menu, selectedItem); } @Override @@ -107,67 +108,13 @@ public class FeedItemlistFragment extends SherlockListFragment { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { - MenuInflater inflater = mode.getMenuInflater(); - inflater.inflate(R.menu.feeditemlist, menu); - mode.setTitle(selectedItem.getTitle()); - - if (selectedItem.getMedia().isDownloaded()) { - menu.findItem(R.id.play_item).setVisible(true); - menu.findItem(R.id.remove_item).setVisible(true); - } else if (selectedItem.getMedia().getFile_url() == null) { - menu.findItem(R.id.download_item).setVisible(true); - } else { - menu.findItem(R.id.cancel_download_item).setVisible(true); - } - - if (selectedItem.isRead()) { - menu.findItem(R.id.mark_unread_item).setVisible(true); - } else { - menu.findItem(R.id.mark_read_item).setVisible(true); - } - - if (manager.isInQueue(selectedItem)) { - menu.findItem(R.id.remove_from_queue_item).setVisible(true); - } else { - menu.findItem(R.id.add_to_queue_item).setVisible(true); - } - - return true; + return FeedItemMenuHandler.onCreateMenu(mode.getMenuInflater(), menu); } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { - switch (item.getItemId()) { - case R.id.download_item: - requester.downloadMedia(getSherlockActivity(), - selectedItem.getMedia()); - break; - case R.id.play_item: - manager.playMedia(getSherlockActivity(), - selectedItem.getMedia()); - break; - case R.id.remove_item: - manager.deleteFeedMedia(getSherlockActivity(), - selectedItem.getMedia()); - break; - case R.id.cancel_download_item: - requester.cancelDownload(getSherlockActivity(), selectedItem - .getMedia().getDownloadId()); - break; - case R.id.mark_read_item: - manager.markItemRead(getSherlockActivity(), selectedItem, true); - break; - case R.id.mark_unread_item: - manager.markItemRead(getSherlockActivity(), selectedItem, false); - break; - case R.id.add_to_queue_item: - manager.addQueueItem(getSherlockActivity(), selectedItem); - break; - case R.id.remove_from_queue_item: - manager.removeQueueItem(getSherlockActivity(), selectedItem); - break; - } + FeedItemMenuHandler.onMenuItemClicked(getSherlockActivity(), item, selectedItem); fila.notifyDataSetChanged(); mode.finish(); return true; diff --git a/src/de/podfetcher/syndication/util/FeedItemMenuHandler.java b/src/de/podfetcher/syndication/util/FeedItemMenuHandler.java new file mode 100644 index 000000000..e1aded68e --- /dev/null +++ b/src/de/podfetcher/syndication/util/FeedItemMenuHandler.java @@ -0,0 +1,90 @@ +package de.podfetcher.syndication.util; + +import android.content.Context; + +import com.actionbarsherlock.view.Menu; +import com.actionbarsherlock.view.MenuInflater; +import com.actionbarsherlock.view.MenuItem; + +import de.podfetcher.R; +import de.podfetcher.feed.FeedItem; +import de.podfetcher.feed.FeedManager; +import de.podfetcher.storage.DownloadRequester; + +/** Handles interactions with the FeedItemMenu. */ +public class FeedItemMenuHandler { + private FeedItemMenuHandler() { + + } + + public static boolean onPrepareMenu(Menu menu, FeedItem selectedItem) { + FeedManager manager = FeedManager.getInstance(); + + if (selectedItem.getMedia().isDownloaded()) { + menu.findItem(R.id.play_item).setVisible(true); + menu.findItem(R.id.remove_item).setVisible(true); + } else if (selectedItem.getMedia().getFile_url() == null) { + menu.findItem(R.id.download_item).setVisible(true); + } else { + menu.findItem(R.id.cancel_download_item).setVisible(true); + } + + if (selectedItem.isRead()) { + menu.findItem(R.id.mark_unread_item).setVisible(true); + } else { + menu.findItem(R.id.mark_read_item).setVisible(true); + } + + if (manager.isInQueue(selectedItem)) { + menu.findItem(R.id.remove_from_queue_item).setVisible(true); + } else { + menu.findItem(R.id.add_to_queue_item).setVisible(true); + } + return true; + } + + public static boolean onMenuItemClicked(Context context, MenuItem item, FeedItem selectedItem) { + DownloadRequester requester = DownloadRequester.getInstance(); + FeedManager manager = FeedManager.getInstance(); + switch (item.getItemId()) { + case R.id.download_item: + requester.downloadMedia(context, + selectedItem.getMedia()); + break; + case R.id.play_item: + manager.playMedia(context, + selectedItem.getMedia()); + break; + case R.id.remove_item: + manager.deleteFeedMedia(context, + selectedItem.getMedia()); + break; + case R.id.cancel_download_item: + requester.cancelDownload(context, selectedItem + .getMedia().getDownloadId()); + break; + case R.id.mark_read_item: + manager.markItemRead(context, selectedItem, true); + break; + case R.id.mark_unread_item: + manager.markItemRead(context, selectedItem, false); + break; + case R.id.add_to_queue_item: + manager.addQueueItem(context, selectedItem); + break; + case R.id.remove_from_queue_item: + manager.removeQueueItem(context, selectedItem); + break; + } + // Refresh menu state + + return true; + } + + public static boolean onCreateMenu(MenuInflater inflater, Menu menu) { + inflater.inflate(R.menu.feeditem, menu); + return true; + } + + +} |