use of io.jawg.osmcontributor.ui.events.edition.PleaseApplyPoiChanges in project osm-contributor by jawg.
the class PhotoActivity method defineImageOnPoi.
/**
* Associate the newly uploaded flickr picture to the current Poi
*
* @param imageUrl The complete URL to access this picture
*/
private void defineImageOnPoi(String imageUrl) {
if (imageUrl.length() > 0) {
Poi currentPoi = application.getOsmTemplateComponent().getPoiManager().queryForId(poiId);
Map<String, String> currentPoiTagsMap = new HashMap<String, String>(currentPoi.getTagsMap());
if (currentPoiTagsMap.containsKey(OSM_FLICKR_TAG)) {
StringBuilder newFlickrTag = new StringBuilder(currentPoiTagsMap.get(OSM_FLICKR_TAG).trim()).append(";").append(imageUrl);
currentPoiTagsMap.put(OSM_FLICKR_TAG, newFlickrTag.toString());
} else {
currentPoiTagsMap.put(OSM_FLICKR_TAG, imageUrl);
}
PoiChanges currentPoiChanges = new PoiChanges(poiId);
currentPoiChanges.setTagsMap(currentPoiTagsMap);
eventBus.post(new PleaseApplyPoiChanges(currentPoiChanges));
} else {
Log.e(TAG, "Invalid Flickr URL: " + imageUrl);
}
}
use of io.jawg.osmcontributor.ui.events.edition.PleaseApplyPoiChanges in project osm-contributor by jawg.
the class EditPoiFragment method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (tagsAdapter == null) {
getActivity().finish();
return true;
}
if (id == R.id.action_confirm_edit) {
// If we are in expert mode, directly create or update the Poi
if (sharedPreferences.getBoolean(getString(R.string.shared_prefs_expert_mode), false)) {
if (creation) {
getActivity().setResult(EditPoiActivity.POI_CREATED, null);
eventBus.post(new PleaseCreatePoiEvent(poi, tagsAdapter.getPoiChanges()));
OsmAnswers.localPoiAction(poi.getType().getTechnicalName(), "add");
} else if (tagsAdapter.isChange()) {
getActivity().setResult(EditPoiActivity.POI_EDITED, null);
eventBus.post(new PleaseApplyPoiChanges(tagsAdapter.getPoiChanges()));
OsmAnswers.localPoiAction(poi.getType().getTechnicalName(), "update");
} else {
Toast.makeText(getActivity(), R.string.not_any_changes, Toast.LENGTH_SHORT).show();
}
return true;
}
// else check if all mandatory tags are completed.
if (creation) {
if (!poi.getType().hasMandatoryTags() || tagsAdapter.isValidChanges()) {
getActivity().setResult(EditPoiActivity.POI_CREATED, null);
eventBus.post(new PleaseCreatePoiEvent(poi, tagsAdapter.getPoiChanges()));
OsmAnswers.localPoiAction(poi.getType().getTechnicalName(), "add");
} else {
tagsAdapter.refreshErrorStatus();
Toast.makeText(getActivity(), R.string.uncompleted_fields, Toast.LENGTH_SHORT).show();
}
return true;
}
// In edit mode, check if there are changes then check if all the mandatory tags are completed.
if (tagsAdapter.isChange()) {
if (tagsAdapter.isValidChanges()) {
getActivity().setResult(EditPoiActivity.POI_EDITED, null);
eventBus.post(new PleaseApplyPoiChanges(tagsAdapter.getPoiChanges()));
OsmAnswers.localPoiAction(poi.getType().getTechnicalName(), "update");
} else {
tagsAdapter.refreshErrorStatus();
Toast.makeText(getActivity(), R.string.uncompleted_fields, Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(getActivity(), R.string.not_any_changes, Toast.LENGTH_SHORT).show();
}
return true;
}
if (id == android.R.id.home) {
if (!tagsAdapter.isChange()) {
getActivity().setResult(Activity.RESULT_CANCELED, null);
getActivity().finish();
} else {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
alertDialog.setTitle(R.string.quit_edition_title);
alertDialog.setMessage(R.string.quit_edition_message);
alertDialog.setPositiveButton(R.string.quit_edition_positive_btn, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
getActivity().setResult(Activity.RESULT_CANCELED, null);
getActivity().finish();
}
});
alertDialog.setNegativeButton(R.string.quit_edition_negative_btn, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertDialog.show();
}
return true;
}
return super.onOptionsItemSelected(item);
}
Aggregations