From 0c2056f7c519c5b280eee36cc03da3102956924f Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 15 Jun 2018 14:24:09 +0300 Subject: [PATCH] add CoordinateInputActionsBottomSheet --- .../CoordinateInputActionsBottomSheet.java | 75 +++++++++++++++++++ .../CoordinateInputDialogFragment.java | 35 +++++++++ .../adapters/CoordinateInputAdapter.java | 35 ++++----- 3 files changed, 124 insertions(+), 21 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputActionsBottomSheet.java diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputActionsBottomSheet.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputActionsBottomSheet.java new file mode 100644 index 0000000000..2746466fe6 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputActionsBottomSheet.java @@ -0,0 +1,75 @@ +package net.osmand.plus.mapmarkers; + +import android.os.Bundle; +import android.view.View; + +import net.osmand.plus.R; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; +import net.osmand.plus.mapmarkers.adapters.CoordinateInputAdapter; + +public class CoordinateInputActionsBottomSheet extends MenuBottomSheetDialogFragment { + + public final static String TAG = "CoordinateInputActionsBottomSheet"; + + private CoordinateInputActionsListener listener; + + public void setListener(CoordinateInputActionsListener listener) { + this.listener = listener; + } + + @Override + public void createMenuItems(Bundle savedInstanceState) { + Bundle args = getArguments(); + if (args == null) { + return; + } + final int position = args.getInt(CoordinateInputAdapter.ADAPTER_POSITION); + + items.add(new TitleItem(getString(R.string.shared_string_actions))); + + BaseBottomSheetItem editItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_type_edit)) + .setTitle(getString(R.string.shared_string_edit)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + listener.editItem(position); + dismiss(); + } + }) + .create(); + items.add(editItem); + + BaseBottomSheetItem deleteItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_type_delete)) + .setTitle(getString(R.string.shared_string_delete)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + listener.removeItem(position); + dismiss(); + } + }) + .create(); + items.add(deleteItem); + + } + + @Override + protected int getDismissButtonTextId() { + return R.string.shared_string_cancel; + } + + interface CoordinateInputActionsListener { + + void removeItem(int position); + + void editItem(int position); + + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index 25eebb880f..aaf36d68e6 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -296,6 +296,25 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm enterEditingMode(adapter.getItem(pos)); } }); + adapter.setOnActionsClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + RecyclerView.ViewHolder viewHolder = recyclerView.findContainingViewHolder(v); + if (viewHolder != null) { + int pos = viewHolder.getAdapterPosition(); + if (pos == RecyclerView.NO_POSITION) { + return; + } + Bundle args = new Bundle(); + args.putInt(CoordinateInputAdapter.ADAPTER_POSITION, pos); + CoordinateInputActionsBottomSheet fragment = new CoordinateInputActionsBottomSheet(); + fragment.setUsedOnMap(false); + fragment.setArguments(args); + fragment.setListener(createCoordinateInputActionsListener()); + fragment.show(getChildFragmentManager(), CoordinateInputActionsBottomSheet.TAG); + } + } + }); setBackgroundColor(R.id.bottom_controls_container, lightTheme ? R.color.keyboard_item_control_light_bg : R.color.keyboard_item_control_dark_bg); @@ -884,6 +903,22 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm }; } + private CoordinateInputActionsBottomSheet.CoordinateInputActionsListener createCoordinateInputActionsListener() { + return new CoordinateInputActionsBottomSheet.CoordinateInputActionsListener() { + + @Override + public void removeItem(int position) { + adapter.removeItem(position); + } + + @Override + public void editItem(int position) { + enterEditingMode(adapter.getItem(position)); + } + + }; + } + private void changeHand() { dismissEditingMode(); ((FrameLayout) mainView.findViewById(R.id.left_container)).removeViewAt(0); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java index 98a6727cda..268c574b77 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java @@ -22,6 +22,8 @@ import java.util.List; public class CoordinateInputAdapter extends RecyclerView.Adapter { + public static final String ADAPTER_POSITION = "position"; + private OsmandApplication app; private List mapMarkers; @@ -31,11 +33,16 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter mapMarkers) { this.app = app; this.mapMarkers = mapMarkers; @@ -61,23 +68,12 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter