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,7 +1366,7 @@ public class FeedManager {
/** Is called by a FeedManagerTask after completion. */ /** Is called by a FeedManagerTask after completion. */
public interface TaskCallback { public interface TaskCallback {
void onCompletion(); void onCompletion(Cursor result);
} }
/** A runnable that can post a callback to a handler after completion. */ /** A runnable that can post a callback to a handler after completion. */
@ -1374,6 +1374,9 @@ public class FeedManager {
private Handler handler; private Handler handler;
private TaskCallback callback; 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 * Standard contructor. No callbacks are going to be posted to a
* handler. * handler.
@ -1399,7 +1402,7 @@ public class FeedManager {
handler.post(new Runnable() { handler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
callback.onCompletion(); callback.onCompletion(result);
} }
}); });
} }
@ -1408,6 +1411,10 @@ public class FeedManager {
/** This method will be executed in the same thread as the run() method. */ /** This method will be executed in the same thread as the run() method. */
public abstract void execute(); 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.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.database.Cursor;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
@ -113,7 +114,7 @@ public class ItemDescriptionFragment extends SherlockFragment {
FeedManager.getInstance().loadExtraInformationOfItem( FeedManager.getInstance().loadExtraInformationOfItem(
getActivity(), item, new FeedManager.TaskCallback() { getActivity(), item, new FeedManager.TaskCallback() {
@Override @Override
public void onCompletion() { public void onCompletion(Cursor result) {
startLoader(); startLoader();
} }
}); });