Skip to content

Commit

Permalink
Abort and rollback correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Dec 2, 2024
1 parent a543693 commit 16f59f2
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package de.blau.android.easyedit;

import static de.blau.android.contract.Constants.LOG_TAG_LEN;

import java.util.HashMap;

import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.view.ActionMode;
import de.blau.android.R;
import de.blau.android.osm.Tags;
Expand All @@ -14,7 +17,9 @@
import de.blau.android.util.ThemeUtils;

public class WaySegmentModifyActionModeCallback extends NonSimpleActionModeCallback {
private static final String DEBUG_TAG = WaySegmentModifyActionModeCallback.class.getSimpleName().substring(0, Math.min(23, WaySegmentModifyActionModeCallback.class.getSimpleName().length()));

private static final int TAG_LEN = Math.min(LOG_TAG_LEN, WaySegmentModifyActionModeCallback.class.getSimpleName().length());
private static final String DEBUG_TAG = WaySegmentModifyActionModeCallback.class.getSimpleName().substring(0, TAG_LEN);

private static final int MENUITEM_BRIDGE = 24;
private static final int MENUITEM_TUNNEL = 25;
Expand Down Expand Up @@ -112,6 +117,20 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return true;
}

@Override
protected void onCloseClicked() {
onBackPressed();
}

@Override
public boolean onBackPressed() {
new AlertDialog.Builder(main).setTitle(R.string.abort_action_title).setPositiveButton(R.string.yes, (dialog, which) -> {
logic.rollback();
super.onBackPressed();
}).setNeutralButton(R.string.cancel, null).show();
return false;
}

@Override
public void saveState(SerializableState state) {
state.putLong(WAY_ID_KEY, way.getOsmId());
Expand Down

0 comments on commit 16f59f2

Please sign in to comment.