use of com.manan.dev.ec2018app.Adapters.SponserAdapter 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();
}
}
Aggregations