diff --git a/OsmAnd/res/layout-land/empty_state_osm_edits.xml b/OsmAnd/res/layout-land/empty_state_osm_edits.xml new file mode 100644 index 0000000000..cac933204f --- /dev/null +++ b/OsmAnd/res/layout-land/empty_state_osm_edits.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/empty_state_osm_edits.xml b/OsmAnd/res/layout/empty_state_osm_edits.xml new file mode 100644 index 0000000000..0cc477ea9a --- /dev/null +++ b/OsmAnd/res/layout/empty_state_osm_edits.xml @@ -0,0 +1,39 @@ + + + + + + + + + + \ No newline at end of file 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/res/layout/list_item_header.xml b/OsmAnd/res/layout/list_item_header.xml index 8799f11e36..24ab6fb14f 100644 --- a/OsmAnd/res/layout/list_item_header.xml +++ b/OsmAnd/res/layout/list_item_header.xml @@ -45,4 +45,4 @@ - + \ No newline at end of file diff --git a/OsmAnd/res/layout/note_list_item.xml b/OsmAnd/res/layout/note_list_item.xml index c0faa3a780..91f89197c9 100644 --- a/OsmAnd/res/layout/note_list_item.xml +++ b/OsmAnd/res/layout/note_list_item.xml @@ -58,8 +58,9 @@ android:layout_height="wrap_content" android:ellipsize="end" android:maxLines="1" + android:layout_marginTop="@dimen/map_widget_icon_margin" android:textColor="?android:textColorSecondary" - android:textSize="@dimen/default_sub_text_size" + android:textSize="@dimen/default_desc_text_size" tools:text="Oct 13, 2017 * 3 MB * 01:14"/> diff --git a/OsmAnd/res/values/colors.xml b/OsmAnd/res/values/colors.xml index c95e62c66f..3ce6338481 100644 --- a/OsmAnd/res/values/colors.xml +++ b/OsmAnd/res/values/colors.xml @@ -305,4 +305,8 @@ #9fadfc #ed5421 + #78cc5c + #fac403 + #ee5622 + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 0182b51716..74bd2dc17a 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,11 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Create or modify OSM objects + Create or modify OSM POI, opening or commenting OSM Notes, and contributing recorded GPX files. + Deleted + Edited + Added Marker %s activated. Tap on marker on the map, move it to the first place in active markers, without opening context menu. One tap active 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 bcaa26d95f..f2ac87d344 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -258,11 +258,9 @@ public class OsmEditingPlugin extends OsmandPlugin { @Override public void addMyPlacesTab(FavoritesActivity favoritesActivity, List mTabs, Intent intent) { - if (getDBPOI().getOpenstreetmapPoints().size() > 0 || getDBBug().getOsmbugsPoints().size() > 0) { - mTabs.add(favoritesActivity.getTabIndicator(R.string.osm_edits, OsmEditsFragment.class)); - if (intent != null && "OSM".equals(intent.getStringExtra("TAB"))) { - app.getSettings().FAVORITES_TAB.set(R.string.osm_edits); - } + mTabs.add(favoritesActivity.getTabIndicator(R.string.osm_edits, OsmEditsFragment.class)); + if (intent != null && "OSM".equals(intent.getStringExtra("TAB"))) { + app.getSettings().FAVORITES_TAB.set(R.string.osm_edits); } } @@ -423,21 +421,32 @@ 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; } } - private static String getPrefix(OsmPoint osmPoint) { - return (osmPoint.getGroup() == OsmPoint.Group.POI ? "POI " : "Bug ") + " id: " + osmPoint.getId() + " "; + 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() + " "; } @Override diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java new file mode 100644 index 0000000000..ece0f7147f --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java @@ -0,0 +1,228 @@ +package net.osmand.plus.osmedit; + +import android.graphics.drawable.Drawable; +import android.support.annotation.NonNull; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.CheckBox; +import android.widget.ImageButton; +import android.widget.ImageView; +import android.widget.TextView; + +import net.osmand.osm.PoiType; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.render.RenderingIcons; +import net.osmand.util.Algorithms; + +import java.util.List; +import java.util.Map; + +public class OsmEditsAdapter extends ArrayAdapter { + + private OsmandApplication app; + + private boolean selectionMode; + private List selectedOsmEdits; + + private OsmEditsAdapterListener listener; + + public OsmEditsAdapter(OsmandApplication app, @NonNull List points) { + super(app, 0, points); + this.app = app; + } + + public boolean isSelectionMode() { + return selectionMode; + } + + public void setSelectionMode(boolean selectionMode) { + this.selectionMode = selectionMode; + } + + public void setSelectedOsmEdits(List selectedOsmEdits) { + this.selectedOsmEdits = selectedOsmEdits; + } + + public void setAdapterListener(OsmEditsAdapterListener listener) { + this.listener = listener; + } + + @NonNull + @Override + public View getView(int position, View convertView, @NonNull ViewGroup parent) { + View view = convertView; + if (view == null) { + view = LayoutInflater.from(getContext()).inflate(R.layout.note_list_item, parent, false); + OsmEditViewHolder holder = new OsmEditViewHolder(view); + view.setTag(holder); + } + final OsmPoint osmEdit = getItem(position); + + if (osmEdit != null) { + final OsmEditViewHolder holder = (OsmEditViewHolder) view.getTag(); + + holder.titleTextView.setText(OsmEditingPlugin.getName(osmEdit)); + holder.descriptionTextView.setText(getDescription(osmEdit)); + Drawable icon = getIcon(osmEdit); + if (icon != null) { + holder.icon.setImageDrawable(icon); + } + if (selectionMode) { + holder.optionsImageButton.setVisibility(View.GONE); + holder.selectCheckBox.setVisibility(View.VISIBLE); + holder.selectCheckBox.setChecked(selectedOsmEdits.contains(osmEdit)); + holder.icon.setVisibility(View.GONE); + holder.selectCheckBox.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onItemSelect(osmEdit, holder.selectCheckBox.isChecked()); + } + } + }); + } else { + holder.icon.setVisibility(View.VISIBLE); + holder.optionsImageButton.setVisibility(View.VISIBLE); + holder.selectCheckBox.setVisibility(View.GONE); + } + + holder.optionsImageButton.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_overflow_menu_white)); + holder.optionsImageButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.onOptionsClick(osmEdit); + } + } + }); + holder.mainView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (selectionMode) { + holder.selectCheckBox.performClick(); + } else { + if (listener != null) { + listener.onItemShowMap(osmEdit); + } + } + + } + }); + boolean showDivider = getCount() > 1 && position != getCount() - 1; + holder.bottomDivider.setVisibility(showDivider ? View.VISIBLE : View.GONE); + } + + return view; + } + + private Drawable getIcon(OsmPoint point) { + if (point.getGroup() == OsmPoint.Group.POI) { + OpenstreetmapPoint osmPoint = (OpenstreetmapPoint) point; + int iconResId = 0; + String poiTranslation = osmPoint.getEntity().getTag(EditPoiData.POI_TYPE_TAG); + if (poiTranslation != null) { + Map poiTypeMap = app.getPoiTypes().getAllTranslatedNames(false); + PoiType poiType = poiTypeMap.get(poiTranslation.toLowerCase()); + if (poiType != null) { + String id = null; + if (RenderingIcons.containsBigIcon(poiType.getIconKeyName())) { + id = poiType.getIconKeyName(); + } else if (RenderingIcons.containsBigIcon(poiType.getOsmTag() + "_" + poiType.getOsmValue())) { + id = poiType.getOsmTag() + "_" + poiType.getOsmValue(); + } + if (id != null) { + iconResId = RenderingIcons.getBigIconResourceId(id); + } + } + } + if (iconResId == 0) { + iconResId = R.drawable.ic_type_info; + } + int colorResId = R.color.color_distance; + if (point.getAction() == OsmPoint.Action.CREATE) { + colorResId = R.color.color_osm_edit_create; + } else if (point.getAction() == OsmPoint.Action.MODIFY) { + colorResId = R.color.color_osm_edit_modify; + } else if (point.getAction() == OsmPoint.Action.DELETE) { + colorResId = R.color.color_osm_edit_delete; + } else if (point.getAction() == OsmPoint.Action.REOPEN) { + colorResId = R.color.color_osm_edit_modify; + } + return app.getIconsCache().getIcon(iconResId, colorResId); + } else if (point.getGroup() == OsmPoint.Group.BUG) { + return app.getIconsCache().getIcon(R.drawable.ic_type_bug, R.color.color_distance); + } + return null; + } + + private String getDescription(OsmPoint point) { + String action = ""; + if (point.getAction() == OsmPoint.Action.CREATE) { + action = getContext().getString(R.string.shared_string_added); + } else if (point.getAction() == OsmPoint.Action.MODIFY) { + action = getContext().getString(R.string.shared_string_edited); + } else if (point.getAction() == OsmPoint.Action.DELETE) { + action = getContext().getString(R.string.shared_string_deleted); + } else if (point.getAction() == OsmPoint.Action.REOPEN) { + action = getContext().getString(R.string.shared_string_edited); + } + + String category = ""; + if (point.getGroup() == OsmPoint.Group.POI) { + category = ((OpenstreetmapPoint) point).getEntity().getTag(EditPoiData.POI_TYPE_TAG); + } + + String comment = ""; + if (point.getGroup() == OsmPoint.Group.BUG) { + comment = getContext().getString(R.string.osn_bug_name); + } + + String prefix = OsmEditingPlugin.getPrefix(point); + + String description = ""; + if (!Algorithms.isEmpty(action)) { + description += action + " • "; + } + if (!Algorithms.isEmpty(comment)) { + description += comment + " • "; + } + if (!Algorithms.isEmpty(category)) { + description += category + " • "; + } + description += prefix; + + return description; + } + + private class OsmEditViewHolder { + View mainView; + ImageView icon; + CheckBox selectCheckBox; + ImageButton optionsImageButton; + TextView titleTextView; + TextView descriptionTextView; + View bottomDivider; + + OsmEditViewHolder(View view) { + mainView = view; + icon = (ImageView) view.findViewById(R.id.icon); + selectCheckBox = (CheckBox) view.findViewById(R.id.check_box); + optionsImageButton = (ImageButton) view.findViewById(R.id.options); + titleTextView = (TextView) view.findViewById(R.id.title); + descriptionTextView = (TextView) view.findViewById(R.id.description); + bottomDivider = view.findViewById(R.id.bottom_divider); + } + } + + public interface OsmEditsAdapterListener { + + void onItemSelect(OsmPoint point, boolean checked); + + void onItemShowMap(OsmPoint point); + + 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 2f4bff96e6..0ab69b4764 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -9,10 +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.view.MenuItemCompat; +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 +19,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.AdapterView.OnItemClickListener; +import android.view.ViewStub; import android.widget.ArrayAdapter; import android.widget.CheckBox; import android.widget.EditText; @@ -30,7 +28,6 @@ import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; -import net.osmand.AndroidUtils; import net.osmand.data.PointDescription; import net.osmand.osm.edit.Node; import net.osmand.plus.OsmandApplication; @@ -41,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; @@ -60,44 +56,68 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -public class OsmEditsFragment extends OsmAndListFragment - implements SendPoiDialogFragment.ProgressDialogPoiUploader, OpenstreetmapLocalUtil.OnNodeCommittedListener { - OsmEditingPlugin plugin; - - private OsmEditsAdapter listAdapter; - private View footerView; - - private boolean selectionMode = false; - +public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialogFragment.ProgressDialogPoiUploader, OpenstreetmapLocalUtil.OnNodeCommittedListener { private final static int MODE_DELETE = 100; private final static int MODE_UPLOAD = 101; - private ActionMode actionMode; - private long refreshId; + private OsmEditingPlugin plugin; + + private View footerView; + private View headerView; + private View emptyView; + + private List osmEdits = new ArrayList<>(); + private OsmEditsAdapter listAdapter; private ArrayList osmEditsSelected = new ArrayList<>(); + private ActionMode actionMode; + private long refreshId; + + public static void getOsmEditView(View v, OsmPoint child, OsmandApplication app) { + TextView viewName = ((TextView) v.findViewById(R.id.name)); + ImageView icon = (ImageView) v.findViewById(R.id.icon); + String name = OsmEditingPlugin.getEditName(child); + viewName.setText(name); + if (child.getGroup() == OsmPoint.Group.POI) { + icon.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_type_info, R.color.color_distance)); + } else if (child.getGroup() == OsmPoint.Group.BUG) { + icon.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_type_bug, R.color.color_distance)); + } + + TextView descr = (TextView) v.findViewById(R.id.description); + if (child.getAction() == OsmPoint.Action.CREATE) { + descr.setText(R.string.action_create); + } else if (child.getAction() == OsmPoint.Action.MODIFY) { + descr.setText(R.string.action_modify); + } else if (child.getAction() == OsmPoint.Action.DELETE) { + descr.setText(R.string.action_delete); + } else if (child.getAction() == OsmPoint.Action.REOPEN) { + descr.setText(R.string.action_modify); + } + } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setHasOptionsMenu(true); plugin = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class); - View view = getActivity().getLayoutInflater().inflate(R.layout.update_index, container, false); - ((TextView) view.findViewById(R.id.header)).setText(R.string.your_edits); - final CheckBox selectAll = (CheckBox) view.findViewById(R.id.select_all); - selectAll.setVisibility(View.GONE); - selectAll.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (selectAll.isChecked()) { - selectAll(); - } else { - deselectAll(); - } - updateSelectionTitle(actionMode); - } - }); + View view = inflater.inflate(R.layout.update_index, container, false); + view.findViewById(R.id.header_layout).setVisibility(View.GONE); + ViewStub emptyStub = (ViewStub) view.findViewById(R.id.empty_view_stub); + emptyStub.setLayoutResource(R.layout.empty_state_osm_edits); + emptyView = emptyStub.inflate(); + int icRes = getMyApplication().getSettings().isLightContent() + ? 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); + emptyView.setBackgroundColor(getResources().getColor(getMyApplication().getSettings() + .isLightContent() ? R.color.ctx_menu_info_view_bg_light : R.color.ctx_menu_info_view_bg_dark)); + + Fragment optionsFragment = getChildFragmentManager().findFragmentByTag(OsmEditOptionsBottomSheetDialogFragment.TAG); + if (optionsFragment != null) { + ((OsmEditOptionsBottomSheetDialogFragment) optionsFragment).setListener(createOsmEditOptionsFragmentListener()); + } + plugin.getPoiModificationLocalUtil().addNodeCommittedListener(this); return view; } @@ -108,23 +128,24 @@ public class OsmEditsFragment extends OsmAndListFragment super.onDestroyView(); } - public android.widget.ArrayAdapter getAdapter() { + @Override + public ArrayAdapter getAdapter() { return listAdapter; } - + private void selectAll() { - for (int i = 0; i < listAdapter.getCount(); i++) { - OsmPoint point = listAdapter.getItem(i); + for (int i = 0; i < osmEdits.size(); i++) { + OsmPoint point = osmEdits.get(i); if (!osmEditsSelected.contains(point)) { osmEditsSelected.add(point); } } - listAdapter.notifyDataSetInvalidated(); + listAdapter.notifyDataSetChanged(); } private void deselectAll() { osmEditsSelected.clear(); - listAdapter.notifyDataSetInvalidated(); + listAdapter.notifyDataSetChanged(); } @Override @@ -147,22 +168,22 @@ public class OsmEditsFragment extends OsmAndListFragment return true; } }); - MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); + item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); item = menu.add(R.string.local_osm_changes_backup). setIcon(R.drawable.ic_action_gshare_dark); - MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); + item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { new BackupOpenstreetmapPointAsyncTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, - listAdapter.dataPoints.toArray(new OsmPoint[listAdapter.dataPoints.size()])); + osmEdits.toArray(new OsmPoint[osmEdits.size()])); return true; } }); item = menu.add(R.string.shared_string_delete_all). setIcon(R.drawable.ic_action_delete_dark); - MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); + item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { @@ -178,8 +199,7 @@ public class OsmEditsFragment extends OsmAndListFragment @Override public boolean onCreateActionMode(final ActionMode mode, Menu menu) { enableSelectionMode(true); - MenuItem item = menu.add(R.string.local_openstreetmap_uploadall). - setIcon(R.drawable.ic_action_export); + MenuItem item = menu.add(R.string.local_openstreetmap_uploadall).setIcon(R.drawable.ic_action_export); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { @@ -188,9 +208,9 @@ public class OsmEditsFragment extends OsmAndListFragment return true; } }); - MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); + item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); osmEditsSelected.clear(); - listAdapter.notifyDataSetInvalidated(); + listAdapter.notifyDataSetChanged(); updateSelectionMode(mode); return true; } @@ -208,7 +228,7 @@ public class OsmEditsFragment extends OsmAndListFragment @Override public void onDestroyActionMode(ActionMode mode) { enableSelectionMode(false); - listAdapter.notifyDataSetInvalidated(); + listAdapter.notifyDataSetChanged(); } }); @@ -240,9 +260,9 @@ public class OsmEditsFragment extends OsmAndListFragment return true; } }); - MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); + item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); osmEditsSelected.clear(); - listAdapter.notifyDataSetInvalidated(); + listAdapter.notifyDataSetChanged(); updateSelectionMode(mode); return true; } @@ -260,7 +280,7 @@ public class OsmEditsFragment extends OsmAndListFragment @Override public void onDestroyActionMode(ActionMode mode) { enableSelectionMode(false); - listAdapter.notifyDataSetInvalidated(); + listAdapter.notifyDataSetChanged(); } }); @@ -285,9 +305,9 @@ public class OsmEditsFragment extends OsmAndListFragment if (view == null) { return; } - CheckBox selectAll = (CheckBox) view.findViewById(R.id.select_all); - for (int i = 0; i < listAdapter.getCount(); i++) { - OsmPoint point = listAdapter.getItem(i); + CheckBox selectAll = (CheckBox) view.findViewById(R.id.check_box); + for (int i = 0; i < osmEdits.size(); i++) { + OsmPoint point = osmEdits.get(i); if (!osmEditsSelected.contains(point)) { selectAll.setChecked(false); return; @@ -297,11 +317,10 @@ public class OsmEditsFragment extends OsmAndListFragment } private void enableSelectionMode(boolean selectionMode) { - this.selectionMode = selectionMode; + listAdapter.setSelectionMode(selectionMode); //noinspection ConstantConditions - getView().findViewById(R.id.select_all).setVisibility(selectionMode ? View.VISIBLE : View.GONE); - ((FavoritesActivity) getActivity()).setToolbarVisibility(!selectionMode && - AndroidUiHelper.isOrientationPortrait(getActivity())); + getView().findViewById(R.id.check_box).setVisibility(selectionMode ? View.VISIBLE : View.GONE); + ((FavoritesActivity) getActivity()).setToolbarVisibility(!selectionMode && AndroidUiHelper.isOrientationPortrait(getActivity())); ((FavoritesActivity) getActivity()).updateListViewFooter(footerView); } @@ -313,17 +332,15 @@ public class OsmEditsFragment extends OsmAndListFragment } private void deleteItems(final ArrayList points) { - DeleteOsmEditsConfirmDialogFragment.createInstance(points). - show(getChildFragmentManager(), DeleteOsmEditsConfirmDialogFragment.TAG); + DeleteOsmEditsConfirmDialogFragment.createInstance(points).show(getChildFragmentManager(), DeleteOsmEditsConfirmDialogFragment.TAG); } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - getListView().setBackgroundColor( - getResources().getColor( - getMyApplication().getSettings().isLightContent() ? R.color.ctx_menu_info_view_bg_light - : R.color.ctx_menu_info_view_bg_dark)); + getListView().setBackgroundColor(getResources().getColor(getMyApplication().getSettings().isLightContent() + ? R.color.ctx_menu_info_view_bg_light + : R.color.ctx_menu_info_view_bg_dark)); } @Override @@ -333,34 +350,62 @@ public class OsmEditsFragment extends OsmAndListFragment } private void fetchData() { - ArrayList dataPoints = new ArrayList<>(); + osmEdits = new ArrayList<>(); List l1 = plugin.getDBPOI().getOpenstreetmapPoints(); List l2 = plugin.getDBBug().getOsmbugsPoints(); - dataPoints.addAll(l1); - dataPoints.addAll(l2); - if (listAdapter == null) { - listAdapter = new OsmEditsAdapter(dataPoints); - ListView listView = getListView(); - if (dataPoints.size() > 0 && footerView == null) { - //listView.addHeaderView(getActivity().getLayoutInflater().inflate(R.layout.list_shadow_header, null, false)); - footerView = getActivity().getLayoutInflater().inflate(R.layout.list_shadow_footer, null, false); + osmEdits.addAll(l1); + osmEdits.addAll(l2); + ListView listView = getListView(); + listView.setDivider(null); + listView.setEmptyView(emptyView); + + if (osmEdits.size() > 0) { + if (footerView == null) { + footerView = getActivity().getLayoutInflater().inflate(R.layout.list_shadow_footer, listView, false); listView.addFooterView(footerView); - listView.setHeaderDividersEnabled(false); - listView.setFooterDividersEnabled(false); } - listView.setAdapter(listAdapter); - listView.setOnItemClickListener(new OnItemClickListener() { - - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - OsmPoint it = listAdapter.getItem(position); - openPopUpMenu(view, it); - - } - }); - } else { - listAdapter.setNewList(dataPoints); + if (headerView == null) { + headerView = getActivity().getLayoutInflater().inflate(R.layout.list_item_header, listView, false); + listView.addHeaderView(headerView); + ((TextView) headerView.findViewById(R.id.title_text_view)).setText(R.string.your_edits); + final CheckBox selectAll = (CheckBox) headerView.findViewById(R.id.check_box); + selectAll.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (selectAll.isChecked()) { + selectAll(); + } else { + deselectAll(); + } + updateSelectionTitle(actionMode); + } + }); + } } + listAdapter = new OsmEditsAdapter(getMyApplication(), osmEdits); + listAdapter.setSelectedOsmEdits(osmEditsSelected); + listAdapter.setAdapterListener(new OsmEditsAdapter.OsmEditsAdapterListener() { + @Override + public void onItemSelect(OsmPoint point, boolean checked) { + if (checked) { + osmEditsSelected.add(point); + } else { + osmEditsSelected.remove(point); + } + updateSelectionMode(actionMode); + } + + @Override + public void onItemShowMap(OsmPoint point) { + showOnMap(point); + } + + @Override + public void onOptionsClick(OsmPoint note) { + openPopUpMenu(note); + } + }); + listView.setAdapter(listAdapter); } private void showBugDialog(final OsmNotesPoint point) { @@ -390,31 +435,6 @@ public class OsmEditsFragment extends OsmAndListFragment builder.create().show(); } - public static void getOsmEditView(View v, OsmPoint child, OsmandApplication app) { - TextView viewName = ((TextView) v.findViewById(R.id.name)); - ImageView icon = (ImageView) v.findViewById(R.id.icon); - String name = OsmEditingPlugin.getEditName(child); - viewName.setText(name); - if (child.getGroup() == OsmPoint.Group.POI) { - icon.setImageDrawable(app.getIconsCache(). - getIcon(R.drawable.ic_type_info, R.color.color_distance)); - } else if (child.getGroup() == OsmPoint.Group.BUG) { - icon.setImageDrawable(app.getIconsCache(). - getIcon(R.drawable.ic_type_bug, R.color.color_distance)); - } - - TextView descr = (TextView) v.findViewById(R.id.description); - if (child.getAction() == OsmPoint.Action.CREATE) { - descr.setText(R.string.action_create); - } else if (child.getAction() == OsmPoint.Action.MODIFY) { - descr.setText(R.string.action_modify); - } else if (child.getAction() == OsmPoint.Action.DELETE) { - descr.setText(R.string.action_delete); - } else if (child.getAction() == OsmPoint.Action.REOPEN) { - descr.setText(R.string.action_modify); - } - } - @Override public void onNoteCommitted() { getMyApplication().runInUIThread(new Runnable() { @@ -425,173 +445,56 @@ public class OsmEditsFragment extends OsmAndListFragment }); } - protected class OsmEditsAdapter extends ArrayAdapter { - private List dataPoints; - - - public OsmEditsAdapter(List points) { - super(getActivity(), net.osmand.plus.R.layout.note, points); - dataPoints = points; - } - - public void setNewList(List dp) { - dataPoints = dp; - setNotifyOnChange(false); - clear(); - for (OsmPoint pnt : dp) { - add(pnt); - } - setNotifyOnChange(true); - notifyDataSetChanged(); - } - - public List getDataPoints() { - return dataPoints; - } - - public void delete(OsmPoint i) { - dataPoints.remove(i); - remove(i); - listAdapter.notifyDataSetChanged(); - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - View v = convertView; - final OsmPoint child = getItem(position); - if (v == null) { - LayoutInflater inflater = getActivity().getLayoutInflater(); - v = inflater.inflate(net.osmand.plus.R.layout.note, parent, false); - } - getOsmEditView(v, child, getMyApplication()); - - v.findViewById(R.id.play).setVisibility(View.GONE); - - final CheckBox ch = (CheckBox) v.findViewById(R.id.check_local_index); - View options = v.findViewById(R.id.options); - if (selectionMode) { - options.setVisibility(View.GONE); - ch.setVisibility(View.VISIBLE); - ch.setChecked(osmEditsSelected.contains(child)); - v.findViewById(R.id.icon).setVisibility(View.GONE); - ch.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - onItemSelect(ch, child); - } - }); - } else { - v.findViewById(R.id.icon).setVisibility(View.VISIBLE); - options.setVisibility(View.VISIBLE); - ch.setVisibility(View.GONE); - } - - ((ImageView) options).setImageDrawable(getMyApplication().getIconsCache() - .getThemedIcon(R.drawable.ic_overflow_menu_white)); - options.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - openPopUpMenu(v, child); - } - }); - v.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (selectionMode) { - ch.setChecked(!ch.isChecked()); - onItemSelect(ch, child); - } else { - showOnMap(child); - } - - } - }); - return v; - } - - public void onItemSelect(CheckBox ch, OsmPoint child) { - if (ch.isChecked()) { - osmEditsSelected.add(child); - } else { - osmEditsSelected.remove(child); - } - updateSelectionMode(actionMode); - } - + 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 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 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) { - if(info instanceof OpenstreetmapPoint && info.getId() == refreshId) { - for(OpenstreetmapPoint p : plugin.getDBPOI().getOpenstreetmapPoints()) { - if(p.getId() == info.getId()) { + if (info instanceof OpenstreetmapPoint && info.getId() == refreshId) { + for (OpenstreetmapPoint p : plugin.getDBPOI().getOpenstreetmapPoints()) { + if (p.getId() == info.getId()) { return p; } } @@ -623,22 +526,85 @@ public class OsmEditsFragment extends OsmAndListFragment super.uploadEnded(loadErrorsMap); for (OsmPoint osmPoint : loadErrorsMap.keySet()) { if (loadErrorsMap.get(osmPoint) == null) { - listAdapter.remove(osmPoint); + osmEdits.remove(osmPoint); } } listAdapter.notifyDataSetChanged(); } }; dialog.show(getActivity().getSupportFragmentManager(), ProgressDialogFragment.TAG); - UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask( - dialog, listener, plugin, points.length, closeChangeSet, anonymously); + UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(dialog, listener, plugin, points.length, closeChangeSet, anonymously); uploadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, points); } + private void showOnMap(OsmPoint osmPoint) { + boolean isOsmPoint = osmPoint instanceof OpenstreetmapPoint; + String type = osmPoint.getGroup() == OsmPoint.Group.POI ? PointDescription.POINT_TYPE_POI : PointDescription.POINT_TYPE_OSM_BUG; + String name = (isOsmPoint ? ((OpenstreetmapPoint) osmPoint).getName() : ((OsmNotesPoint) osmPoint).getText()); + getMyApplication().getSettings().setMapLocationToShow(osmPoint.getLatitude(), osmPoint.getLongitude(), 15, + new PointDescription(type, name), true, osmPoint); //$NON-NLS-1$ + MapActivity.launchMapActivityMoveToTop(getActivity()); + } + + private void deletePoint(OsmPoint osmPoint) { + osmEdits.remove(osmPoint); + listAdapter.notifyDataSetChanged(); + } + + private void notifyDataSetChanged() { + listAdapter.notifyDataSetChanged(); + } + + public static class DeleteOsmEditsConfirmDialogFragment extends DialogFragment { + public static final String TAG = "DeleteOsmEditsConfirmDialogFragment"; + private static final String POINTS_LIST = "points_list"; + + public static DeleteOsmEditsConfirmDialogFragment createInstance( + ArrayList points) { + DeleteOsmEditsConfirmDialogFragment fragment = new DeleteOsmEditsConfirmDialogFragment(); + Bundle args = new Bundle(); + args.putSerializable(POINTS_LIST, points); + fragment.setArguments(args); + return fragment; + } + + @NonNull + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + final OsmEditsFragment parentFragment = (OsmEditsFragment) getParentFragment(); + final OsmEditingPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class); + @SuppressWarnings("unchecked") + final ArrayList points = (ArrayList) getArguments().getSerializable(POINTS_LIST); + + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + assert points != null; + builder.setMessage(getString(R.string.local_osm_changes_delete_all_confirm, points.size())); + builder.setPositiveButton(R.string.shared_string_delete, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Iterator it = points.iterator(); + while (it.hasNext()) { + OsmPoint osmPoint = it.next(); + assert plugin != null; + if (osmPoint.getGroup() == OsmPoint.Group.POI) { + plugin.getDBPOI().deletePOI((OpenstreetmapPoint) osmPoint); + } else if (osmPoint.getGroup() == OsmPoint.Group.BUG) { + plugin.getDBBug().deleteAllBugModifications((OsmNotesPoint) osmPoint); + } + it.remove(); + parentFragment.deletePoint(osmPoint); + } + parentFragment.notifyDataSetChanged(); + + } + }); + builder.setNegativeButton(R.string.shared_string_cancel, null); + return builder.create(); + } + } public class BackupOpenstreetmapPointAsyncTask extends AsyncTask { - private File osmchange; public BackupOpenstreetmapPointAsyncTask() { @@ -745,71 +711,4 @@ public class OsmEditsFragment extends OsmAndListFragment } } - private void showOnMap(OsmPoint osmPoint) { - boolean isOsmPoint = osmPoint instanceof OpenstreetmapPoint; - String type = osmPoint.getGroup() == OsmPoint.Group.POI ? PointDescription.POINT_TYPE_POI : PointDescription.POINT_TYPE_OSM_BUG; - String name = (isOsmPoint ? ((OpenstreetmapPoint) osmPoint).getName() : ((OsmNotesPoint) osmPoint).getText()); - getMyApplication().getSettings().setMapLocationToShow(osmPoint.getLatitude(), osmPoint.getLongitude(), 15, - new PointDescription(type, name), true, osmPoint); //$NON-NLS-1$ - MapActivity.launchMapActivityMoveToTop(getActivity()); - } - - private void deletePoint(OsmPoint osmPoint) { - listAdapter.delete(osmPoint); - } - - private void notifyDataSetChanged() { - listAdapter.notifyDataSetChanged(); - } - - public static class DeleteOsmEditsConfirmDialogFragment extends DialogFragment { - public static final String TAG = "DeleteOsmEditsConfirmDialogFragment"; - private static final String POINTS_LIST = "points_list"; - - @NonNull - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - final OsmEditsFragment parentFragment = (OsmEditsFragment) getParentFragment(); - final OsmEditingPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class); - @SuppressWarnings("unchecked") - final ArrayList points = - (ArrayList) getArguments().getSerializable(POINTS_LIST); - - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - assert points != null; - builder.setMessage(getString(R.string.local_osm_changes_delete_all_confirm, - points.size())); - builder.setPositiveButton(R.string.shared_string_delete, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - Iterator it = points.iterator(); - while (it.hasNext()) { - OsmPoint osmPoint = it.next(); - assert plugin != null; - if (osmPoint.getGroup() == OsmPoint.Group.POI) { - plugin.getDBPOI().deletePOI((OpenstreetmapPoint) osmPoint); - } else if (osmPoint.getGroup() == OsmPoint.Group.BUG) { - plugin.getDBBug().deleteAllBugModifications((OsmNotesPoint) osmPoint); - } - it.remove(); - parentFragment.deletePoint(osmPoint); - } - parentFragment.notifyDataSetChanged(); - - } - }); - builder.setNegativeButton(R.string.shared_string_cancel, null); - return builder.create(); - } - - public static DeleteOsmEditsConfirmDialogFragment createInstance( - ArrayList points) { - DeleteOsmEditsConfirmDialogFragment fragment = new DeleteOsmEditsConfirmDialogFragment(); - Bundle args = new Bundle(); - args.putSerializable(POINTS_LIST, points); - fragment.setArguments(args); - return fragment; - } - } - } \ No newline at end of file