Search in sources :

Example 1 with QuestGroup

use of de.westnordost.streetcomplete.data.QuestGroup in project StreetComplete by westnordost.

the class FindQuestSourceComponent method findSource.

public void findSource(final long questId, final QuestGroup group, final Location[] locations, final Listener listener) {
    Double distance = getDistanceToElementInMeters(questId, group, locations);
    if (dontShowAgain || distance != null && distance < MAX_DISTANCE_TO_ELEMENT_FOR_SURVEY) {
        listener.onFindQuestSourceResult(SURVEY);
    } else {
        View inner = LayoutInflater.from(activity).inflate(R.layout.quest_source_dialog_layout, null, false);
        final CheckBox checkBox = inner.findViewById(R.id.checkBoxDontShowAgain);
        AlertDialogBuilder alertDialogBuilder = new AlertDialogBuilder(activity);
        alertDialogBuilder.setTitle(R.string.quest_source_dialog_title).setView(inner).setPositiveButton(R.string.quest_generic_confirmation_yes, (dialog, which) -> {
            ++timesShown;
            dontShowAgain = checkBox.isChecked();
            listener.onFindQuestSourceResult(SURVEY);
        }).setNegativeButton(android.R.string.cancel, null);
        checkBox.setVisibility(timesShown < 2 ? View.GONE : View.VISIBLE);
        alertDialogBuilder.show();
    }
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) OsmNoteQuestDao(de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuestDao) AlertDialogBuilder(de.westnordost.streetcomplete.view.dialogs.AlertDialogBuilder) LayoutInflater(android.view.LayoutInflater) DistanceOp(com.vividsolutions.jts.operation.distance.DistanceOp) SphericalEarthMath(de.westnordost.streetcomplete.util.SphericalEarthMath) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) List(java.util.List) R(de.westnordost.streetcomplete.R) CheckBox(android.widget.CheckBox) QuestGroup(de.westnordost.streetcomplete.data.QuestGroup) View(android.view.View) Geometry(com.vividsolutions.jts.geom.Geometry) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Location(android.location.Location) JTSConst(de.westnordost.streetcomplete.util.JTSConst) Activity(android.app.Activity) OsmQuestDao(de.westnordost.streetcomplete.data.osm.persist.OsmQuestDao) ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) AlertDialogBuilder(de.westnordost.streetcomplete.view.dialogs.AlertDialogBuilder) CheckBox(android.widget.CheckBox) View(android.view.View)

Example 2 with QuestGroup

use of de.westnordost.streetcomplete.data.QuestGroup in project StreetComplete by westnordost.

the class QuestAnswerComponentTest method testListener.

public void testListener() {
    QuestAnswerComponent c1 = new QuestAnswerComponent();
    final int expectQuestId = 3;
    final QuestGroup expectGroup = QuestGroup.OSM_NOTE;
    final String expectNote = "test";
    final String expectQuestTitle = "What?";
    final Bundle expectBundle = new Bundle();
    final ArrayList<String> expectImagePaths = new ArrayList<>();
    expectImagePaths.add("dings");
    expectImagePaths.add("dongs");
    expectBundle.putString("A", "B");
    c1.onAttach(new OsmQuestAnswerListener() {

        @Override
        public void onAnsweredQuest(long questId, QuestGroup group, Bundle answer) {
            assertEquals(expectQuestId, questId);
            assertEquals(expectGroup, group);
            assertEquals(expectBundle, answer);
        }

        @Override
        public void onLeaveNote(long questId, QuestGroup group, String questTitle, String note, ArrayList<String> imagePaths) {
            assertEquals(expectQuestId, questId);
            assertEquals(expectGroup, group);
            assertEquals(expectNote, note);
            assertEquals(expectQuestTitle, questTitle);
            assertEquals(expectImagePaths, imagePaths);
        }

        @Override
        public void onSkippedQuest(long questId, QuestGroup group) {
            assertEquals(expectQuestId, questId);
            assertEquals(expectGroup, group);
        }
    });
    c1.onCreate(QuestAnswerComponent.createArguments(expectQuestId, expectGroup));
    c1.onLeaveNote(expectQuestTitle, expectNote, expectImagePaths);
    c1.onAnswerQuest(expectBundle);
    c1.onSkippedQuest();
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) QuestGroup(de.westnordost.streetcomplete.data.QuestGroup)

Aggregations

QuestGroup (de.westnordost.streetcomplete.data.QuestGroup)2 ArrayList (java.util.ArrayList)2 Activity (android.app.Activity)1 Location (android.location.Location)1 Bundle (android.os.Bundle)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 CheckBox (android.widget.CheckBox)1 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)1 DistanceOp (com.vividsolutions.jts.operation.distance.DistanceOp)1 R (de.westnordost.streetcomplete.R)1 ElementGeometry (de.westnordost.streetcomplete.data.osm.ElementGeometry)1 OsmQuestDao (de.westnordost.streetcomplete.data.osm.persist.OsmQuestDao)1 OsmNoteQuestDao (de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuestDao)1 JTSConst (de.westnordost.streetcomplete.util.JTSConst)1 SphericalEarthMath (de.westnordost.streetcomplete.util.SphericalEarthMath)1 AlertDialogBuilder (de.westnordost.streetcomplete.view.dialogs.AlertDialogBuilder)1 List (java.util.List)1