Search in sources :

Example 1 with JoinRequestIDsForJson

use of br.ufrj.caronae.models.modelsforjson.JoinRequestIDsForJson in project caronae-android by caronae.

the class RequestersAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RequestersAdapter.ViewHolder holder, final int position) {
    final User user = users.get(position);
    holder.name_tv.setText(user.getName());
    holder.course_tv.setText(user.getCourse());
    String profilePicUrl = user.getProfilePicUrl();
    if (profilePicUrl != null && !profilePicUrl.isEmpty()) {
        Picasso.with(activity).load(profilePicUrl).placeholder(R.drawable.user_pic).error(R.drawable.user_pic).transform(new RoundedTransformation()).into(holder.photo_iv);
    } else {
        holder.photo_iv.setImageResource(R.drawable.user_pic);
    }
    holder.photo_iv.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent intent = new Intent(activity, ProfileAct.class);
            intent.putExtra("user", new Gson().toJson(user));
            intent.putExtra("from", "requesters");
            activity.startActivity(intent);
        }
    });
    holder.accept_bt.setTextColor(color);
    holder.accept_bt.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            final ProgressDialog pd = ProgressDialog.show(activity, "", activity.getString(R.string.wait), true, true);
            CaronaeAPI.service(activity.getApplicationContext()).answerJoinRequest(String.valueOf(rideId), new JoinRequestIDsForJson(user.getDbId(), true)).enqueue(new Callback<ResponseBody>() {

                @Override
                public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                    if (response.isSuccessful()) {
                        pd.dismiss();
                        Util.toast(R.string.requestAccepted);
                        users.remove(user);
                        notifyItemRemoved(holder.getAdapterPosition());
                        if (users.isEmpty())
                            activity.finish();
                        FirebaseTopicsHandler.subscribeFirebaseTopic(rideId + "");
                    } else {
                        Util.treatResponseFromServer(response);
                        pd.dismiss();
                        Log.e("answerJoinRequest", response.message());
                        Util.toast(R.string.errorAnsweRequest);
                    }
                }

                @Override
                public void onFailure(Call<ResponseBody> call, Throwable t) {
                    pd.dismiss();
                    Log.e("answerJoinRequest", t.getMessage());
                    Util.toast(R.string.errorAnsweRequest);
                }
            });
        }
    });
    holder.reject_bt.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            final ProgressDialog pd = ProgressDialog.show(activity, "", activity.getString(R.string.wait), true, true);
            CaronaeAPI.service(activity.getApplicationContext()).answerJoinRequest(String.valueOf(rideId), new JoinRequestIDsForJson(user.getDbId(), false)).enqueue(new Callback<ResponseBody>() {

                @Override
                public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                    if (response.isSuccessful()) {
                        pd.dismiss();
                        Util.toast(R.string.requestRejected);
                        users.remove(user);
                        notifyItemRemoved(holder.getAdapterPosition());
                    } else {
                        Util.treatResponseFromServer(response);
                        pd.dismiss();
                        Log.e("answerJoinRequest", response.message());
                    }
                }

                @Override
                public void onFailure(Call<ResponseBody> call, Throwable t) {
                    pd.dismiss();
                    Log.e("answerJoinRequest", t.getMessage());
                }
            });
        }
    });
}
Also used : Call(retrofit2.Call) User(br.ufrj.caronae.models.User) Gson(com.google.gson.Gson) Intent(android.content.Intent) ProgressDialog(android.app.ProgressDialog) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) JoinRequestIDsForJson(br.ufrj.caronae.models.modelsforjson.JoinRequestIDsForJson) Response(retrofit2.Response) ProfileAct(br.ufrj.caronae.acts.ProfileAct) Callback(retrofit2.Callback) RoundedTransformation(br.ufrj.caronae.RoundedTransformation)

Aggregations

ProgressDialog (android.app.ProgressDialog)1 Intent (android.content.Intent)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 RoundedTransformation (br.ufrj.caronae.RoundedTransformation)1 ProfileAct (br.ufrj.caronae.acts.ProfileAct)1 User (br.ufrj.caronae.models.User)1 JoinRequestIDsForJson (br.ufrj.caronae.models.modelsforjson.JoinRequestIDsForJson)1 Gson (com.google.gson.Gson)1 Call (retrofit2.Call)1 Callback (retrofit2.Callback)1 Response (retrofit2.Response)1