Search in sources :

Example 26 with OpenstreetmapPoint

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

the class DashOsmEditsFragment method setupEditings.

private void setupEditings() {
    View mainView = getView();
    assert mainView != null;
    if (plugin == null) {
        mainView.setVisibility(View.GONE);
        return;
    }
    ArrayList<OsmPoint> dataPoints = new ArrayList<>();
    getOsmPoints(dataPoints);
    if (dataPoints.size() == 0) {
        mainView.setVisibility(View.GONE);
        return;
    } else {
        mainView.setVisibility(View.VISIBLE);
        DashboardOnMap.handleNumberOfRows(dataPoints, getMyApplication().getSettings(), ROW_NUMBER_TAG);
    }
    LinearLayout osmLayout = (LinearLayout) mainView.findViewById(R.id.items);
    osmLayout.removeAllViews();
    for (final OsmPoint point : dataPoints) {
        LayoutInflater inflater = getActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.note, null, false);
        OsmEditsFragment.getOsmEditView(view, point, getMyApplication());
        ImageButton send = (ImageButton) view.findViewById(R.id.play);
        send.setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_export));
        send.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (point.getGroup() == OsmPoint.Group.POI) {
                    selectedPoint = point;
                    if (getMyApplication().getOsmOAuthHelper().isLogged()) {
                        SendPoiBottomSheetFragment.showInstance(getChildFragmentManager(), new OsmPoint[] { point });
                    } else {
                        LoginBottomSheetFragment.showInstance(getActivity().getSupportFragmentManager(), DashOsmEditsFragment.this);
                    }
                } else {
                    SendOsmNoteBottomSheetFragment.showInstance(getChildFragmentManager(), new OsmPoint[] { point });
                }
            }
        });
        view.findViewById(R.id.options).setVisibility(View.GONE);
        view.findViewById(R.id.divider).setVisibility(View.VISIBLE);
        view.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                boolean poi = point.getGroup() == OsmPoint.Group.POI;
                String name = poi ? ((OpenstreetmapPoint) point).getName() : ((OsmNotesPoint) point).getText();
                getMyApplication().getSettings().setMapLocationToShow(point.getLatitude(), point.getLongitude(), 15, new PointDescription(poi ? PointDescription.POINT_TYPE_POI : PointDescription.POINT_TYPE_OSM_BUG, name), true, // $NON-NLS-1$
                point);
                MapActivity.launchMapActivityMoveToTop(getActivity());
            }
        });
        osmLayout.addView(view);
    }
}
Also used : OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) ArrayList(java.util.ArrayList) View(android.view.View) TextView(android.widget.TextView) ImageButton(android.widget.ImageButton) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) LayoutInflater(android.view.LayoutInflater) PointDescription(net.osmand.data.PointDescription) LinearLayout(android.widget.LinearLayout)

Example 27 with OpenstreetmapPoint

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

the class OsmEditsAdapter method getIcon.

private Drawable getIcon(OsmPoint point) {
    if (point.getGroup() == OsmPoint.Group.POI) {
        OpenstreetmapPoint osmPoint = (OpenstreetmapPoint) point;
        int iconResId = 0;
        String poiTranslation = osmPoint.getEntity().getTag(Entity.POI_TYPE_TAG);
        if (poiTranslation != null) {
            Map<String, PoiType> poiTypeMap = app.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;
        }
        int colorResId = R.color.color_distance;
        if (point.getAction() == OsmPoint.Action.CREATE) {
            colorResId = R.color.color_osm_edit_create;
        } else if (point.getAction() == OsmPoint.Action.MODIFY) {
            colorResId = R.color.color_osm_edit_modify;
        } else if (point.getAction() == OsmPoint.Action.DELETE) {
            colorResId = R.color.color_osm_edit_delete;
        } else if (point.getAction() == OsmPoint.Action.REOPEN) {
            colorResId = R.color.color_osm_edit_modify;
        }
        return app.getUIUtilities().getIcon(iconResId, colorResId);
    } else if (point.getGroup() == OsmPoint.Group.BUG) {
        return app.getUIUtilities().getIcon(R.drawable.ic_action_osm_note_add, R.color.color_distance);
    }
    return null;
}
Also used : OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) PoiType(net.osmand.osm.PoiType) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)

Example 28 with OpenstreetmapPoint

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

the class OsmEditingPlugin method getEditName.

public static String getEditName(OsmPoint point) {
    String prefix = getPrefix(point);
    String name = getName(point);
    if (point.getGroup() == OsmPoint.Group.POI) {
        String subtype = "";
        if (!Algorithms.isEmpty(((OpenstreetmapPoint) point).getSubtype())) {
            subtype = " (" + ((OpenstreetmapPoint) point).getSubtype() + ") ";
        }
        return prefix + subtype + name;
    } else if (point.getGroup() == OsmPoint.Group.BUG) {
        return prefix + name;
    } else {
        return prefix;
    }
}
Also used : OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) SpannableString(android.text.SpannableString)

Example 29 with OpenstreetmapPoint

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

Example 30 with OpenstreetmapPoint

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

the class EditPoiDialogFragment method showEditInstance.

public static void showEditInstance(final MapObject mapObject, final AppCompatActivity activity) {
    final OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
    if (plugin == null) {
        return;
    }
    final OsmandApplication app = ((OsmandApplication) activity.getApplication());
    final OpenstreetmapUtil openstreetmapUtilToLoad = app.getSettings().isInternetConnectionAvailable(true) ? plugin.getPoiModificationRemoteUtil() : plugin.getPoiModificationLocalUtil();
    new AsyncTask<Void, Void, Entity>() {

        @Override
        protected Entity doInBackground(Void... params) {
            return openstreetmapUtilToLoad.loadEntity(mapObject);
        }

        @Override
        protected void onPostExecute(Entity entity) {
            if (entity != null) {
                Entity existingOsmEditEntity = getExistingOsmEditEntity(plugin, entity.getId());
                Entity entityToEdit = existingOsmEditEntity != null ? existingOsmEditEntity : entity;
                EditPoiDialogFragment fragment = EditPoiDialogFragment.createInstance(entityToEdit, false);
                fragment.show(activity.getSupportFragmentManager(), TAG);
            } else {
                Toast.makeText(activity, activity.getString(R.string.poi_cannot_be_found), Toast.LENGTH_LONG).show();
            }
        }

        @Nullable
        private Entity getExistingOsmEditEntity(@NonNull OsmEditingPlugin osmEditingPlugin, long entityId) {
            List<OpenstreetmapPoint> osmEdits = osmEditingPlugin.getDBPOI().getOpenstreetmapPoints();
            for (OpenstreetmapPoint osmEdit : osmEdits) {
                if (osmEdit.getId() == entityId && osmEdit.getAction() == Action.MODIFY) {
                    return osmEdit.getEntity();
                }
            }
            return null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : Entity(net.osmand.osm.edit.Entity) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) OsmandApplication(net.osmand.plus.OsmandApplication) List(java.util.List) Nullable(androidx.annotation.Nullable) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) OpenstreetmapUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapUtil)

Aggregations

OpenstreetmapPoint (net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)30 OsmPoint (net.osmand.plus.plugins.osmedit.data.OsmPoint)18 OsmNotesPoint (net.osmand.plus.plugins.osmedit.data.OsmNotesPoint)17 Entity (net.osmand.osm.edit.Entity)10 ArrayList (java.util.ArrayList)8 PoiType (net.osmand.osm.PoiType)8 File (java.io.File)5 Node (net.osmand.osm.edit.Node)5 HistoryEntry (net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry)5 MapMarkersGroup (net.osmand.plus.mapmarkers.MapMarkersGroup)5 FavoriteGroup (net.osmand.plus.myplaces.FavoriteGroup)5 OsmEditingPlugin (net.osmand.plus.plugins.osmedit.OsmEditingPlugin)5 QuickAction (net.osmand.plus.quickaction.QuickAction)5 List (java.util.List)4 ITileSource (net.osmand.map.ITileSource)4 MapActivity (net.osmand.plus.activities.MapActivity)4 AvoidRoadInfo (net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo)4 OnlineRoutingEngine (net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine)4 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)4 View (android.view.View)3