Search in sources :

Example 6 with NoCacheRetryJsonRequest

use of fr.neamar.lolgamedata.volley.NoCacheRetryJsonRequest in project teamward-client by Neamar.

the class PerformanceActivity method downloadPerformance.

public void downloadPerformance() {
    // Instantiate the RequestQueue.
    final RequestQueue queue = VolleyQueue.newRequestQueue(this);
    try {
        String url = ((LolApplication) getApplication()).getApiUrl() + "/summoner/performance?summoner=" + URLEncoder.encode(player.summoner.name, "UTF-8") + "&region=" + player.region + "&champion=" + URLEncoder.encode(player.champion.name, "UTF-8");
        if (BuildConfig.DEBUG && player.summoner.name.equalsIgnoreCase("MOCK")) {
            url = "https://gist.githubusercontent.com/Neamar/eb278b4d5f188546f56028c3a0310507/raw/performance.json";
        }
        NoCacheRetryJsonRequest jsonRequest = new NoCacheRetryJsonRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                ArrayList<Match> matches = Match.getMatches(response);
                AggregatedPerformance aggregated = AggregatedPerformance.getAggregated(response);
                displayPerformance(matches, aggregated);
                Log.i(TAG, "Displaying performance for " + player.summoner.name);
                Tracker.trackPerformanceViewed(PerformanceActivity.this, player, matches.size());
                queue.stop();
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                findViewById(R.id.progressBar).setVisibility(View.GONE);
                Log.e(TAG, error.toString());
                queue.stop();
                if (error instanceof NoConnectionError) {
                    displaySnack(getString(R.string.no_internet_connection));
                    return;
                }
                try {
                    String responseBody = new String(error.networkResponse.data, "utf-8");
                    Log.i(TAG, responseBody);
                    Tracker.trackErrorViewingDetails(PerformanceActivity.this, player.region, responseBody.replace("Error:", ""));
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                } catch (NullPointerException e) {
                // Do nothing, no text content in the HTTP reply.
                }
                findViewById(R.id.matchHistoryHolder).setVisibility(View.INVISIBLE);
            }
        });
        queue.add(jsonRequest);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
}
Also used : VolleyError(com.android.volley.VolleyError) NoCacheRetryJsonRequest(fr.neamar.lolgamedata.volley.NoCacheRetryJsonRequest) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoConnectionError(com.android.volley.NoConnectionError) Response(com.android.volley.Response) JSONObject(org.json.JSONObject) RequestQueue(com.android.volley.RequestQueue) AggregatedPerformance(fr.neamar.lolgamedata.pojo.AggregatedPerformance)

Aggregations

RequestQueue (com.android.volley.RequestQueue)6 Response (com.android.volley.Response)6 VolleyError (com.android.volley.VolleyError)6 NoCacheRetryJsonRequest (fr.neamar.lolgamedata.volley.NoCacheRetryJsonRequest)6 JSONObject (org.json.JSONObject)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 NoConnectionError (com.android.volley.NoConnectionError)3 ProgressDialog (android.app.ProgressDialog)2 JSONException (org.json.JSONException)2 Activity (android.app.Activity)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 TextView (android.widget.TextView)1 LolApplication (fr.neamar.lolgamedata.LolApplication)1 SnackBarActivity (fr.neamar.lolgamedata.SnackBarActivity)1 CounterChampionAdapter (fr.neamar.lolgamedata.adapter.CounterChampionAdapter)1 Account (fr.neamar.lolgamedata.pojo.Account)1 AggregatedPerformance (fr.neamar.lolgamedata.pojo.AggregatedPerformance)1