use of fr.neamar.lolgamedata.pojo.Counters in project teamward-client by Neamar.
the class CounterChampionsFragment method loadCounters.
private void loadCounters(final RecyclerView recyclerView, final Account account, final String role) {
// Instantiate the RequestQueue.
final RequestQueue queue = VolleyQueue.newRequestQueue(getActivity());
final String summonerName = account.summonerName;
String region = account.region;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
final int requiredChampionMastery = Integer.parseInt(prefs.getString("counter_required_mastery", "3"));
try {
String url = ((LolApplication) getActivity().getApplication()).getApiUrl() + "/summoner/counter?summoner=" + URLEncoder.encode(summonerName, "UTF-8") + "®ion=" + region.toLowerCase(Locale.ROOT) + "&role=" + role.toLowerCase(Locale.ROOT) + "&level=" + requiredChampionMastery;
if (BuildConfig.DEBUG && summonerName.equalsIgnoreCase("MOCK")) {
url = "https://gist.githubusercontent.com/Neamar/eb278b4d5f188546f56028c3a0310507/raw/counters.json";
}
NoCacheRetryJsonRequest jsonRequest = new NoCacheRetryJsonRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
loadIndicator.setVisibility(View.GONE);
try {
Counters counters = new Counters(account, role, response);
adapter = new CounterChampionAdapter(counters);
recyclerView.setAdapter(adapter);
Log.i(TAG, "Loaded counters!");
Activity activity = getActivity();
if (activity != null) {
Tracker.trackViewCounters(activity, account, role, requiredChampionMastery);
}
} catch (JSONException e) {
e.printStackTrace();
}
queue.stop();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
loadIndicator.setVisibility(View.GONE);
Log.e(TAG, error.toString());
queue.stop();
error.printStackTrace();
if (error instanceof NoConnectionError) {
if (getActivity() != null) {
displaySnack(getString(R.string.no_internet_connection));
}
}
try {
String responseBody = new String(error.networkResponse.data, "utf-8");
Log.i(TAG, responseBody);
displaySnack(responseBody);
Activity activity = getActivity();
if (activity != null) {
Tracker.trackErrorViewingCounters(activity, account, responseBody.replace("Error:", ""));
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (NullPointerException e) {
// Do nothing, no text content in the HTTP reply.
}
}
});
queue.add(jsonRequest);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
use of fr.neamar.lolgamedata.pojo.Counters in project teamward-client by Neamar.
the class CounterChampionAdapter method filter.
public void filter(String filter) {
counters = new Counters();
Locale locale = Locale.getDefault();
for (int i = 0; i < allCounters.counters.size(); i++) {
if (allCounters.counters.get(i).champion.name.toLowerCase(locale).startsWith(filter.toLowerCase(locale))) {
counters.counters.add(allCounters.counters.get(i));
}
}
notifyDataSetChanged();
}
Aggregations