Search in sources :

Example 6 with Comment

use of io.jawg.osmcontributor.model.entities.Comment in project osm-contributor by jawg.

the class CommentAdapter method getView.

@Override
public View getView(final int position, View view, final ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final Comment comment = comments.get(position);
    final ViewHolder holder;
    if (view != null) {
        holder = (ViewHolder) view.getTag();
    } else {
        view = inflater.inflate(R.layout.single_comment_layout, parent, false);
        holder = new ViewHolder(view);
        view.setTag(holder);
    }
    holder.getCommentContentTextView().setText(comment.getText());
    holder.getActionTextView().setText(comment.getAction());
    DateTimeFormatter fmt = DateTimeFormat.forPattern("MM/dd/yy");
    String date = comment.getCreatedDate() == null ? "" : fmt.print(comment.getCreatedDate());
    if (comment.getUpdated()) {
        date = context.getResources().getString(R.string.synchronizing);
    }
    holder.getDateTextView().setText(date);
    return view;
}
Also used : Comment(io.jawg.osmcontributor.model.entities.Comment) LayoutInflater(android.view.LayoutInflater) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 7 with Comment

use of io.jawg.osmcontributor.model.entities.Comment in project osm-contributor by jawg.

the class NoteManagerTest method getNote.

private Note getNote(int i) {
    Note note = new Note();
    note.setLatitude(42.0);
    note.setLongitude(73.0);
    note.setUpdated(true);
    Comment newComment = new Comment();
    newComment.setText("firstComment" + i);
    newComment.setAction(Comment.ACTION_OPEN);
    newComment.setNote(note);
    newComment.setUpdated(true);
    newComment.setCreatedDate(new DateTime());
    note.getComments().add(newComment);
    note.setStatus(Note.STATUS_SYNC);
    return note;
}
Also used : Comment(io.jawg.osmcontributor.model.entities.Comment) Note(io.jawg.osmcontributor.model.entities.Note) DateTime(org.joda.time.DateTime)

Example 8 with Comment

use of io.jawg.osmcontributor.model.entities.Comment in project osm-contributor by jawg.

the class NoteManagerTest method testSaveAndQuery.

@Test
public void testSaveAndQuery() {
    NoteManager noteManager = component.getNoteManager();
    Note note = getNote(1);
    Note saved = noteManager.saveNote(note);
    Note queried = noteManager.queryForId(saved.getId());
    Comment queriedComment = ((ArrayList<Comment>) queried.getComments()).get(0);
    assertThat(queried.getLatitude()).isEqualTo(42.0);
    assertThat(queried.getLongitude()).isEqualTo(73.0);
    assertThat(queried.getUpdated()).isTrue();
    assertThat(queriedComment.getText()).isEqualTo("firstComment1");
}
Also used : Comment(io.jawg.osmcontributor.model.entities.Comment) Note(io.jawg.osmcontributor.model.entities.Note) ArrayList(java.util.ArrayList) NoteManager(io.jawg.osmcontributor.ui.managers.NoteManager) Test(org.junit.Test)

Example 9 with Comment

use of io.jawg.osmcontributor.model.entities.Comment in project osm-contributor by jawg.

the class NoteManagerTest method testBulkSaveAndBulkUpdate.

@Test
public void testBulkSaveAndBulkUpdate() {
    NoteManager noteManager = component.getNoteManager();
    // try to save and then update 1000 notes.
    // 1000 because it can happen in real life and pose problems if we try to do an "IN" sql clause
    List<Note> notes = new ArrayList<>(1000);
    for (int i = 0; i < 1000; i++) {
        notes.add(getNote(i));
    }
    noteManager.saveNotes(notes);
    for (Note note : notes) {
        assertThat(note.getId()).isNotNull();
    }
    for (Note note : notes) {
        Comment newComment = new Comment();
        newComment.setText("secondComment");
        newComment.setAction(Comment.ACTION_OPEN);
        newComment.setNote(note);
        newComment.setUpdated(true);
        newComment.setCreatedDate(new DateTime());
        note.getComments().clear();
        note.getComments().add(newComment);
    }
    List<Note> savedNotes = noteManager.saveNotes(notes);
    for (Note note : savedNotes) {
        assertThat(note.getComments()).hasSize(1);
        Comment com = ((ArrayList<Comment>) note.getComments()).get(0);
        assertThat(com.getText()).isEqualTo("secondComment");
    }
}
Also used : Comment(io.jawg.osmcontributor.model.entities.Comment) Note(io.jawg.osmcontributor.model.entities.Note) ArrayList(java.util.ArrayList) NoteManager(io.jawg.osmcontributor.ui.managers.NoteManager) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

Comment (io.jawg.osmcontributor.model.entities.Comment)9 ArrayList (java.util.ArrayList)5 Note (io.jawg.osmcontributor.model.entities.Note)4 DateTime (org.joda.time.DateTime)3 CommentDto (io.jawg.osmcontributor.rest.dtos.osm.CommentDto)2 PleaseApplyNewComment (io.jawg.osmcontributor.ui.events.map.PleaseApplyNewComment)2 NoteManager (io.jawg.osmcontributor.ui.managers.NoteManager)2 Test (org.junit.Test)2 LayoutInflater (android.view.LayoutInflater)1 NoteSavedEvent (io.jawg.osmcontributor.model.events.NoteSavedEvent)1 NoteDto (io.jawg.osmcontributor.rest.dtos.osm.NoteDto)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1