Search in sources :

Example 1 with PleaseApplyPoiChanges

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);
    }
}
Also used : HashMap(java.util.HashMap) PoiChanges(io.jawg.osmcontributor.utils.edition.PoiChanges) PleaseApplyPoiChanges(io.jawg.osmcontributor.ui.events.edition.PleaseApplyPoiChanges) PleaseApplyPoiChanges(io.jawg.osmcontributor.ui.events.edition.PleaseApplyPoiChanges) Poi(io.jawg.osmcontributor.model.entities.Poi)

Example 2 with PleaseApplyPoiChanges

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);
}
Also used : AlertDialog(android.app.AlertDialog) PleaseCreatePoiEvent(io.jawg.osmcontributor.model.events.PleaseCreatePoiEvent) DialogInterface(android.content.DialogInterface) PleaseApplyPoiChanges(io.jawg.osmcontributor.ui.events.edition.PleaseApplyPoiChanges)

Aggregations

PleaseApplyPoiChanges (io.jawg.osmcontributor.ui.events.edition.PleaseApplyPoiChanges)2 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 Poi (io.jawg.osmcontributor.model.entities.Poi)1 PleaseCreatePoiEvent (io.jawg.osmcontributor.model.events.PleaseCreatePoiEvent)1 PoiChanges (io.jawg.osmcontributor.utils.edition.PoiChanges)1 HashMap (java.util.HashMap)1