Search in sources :

Example 1 with OsmNoteQuest

use of de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuest in project StreetComplete by westnordost.

the class QuestController method solveOsmNoteQuest.

private boolean solveOsmNoteQuest(long questId, Bundle answer) {
    OsmNoteQuest q = osmNoteQuestDB.get(questId);
    ArrayList<String> imagePaths = answer.getStringArrayList(NoteDiscussionForm.IMAGE_PATHS);
    String comment = answer.getString(NoteDiscussionForm.TEXT);
    if (comment != null && !comment.isEmpty()) {
        q.setComment(comment);
        q.setStatus(QuestStatus.ANSWERED);
        q.setImagePaths(imagePaths);
        osmNoteQuestDB.update(q);
        return true;
    } else {
        throw new RuntimeException("NoteQuest has been answered with an empty comment!");
    }
}
Also used : OsmNoteQuest(de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuest)

Example 2 with OsmNoteQuest

use of de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuest in project StreetComplete by westnordost.

the class QuestController method retrieve.

/**
 * Retrieve the given quest from local database asynchronously, including the element / note.
 */
public void retrieve(final QuestGroup group, final long questId) {
    workerHandler.post(() -> {
        if (group == QuestGroup.OSM) {
            // race condition: another thread may have removed the element already (#288)
            OsmQuest osmQuest = osmQuestDB.get(questId);
            if (osmQuest == null)
                return;
            Element element = osmElementDB.get(osmQuest.getElementType(), osmQuest.getElementId());
            if (element == null)
                return;
            relay.onQuestSelected(osmQuest, group, element);
        } else if (group == QuestGroup.OSM_NOTE) {
            OsmNoteQuest osmNoteQuest = osmNoteQuestDB.get(questId);
            if (osmNoteQuest == null)
                return;
            relay.onQuestSelected(osmNoteQuest, group, null);
        }
    });
}
Also used : Element(de.westnordost.osmapi.map.data.Element) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest) OsmNoteQuest(de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuest)

Example 3 with OsmNoteQuest

use of de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuest in project StreetComplete by westnordost.

the class QuestController method hideQuest.

/**
 * Make the given quest invisible asynchronously (per user interaction).
 */
public void hideQuest(final long questId, final QuestGroup group) {
    workerHandler.post(() -> {
        if (group == QuestGroup.OSM) {
            OsmQuest q = osmQuestDB.get(questId);
            if (q == null)
                return;
            q.setStatus(QuestStatus.HIDDEN);
            osmQuestDB.update(q);
            relay.onQuestRemoved(q.getId(), group);
        } else if (group == QuestGroup.OSM_NOTE) {
            OsmNoteQuest q = osmNoteQuestDB.get(questId);
            if (q == null)
                return;
            q.setStatus(QuestStatus.HIDDEN);
            osmNoteQuestDB.update(q);
            relay.onQuestRemoved(q.getId(), group);
        }
    });
}
Also used : OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest) OsmNoteQuest(de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuest)

Example 4 with OsmNoteQuest

use of de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuest in project StreetComplete by westnordost.

the class ApplyNoteVisibilityChangedTask method doInBackground.

@Override
protected Void doInBackground(Void... voids) {
    boolean showNonQuestionNotes = prefs.getBoolean(Prefs.SHOW_NOTES_NOT_PHRASED_AS_QUESTIONS, false);
    for (OsmNoteQuest quest : osmNoteQuestDao.getAll(null, null)) {
        if (quest.getStatus() == QuestStatus.NEW || quest.getStatus() == QuestStatus.INVISIBLE) {
            boolean visible = quest.probablyContainsQuestion() || showNonQuestionNotes;
            QuestStatus newQuestStatus = visible ? QuestStatus.NEW : QuestStatus.INVISIBLE;
            if (quest.getStatus() != newQuestStatus) {
                quest.setStatus(newQuestStatus);
                osmNoteQuestDao.update(quest);
            }
        }
    }
    return null;
}
Also used : QuestStatus(de.westnordost.streetcomplete.data.QuestStatus) OsmNoteQuest(de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuest)

Aggregations

OsmNoteQuest (de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuest)4 OsmQuest (de.westnordost.streetcomplete.data.osm.OsmQuest)2 Element (de.westnordost.osmapi.map.data.Element)1 QuestStatus (de.westnordost.streetcomplete.data.QuestStatus)1