Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import de.westnordost.streetcomplete.data.osm.mapdata.Element

/** Return whether this element is a kind of place, regardless whether it is currently vacant or
* not */
fun Element.isPlaceOrDisusedPlace(): Boolean =
isPlace() || isDisusedPlace()
fun Element.isKindOfPlace(): Boolean =
isPlace() || isDisusedPlace() || isAbandonedPlace()

/** Return whether this element is a kind of disused or vacant place */
fun Element.isDisusedPlace(): Boolean =
IS_VACANT_PLACE_EXPRESSION.matches(this) ||
this.asIfItWasnt("disused")?.let { IS_PLACE_EXPRESSION.matches(it) } == true

fun Element.isAbandonedPlace(): Boolean =
this.asIfItWasnt("abandoned")?.let { IS_PLACE_EXPRESSION.matches(it) } == true

fun Element.isPlace(): Boolean =
IS_PLACE_EXPRESSION.matches(this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import de.westnordost.streetcomplete.data.elementfilter.toElementFilterExpressio
import de.westnordost.streetcomplete.data.osm.mapdata.Element

/** Return whether this element is a kind of thing, regardless whether it is disused or not */
fun Element.isThingOrDisusedThing(): Boolean =
isThing() || isDisusedThing()
fun Element.isKindOfThing(): Boolean =
isThing() || isDisusedThing() || isAbandonedThing()

fun Element.isThing(): Boolean =
IS_THING_EXPRESSION.matches(this)

fun Element.isDisusedThing(): Boolean =
this.asIfItWasnt("disused")?.let { IS_THING_EXPRESSION.matches(it) } == true

fun Element.isAbandonedThing(): Boolean =
this.asIfItWasnt("abandoned")?.let { IS_THING_EXPRESSION.matches(it) } == true

/** Small map features that are often mapped as points and usually cannot be entered.
*
* To demarcate this category from others, the following are not included:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ data class PointStyle(
val label: String? = null,
/** color to use for the icon */
val color: String? = null,
/** night mode color for the icon */
val nightColor: String? = null,
) : Style
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry
import de.westnordost.streetcomplete.data.osm.mapdata.Node
import de.westnordost.streetcomplete.data.osm.mapdata.filter
import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement
import de.westnordost.streetcomplete.osm.asIfItWasnt
import de.westnordost.streetcomplete.osm.isAbandonedPlace
import de.westnordost.streetcomplete.osm.isDisusedPlace
import de.westnordost.streetcomplete.osm.isPlaceOrDisusedPlace
import de.westnordost.streetcomplete.osm.isKindOfPlace
import de.westnordost.streetcomplete.overlays.Color
import de.westnordost.streetcomplete.overlays.Overlay
import de.westnordost.streetcomplete.overlays.PointStyle
Expand Down Expand Up @@ -36,17 +38,25 @@ class PlacesOverlay(private val getFeature: (Element) -> Feature?) : Overlay {
override fun getStyledElements(mapData: MapDataWithGeometry) =
mapData
.asSequence()
.filter { it.isPlaceOrDisusedPlace() }
.map { element ->
// show disused places always with the icon for "disused shop" icon
val icon = getFeature(element)?.icon?.let { presetIconIndex[it] }
?: if (element.isDisusedPlace()) R.drawable.preset_fas_store_alt_slash else null
?: R.drawable.preset_maki_shop
.filter { it.isKindOfPlace() }
.mapNotNull { element ->
val feature = getFeature(element)
?: element.asIfItWasnt("disused")?.let { getFeature(it) }
?: element.asIfItWasnt("abandoned")?.let { getFeature(it) }
?: return@mapNotNull null

val icon = feature.icon?.let { presetIconIndex[it] } ?: R.drawable.preset_maki_shop

val label = getNameLabel(element.tags)

val style = if (element is Node) {
PointStyle(icon, label)
PointStyle(icon, label,
if (element.isDisusedPlace()) "#606269"
else if (element.isAbandonedPlace()) "#B06269"
else null,
if (element.isDisusedPlace()) "#aaaaaf"
else if (element.isAbandonedPlace()) "#ffaaaa"
else null)
} else {
PolygonStyle(Color.INVISIBLE, icon, label)
}
Expand All @@ -63,5 +73,5 @@ class PlacesOverlay(private val getFeature: (Element) -> Feature?) : Overlay {

override fun createForm(element: Element?) =
// this check is necessary because the form shall not be shown for entrances
if (element == null || element.isPlaceOrDisusedPlace()) PlacesOverlayForm() else null
if (element == null || element.isKindOfPlace()) PlacesOverlayForm() else null
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import de.westnordost.streetcomplete.databinding.FragmentOverlayPlacesBinding
import de.westnordost.streetcomplete.osm.POPULAR_PLACE_FEATURE_IDS
import de.westnordost.streetcomplete.osm.applyReplacePlaceTo
import de.westnordost.streetcomplete.osm.applyTo
import de.westnordost.streetcomplete.osm.asIfItWasnt
import de.westnordost.streetcomplete.osm.isDisusedPlace
import de.westnordost.streetcomplete.osm.isPlace
import de.westnordost.streetcomplete.osm.localized_name.LocalizedName
Expand Down Expand Up @@ -80,6 +81,7 @@ class PlacesOverlayForm : AbstractOverlayForm() {

return getFeatureDictionaryFeature(element)
?: if (element.isDisusedPlace()) vacantShopFeature else null
?: getAbandonedFeatureDictionaryFeature(element)
?: BaseFeature(
id = "shop/unknown",
names = listOf(requireContext().getString(R.string.unknown_shop_title)),
Expand All @@ -101,6 +103,13 @@ class PlacesOverlayForm : AbstractOverlayForm() {
).firstOrNull { it.toElement().isPlace() }
}

private fun getAbandonedFeatureDictionaryFeature(element: Element): Feature? {
val abandonedElement = element.asIfItWasnt("abandoned") ?: return null
val abandonedFeature = getFeatureDictionaryFeature(abandonedElement) ?: return null
val abandonedLabel = resources.getString(R.string.abandoned).uppercase()
return abandonedFeature.toPrefixedFeature("abandoned", abandonedLabel)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry
import de.westnordost.streetcomplete.data.osm.mapdata.Node
import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement
import de.westnordost.streetcomplete.osm.asIfItWasnt
import de.westnordost.streetcomplete.osm.isThingOrDisusedThing
import de.westnordost.streetcomplete.osm.isAbandonedPlace
import de.westnordost.streetcomplete.osm.isAbandonedThing
import de.westnordost.streetcomplete.osm.isDisusedPlace
import de.westnordost.streetcomplete.osm.isDisusedThing
import de.westnordost.streetcomplete.osm.isKindOfThing
import de.westnordost.streetcomplete.overlays.Color
import de.westnordost.streetcomplete.overlays.Overlay
import de.westnordost.streetcomplete.overlays.PointStyle
Expand All @@ -26,18 +30,23 @@ class ThingsOverlay(private val getFeature: (Element) -> Feature?) : Overlay {
override fun getStyledElements(mapData: MapDataWithGeometry) =
mapData
.asSequence()
.filter { it.isThingOrDisusedThing() }
.filter { it.isKindOfThing() }
.mapNotNull { element ->
// show disused things with the same icon as normal things because they usually look
// similar (a disused telephone booth still looks like a telephone booth, etc.)
val feature = getFeature(element)
?: element.asIfItWasnt("disused")?.let { getFeature(it) }
?: element.asIfItWasnt("abandoned")?.let { getFeature(it) }
?: return@mapNotNull null

val icon = feature.icon?.let { presetIconIndex[it] } ?: R.drawable.preset_maki_marker_stroked

val style = if (element is Node) {
PointStyle(icon)
PointStyle(icon, null,
if (element.isDisusedThing()) "#606269"
else if (element.isAbandonedThing()) "#B06269"
else null,
if (element.isDisusedThing()) "#9999AF"
else if (element.isAbandonedThing()) "#FF99AF"
else null)
} else {
PolygonStyle(Color.INVISIBLE, icon)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ThingsOverlayForm : AbstractOverlayForm() {

return getFeatureDictionaryFeature(element)
?: getDisusedFeatureDictionaryFeature(element)
?: getAbandonedFeatureDictionaryFeature(element)
?: BaseFeature(
id = "thing/unknown",
names = listOf(requireContext().getString(R.string.unknown_object)),
Expand All @@ -69,6 +70,12 @@ class ThingsOverlayForm : AbstractOverlayForm() {
val disusedLabel = resources.getString(R.string.disused).uppercase()
return disusedFeature.toPrefixedFeature("disused", disusedLabel)
}
private fun getAbandonedFeatureDictionaryFeature(element: Element): Feature? {
val abandonedElement = element.asIfItWasnt("abandoned") ?: return null
val abandonedFeature = getFeatureDictionaryFeature(abandonedElement) ?: return null
val abandonedLabel = resources.getString(R.string.abandoned).uppercase()
return abandonedFeature.toPrefixedFeature("abandoned", abandonedLabel)
}

private fun getFeatureDictionaryFeature(element: Element): Feature? {
val languages = getLanguagesForFeatureDictionary(resources.configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import de.westnordost.streetcomplete.data.quest.QuestKey
import de.westnordost.streetcomplete.data.visiblequests.HideQuestController
import de.westnordost.streetcomplete.data.visiblequests.QuestsHiddenController
import de.westnordost.streetcomplete.osm.applyReplacePlaceTo
import de.westnordost.streetcomplete.osm.isPlaceOrDisusedPlace
import de.westnordost.streetcomplete.osm.isKindOfPlace
import de.westnordost.streetcomplete.osm.ALL_PATHS
import de.westnordost.streetcomplete.osm.ALL_ROADS
import de.westnordost.streetcomplete.quests.custom.CustomQuestList
Expand Down Expand Up @@ -71,7 +71,6 @@ import kotlinx.datetime.DateTimeUnit
import kotlinx.datetime.LocalDate
import kotlinx.datetime.plus
import kotlinx.datetime.toJavaLocalDate
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.koin.android.ext.android.inject
import org.koin.core.qualifier.named
Expand Down Expand Up @@ -336,7 +335,7 @@ abstract class AbstractOsmQuestForm<T> : AbstractQuestForm(), IsShowingQuestDeta
}

protected fun replacePlace(extra: Boolean = true) {
if (element.isPlaceOrDisusedPlace()) {
if (element.isKindOfPlace()) {
ShopGoneDialog(
requireContext(),
element,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry
import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType
import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement.CITIZEN
import de.westnordost.streetcomplete.osm.Tags
import de.westnordost.streetcomplete.osm.isPlaceOrDisusedPlace
import de.westnordost.streetcomplete.osm.isKindOfPlace
import de.westnordost.streetcomplete.util.ktx.toYesNo

class AddAcceptsCards : OsmFilterQuestType<CardAcceptance>() {
Expand All @@ -34,7 +34,7 @@ class AddAcceptsCards : OsmFilterQuestType<CardAcceptance>() {
override fun getTitle(tags: Map<String, String>) = R.string.quest_accepts_cards

override fun getHighlightedElements(element: Element, getMapData: () -> MapDataWithGeometry) =
getMapData().asSequence().filter { it.isPlaceOrDisusedPlace() }
getMapData().asSequence().filter { it.isKindOfPlace() }

override fun createForm() = AddAcceptsCardsForm()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType
import de.westnordost.streetcomplete.data.quest.NoCountriesExcept
import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement.CITIZEN
import de.westnordost.streetcomplete.osm.Tags
import de.westnordost.streetcomplete.osm.isPlaceOrDisusedPlace
import de.westnordost.streetcomplete.osm.isKindOfPlace
import de.westnordost.streetcomplete.quests.YesNoQuestForm
import de.westnordost.streetcomplete.util.ktx.toYesNo

Expand Down Expand Up @@ -66,7 +66,7 @@ class AddAcceptsCash : OsmFilterQuestType<Boolean>() {
override fun getTitle(tags: Map<String, String>) = R.string.quest_accepts_cash_title2

override fun getHighlightedElements(element: Element, getMapData: () -> MapDataWithGeometry) =
getMapData().asSequence().filter { it.isPlaceOrDisusedPlace() }
getMapData().asSequence().filter { it.isKindOfPlace() }

override fun createForm() = YesNoQuestForm()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry
import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType
import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement.CITIZEN
import de.westnordost.streetcomplete.osm.Tags
import de.westnordost.streetcomplete.osm.isPlaceOrDisusedPlace
import de.westnordost.streetcomplete.osm.isKindOfPlace
import de.westnordost.streetcomplete.quests.YesNoQuestForm
import de.westnordost.streetcomplete.util.ktx.toYesNo

Expand All @@ -33,7 +33,7 @@ class AddAirConditioning : OsmFilterQuestType<Boolean>() {
override fun getTitle(tags: Map<String, String>) = R.string.quest_airConditioning_title

override fun getHighlightedElements(element: Element, getMapData: () -> MapDataWithGeometry) =
getMapData().asSequence().filter { it.isPlaceOrDisusedPlace() }
getMapData().asSequence().filter { it.isKindOfPlace() }

override fun createForm() = YesNoQuestForm()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry
import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType
import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement.BICYCLIST
import de.westnordost.streetcomplete.osm.Tags
import de.westnordost.streetcomplete.osm.isPlaceOrDisusedPlace
import de.westnordost.streetcomplete.osm.isKindOfPlace
import de.westnordost.streetcomplete.osm.updateWithCheckDate
import de.westnordost.streetcomplete.quests.YesNoQuestForm
import de.westnordost.streetcomplete.util.ktx.toYesNo
Expand All @@ -31,7 +31,7 @@ class AddBicyclePump : OsmFilterQuestType<Boolean>() {
override fun getTitle(tags: Map<String, String>) = R.string.quest_air_pump_bicycle_shop_title

override fun getHighlightedElements(element: Element, getMapData: () -> MapDataWithGeometry) =
getMapData().asSequence().filter { it.isPlaceOrDisusedPlace() }
getMapData().asSequence().filter { it.isKindOfPlace() }

override fun createForm() = YesNoQuestForm()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry
import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType
import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement.BICYCLIST
import de.westnordost.streetcomplete.osm.Tags
import de.westnordost.streetcomplete.osm.isPlaceOrDisusedPlace
import de.westnordost.streetcomplete.osm.isKindOfPlace
import de.westnordost.streetcomplete.osm.updateWithCheckDate
import de.westnordost.streetcomplete.quests.YesNoQuestForm
import de.westnordost.streetcomplete.util.ktx.toYesNo
Expand All @@ -32,7 +32,7 @@ class AddBikeRepairAvailability : OsmFilterQuestType<Boolean>() {
override fun getTitle(tags: Map<String, String>) = R.string.quest_bicycle_shop_repair_title

override fun getHighlightedElements(element: Element, getMapData: () -> MapDataWithGeometry) =
getMapData().asSequence().filter { it.isPlaceOrDisusedPlace() }
getMapData().asSequence().filter { it.isKindOfPlace() }

override fun createForm() = YesNoQuestForm()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry
import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType
import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement.BICYCLIST
import de.westnordost.streetcomplete.osm.Tags
import de.westnordost.streetcomplete.osm.isPlaceOrDisusedPlace
import de.westnordost.streetcomplete.osm.isKindOfPlace
import de.westnordost.streetcomplete.osm.updateWithCheckDate

class AddSecondHandBicycleAvailability : OsmFilterQuestType<SecondHandBicycleAvailability>() {
Expand Down Expand Up @@ -35,7 +35,7 @@ class AddSecondHandBicycleAvailability : OsmFilterQuestType<SecondHandBicycleAva
override fun getTitle(tags: Map<String, String>) = R.string.quest_bicycle_shop_second_hand_title

override fun getHighlightedElements(element: Element, getMapData: () -> MapDataWithGeometry) =
getMapData().asSequence().filter { it.isPlaceOrDisusedPlace() }
getMapData().asSequence().filter { it.isKindOfPlace() }

override fun createForm() = AddSecondHandBicycleAvailabilityForm()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry
import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType
import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement.CITIZEN
import de.westnordost.streetcomplete.osm.Tags
import de.westnordost.streetcomplete.osm.isPlaceOrDisusedPlace
import de.westnordost.streetcomplete.osm.isKindOfPlace
import de.westnordost.streetcomplete.osm.updateWithCheckDate

class AddGlutenFree : OsmFilterQuestType<DietAvailabilityAnswer>() {
Expand Down Expand Up @@ -37,7 +37,7 @@ class AddGlutenFree : OsmFilterQuestType<DietAvailabilityAnswer>() {
override fun getTitle(tags: Map<String, String>) = R.string.quest_dietType_glutenfree_name_title

override fun getHighlightedElements(element: Element, getMapData: () -> MapDataWithGeometry) =
getMapData().asSequence().filter { it.isPlaceOrDisusedPlace() }
getMapData().asSequence().filter { it.isKindOfPlace() }

override fun createForm() = AddDietTypeForm()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry
import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType
import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement.CITIZEN
import de.westnordost.streetcomplete.osm.Tags
import de.westnordost.streetcomplete.osm.isPlaceOrDisusedPlace
import de.westnordost.streetcomplete.osm.isKindOfPlace
import de.westnordost.streetcomplete.osm.updateWithCheckDate

class AddHalal : OsmFilterQuestType<DietAvailabilityAnswer>() {
Expand Down Expand Up @@ -35,7 +35,7 @@ class AddHalal : OsmFilterQuestType<DietAvailabilityAnswer>() {
override fun getTitle(tags: Map<String, String>) = R.string.quest_dietType_halal_name_title2

override fun getHighlightedElements(element: Element, getMapData: () -> MapDataWithGeometry) =
getMapData().asSequence().filter { it.isPlaceOrDisusedPlace() }
getMapData().asSequence().filter { it.isKindOfPlace() }

override fun createForm() = AddDietTypeForm()

Expand Down
Loading