Added menu item to mark all items as read

This commit is contained in:
daniel oeh 2012-07-11 11:05:46 +02:00
parent 1cc0d763ba
commit 870b673527
3 changed files with 51 additions and 0 deletions

View File

@ -194,6 +194,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) { public void refreshAllFeeds(Context context) {
Log.d(TAG, "Refreshing all feeds."); Log.d(TAG, "Refreshing all feeds.");
for (Feed feed : feeds) { for (Feed feed : feeds) {

View File

@ -105,6 +105,7 @@ public class FeedlistFragment extends SherlockListFragment implements
filter.addAction(DownloadService.ACTION_DOWNLOAD_HANDLED); filter.addAction(DownloadService.ACTION_DOWNLOAD_HANDLED);
filter.addAction(DownloadService.ACTION_FEED_SYNC_COMPLETED); filter.addAction(DownloadService.ACTION_FEED_SYNC_COMPLETED);
filter.addAction(DownloadRequester.ACTION_DOWNLOAD_QUEUED); filter.addAction(DownloadRequester.ACTION_DOWNLOAD_QUEUED);
filter.addAction(FeedManager.ACTION_UNREAD_ITEMS_UPDATE);
pActivity.registerReceiver(contentUpdate, filter); pActivity.registerReceiver(contentUpdate, filter);
fla.notifyDataSetChanged(); fla.notifyDataSetChanged();

View File

@ -1,9 +1,15 @@
package de.podfetcher.fragment; 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.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.os.Bundle;
import de.podfetcher.R;
import de.podfetcher.feed.FeedManager; import de.podfetcher.feed.FeedManager;
/** Contains all unread items. */ /** Contains all unread items. */
@ -31,6 +37,12 @@ public class UnreadItemlistFragment extends ItemlistFragment {
new IntentFilter(FeedManager.ACTION_UNREAD_ITEMS_UPDATE)); new IntentFilter(FeedManager.ACTION_UNREAD_ITEMS_UPDATE));
} }
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
private BroadcastReceiver unreadItemsUpdate = new BroadcastReceiver() { private BroadcastReceiver unreadItemsUpdate = new BroadcastReceiver() {
@Override @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;
}
} }