Update poi

This commit is contained in:
Victor Shcherb 2015-11-16 01:14:36 +01:00
parent 0314ef16e6
commit 854c15d158
2 changed files with 61 additions and 39 deletions

View file

@ -44,7 +44,7 @@ import android.widget.ImageButton;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.CallbackWithObject;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
@ -97,6 +97,7 @@ public class EditPoiDialogFragment extends DialogFragment {
private OpenstreetmapUtil mOpenstreetmapUtil; private OpenstreetmapUtil mOpenstreetmapUtil;
private TextInputLayout poiTypeTextInputLayout; private TextInputLayout poiTypeTextInputLayout;
private View view;
@Override @Override
public void onAttach(Activity activity) { public void onAttach(Activity activity) {
@ -128,7 +129,7 @@ public class EditPoiDialogFragment extends DialogFragment {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_edit_poi, container, false); view = inflater.inflate(R.layout.fragment_edit_poi, container, false);
final OsmandSettings settings = getMyApplication().getSettings(); final OsmandSettings settings = getMyApplication().getSettings();
boolean isLightTheme = settings.OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; boolean isLightTheme = settings.OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
@ -327,19 +328,20 @@ public class EditPoiDialogFragment extends DialogFragment {
node.putTag(tag.getKey(), tag.getValue()); node.putTag(tag.getKey(), tag.getValue());
} }
} }
commitNode(action, node, mOpenstreetmapUtil.getEntityInfo(node.getId()), commitNode(action, node, mOpenstreetmapUtil.getEntityInfo(node.getId()), "", false,
"", new CallbackWithObject<Node>() {
false,
new Runnable() {
@Override @Override
public void run() { public boolean processResult(Node result) {
if (result != null) {
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (plugin != null && offlineEdit) { if (plugin != null && offlineEdit) {
List<OpenstreetmapPoint> points = plugin.getDBPOI().getOpenstreetmapPoints(); List<OpenstreetmapPoint> points = plugin.getDBPOI().getOpenstreetmapPoints();
if (getActivity() instanceof MapActivity && points.size() > 0) { if (getActivity() instanceof MapActivity && points.size() > 0) {
OsmPoint point = points.get(points.size() - 1); OsmPoint point = points.get(points.size() - 1);
MapActivity mapActivity = (MapActivity) getActivity(); MapActivity mapActivity = (MapActivity) getActivity();
mapActivity.getContextMenu().showOrUpdate(new LatLon(point.getLatitude(), point.getLongitude()), mapActivity.getContextMenu().showOrUpdate(
new LatLon(point.getLatitude(), point.getLongitude()),
plugin.getOsmEditsLayer(mapActivity).getObjectName(point), point); plugin.getOsmEditsLayer(mapActivity).getObjectName(point), point);
} }
} }
@ -348,6 +350,15 @@ public class EditPoiDialogFragment extends DialogFragment {
((MapActivity) getActivity()).getMapView().refreshMap(true); ((MapActivity) getActivity()).getMapView().refreshMap(true);
} }
dismiss(); dismiss();
} else {
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
mOpenstreetmapUtil = plugin.getPoiModificationLocalUtil();
Button saveButton = (Button) view.findViewById(R.id.saveButton);
saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil
? R.string.shared_string_upload : R.string.shared_string_save);
}
return false;
} }
}, getActivity(), mOpenstreetmapUtil); }, getActivity(), mOpenstreetmapUtil);
} }
@ -399,7 +410,7 @@ public class EditPoiDialogFragment extends DialogFragment {
final EntityInfo info, final EntityInfo info,
final String comment, final String comment,
final boolean closeChangeSet, final boolean closeChangeSet,
final Runnable successAction, final CallbackWithObject<Node> postExecute,
final Activity activity, final Activity activity,
final OpenstreetmapUtil openstreetmapUtil) { final OpenstreetmapUtil openstreetmapUtil) {
if (info == null && OsmPoint.Action.CREATE != action && openstreetmapUtil instanceof OpenstreetmapRemoteUtil) { if (info == null && OsmPoint.Action.CREATE != action && openstreetmapUtil instanceof OpenstreetmapRemoteUtil) {
@ -423,8 +434,8 @@ public class EditPoiDialogFragment extends DialogFragment {
@Override @Override
protected void onPostExecute(Node result) { protected void onPostExecute(Node result) {
progress.dismiss(); progress.dismiss();
if (result != null) { if(postExecute != null) {
successAction.run(); postExecute.processResult(result);
} }
} }
}.execute(); }.execute();
@ -640,25 +651,36 @@ public class EditPoiDialogFragment extends DialogFragment {
String c = comment == null ? null : comment.getText().toString(); String c = comment == null ? null : comment.getText().toString();
boolean closeChangeSet = closeChangesetCheckBox != null boolean closeChangeSet = closeChangesetCheckBox != null
&& closeChangesetCheckBox.isChecked(); && closeChangesetCheckBox.isChecked();
commitNode(OsmPoint.Action.DELETE, n, openstreetmapUtil.getEntityInfo(n.getId()), c, deleteNode(n, c, closeChangeSet);
closeChangeSet, new Runnable() { }
});
builder.create().show();
}
private void deleteNode(final Node n, final String c, final boolean closeChangeSet) {
final boolean isLocalEdit = openstreetmapUtil instanceof OpenstreetmapLocalUtil;
commitNode(OsmPoint.Action.DELETE, n, openstreetmapUtil.getEntityInfo(n.getId()), c, closeChangeSet,
new CallbackWithObject<Node>() {
@Override @Override
public void run() { public boolean processResult(Node result) {
if (result != null) {
if (isLocalEdit) { if (isLocalEdit) {
AccessibleToast.makeText( AccessibleToast.makeText(activity, R.string.osm_changes_added_to_local_edits,
activity, R.string.osm_changes_added_to_local_edits,
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
} else { } else {
AccessibleToast.makeText(activity, R.string.poi_remove_success, Toast.LENGTH_LONG).show(); AccessibleToast.makeText(activity, R.string.poi_remove_success, Toast.LENGTH_LONG)
.show();
} }
if (activity instanceof MapActivity) { if (activity instanceof MapActivity) {
((MapActivity) activity).getMapView().refreshMap(true); ((MapActivity) activity).getMapView().refreshMap(true);
} }
} }
}, activity, openstreetmapUtil); return false;
} }
}); }, activity, openstreetmapUtil);
builder.create().show();
} }
} }

View file

@ -94,7 +94,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
public OsmBugsLocalUtil getOsmNotesLocalUtil() { public OsmBugsLocalUtil getOsmNotesLocalUtil() {
if(localNotesUtil == null) { if(localNotesUtil == null) {
localNotesUtil = new OsmBugsLocalUtil(app, dbbug); localNotesUtil = new OsmBugsLocalUtil(app, getDBBug());
} }
return localNotesUtil; return localNotesUtil;
} }