diff --git a/src/main/java/de/blau/android/easyedit/AbortableActionModeCallback.java b/src/main/java/de/blau/android/easyedit/AbortableActionModeCallback.java new file mode 100644 index 000000000..c8440a663 --- /dev/null +++ b/src/main/java/de/blau/android/easyedit/AbortableActionModeCallback.java @@ -0,0 +1,30 @@ +package de.blau.android.easyedit; + +import androidx.appcompat.app.AlertDialog; +import de.blau.android.R; + +public abstract class AbortableActionModeCallback extends NonSimpleActionModeCallback { + + /** + * Common code if you want to abort an action mode and rollback any changes + * + * @param manager + */ + protected AbortableActionModeCallback(EasyEditManager manager) { + super(manager); + } + + @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; + } +} diff --git a/src/main/java/de/blau/android/easyedit/RotationActionModeCallback.java b/src/main/java/de/blau/android/easyedit/RotationActionModeCallback.java index 9229dff65..102da2c46 100644 --- a/src/main/java/de/blau/android/easyedit/RotationActionModeCallback.java +++ b/src/main/java/de/blau/android/easyedit/RotationActionModeCallback.java @@ -8,14 +8,13 @@ import android.util.Log; import android.view.Menu; import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; import androidx.appcompat.view.ActionMode; import de.blau.android.R; /** * Rotate the current selection */ -public class RotationActionModeCallback extends NonSimpleActionModeCallback { +public class RotationActionModeCallback extends AbortableActionModeCallback { private static final int TAG_LEN = Math.min(LOG_TAG_LEN, RotationActionModeCallback.class.getSimpleName().length()); private static final String DEBUG_TAG = RotationActionModeCallback.class.getSimpleName().substring(0, TAG_LEN); @@ -74,18 +73,4 @@ public void onDestroyActionMode(ActionMode mode) { } super.onDestroyActionMode(mode); } - - @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; - } } diff --git a/src/main/java/de/blau/android/easyedit/WaySegmentModifyActionModeCallback.java b/src/main/java/de/blau/android/easyedit/WaySegmentModifyActionModeCallback.java index 901e0962f..1a27b3b3c 100644 --- a/src/main/java/de/blau/android/easyedit/WaySegmentModifyActionModeCallback.java +++ b/src/main/java/de/blau/android/easyedit/WaySegmentModifyActionModeCallback.java @@ -8,7 +8,6 @@ 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; @@ -16,7 +15,7 @@ import de.blau.android.util.SerializableState; import de.blau.android.util.ThemeUtils; -public class WaySegmentModifyActionModeCallback extends NonSimpleActionModeCallback { +public class WaySegmentModifyActionModeCallback extends AbortableActionModeCallback { 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); @@ -117,20 +116,6 @@ 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());