use of io.jawg.osmcontributor.model.entities.Note in project osm-contributor by jawg.
the class NoteManager method onPleaseApplyNewComment.
@Subscribe(threadMode = ThreadMode.ASYNC)
public void onPleaseApplyNewComment(PleaseApplyNewComment event) {
Timber.d("please apply new comment");
if (loginManager.checkCredentials()) {
Note note = syncNoteManager.remoteAddComment(createComment(event.getNote(), event.getAction(), event.getText()));
if (note != null) {
mergeBackendNote(note);
bus.post(new NewNoteCreatedEvent(note.getId()));
bus.post(new SyncFinishUploadNote(note));
}
} else {
bus.post(new ApplyNewCommentFailedEvent());
}
}
use of io.jawg.osmcontributor.model.entities.Note in project osm-contributor by jawg.
the class NoteManager method mergeBackendNote.
/**
* Merge Note in parameters to the already in the database.
*
* @param remoteNote The Note to merge.
*/
public void mergeBackendNote(Note remoteNote) {
Note localNote = noteDao.queryByBackendId(remoteNote.getBackendId());
if (localNote != null) {
remoteNote.setId(localNote.getId());
}
saveNote(remoteNote);
}
use of io.jawg.osmcontributor.model.entities.Note in project osm-contributor by jawg.
the class NoteManager method mergeBackendNotes.
/**
* Merge Notes in parameters to those already in the database.
*
* @param remoteNotes The Notes to merge.
*/
public void mergeBackendNotes(List<Note> remoteNotes) {
List<Note> toMergeNotes = new ArrayList<>();
Map<String, Note> remoteNotesMap = new HashMap<>();
// Map remote Note backend Ids
for (Note note : remoteNotes) {
remoteNotesMap.put(note.getBackendId(), note);
}
// List matching Notes
List<Note> localNotes = noteDao.queryByBackendIds(remoteNotesMap.keySet());
Map<String, Note> localNotesMap = new HashMap<>();
// Map matching local Notes
for (Note localNote : localNotes) {
localNotesMap.put(localNote.getBackendId(), localNote);
}
// Browse remote notes
for (Note remoteNote : remoteNotes) {
Note localNote = localNotesMap.get(remoteNote.getBackendId());
if (localNote != null) {
remoteNote.setId(localNote.getId());
}
// This Note should be updated
toMergeNotes.add(remoteNote);
}
// saveNotes of either new or existing Notes
saveNotes(toMergeNotes);
}
use of io.jawg.osmcontributor.model.entities.Note in project osm-contributor by jawg.
the class OSMSyncNoteManager method remoteAddComment.
/**
* {@inheritDoc}
*/
public Note remoteAddComment(final Comment comment) {
Call<OsmDto> osmDtoCall;
switch(comment.getAction()) {
case Comment.ACTION_CLOSE:
osmDtoCall = osmRestClient.closeNote(comment.getNote().getBackendId(), comment.getText(), "");
break;
case Comment.ACTION_REOPEN:
osmDtoCall = osmRestClient.reopenNote(comment.getNote().getBackendId(), comment.getText(), "");
break;
case Comment.ACTION_OPEN:
osmDtoCall = osmRestClient.addNote(comment.getNote().getLatitude(), comment.getNote().getLongitude(), comment.getText(), "");
break;
default:
osmDtoCall = osmRestClient.addComment(comment.getNote().getBackendId(), comment.getText(), "");
break;
}
try {
Response<OsmDto> response = osmDtoCall.execute();
if (response.isSuccessful()) {
OsmDto osmDto = response.body();
if (osmDto != null) {
NoteDto noteDto = osmDto.getNoteDtoList().get(0);
Note note = noteMapper.convertNoteDtoToNote(noteDto);
note.setUpdated(false);
note.setId(comment.getNote().getId());
return note;
}
} else if (response.code() == 409) {
bus.post(new SyncConflictingNoteErrorEvent(comment.getNote()));
}
} catch (IOException e) {
Timber.e(e, "Retrofit error, couldn't create comment !");
}
bus.post(new SyncUploadNoteRetrofitErrorEvent(comment.getNote().getId()));
return null;
}
use of io.jawg.osmcontributor.model.entities.Note 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;
}
Aggregations