Improved performance of FeedItemMenuHandler's prepare method

This commit is contained in:
daniel oeh 2013-01-21 22:47:19 +01:00
parent ccd75800c9
commit 825ccd28c1
2 changed files with 44 additions and 44 deletions

View File

@ -5,29 +5,25 @@
android:id="@+id/download_item"
android:icon="?attr/av_download"
android:showAsAction="ifRoom"
android:title="@string/download_label"
android:visible="false">
android:title="@string/download_label">
</item>
<item
android:id="@+id/stream_item"
android:icon="?attr/action_stream"
android:showAsAction="ifRoom"
android:title="@string/stream_label"
android:visible="false">
android:title="@string/stream_label">
</item>
<item
android:id="@+id/play_item"
android:icon="?attr/av_play"
android:showAsAction="ifRoom"
android:title="@string/play_label"
android:visible="false">
android:title="@string/play_label">
</item>
<item
android:id="@+id/remove_item"
android:icon="?attr/content_discard"
android:showAsAction="collapseActionView"
android:title="@string/remove_label"
android:visible="false">
android:title="@string/remove_label">
</item>
<item
android:id="@+id/cancel_download_item"
@ -38,26 +34,22 @@
<item
android:id="@+id/mark_read_item"
android:showAsAction="collapseActionView"
android:title="@string/mark_read_label"
android:visible="false">
android:title="@string/mark_read_label">
</item>
<item
android:id="@+id/mark_unread_item"
android:showAsAction="collapseActionView"
android:title="@string/mark_unread_label"
android:visible="false">
android:title="@string/mark_unread_label">
</item>
<item
android:id="@+id/add_to_queue_item"
android:showAsAction="collapseActionView"
android:title="@string/add_to_queue_label"
android:visible="false">
android:title="@string/add_to_queue_label">
</item>
<item
android:id="@+id/remove_from_queue_item"
android:showAsAction="collapseActionView"
android:title="@string/remove_from_queue_label"
android:visible="false">
android:title="@string/remove_from_queue_label">
</item>
<item
android:id="@+id/share_link_item"
@ -68,14 +60,12 @@
android:id="@+id/visit_website_item"
android:icon="?attr/location_web_site"
android:showAsAction="ifRoom|collapseActionView"
android:title="@string/visit_website_label"
android:visible="false">
android:title="@string/visit_website_label">
</item>
<item
android:id="@+id/support_item"
android:showAsAction="collapseActionView"
android:title="@string/support_label"
android:visible="false">
android:title="@string/support_label">
</item>
</menu>

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 android.os.Debug;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@ -47,36 +48,45 @@ public class FeedItemMenuHandler {
&& (!downloading);
FeedItem.State state = selectedItem.getState();
mi.setItemVisibility(R.id.play_item, downloaded);
mi.setItemVisibility(R.id.remove_item, downloaded);
mi.setItemVisibility(R.id.download_item, notLoadedAndNotLoading);
mi.setItemVisibility(R.id.stream_item, notLoadedAndNotLoading
| downloading);
mi.setItemVisibility(R.id.cancel_download_item, downloading);
if (!downloaded) {
mi.setItemVisibility(R.id.play_item, false);
mi.setItemVisibility(R.id.remove_item, false);
}
if (!notLoadedAndNotLoading) {
mi.setItemVisibility(R.id.download_item, false);
}
if (!(notLoadedAndNotLoading | downloading)) {
mi.setItemVisibility(R.id.stream_item, false);
}
if (!downloading) {
mi.setItemVisibility(R.id.cancel_download_item, false);
}
boolean isInQueue = manager.isInQueue(selectedItem);
mi.setItemVisibility(R.id.remove_from_queue_item, isInQueue);
mi.setItemVisibility(R.id.add_to_queue_item,
!isInQueue && selectedItem.getMedia() != null);
mi.setItemVisibility(R.id.share_link_item,
selectedItem.getLink() != null);
mi.setItemVisibility(R.id.mark_unread_item,
state == FeedItem.State.IN_PROGRESS
|| state == FeedItem.State.READ);
mi.setItemVisibility(R.id.mark_read_item, state == FeedItem.State.NEW
|| state == FeedItem.State.IN_PROGRESS);
if (selectedItem.getLink() != null) {
mi.setItemVisibility(R.id.visit_website_item, true);
if (!isInQueue) {
mi.setItemVisibility(R.id.remove_from_queue_item, false);
}
if (!(!isInQueue && selectedItem.getMedia() != null)) {
mi.setItemVisibility(R.id.add_to_queue_item, false);
}
if (selectedItem.getLink() == null) {
mi.setItemVisibility(R.id.share_link_item, false);
}
if (selectedItem.getPaymentLink() != null) {
mi.setItemVisibility(R.id.support_item, true);
if (!(state == FeedItem.State.IN_PROGRESS || state == FeedItem.State.READ)) {
mi.setItemVisibility(R.id.mark_unread_item, false);
}
if (!(state == FeedItem.State.NEW || state == FeedItem.State.IN_PROGRESS)) {
mi.setItemVisibility(R.id.mark_read_item, false);
}
if (selectedItem.getLink() == null) {
mi.setItemVisibility(R.id.visit_website_item, false);
}
if (selectedItem.getPaymentLink() == null) {
mi.setItemVisibility(R.id.support_item, false);
}
return true;
}