Add ability to delete quick action in editing screen
This commit is contained in:
parent
f5f971874f
commit
38a5eaf50c
2 changed files with 52 additions and 14 deletions
|
@ -1,6 +1,7 @@
|
|||
package net.osmand.plus.quickaction;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
|
@ -9,6 +10,8 @@ import android.os.Bundle;
|
|||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
|
@ -31,6 +34,8 @@ import net.osmand.plus.activities.MapActivity;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import static net.osmand.plus.quickaction.QuickActionListFragment.showConfirmActionDeleteDialog;
|
||||
|
||||
/**
|
||||
* Created by rosty on 12/27/16.
|
||||
*/
|
||||
|
@ -168,6 +173,32 @@ public class CreateEditActionDialog extends DialogFragment implements CallbackWi
|
|||
dismiss();
|
||||
}
|
||||
});
|
||||
if (!isNew) {
|
||||
Menu menu = toolbar.getMenu();
|
||||
menu.clear();
|
||||
|
||||
MenuItem item = menu.add(R.string.shared_string_delete).setIcon(R.drawable.ic_action_delete_dark);
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
Context ctx = getContext();
|
||||
if (ctx != null) {
|
||||
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
quickActionRegistry.deleteQuickAction(action);
|
||||
quickActionRegistry.notifyUpdates();
|
||||
|
||||
dialog.dismiss();
|
||||
dismiss();
|
||||
}
|
||||
};
|
||||
showConfirmActionDeleteDialog(ctx, action, !isLightContent, listener);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupHeader(View root, Bundle savedInstanceState){
|
||||
|
|
|
@ -184,26 +184,24 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements Quick
|
|||
quickActionRegistry.updateQuickActions(adapter.getQuickActions());
|
||||
}
|
||||
|
||||
void createAndShowDeleteDialog(final int itemPosition, final String itemName) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(getContext(), !isLightContent));
|
||||
static void showConfirmActionDeleteDialog(Context ctx, QuickAction action, boolean nightMode, DialogInterface.OnClickListener listener) {
|
||||
OsmandApplication app = (OsmandApplication) ctx.getApplicationContext();
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(ctx, nightMode));
|
||||
builder.setTitle(R.string.quick_actions_delete);
|
||||
builder.setMessage(getResources().getString(R.string.quick_actions_delete_text, itemName));
|
||||
builder.setIcon(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_delete_dark));
|
||||
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
adapter.deleteItem(itemPosition);
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
builder.setMessage(app.getString(R.string.quick_actions_delete_text, ctx.getString(action.getNameRes())));
|
||||
builder.setIcon(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_delete_dark));
|
||||
builder.setPositiveButton(R.string.shared_string_yes, listener);
|
||||
builder.setNegativeButton(R.string.shared_string_no, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
AlertDialog dialog = builder.show();
|
||||
int activeColorPrimaryResId = isLightContent ? R.color.active_color_primary_light : R.color.active_color_primary_dark;
|
||||
dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(ContextCompat.getColor(getContext(), activeColorPrimaryResId));
|
||||
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(ContextCompat.getColor(getContext(), activeColorPrimaryResId));
|
||||
int activeColorId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
|
||||
int activeColor = ContextCompat.getColor(ctx, activeColorId);
|
||||
dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(activeColor);
|
||||
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(activeColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -257,7 +255,16 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements Quick
|
|||
itemVH.closeBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
createAndShowDeleteDialog(holder.getAdapterPosition(), getResources().getString(item.getNameRes()));
|
||||
Context ctx = getContext();
|
||||
if (ctx != null) {
|
||||
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
adapter.deleteItem(holder.getAdapterPosition());
|
||||
dialog.dismiss();
|
||||
}
|
||||
};
|
||||
showConfirmActionDeleteDialog(ctx, item, !isLightContent, listener);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue