Search in sources :

Example 1 with Sponsers

use of com.manan.dev.ec2018app.Models.Sponsers in project EC2018App by Manan-YMCA.

the class SponserAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
    final Sponsers sponsers = sponsersList.get(position);
    holder.sname.setText(sponsers.getSname());
    Picasso.with(mContext).load(sponsers.getImageUrl()).resize(750, 500).into(holder.sponserPic);
    holder.title.setText(sponsers.getTitle());
    holder.cardview.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Uri uri = Uri.parse(sponsers.getUrl());
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            mContext.startActivity(intent);
        }
    });
}
Also used : Sponsers(com.manan.dev.ec2018app.Models.Sponsers) Intent(android.content.Intent) CardView(android.support.v7.widget.CardView) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) Uri(android.net.Uri)

Example 2 with Sponsers

use of com.manan.dev.ec2018app.Models.Sponsers 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();
    }
}
Also used : VolleyError(com.android.volley.VolleyError) SponserAdapter(com.manan.dev.ec2018app.Adapters.SponserAdapter) Sponsers(com.manan.dev.ec2018app.Models.Sponsers) StringRequest(com.android.volley.toolbox.StringRequest) JSONArray(org.json.JSONArray) ProgressDialog(android.app.ProgressDialog) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Response(com.android.volley.Response) JSONObject(org.json.JSONObject) RequestQueue(com.android.volley.RequestQueue) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 TextView (android.widget.TextView)2 Sponsers (com.manan.dev.ec2018app.Models.Sponsers)2 ProgressDialog (android.app.ProgressDialog)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1 CardView (android.support.v7.widget.CardView)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 ImageView (android.widget.ImageView)1 RequestQueue (com.android.volley.RequestQueue)1 Response (com.android.volley.Response)1 VolleyError (com.android.volley.VolleyError)1 StringRequest (com.android.volley.toolbox.StringRequest)1 SponserAdapter (com.manan.dev.ec2018app.Adapters.SponserAdapter)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1