Search in sources :

Example 1 with Action

use of net.osmand.plus.plugins.osmedit.data.OsmPoint.Action in project Osmand by osmandapp.

the class AddPOIAction method execute.

@Override
public void execute(@NonNull final MapActivity mapActivity) {
    OsmandApplication app = mapActivity.getMyApplication();
    OsmandSettings settings = app.getSettings();
    OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
    if (plugin == null)
        return;
    LatLon latLon = mapActivity.getMapView().getCurrentRotatedTileBox().getCenterLatLon();
    Node node = new Node(latLon.getLatitude(), latLon.getLongitude(), -1);
    node.replaceTags(getTagsFromParams());
    EditPoiData editPoiData = new EditPoiData(node, mapActivity.getMyApplication());
    if (Boolean.parseBoolean(getParams().get(KEY_DIALOG)) || editPoiData.hasEmptyValue()) {
        Entity newEntity = editPoiData.getEntity();
        EditPoiDialogFragment editPoiDialogFragment = EditPoiDialogFragment.createInstance(newEntity, true, getTagsFromParams());
        editPoiDialogFragment.show(mapActivity.getSupportFragmentManager(), EditPoiDialogFragment.TAG);
    } else {
        OpenstreetmapUtil mOpenstreetmapUtil;
        if (plugin.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) {
            mOpenstreetmapUtil = plugin.getPoiModificationLocalUtil();
        } else {
            mOpenstreetmapUtil = plugin.getPoiModificationRemoteUtil();
        }
        final boolean offlineEdit = mOpenstreetmapUtil instanceof OpenstreetmapLocalUtil;
        Node newNode = new Node(node.getLatitude(), node.getLongitude(), node.getId());
        Action action = newNode.getId() < 0 ? OsmPoint.Action.CREATE : OsmPoint.Action.MODIFY;
        for (Map.Entry<String, String> tag : editPoiData.getTagValues().entrySet()) {
            if (tag.getKey().equals(POI_TYPE_TAG)) {
                final PoiType poiType = editPoiData.getAllTranslatedSubTypes().get(tag.getValue().trim().toLowerCase());
                if (poiType != null) {
                    newNode.putTagNoLC(poiType.getEditOsmTag(), poiType.getEditOsmValue());
                    if (poiType.getOsmTag2() != null) {
                        newNode.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2());
                    }
                    if (poiType.getEditOsmTag2() != null) {
                        newNode.putTagNoLC(poiType.getEditOsmTag2(), poiType.getEditOsmValue2());
                    }
                } else if (!Algorithms.isEmpty(tag.getValue())) {
                    PoiCategory category = editPoiData.getPoiCategory();
                    if (category != null) {
                        newNode.putTagNoLC(category.getDefaultTag(), tag.getValue());
                    }
                }
                if (offlineEdit && !Algorithms.isEmpty(tag.getValue())) {
                    newNode.putTagNoLC(tag.getKey(), tag.getValue());
                }
            } else if (!Algorithms.isEmpty(tag.getKey()) && !Algorithms.isEmpty(tag.getValue())) {
                newNode.putTagNoLC(tag.getKey(), tag.getValue());
            }
        }
        EditPoiDialogFragment.commitEntity(action, newNode, mOpenstreetmapUtil.getEntityInfo(newNode.getId()), "", false, result -> {
            if (result != null) {
                OsmEditingPlugin plugin1 = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
                if (plugin1 != null && offlineEdit) {
                    List<OpenstreetmapPoint> points = plugin1.getDBPOI().getOpenstreetmapPoints();
                    if (points.size() > 0) {
                        OsmPoint point = points.get(points.size() - 1);
                        mapActivity.getContextMenu().showOrUpdate(new LatLon(point.getLatitude(), point.getLongitude()), plugin1.getOsmEditsLayer(mapActivity).getObjectName(point), point);
                    }
                }
                mapActivity.getMapView().refreshMap(true);
            }
            return false;
        }, mapActivity, mOpenstreetmapUtil, null);
    }
}
Also used : Entity(net.osmand.osm.edit.Entity) QuickAction(net.osmand.plus.quickaction.QuickAction) Action(net.osmand.plus.plugins.osmedit.data.OsmPoint.Action) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OsmandApplication(net.osmand.plus.OsmandApplication) Node(net.osmand.osm.edit.Node) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) EditPoiDialogFragment(net.osmand.plus.plugins.osmedit.dialogs.EditPoiDialogFragment) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) LatLon(net.osmand.data.LatLon) OpenstreetmapLocalUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapLocalUtil) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) PoiCategory(net.osmand.osm.PoiCategory) EditPoiData(net.osmand.plus.plugins.osmedit.data.EditPoiData) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) OpenstreetmapUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapUtil)

Example 2 with Action

use of net.osmand.plus.plugins.osmedit.data.OsmPoint.Action in project Osmand by osmandapp.

the class OsmBugsLayer method getHandleBugListener.

HandleBugListener getHandleBugListener(@NonNull MapActivity mapActivity) {
    return (obj, action, bug, point, text) -> {
        if (mapActivity.isFinishing()) {
            return;
        }
        if (obj != null && obj.warning == null) {
            if (local == getOsmBugsUtil(bug)) {
                Toast.makeText(ctx, R.string.osm_changes_added_to_local_edits, Toast.LENGTH_LONG).show();
                if (obj.local != null) {
                    PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_OSM_BUG, obj.local.getText());
                    mapActivity.getContextMenu().show(new LatLon(obj.local.getLatitude(), obj.local.getLongitude()), pd, obj.local);
                    mapActivity.getMapLayers().getContextMenuLayer().updateContextMenu();
                }
            } else {
                if (action == Action.REOPEN) {
                    Toast.makeText(ctx, R.string.osn_add_dialog_success, Toast.LENGTH_LONG).show();
                } else if (action == Action.MODIFY) {
                    Toast.makeText(ctx, R.string.osb_comment_dialog_success, Toast.LENGTH_LONG).show();
                } else if (action == Action.DELETE) {
                    Toast.makeText(ctx, R.string.osn_close_dialog_success, Toast.LENGTH_LONG).show();
                } else if (action == Action.CREATE) {
                    Toast.makeText(ctx, R.string.osn_add_dialog_success, Toast.LENGTH_LONG).show();
                }
            }
            clearCache();
        } else {
            int r = R.string.osb_comment_dialog_error;
            if (action == Action.REOPEN) {
                r = R.string.osn_add_dialog_error;
                reopenBug(mapActivity, bug, text);
            } else if (action == Action.DELETE) {
                r = R.string.osn_close_dialog_error;
                closeBug(mapActivity, bug, text);
            } else if (action == Action.CREATE) {
                r = R.string.osn_add_dialog_error;
                openBug(mapActivity, bug.getLatitude(), bug.getLongitude(), text, false);
            } else if (action == null) {
                r = R.string.osn_modify_dialog_error;
                modifyBug(mapActivity, point);
            } else {
                commentBug(mapActivity, bug, text);
            }
            Toast.makeText(ctx, ctx.getResources().getString(r) + "\n" + obj, Toast.LENGTH_LONG).show();
        }
    };
}
Also used : Context(android.content.Context) PointF(android.graphics.PointF) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) QuadRect(net.osmand.data.QuadRect) NonNull(androidx.annotation.NonNull) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) R(net.osmand.plus.R) ArrayList(java.util.ArrayList) LatLon(net.osmand.data.LatLon) OsmBugsUtil(net.osmand.plus.plugins.osmedit.helpers.OsmBugsUtil) URLConnection(java.net.URLConnection) Toast(android.widget.Toast) SendOsmNoteBottomSheetFragment(net.osmand.plus.plugins.osmedit.dialogs.SendOsmNoteBottomSheetFragment) View(android.view.View) Canvas(android.graphics.Canvas) PlatformUtil(net.osmand.PlatformUtil) ContextCompat(androidx.core.content.ContextCompat) XmlPullParser(org.xmlpull.v1.XmlPullParser) IContextMenuProvider(net.osmand.plus.views.layers.ContextMenuLayer.IContextMenuProvider) OsmandMapLayer(net.osmand.plus.views.layers.base.OsmandMapLayer) DEFAULT_UI_ICON_ID(net.osmand.data.FavouritePoint.DEFAULT_UI_ICON_ID) Xml(android.util.Xml) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) HandleOsmNoteAsyncTask(net.osmand.plus.plugins.osmedit.asynctasks.HandleOsmNoteAsyncTask) IOException(java.io.IOException) RotatedTileBox(net.osmand.data.RotatedTileBox) InputStreamReader(java.io.InputStreamReader) PointDescription(net.osmand.data.PointDescription) OsmandApplication(net.osmand.plus.OsmandApplication) BugBottomSheetDialog(net.osmand.plus.plugins.osmedit.dialogs.BugBottomSheetDialog) Serializable(java.io.Serializable) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) List(java.util.List) Nullable(androidx.annotation.Nullable) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) Action(net.osmand.plus.plugins.osmedit.data.OsmPoint.Action) HandleBugListener(net.osmand.plus.plugins.osmedit.asynctasks.HandleOsmNoteAsyncTask.HandleBugListener) OsmBugsLocalUtil(net.osmand.plus.plugins.osmedit.helpers.OsmBugsLocalUtil) Log(org.apache.commons.logging.Log) BufferedReader(java.io.BufferedReader) PointImageDrawable(net.osmand.plus.views.PointImageDrawable) BackgroundType(net.osmand.data.FavouritePoint.BackgroundType) EditText(android.widget.EditText) QuadTree(net.osmand.data.QuadTree) NetworkUtils(net.osmand.osm.io.NetworkUtils) MapActivity(net.osmand.plus.activities.MapActivity) LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription)

Example 3 with Action

use of net.osmand.plus.plugins.osmedit.data.OsmPoint.Action in project Osmand by osmandapp.

the class SaveOsmNoteAsyncTask method doInBackground.

@Override
protected OsmNotesPoint doInBackground(OsmNotesPoint... params) {
    OsmNotesPoint mOsmNotesPoint = params[0];
    Action action = mOsmNotesPoint.getAction();
    plugin.getDBBug().deleteAllBugModifications(mOsmNotesPoint);
    OsmBugsUtil.OsmBugResult result = mOsmbugsUtil.commit(mOsmNotesPoint, mText, action);
    return result == null ? null : result.local;
}
Also used : OsmBugsUtil(net.osmand.plus.plugins.osmedit.helpers.OsmBugsUtil) Action(net.osmand.plus.plugins.osmedit.data.OsmPoint.Action) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint)

Example 4 with Action

use of net.osmand.plus.plugins.osmedit.data.OsmPoint.Action in project Osmand by osmandapp.

the class EditPoiDialogFragment method save.

public void save() {
    Entity original = editPoiData.getEntity();
    final boolean offlineEdit = mOpenstreetmapUtil instanceof OpenstreetmapLocalUtil;
    Entity entity;
    if (original instanceof Node) {
        entity = new Node(original.getLatitude(), original.getLongitude(), original.getId());
    } else if (original instanceof Way) {
        entity = new Way(original.getId(), ((Way) original).getNodeIds(), original.getLatitude(), original.getLongitude());
    } else {
        return;
    }
    Action action = entity.getId() < 0 ? Action.CREATE : Action.MODIFY;
    for (Map.Entry<String, String> tag : editPoiData.getTagValues().entrySet()) {
        if (!Algorithms.isEmpty(tag.getKey()) && !Algorithms.isEmpty(tag.getValue()) && !tag.getKey().equals(POI_TYPE_TAG)) {
            entity.putTagNoLC(tag.getKey(), tag.getValue());
        }
    }
    String poiTypeTag = editPoiData.getTagValues().get(POI_TYPE_TAG);
    String comment = "";
    if (poiTypeTag != null) {
        final PoiType poiType = editPoiData.getAllTranslatedSubTypes().get(poiTypeTag.trim().toLowerCase());
        if (poiType != null) {
            entity.putTagNoLC(poiType.getEditOsmTag(), poiType.getEditOsmValue());
            entity.removeTag(Entity.REMOVE_TAG_PREFIX + poiType.getEditOsmTag());
            if (poiType.getOsmTag2() != null) {
                entity.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2());
                entity.removeTag(Entity.REMOVE_TAG_PREFIX + poiType.getOsmTag2());
            }
            if (poiType.getEditOsmTag2() != null) {
                entity.putTagNoLC(poiType.getEditOsmTag2(), poiType.getEditOsmValue2());
                entity.removeTag(Entity.REMOVE_TAG_PREFIX + poiType.getEditOsmTag2());
            }
        } else if (!Algorithms.isEmpty(poiTypeTag)) {
            PoiCategory category = editPoiData.getPoiCategory();
            if (category != null) {
                entity.putTagNoLC(category.getDefaultTag(), poiTypeTag);
            }
        }
        if (offlineEdit && !Algorithms.isEmpty(poiTypeTag)) {
            entity.putTagNoLC(POI_TYPE_TAG, poiTypeTag);
        }
        String actionString = action == Action.CREATE ? getString(R.string.default_changeset_add) : getString(R.string.default_changeset_edit);
        comment = actionString + " " + poiTypeTag;
    }
    commitEntity(action, entity, mOpenstreetmapUtil.getEntityInfo(entity.getId()), comment, false, result -> {
        OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
        if (result != null) {
            if (offlineEdit) {
                List<OpenstreetmapPoint> points = plugin.getDBPOI().getOpenstreetmapPoints();
                if (getActivity() instanceof MapActivity && points.size() > 0) {
                    OsmPoint point = points.get(points.size() - 1);
                    MapActivity mapActivity = (MapActivity) getActivity();
                    mapActivity.getContextMenu().showOrUpdate(new LatLon(point.getLatitude(), point.getLongitude()), plugin.getOsmEditsLayer(mapActivity).getObjectName(point), point);
                    mapActivity.getMapLayers().getContextMenuLayer().updateContextMenu();
                }
            }
            if (getActivity() instanceof MapActivity) {
                ((MapActivity) getActivity()).getMapView().refreshMap(true);
            }
            dismissAllowingStateLoss();
        } else {
            mOpenstreetmapUtil = plugin.getPoiModificationLocalUtil();
            Button saveButton = view.findViewById(R.id.saveButton);
            saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil ? R.string.shared_string_upload : R.string.shared_string_save);
        }
        return false;
    }, getActivity(), mOpenstreetmapUtil, action == Action.MODIFY ? editPoiData.getChangedTags() : null);
}
Also used : Entity(net.osmand.osm.edit.Entity) Action(net.osmand.plus.plugins.osmedit.data.OsmPoint.Action) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) Node(net.osmand.osm.edit.Node) PoiType(net.osmand.osm.PoiType) Way(net.osmand.osm.edit.Way) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) OpenstreetmapLocalUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapLocalUtil) LatLon(net.osmand.data.LatLon) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) OpenstreetmapRemoteUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapRemoteUtil) ImageButton(android.widget.ImageButton) Button(android.widget.Button) AppCompatImageButton(androidx.appcompat.widget.AppCompatImageButton) PoiCategory(net.osmand.osm.PoiCategory) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) MapActivity(net.osmand.plus.activities.MapActivity)

Aggregations

Action (net.osmand.plus.plugins.osmedit.data.OsmPoint.Action)4 LatLon (net.osmand.data.LatLon)3 OsmPoint (net.osmand.plus.plugins.osmedit.data.OsmPoint)3 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 PoiCategory (net.osmand.osm.PoiCategory)2 PoiType (net.osmand.osm.PoiType)2 Entity (net.osmand.osm.edit.Entity)2 Node (net.osmand.osm.edit.Node)2 OsmandApplication (net.osmand.plus.OsmandApplication)2 MapActivity (net.osmand.plus.activities.MapActivity)2 OsmEditingPlugin (net.osmand.plus.plugins.osmedit.OsmEditingPlugin)2 OpenstreetmapPoint (net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)2 OsmNotesPoint (net.osmand.plus.plugins.osmedit.data.OsmNotesPoint)2 OpenstreetmapLocalUtil (net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapLocalUtil)2 OsmBugsUtil (net.osmand.plus.plugins.osmedit.helpers.OsmBugsUtil)2 OsmandSettings (net.osmand.plus.settings.backend.OsmandSettings)2 Context (android.content.Context)1 Canvas (android.graphics.Canvas)1 PointF (android.graphics.PointF)1