Skip to content

Commit

Permalink
Merge branch 'remove_code_duplication'
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Dec 8, 2024
2 parents c9b86db + c8556c3 commit b9f946f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
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;
import de.blau.android.osm.Way;
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);
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit b9f946f

Please sign in to comment.