Search in sources :

Example 76 with Response

use of com.android.volley.Response in project easy by MehdiBenmesa.

the class NoteService method getNoteByStudentByModule.

public void getNoteByStudentByModule(String moduleId, final INote callBack) throws JSONException {
    System.out.println("AVANT ABSENCE 2 ");
    CustomRequestArray jsonReq = new CustomRequestArray(Request.Method.GET, GET_NOTE_BY_MODULES + "/" + App.getInstance().getUser().getString("_id") + "/" + moduleId, null, new Response.Listener<JSONArray>() {

        @Override
        public void onResponse(JSONArray response) {
            callBack.onDataReceived(response);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
        }
    });
    App.getInstance().addToRequestQueue(jsonReq);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) CustomRequestArray(dz.easy.androidclient.Util.CustomRequestArray) JSONArray(org.json.JSONArray)

Example 77 with Response

use of com.android.volley.Response in project easy by MehdiBenmesa.

the class AbsenceService method getAbsneceBySeance.

public void getAbsneceBySeance(String idSeance, final IAbsence callBack) {
    CustomRequestArray jsonReq = new CustomRequestArray(Request.Method.GET, GET_ABSENCE_BY_SEANCE + "/" + idSeance, null, new Response.Listener<JSONArray>() {

        @Override
        public void onResponse(JSONArray response) {
            callBack.onDataReceived(response);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
        }
    });
    App.getInstance().addToRequestQueue(jsonReq);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) CustomRequestArray(dz.easy.androidclient.Util.CustomRequestArray) JSONArray(org.json.JSONArray)

Example 78 with Response

use of com.android.volley.Response in project WordPress-Android by wordpress-mobile.

the class ReaderPostActions method bumpPageViewForPost.

public static void bumpPageViewForPost(SiteStore siteStore, ReaderPost post) {
    if (post == null) {
        return;
    }
    // don't bump stats for posts in sites the current user is an admin of, unless
    // this is a private post since we count views for private posts from owner or member
    SiteModel site = siteStore.getSiteBySiteId(post.blogId);
    // site will be null here if the user is not the owner or a member of the site
    if (site != null && !post.isPrivate) {
        AppLog.d(T.READER, "skipped bump page view - user is admin");
        return;
    }
    Response.Listener<String> listener = new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            AppLog.d(T.READER, "bump page view succeeded");
        }
    };
    Response.ErrorListener errorListener = new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError volleyError) {
            AppLog.e(T.READER, volleyError);
            AppLog.w(T.READER, "bump page view failed");
        }
    };
    Request request = new StringRequest(Request.Method.GET, getTrackingPixelForPost(post), listener, errorListener) {

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            // call will fail without correct refer(r)er
            Map<String, String> headers = new HashMap<>();
            headers.put("Referer", TRACKING_REFERRER);
            return headers;
        }
    };
    WordPress.sRequestQueue.add(request);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) UpdateResultListener(org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResultListener) HashMap(java.util.HashMap) StringRequest(com.android.volley.toolbox.StringRequest) RestRequest(com.wordpress.rest.RestRequest) StringRequest(com.android.volley.toolbox.StringRequest) Request(com.android.volley.Request) SiteModel(org.wordpress.android.fluxc.model.SiteModel)

Example 79 with Response

use of com.android.volley.Response in project WordPress-Android by wordpress-mobile.

the class ReaderVideoUtils method requestVimeoThumbnail.

/*
     * unlike YouTube thumbnails, Vimeo thumbnails require network request
     */
public static void requestVimeoThumbnail(final String videoUrl, final VideoThumbnailListener thumbListener) {
    // useless without a listener
    if (thumbListener == null)
        return;
    String id = getVimeoVideoId(videoUrl);
    if (TextUtils.isEmpty(id)) {
        thumbListener.onResponse(false, null);
        return;
    }
    Response.Listener<JSONArray> listener = new Response.Listener<JSONArray>() {

        public void onResponse(JSONArray response) {
            String thumbnailUrl = null;
            if (response != null && response.length() > 0) {
                JSONObject json = response.optJSONObject(0);
                if (json != null && json.has("thumbnail_large"))
                    thumbnailUrl = JSONUtils.getString(json, "thumbnail_large");
            }
            if (TextUtils.isEmpty(thumbnailUrl)) {
                thumbListener.onResponse(false, null);
            } else {
                thumbListener.onResponse(true, thumbnailUrl);
            }
        }
    };
    Response.ErrorListener errorListener = new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError volleyError) {
            AppLog.e(T.READER, volleyError);
            thumbListener.onResponse(false, null);
        }
    };
    String url = "https://vimeo.com/api/v2/video/" + id + ".json";
    JsonArrayRequest request = new JsonArrayRequest(url, listener, errorListener);
    WordPress.sRequestQueue.add(request);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) JsonArrayRequest(com.android.volley.toolbox.JsonArrayRequest) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Example 80 with Response

use of com.android.volley.Response in project WordPress-Android by wordpress-mobile.

the class ReaderBlogActions method checkUrlReachable.

/*
     * tests whether the passed url can be reached - does NOT use authentication, and does not
     * account for 404 replacement pages used by ISPs such as Charter
     */
public static void checkUrlReachable(final String blogUrl, final ReaderActions.OnRequestListener requestListener) {
    // listener is required
    if (requestListener == null)
        return;
    Response.Listener<String> listener = new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            requestListener.onSuccess();
        }
    };
    Response.ErrorListener errorListener = new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError volleyError) {
            AppLog.e(T.READER, volleyError);
            int statusCode;
            // since a redirect to an unauthorized url may return a 301 rather than a 401
            if (volleyError instanceof com.android.volley.AuthFailureError) {
                statusCode = 401;
            } else {
                statusCode = VolleyUtils.statusCodeFromVolleyError(volleyError);
            }
            // success since it means the blog url is reachable
            if (statusCode == 301) {
                requestListener.onSuccess();
            } else {
                requestListener.onFailure(statusCode);
            }
        }
    };
    // TODO: this should be a HEAD request, but even though Volley supposedly supports HEAD
    // using it results in "java.lang.IllegalStateException: Unknown method type"
    StringRequest request = new StringRequest(Request.Method.GET, blogUrl, listener, errorListener);
    WordPress.sRequestQueue.add(request);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) UpdateBlogInfoListener(org.wordpress.android.ui.reader.actions.ReaderActions.UpdateBlogInfoListener) ActionListener(org.wordpress.android.ui.reader.actions.ReaderActions.ActionListener) StringRequest(com.android.volley.toolbox.StringRequest)

Aggregations

Response (com.android.volley.Response)110 VolleyError (com.android.volley.VolleyError)108 JSONObject (org.json.JSONObject)80 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)60 RequestQueue (com.android.volley.RequestQueue)58 HashMap (java.util.HashMap)57 JSONException (org.json.JSONException)57 User (model.User)49 JSONArray (org.json.JSONArray)29 CustomRequestArray (dz.easy.androidclient.Util.CustomRequestArray)18 Context (android.content.Context)17 Toast (android.widget.Toast)17 StringRequest (com.android.volley.toolbox.StringRequest)14 TextView (android.widget.TextView)9 CustomRequest (dz.easy.androidclient.Util.CustomRequest)9 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)7 Intent (android.content.Intent)6 GridLayoutManager (android.support.v7.widget.GridLayoutManager)6 JsonArrayRequest (com.android.volley.toolbox.JsonArrayRequest)6 MaterialViewPagerHeaderDecorator (com.github.florent37.materialviewpager.header.MaterialViewPagerHeaderDecorator)5