Search in sources :

Example 1 with PleaseApplyNewComment

use of io.jawg.osmcontributor.ui.events.map.PleaseApplyNewComment in project osm-contributor by jawg.

the class NoteActivity method addCommentOnClick.

@OnClick(R.id.send_comment)
void addCommentOnClick() {
    if (newCommentEditText.getText().toString().isEmpty()) {
        Toast.makeText(this, R.string.comment_text_cant_be_null, Toast.LENGTH_SHORT).show();
    } else {
        if (note.getStatus().equals(Note.STATUS_SYNC)) {
            Toast.makeText(this, R.string.comment_synchronizing, Toast.LENGTH_SHORT).show();
        } else {
            eventBus.post(new PleaseApplyNewComment(note, newCommentActionSpinner.getSelectedItem().toString(), newCommentEditText.getText().toString()));
            newCommentEditText.getText().clear();
            closeKeyboard();
        }
    }
}
Also used : PleaseApplyNewComment(io.jawg.osmcontributor.ui.events.map.PleaseApplyNewComment) OnClick(butterknife.OnClick)

Example 2 with PleaseApplyNewComment

use of io.jawg.osmcontributor.ui.events.map.PleaseApplyNewComment in project osm-contributor by jawg.

the class NoteCommentDialogFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    ((OsmTemplateApplication) getActivity().getApplication()).getOsmTemplateComponent().inject(this);
    lat = getArguments().getDouble(LAT);
    lng = getArguments().getDouble(LNG);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    final EditText input = new EditText(this.getActivity());
    input.setMaxLines(5);
    openKeyboard();
    String title = getResources().getString(R.string.title_creation_note);
    builder.setTitle(title).setView(input).setPositiveButton(R.string.create_note, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            String comment = input.getText().toString();
            if (!comment.isEmpty()) {
                Note note = new Note();
                note.setStatus(Note.STATUS_SYNC);
                note.setLatitude(lat);
                note.setLongitude(lng);
                note.setUpdated(true);
                eventBus.post(new PleaseApplyNewComment(note, Comment.ACTION_OPEN, comment));
                closeKeyboard();
            }
        }
    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    final AlertDialog dialog = builder.create();
    dialog.show();
    // Initially disable the button
    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
    input.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            // Check if edittext is empty
            if (TextUtils.isEmpty(s)) {
                // Disable ok button
                dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
            } else {
                // Something into edit text. Enable the button.
                dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
            }
        }
    });
    return dialog;
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) PleaseApplyNewComment(io.jawg.osmcontributor.ui.events.map.PleaseApplyNewComment) Note(io.jawg.osmcontributor.model.entities.Note) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable)

Aggregations

PleaseApplyNewComment (io.jawg.osmcontributor.ui.events.map.PleaseApplyNewComment)2 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 EditText (android.widget.EditText)1 OnClick (butterknife.OnClick)1 Note (io.jawg.osmcontributor.model.entities.Note)1