From 631b008a784a4ac30776c092a9187f5944019c8b Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Sat, 14 Oct 2017 16:20:17 +0300 Subject: [PATCH] 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(); }