From 987e45a0dad4679876b5abed1373378146e2303f Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 13 Oct 2017 14:47:38 +0300 Subject: [PATCH 1/5] Fix #4564 --- .../plus/osmedit/EditPoiDialogFragment.java | 18 ++++++++++++++++++ .../osmand/plus/osmedit/OsmEditsFragment.java | 13 ++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java index 188915c41e..165c37ab4d 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java @@ -93,6 +93,8 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { BASIC_TAGS.add(OSMSettings.OSMTagKey.OPENING_HOURS.getValue()); } + private OnPoiChangedListener onPoiChangedListener; + private EditPoiData editPoiData; private ViewPager viewPager; private AutoCompleteTextView poiTypeEditText; @@ -101,6 +103,10 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { private TextInputLayout poiTypeTextInputLayout; private View view; + public void setOnPoiChangedListener(OnPoiChangedListener listener) { + this.onPoiChangedListener = listener; + } + @Override public void onAttach(Activity activity) { super.onAttach(activity); @@ -473,6 +479,9 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { if (getActivity() instanceof MapActivity) { ((MapActivity) getActivity()).getMapView().refreshMap(true); } + if (onPoiChangedListener != null) { + onPoiChangedListener.onPoiChanged(); + } dismiss(); } else { OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); @@ -618,11 +627,16 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { } public static EditPoiDialogFragment createInstance(Node node, boolean isAddingPoi) { + return createInstance(node, isAddingPoi, (OnPoiChangedListener) null); + } + + public static EditPoiDialogFragment createInstance(Node node, boolean isAddingPoi, OnPoiChangedListener listener) { EditPoiDialogFragment editPoiDialogFragment = new EditPoiDialogFragment(); Bundle args = new Bundle(); args.putSerializable(KEY_AMENITY_NODE, node); args.putBoolean(IS_ADDING_POI, isAddingPoi); editPoiDialogFragment.setArguments(args); + editPoiDialogFragment.setOnPoiChangedListener(listener); return editPoiDialogFragment; } @@ -835,4 +849,8 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { public interface OnFragmentActivatedListener { void onFragmentActivated(); } + + public interface OnPoiChangedListener { + void onPoiChanged(); + } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index cd221f2e5f..2eeca24776 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -323,6 +323,10 @@ public class OsmEditsFragment extends OsmAndListFragment @Override public void onResume() { super.onResume(); + fetchData(); + } + + private void fetchData() { ArrayList dataPoints = new ArrayList<>(); List l1 = plugin.getDBPOI().getOpenstreetmapPoints(); List l2 = plugin.getDBBug().getOsmbugsPoints(); @@ -351,7 +355,6 @@ public class OsmEditsFragment extends OsmAndListFragment } else { listAdapter.setNewList(dataPoints); } - } private void showBugDialog(final OsmNotesPoint point) { @@ -527,8 +530,12 @@ public class OsmEditsFragment extends OsmAndListFragment OpenstreetmapPoint i = (OpenstreetmapPoint) getPointAfterModify(info); final Node entity = i.getEntity(); refreshId = entity.getId(); - EditPoiDialogFragment.createInstance(entity, false) - .show(getActivity().getSupportFragmentManager(), "edit_poi"); + EditPoiDialogFragment.createInstance(entity, false, new EditPoiDialogFragment.OnPoiChangedListener() { + @Override + public void onPoiChanged() { + fetchData(); + } + }).show(getActivity().getSupportFragmentManager(), "edit_poi"); return true; } }); From 79958c26f96dc57de7b756da9b652cc6a6931626 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Sat, 14 Oct 2017 15:36:11 +0300 Subject: [PATCH 2/5] Create listener in openstreetmaplocalutil --- .../plus/osmedit/EditPoiDialogFragment.java | 14 -------- .../plus/osmedit/OpenstreetmapLocalUtil.java | 13 +++++++ .../osmand/plus/osmedit/OsmEditsFragment.java | 34 ++++++++++++++----- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java index 165c37ab4d..3f5de25956 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java @@ -93,8 +93,6 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { BASIC_TAGS.add(OSMSettings.OSMTagKey.OPENING_HOURS.getValue()); } - private OnPoiChangedListener onPoiChangedListener; - private EditPoiData editPoiData; private ViewPager viewPager; private AutoCompleteTextView poiTypeEditText; @@ -103,10 +101,6 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { private TextInputLayout poiTypeTextInputLayout; private View view; - public void setOnPoiChangedListener(OnPoiChangedListener listener) { - this.onPoiChangedListener = listener; - } - @Override public void onAttach(Activity activity) { super.onAttach(activity); @@ -479,9 +473,6 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { if (getActivity() instanceof MapActivity) { ((MapActivity) getActivity()).getMapView().refreshMap(true); } - if (onPoiChangedListener != null) { - onPoiChangedListener.onPoiChanged(); - } dismiss(); } else { OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); @@ -627,16 +618,11 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { } public static EditPoiDialogFragment createInstance(Node node, boolean isAddingPoi) { - return createInstance(node, isAddingPoi, (OnPoiChangedListener) null); - } - - public static EditPoiDialogFragment createInstance(Node node, boolean isAddingPoi, OnPoiChangedListener listener) { EditPoiDialogFragment editPoiDialogFragment = new EditPoiDialogFragment(); Bundle args = new Bundle(); args.putSerializable(KEY_AMENITY_NODE, node); args.putBoolean(IS_ADDING_POI, isAddingPoi); editPoiDialogFragment.setArguments(args); - editPoiDialogFragment.setOnPoiChangedListener(listener); return editPoiDialogFragment; } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java index 27c20ff791..0d33fd5d1b 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java @@ -21,6 +21,12 @@ public class OpenstreetmapLocalUtil implements OpenstreetmapUtil { this.plugin = plugin; } + private OnNodeCommittedListener listener; + + public void setOnNodeCommittedListener(OnNodeCommittedListener listener) { + this.listener = listener; + } + @Override public EntityInfo getEntityInfo(long id) { return null; @@ -41,6 +47,9 @@ public class OpenstreetmapLocalUtil implements OpenstreetmapUtil { } else { plugin.getDBPOI().addOpenstreetmap(p); } + if (listener != null) { + listener.onNoteCommitted(); + } return newNode; } @@ -78,5 +87,9 @@ public class OpenstreetmapLocalUtil implements OpenstreetmapUtil { @Override public void closeChangeSet() { } + + public interface OnNodeCommittedListener { + void onNoteCommitted(); + } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index 2eeca24776..0f7f6f6062 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -61,7 +61,7 @@ import java.util.List; import java.util.Map; public class OsmEditsFragment extends OsmAndListFragment - implements SendPoiDialogFragment.ProgressDialogPoiUploader { + implements SendPoiDialogFragment.ProgressDialogPoiUploader, OpenstreetmapLocalUtil.OnNodeCommittedListener { OsmEditingPlugin plugin; private OsmEditsAdapter listAdapter; @@ -98,10 +98,22 @@ public class OsmEditsFragment extends OsmAndListFragment updateSelectionTitle(actionMode); } }); + if (getMyApplication().getSettings().OFFLINE_EDITION.get() + || !getMyApplication().getSettings().isInternetConnectionAvailable(true)) { + plugin.getPoiModificationLocalUtil().setOnNodeCommittedListener(this); + } return view; } - + @Override + public void onDestroyView() { + if (getMyApplication().getSettings().OFFLINE_EDITION.get() + || !getMyApplication().getSettings().isInternetConnectionAvailable(true)) { + plugin.getPoiModificationLocalUtil().setOnNodeCommittedListener(null); + } + super.onDestroyView(); + } + public android.widget.ArrayAdapter getAdapter() { return listAdapter; } @@ -409,6 +421,16 @@ public class OsmEditsFragment extends OsmAndListFragment } } + @Override + public void onNoteCommitted() { + getMyApplication().runInUIThread(new Runnable() { + @Override + public void run() { + fetchData(); + } + }); + } + protected class OsmEditsAdapter extends ArrayAdapter { private List dataPoints; @@ -530,12 +552,8 @@ public class OsmEditsFragment extends OsmAndListFragment OpenstreetmapPoint i = (OpenstreetmapPoint) getPointAfterModify(info); final Node entity = i.getEntity(); refreshId = entity.getId(); - EditPoiDialogFragment.createInstance(entity, false, new EditPoiDialogFragment.OnPoiChangedListener() { - @Override - public void onPoiChanged() { - fetchData(); - } - }).show(getActivity().getSupportFragmentManager(), "edit_poi"); + EditPoiDialogFragment.createInstance(entity, false) + .show(getActivity().getSupportFragmentManager(), "edit_poi"); return true; } }); From 631b008a784a4ac30776c092a9187f5944019c8b Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Sat, 14 Oct 2017 16:20:17 +0300 Subject: [PATCH 3/5] Fix listeners --- .../plus/osmedit/OpenstreetmapLocalUtil.java | 15 +++++++++++---- .../net/osmand/plus/osmedit/OsmEditsFragment.java | 10 ++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java index 0d33fd5d1b..4adf2b756a 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java @@ -11,6 +11,9 @@ import net.osmand.util.MapUtils; import org.apache.commons.logging.Log; +import java.util.ArrayList; +import java.util.List; + public class OpenstreetmapLocalUtil implements OpenstreetmapUtil { public final static Log LOG = PlatformUtil.getLog(OpenstreetmapLocalUtil.class); @@ -21,10 +24,14 @@ public class OpenstreetmapLocalUtil implements OpenstreetmapUtil { this.plugin = plugin; } - private OnNodeCommittedListener listener; + private List listeners = new ArrayList<>(); - public void setOnNodeCommittedListener(OnNodeCommittedListener listener) { - this.listener = listener; + public void addNodeCommittedListener(OnNodeCommittedListener listener) { + listeners.add(listener); + } + + public void removeNodeCommittedListener(OnNodeCommittedListener listener) { + listeners.remove(listener); } @Override @@ -47,7 +54,7 @@ public class OpenstreetmapLocalUtil implements OpenstreetmapUtil { } else { plugin.getDBPOI().addOpenstreetmap(p); } - if (listener != null) { + for (OnNodeCommittedListener listener : listeners) { listener.onNoteCommitted(); } return newNode; diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index 0f7f6f6062..9d529744d0 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -98,19 +98,13 @@ public class OsmEditsFragment extends OsmAndListFragment updateSelectionTitle(actionMode); } }); - if (getMyApplication().getSettings().OFFLINE_EDITION.get() - || !getMyApplication().getSettings().isInternetConnectionAvailable(true)) { - plugin.getPoiModificationLocalUtil().setOnNodeCommittedListener(this); - } + plugin.getPoiModificationLocalUtil().addNodeCommittedListener(this); return view; } @Override public void onDestroyView() { - if (getMyApplication().getSettings().OFFLINE_EDITION.get() - || !getMyApplication().getSettings().isInternetConnectionAvailable(true)) { - plugin.getPoiModificationLocalUtil().setOnNodeCommittedListener(null); - } + plugin.getPoiModificationLocalUtil().removeNodeCommittedListener(null); super.onDestroyView(); } From cba0c167aad1082167620716c7d2a3abe2d57212 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Sat, 14 Oct 2017 16:22:04 +0300 Subject: [PATCH 4/5] Fix removing listener --- OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index 9d529744d0..442bacd7cd 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -104,7 +104,7 @@ public class OsmEditsFragment extends OsmAndListFragment @Override public void onDestroyView() { - plugin.getPoiModificationLocalUtil().removeNodeCommittedListener(null); + plugin.getPoiModificationLocalUtil().removeNodeCommittedListener(this); super.onDestroyView(); } From af4ad79295c31fc379757ebdb6d3a8af9466a432 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Sat, 14 Oct 2017 16:37:44 +0300 Subject: [PATCH 5/5] Remove unnecessary listener and perform checking before adding --- OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java | 4 ---- .../src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java | 4 +++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java index 3f5de25956..188915c41e 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java @@ -835,8 +835,4 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { public interface OnFragmentActivatedListener { void onFragmentActivated(); } - - public interface OnPoiChangedListener { - void onPoiChanged(); - } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java index 4adf2b756a..0370cfb7ff 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java @@ -27,7 +27,9 @@ public class OpenstreetmapLocalUtil implements OpenstreetmapUtil { private List listeners = new ArrayList<>(); public void addNodeCommittedListener(OnNodeCommittedListener listener) { - listeners.add(listener); + if (!listeners.contains(listener)) { + listeners.add(listener); + } } public void removeNodeCommittedListener(OnNodeCommittedListener listener) {