Add cancel dialog
This commit is contained in:
parent
e7e543fff4
commit
594b2d9a68
2 changed files with 45 additions and 3 deletions
|
@ -223,6 +223,16 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew {
|
|||
|
||||
@Override
|
||||
protected boolean wasSaved() {
|
||||
final FavouritePoint favorite = getFavorite();
|
||||
if (favorite != null) {
|
||||
final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(),
|
||||
getNameTextValue(), getCategoryTextValue());
|
||||
point.setDescription(getDescriptionTextValue());
|
||||
point.setColor(color);
|
||||
point.setBackgroundType(backgroundType);
|
||||
point.setIconId(iconId);
|
||||
return isChanged(favorite, point);
|
||||
}
|
||||
return saved;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package net.osmand.plus.mapcontextmenu.editors;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.os.Build;
|
||||
|
@ -22,6 +24,7 @@ import android.widget.TextView;
|
|||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.ColorRes;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -62,6 +65,8 @@ import static net.osmand.util.Algorithms.capitalizeFirstLetter;
|
|||
|
||||
public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
|
||||
|
||||
public static final String TAG = "PointEditorFragmentNew";
|
||||
|
||||
private View view;
|
||||
private EditText nameEdit;
|
||||
private TextView addDelDescription;
|
||||
|
@ -112,7 +117,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
|
|||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
showExitDialog();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -165,8 +170,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
|
|||
cancelButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
cancelled = true;
|
||||
dismiss();
|
||||
showExitDialog();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -734,6 +738,34 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
|
|||
return getPaintedContentIcon(iconId, color);
|
||||
}
|
||||
|
||||
private void showExitDialog() {
|
||||
hideKeyboard();
|
||||
if (!wasSaved()) {
|
||||
AlertDialog.Builder dismissDialog = createWarningDialog(getActivity(),
|
||||
R.string.shared_string_dismiss, R.string.exit_without_saving, R.string.shared_string_cancel);
|
||||
dismissDialog.setPositiveButton(R.string.shared_string_exit, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
cancelled = true;
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
dismissDialog.show();
|
||||
} else {
|
||||
cancelled = true;
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
private AlertDialog.Builder createWarningDialog(Activity activity, int title, int message, int negButton) {
|
||||
Context themedContext = UiUtilities.getThemedContext(activity, nightMode);
|
||||
AlertDialog.Builder warningDialog = new AlertDialog.Builder(themedContext);
|
||||
warningDialog.setTitle(getString(title));
|
||||
warningDialog.setMessage(getString(message));
|
||||
warningDialog.setNegativeButton(negButton, null);
|
||||
return warningDialog;
|
||||
}
|
||||
|
||||
class GroupAdapter extends RecyclerView.Adapter<GroupsViewHolder> {
|
||||
|
||||
private static final int VIEW_TYPE_FOOTER = 1;
|
||||
|
|
Loading…
Reference in a new issue