use of br.ufrj.caronae.models.RideRequestSent in project caronae-android by caronae.
the class RideOfferAct method configureActivityWithRide.
private void configureActivityWithRide(final RideForJson rideWithUsers, boolean isFull) {
final boolean requested = getIntent().getBooleanExtra("requested", false);
if (rideWithUsers == null) {
Util.toast(getString(R.string.act_activeride_rideNUll));
finish();
}
AllRidesFrag.setPageThatWas(rideWithUsers.isGoing());
final User driver = rideWithUsers.getDriver();
final boolean isDriver = driver.getDbId() == App.getUser().getDbId();
int color = Util.getColorbyZone(rideWithUsers.getZone());
join_bt.setBackgroundColor(color);
location_dt.setTextColor(color);
final String location;
if (rideWithUsers.isGoing())
location = rideWithUsers.getNeighborhood() + " ➜ " + rideWithUsers.getHub();
else
location = rideWithUsers.getHub() + " ➜ " + rideWithUsers.getNeighborhood();
String profilePicUrl = driver.getProfilePicUrl();
if (profilePicUrl == null || profilePicUrl.isEmpty()) {
Picasso.with(this.getApplicationContext()).load(R.drawable.user_pic).into(user_pic);
} else {
Picasso.with(this.getApplicationContext()).load(profilePicUrl).placeholder(R.drawable.user_pic).error(R.drawable.user_pic).transform(new RoundedTransformation()).into(user_pic);
}
user_pic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!isDriver) {
// dont allow user to open own profile
Intent intent = new Intent(getApplicationContext(), ProfileAct.class);
intent.putExtra("user", new Gson().toJson(driver));
intent.putExtra("from", "rideoffer");
startActivity(intent);
}
}
});
location_dt.setText(location);
name_dt.setText(driver.getName());
profile_dt.setText(driver.getProfile());
if (rideWithUsers.getRoute().equals("")) {
way_dt.setText("- - -");
} else {
way_dt.setText(rideWithUsers.getRoute());
}
if (rideWithUsers.getPlace().equals("")) {
place_dt.setText("- - -");
} else {
place_dt.setText(rideWithUsers.getPlace());
}
course_dt.setText(driver.getCourse());
if (rideWithUsers.isGoing())
time_dt.setText(getString(R.string.arrivingAt, Util.formatTime(rideWithUsers.getTime())));
else
time_dt.setText(getString(R.string.leavingAt, Util.formatTime(rideWithUsers.getTime())));
time_dt.setTextColor(color);
date_dt.setText(Util.formatBadDateWithoutYear(rideWithUsers.getDate()));
date_dt.setTextColor(color);
if (rideWithUsers.getDescription().equals("")) {
description_dt.setText("- - -");
} else {
description_dt.setText(rideWithUsers.getDescription());
}
if (isDriver) {
join_bt.setVisibility(View.GONE);
} else {
if (requested) {
join_bt.setVisibility(View.GONE);
requested_dt.setVisibility(View.VISIBLE);
} else {
if (isFull) {
join_bt.setText("CARONA CHEIA");
join_bt.setClickable(false);
} else {
join_bt.setClickable(true);
final Context context = this;
join_bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
List<ActiveRide> list = ActiveRide.find(ActiveRide.class, "date = ? and going = ?", rideWithUsers.getDate(), rideWithUsers.isGoing() ? "1" : "0");
if (list != null && !list.isEmpty()) {
Util.toast(getString(R.string.act_rideOffer_rideConflict));
return;
}
com.rey.material.app.Dialog.Builder builder = new SimpleDialog.Builder(R.style.SlideInDialog) {
@Override
protected void onBuildDone(com.rey.material.app.Dialog dialog) {
dialog.layoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
dialog.getWindow().getAttributes().windowAnimations = R.style.SlideInRightDialog;
}
@Override
public void onPositiveActionClicked(com.rey.material.app.DialogFragment fragment) {
final ProgressDialog pd = ProgressDialog.show(context, "", getString(R.string.wait), true, true);
CaronaeAPI.service(context).requestJoin(String.valueOf(rideWithUsers.getDbId())).enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response.isSuccessful()) {
RideRequestSent rideRequest = new RideRequestSent(rideWithUsers.getDbId(), rideWithUsers.isGoing(), rideWithUsers.getDate());
rideRequest.save();
createChatAssets(rideWithUsers);
join_bt.startAnimation(getAnimationForSendButton());
requested_dt.startAnimation(getAnimationForResquestedText());
App.getBus().post(rideRequest);
pd.dismiss();
Util.snack(coordinatorLayout, getResources().getString(R.string.requestSent));
} else {
Util.treatResponseFromServer(response);
pd.dismiss();
Util.snack(coordinatorLayout, getResources().getString(R.string.errorRequestSent));
Log.e("requestJoin", response.message());
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
pd.dismiss();
Util.snack(coordinatorLayout, getResources().getString(R.string.requestSent));
Log.e("requestJoin", t.getMessage());
}
});
super.onPositiveActionClicked(fragment);
}
@Override
public void onNegativeActionClicked(com.rey.material.app.DialogFragment fragment) {
super.onNegativeActionClicked(fragment);
}
};
((SimpleDialog.Builder) builder).message(getString(R.string.act_rideOffer_requestWarn)).title(getString(R.string.attention)).positiveAction(getString(R.string.ok)).negativeAction(getString(R.string.cancel));
com.rey.material.app.DialogFragment fragment = com.rey.material.app.DialogFragment.newInstance(builder);
fragment.show(getSupportFragmentManager(), "a");
}
});
}
}
}
configureShareButton();
}
use of br.ufrj.caronae.models.RideRequestSent in project caronae-android by caronae.
the class RideOfferAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RideOfferAdapter.ViewHolder viewHolder, int position) {
if (!(mixedList == null || mixedList.size() == 0)) {
if (mixedList.get(position).getClass().equals(RideForJson.class)) {
final RideForJson rideOffer = (RideForJson) mixedList.get(position);
int color = Util.getColorbyZone(rideOffer.getZone());
viewHolder.location_tv.setTextColor(color);
viewHolder.time_tv.setTextColor(color);
viewHolder.name_tv.setTextColor(color);
viewHolder.date_tv.setTextColor(color);
viewHolder.photo_iv.setBorderColor(color);
String profilePicUrl = rideOffer.getDriver().getProfilePicUrl();
if (profilePicUrl != null && !profilePicUrl.isEmpty()) {
Picasso.with(context).load(profilePicUrl).placeholder(R.drawable.user_pic).error(R.drawable.user_pic).transform(new RoundedTransformation()).into(viewHolder.photo_iv);
} else {
viewHolder.photo_iv.setImageResource(R.drawable.user_pic);
}
String timeText;
if (rideOffer.isGoing())
timeText = context.getResources().getString(R.string.arrivingAt, Util.formatTime(rideOffer.getTime()));
else
timeText = context.getResources().getString(R.string.leavingAt, Util.formatTime(rideOffer.getTime()));
viewHolder.time_tv.setText(timeText);
viewHolder.date_tv.setText(Util.formatBadDateWithoutYear(rideOffer.getDate()));
String name = rideOffer.getDriver().getName();
try {
String[] split = name.split(" ");
String shortName = split[0] + " " + split[split.length - 1];
viewHolder.name_tv.setText(shortName);
} catch (Exception e) {
viewHolder.name_tv.setText(name);
}
String location;
if (rideOffer.isGoing())
location = rideOffer.getNeighborhood() + " ➜ " + rideOffer.getHub();
else
location = rideOffer.getHub() + " ➜ " + rideOffer.getNeighborhood();
viewHolder.location_tv.setText(location);
List<RideRequestSent> rideRequests = RideRequestSent.find(RideRequestSent.class, "db_id = ?", rideOffer.getDbId() + "");
boolean requested = false;
if (rideRequests != null && !rideRequests.isEmpty())
requested = true;
viewHolder.requestIndicator_iv.setVisibility(requested ? View.VISIBLE : View.INVISIBLE);
final boolean finalRequested = requested;
viewHolder.parentLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, RideOfferAct.class);
intent.putExtra("ride", rideOffer);
intent.putExtra("requested", finalRequested);
context.startActivity(intent);
}
});
} else {
viewHolder.header_text.setText(getDateText((RideForJson) mixedList.get(position + 1)));
}
}
}
Aggregations