use of com.rey.material.app.DialogFragment in project caronae-android by caronae.
the class ActiveRideAct method showCloseDialog.
private void showCloseDialog() {
Dialog.Builder builder = new SimpleDialog.Builder(R.style.SimpleDialogLight) {
@Override
protected void onBuildDone(Dialog dialog) {
dialog.layoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
@Override
public void onPositiveActionClicked(DialogFragment fragment) {
SharedPref.saveRemoveRideFromList(rideId2);
ActiveRideAct.this.finish();
super.onPositiveActionClicked(fragment);
}
@Override
public void onNegativeActionClicked(DialogFragment fragment) {
super.onNegativeActionClicked(fragment);
}
};
builder.title("Opa...").positiveAction(getString(R.string.ok)).contentView(R.layout.rideended);
DialogFragment fragment = DialogFragment.newInstance(builder);
fragment.show(getSupportFragmentManager(), null);
}
use of com.rey.material.app.DialogFragment in project caronae-android by caronae.
the class MyRidesAdapter method configureMyOfferRide.
private void configureMyOfferRide(int position, final MyRidesAdapter.ViewHolder holder) {
final Ride ride = (Ride) rides.get(position);
int color = Util.getColorbyZone(ride.getZone());
holder.location_tv.setTextColor(color);
if (ride.isGoing())
holder.time_tv.setText(activity.getString(R.string.arrivingAt, Util.formatBadHour(ride.getTime())));
else
holder.time_tv.setText(activity.getString(R.string.leavingAt, Util.formatBadHour(ride.getTime())));
if (ride.getDate().contains("-")) {
ride.setDate(Util.formatBadDateWithYear(ride.getDate()));
}
holder.date_tv.setText(Util.formatGoodDateWithoutYear(ride.getDate()));
holder.slots_tv.setText(activity.getString(R.string.Xslots, ride.getSlots(), (Integer.parseInt(ride.getSlots()) > 1 ? "s" : "")));
String location;
if (ride.isGoing())
location = ride.getNeighborhood() + " ➜ " + ride.getHub();
else
location = ride.getHub() + " ➜ " + ride.getNeighborhood();
holder.location_tv.setText(location);
String s = activity.getString(R.string.repeats);
if (ride.isRoutine()) {
s += ride.getWeekDays().contains("7") ? activity.getString(R.string.sunday) : "";
s += ride.getWeekDays().contains("1") ? activity.getString(R.string.monday) : "";
s += ride.getWeekDays().contains("2") ? activity.getString(R.string.tuesday) : "";
s += ride.getWeekDays().contains("3") ? activity.getString(R.string.wednesday) : "";
s += ride.getWeekDays().contains("4") ? activity.getString(R.string.thursday) : "";
s += ride.getWeekDays().contains("5") ? activity.getString(R.string.friday) : "";
s += ride.getWeekDays().contains("6") ? activity.getString(R.string.saturday) : "";
s = s.substring(0, s.length() - 1);
} else {
s = activity.getString(R.string.notRoutine);
}
holder.routine_tv.setText(s);
holder.delete_bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (ride.isRoutine()) {
Dialog.Builder builder = new SimpleDialog.Builder(R.style.SimpleDialogLight) {
@Override
protected void onBuildDone(Dialog dialog) {
dialog.layoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
@Override
public void onPositiveActionClicked(DialogFragment fragment) {
RadioGroup radioGroup = (RadioGroup) fragment.getDialog().findViewById(R.id.radioGroup);
int checkedRadioButton = radioGroup.getCheckedRadioButtonId();
switch(checkedRadioButton) {
case R.id.all_rb:
deleteAllRidesFromRoutine();
break;
case R.id.single_rb:
deleteSingleRide();
break;
}
super.onPositiveActionClicked(fragment);
}
@Override
public void onNegativeActionClicked(DialogFragment fragment) {
super.onNegativeActionClicked(fragment);
}
};
builder.title(activity.getString(R.string.attention)).positiveAction(activity.getString(R.string.ok)).negativeAction(activity.getString(R.string.cancel)).contentView(R.layout.delete_routine_dialog);
DialogFragment fragment = DialogFragment.newInstance(builder);
fragment.show(activity.getSupportFragmentManager(), null);
} else {
deleteSingleRide();
}
}
private void deleteAllRidesFromRoutine() {
Dialog.Builder builder = new SimpleDialog.Builder(R.style.SimpleDialogLight) {
@Override
public void onPositiveActionClicked(DialogFragment fragment) {
final ProgressDialog pd = ProgressDialog.show(activity, "", activity.getString(R.string.wait), true, true);
final String routineId = ride.getRoutineId();
CaronaeAPI.service(activity.getApplicationContext()).deleteAllRidesFromRoutine(routineId).enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response.isSuccessful()) {
pd.dismiss();
Util.toast(R.string.ridesDeleted);
if (routineId != null) {
Iterator<Object> it = rides.iterator();
while (it.hasNext()) {
Object object = it.next();
if (object.getClass() == Ride.class) {
Ride ride2 = (Ride) object;
if (ride2.getRoutineId().equals(routineId))
it.remove();
}
}
}
notifyDataSetChanged();
Ride.deleteAll(Ride.class, "routine_id = ?", routineId);
} else {
Util.treatResponseFromServer(response);
pd.dismiss();
Util.toast(activity.getString(R.string.errorDeleteRide));
Log.e("deleteAllFromRoutine", response.message());
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
pd.dismiss();
Util.toast(activity.getString(R.string.errorDeleteRide));
Log.e("deleteAllFromRoutine", t.getMessage());
}
});
super.onPositiveActionClicked(fragment);
}
@Override
public void onNegativeActionClicked(DialogFragment fragment) {
super.onNegativeActionClicked(fragment);
}
};
((SimpleDialog.Builder) builder).message(activity.getString(R.string.warnDeleteRidesCouldBeActive)).title(activity.getString(R.string.attention)).positiveAction(activity.getString(R.string.ok)).negativeAction(activity.getString(R.string.cancel));
DialogFragment fragment = DialogFragment.newInstance(builder);
fragment.show(activity.getSupportFragmentManager(), null);
}
private void deleteSingleRide() {
Dialog.Builder builder = new SimpleDialog.Builder(R.style.SimpleDialogLight) {
@Override
public void onPositiveActionClicked(DialogFragment fragment) {
final ProgressDialog pd = ProgressDialog.show(activity, "", activity.getString(R.string.wait), true, true);
CaronaeAPI.service(activity.getApplicationContext()).deleteRide(ride.getDbId() + "").enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response.isSuccessful()) {
pd.dismiss();
Util.toast(R.string.rideDeleted);
rides.remove(ride);
notifyItemRemoved(holder.getAdapterPosition());
for (int rideCounter = 0; rideCounter < rides.size(); rideCounter++) {
if (rides.get(rideCounter).getClass() == RideForJson.class) {
RideForJson rideForJson = (RideForJson) rides.get(rideCounter);
if (rideForJson.getId() == ride.getId()) {
rides.remove(rideForJson);
notifyItemRemoved(rideCounter);
}
}
}
ride.delete();
} else {
Util.treatResponseFromServer(response);
pd.dismiss();
Util.toast(activity.getString(R.string.errorDeleteRide));
Log.e("deleteRide", response.message());
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
pd.dismiss();
Util.toast(activity.getString(R.string.errorDeleteRide));
Log.e("deleteRide", t.getMessage());
}
});
super.onPositiveActionClicked(fragment);
}
@Override
public void onNegativeActionClicked(DialogFragment fragment) {
super.onNegativeActionClicked(fragment);
}
};
((SimpleDialog.Builder) builder).message(activity.getString(R.string.warnDeleteRideCouldBeActive)).title(activity.getString(R.string.attention)).positiveAction(activity.getString(R.string.ok)).negativeAction(activity.getString(R.string.cancel));
DialogFragment fragment = DialogFragment.newInstance(builder);
fragment.show(activity.getSupportFragmentManager(), null);
}
});
final int colorToSend = color;
final boolean[] isOpen = { false, false };
holder.myRideLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
holder.delete_bt.setBackgroundColor(color);
holder.myRideLayout.addSwipeListener(new SwipeLayout.SwipeListener() {
@Override
public void onStartOpen(SwipeLayout layout) {
isOpen[0] = true;
isOpen[1] = true;
}
@Override
public void onOpen(SwipeLayout layout) {
}
@Override
public void onStartClose(SwipeLayout layout) {
}
@Override
public void onClose(SwipeLayout layout) {
isOpen[1] = false;
}
@Override
public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
}
@Override
public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
}
});
holder.share_bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, Util.getTextToShareRide(ride));
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Check out this site!");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(intent.createChooser(intent, "Compartilhar Carona"));
}
});
holder.myRideLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!isOpen[0]) {
final ProgressDialog pd = ProgressDialog.show(activity, "", activity.getResources().getString(R.string.wait), true, true);
RideRequestReceived.deleteAll(RideRequestReceived.class, "db_id = ?", ride.getDbId() + "");
holder.newRequest_iv.setVisibility(View.INVISIBLE);
CaronaeAPI.service(activity.getApplicationContext()).getRequesters(ride.getDbId() + "").enqueue(new Callback<List<User>>() {
@Override
public void onResponse(Call<List<User>> call, Response<List<User>> response) {
if (response.isSuccessful()) {
pd.dismiss();
List<User> users = response.body();
if (users.isEmpty()) {
Util.toast(R.string.noRequesters);
} else {
Intent intent = new Intent(activity, RequestersListAct.class);
intent.putParcelableArrayListExtra("users", (ArrayList<User>) users);
intent.putExtra("rideId", ride.getDbId());
intent.putExtra("color", colorToSend);
activity.startActivity(intent);
}
} else {
Util.treatResponseFromServer(response);
pd.dismiss();
Util.toast(R.string.errorGetRequesters);
Log.e("getRequesters", response.message());
}
}
@Override
public void onFailure(Call<List<User>> call, Throwable t) {
pd.dismiss();
Util.toast(R.string.errorGetRequesters);
Log.e("getRequesters", t.getMessage());
}
});
} else if (isOpen[0] && !isOpen[1]) {
isOpen[0] = false;
}
}
});
boolean found = false;
for (RideRequestReceived requestReceived : rideRequestReceivedList) {
if (requestReceived.getDbId() == ride.getDbId()) {
holder.newRequest_iv.setVisibility(View.VISIBLE);
found = true;
break;
}
}
if (!found) {
CaronaeAPI.service(activity.getApplicationContext()).getRequesters(ride.getDbId() + "").enqueue(new Callback<List<User>>() {
@Override
public void onResponse(Call<List<User>> call, Response<List<User>> response) {
if (response.isSuccessful()) {
List<User> requesters = response.body();
if (requesters.isEmpty()) {
holder.newRequest_iv.setVisibility(View.INVISIBLE);
} else {
holder.newRequest_iv.setVisibility(View.VISIBLE);
new RideRequestReceived(Integer.valueOf(ride.getDbId())).save();
}
} else {
Util.toast(R.string.errorGetRequesters);
Log.e("getRequesters", response.message());
}
}
@Override
public void onFailure(Call<List<User>> call, Throwable t) {
Util.toast(R.string.errorGetRequesters);
Log.e("getRequesters", t.getMessage());
}
});
}
}
Aggregations