From 3b051b8c8db24218f64879aa14e6985261d58203 Mon Sep 17 00:00:00 2001 From: Matija Nalis Date: Mon, 9 Sep 2024 20:47:26 +0200 Subject: [PATCH] Implements AddBoardName quest (#5882) --- .../streetcomplete/quests/QuestsModule.kt | 2 + .../quests/board_name/AddBoardName.kt | 42 +++++++++++++++++++ .../quests/board_name/AddBoardNameForm.kt | 34 +++++++++++++++ .../quests/board_name/BoardNameAnswer.kt | 8 ++++ .../main/res/drawable/ic_quest_board_name.xml | 35 ++++++++++++++++ app/src/main/res/values/strings.xml | 2 + 6 files changed, 123 insertions(+) create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/board_name/AddBoardName.kt create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/board_name/AddBoardNameForm.kt create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/board_name/BoardNameAnswer.kt create mode 100644 app/src/main/res/drawable/ic_quest_board_name.xml diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/QuestsModule.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/QuestsModule.kt index 1d7e43d5d3..5adc8f567b 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/QuestsModule.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/QuestsModule.kt @@ -39,6 +39,7 @@ import de.westnordost.streetcomplete.quests.bike_rental_capacity.AddBikeRentalCa import de.westnordost.streetcomplete.quests.bike_rental_type.AddBikeRentalType import de.westnordost.streetcomplete.quests.bike_shop.AddBikeRepairAvailability import de.westnordost.streetcomplete.quests.bike_shop.AddSecondHandBicycleAvailability +import de.westnordost.streetcomplete.quests.board_name.AddBoardName import de.westnordost.streetcomplete.quests.board_type.AddBoardType import de.westnordost.streetcomplete.quests.bollard_type.AddBollardType import de.westnordost.streetcomplete.quests.bridge_structure.AddBridgeStructure @@ -340,6 +341,7 @@ fun questTypeRegistry( 155 to AddGritBinSeasonal(), 50 to AddBoardType(), + 171 to AddBoardName(), 51 to AddBarrierType(), // basically any more detailed rendering and routing: OSM Carto, mapy.cz, OSMand for start 52 to AddBarrierOnPath(), diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/board_name/AddBoardName.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/board_name/AddBoardName.kt new file mode 100644 index 0000000000..d82a83549b --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/board_name/AddBoardName.kt @@ -0,0 +1,42 @@ +package de.westnordost.streetcomplete.quests.board_name + +import de.westnordost.streetcomplete.R +import de.westnordost.streetcomplete.data.osm.geometry.ElementGeometry +import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType +import de.westnordost.streetcomplete.data.quest.AllCountriesExcept +import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement.OUTDOORS +import de.westnordost.streetcomplete.osm.Tags +import de.westnordost.streetcomplete.osm.applyTo + +class AddBoardName : OsmFilterQuestType() { + + override val elementFilter = """ + nodes, ways, relations with + ( + tourism=information and information=board + and board_type != notice + and !board:title + ) + and !name and noname != yes and name:signed != no + """ + + override val changesetComment = "Determine information board names" + override val wikiLink = "Tag:information=board" + override val icon = R.drawable.ic_quest_board_name + override val achievements = listOf(OUTDOORS) + + override fun getTitle(tags: Map) = R.string.quest_board_name_title + + override fun createForm() = AddBoardNameForm() + + override fun applyAnswerTo(answer: BoardNameAnswer, tags: Tags, geometry: ElementGeometry, timestampEdited: Long) { + when (answer) { + is NoBoardName -> { + tags["noname"] = "yes" + } + is BoardName -> { + answer.localizedNames.applyTo(tags) + } + } + } +} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/board_name/AddBoardNameForm.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/board_name/AddBoardNameForm.kt new file mode 100644 index 0000000000..649400cf93 --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/board_name/AddBoardNameForm.kt @@ -0,0 +1,34 @@ +package de.westnordost.streetcomplete.quests.board_name + +import androidx.appcompat.app.AlertDialog +import de.westnordost.streetcomplete.R +import de.westnordost.streetcomplete.databinding.QuestLocalizednameBinding +import de.westnordost.streetcomplete.osm.LocalizedName +import de.westnordost.streetcomplete.quests.AAddLocalizedNameForm +import de.westnordost.streetcomplete.quests.AnswerItem + +class AddBoardNameForm : AAddLocalizedNameForm() { + + override val contentLayoutResId = R.layout.quest_localizedname + private val binding by contentViewBinding(QuestLocalizednameBinding::bind) + + override val addLanguageButton get() = binding.addLanguageButton + override val namesList get() = binding.namesList + + override val otherAnswers = listOf( + AnswerItem(R.string.quest_placeName_no_name_answer) { confirmNoName() }, + AnswerItem(R.string.quest_streetName_answer_cantType) { showKeyboardInfo() } + ) + + override fun onClickOk(names: List) { + applyAnswer(BoardName(names)) + } + + private fun confirmNoName() { + AlertDialog.Builder(requireContext()) + .setTitle(R.string.quest_name_answer_noName_confirmation_title) + .setPositiveButton(R.string.quest_name_noName_confirmation_positive) { _, _ -> applyAnswer(NoBoardName) } + .setNegativeButton(R.string.quest_generic_confirmation_no, null) + .show() + } +} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/board_name/BoardNameAnswer.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/board_name/BoardNameAnswer.kt new file mode 100644 index 0000000000..19755b7b59 --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/board_name/BoardNameAnswer.kt @@ -0,0 +1,8 @@ +package de.westnordost.streetcomplete.quests.board_name + +import de.westnordost.streetcomplete.osm.LocalizedName + +sealed interface BoardNameAnswer + +data object NoBoardName : BoardNameAnswer +data class BoardName(val localizedNames: List) : BoardNameAnswer diff --git a/app/src/main/res/drawable/ic_quest_board_name.xml b/app/src/main/res/drawable/ic_quest_board_name.xml new file mode 100644 index 0000000000..502d36bbec --- /dev/null +++ b/app/src/main/res/drawable/ic_quest_board_name.xml @@ -0,0 +1,35 @@ + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 513b6beff0..8e056c9f99 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -793,6 +793,8 @@ Before uploading your changes, the app checks with a <a href=\"https://www.we Is there a working bicycle pump here? Is there an air compressor available here? + "What’s the title of this information board?" + What’s the topic of this information board? History Geology