From 79958c26f96dc57de7b756da9b652cc6a6931626 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Sat, 14 Oct 2017 15:36:11 +0300 Subject: [PATCH] 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; } });