Search in sources :

Example 1 with OpenstreetmapPoint

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

the class SendPoiDialogFragment method createDefaultChangeSet.

private String createDefaultChangeSet() {
    Map<String, PoiType> allTranslatedSubTypes = getMyApplication().getPoiTypes().getAllTranslatedNames(true);
    if (allTranslatedSubTypes == null) {
        return "";
    }
    Map<String, Integer> addGroup = new HashMap<>();
    Map<String, Integer> editGroup = new HashMap<>();
    Map<String, Integer> deleteGroup = new HashMap<>();
    Map<String, Integer> reopenGroup = new HashMap<>();
    String comment = "";
    for (OsmPoint p : poi) {
        if (p.getGroup() == OsmPoint.Group.POI) {
            OsmPoint.Action action = p.getAction();
            String type = ((OpenstreetmapPoint) p).getEntity().getTag(EditPoiData.POI_TYPE_TAG);
            if (type == null) {
                continue;
            }
            PoiType localizedPoiType = allTranslatedSubTypes.get(type.toLowerCase().trim());
            if (localizedPoiType != null) {
                type = Algorithms.capitalizeFirstLetter(localizedPoiType.getKeyName().replace('_', ' '));
            }
            if (action == OsmPoint.Action.CREATE) {
                if (!addGroup.containsKey(type)) {
                    addGroup.put(type, 1);
                } else {
                    addGroup.put(type, addGroup.get(type) + 1);
                }
            } else if (action == OsmPoint.Action.MODIFY) {
                if (!editGroup.containsKey(type)) {
                    editGroup.put(type, 1);
                } else {
                    editGroup.put(type, editGroup.get(type) + 1);
                }
            } else if (action == OsmPoint.Action.DELETE) {
                if (!deleteGroup.containsKey(type)) {
                    deleteGroup.put(type, 1);
                } else {
                    deleteGroup.put(type, deleteGroup.get(type) + 1);
                }
            } else if (action == OsmPoint.Action.REOPEN) {
                if (!reopenGroup.containsKey(type)) {
                    reopenGroup.put(type, 1);
                } else {
                    reopenGroup.put(type, reopenGroup.get(type) + 1);
                }
            }
        }
    }
    int modifiedItemsOutOfLimit = 0;
    for (int i = 0; i < 4; i++) {
        String action;
        Map<String, Integer> group;
        switch(i) {
            case 0:
                action = getString(R.string.default_changeset_add);
                group = addGroup;
                break;
            case 1:
                action = getString(R.string.default_changeset_edit);
                group = editGroup;
                break;
            case 2:
                action = getString(R.string.default_changeset_delete);
                group = deleteGroup;
                break;
            case 3:
                action = getString(R.string.default_changeset_reopen);
                group = reopenGroup;
                break;
            default:
                action = "";
                group = new HashMap<>();
        }
        if (!group.isEmpty()) {
            int pos = 0;
            for (Map.Entry<String, Integer> entry : group.entrySet()) {
                String type = entry.getKey();
                int quantity = entry.getValue();
                if (comment.length() > 200) {
                    modifiedItemsOutOfLimit += quantity;
                } else {
                    if (pos == 0) {
                        comment = comment.concat(comment.length() == 0 ? "" : "; ").concat(action).concat(" ").concat(quantity == 1 ? "" : quantity + " ").concat(type);
                    } else {
                        comment = comment.concat(", ").concat(quantity == 1 ? "" : quantity + " ").concat(type);
                    }
                }
                pos++;
            }
        }
    }
    if (modifiedItemsOutOfLimit != 0) {
        comment = comment.concat("; ").concat(modifiedItemsOutOfLimit + " ").concat(getString(R.string.items_modified)).concat(".");
    } else if (!comment.equals("")) {
        comment = comment.concat(".");
    }
    return comment;
}
Also used : OsmPoint(net.osmand.plus.osmedit.OsmPoint) HashMap(java.util.HashMap) PoiType(net.osmand.osm.PoiType) HashMap(java.util.HashMap) Map(java.util.Map) OpenstreetmapPoint(net.osmand.plus.osmedit.OpenstreetmapPoint) OsmPoint(net.osmand.plus.osmedit.OsmPoint)

Example 2 with OpenstreetmapPoint

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

the class SendPoiDialogFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT);
    final PoiUploaderType poiUploaderType = PoiUploaderType.valueOf(getArguments().getString(POI_UPLOADER_TYPE, PoiUploaderType.SIMPLE.name()));
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    View view = getActivity().getLayoutInflater().inflate(R.layout.send_poi_dialog, null);
    final SwitchCompat uploadAnonymously = (SwitchCompat) view.findViewById(R.id.upload_anonymously_switch);
    final EditText messageEditText = (EditText) view.findViewById(R.id.message_field);
    final EditText userNameEditText = (EditText) view.findViewById(R.id.user_name_field);
    final EditText passwordEditText = (EditText) view.findViewById(R.id.password_field);
    final View messageLabel = view.findViewById(R.id.message_label);
    final View userNameLabel = view.findViewById(R.id.osm_user_name_label);
    final View passwordLabel = view.findViewById(R.id.osm_user_password_label);
    final CheckBox closeChangeSetCheckBox = (CheckBox) view.findViewById(R.id.close_change_set_checkbox);
    final OsmandSettings settings = ((OsmandApplication) getActivity().getApplication()).getSettings();
    userNameEditText.setText(settings.USER_NAME.get());
    passwordEditText.setText(settings.USER_PASSWORD.get());
    boolean hasPoiGroup = false;
    assert poi != null;
    for (OsmPoint p : poi) {
        if (p.getGroup() == OsmPoint.Group.POI) {
            hasPoiGroup = true;
            break;
        }
    }
    String defaultChangeSet = createDefaultChangeSet();
    messageEditText.setText(defaultChangeSet);
    final boolean hasPOI = hasPoiGroup;
    messageLabel.setVisibility(hasPOI ? View.VISIBLE : View.GONE);
    messageEditText.setVisibility(hasPOI ? View.VISIBLE : View.GONE);
    closeChangeSetCheckBox.setVisibility(hasPOI ? View.VISIBLE : View.GONE);
    closeChangeSetCheckBox.setChecked(hasPOI && !defaultChangeSet.equals(""));
    view.findViewById(R.id.osm_note_header).setVisibility(hasPOI ? View.GONE : View.VISIBLE);
    uploadAnonymously.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            userNameLabel.setVisibility(isChecked ? View.GONE : View.VISIBLE);
            userNameEditText.setVisibility(isChecked ? View.GONE : View.VISIBLE);
            passwordLabel.setVisibility(isChecked ? View.GONE : View.VISIBLE);
            passwordEditText.setVisibility(isChecked ? View.GONE : View.VISIBLE);
        }
    });
    final ProgressDialogPoiUploader progressDialogPoiUploader;
    if (poiUploaderType == PoiUploaderType.SIMPLE && getActivity() instanceof MapActivity) {
        progressDialogPoiUploader = new SendPoiDialogFragment.SimpleProgressDialogPoiUploader((MapActivity) getActivity());
    } else {
        progressDialogPoiUploader = (ProgressDialogPoiUploader) getParentFragment();
    }
    builder.setTitle(hasPOI ? R.string.upload_poi : R.string.upload_osm_note).setView(view).setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (progressDialogPoiUploader != null) {
                settings.USER_NAME.set(userNameEditText.getText().toString());
                settings.USER_PASSWORD.set(passwordEditText.getText().toString());
                String comment = messageEditText.getText().toString();
                if (comment.length() > 0) {
                    for (OsmPoint osmPoint : poi) {
                        if (osmPoint.getGroup() == OsmPoint.Group.POI) {
                            ((OpenstreetmapPoint) osmPoint).setComment(comment);
                            break;
                        }
                    }
                }
                progressDialogPoiUploader.showProgressDialog(poi, closeChangeSetCheckBox.isChecked(), !hasPOI && uploadAnonymously.isChecked());
            }
        }
    }).setNegativeButton(R.string.shared_string_cancel, null);
    return builder.create();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) OsmPoint(net.osmand.plus.osmedit.OsmPoint) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) View(android.view.View) OsmandSettings(net.osmand.plus.OsmandSettings) OpenstreetmapPoint(net.osmand.plus.osmedit.OpenstreetmapPoint) CheckBox(android.widget.CheckBox) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat) MapActivity(net.osmand.plus.activities.MapActivity) NonNull(android.support.annotation.NonNull)

Aggregations

OpenstreetmapPoint (net.osmand.plus.osmedit.OpenstreetmapPoint)2 OsmPoint (net.osmand.plus.osmedit.OsmPoint)2 DialogInterface (android.content.DialogInterface)1 NonNull (android.support.annotation.NonNull)1 AlertDialog (android.support.v7.app.AlertDialog)1 SwitchCompat (android.support.v7.widget.SwitchCompat)1 View (android.view.View)1 CheckBox (android.widget.CheckBox)1 CompoundButton (android.widget.CompoundButton)1 EditText (android.widget.EditText)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 PoiType (net.osmand.osm.PoiType)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 OsmandSettings (net.osmand.plus.OsmandSettings)1 MapActivity (net.osmand.plus.activities.MapActivity)1