Skip to content

Commit

Permalink
Add quests for capacity=, capacity:disabled= and orientation= f…
Browse files Browse the repository at this point in the history
…or `amenity=parking` (#497)


---------

Co-authored-by: Helium314 <[email protected]>
  • Loading branch information
wielandb and Helium314 authored Mar 27, 2024
1 parent 4e58ad7 commit 2cc88a3
Show file tree
Hide file tree
Showing 15 changed files with 614 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,11 @@ import de.westnordost.streetcomplete.quests.opening_hours_signed.CheckOpeningHou
import de.westnordost.streetcomplete.quests.orchard_produce.AddOrchardProduce
import de.westnordost.streetcomplete.quests.parking_access.AddBikeParkingAccess
import de.westnordost.streetcomplete.quests.parking_access.AddParkingAccess
import de.westnordost.streetcomplete.quests.parking_capacity.AddDisabledParkingCapacity
import de.westnordost.streetcomplete.quests.parking_capacity.AddParkingCapacity
import de.westnordost.streetcomplete.quests.parking_fee.AddBikeParkingFee
import de.westnordost.streetcomplete.quests.parking_fee.AddParkingFee
import de.westnordost.streetcomplete.quests.parking_orientation.AddParkingOrientation
import de.westnordost.streetcomplete.quests.parking_type.AddParkingType
import de.westnordost.streetcomplete.quests.pharmacy.AddIsPharmacyDispensing
import de.westnordost.streetcomplete.quests.piste_lit.AddPisteLit
Expand Down Expand Up @@ -628,6 +631,9 @@ fun getQuestTypeList(
EE_QUEST_OFFSET + 40 to AddPisteLit(),
EE_QUEST_OFFSET + 35 to AddPisteRef(),
EE_QUEST_OFFSET + 36 to AddPisteDifficulty(),
EE_QUEST_OFFSET + 45 to AddParkingCapacity(),
EE_QUEST_OFFSET + 46 to AddDisabledParkingCapacity(),
EE_QUEST_OFFSET + 47 to AddParkingOrientation(),
EE_QUEST_OFFSET + 10 to OsmoseQuest(osmoseDao),
EE_QUEST_OFFSET + 11 to CustomQuest(customQuestList),
// POI quests
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package de.westnordost.streetcomplete.quests.parking_capacity

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.WHEELCHAIR
import de.westnordost.streetcomplete.osm.Tags

class AddDisabledParkingCapacity : OsmFilterQuestType<String>() {

override val elementFilter = """
nodes, ways with
amenity = parking
and access !~ private|no
and !capacity:disabled
"""

override val changesetComment = "Specify disabled parking capacities"
override val wikiLink = "Key:capacity:disabled"
override val icon = R.drawable.ic_quest_parking_capacity_disabled
override val achievements = listOf(WHEELCHAIR)
override val defaultDisabledMessage = R.string.quest_parking_capacity_disabled_default_disabled_msg

override fun getTitle(tags: Map<String, String>) = R.string.quest_parking_capacity_disabled_title

override fun getHighlightedElements(element: Element, getMapData: () -> MapDataWithGeometry) =
getMapData().filter("nodes, ways with amenity = parking")

override fun createForm() = AddDisabledParkingCapacityForm()

override fun applyAnswerTo(answer: String, tags: Tags, geometry: ElementGeometry, timestampEdited: Long) {
tags["capacity:disabled"] = answer
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package de.westnordost.streetcomplete.quests.parking_capacity

import android.os.Bundle
import android.view.View
import androidx.core.widget.doAfterTextChanged
import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.databinding.QuestDisabledParkingCapacityBinding
import de.westnordost.streetcomplete.quests.AbstractOsmQuestForm
import de.westnordost.streetcomplete.quests.AnswerItem
import de.westnordost.streetcomplete.util.ktx.intOrNull

class AddDisabledParkingCapacityForm : AbstractOsmQuestForm<String>() {

override val contentLayoutResId = R.layout.quest_disabled_parking_capacity
private val binding by contentViewBinding(QuestDisabledParkingCapacityBinding::bind)

private val capacity get() = binding.capacityInput.intOrNull ?: 0

override val otherAnswers = mutableListOf<AnswerItem>()

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.capacityInput.doAfterTextChanged { checkIsFormComplete() }
if (element.tags["capacity:disabled"] != "yes") {
otherAnswers.add(AnswerItem(R.string.quest_parking_capacity_disabled_answer_yes) {
applyAnswer(
"yes"
)
})
}
}

override fun isFormComplete() = capacity >= 0

override fun onClickOk() {
if (capacity == 0) {
applyAnswer("no")
} else {
applyAnswer(capacity.toString())
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package de.westnordost.streetcomplete.quests.parking_capacity

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.CAR
import de.westnordost.streetcomplete.osm.Tags
import de.westnordost.streetcomplete.osm.updateWithCheckDate

class AddParkingCapacity : OsmFilterQuestType<Int>() {

override val elementFilter = """
nodes, ways with
amenity = parking
and parking = surface
and access !~ private|no
and !capacity
"""

override val changesetComment = "Specify parking capacities"
override val wikiLink = "Tag:amenity=parking"
override val icon = R.drawable.ic_quest_parking_capacity
override val achievements = listOf(CAR)
override val defaultDisabledMessage = R.string.default_disabled_msg_ee

override fun getTitle(tags: Map<String, String>) = R.string.quest_parking_capacity_title

override fun getHighlightedElements(element: Element, getMapData: () -> MapDataWithGeometry) =
getMapData().filter("nodes, ways with amenity = parking")

override fun createForm() = AddParkingCapacityForm()

override fun applyAnswerTo(answer: Int, tags: Tags, geometry: ElementGeometry, timestampEdited: Long) {
tags.updateWithCheckDate("capacity", answer.toString())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package de.westnordost.streetcomplete.quests.parking_capacity

import android.os.Bundle
import android.view.View
import androidx.core.widget.doAfterTextChanged
import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.databinding.QuestCarParkingCapacityBinding
import de.westnordost.streetcomplete.quests.AbstractOsmQuestForm
import de.westnordost.streetcomplete.util.ktx.intOrNull

class AddParkingCapacityForm : AbstractOsmQuestForm<Int>() {

override val contentLayoutResId = R.layout.quest_car_parking_capacity
private val binding by contentViewBinding(QuestCarParkingCapacityBinding::bind)

private val capacity get() = binding.capacityInput.intOrNull ?: 0

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.capacityInput.doAfterTextChanged { checkIsFormComplete() }
}

override fun isFormComplete() = capacity > 0

override fun onClickOk() {
applyAnswer(capacity)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package de.westnordost.streetcomplete.quests.parking_orientation

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.user.achievements.EditTypeAchievement.CAR
import de.westnordost.streetcomplete.osm.Tags
import de.westnordost.streetcomplete.osm.street_parking.ParkingOrientation

class AddParkingOrientation : OsmFilterQuestType<ParkingOrientation>() {

override val elementFilter = """
nodes, ways, relations with
amenity = parking
and parking ~ "lane|street_side|on_kerb|half_on_kerb"
and !orientation
"""
override val changesetComment = "Specify parking orientation"
override val wikiLink = "Key:orientation"
override val icon = R.drawable.ic_quest_parking_orientation
override val achievements = listOf(CAR)

override fun getTitle(tags: Map<String, String>) = R.string.quest_parking_orientation_title

override fun createForm() = AddParkingOrientationForm()

override val defaultDisabledMessage = R.string.default_disabled_msg_ee

override fun applyAnswerTo(answer: ParkingOrientation, tags: Tags, geometry: ElementGeometry, timestampEdited: Long) {
tags["orientation"] = answer.osmValue
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package de.westnordost.streetcomplete.quests.parking_orientation

import de.westnordost.streetcomplete.osm.street_parking.ParkingOrientation
import de.westnordost.streetcomplete.quests.AImageListQuestForm
class AddParkingOrientationForm : AImageListQuestForm<ParkingOrientation, ParkingOrientation>() {
override val items get() = ParkingOrientation.values().map { it.asItem(requireContext(), element.tags["parking"]) }
override val itemsPerRow = 3

override fun onClickOk(selectedItems: List<ParkingOrientation>) {
applyAnswer(selectedItems.single())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package de.westnordost.streetcomplete.quests.parking_orientation

import android.content.Context
import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.osm.street_parking.ParkingOrientation
import de.westnordost.streetcomplete.osm.street_parking.ParkingOrientation.DIAGONAL
import de.westnordost.streetcomplete.osm.street_parking.ParkingOrientation.PARALLEL
import de.westnordost.streetcomplete.osm.street_parking.ParkingOrientation.PERPENDICULAR
import de.westnordost.streetcomplete.osm.street_parking.StreetParkingDrawable
import de.westnordost.streetcomplete.util.ktx.asBitmapDrawable
import de.westnordost.streetcomplete.view.DrawableImage
import de.westnordost.streetcomplete.view.ResText
import de.westnordost.streetcomplete.view.image_select.Item2
import de.westnordost.streetcomplete.osm.street_parking.ParkingOrientation.DIAGONAL as DISPLAY_DIAGONAL
import de.westnordost.streetcomplete.osm.street_parking.ParkingOrientation.PARALLEL as DISPLAY_PARALLEL
import de.westnordost.streetcomplete.osm.street_parking.ParkingOrientation.PERPENDICULAR as DISPLAY_PERPENDICULAR
import de.westnordost.streetcomplete.osm.street_parking.ParkingPosition.HALF_ON_STREET as DISPLAY_HALF_ON_STREET
import de.westnordost.streetcomplete.osm.street_parking.ParkingPosition.OFF_STREET as DISPLAY_OFF_STREET
import de.westnordost.streetcomplete.osm.street_parking.ParkingPosition.ON_STREET as DISPLAY_ON_STREET
import de.westnordost.streetcomplete.osm.street_parking.ParkingPosition.STREET_SIDE as DISPLAY_STREET_SIDE

fun ParkingOrientation.asItem(context: Context, parkingTagValue: String?): Item2<ParkingOrientation> {
val orientationDisplayVal = when (this) {
PARALLEL -> DISPLAY_PARALLEL
DIAGONAL -> DISPLAY_DIAGONAL
PERPENDICULAR -> DISPLAY_PERPENDICULAR
}
val positionDisplayVal = when (parkingTagValue) {
"street_side" -> DISPLAY_STREET_SIDE
"on_kerb" -> DISPLAY_OFF_STREET
"half_on_kerb" -> DISPLAY_HALF_ON_STREET
else -> DISPLAY_ON_STREET
}
val drawable = DrawableImage(StreetParkingDrawable(context, orientationDisplayVal, positionDisplayVal, false, 128, 128, R.drawable.ic_car1).asBitmapDrawable(context.resources))
return Item2(this, drawable, ResText(titleResId), null)
}
private val ParkingOrientation.titleResId: Int get() = when (this) {
PARALLEL -> R.string.street_parking_parallel
DIAGONAL -> R.string.street_parking_diagonal
PERPENDICULAR -> R.string.street_parking_perpendicular
}

val ParkingOrientation.osmValue get() = when (this) {
PARALLEL -> "parallel"
DIAGONAL -> "diagonal"
PERPENDICULAR -> "perpendicular"
}
46 changes: 46 additions & 0 deletions app/src/main/res/drawable/ic_car.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="106dp"
android:height="100dp"
android:viewportWidth="106"
android:viewportHeight="100">
<path
android:fillColor="#FF000000"
android:pathData="m52.95,8.37c-10.07,0 -20.15,0.72 -25.9,2.16 -8.2,2.05 -12.1,18.12 -13.61,26.53 -0.65,-0.39 -1.41,-0.63 -2.22,-0.63l-5.75,0c-2.39,0 -4.32,1.93 -4.32,4.32 0,2.39 1.93,4.32 4.32,4.32l3.21,0c-1.76,3.41 -1.77,8.63 -1.77,8.63l0,37.41c0,3.18 2.58,5.75 5.75,5.75l8.63,0c3.18,0 5.76,-2.58 5.76,-5.75l0,-1.16c7.81,1.15 15.29,1.16 25.9,1.16 10.61,0 18.09,-0.01 25.9,-1.16l0,1.16c0,3.18 2.58,5.75 5.76,5.75l8.63,0c3.18,0 5.75,-2.58 5.75,-5.75l0,-37.41c0,-4.26 -0.79,-6.94 -1.79,-8.63l3.22,0c2.38,0 4.32,-1.93 4.32,-4.32 0,-2.39 -1.94,-4.32 -4.32,-4.32l-5.75,0c-0.82,0 -1.57,0.24 -2.22,0.63 -1.5,-8.42 -5.41,-24.48 -13.61,-26.53 -5.76,-1.44 -15.83,-2.16 -25.9,-2.16z"
android:fillAlpha="0.2"/>
<path
android:pathData="M98.93,86.79C98.93,89.97 96.35,92.54 93.17,92.54l-8.63,-0c-3.18,-0 -5.76,-2.58 -5.76,-5.76l0,-23.02c0,-3.18 2.58,-5.76 5.76,-5.76l8.63,-0c3.18,-0 5.76,2.58 5.76,5.76z"
android:fillColor="#555555"/>
<path
android:pathData="M26.98,86.79C26.98,89.97 24.4,92.54 21.22,92.54L12.59,92.54C9.41,92.54 6.84,89.97 6.84,86.79l0,-23.02c0,-3.18 2.58,-5.76 5.76,-5.76l8.63,-0c3.18,-0 5.76,2.58 5.76,5.76z"
android:fillColor="#555555"/>
<path
android:pathData="m78.78,6.21c11.17,2.79 14.39,31.66 14.39,31.66 0,-0 5.76,-0 5.76,11.51L98.93,72.4C98.93,72.4 98.58,81.12 87.41,83.91 75.9,86.79 67.27,86.79 52.88,86.79 38.49,86.79 29.86,86.79 18.35,83.91 7.18,81.12 6.84,72.4 6.84,72.4l0,-23.02c0,-0 0,-11.51 5.76,-11.51 0,-0 3.22,-28.86 14.39,-31.66 11.51,-2.88 40.29,-2.88 51.8,-0z"
android:fillColor="#3b88c3"/>
<path
android:pathData="m52.88,34.99c11.24,-0 24.82,0.58 34.53,1.62L84.54,20.6C81.66,11.97 64.39,11.97 52.88,11.97 41.37,11.97 24.1,11.97 21.22,20.6L18.35,36.61C28.07,35.56 41.64,34.99 52.88,34.99"
android:fillColor="#bbddf5"/>
<path
android:pathData="m11.15,40.74l-5.76,-0C3.01,40.74 1.08,38.81 1.08,36.43 1.08,34.04 3.01,32.11 5.4,32.11l5.76,-0C13.54,32.11 15.47,34.04 15.47,36.43 15.47,38.81 13.54,40.74 11.15,40.74Z"
android:fillColor="#3b88c3"/>
<path
android:pathData="m94.61,40.74l5.76,-0c2.38,-0 4.32,-1.93 4.32,-4.32 0,-2.39 -1.93,-4.32 -4.32,-4.32l-5.76,-0C92.23,32.11 90.29,34.04 90.29,36.43 90.29,38.81 92.23,40.74 94.61,40.74Z"
android:fillColor="#3b88c3"/>
<path
android:pathData="M32.74,58.01C32.74,62.78 28.87,66.64 24.1,66.64L21.22,66.64c-4.77,-0 -8.63,-3.86 -8.63,-8.63 0,-4.77 3.86,-8.63 8.63,-8.63l2.88,-0c4.77,-0 8.63,3.86 8.63,8.63"
android:fillColor="#ffffff"/>
<path
android:pathData="m93.17,58.01c0,4.77 -3.87,8.63 -8.63,8.63l-2.88,-0c-4.77,-0 -8.63,-3.86 -8.63,-8.63 0,-4.77 3.87,-8.63 8.63,-8.63l2.88,-0c4.77,-0 8.63,3.86 8.63,8.63"
android:fillColor="#ffffff"/>
<path
android:pathData="m15.22,49.03c8.1,-4.01 20.88,0.21 21.01,0.25 1.51,0.51 3.14,-0.3 3.65,-1.81 0.51,-1.51 -0.29,-3.13 -1.8,-3.64 -0.61,-0.21 -15.15,-5.03 -25.4,0.04 -1.42,0.71 -2.01,2.43 -1.31,3.86 0.26,0.53 0.67,0.94 1.14,1.22 0.81,0.46 1.82,0.53 2.72,0.09z"
android:fillColor="#226699"/>
<path
android:pathData="m94.39,47.72c0.7,-1.43 0.12,-3.15 -1.31,-3.86 -10.25,-5.07 -24.79,-0.25 -25.4,-0.04 -1.5,0.51 -2.31,2.14 -1.8,3.64 0.5,1.51 2.14,2.31 3.64,1.81 0.13,-0.04 12.9,-4.26 21.01,-0.25 0.89,0.44 1.91,0.38 2.72,-0.09 0.47,-0.27 0.88,-0.69 1.14,-1.22z"
android:fillColor="#226699"/>
<path
android:pathData="m13.43,71.56c-1.13,-1.13 -1.13,-2.94 0,-4.07 0.99,-0.99 2.52,-1.11 3.65,-0.35C17.75,67.42 23.66,69.52 52.88,69.52c29.22,-0 35.13,-2.1 35.8,-2.39 1.13,-0.76 2.65,-0.64 3.65,0.35 1.13,1.13 1.13,2.94 0,4.07C89.25,74.63 69.18,75.28 52.88,75.28 36.58,75.28 16.51,74.63 13.43,71.56Z"
android:fillColor="#55acee"/>
<path
android:pathData="M52.88,83.91C41.75,83.91 32.74,81.03 32.74,76.72 32.74,74.33 41.75,75.28 52.88,75.28 64.01,75.28 73.03,74.33 73.03,76.72 73.03,81.03 64.01,83.91 52.88,83.91Z"
android:fillColor="#226699"/>
</vector>
29 changes: 29 additions & 0 deletions app/src/main/res/drawable/ic_quest_parking_capacity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="128dp"
android:height="128dp"
android:viewportWidth="128"
android:viewportHeight="128">

<path
android:fillColor="#fd5"
android:strokeWidth=".2"
android:pathData="M128 64c0 35.346-28.654 64-64 64-35.346 0-64-28.654-64-64 0-35.346 28.654-64 64-64 35.346 0 64 28.654 64 64" />
<path
android:strokeColor="#000"
android:strokeAlpha=".2"
android:strokeWidth="8"
android:pathData="M36.222 24h55.056c4.6935 0 8.472 3.7785 8.472 8.472v63.056c0 4.6935-3.7785 8.472-8.472 8.472h-55.056c-4.6935 0-8.472-3.7785-8.472-8.472v-63.056c0-4.6935 3.7785-8.472 8.472-8.472z" />
<path
android:fillColor="#495aad"
android:strokeColor="#fff"
android:strokeAlpha=".98995"
android:strokeWidth="8"
android:pathData="M36.347 20.111h55.056c4.6935 0 8.472 3.7785 8.472 8.472v63.056c0 4.6935-3.7785 8.472-8.472 8.472h-55.056c-4.6935 0-8.472-3.7785-8.472-8.472v-63.056c0-4.6935 3.7785-8.472 8.472-8.472z" />
<path
android:fillColor="#ffffff"
android:pathData="M 53.361546,28.366678 c -4.0013,2 -5.0013,12 -5.0013,12 -2.1206,0.55846 -5.0395,2.2998 -5.0404,4.0781 l 0.0391,3.9219 c 0.002,2 1.0013,3 4.0013,3 v 5 c 0,0 -0.27444,1.9473 1,2 h 5 c 1.2503,0 1,-2 1,-2 v -4 h 18 v 4 c 0,0 -0.24382,2 1.0065,2 h 5.0013 c 1.2503,0 0.99218,-2 0.99218,-2 v -5 c 3,0 4,-1 4.0091,-3 v -4 c -0.54462,-1.8708 -3.2587,-3.4384 -5.0013,-4 0,0 -1.0078,-10 -5.0013,-12 z m 17.505,4 c 2.5007,3 2.5007,8 2.5007,8 h -20.005 c 0,0 0,-5 2.5007,-8 z" />
<path
android:fillColor="#ffffff"
android:pathData="M 53.361546,62.366678 c -4.0013,2 -5.0013,12 -5.0013,12 -2.1206,0.55846 -5.0395,2.2998 -5.0404,4.0781 l 0.0391,3.9219 c 0.002,2 1.0013,3 4.0013,3 v 5 c 0,0 -0.27444,1.9473 1,2 h 5 c 1.2503,0 1,-2 1,-2 v -4 h 18 v 4 c 0,0 -0.24382,2 1.0065,2 h 5.0013 c 1.2503,0 0.99218,-2 0.99218,-2 v -5 c 3,0 4,-1 4.0091,-3 v -4 c -0.54462,-1.8708 -3.2587,-3.4384 -5.0013,-4 0,0 -1.0078,-10 -5.0013,-12 z m 17.505,4 c 2.5007,3 2.5007,8 2.5007,8 h -20.005 c 0,0 0,-5 2.5007,-8 z" />
</vector>
Loading

0 comments on commit 2cc88a3

Please sign in to comment.