forked from streetcomplete/StreetComplete
-
-
Notifications
You must be signed in to change notification settings - Fork 20
implement ičo and vatin quests #669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vfosnar
wants to merge
6
commits into
Helium314:modified
Choose a base branch
from
vfosnar:vatin_ico
base: modified
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6b09a97
implement ičo and vatin quest
vfosnar 0a5e973
bad check for :signed != no
vfosnar 137bb09
Merge branch 'modified' into vatin_ico
vfosnar 27d4b72
resolve conflict, fix disabled by default
vfosnar 74cf102
resolve some notes from @mnalis
vfosnar 08283a3
resolve more notes from @mnalis
vfosnar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
154 changes: 154 additions & 0 deletions
154
app/src/main/java/de/westnordost/streetcomplete/quests/place_ico/AddPlaceIco.kt
This file contains hidden or 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,154 @@ | ||
| package de.westnordost.streetcomplete.quests.place_ico | ||
|
|
||
| import android.content.Context | ||
| import de.westnordost.osmfeatures.Feature | ||
| import de.westnordost.streetcomplete.R | ||
| import de.westnordost.streetcomplete.data.elementfilter.toElementFilterExpression | ||
| import de.westnordost.streetcomplete.data.osm.geometry.ElementGeometry | ||
| import de.westnordost.streetcomplete.data.osm.mapdata.Element | ||
| import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry | ||
| import de.westnordost.streetcomplete.data.osm.osmquests.OsmElementQuestType | ||
| import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement.CITIZEN | ||
| import de.westnordost.streetcomplete.osm.Tags | ||
| import de.westnordost.streetcomplete.osm.isPlaceOrDisusedPlace | ||
| import de.westnordost.streetcomplete.quests.fullElementSelectionDialog | ||
| import de.westnordost.streetcomplete.quests.questPrefix | ||
|
|
||
| class AddPlaceIco( | ||
| private val getFeature: (Element) -> Feature? | ||
| ) : OsmElementQuestType<PlaceIcoAnswer> { | ||
|
|
||
| private val filter by lazy { (""" | ||
| nodes, ways with | ||
| ( | ||
| shop and shop !~ no|vacant | ||
| or office and office !~ no|vacant | ||
| or craft | ||
| or amenity = recycling and recycling_type = centre | ||
| or tourism = information and information = office | ||
| or """ + | ||
|
|
||
| // The common list is shared by the name quest, the opening hours quest and the wheelchair quest. | ||
| // So when adding other tags to the common list keep in mind that they need to be appropriate for all those quests. | ||
| // Independent tags can by added in the "name only" tab. | ||
mnalis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| prefs.getString(questPrefix(prefs) + PREF_ELEMENTS, NAME_PLACES)+ "\n" + """ | ||
| ) | ||
| and !brand and !ref:ico and ref:ico:signed != no | ||
| """).toElementFilterExpression() } | ||
|
|
||
| override val changesetComment = "Determine place IČO" | ||
| override val wikiLink = "Key:ref:ico" | ||
| override val icon = R.drawable.ic_quest_general_ref | ||
| override val isReplacePlaceEnabled = true | ||
| override val achievements = listOf(CITIZEN) | ||
|
|
||
| override fun getTitle(tags: Map<String, String>) = R.string.quest_placeIco_title | ||
|
|
||
| override fun getApplicableElements(mapData: MapDataWithGeometry): Iterable<Element> = | ||
| mapData.filter { isApplicableTo(it) } | ||
|
|
||
| override fun isApplicableTo(element: Element): Boolean = | ||
| filter.matches(element) && getFeature(element) != null | ||
|
|
||
| override fun getHighlightedElements(element: Element, getMapData: () -> MapDataWithGeometry) = | ||
| getMapData().asSequence().filter { it.isPlaceOrDisusedPlace() } | ||
|
|
||
| override fun createForm() = AddPlaceIcoForm() | ||
|
|
||
| override fun applyAnswerTo(answer: PlaceIcoAnswer, tags: Tags, geometry: ElementGeometry, timestampEdited: Long) { | ||
| when (answer) { | ||
| is NoPlaceIcoSign -> { | ||
| tags["ref:ico:signed"] = "no" | ||
| } | ||
| is PlaceIco -> { | ||
| tags["ref:ico"] = answer.ico | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override val hasQuestSettings = true | ||
|
|
||
| override val defaultDisabledMessage = R.string.default_disabled_msg_ee | ||
|
|
||
| override fun getQuestSettingsDialog(context: Context) = | ||
| fullElementSelectionDialog(context, prefs, questPrefix(prefs) + PREF_ELEMENTS, R.string.quest_settings_element_selection, NAME_PLACES) | ||
| } | ||
|
|
||
| private val NAME_PLACES = mapOf( | ||
| "amenity" to arrayOf( | ||
| // common | ||
| "restaurant", "cafe", "ice_cream", "fast_food", "bar", "pub", "biergarten", // eat & drink | ||
| "food_court", "nightclub", | ||
| "cinema", "planetarium", "casino", // amenities | ||
| "townhall", "courthouse", "embassy", "community_centre", "youth_centre", "library", // civic | ||
| "driving_school", "music_school", "prep_school", "language_school", "dive_centre", // learning | ||
| "dancing_school", "ski_school", "flight_school", "surf_school", "sailing_school", | ||
| "cooking_school", | ||
| "bank", "bureau_de_change", "money_transfer", "post_office", "marketplace", // commercial | ||
| "internet_cafe", "payment_centre", | ||
| "car_wash", "car_rental", "fuel", // car stuff | ||
| "dentist", "doctors", "clinic", "pharmacy", "veterinary", // health | ||
| "animal_boarding", "animal_shelter", "animal_breeding", // animals | ||
| "coworking_space", // work | ||
|
|
||
| // name & opening hours | ||
| "boat_rental", | ||
|
|
||
| // name & wheelchair | ||
| "theatre", // culture | ||
| "conference_centre", "arts_centre", // events | ||
| "police", "ranger_station", // civic | ||
| "ferry_terminal", // transport | ||
| "place_of_worship", // religious | ||
| "hospital", // health care | ||
| "brothel", "gambling", "love_hotel", "stripclub", // bad stuff | ||
|
|
||
| // name only | ||
| "studio", // culture | ||
| "events_venue", "exhibition_centre", "music_venue", // events | ||
| "prison", "fire_station", // civic | ||
| "social_facility", "nursing_home", "childcare", "retirement_home", "social_centre", // social | ||
| "monastery", // religious | ||
| "kindergarten", "school", "college", "university", "research_institute", // education | ||
| ), | ||
| "tourism" to arrayOf( | ||
| // common | ||
| "zoo", "aquarium", "theme_park", "gallery", "museum", | ||
|
|
||
| // name & wheelchair | ||
| "attraction", | ||
| "hotel", "guest_house", "motel", "hostel", "alpine_hut", "apartment", "resort", "camp_site", "caravan_site", "chalet" // accommodations | ||
|
|
||
| // and tourism = information, see above | ||
| ), | ||
| "leisure" to arrayOf( | ||
| // common | ||
| "fitness_centre", "golf_course", "water_park", "miniature_golf", "bowling_alley", | ||
| "amusement_arcade", "adult_gaming_centre", "tanning_salon", | ||
|
|
||
| // name & wheelchair | ||
| "sports_centre", "stadium", | ||
|
|
||
| // name only | ||
| "dance", "nature_reserve", "marina", "horse_riding", | ||
| ), | ||
| "landuse" to arrayOf( | ||
| "cemetery", "allotments" | ||
| ), | ||
| "military" to arrayOf( | ||
| "airfield", "barracks", "training_area" | ||
| ), | ||
| "healthcare" to arrayOf( | ||
| // common | ||
| "pharmacy", "doctor", "clinic", "dentist", "centre", "physiotherapist", | ||
| "laboratory", "alternative", "psychotherapist", "optometrist", "podiatrist", | ||
| "nurse", "counselling", "speech_therapist", "blood_donation", "sample_collection", | ||
| "occupational_therapist", "dialysis", "vaccination_centre", "audiologist", | ||
| "blood_bank", "nutrition_counselling", | ||
|
|
||
| // name & wheelchair | ||
| "rehabilitation", "hospice", "midwife", "birthing_centre" | ||
| ), | ||
| ).map { it.key + " ~ " + it.value.joinToString("|") }.joinToString("\n or ") | ||
| private const val PREF_ELEMENTS = "qs_AddPlaceIco_element_selection" | ||
50 changes: 50 additions & 0 deletions
50
app/src/main/java/de/westnordost/streetcomplete/quests/place_ico/AddPlaceIcoForm.kt
This file contains hidden or 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,50 @@ | ||
| package de.westnordost.streetcomplete.quests.place_ico | ||
|
|
||
| import android.os.Bundle | ||
| import android.text.InputType | ||
| import android.view.View | ||
| import androidx.appcompat.app.AlertDialog | ||
| import androidx.core.text.isDigitsOnly | ||
| import androidx.core.widget.doAfterTextChanged | ||
| import de.westnordost.streetcomplete.R | ||
| import de.westnordost.streetcomplete.databinding.QuestContactBinding | ||
| import de.westnordost.streetcomplete.quests.AbstractOsmQuestForm | ||
| import de.westnordost.streetcomplete.quests.AnswerItem | ||
|
|
||
| class AddPlaceIcoForm : AbstractOsmQuestForm<PlaceIcoAnswer>() { | ||
|
|
||
| override val contentLayoutResId = R.layout.quest_contact | ||
| private val binding by contentViewBinding(QuestContactBinding::bind) | ||
|
|
||
| private val ico get() = binding.nameInput.text?.toString().orEmpty().trim() | ||
|
|
||
| override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
| super.onViewCreated(view, savedInstanceState) | ||
| binding.nameInput.inputType = InputType.TYPE_CLASS_NUMBER | ||
|
|
||
| binding.nameInput.doAfterTextChanged { | ||
| checkIsFormComplete() | ||
| } | ||
| } | ||
|
|
||
| override val otherAnswers get() = listOfNotNull( | ||
| AnswerItem(R.string.quest_placeIco_no_ico_answer) { confirmNoSign() } | ||
| ) | ||
|
|
||
| override fun onClickOk() { | ||
| applyAnswer(PlaceIco(ico)) | ||
| } | ||
|
|
||
| override fun isFormComplete() = ico.length == 8 && ico.isDigitsOnly() | ||
|
|
||
| private fun confirmNoSign() { | ||
| val ctx = context ?: return | ||
| AlertDialog.Builder(ctx) | ||
| .setTitle(R.string.quest_generic_confirmation_title) | ||
| .setPositiveButton(R.string.quest_generic_confirmation_yes) { _, _ -> applyAnswer( | ||
| NoPlaceIcoSign | ||
| ) } | ||
| .setNegativeButton(R.string.quest_generic_confirmation_no, null) | ||
| .show() | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
app/src/main/java/de/westnordost/streetcomplete/quests/place_ico/PlaceIcoAnswer.kt
This file contains hidden or 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.place_ico | ||
|
|
||
| sealed interface PlaceIcoAnswer | ||
|
|
||
| data class PlaceIco(val ico: String) : PlaceIcoAnswer | ||
| data object NoPlaceIcoSign : PlaceIcoAnswer |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.