Search in sources :

Example 11 with Note

use of de.westnordost.osmapi.notes.Note in project StreetComplete by westnordost.

the class OsmNoteQuestChangesUpload method uploadNoteChanges.

Note uploadNoteChanges(OsmNoteQuest quest) {
    String text = quest.getComment();
    try {
        text += AttachPhotoUtils.uploadAndGetAttachedPhotosText(imageUploader, quest.getImagePaths());
        Note newNote = osmDao.comment(quest.getNote().id, text);
        /* Unlike OSM quests, note quests are never deleted when the user contributed to it
			   but must remain in the database with the status CLOSED as long as they are not
			   solved. The reason is because as long as a note is unsolved, the problem at that
			   position persists and thus it should still block other quests to be created.
			   (Reminder: Note quests block other quests)
			  */
        // so, not this: questDB.delete(quest.getId());
        quest.setStatus(QuestStatus.CLOSED);
        quest.setNote(newNote);
        questDB.update(quest);
        noteDB.put(newNote);
        AttachPhotoUtils.deleteImages(quest.getImagePaths());
        return newNote;
    } catch (OsmConflictException e) {
        // someone else already closed the note -> our contribution is probably worthless. Delete
        questDB.delete(quest.getId());
        noteDB.delete(quest.getNote().id);
        AttachPhotoUtils.deleteImages(quest.getImagePaths());
        Log.i(TAG, "Dropped the comment " + getNoteQuestStringForLog(quest) + " because the note has already been closed");
        return null;
    }
}
Also used : OsmConflictException(de.westnordost.osmapi.common.errors.OsmConflictException) Note(de.westnordost.osmapi.notes.Note)

Example 12 with Note

use of de.westnordost.osmapi.notes.Note in project StreetComplete by westnordost.

the class OsmNoteQuestDao method createObjectFrom.

@Override
protected OsmNoteQuest createObjectFrom(Cursor cursor) {
    int colQuestId = cursor.getColumnIndexOrThrow(Columns.QUEST_ID), colNoteId = cursor.getColumnIndexOrThrow(Columns.NOTE_ID), colQuestStatus = cursor.getColumnIndexOrThrow(Columns.QUEST_STATUS), colComment = cursor.getColumnIndexOrThrow(Columns.COMMENT), colLastUpdate = cursor.getColumnIndexOrThrow(Columns.LAST_UPDATE), colImagePaths = cursor.getColumnIndexOrThrow(Columns.IMAGE_PATHS);
    long questId = cursor.getLong(colQuestId);
    String comment = null;
    if (!cursor.isNull(colComment)) {
        comment = cursor.getString(colComment);
    }
    QuestStatus status = QuestStatus.valueOf(cursor.getString(colQuestStatus));
    ArrayList<String> imagePaths = new ArrayList<>();
    if (!cursor.isNull(colImagePaths)) {
        imagePaths = serializer.toObject(cursor.getBlob(colImagePaths), ArrayList.class);
    }
    Date lastUpdate = new Date(cursor.getLong(colLastUpdate));
    Note note = null;
    if (!cursor.isNull(colNoteId)) {
        note = NoteDao.createObjectFrom(serializer, cursor);
    }
    return new OsmNoteQuest(questId, note, status, comment, lastUpdate, questType, imagePaths);
}
Also used : Note(de.westnordost.osmapi.notes.Note) ArrayList(java.util.ArrayList) QuestStatus(de.westnordost.streetcomplete.data.QuestStatus) Date(java.util.Date)

Example 13 with Note

use of de.westnordost.osmapi.notes.Note in project StreetComplete by westnordost.

the class NoteDaoTest method testPutReplace.

public void testPutReplace() {
    Note note = createNote();
    dao.put(note);
    note.status = Note.Status.CLOSED;
    dao.put(note);
    Note dbNote = dao.get(note.id);
    checkEqual(note, dbNote);
}
Also used : Note(de.westnordost.osmapi.notes.Note)

Example 14 with Note

use of de.westnordost.osmapi.notes.Note in project StreetComplete by westnordost.

the class NoteDaoTest method createNote.

static Note createNote() {
    Note note = new Note();
    note.position = new OsmLatLon(1, 1);
    note.status = Note.Status.OPEN;
    note.id = 5;
    note.dateCreated = new Date(5000);
    NoteComment comment = new NoteComment();
    comment.text = "hi";
    comment.date = new Date(5000);
    comment.action = NoteComment.Action.OPENED;
    comment.user = new User(5, "PingPong");
    note.comments.add(comment);
    return note;
}
Also used : NoteComment(de.westnordost.osmapi.notes.NoteComment) User(de.westnordost.osmapi.user.User) Note(de.westnordost.osmapi.notes.Note) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) Date(java.util.Date)

Example 15 with Note

use of de.westnordost.osmapi.notes.Note in project StreetComplete by westnordost.

the class NoteDaoTest method testPutGetWithClosedDate.

public void testPutGetWithClosedDate() {
    Note note = createNote();
    note.dateClosed = new Date(6000);
    dao.put(note);
    Note dbNote = dao.get(note.id);
    checkEqual(note, dbNote);
}
Also used : Note(de.westnordost.osmapi.notes.Note) Date(java.util.Date)

Aggregations

Note (de.westnordost.osmapi.notes.Note)32 OsmLatLon (de.westnordost.osmapi.map.data.OsmLatLon)10 Date (java.util.Date)8 LatLon (de.westnordost.osmapi.map.data.LatLon)5 ArrayList (java.util.ArrayList)5 BoundingBox (de.westnordost.osmapi.map.data.BoundingBox)4 NoteComment (de.westnordost.osmapi.notes.NoteComment)3 Way (de.westnordost.osmapi.map.data.Way)2 QuestStatus (de.westnordost.streetcomplete.data.QuestStatus)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 View (android.view.View)1 Button (android.widget.Button)1 TextView (android.widget.TextView)1 Handler (de.westnordost.osmapi.common.Handler)1 SingleElementHandler (de.westnordost.osmapi.common.SingleElementHandler)1 OsmConflictException (de.westnordost.osmapi.common.errors.OsmConflictException)1 NotesDao (de.westnordost.osmapi.notes.NotesDao)1 User (de.westnordost.osmapi.user.User)1 QuestGroup (de.westnordost.streetcomplete.data.QuestGroup)1 VisibleQuestListener (de.westnordost.streetcomplete.data.VisibleQuestListener)1