FeedManager tasks can now return a result on completion

This commit is contained in:
daniel oeh 2012-10-28 14:11:08 +01:00
parent dfc2b4802a
commit 50b02ff77e
2 changed files with 11 additions and 3 deletions

View File

@ -1366,13 +1366,16 @@ public class FeedManager {
/** Is called by a FeedManagerTask after completion. */
public interface TaskCallback {
void onCompletion();
void onCompletion(Cursor result);
}
/** A runnable that can post a callback to a handler after completion. */
abstract class Task implements Runnable {
private Handler handler;
private TaskCallback callback;
/** Can be used for returning database query results. */
private Cursor result;
/**
* Standard contructor. No callbacks are going to be posted to a
@ -1399,7 +1402,7 @@ public class FeedManager {
handler.post(new Runnable() {
@Override
public void run() {
callback.onCompletion();
callback.onCompletion(result);
}
});
}
@ -1407,6 +1410,10 @@ public class FeedManager {
/** This method will be executed in the same thread as the run() method. */
public abstract void execute();
protected void setResult(Cursor c) {
result = c;
}
}

View File

@ -4,6 +4,7 @@ import org.apache.commons.lang3.StringEscapeUtils;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
@ -113,7 +114,7 @@ public class ItemDescriptionFragment extends SherlockFragment {
FeedManager.getInstance().loadExtraInformationOfItem(
getActivity(), item, new FeedManager.TaskCallback() {
@Override
public void onCompletion() {
public void onCompletion(Cursor result) {
startLoader();
}
});