Queue and unreadItemlist now update more frequently

This commit is contained in:
daniel oeh 2012-07-11 10:13:31 +02:00
parent d79dd76d9a
commit 1cc0d763ba
3 changed files with 101 additions and 9 deletions

View File

@ -25,6 +25,11 @@ import android.util.Log;
public class FeedManager {
private static final String TAG = "FeedManager";
public static final String ACTION_UNREAD_ITEMS_UPDATE = "de.podfetcher.action.feed.unreadItemsUpdate";
public static final String ACTION_QUEUE_UPDATE = "de.podfetcher.action.feed.queueUpdate";
public static final String EXTRA_FEED_ITEM_ID = "de.podfetcher.extra.feed.feedItemId";
public static final String EXTRA_FEED_ID = "de.podfetcher.extra.feed.feedId";
/** Number of completed Download status entries to store. */
private static final int DOWNLOAD_LOG_SIZE = 25;
@ -140,12 +145,31 @@ public class FeedManager {
}
private void sendUnreadItemsUpdateBroadcast(Context context, FeedItem item) {
Intent update = new Intent(ACTION_UNREAD_ITEMS_UPDATE);
if (item != null) {
update.putExtra(EXTRA_FEED_ID, item.getFeed().getId());
update.putExtra(EXTRA_FEED_ITEM_ID, item.getId());
}
context.sendBroadcast(update);
}
private void sendQueueUpdateBroadcast(Context context, FeedItem item) {
Intent update = new Intent(ACTION_QUEUE_UPDATE);
if (item != null) {
update.putExtra(EXTRA_FEED_ID, item.getFeed().getId());
update.putExtra(EXTRA_FEED_ITEM_ID, item.getId());
}
context.sendBroadcast(update);
}
/**
* Sets the 'read'-attribute of a FeedItem. Should be used by all Classes
* instead of the setters of FeedItem.
*/
public void markItemRead(Context context, FeedItem item, boolean read) {
Log.d(TAG, "Setting item with title " + item.getTitle() + " as read/unread");
Log.d(TAG, "Setting item with title " + item.getTitle()
+ " as read/unread");
item.read = read;
setFeedItem(context, item);
if (read == true) {
@ -154,6 +178,7 @@ public class FeedManager {
unreadItems.add(item);
Collections.sort(unreadItems, new FeedItemPubdateComparator());
}
sendUnreadItemsUpdateBroadcast(context, item);
}
/**
@ -199,6 +224,7 @@ public class FeedManager {
adapter.open();
adapter.setQueue(queue);
adapter.close();
sendQueueUpdateBroadcast(context, item);
}
/** Uses external adapter. */
@ -207,6 +233,7 @@ public class FeedManager {
if (removed) {
adapter.setQueue(queue);
}
}
/** Uses its own adapter. */
@ -218,6 +245,7 @@ public class FeedManager {
adapter.setQueue(queue);
adapter.close();
}
sendQueueUpdateBroadcast(context, item);
}
public void moveQueueItem(Context context, FeedItem item, int delta) {
@ -232,6 +260,7 @@ public class FeedManager {
adapter.setQueue(queue);
adapter.close();
}
sendQueueUpdateBroadcast(context, item);
}
public boolean isInQueue(FeedItem item) {

View File

@ -1,5 +1,10 @@
package de.podfetcher.fragment;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import com.actionbarsherlock.view.ActionMode;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
@ -16,15 +21,34 @@ public class QueueFragment extends ItemlistFragment {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
super.onCreateActionMode(mode, menu);
menu.add(Menu.NONE, R.id.move_up_item, Menu.NONE, R.string.move_up_label);
menu.add(Menu.NONE, R.id.move_down_item, Menu.NONE, R.string.move_down_label);
menu.add(Menu.NONE, R.id.move_up_item, Menu.NONE,
R.string.move_up_label);
menu.add(Menu.NONE, R.id.move_down_item, Menu.NONE,
R.string.move_down_label);
return true;
}
@Override
public void onPause() {
super.onPause();
try {
getActivity().unregisterReceiver(queueUpdate);
} catch (IllegalArgumentException e) {
}
}
@Override
public void onResume() {
super.onResume();
getActivity().registerReceiver(queueUpdate,
new IntentFilter(FeedManager.ACTION_QUEUE_UPDATE));
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
boolean handled = false;
switch(item.getItemId()) {
switch (item.getItemId()) {
case R.id.move_up_item:
manager.moveQueueItem(getActivity(), selectedItem, -1);
handled = true;
@ -33,12 +57,21 @@ public class QueueFragment extends ItemlistFragment {
manager.moveQueueItem(getActivity(), selectedItem, 1);
handled = true;
break;
default:
handled = super.onActionItemClicked(mode, item);
default:
handled = super.onActionItemClicked(mode, item);
}
fila.notifyDataSetChanged();
mode.finish();
return handled;
}
private BroadcastReceiver queueUpdate = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
fila.notifyDataSetChanged();
}
};
}

View File

@ -1,5 +1,9 @@
package de.podfetcher.fragment;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import de.podfetcher.feed.FeedManager;
/** Contains all unread items. */
@ -10,4 +14,30 @@ public class UnreadItemlistFragment extends ItemlistFragment {
}
@Override
public void onPause() {
super.onPause();
try {
getActivity().unregisterReceiver(unreadItemsUpdate);
} catch (IllegalArgumentException e) {
}
}
@Override
public void onResume() {
super.onResume();
getActivity().registerReceiver(unreadItemsUpdate,
new IntentFilter(FeedManager.ACTION_UNREAD_ITEMS_UPDATE));
}
private BroadcastReceiver unreadItemsUpdate = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
fila.notifyDataSetChanged();
}
};
}