Fix listeners

This commit is contained in:
PavelRatushnyi 2017-10-14 16:20:17 +03:00
parent 7a28118033
commit 631b008a78
2 changed files with 13 additions and 12 deletions

View file

@ -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<OnNodeCommittedListener> 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;

View file

@ -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();
}