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 { public class FeedManager {
private static final String TAG = "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. */ /** Number of completed Download status entries to store. */
private static final int DOWNLOAD_LOG_SIZE = 25; 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 * Sets the 'read'-attribute of a FeedItem. Should be used by all Classes
* instead of the setters of FeedItem. * instead of the setters of FeedItem.
*/ */
public void markItemRead(Context context, FeedItem item, boolean read) { 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; item.read = read;
setFeedItem(context, item); setFeedItem(context, item);
if (read == true) { if (read == true) {
@ -154,6 +178,7 @@ public class FeedManager {
unreadItems.add(item); unreadItems.add(item);
Collections.sort(unreadItems, new FeedItemPubdateComparator()); Collections.sort(unreadItems, new FeedItemPubdateComparator());
} }
sendUnreadItemsUpdateBroadcast(context, item);
} }
/** /**
@ -199,6 +224,7 @@ public class FeedManager {
adapter.open(); adapter.open();
adapter.setQueue(queue); adapter.setQueue(queue);
adapter.close(); adapter.close();
sendQueueUpdateBroadcast(context, item);
} }
/** Uses external adapter. */ /** Uses external adapter. */
@ -207,6 +233,7 @@ public class FeedManager {
if (removed) { if (removed) {
adapter.setQueue(queue); adapter.setQueue(queue);
} }
} }
/** Uses its own adapter. */ /** Uses its own adapter. */
@ -218,6 +245,7 @@ public class FeedManager {
adapter.setQueue(queue); adapter.setQueue(queue);
adapter.close(); adapter.close();
} }
sendQueueUpdateBroadcast(context, item);
} }
public void moveQueueItem(Context context, FeedItem item, int delta) { public void moveQueueItem(Context context, FeedItem item, int delta) {
@ -232,6 +260,7 @@ public class FeedManager {
adapter.setQueue(queue); adapter.setQueue(queue);
adapter.close(); adapter.close();
} }
sendQueueUpdateBroadcast(context, item);
} }
public boolean isInQueue(FeedItem item) { public boolean isInQueue(FeedItem item) {

View File

@ -1,5 +1,10 @@
package de.podfetcher.fragment; 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.ActionMode;
import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.MenuItem;
@ -16,11 +21,30 @@ public class QueueFragment extends ItemlistFragment {
@Override @Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) { public boolean onCreateActionMode(ActionMode mode, Menu menu) {
super.onCreateActionMode(mode, 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_up_item, Menu.NONE,
menu.add(Menu.NONE, R.id.move_down_item, Menu.NONE, R.string.move_down_label); R.string.move_up_label);
menu.add(Menu.NONE, R.id.move_down_item, Menu.NONE,
R.string.move_down_label);
return true; 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 @Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) { public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
boolean handled = false; boolean handled = false;
@ -41,4 +65,13 @@ public class QueueFragment extends ItemlistFragment {
return handled; 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; 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; import de.podfetcher.feed.FeedManager;
/** Contains all unread items. */ /** 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();
}
};
} }