Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

De-duplicate some common code for aborting an action mode #2742

Merged
merged 1 commit into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading