Search in sources :

Example 1 with EditPoiData

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

the class BasicEditPoiFragment method removeUnsavedOpeningHours.

public void removeUnsavedOpeningHours() {
    EditPoiData data = getData();
    if (data != null) {
        OpeningHoursParser.OpeningHours openingHours = OpeningHoursParser.parseOpenedHoursHandleErrors(data.getTagValues().get(OSMSettings.OSMTagKey.OPENING_HOURS.getValue()));
        if (openingHours == null) {
            openingHours = new OpeningHoursParser.OpeningHours();
        }
        mOpeningHoursAdapter.replaceOpeningHours(openingHours);
        mOpeningHoursAdapter.updateViews();
    }
}
Also used : EditPoiData(net.osmand.plus.plugins.osmedit.data.EditPoiData) OpeningHoursParser(net.osmand.util.OpeningHoursParser)

Example 2 with EditPoiData

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

the class BasicEditPoiFragment method onFragmentActivated.

@Override
public void onFragmentActivated() {
    EditPoiData data = getData();
    if (data == null) {
        return;
    }
    basicTagsInitialized = false;
    Map<String, String> tagValues = data.getTagValues();
    streetEditText.setText(tagValues.get(OSMSettings.OSMTagKey.ADDR_STREET.getValue()));
    houseNumberEditText.setText(tagValues.get(OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER.getValue()));
    phoneEditText.setText(tagValues.get(OSMSettings.OSMTagKey.PHONE.getValue()));
    webSiteEditText.setText(tagValues.get(OSMSettings.OSMTagKey.WEBSITE.getValue()));
    descriptionEditText.setText(tagValues.get(OSMSettings.OSMTagKey.DESCRIPTION.getValue()));
    OpeningHoursParser.OpeningHours openingHours = OpeningHoursParser.parseOpenedHoursHandleErrors(tagValues.get(OSMSettings.OSMTagKey.OPENING_HOURS.getValue()));
    if (openingHours == null) {
        openingHours = new OpeningHoursParser.OpeningHours();
    }
    mOpeningHoursAdapter.replaceOpeningHours(openingHours);
    mOpeningHoursAdapter.updateViews();
    basicTagsInitialized = true;
}
Also used : EditPoiData(net.osmand.plus.plugins.osmedit.data.EditPoiData) OpeningHoursParser(net.osmand.util.OpeningHoursParser)

Example 3 with EditPoiData

use of net.osmand.plus.plugins.osmedit.data.EditPoiData 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 4 with EditPoiData

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

the class EditPoiDialogFragment method onAttach.

@Override
public void onAttach(@NonNull Context activity) {
    super.onAttach(activity);
    OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
    if (plugin.OFFLINE_EDITION.get() || !getSettings().isInternetConnectionAvailable(true)) {
        mOpenstreetmapUtil = plugin.getPoiModificationLocalUtil();
    } else {
        mOpenstreetmapUtil = plugin.getPoiModificationRemoteUtil();
    }
    Entity entity = (Entity) getArguments().getSerializable(KEY_AMENITY_ENTITY);
    editPoiData = new EditPoiData(entity, getMyApplication());
}
Also used : Entity(net.osmand.osm.edit.Entity) EditPoiData(net.osmand.plus.plugins.osmedit.data.EditPoiData) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin)

Aggregations

EditPoiData (net.osmand.plus.plugins.osmedit.data.EditPoiData)4 Entity (net.osmand.osm.edit.Entity)2 OsmEditingPlugin (net.osmand.plus.plugins.osmedit.OsmEditingPlugin)2 OpeningHoursParser (net.osmand.util.OpeningHoursParser)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 LatLon (net.osmand.data.LatLon)1 AbstractPoiType (net.osmand.osm.AbstractPoiType)1 PoiCategory (net.osmand.osm.PoiCategory)1 PoiType (net.osmand.osm.PoiType)1 Node (net.osmand.osm.edit.Node)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 OpenstreetmapPoint (net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)1 OsmPoint (net.osmand.plus.plugins.osmedit.data.OsmPoint)1 Action (net.osmand.plus.plugins.osmedit.data.OsmPoint.Action)1 EditPoiDialogFragment (net.osmand.plus.plugins.osmedit.dialogs.EditPoiDialogFragment)1 OpenstreetmapLocalUtil (net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapLocalUtil)1 OpenstreetmapUtil (net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapUtil)1 QuickAction (net.osmand.plus.quickaction.QuickAction)1