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());
}
});
}
});
}
Aggregations