Implemented FeedManager.Task

FeedManager.Task should be used to do operations in the background and
let callers specify a callback object to be notified when the operation
has completed.
This commit is contained in:
daniel oeh 2012-10-24 21:08:18 +02:00
parent 647f3ecc39
commit 0fb4e9582b
1 changed files with 49 additions and 2 deletions

View File

@ -627,7 +627,7 @@ public class FeedManager {
if (itemIndex != -1 && itemIndex < (queue.size() - 1)) {
return queue.get(itemIndex + 1);
}
}
}
return null;
}
@ -1145,7 +1145,8 @@ public class FeedManager {
mediaIds.add(String.valueOf(mediaId));
item.setMedia(new FeedMedia(mediaId, item));
}
item.read = (itemlistCursor.getInt(PodDBAdapter.IDX_FI_SMALL_READ) > 0) ? true
item.read = (itemlistCursor
.getInt(PodDBAdapter.IDX_FI_SMALL_READ) > 0) ? true
: false;
item.setItemIdentifier(itemlistCursor
.getString(PodDBAdapter.IDX_FI_SMALL_ITEM_IDENTIFIER));
@ -1337,4 +1338,50 @@ public class FeedManager {
return playbackHistory;
}
/** Is called by a FeedManagerTask after completion. */
public interface TaskCallback {
void onCompletion();
}
/** A runnable that can post a callback to a handler after completion. */
abstract class Task implements Runnable {
private Handler handler;
private TaskCallback callback;
/**
* Standard contructor. No callbacks are going to be posted to a
* handler.
*/
public Task() {
super();
}
/**
* The Task will post a Runnable to 'handler' that will execute the
* 'callback' after completion.
*/
public Task(Handler handler, TaskCallback callback) {
super();
this.handler = handler;
this.callback = callback;
}
@Override
public final void run() {
execute();
if (handler != null && callback != null) {
handler.post(new Runnable() {
@Override
public void run() {
callback.onCompletion();
}
});
}
}
/** This method will be executed in the same thread as the run() method. */
public abstract void execute();
}
}