Hide 'mark all read' and 'refresh all feeds' - items when they aren't

needed
This commit is contained in:
daniel oeh 2012-08-18 17:24:08 +02:00
parent b99a810a1b
commit 663993afb2
3 changed files with 24 additions and 1 deletions

View File

@ -135,6 +135,7 @@ public class MainActivity extends SherlockFragmentActivity {
boolean hasFeeds = !manager.getFeeds().isEmpty();
menu.findItem(R.id.opml_export).setVisible(hasFeeds);
menu.findItem(R.id.all_feed_refresh).setVisible(hasFeeds);
return true;
}

View File

@ -79,6 +79,25 @@ public class Feed extends FeedFile {
return count;
}
/**
* Returns true if at least one item in the itemlist is unread.If the
* 'display only episodes' - preference is set to true, this method will
* only count items with episodes.
*/
public boolean hasNewItems() {
boolean displayOnlyEpisodes = PreferenceManager
.getDefaultSharedPreferences(PodcastApp.getInstance())
.getBoolean(PodcastApp.PREF_DISPLAY_ONLY_EPISODES, false);
for (FeedItem item : items) {
if (!item.isRead()) {
if (!displayOnlyEpisodes || item.getMedia() != null) {
return true;
}
}
}
return false;
}
/**
* Returns the number of FeedItems. If the 'display only episodes' -
* preference is set to true, this method will only count items with

View File

@ -33,6 +33,8 @@ public class FeedMenuHandler {
public static boolean onPrepareOptionsMenu(Menu menu, Feed selectedFeed) {
if (AppConfig.DEBUG)
Log.d(TAG, "Preparing options menu");
menu.findItem(R.id.mark_all_read_item).setVisible(
selectedFeed.hasNewItems());
if (selectedFeed.getPaymentLink() != null) {
menu.findItem(R.id.support_item).setVisible(true);
}
@ -73,7 +75,8 @@ public class FeedMenuHandler {
context.startActivity(new Intent(Intent.ACTION_VIEW, uri));
break;
case R.id.support_item:
new FlattrClickWorker(context, selectedFeed.getPaymentLink()).executeAsync();
new FlattrClickWorker(context, selectedFeed.getPaymentLink())
.executeAsync();
break;
case R.id.share_link_item:
ShareUtils.shareFeedlink(context, selectedFeed);