Search in sources :

Example 1 with AggregatedPerformance

use of fr.neamar.lolgamedata.pojo.AggregatedPerformance 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

NoConnectionError (com.android.volley.NoConnectionError)1 RequestQueue (com.android.volley.RequestQueue)1 Response (com.android.volley.Response)1 VolleyError (com.android.volley.VolleyError)1 AggregatedPerformance (fr.neamar.lolgamedata.pojo.AggregatedPerformance)1 NoCacheRetryJsonRequest (fr.neamar.lolgamedata.volley.NoCacheRetryJsonRequest)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 JSONObject (org.json.JSONObject)1