Search in sources :

Example 6 with JsonHttpResponseHandler

use of com.loopj.android.http.JsonHttpResponseHandler in project app by TourLive.

the class APIClient method getJudgments.

public static String getJudgments(String url, RequestParams params) {
    final String[] messages = { "success" };
    APIClient.get(url, null, new JsonHttpResponseHandler() {

        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject data) {
            try {
                Parser.parseJudgmentsAndPersist(data.getJSONObject("data").getJSONArray("judgements"), stageNr);
                messages[0] = "success";
            } catch (Exception ex) {
                messages[0] = ex.getMessage();
            }
        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONArray riders) {
        // Not needed and therefore not implemented
        }

        @Override
        public void onFailure(int error, Header[] headers, Throwable throwable, JSONObject riders) {
            if (throwable.getMessage().equals(throwableType)) {
                messages[0] = readTimeOutMessage + throwable.getMessage();
            } else {
                messages[0] = throwable.getMessage();
            }
        }
    });
    return messages[0];
}
Also used : Header(cz.msebera.android.httpclient.Header) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JsonHttpResponseHandler(com.loopj.android.http.JsonHttpResponseHandler) JSONException(org.json.JSONException)

Example 7 with JsonHttpResponseHandler

use of com.loopj.android.http.JsonHttpResponseHandler in project app by TourLive.

the class APIClient method getStages.

public static String getStages(String url, RequestParams params) {
    final String[] messages = { "success" };
    APIClient.get(url, null, new JsonHttpResponseHandler() {

        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject data) {
        // Not needed and therefore not implemented
        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONArray stages) {
            try {
                for (int i = 0; i < stages.length(); i++) {
                    JSONObject stage = stages.getJSONObject(i);
                    if (stage.getInt("stageId") == Integer.valueOf(stageId)) {
                        // gets the second last stage, cause of data leak on API
                        stageNr = i;
                    }
                }
                Parser.parseStagesAndPersist(stages, stageNr);
                messages[0] = "success";
            } catch (Exception ex) {
                messages[0] = ex.getMessage();
            }
        }

        @Override
        public void onFailure(int error, Header[] headers, Throwable throwable, JSONObject riders) {
            if (throwable.getMessage().equals(throwableType)) {
                messages[0] = readTimeOutMessage + throwable.getMessage();
            } else {
                messages[0] = throwable.getMessage();
            }
        }
    });
    return messages[0];
}
Also used : Header(cz.msebera.android.httpclient.Header) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JsonHttpResponseHandler(com.loopj.android.http.JsonHttpResponseHandler) JSONException(org.json.JSONException)

Example 8 with JsonHttpResponseHandler

use of com.loopj.android.http.JsonHttpResponseHandler in project app by TourLive.

the class APIClient method getMaillots.

public static String getMaillots(String url, RequestParams params) {
    final String[] messages = { "success" };
    APIClient.get(url, null, new JsonHttpResponseHandler() {

        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject data) {
        // Not needed and therefore not implemented
        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONArray maillots) {
            try {
                Parser.parseMaillotsAndPersist(maillots);
                messages[0] = "success";
            } catch (Exception ex) {
                messages[0] = ex.getMessage();
            }
        }

        @Override
        public void onFailure(int error, Header[] headers, Throwable throwable, JSONObject riders) {
            if (throwable.getMessage().equals(throwableType)) {
                messages[0] = readTimeOutMessage + throwable.getMessage();
            } else {
                messages[0] = throwable.getMessage();
            }
        }
    });
    return messages[0];
}
Also used : Header(cz.msebera.android.httpclient.Header) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JsonHttpResponseHandler(com.loopj.android.http.JsonHttpResponseHandler) JSONException(org.json.JSONException)

Example 9 with JsonHttpResponseHandler

use of com.loopj.android.http.JsonHttpResponseHandler in project app by TourLive.

the class APIClient method postToAPI.

public static void postToAPI(String url, RequestParams params) {
    if (Looper.myLooper() == null)
        Looper.prepare();
    uiHandler = new Handler();
    APIClient.post(url, null, new JsonHttpResponseHandler() {

        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject data) {
            try {
                uiHandler.post(() -> {
                    new String("successfully");
                });
            } catch (Exception ex) {
                uiHandler.post(ex::getMessage);
            }
        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONArray data) {
            try {
            // Not needed
            } catch (Exception ex) {
                uiHandler.post(ex::getMessage);
            }
        }

        @Override
        public void onFailure(int error, Header[] headers, Throwable throwable, JSONObject riders) {
            uiHandler.post(throwable::getMessage);
        }
    });
}
Also used : Header(cz.msebera.android.httpclient.Header) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JsonHttpResponseHandler(com.loopj.android.http.JsonHttpResponseHandler) Handler(android.os.Handler) AsyncHttpResponseHandler(com.loopj.android.http.AsyncHttpResponseHandler) JsonHttpResponseHandler(com.loopj.android.http.JsonHttpResponseHandler) JSONException(org.json.JSONException)

Example 10 with JsonHttpResponseHandler

use of com.loopj.android.http.JsonHttpResponseHandler in project app by TourLive.

the class APIClient method getActualRaceId.

public static String getActualRaceId(String url, RequestParams params) {
    final String[] messages = { "success" };
    APIClient.get(url, null, new JsonHttpResponseHandler() {

        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject data) {
        // Not needed and therefore not implemented
        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONArray settings) {
            try {
                stageId = settings.getJSONObject(0).getString("parameter");
                raceId = settings.getJSONObject(1).getString("parameter");
                messages[0] = "success";
            } catch (JSONException ex) {
                messages[0] = ex.getMessage();
            }
        }

        @Override
        public void onFailure(int error, Header[] headers, Throwable throwable, JSONObject riders) {
            if (throwable.getMessage().equals(throwableType)) {
                messages[0] = readTimeOutMessage + throwable.getMessage();
            } else {
                messages[0] = throwable.getMessage();
            }
        }
    });
    return messages[0];
}
Also used : Header(cz.msebera.android.httpclient.Header) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JsonHttpResponseHandler(com.loopj.android.http.JsonHttpResponseHandler)

Aggregations

JsonHttpResponseHandler (com.loopj.android.http.JsonHttpResponseHandler)10 JSONArray (org.json.JSONArray)10 JSONObject (org.json.JSONObject)10 Header (cz.msebera.android.httpclient.Header)9 JSONException (org.json.JSONException)9 Handler (android.os.Handler)2 AsyncHttpResponseHandler (com.loopj.android.http.AsyncHttpResponseHandler)2 Intent (android.content.Intent)1 Uri (android.net.Uri)1 Message (android.os.Message)1 Animation (com.zhan_dui.model.Animation)1