From 870b673527fda111b29d901fc179635594160ba3 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Wed, 11 Jul 2012 11:05:46 +0200 Subject: [PATCH] Added menu item to mark all items as read --- src/de/podfetcher/feed/FeedManager.java | 14 ++++++++ .../podfetcher/fragment/FeedlistFragment.java | 1 + .../fragment/UnreadItemlistFragment.java | 36 +++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/src/de/podfetcher/feed/FeedManager.java b/src/de/podfetcher/feed/FeedManager.java index 3c8f77770..d01c89188 100644 --- a/src/de/podfetcher/feed/FeedManager.java +++ b/src/de/podfetcher/feed/FeedManager.java @@ -193,6 +193,20 @@ public class FeedManager { } } } + + /** Marks all items in the unread items list as read */ + public void markAllItemsRead(Context context) { + Log.d(TAG, "marking all items as read"); + PodDBAdapter adapter = new PodDBAdapter(context); + adapter.open(); + for (FeedItem item : unreadItems) { + item.read = true; + setFeedItem(item, adapter); + } + adapter.close(); + unreadItems.clear(); + sendUnreadItemsUpdateBroadcast(context, null); + } public void refreshAllFeeds(Context context) { Log.d(TAG, "Refreshing all feeds."); diff --git a/src/de/podfetcher/fragment/FeedlistFragment.java b/src/de/podfetcher/fragment/FeedlistFragment.java index 763c89ac7..4eb2c96b2 100644 --- a/src/de/podfetcher/fragment/FeedlistFragment.java +++ b/src/de/podfetcher/fragment/FeedlistFragment.java @@ -105,6 +105,7 @@ public class FeedlistFragment extends SherlockListFragment implements filter.addAction(DownloadService.ACTION_DOWNLOAD_HANDLED); filter.addAction(DownloadService.ACTION_FEED_SYNC_COMPLETED); filter.addAction(DownloadRequester.ACTION_DOWNLOAD_QUEUED); + filter.addAction(FeedManager.ACTION_UNREAD_ITEMS_UPDATE); pActivity.registerReceiver(contentUpdate, filter); fla.notifyDataSetChanged(); diff --git a/src/de/podfetcher/fragment/UnreadItemlistFragment.java b/src/de/podfetcher/fragment/UnreadItemlistFragment.java index 0b25c61a4..becb3ec53 100644 --- a/src/de/podfetcher/fragment/UnreadItemlistFragment.java +++ b/src/de/podfetcher/fragment/UnreadItemlistFragment.java @@ -1,9 +1,15 @@ package de.podfetcher.fragment; +import com.actionbarsherlock.view.Menu; +import com.actionbarsherlock.view.MenuInflater; +import com.actionbarsherlock.view.MenuItem; + import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.os.Bundle; +import de.podfetcher.R; import de.podfetcher.feed.FeedManager; /** Contains all unread items. */ @@ -31,6 +37,12 @@ public class UnreadItemlistFragment extends ItemlistFragment { new IntentFilter(FeedManager.ACTION_UNREAD_ITEMS_UPDATE)); } + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setHasOptionsMenu(true); + } + private BroadcastReceiver unreadItemsUpdate = new BroadcastReceiver() { @Override @@ -40,4 +52,28 @@ public class UnreadItemlistFragment extends ItemlistFragment { }; + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + super.onCreateOptionsMenu(menu, inflater); + menu.add(Menu.NONE, R.id.mark_all_read_item, Menu.NONE, getActivity() + .getString(R.string.mark_all_read_label)); + } + + @Override + public void onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.mark_all_read_item: + manager.markAllItemsRead(getActivity()); + break; + default: + return false; + } + return true; + } + }