Skip to content
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

implement ičo and vatin quests #669

Open
wants to merge 6 commits into
base: modified
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import de.westnordost.streetcomplete.quests.baby_changing_table.AddBabyChangingT
import de.westnordost.streetcomplete.quests.barrier_bicycle_barrier_installation.AddBicycleBarrierInstallation
import de.westnordost.streetcomplete.quests.barrier_bicycle_barrier_type.AddBicycleBarrierType
import de.westnordost.streetcomplete.quests.barrier_height.AddBarrierHeight
import de.westnordost.streetcomplete.quests.barrier_opening.AddBarrierOpening
import de.westnordost.streetcomplete.quests.barrier_locked.AddBarrierLocked
import de.westnordost.streetcomplete.quests.barrier_opening.AddBarrierOpening
import de.westnordost.streetcomplete.quests.barrier_type.AddBarrierOnPath
import de.westnordost.streetcomplete.quests.barrier_type.AddBarrierOnRoad
import de.westnordost.streetcomplete.quests.barrier_type.AddBarrierType
Expand Down Expand Up @@ -148,7 +148,9 @@ import de.westnordost.streetcomplete.quests.piste_difficulty.AddPisteDifficulty
import de.westnordost.streetcomplete.quests.piste_lit.AddPisteLit
import de.westnordost.streetcomplete.quests.piste_ref.AddPisteRef
import de.westnordost.streetcomplete.quests.pitch_lit.AddPitchLit
import de.westnordost.streetcomplete.quests.place_ico.AddPlaceIco
import de.westnordost.streetcomplete.quests.place_name.AddPlaceName
import de.westnordost.streetcomplete.quests.place_vatin.AddPlaceVatin
import de.westnordost.streetcomplete.quests.playground_access.AddPlaygroundAccess
import de.westnordost.streetcomplete.quests.police_type.AddPoliceType
import de.westnordost.streetcomplete.quests.postbox_collection_times.AddPostboxCollectionTimes
Expand All @@ -166,7 +168,9 @@ import de.westnordost.streetcomplete.quests.road_name.AddRoadName
import de.westnordost.streetcomplete.quests.road_name.RoadNameSuggestionsSource
import de.westnordost.streetcomplete.quests.roof_colour.AddRoofColour
import de.westnordost.streetcomplete.quests.roof_shape.AddRoofShape
import de.westnordost.streetcomplete.quests.sac_scale.AddSacScale
vfosnar marked this conversation as resolved.
Show resolved Hide resolved
import de.westnordost.streetcomplete.quests.sanitary_dump_station.AddSanitaryDumpStation
import de.westnordost.streetcomplete.quests.sauna_availability.AddSaunaAvailability
vfosnar marked this conversation as resolved.
Show resolved Hide resolved
import de.westnordost.streetcomplete.quests.seating.AddOutdoorSeatingType
import de.westnordost.streetcomplete.quests.seating.AddSeating
import de.westnordost.streetcomplete.quests.segregated.AddCyclewaySegregation
Expand Down Expand Up @@ -204,6 +208,7 @@ import de.westnordost.streetcomplete.quests.surface.AddPathSurface
import de.westnordost.streetcomplete.quests.surface.AddPitchSurface
import de.westnordost.streetcomplete.quests.surface.AddRoadSurface
import de.westnordost.streetcomplete.quests.surface.AddSidewalkSurface
import de.westnordost.streetcomplete.quests.swimming_pool_availability.AddSwimmingPoolAvailability
import de.westnordost.streetcomplete.quests.tactile_paving.AddTactilePavingBusStop
import de.westnordost.streetcomplete.quests.tactile_paving.AddTactilePavingCrosswalk
import de.westnordost.streetcomplete.quests.tactile_paving.AddTactilePavingKerb
Expand All @@ -218,9 +223,6 @@ import de.westnordost.streetcomplete.quests.traffic_signals_sound.AddTrafficSign
import de.westnordost.streetcomplete.quests.traffic_signals_vibrate.AddTrafficSignalsVibration
import de.westnordost.streetcomplete.quests.trail_visibility.AddTrailVisibility
import de.westnordost.streetcomplete.quests.tree.AddTreeGenus
import de.westnordost.streetcomplete.quests.sac_scale.AddSacScale
import de.westnordost.streetcomplete.quests.sauna_availability.AddSaunaAvailability
import de.westnordost.streetcomplete.quests.swimming_pool_availability.AddSwimmingPoolAvailability
import de.westnordost.streetcomplete.quests.valves.AddValves
import de.westnordost.streetcomplete.quests.via_ferrata_scale.AddViaFerrataScale
import de.westnordost.streetcomplete.quests.way_lit.AddWayLit
Expand Down Expand Up @@ -639,6 +641,8 @@ fun getQuestTypeList(
EE_QUEST_OFFSET + 53 to AddSwimmingPoolAvailability(),
EE_QUEST_OFFSET + 10 to OsmoseQuest(osmoseDao),
EE_QUEST_OFFSET + 11 to CustomQuest(customQuestList),
EE_QUEST_OFFSET + 54 to AddPlaceIco(getFeature),
EE_QUEST_OFFSET + 55 to AddPlaceVatin(getFeature),
// POI quests
EE_QUEST_OFFSET + 12 to ShowBusiness(),
EE_QUEST_OFFSET + 13 to ShowBicycleStuff(),
Expand Down
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"
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()
}
}
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
Loading