Search in sources :

Example 11 with OsmPoint

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

the class DashOsmEditsFragment method showProgressDialog.

@Override
public void showProgressDialog(OsmPoint[] points, boolean closeChangeSet, boolean anonymously) {
    OsmPoint[] toUpload = points;
    ProgressDialogFragment dialog = ProgressDialogFragment.createInstance(R.string.uploading, R.string.local_openstreetmap_uploading, ProgressDialog.STYLE_HORIZONTAL);
    OsmEditsUploadListener listener = new OsmEditsUploadListenerHelper(getActivity(), getString(R.string.local_openstreetmap_were_uploaded)) {

        @Override
        public void uploadUpdated(OsmPoint point) {
            super.uploadUpdated(point);
            if (DashOsmEditsFragment.this.isAdded()) {
                onOpenDash();
            }
        }

        @Override
        public void uploadEnded(Map<OsmPoint, String> loadErrorsMap) {
            super.uploadEnded(loadErrorsMap);
            if (DashOsmEditsFragment.this.isAdded()) {
                onOpenDash();
            }
        }
    };
    dialog.show(getChildFragmentManager(), ProgressDialogFragment.TAG);
    UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(dialog, listener, plugin, toUpload.length, closeChangeSet, anonymously);
    uploadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, toUpload);
}
Also used : OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OsmEditsUploadListenerHelper(net.osmand.plus.plugins.osmedit.helpers.OsmEditsUploadListenerHelper) ProgressDialogFragment(net.osmand.plus.dialogs.ProgressDialogFragment) OsmEditsUploadListener(net.osmand.plus.plugins.osmedit.OsmEditsUploadListener) Map(java.util.Map) DashboardOnMap(net.osmand.plus.dashboard.DashboardOnMap) UploadOpenstreetmapPointAsyncTask(net.osmand.plus.plugins.osmedit.asynctasks.UploadOpenstreetmapPointAsyncTask)

Example 12 with OsmPoint

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

the class UploadOpenstreetmapPointAsyncTask method doInBackground.

@Override
protected Map<OsmPoint, String> doInBackground(OsmPoint... points) {
    TrafficStats.setThreadStatsTag(THREAD_ID);
    Map<OsmPoint, String> loadErrorsMap = new HashMap<>();
    boolean uploaded = false;
    for (OsmPoint point : points) {
        if (interruptUploading) {
            break;
        }
        if (point.getGroup() == OsmPoint.Group.POI) {
            OpenstreetmapPoint p = (OpenstreetmapPoint) point;
            EntityInfo entityInfo = null;
            p.trimChangedTagNamesValues();
            if (OsmPoint.Action.CREATE != p.getAction()) {
                entityInfo = remotepoi.loadEntity(p.getEntity());
            }
            Entity n = remotepoi.commitEntityImpl(p.getAction(), p.getEntity(), entityInfo, p.getComment(), false, null);
            if (n != null) {
                uploaded = true;
                plugin.getDBPOI().deletePOI(p);
                publishProgress(p);
            }
            loadErrorsMap.put(point, n != null ? null : "Unknown problem");
        } else if (point.getGroup() == OsmPoint.Group.BUG) {
            OsmNotesPoint p = (OsmNotesPoint) point;
            String errorMessage = remotebug.commit(p, p.getText(), p.getAction(), loadAnonymous).warning;
            if (errorMessage == null) {
                plugin.getDBBug().deleteAllBugModifications(p);
                publishProgress(p);
            }
            loadErrorsMap.put(point, errorMessage);
        }
    }
    if (uploaded && closeChangeSet) {
        remotepoi.closeChangeSet();
    }
    return loadErrorsMap;
}
Also used : Entity(net.osmand.osm.edit.Entity) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) HashMap(java.util.HashMap) EntityInfo(net.osmand.osm.edit.EntityInfo) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint)

Example 13 with OsmPoint

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

the class OsmEditsUploadListenerHelper method uploadEnded.

@MainThread
@Override
public void uploadEnded(Map<OsmPoint, String> loadErrorsMap) {
    if (activity.getSupportFragmentManager().isStateSaved()) {
        return;
    }
    int uploaded = 0;
    int pointsNum = loadErrorsMap.keySet().size();
    for (String s : loadErrorsMap.values()) {
        if (s == null) {
            uploaded++;
        }
    }
    if (uploaded == pointsNum) {
        Toast.makeText(activity, MessageFormat.format(numberFormat, uploaded), Toast.LENGTH_LONG).show();
    } else if (pointsNum == 1) {
        Log.v(TAG, "in if1");
        OsmPoint point = loadErrorsMap.keySet().iterator().next();
        String message = loadErrorsMap.get(point);
        if (message.equals(activity.getString(R.string.auth_failed))) {
            LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), null);
        } else {
            DialogFragment dialogFragment = UploadingErrorDialogFragment.getInstance(message, point);
            dialogFragment.show(activity.getSupportFragmentManager(), "error_loading");
        }
    } else {
        UploadingMultipleErrorDialogFragment dialogFragment = UploadingMultipleErrorDialogFragment.createInstance(loadErrorsMap);
        dialogFragment.show(activity.getSupportFragmentManager(), "multiple_error_loading");
    }
}
Also used : OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) ProgressDialogFragment(net.osmand.plus.dialogs.ProgressDialogFragment) DialogFragment(androidx.fragment.app.DialogFragment) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) MainThread(androidx.annotation.MainThread)

Example 14 with OsmPoint

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

the class EditPOIMenuController method getRightIconId.

@Override
public int getRightIconId() {
    if (osmPoint.getGroup() == OsmPoint.Group.POI) {
        OpenstreetmapPoint osmP = (OpenstreetmapPoint) osmPoint;
        int iconResId = 0;
        String poiTranslation = osmP.getEntity().getTag(POI_TYPE_TAG);
        MapActivity mapActivity = getMapActivity();
        if (poiTranslation != null && mapActivity != null) {
            Map<String, PoiType> poiTypeMap = mapActivity.getMyApplication().getPoiTypes().getAllTranslatedNames(false);
            PoiType poiType = poiTypeMap.get(poiTranslation.toLowerCase());
            if (poiType != null) {
                String id = null;
                if (RenderingIcons.containsBigIcon(poiType.getIconKeyName())) {
                    id = poiType.getIconKeyName();
                } else if (RenderingIcons.containsBigIcon(poiType.getOsmTag() + "_" + poiType.getOsmValue())) {
                    id = poiType.getOsmTag() + "_" + poiType.getOsmValue();
                }
                if (id != null) {
                    iconResId = RenderingIcons.getBigIconResourceId(id);
                }
            }
        }
        if (iconResId == 0) {
            iconResId = R.drawable.ic_action_info_dark;
        }
        return iconResId;
    } else if (osmPoint.getGroup() == OsmPoint.Group.BUG) {
        return R.drawable.ic_action_osm_note_add;
    } else {
        return 0;
    }
}
Also used : OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) PoiType(net.osmand.osm.PoiType) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) MapActivity(net.osmand.plus.activities.MapActivity)

Example 15 with OsmPoint

use of net.osmand.plus.plugins.osmedit.data.OsmPoint 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)

Aggregations

OsmPoint (net.osmand.plus.plugins.osmedit.data.OsmPoint)29 OpenstreetmapPoint (net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)21 OsmNotesPoint (net.osmand.plus.plugins.osmedit.data.OsmNotesPoint)15 PoiType (net.osmand.osm.PoiType)6 Map (java.util.Map)5 Entity (net.osmand.osm.edit.Entity)5 View (android.view.View)4 LinearLayout (android.widget.LinearLayout)4 LatLon (net.osmand.data.LatLon)4 TextView (android.widget.TextView)3 FragmentActivity (androidx.fragment.app.FragmentActivity)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 MapActivity (net.osmand.plus.activities.MapActivity)3 SimpleBottomSheetItem (net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem)3 ProgressDialogFragment (net.osmand.plus.dialogs.ProgressDialogFragment)3 OsmEditingPlugin (net.osmand.plus.plugins.osmedit.OsmEditingPlugin)3 ContextThemeWrapper (android.view.ContextThemeWrapper)2 CompoundButton (android.widget.CompoundButton)2 ImageButton (android.widget.ImageButton)2