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") + "®ion=" + 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();
}
}
Aggregations