From 663993afb25f8ec50678b44399c6538d1b9bd71c Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Sat, 18 Aug 2012 17:24:08 +0200 Subject: [PATCH] Hide 'mark all read' and 'refresh all feeds' - items when they aren't needed --- .../antennapod/activity/MainActivity.java | 1 + src/de/danoeh/antennapod/feed/Feed.java | 19 +++++++++++++++++++ .../util/menuhandler/FeedMenuHandler.java | 5 ++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/de/danoeh/antennapod/activity/MainActivity.java b/src/de/danoeh/antennapod/activity/MainActivity.java index d6db17740..31907dde3 100644 --- a/src/de/danoeh/antennapod/activity/MainActivity.java +++ b/src/de/danoeh/antennapod/activity/MainActivity.java @@ -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; } diff --git a/src/de/danoeh/antennapod/feed/Feed.java b/src/de/danoeh/antennapod/feed/Feed.java index 4b74a62d1..057153176 100644 --- a/src/de/danoeh/antennapod/feed/Feed.java +++ b/src/de/danoeh/antennapod/feed/Feed.java @@ -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 diff --git a/src/de/danoeh/antennapod/util/menuhandler/FeedMenuHandler.java b/src/de/danoeh/antennapod/util/menuhandler/FeedMenuHandler.java index 6bb1478d6..0851ff062 100644 --- a/src/de/danoeh/antennapod/util/menuhandler/FeedMenuHandler.java +++ b/src/de/danoeh/antennapod/util/menuhandler/FeedMenuHandler.java @@ -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);