Queue and unreadItemlist now update more frequently
This commit is contained in:
parent
d79dd76d9a
commit
1cc0d763ba
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -175,7 +200,7 @@ public class FeedManager {
|
|||
refreshFeed(context, feed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void refreshFeed(Context context, Feed feed) {
|
||||
requester.downloadFeed(context, new Feed(feed.getDownload_url(),
|
||||
new Date()));
|
||||
|
@ -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,8 +245,9 @@ public class FeedManager {
|
|||
adapter.setQueue(queue);
|
||||
adapter.close();
|
||||
}
|
||||
sendQueueUpdateBroadcast(context, item);
|
||||
}
|
||||
|
||||
|
||||
public void moveQueueItem(Context context, FeedItem item, int delta) {
|
||||
Log.d(TAG, "Moving queue item");
|
||||
int itemIndex = queue.indexOf(item);
|
||||
|
@ -232,6 +260,7 @@ public class FeedManager {
|
|||
adapter.setQueue(queue);
|
||||
adapter.close();
|
||||
}
|
||||
sendQueueUpdateBroadcast(context, item);
|
||||
}
|
||||
|
||||
public boolean isInQueue(FeedItem item) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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. */
|
||||
|
@ -7,7 +11,33 @@ public class UnreadItemlistFragment extends ItemlistFragment {
|
|||
|
||||
public UnreadItemlistFragment() {
|
||||
super(FeedManager.getInstance().getUnreadItems(), true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue