forked from streetcomplete/StreetComplete
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
collecting street data for streetcomplete#213
- Loading branch information
1 parent
e0e4313
commit 66a18e5
Showing
10 changed files
with
100 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
app/src/main/java/de/westnordost/streetcomplete/quests/address/AddAddressStreet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package de.westnordost.streetcomplete.quests.address | ||
|
||
import de.westnordost.osmapi.map.data.BoundingBox | ||
import de.westnordost.osmapi.map.data.Element | ||
import de.westnordost.streetcomplete.R | ||
import de.westnordost.streetcomplete.data.osm.OsmElementQuestType | ||
import de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder | ||
import de.westnordost.streetcomplete.data.osm.download.MapDataWithGeometryHandler | ||
import de.westnordost.streetcomplete.data.osm.download.OverpassMapDataDao | ||
import de.westnordost.streetcomplete.data.osm.tql.getQuestPrintStatement | ||
import de.westnordost.streetcomplete.data.osm.tql.toGlobalOverpassBBox | ||
|
||
class AddAddressStreet(private val overpassMapDataDao: OverpassMapDataDao) : OsmElementQuestType<AddressStreetAnswer> { | ||
override val commitMessage = "Add address" | ||
override val icon = R.drawable.ic_quest_label | ||
|
||
override fun getTitle(tags: Map<String, String>) = R.string.quest_address_street_title | ||
|
||
override fun createForm() = AddAddressStreetForm() | ||
|
||
override fun download(bbox: BoundingBox, handler: MapDataWithGeometryHandler): Boolean { | ||
return overpassMapDataDao.getAndHandleQuota(getOverpassQuery(bbox), handler); | ||
} | ||
|
||
override fun isApplicableTo(element: Element): Boolean? = null | ||
|
||
override fun applyAnswerTo(answer: AddressStreetAnswer, changes: StringMapChangesBuilder) { | ||
when(answer){ | ||
is StreetName -> {changes.add("addr:street", answer.name)} | ||
is PlaceName -> {changes.add("addr:place", answer.name)} | ||
} | ||
} | ||
|
||
private fun getOverpassQuery(bbox: BoundingBox) = | ||
bbox.toGlobalOverpassBBox() + """ | ||
relation["type"="associatedStreet"]; | ||
> -> .inStreetRelation; | ||
nwr["addr:street"!~".*"]["addr:housenumber"]["addr:place"!~".*"] -> .missing_data; | ||
(.missing_data; - .inStreetRelation;);""" + | ||
getQuestPrintStatement() | ||
} |
40 changes: 40 additions & 0 deletions
40
app/src/main/java/de/westnordost/streetcomplete/quests/address/AddAddressStreetForm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package de.westnordost.streetcomplete.quests.address | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.appcompat.app.AlertDialog | ||
import de.westnordost.streetcomplete.R | ||
import de.westnordost.streetcomplete.quests.AbstractQuestFormAnswerFragment | ||
import de.westnordost.streetcomplete.quests.OtherAnswer | ||
import de.westnordost.streetcomplete.util.TextChangedWatcher | ||
import kotlinx.android.synthetic.main.quest_placename.* | ||
|
||
class AddAddressStreetForm : AbstractQuestFormAnswerFragment<AddressStreetAnswer>() { | ||
override val contentLayoutResId = R.layout.quest_placename | ||
|
||
override val otherAnswers = listOf( | ||
OtherAnswer(R.string.quest_address_street_no_named_streets) { confirmNoName() } | ||
) | ||
|
||
private val placeName get() = nameInput?.text?.toString().orEmpty().trim() | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
nameInput.addTextChangedListener(TextChangedWatcher { checkIsFormComplete() }) | ||
} | ||
|
||
override fun onClickOk() { | ||
applyAnswer(StreetName(placeName)) | ||
} | ||
|
||
private fun confirmNoName() { | ||
AlertDialog.Builder(activity!!) | ||
.setTitle(R.string.quest_name_answer_noName_confirmation_title) | ||
.setPositiveButton(R.string.quest_name_noName_confirmation_positive) { _, _ -> applyAnswer(PlaceName("TODO")) } //TODO! | ||
.setNegativeButton(R.string.quest_generic_confirmation_no, null) | ||
.show() | ||
} | ||
|
||
override fun isFormComplete() = placeName.isNotEmpty() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../quests/housenumber/AddHousenumberForm.kt → ...lete/quests/address/AddHousenumberForm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
app/src/main/java/de/westnordost/streetcomplete/quests/address/AddressStreetAnswer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package de.westnordost.streetcomplete.quests.address | ||
|
||
sealed class AddressStreetAnswer | ||
|
||
data class StreetName(val name:String) : AddressStreetAnswer() | ||
data class PlaceName(val name:String) : AddressStreetAnswer() |
2 changes: 1 addition & 1 deletion
2
...e/quests/housenumber/HousenumberAnswer.kt → ...plete/quests/address/HousenumberAnswer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters