Search in sources :

Example 16 with OsmQuest

use of de.westnordost.streetcomplete.data.osm.OsmQuest in project StreetComplete by westnordost.

the class OsmQuestDaoTest method testGetNoFittingNextNewAt.

public void testGetNoFittingNextNewAt() {
    ElementGeometry geom = new ElementGeometry(new OsmLatLon(5, 5));
    OsmQuest quest = createNewQuest(new TestQuestType(), 1, Element.Type.NODE, geom);
    quest.setStatus(QuestStatus.ANSWERED);
    addToDaos(quest, createNewQuest(new TestQuestType2(), 2, Element.Type.NODE, geom));
    assertNull(dao.getNextNewAt(1, Arrays.asList("TestQuestType")));
}
Also used : ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest) TestQuestType(de.westnordost.streetcomplete.data.osm.persist.test.TestQuestType) TestQuestType2(de.westnordost.streetcomplete.data.osm.persist.test.TestQuestType2)

Example 17 with OsmQuest

use of de.westnordost.streetcomplete.data.osm.OsmQuest in project StreetComplete by westnordost.

the class MainActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    Intent intent;
    switch(id) {
        case R.id.action_undo:
            OsmQuest quest = questController.getLastSolvedOsmQuest();
            if (quest != null)
                confirmUndo(quest);
            else
                Toast.makeText(this, R.string.no_changes_to_undo, Toast.LENGTH_SHORT).show();
            return true;
        case R.id.action_settings:
            intent = new Intent(this, SettingsActivity.class);
            startActivity(intent);
            return true;
        case R.id.action_about:
            intent = new Intent(this, FragmentContainerActivity.class);
            intent.putExtra(FragmentContainerActivity.EXTRA_FRAGMENT_CLASS, AboutFragment.class.getName());
            startActivity(intent);
            return true;
        case R.id.action_download:
            if (isConnected())
                downloadDisplayedArea();
            else
                Toast.makeText(this, R.string.offline, Toast.LENGTH_SHORT).show();
            return true;
    }
    return super.onOptionsItemSelected(item);
}
Also used : AboutFragment(de.westnordost.streetcomplete.about.AboutFragment) Intent(android.content.Intent) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest) Point(android.graphics.Point) SettingsActivity(de.westnordost.streetcomplete.settings.SettingsActivity)

Example 18 with OsmQuest

use of de.westnordost.streetcomplete.data.osm.OsmQuest in project StreetComplete by westnordost.

the class QuestController method createNote.

/**
 * Create a note for the given OSM Quest instead of answering it. The quest will turn
 *  invisible.
 */
public void createNote(final long osmQuestId, final String questTitle, final String text, final ArrayList<String> imagePaths) {
    workerHandler.post(() -> {
        OsmQuest q = osmQuestDB.get(osmQuestId);
        // race condition: another thread may have removed the element already (#288)
        if (q == null)
            return;
        CreateNote createNote = new CreateNote();
        createNote.position = q.getMarkerLocation();
        createNote.text = text;
        createNote.questTitle = questTitle;
        createNote.elementType = q.getElementType();
        createNote.elementId = q.getElementId();
        createNote.imagePaths = imagePaths;
        createNoteDB.add(createNote);
        /* The quests that reference the same element for which the user was not able to
			   answer the question are removed because the to-be-created note blocks quest
			   creation for other users, so those quests should be removed from the user's
			   own display as well. As soon as the note is resolved, the quests will be re-
			   created next time they are downloaded */
        List<OsmQuest> questsForThisOsmElement = osmQuestDB.getAll(null, QuestStatus.NEW, null, q.getElementType(), q.getElementId());
        List<Long> otherQuestIdsForThisOsmElement = new ArrayList<>(questsForThisOsmElement.size());
        for (OsmQuest quest : questsForThisOsmElement) {
            if (quest.getId() != osmQuestId)
                otherQuestIdsForThisOsmElement.add(quest.getId());
        }
        /* creating a note instead of "really" solving the quest still counts as solving in
			   regards of the listener because the user answered to the quest and thats something
			 that needs to be uploaded */
        osmQuestDB.delete(osmQuestId);
        relay.onQuestSolved(osmQuestId, QuestGroup.OSM);
        osmQuestDB.deleteAll(otherQuestIdsForThisOsmElement);
        relay.onQuestsRemoved(otherQuestIdsForThisOsmElement, QuestGroup.OSM);
        osmElementDB.deleteUnreferenced();
        geometryDB.deleteUnreferenced();
    });
}
Also used : CreateNote(de.westnordost.streetcomplete.data.osmnotes.CreateNote) ArrayList(java.util.ArrayList) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest)

Example 19 with OsmQuest

use of de.westnordost.streetcomplete.data.osm.OsmQuest in project StreetComplete by westnordost.

the class QuestController method undoOsmQuest.

public void undoOsmQuest(final OsmQuest quest) {
    workerHandler.post(() -> {
        if (quest == null)
            return;
        // not uploaded yet -> simply revert to NEW
        if (quest.getStatus() == QuestStatus.ANSWERED || quest.getStatus() == QuestStatus.HIDDEN) {
            quest.setStatus(QuestStatus.NEW);
            quest.setChanges(null, null);
            osmQuestDB.update(quest);
            // inform relay that the quest is visible again
            relay.onQuestsCreated(Collections.singletonList(quest), QuestGroup.OSM);
        } else // already uploaded! -> create change to reverse the previous change
        if (quest.getStatus() == QuestStatus.CLOSED) {
            quest.setStatus(QuestStatus.REVERT);
            osmQuestDB.update(quest);
            OsmQuest reversedQuest = new OsmQuest(quest.getOsmElementQuestType(), quest.getElementType(), quest.getElementId(), quest.getGeometry());
            reversedQuest.setChanges(quest.getChanges().reversed(), quest.getChangesSource());
            reversedQuest.setStatus(QuestStatus.ANSWERED);
            undoOsmQuestDB.add(reversedQuest);
            relay.onQuestReverted(quest.getId(), QuestGroup.OSM);
        } else {
            throw new IllegalStateException("Tried to undo a quest that hasn't been answered yet");
        }
    });
}
Also used : OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest)

Example 20 with OsmQuest

use of de.westnordost.streetcomplete.data.osm.OsmQuest in project StreetComplete by westnordost.

the class QuestController method solveOsmQuest.

private boolean solveOsmQuest(long questId, Bundle answer, String source) {
    // race condition: another thread (i.e. quest download thread) may have removed the
    // element already (#282). So in this case, just ignore
    OsmQuest q = osmQuestDB.get(questId);
    if (q == null)
        return false;
    Element element = osmElementDB.get(q.getElementType(), q.getElementId());
    if (element == null)
        return false;
    StringMapChanges changes;
    try {
        StringMapChangesBuilder changesBuilder = new StringMapChangesBuilder(element.getTags());
        q.getOsmElementQuestType().applyAnswerTo(answer, changesBuilder);
        changes = changesBuilder.create();
    } catch (IllegalArgumentException e) {
        // if applying the changes results in an error (=a conflict), the data the quest(ion)
        // was based on is not valid anymore -> like with other conflicts, silently drop the
        // user's change (#289) and the quest
        osmQuestDB.delete(questId);
        return false;
    }
    if (!changes.isEmpty()) {
        q.setChanges(changes, source);
        q.setStatus(QuestStatus.ANSWERED);
        osmQuestDB.update(q);
        openChangesetsDao.setLastQuestSolvedTimeToNow();
        return true;
    } else {
        throw new RuntimeException("OsmQuest " + questId + " (" + q.getType().getClass().getSimpleName() + ") has been answered by the user but the changeset is empty!");
    }
}
Also used : StringMapChanges(de.westnordost.streetcomplete.data.osm.changes.StringMapChanges) Element(de.westnordost.osmapi.map.data.Element) StringMapChangesBuilder(de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest)

Aggregations

OsmQuest (de.westnordost.streetcomplete.data.osm.OsmQuest)31 Element (de.westnordost.osmapi.map.data.Element)11 ElementGeometry (de.westnordost.streetcomplete.data.osm.ElementGeometry)9 OsmLatLon (de.westnordost.osmapi.map.data.OsmLatLon)7 Point (android.graphics.Point)6 OsmQuestDao (de.westnordost.streetcomplete.data.osm.persist.OsmQuestDao)6 MergedElementDao (de.westnordost.streetcomplete.data.osm.persist.MergedElementDao)5 TestQuestType (de.westnordost.streetcomplete.data.osm.persist.test.TestQuestType)5 ArrayList (java.util.ArrayList)5 TestQuestType2 (de.westnordost.streetcomplete.data.osm.persist.test.TestQuestType2)4 DownloadedTilesDao (de.westnordost.streetcomplete.data.tiles.DownloadedTilesDao)4 MapDataDao (de.westnordost.osmapi.map.MapDataDao)3 OpenChangesetsDao (de.westnordost.streetcomplete.data.changesets.OpenChangesetsDao)3 StringMapChanges (de.westnordost.streetcomplete.data.osm.changes.StringMapChanges)3 HashMap (java.util.HashMap)3 SharedPreferences (android.content.SharedPreferences)2 BoundingBox (de.westnordost.osmapi.map.data.BoundingBox)2 QuestStatus (de.westnordost.streetcomplete.data.QuestStatus)2 OsmElementQuestType (de.westnordost.streetcomplete.data.osm.OsmElementQuestType)2 ElementGeometryDao (de.westnordost.streetcomplete.data.osm.persist.ElementGeometryDao)2