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);
}
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;
}
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");
}
}
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;
}
}
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);
}
}
Aggregations