Search in sources :

Example 11 with Note

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

the class NoteMapper method convertNoteDtosToNotes.

public List<Note> convertNoteDtosToNotes(List<NoteDto> dtos) {
    List<Note> result = new ArrayList<>();
    if (dtos != null) {
        for (NoteDto dto : dtos) {
            Note note = new Note();
            note.setLatitude(dto.getLat());
            note.setLongitude(dto.getLon());
            note.setBackendId(dto.getId());
            note.setUpdated(false);
            note.setStatus(dto.getStatus());
            DateTime dt = null;
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z", Locale.US);
            try {
                Date date = simpleDateFormat.parse(dto.getDate_created());
                dt = new DateTime(date);
            } catch (ParseException ex) {
                System.out.println("Exception " + ex);
            }
            note.setCreatedDate(dt);
            ArrayList<Comment> comments = new ArrayList<>(dto.getCommentDtoList().size());
            for (CommentDto commentDto : dto.getCommentDtoList()) {
                Comment comment = new Comment();
                comment.setNote(note);
                comment.setUpdated(false);
                comment.setAction(commentDto.getAction());
                comment.setText(commentDto.getText());
                try {
                    Date date = simpleDateFormat.parse(commentDto.getDate());
                    dt = new DateTime(date);
                } catch (ParseException ex) {
                    System.out.println("Exception " + ex);
                }
                comment.setCreatedDate(dt);
                comments.add(comment);
            }
            note.setComments(comments);
            result.add(note);
        }
    }
    return result;
}
Also used : Comment(io.jawg.osmcontributor.model.entities.Comment) Note(io.jawg.osmcontributor.model.entities.Note) ArrayList(java.util.ArrayList) CommentDto(io.jawg.osmcontributor.rest.dtos.osm.CommentDto) ParseException(java.text.ParseException) NoteDto(io.jawg.osmcontributor.rest.dtos.osm.NoteDto) SimpleDateFormat(java.text.SimpleDateFormat) DateTime(org.joda.time.DateTime) Date(java.util.Date)

Example 12 with Note

use of io.jawg.osmcontributor.model.entities.Note 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 13 with Note

use of io.jawg.osmcontributor.model.entities.Note 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 14 with Note

use of io.jawg.osmcontributor.model.entities.Note 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)

Example 15 with Note

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

the class MapFragmentPresenter method onLoaded.

private void onLoaded(List<MapElement> mapElements, LocationMarkerView.MarkerType markerType) {
    LocationMarkerView markerSelected = mapFragment.getMarkerSelected();
    for (MapElement mapElement : mapElements) {
        ids.add(mapElement.getId());
        LocationMarkerViewOptions markerOptions = mapFragment.getMarkerOptions(markerType, mapElement.getId());
        boolean selected = false;
        if (markerOptions == null) {
            markerOptions = new LocationMarkerViewOptions<>().relatedObject(mapElement).position(mapElement.getPosition());
            if (mapFragment.getSelectedMarkerType().equals(markerType) && mapElement.getId().equals(mapFragment.getMarkerSelectedId())) {
                selected = true;
                mapFragment.setMarkerSelected(markerOptions.getMarker());
            } else if (mapFragment.getSelectedMarkerType().equals(LocationMarkerView.MarkerType.POI) && markerSelected != null && mapElement.getId().equals(((Poi) markerSelected.getRelatedObject()).getId())) {
                selected = true;
            }
            // the poi in edition should be hidden
            if (!(markerSelected != null && mapFragment.getMapMode() == MapMode.POI_POSITION_EDITION && markerSelected.equals(markerOptions.getMarker())) && (mapElement instanceof Poi && !((Poi) mapElement).getToDelete())) {
                setIcon(markerOptions, mapElement, selected);
                mapFragment.addPoi(markerOptions);
            }
            if (markerType == LocationMarkerView.MarkerType.NOTE) {
                if (mapFragment.getSelectedMarkerType().equals(LocationMarkerView.MarkerType.NOTE) && mapElement.getId().equals(mapFragment.getMarkerSelectedId())) {
                    mapFragment.setMarkerSelected(markerOptions.getMarker());
                }
                setIcon(markerOptions, mapElement, false);
                mapFragment.addNote(markerOptions);
            }
        } else {
            if (markerType == LocationMarkerView.MarkerType.POI) {
                Poi poi = (Poi) mapElement;
                Poi oldPoi = (Poi) markerOptions.getMarker().getRelatedObject();
                oldPoi.setName(poi.getName());
                oldPoi.setUpdated(poi.getUpdated());
                selected = false;
                if (mapFragment.getSelectedMarkerType().equals(LocationMarkerView.MarkerType.POI) && (mapElement.getId().equals(mapFragment.getMarkerSelectedId()) || markerSelected != null && mapElement.getId().equals(((Poi) markerSelected.getRelatedObject()).getId()))) {
                    selected = true;
                }
                setIcon(markerOptions, oldPoi, selected);
            } else {
                if (mapFragment.getSelectedMarkerType().equals(LocationMarkerView.MarkerType.NOTE) && markerSelected != null && mapElement.getId().equals(((Note) markerSelected.getRelatedObject()).getId())) {
                    selected = true;
                }
                setIcon(markerOptions, mapElement, selected);
            }
            // update the detail banner data
            if (selected) {
                if (mapFragment.getMapMode() == MapMode.DETAIL_NOTE) {
                    eventBus.post(new PleaseChangeValuesDetailNoteFragmentEvent((Note) mapElement));
                } else {
                    Poi poi = (Poi) mapElement;
                    eventBus.post(new PleaseChangeValuesDetailPoiFragmentEvent(poi));
                }
            }
        }
    }
    if ((mapFragment.getMapMode() == MapMode.DEFAULT || mapFragment.getMapMode() == MapMode.POI_CREATION)) {
        mapFragment.reselectMarker();
    }
    if (mapFragment.getSelectedMarkerType().equals(markerType) && markerSelected == null) {
        mapFragment.setMarkerSelectedId(-1L);
    }
}
Also used : MapElement(io.jawg.osmcontributor.utils.core.MapElement) LocationMarkerViewOptions(io.jawg.osmcontributor.ui.utils.views.map.marker.LocationMarkerViewOptions) Note(io.jawg.osmcontributor.model.entities.Note) PleaseChangeValuesDetailPoiFragmentEvent(io.jawg.osmcontributor.ui.events.map.PleaseChangeValuesDetailPoiFragmentEvent) Poi(io.jawg.osmcontributor.model.entities.Poi) LocationMarkerView(io.jawg.osmcontributor.ui.utils.views.map.marker.LocationMarkerView) PleaseChangeValuesDetailNoteFragmentEvent(io.jawg.osmcontributor.ui.events.map.PleaseChangeValuesDetailNoteFragmentEvent)

Aggregations

Note (io.jawg.osmcontributor.model.entities.Note)15 ArrayList (java.util.ArrayList)5 Comment (io.jawg.osmcontributor.model.entities.Comment)4 SyncFinishUploadNote (io.jawg.osmcontributor.rest.events.SyncFinishUploadNote)4 DateTime (org.joda.time.DateTime)3 Poi (io.jawg.osmcontributor.model.entities.Poi)2 NoteDto (io.jawg.osmcontributor.rest.dtos.osm.NoteDto)2 PleaseChangeValuesDetailNoteFragmentEvent (io.jawg.osmcontributor.ui.events.map.PleaseChangeValuesDetailNoteFragmentEvent)2 NoteManager (io.jawg.osmcontributor.ui.managers.NoteManager)2 MapElement (io.jawg.osmcontributor.utils.core.MapElement)2 Subscribe (org.greenrobot.eventbus.Subscribe)2 Test (org.junit.Test)2 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 Bitmap (android.graphics.Bitmap)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 Animation (android.view.animation.Animation)1 EditText (android.widget.EditText)1 PoisAndNotesDownloadedEvent (io.jawg.osmcontributor.model.events.PoisAndNotesDownloadedEvent)1