From b66f4e804bf8b44fae3575bb1cabb2dd87501ba4 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Thu, 22 Feb 2024 18:09:26 +0100 Subject: [PATCH] ask about leaf type of natural=tree partial implementation of #83 --- .../streetcomplete/quests/QuestsModule.kt | 2 ++ .../quests/leaf_detail/AddTreeLeafType.kt | 34 +++++++++++++++++++ .../quests/leaf_detail/AddTreeLeafTypeForm.kt | 13 +++++++ .../quests/leaf_detail/TreeLeafType.kt | 6 ++++ .../quests/leaf_detail/TreeLeafTypeItem.kt | 18 ++++++++++ app/src/main/res/values/strings.xml | 1 + 6 files changed, 74 insertions(+) create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/leaf_detail/AddTreeLeafType.kt create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/leaf_detail/AddTreeLeafTypeForm.kt create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/leaf_detail/TreeLeafType.kt create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/leaf_detail/TreeLeafTypeItem.kt 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 86312a6276..7bd9f0b819 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/QuestsModule.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/QuestsModule.kt @@ -95,6 +95,7 @@ import de.westnordost.streetcomplete.quests.internet_access.AddInternetAccess import de.westnordost.streetcomplete.quests.kerb_height.AddKerbHeight import de.westnordost.streetcomplete.quests.lanes.AddLanes import de.westnordost.streetcomplete.quests.leaf_detail.AddForestLeafType +import de.westnordost.streetcomplete.quests.leaf_detail.AddTreeLeafType import de.westnordost.streetcomplete.quests.level.AddLevel import de.westnordost.streetcomplete.quests.max_height.AddMaxHeight import de.westnordost.streetcomplete.quests.max_height.AddMaxPhysicalHeight @@ -434,6 +435,7 @@ fun questTypeRegistry( 105 to AddSummitCross(), // summit markings are not necessarily directly at the peak, need to look around 106 to AddSummitRegister(), // register is harder to find than cross + 165 to AddTreeLeafType(), // may need to get close in trickier cases 107 to AddForestLeafType(), // need to walk around in the highlighted section 108 to AddOrchardProduce(), // difficult to find out if the orchard does not carry fruits right now diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/leaf_detail/AddTreeLeafType.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/leaf_detail/AddTreeLeafType.kt new file mode 100644 index 0000000000..2bf30b32ee --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/leaf_detail/AddTreeLeafType.kt @@ -0,0 +1,34 @@ +package de.westnordost.streetcomplete.quests.leaf_detail + +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.mapdata.filter +import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType +import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement.OUTDOORS +import de.westnordost.streetcomplete.osm.Tags + +class AddTreeLeafType : OsmFilterQuestType() { + override val elementFilter = """ + nodes with natural = tree and !leaf_type + """ + override val changesetComment = "Specify leaf types" + override val wikiLink = "Key:leaf_type" + override val icon = R.drawable.ic_quest_leaf + override val achievements = listOf(OUTDOORS) + + override fun getTitle(tags: Map) = R.string.quest_leafType_tree_title + + override fun getHighlightedElements(element: Element, getMapData: () -> MapDataWithGeometry) = + getMapData().filter(""" + nodes with natural=tree + """.toElementFilterExpression()) + + override fun createForm() = AddTreeLeafTypeForm() + + override fun applyAnswerTo(answer: TreeLeafType, tags: Tags, geometry: ElementGeometry, timestampEdited: Long) { + tags["leaf_type"] = answer.osmValue + } +} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/leaf_detail/AddTreeLeafTypeForm.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/leaf_detail/AddTreeLeafTypeForm.kt new file mode 100644 index 0000000000..454f26c6d8 --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/leaf_detail/AddTreeLeafTypeForm.kt @@ -0,0 +1,13 @@ +package de.westnordost.streetcomplete.quests.leaf_detail + +import de.westnordost.streetcomplete.quests.AImageListQuestForm + +class AddTreeLeafTypeForm : AImageListQuestForm() { + + override val items = TreeLeafType.entries.map { it.asItem() } + override val itemsPerRow = 2 + + override fun onClickOk(selectedItems: List) { + applyAnswer(selectedItems.single()) + } +} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/leaf_detail/TreeLeafType.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/leaf_detail/TreeLeafType.kt new file mode 100644 index 0000000000..48843c475d --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/leaf_detail/TreeLeafType.kt @@ -0,0 +1,6 @@ +package de.westnordost.streetcomplete.quests.leaf_detail + +enum class TreeLeafType(val osmValue: String) { + NEEDLELEAVED("needleleaved"), + BROADLEAVED("broadleaved"), +} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/leaf_detail/TreeLeafTypeItem.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/leaf_detail/TreeLeafTypeItem.kt new file mode 100644 index 0000000000..a3ad87c0d6 --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/leaf_detail/TreeLeafTypeItem.kt @@ -0,0 +1,18 @@ +package de.westnordost.streetcomplete.quests.leaf_detail + +import de.westnordost.streetcomplete.R +import de.westnordost.streetcomplete.quests.leaf_detail.TreeLeafType.BROADLEAVED +import de.westnordost.streetcomplete.quests.leaf_detail.TreeLeafType.NEEDLELEAVED +import de.westnordost.streetcomplete.view.image_select.Item + +fun TreeLeafType.asItem() = Item(this, iconResId, titleResId) + +private val TreeLeafType.titleResId: Int get() = when (this) { + NEEDLELEAVED -> R.string.quest_leaf_type_needles + BROADLEAVED -> R.string.quest_leaf_type_broadleaved +} + +private val TreeLeafType.iconResId: Int get() = when (this) { + NEEDLELEAVED -> R.drawable.leaf_type_needleleaved + BROADLEAVED -> R.drawable.leaf_type_broadleaved +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6dd5b21221..de73cb688c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1102,6 +1102,7 @@ If any lanes are reserved for buses, please leave a note instead." Needles Leaves Both are present + Do the tree here have needles or leaves? On which level number is this place located?