use of com.android.volley.RequestQueue 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();
}
}
use of com.android.volley.RequestQueue in project EC2018App by Manan-YMCA.
the class SponsorsActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sponsors);
sponserList = new ArrayList<>();
progressBar = new ProgressDialog(this);
progressBar.setMessage("Loading Sponsors...");
// progressBar.setCancelable(false);
progressBar.setCanceledOnTouchOutside(false);
progressBar.show();
noSponTV = findViewById(R.id.tv_no_spon);
noSponTV.setVisibility(View.GONE);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(SponsorsActivity.this));
mAdapter = new SponserAdapter(SponsorsActivity.this, sponserList);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(mAdapter);
findViewById(R.id.spon_back_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
if (isNetworkAvailable()) {
RequestQueue queue = Volley.newRequestQueue(SponsorsActivity.this);
String url = "https://elementsculmyca2018.herokuapp.com/api/v1/sponsors/getsponsors";
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject object = new JSONObject(response);
JSONArray sponsersArray = object.getJSONArray("data");
for (int i = 0; i < sponsersArray.length(); i++) {
Sponsers sponsers = new Sponsers();
JSONObject currEvent = sponsersArray.getJSONObject(i);
if (currEvent.has("name")) {
sponsers.setSname(currEvent.getString("name"));
}
if (currEvent.has("title"))
sponsers.setTitle(currEvent.getString("title"));
if (currEvent.has("_id"))
sponsers.setId(currEvent.getString("_id"));
if (currEvent.has("rank"))
sponsers.setRank(currEvent.getInt("rank"));
if (currEvent.has("logo"))
sponsers.setImageUrl(currEvent.getString("logo"));
if (currEvent.has("url"))
sponsers.setUrl(currEvent.getString("url"));
sponserList.add(sponsers);
progressBar.dismiss();
}
mAdapter.notifyDataSetChanged();
} catch (Exception e) {
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressBar.dismiss();
noSponTV.setVisibility(View.VISIBLE);
}
});
queue.add(stringRequest);
} else {
progressBar.dismiss();
noSponTV.setVisibility(View.VISIBLE);
MDToast.makeText(this, "No Internet Connection", Toast.LENGTH_SHORT, MDToast.TYPE_ERROR).show();
}
}
use of com.android.volley.RequestQueue in project EC2018App by Manan-YMCA.
the class FragmentOtpChecker method sendSMS.
private void sendSMS(final String phone, final String otpNum) {
bar.setVisibility(View.VISIBLE);
String url = getResources().getString(R.string.send_sms_api);
RequestQueue queue = Volley.newRequestQueue(mContext);
StringRequest smsReq = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// TODO
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO
bar.setVisibility(View.GONE);
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("From", "CLMYCA");
params.put("To", phone);
params.put("TemplateName", "culmyca-otp");
params.put("VAR1", otpNum);
return params;
}
};
queue.add(smsReq);
if (ActivityCompat.checkSelfPermission(mContext, android.Manifest.permission.READ_SMS) != PackageManager.PERMISSION_GRANTED) {
bar.setVisibility(View.GONE);
} else {
IncomingSms.bindListener(new SmsListener() {
@Override
public void messageReceived(String messageText) {
if (messageText.contains("Culmyca")) {
otp = messageText.substring(0, 6);
if (otp.length() == 6) {
et1.setText(otp.substring(0, 1));
et2.setText(otp.substring(1, 2));
et3.setText(otp.substring(2, 3));
et4.setText(otp.substring(3, 4));
et5.setText(otp.substring(4, 5));
et6.setText(otp.substring(5, 6));
} else {
bar.setVisibility(View.GONE);
}
} else {
bar.setVisibility(View.GONE);
}
}
});
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
bar.setVisibility(View.GONE);
et1.requestFocus();
}
}, 10000);
}
}
use of com.android.volley.RequestQueue in project EC2018App by Manan-YMCA.
the class LoginActivity method getDetails.
private void getDetails(final UserDetails userDetails, final String phone) {
String url = getResources().getString(R.string.get_user_details_api) + phone;
RequestQueue queue = Volley.newRequestQueue(this);
StringRequest obreq = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject obj1 = new JSONObject(response);
Long success = obj1.getLong("success");
if (success == 1) {
checkAndRequestPermissions();
if (ContextCompat.checkSelfPermission(LoginActivity.this, android.Manifest.permission.READ_SMS) == PackageManager.PERMISSION_GRANTED) {
FragmentManager fm = getFragmentManager();
FragmentOtpChecker otpChecker = new FragmentOtpChecker();
Bundle bundle = new Bundle();
bundle.putString("phone", mobileNum.getText().toString());
otpChecker.setArguments(bundle);
otpChecker.show(fm, "otpCheckerFragment");
}
} else {
pbLogin.setVisibility(View.GONE);
// Snackbar.make(RelativeView, "Please register yourself first!", Snackbar.LENGTH_LONG).show();
MDToast.makeText(LoginActivity.this, "Please register yourself first!", Toast.LENGTH_LONG, MDToast.TYPE_INFO).show();
Intent i = new Intent(LoginActivity.this, RegisterActivity.class).putExtra("parent", "xunbao");
;
startActivity(i);
finish();
}
}// Try and catch are included to handle any errors due to JSON
catch (Exception e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public // Handles errors that occur due to Volley
void onErrorResponse(VolleyError error) {
}
});
queue.add(obreq);
}
use of com.android.volley.RequestQueue in project EC2018App by Manan-YMCA.
the class EventRegister method getDetails.
private void getDetails(final String phone) {
String url = getResources().getString(R.string.get_user_details_api) + phone;
RequestQueue queue = Volley.newRequestQueue(this);
StringRequest obreq = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
// barLoader.setVisibility(View.GONE);
pd1.dismiss();
JSONObject obj1 = new JSONObject(response);
JSONObject obj = obj1.getJSONObject("data");
mainName.setText(obj.getString("name"));
mainmail.setText(obj.getString("email"));
mainClg.setText(obj.getString("college"));
mainPhone.setText(phone);
userDetails.setmName(obj.getString("name"));
userDetails.setEmail(obj.getString("email"));
userDetails.setmCollege(obj.getString("college"));
userDetails.setmPhone(phone);
}// Try and catch are included to handle any errors due to JSON
catch (Exception e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public // Handles errors that occur due to Volley
void onErrorResponse(VolleyError error) {
}
});
queue.add(obreq);
}
Aggregations