From fd53cefc1b6c70bd86962b6f17d581c3697140c5 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 20 Nov 2017 14:47:17 +0200 Subject: [PATCH] Add osm edit options menu --- ...t_osm_edit_options_bottom_sheet_dialog.xml | 210 ++++++++++++++++++ ...mEditOptionsBottomSheetDialogFragment.java | 129 +++++++++++ .../osmand/plus/osmedit/OsmEditingPlugin.java | 15 +- .../osmand/plus/osmedit/OsmEditsAdapter.java | 16 +- .../osmand/plus/osmedit/OsmEditsFragment.java | 104 ++++----- 5 files changed, 400 insertions(+), 74 deletions(-) create mode 100644 OsmAnd/res/layout/fragment_osm_edit_options_bottom_sheet_dialog.xml create mode 100644 OsmAnd/src/net/osmand/plus/osmedit/OsmEditOptionsBottomSheetDialogFragment.java diff --git a/OsmAnd/res/layout/fragment_osm_edit_options_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_osm_edit_options_bottom_sheet_dialog.xml new file mode 100644 index 0000000000..61e0860e73 --- /dev/null +++ b/OsmAnd/res/layout/fragment_osm_edit_options_bottom_sheet_dialog.xml @@ -0,0 +1,210 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditOptionsBottomSheetDialogFragment.java new file mode 100644 index 0000000000..ef45713fb6 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditOptionsBottomSheetDialogFragment.java @@ -0,0 +1,129 @@ +package net.osmand.plus.osmedit; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.view.ContextThemeWrapper; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; + +import net.osmand.plus.R; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.widgets.TextViewEx; + +public class OsmEditOptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { + + public final static String TAG = "OsmEditOptionsBottomSheetDialogFragment"; + + public static final String OSM_POINT = "osm_point"; + + private OsmEditOptionsFragmentListener listener; + + public void setListener(OsmEditOptionsFragmentListener listener) { + this.listener = listener; + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_osm_edit_options_bottom_sheet_dialog, container); + + Bundle args = getArguments(); + if (args != null) { + final OsmPoint osmPoint = (OsmPoint) args.getSerializable(OSM_POINT); + + ((TextViewEx) mainView.findViewById(R.id.osm_edit_name)).setText(OsmEditingPlugin.getName(osmPoint) + ":"); + + ((ImageView) mainView.findViewById(R.id.upload_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_export)); + mainView.findViewById(R.id.upload_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (listener != null) { + listener.onUploadClick(osmPoint); + } + dismiss(); + } + }); + + ((ImageView) mainView.findViewById(R.id.show_on_map_icon)).setImageDrawable(getContentIcon(R.drawable.ic_show_on_map)); + mainView.findViewById(R.id.show_on_map_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (listener != null) { + listener.onShowOnMapClick(osmPoint); + } + dismiss(); + } + }); + + if (osmPoint instanceof OpenstreetmapPoint && osmPoint.getAction() != OsmPoint.Action.DELETE) { + mainView.findViewById(R.id.modify_osm_change_row).setVisibility(View.VISIBLE); + ((ImageView) mainView.findViewById(R.id.modify_osm_change_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_edit_dark)); + mainView.findViewById(R.id.modify_osm_change_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (listener != null) { + listener.onModifyOsmChangeClick(osmPoint); + } + dismiss(); + } + }); + } + + if (osmPoint instanceof OsmNotesPoint) { + mainView.findViewById(R.id.modify_osm_note_row).setVisibility(View.VISIBLE); + ((ImageView) mainView.findViewById(R.id.modify_osm_note_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_edit_dark)); + mainView.findViewById(R.id.modify_osm_note_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (listener != null) { + listener.onModifyOsmNoteClick(osmPoint); + } + dismiss(); + } + }); + } + + ((ImageView) mainView.findViewById(R.id.delete_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_delete_dark)); + mainView.findViewById(R.id.delete_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (listener != null) { + listener.onDeleteClick(osmPoint); + } + dismiss(); + } + }); + } + + if (nightMode) { + ((TextViewEx) mainView.findViewById(R.id.osm_edit_name)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); + } + + mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dismiss(); + } + }); + + setupHeightAndBackground(mainView, R.id.osm_edit_options_scroll_view); + + return mainView; + } + + public interface OsmEditOptionsFragmentListener { + + void onUploadClick(OsmPoint osmPoint); + + void onShowOnMapClick(OsmPoint osmPoint); + + void onModifyOsmChangeClick(OsmPoint osmPoint); + + void onModifyOsmNoteClick(OsmPoint osmPoint); + + void onDeleteClick(OsmPoint osmPoint); + } +} diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index b5fb38b5d4..f2ac87d344 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -421,19 +421,30 @@ public class OsmEditingPlugin extends OsmandPlugin { public static String getEditName(OsmPoint point) { String prefix = getPrefix(point); + String name = getName(point); if (point.getGroup() == OsmPoint.Group.POI) { String subtype = ""; if (!Algorithms.isEmpty(((OpenstreetmapPoint) point).getSubtype())) { subtype = " (" + ((OpenstreetmapPoint) point).getSubtype() + ") "; } - return prefix + subtype + ((OpenstreetmapPoint) point).getName(); + return prefix + subtype + name; } else if (point.getGroup() == OsmPoint.Group.BUG) { - return prefix + ((OsmNotesPoint) point).getText(); + return prefix + name; } else { return prefix; } } + public static String getName(OsmPoint point) { + if (point.getGroup() == OsmPoint.Group.POI) { + return ((OpenstreetmapPoint) point).getName(); + } else if (point.getGroup() == OsmPoint.Group.BUG) { + return ((OsmNotesPoint) point).getText(); + } else { + return ""; + } + } + public static String getPrefix(OsmPoint osmPoint) { return (osmPoint.getGroup() == OsmPoint.Group.POI ? "POI" : "Bug") + " id: " + osmPoint.getId() + " "; } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java index 20ab3de571..45edd4b597 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java @@ -64,7 +64,7 @@ public class OsmEditsAdapter extends ArrayAdapter { if (osmEdit != null) { final OsmEditViewHolder holder = (OsmEditViewHolder) view.getTag(); - holder.titleTextView.setText(getName(osmEdit)); + holder.titleTextView.setText(OsmEditingPlugin.getName(osmEdit)); holder.descriptionTextView.setText(getDescription(osmEdit)); Drawable icon = getIcon(osmEdit); if (icon != null) { @@ -94,7 +94,7 @@ public class OsmEditsAdapter extends ArrayAdapter { @Override public void onClick(View v) { if (listener != null) { - listener.onOptionsClick(v, osmEdit); + listener.onOptionsClick(osmEdit); } } }); @@ -147,16 +147,6 @@ public class OsmEditsAdapter extends ArrayAdapter { return null; } - private String getName(OsmPoint point) { - if (point.getGroup() == OsmPoint.Group.POI) { - return ((OpenstreetmapPoint) point).getName(); - } else if (point.getGroup() == OsmPoint.Group.BUG) { - return ((OsmNotesPoint) point).getText(); - } else { - return ""; - } - } - private String getDescription(OsmPoint point) { String action = ""; if (point.getAction() == OsmPoint.Action.CREATE) { @@ -214,6 +204,6 @@ public class OsmEditsAdapter extends ArrayAdapter { void onItemShowMap(OsmPoint point); - void onOptionsClick(View view, OsmPoint note); + void onOptionsClick(OsmPoint note); } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index d70c7e057b..607ff72020 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -9,9 +9,9 @@ import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; +import android.support.v4.app.Fragment; import android.support.v7.app.AlertDialog; import android.support.v7.view.ActionMode; -import android.support.v7.widget.PopupMenu; import android.util.Xml; import android.view.LayoutInflater; import android.view.Menu; @@ -20,8 +20,6 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.ViewStub; -import android.widget.AdapterView; -import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.CheckBox; import android.widget.EditText; @@ -40,13 +38,12 @@ import net.osmand.plus.activities.ActionBarProgressActivity; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.OsmandActionBarActivity; import net.osmand.plus.base.OsmAndListFragment; -import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.plus.dialogs.ProgressDialogFragment; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.myplaces.FavoritesActivity; -import net.osmand.plus.osmedit.OsmPoint.Action; import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment; import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.PoiUploaderType; +import net.osmand.plus.osmedit.OsmEditOptionsBottomSheetDialogFragment.OsmEditOptionsFragmentListener; import net.osmand.util.Algorithms; import org.xmlpull.v1.XmlSerializer; @@ -70,7 +67,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo private View headerView; private View emptyView; - private List osmEdits; + private List osmEdits = new ArrayList<>(); private OsmEditsAdapter listAdapter; private ArrayList osmEditsSelected = new ArrayList<>(); @@ -114,6 +111,11 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo ? R.drawable.ic_empty_state_osm_edits_day : R.drawable.ic_empty_state_osm_edits_night; ((ImageView) emptyView.findViewById(R.id.empty_state_image_view)).setImageResource(icRes); + Fragment optionsFragment = getChildFragmentManager().findFragmentByTag(OsmEditOptionsBottomSheetDialogFragment.TAG); + if (optionsFragment != null) { + ((OsmEditOptionsBottomSheetDialogFragment) optionsFragment).setListener(createOsmEditOptionsFragmentListener()); + } + plugin.getPoiModificationLocalUtil().addNodeCommittedListener(this); return view; } @@ -397,8 +399,8 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo } @Override - public void onOptionsClick(View view, OsmPoint note) { - openPopUpMenu(view, note); + public void onOptionsClick(OsmPoint note) { + openPopUpMenu(note); } }); listView.setAdapter(listAdapter); @@ -441,66 +443,50 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo }); } - private void openPopUpMenu(View v, final OsmPoint info) { - OsmandApplication app = getMyApplication(); - final PopupMenu optionsMenu = new PopupMenu(getActivity(), v); - DirectionsDialogs.setupPopUpMenuIcon(optionsMenu); - MenuItem item = optionsMenu.getMenu().add(R.string.shared_string_show_on_map).setIcon(app.getIconsCache().getThemedIcon(R.drawable.ic_show_on_map)); - item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + private void openPopUpMenu(final OsmPoint info) { + OsmEditOptionsBottomSheetDialogFragment optionsFragment = new OsmEditOptionsBottomSheetDialogFragment(); + Bundle args = new Bundle(); + args.putSerializable(OsmEditOptionsBottomSheetDialogFragment.OSM_POINT, info); + optionsFragment.setUsedOnMap(false); + optionsFragment.setArguments(args); + optionsFragment.setListener(createOsmEditOptionsFragmentListener()); + optionsFragment.show(getChildFragmentManager(), OsmEditOptionsBottomSheetDialogFragment.TAG); + } + + private OsmEditOptionsFragmentListener createOsmEditOptionsFragmentListener() { + return new OsmEditOptionsFragmentListener() { @Override - public boolean onMenuItemClick(MenuItem item) { + public void onUploadClick(OsmPoint osmPoint) { + uploadItems(new OsmPoint[]{getPointAfterModify(osmPoint)}); + } + + @Override + public void onShowOnMapClick(OsmPoint osmPoint) { OsmandSettings settings = getMyApplication().getSettings(); - settings.setMapLocationToShow(info.getLatitude(), info.getLongitude(), settings.getLastKnownMapZoom()); + settings.setMapLocationToShow(osmPoint.getLatitude(), osmPoint.getLongitude(), settings.getLastKnownMapZoom()); MapActivity.launchMapActivityMoveToTop(getActivity()); - return true; } - }); - if (info instanceof OpenstreetmapPoint && info.getAction() != Action.DELETE) { - item = optionsMenu.getMenu().add(R.string.poi_context_menu_modify_osm_change).setIcon(app.getIconsCache().getThemedIcon(R.drawable.ic_action_edit_dark)); - item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { - - @Override - public boolean onMenuItemClick(MenuItem item) { - OpenstreetmapPoint i = (OpenstreetmapPoint) getPointAfterModify(info); - final Node entity = i.getEntity(); - refreshId = entity.getId(); - EditPoiDialogFragment.createInstance(entity, false).show(getActivity().getSupportFragmentManager(), "edit_poi"); - return true; - } - }); - } - if (info instanceof OsmNotesPoint) { - item = optionsMenu.getMenu().add(R.string.context_menu_item_modify_note).setIcon(app.getIconsCache().getThemedIcon(R.drawable.ic_action_edit_dark)); - item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { - - @Override - public boolean onMenuItemClick(MenuItem item) { - showBugDialog((OsmNotesPoint) info); - return true; - } - }); - } - item = optionsMenu.getMenu().add(R.string.shared_string_delete).setIcon(app.getIconsCache().getThemedIcon(R.drawable.ic_action_delete_dark)); - item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override - public boolean onMenuItemClick(MenuItem item) { + public void onModifyOsmChangeClick(OsmPoint osmPoint) { + OpenstreetmapPoint i = (OpenstreetmapPoint) getPointAfterModify(osmPoint); + final Node entity = i.getEntity(); + refreshId = entity.getId(); + EditPoiDialogFragment.createInstance(entity, false).show(getActivity().getSupportFragmentManager(), "edit_poi"); + } + + @Override + public void onModifyOsmNoteClick(OsmPoint osmPoint) { + showBugDialog((OsmNotesPoint) osmPoint); + } + + @Override + public void onDeleteClick(OsmPoint osmPoint) { ArrayList points = new ArrayList<>(); - points.add(info); + points.add(osmPoint); deleteItems(new ArrayList<>(points)); - return true; - } - }); - item = optionsMenu.getMenu().add(R.string.local_openstreetmap_upload).setIcon(app.getIconsCache().getThemedIcon(R.drawable.ic_action_export)); - item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - uploadItems(new OsmPoint[]{getPointAfterModify(info)}); - return true; - } - }); - optionsMenu.show(); + }; } protected OsmPoint getPointAfterModify(OsmPoint info) {