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")));
}
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);
}
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();
});
}
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");
}
});
}
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!");
}
}
Aggregations