git.fiddlerwoaroof.com
Raw Blame History
package com.joinmarrow.marrow.tasks;

import android.os.AsyncTask;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.joinmarrow.marrow.R;

import org.jdeferred.Deferred;

import java.io.IOException;

import us.monoid.json.JSONArray;
import us.monoid.json.JSONException;
import us.monoid.json.JSONObject;
import us.monoid.web.Resty;

/**
 * Created by edwlan on 4/5/15.
 */
public class GetBoneTask extends AsyncTask<String, Void, JSONObject> {
    Deferred taskDeferred;
    private String endpoint;

    public GetBoneTask(Deferred d, String url) {
        super();
        endpoint = url.concat("/api/bones/u/");
        taskDeferred = d;
    }

    protected JSONObject doInBackground(String... user) {
        JSONObject result = new JSONObject();
        if (null != user) {
            try {
                result = new Resty().json(endpoint.concat(user[0])).toObject();
            } catch (IOException | JSONException e) {
                Log.e("marrow", e.getMessage());
            } finally {
                Log.i("marrow", result.toString());
            }
        }
        return result;
    }
    //TODO: use deferred to trigger view update
    protected void onPostExecute(JSONObject result) {
        JSONArray data = new JSONArray();
        try {
            data = result.getJSONArray("marrow");
        } catch (JSONException e) {
            Log.i("marrow", "unexpected JSONException");
            e.printStackTrace();
            Log.d("marrow", result.toString());
        }
        taskDeferred.resolve(data);
    }
}