From c683fd58009bd7b7f9011dac3e544e0ca8dce54f Mon Sep 17 00:00:00 2001 From: Jean-BaptisteC Date: Tue, 21 Nov 2023 18:16:42 +0100 Subject: [PATCH 1/3] Add line_attachment quest --- .../streetcomplete/quests/QuestsModule.kt | 4 +- .../power_attachment/AddPowerAttachment.kt | 42 +++++++++++++++++++ .../AddPowerAttachmentForm.kt | 13 ++++++ .../power_attachment/PowerAttachment.kt | 7 ++++ .../power_attachment/PowerAttachmentItem.kt | 21 ++++++++++ app/src/main/res/values/strings.xml | 5 +++ 6 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/AddPowerAttachment.kt create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/AddPowerAttachmentForm.kt create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/PowerAttachment.kt create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/PowerAttachmentItem.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 eb57b04ea9..052720a243 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/QuestsModule.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/QuestsModule.kt @@ -124,6 +124,7 @@ import de.westnordost.streetcomplete.quests.police_type.AddPoliceType import de.westnordost.streetcomplete.quests.postbox_collection_times.AddPostboxCollectionTimes import de.westnordost.streetcomplete.quests.postbox_ref.AddPostboxRef import de.westnordost.streetcomplete.quests.postbox_royal_cypher.AddPostboxRoyalCypher +import de.westnordost.streetcomplete.quests.power_attachment.AddPowerAttachment import de.westnordost.streetcomplete.quests.powerpoles_material.AddPowerPolesMaterial import de.westnordost.streetcomplete.quests.railway_crossing.AddRailwayCrossingBarrier import de.westnordost.streetcomplete.quests.recycling.AddRecyclingType @@ -293,7 +294,8 @@ fun questTypeRegistry( 26 to AddReligionToPlaceOfWorship(), // icons on maps are different - OSM Carto, mapy.cz, OsmAnd, Sputnik etc 27 to AddReligionToWaysideShrine(), - + + 164 to AddPowerAttachment() 28 to AddPowerPolesMaterial(), 29 to AddIsBuildingUnderground(), // should be before AddHousenumber to avoid asking for underground buildings diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/AddPowerAttachment.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/AddPowerAttachment.kt new file mode 100644 index 0000000000..b94f87a542 --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/AddPowerAttachment.kt @@ -0,0 +1,42 @@ +package de.westnordost.streetcomplete.quests.power_attachment + +import de.westnordost.streetcomplete.R +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.BUILDING +import de.westnordost.streetcomplete.osm.Tags + +class AddPowerAttachment : OsmFilterQuestType() { + + override val elementFilter = """ + nodes with + (power = tower or power = pole or power = insulator) + and !line_attachment + """ + override val changesetComment = "Specify line_attachment power support" + override val wikiLink = "Key:line_attachment" + override val icon = R.drawable.ic_quest_power + override val achievements = listOf(BUILDING) + + override fun getTitle(tags: Map) = R.string.quest_powerAttachment_title + + override fun getHighlightedElements(element: Element, getMapData: () -> MapDataWithGeometry): Sequence { + val mapData = getMapData() + // and also show the (power) lines themselves + return mapData.filter("nodes with power = tower or power = pole or power = insulator") + + mapData.filter("ways with power ~ line|minor_line") + } + + // map data density is usually lower where there are power poles and more context is necessary + // when looking at them from afar + override val highlightedElementsRadius get() = 100.0 + + override fun createForm() = AddPowerAttachmentForm() + + override fun applyAnswerTo(answer: PowerAttachment, tags: Tags, geometry: ElementGeometry, timestampEdited: Long) { + tags["line_attachment"] = answer.osmValue + } +} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/AddPowerAttachmentForm.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/AddPowerAttachmentForm.kt new file mode 100644 index 0000000000..af9de31fa5 --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/AddPowerAttachmentForm.kt @@ -0,0 +1,13 @@ +package de.westnordost.streetcomplete.quests.power_attachment + +import de.westnordost.streetcomplete.quests.AImageListQuestForm + +class AddPowerAttachmentForm : AImageListQuestForm() { + + override val items = PowerAttachment.values().map { it.asItem() } + override val itemsPerRow = 3 + + override fun onClickOk(selectedItems: List) { + applyAnswer(selectedItems.single()) + } +} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/PowerAttachment.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/PowerAttachment.kt new file mode 100644 index 0000000000..1cb421fbed --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/PowerAttachment.kt @@ -0,0 +1,7 @@ +package de.westnordost.streetcomplete.quests.power_attachment + +enum class PowerAttachment(val osmValue: String) { + SUSPENSION("suspension"), + ANCHOR("anchor"), + PIN("pin"), +} diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/PowerAttachmentItem.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/PowerAttachmentItem.kt new file mode 100644 index 0000000000..78df623779 --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/PowerAttachmentItem.kt @@ -0,0 +1,21 @@ +package de.westnordost.streetcomplete.quests.power_attachment + +import de.westnordost.streetcomplete.R +import de.westnordost.streetcomplete.quests.powerpoles_material.PowerAttachment.SUSPENSION +import de.westnordost.streetcomplete.quests.powerpoles_material.PowerAttachment.ANCHOR +import de.westnordost.streetcomplete.quests.powerpoles_material.PowerAttachment.PIN +import de.westnordost.streetcomplete.view.image_select.Item + +fun PowerAttachment.asItem() = Item(this, iconResId, titleResId) + +private val PowerAttachment.titleResId: Int get() = when (this) { + SUSPENSION -> R.string.quest_powerAttachment_suspension + ANCHOR -> R.string.quest_powerAttachment_anchor + PIN -> R.string.quest_powerAttachment_pin +} + +private val PowerAttachment.iconResId: Int get() = when (this) { + SUSPENSION -> R.drawable.power_attachment_suspension + ANCHOR -> R.drawable.power_attachment_anchor + PIN -> R.drawable.power_attachment_pin +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3e3fb75fd2..60a7f638c3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1313,6 +1313,11 @@ If there are no signs along the whole street which apply for the highlighted sec What’s the royal cypher on this postbox? No royal cypher is visible The Crown of Scotland + + How power line is attached on this support? + Suspension + Anchor + Pin What’s this pole made of? From cfcbfef4e59354660eb06818bb63cbf2211d9b02 Mon Sep 17 00:00:00 2001 From: Jean-BaptisteC Date: Thu, 23 Nov 2023 17:50:10 +0100 Subject: [PATCH 2/3] Add suggestions --- .../quests/power_attachment/AddPowerAttachment.kt | 4 ++-- .../quests/power_attachment/PowerAttachmentItem.kt | 8 ++++---- app/src/main/res/values/strings.xml | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/AddPowerAttachment.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/AddPowerAttachment.kt index b94f87a542..1569ce67d0 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/AddPowerAttachment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/AddPowerAttachment.kt @@ -13,7 +13,7 @@ class AddPowerAttachment : OsmFilterQuestType() { override val elementFilter = """ nodes with - (power = tower or power = pole or power = insulator) + power ~ tower|pole|insulator and !line_attachment """ override val changesetComment = "Specify line_attachment power support" @@ -26,7 +26,7 @@ class AddPowerAttachment : OsmFilterQuestType() { override fun getHighlightedElements(element: Element, getMapData: () -> MapDataWithGeometry): Sequence { val mapData = getMapData() // and also show the (power) lines themselves - return mapData.filter("nodes with power = tower or power = pole or power = insulator") + + return mapData.filter("nodes with power ~ tower|pole|insulator") + mapData.filter("ways with power ~ line|minor_line") } diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/PowerAttachmentItem.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/PowerAttachmentItem.kt index 78df623779..6d04bb66f4 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/PowerAttachmentItem.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/power_attachment/PowerAttachmentItem.kt @@ -9,13 +9,13 @@ import de.westnordost.streetcomplete.view.image_select.Item fun PowerAttachment.asItem() = Item(this, iconResId, titleResId) private val PowerAttachment.titleResId: Int get() = when (this) { - SUSPENSION -> R.string.quest_powerAttachment_suspension - ANCHOR -> R.string.quest_powerAttachment_anchor + SUSPENSION -> R.string.quest_powerAttachment_suspension + ANCHOR -> R.string.quest_powerAttachment_anchor PIN -> R.string.quest_powerAttachment_pin } private val PowerAttachment.iconResId: Int get() = when (this) { - SUSPENSION -> R.drawable.power_attachment_suspension - ANCHOR -> R.drawable.power_attachment_anchor + SUSPENSION -> R.drawable.power_attachment_suspension + ANCHOR -> R.drawable.power_attachment_anchor PIN -> R.drawable.power_attachment_pin } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 60a7f638c3..528cb56baf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1314,7 +1314,7 @@ If there are no signs along the whole street which apply for the highlighted sec No royal cypher is visible The Crown of Scotland - How power line is attached on this support? + How is this power line attached? Suspension Anchor Pin From 79ec4cbba739140057dd1876fd082f91f6bc8b72 Mon Sep 17 00:00:00 2001 From: Jean-BaptisteC Date: Thu, 23 Nov 2023 17:51:16 +0100 Subject: [PATCH 3/3] Fix indentations --- app/src/main/res/values/strings.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 528cb56baf..9614e02514 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1314,10 +1314,10 @@ If there are no signs along the whole street which apply for the highlighted sec No royal cypher is visible The Crown of Scotland - How is this power line attached? - Suspension - Anchor - Pin + How is this power line attached? + Suspension + Anchor + Pin What’s this pole made of?