Skip to content

Commit f2f2ae4

Browse files
authored
Maxspeed compose (#6758)
1 parent 76ce268 commit f2f2ae4

File tree

78 files changed

+1366
-1654
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1366
-1654
lines changed

app/src/androidMain/kotlin/de/westnordost/streetcomplete/osm/maxspeed/MaxSpeedUtils2.kt

Lines changed: 0 additions & 36 deletions
This file was deleted.

app/src/androidMain/kotlin/de/westnordost/streetcomplete/quests/QuestsModule.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,23 +206,22 @@ import org.koin.dsl.module
206206

207207
val questsModule = module {
208208
single {
209+
val countryInfos = get<CountryInfos>()
210+
val countryBoundariesLazy = get<Lazy<CountryBoundaries>>(named("CountryBoundariesLazy"))
211+
val featureDictionaryLazy = get<Lazy<FeatureDictionary>>(named("FeatureDictionaryLazy"))
209212
questTypeRegistry(
210213
get(),
211-
{ location ->
212-
val countryInfos = get<CountryInfos>()
213-
val countryBoundaries = get<Lazy<CountryBoundaries>>(named("CountryBoundariesLazy")).value
214-
countryInfos.getByLocation(countryBoundaries, location.longitude, location.latitude)
215-
},
216-
{ element ->
217-
get<Lazy<FeatureDictionary>>(named("FeatureDictionaryLazy")).value.getFeature(element)
218-
}
214+
{ countryInfos.getByLocation(countryBoundariesLazy.value, it.longitude, it.latitude) },
215+
{ countryBoundariesLazy.value.getIds(it.longitude, it.latitude).firstOrNull() },
216+
{ featureDictionaryLazy.value.getFeature(it) }
219217
)
220218
}
221219
}
222220

223221
fun questTypeRegistry(
224222
arSupportChecker: ArSupportChecker,
225223
getCountryInfoByLocation: (LatLon) -> CountryInfo,
224+
getCountryOrSubdivisionCode: (LatLon) -> String?,
226225
getFeature: (Element) -> Feature?,
227226
) = QuestTypeRegistry(listOf(
228227

@@ -562,7 +561,7 @@ fun questTypeRegistry(
562561

563562
/* should best be after road surface because it excludes unpaved roads, also, need to search
564563
* for the sign which is one reason why it is disabled by default */
565-
149 to AddMaxSpeed(),
564+
149 to AddMaxSpeed(getCountryOrSubdivisionCode),
566565

567566
// buildings
568567
150 to AddBuildingType(),

app/src/androidMain/kotlin/de/westnordost/streetcomplete/quests/max_speed/AddMaxSpeed.kt

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package de.westnordost.streetcomplete.quests.max_speed
33
import de.westnordost.streetcomplete.R
44
import de.westnordost.streetcomplete.data.osm.geometry.ElementGeometry
55
import de.westnordost.streetcomplete.data.osm.mapdata.Element
6+
import de.westnordost.streetcomplete.data.osm.mapdata.LatLon
67
import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry
78
import de.westnordost.streetcomplete.data.osm.mapdata.filter
89
import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType
9-
import de.westnordost.streetcomplete.data.quest.AllCountriesExcept
1010
import de.westnordost.streetcomplete.data.quest.AndroidQuest
1111
import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement.CAR
1212
import de.westnordost.streetcomplete.osm.Tags
@@ -15,7 +15,9 @@ import de.westnordost.streetcomplete.osm.surface.UNPAVED_SURFACES
1515
import de.westnordost.streetcomplete.resources.*
1616
import de.westnordost.streetcomplete.util.ktx.toYesNo
1717

18-
class AddMaxSpeed : OsmFilterQuestType<MaxSpeedAnswer>(), AndroidQuest {
18+
class AddMaxSpeed (
19+
private val getCountryOrSubdivisionCode: (LatLon) -> String?
20+
) : OsmFilterQuestType<MaxSpeedAnswer>(), AndroidQuest {
1921

2022
override val elementFilter = """
2123
ways with
@@ -24,6 +26,7 @@ class AddMaxSpeed : OsmFilterQuestType<MaxSpeedAnswer>(), AndroidQuest {
2426
and ${MAX_SPEED_TYPE_KEYS.joinToString(" and ") { "!$it" }}
2527
and surface !~ ${UNPAVED_SURFACES.joinToString("|")}
2628
and cyclestreet != yes and bicycle_road != yes
29+
and living_street != yes
2730
and motor_vehicle !~ private|no
2831
and vehicle !~ private|no
2932
and area != yes
@@ -34,8 +37,6 @@ class AddMaxSpeed : OsmFilterQuestType<MaxSpeedAnswer>(), AndroidQuest {
3437
override val icon = R.drawable.quest_max_speed
3538
override val title = Res.string.quest_maxspeed_title_short2
3639
override val hasMarkersAtEnds = true
37-
// see #813: US has different rules for each different state which need to be respected
38-
override val enabledInCountries = AllCountriesExcept("US")
3940
override val achievements = listOf(CAR)
4041
override val defaultDisabledMessage = Res.string.default_disabled_msg_maxspeed
4142

@@ -45,27 +46,6 @@ class AddMaxSpeed : OsmFilterQuestType<MaxSpeedAnswer>(), AndroidQuest {
4546
override fun createForm() = AddMaxSpeedForm()
4647

4748
override fun applyAnswerTo(answer: MaxSpeedAnswer, tags: Tags, geometry: ElementGeometry, timestampEdited: Long) {
48-
when (answer) {
49-
is MaxSpeedSign -> {
50-
tags["maxspeed"] = answer.value.toString()
51-
tags["maxspeed:type"] = "sign"
52-
}
53-
is MaxSpeedZone -> {
54-
tags["maxspeed"] = answer.value.toString()
55-
tags["maxspeed:type"] = answer.countryCode + ":" + answer.roadType
56-
}
57-
is AdvisorySpeedSign -> {
58-
tags["maxspeed:advisory"] = answer.value.toString()
59-
tags["maxspeed:type:advisory"] = "sign"
60-
}
61-
is IsLivingStreet -> {
62-
tags["highway"] = "living_street"
63-
}
64-
is ImplicitMaxSpeed -> {
65-
tags["maxspeed:type"] = answer.countryCode + ":" + answer.roadType
66-
// Lit is either already set or has been answered by the user, so this wouldn't change the value of the lit tag
67-
answer.lit?.let { tags["lit"] = it.toYesNo() }
68-
}
69-
}
49+
answer.applyTo(tags, getCountryOrSubdivisionCode(geometry.center) ?: "??")
7050
}
7151
}

0 commit comments

Comments
 (0)