Skip to content

Commit

Permalink
Defibrillator Location (Issue #2146) (#5328)
Browse files Browse the repository at this point in the history
  • Loading branch information
qugebert authored Oct 22, 2023
1 parent f5337e0 commit 97276b9
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import de.westnordost.streetcomplete.quests.crossing_island.AddCrossingIsland
import de.westnordost.streetcomplete.quests.crossing_kerb_height.AddCrossingKerbHeight
import de.westnordost.streetcomplete.quests.crossing_type.AddCrossingType
import de.westnordost.streetcomplete.quests.cycleway.AddCycleway
import de.westnordost.streetcomplete.quests.defibrillator.AddDefibrillatorLocation
import de.westnordost.streetcomplete.quests.diet_type.AddHalal
import de.westnordost.streetcomplete.quests.diet_type.AddKosher
import de.westnordost.streetcomplete.quests.diet_type.AddVegan
Expand Down Expand Up @@ -446,6 +447,7 @@ fun questTypeRegistry(
112 to AddWheelchairAccessPublicTransport(), // need to look out for lifts etc, maybe even enter the station

113 to AddIsAmenityIndoor(getFeature), // need to go inside in case it is inside (or gone)
161 to AddDefibrillatorLocation(), // need to go inside in case it is inside (or gone)

// inside camping sites
114 to AddCampType(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package de.westnordost.streetcomplete.quests.defibrillator

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

class AddDefibrillatorLocation : OsmFilterQuestType<String>() {

override val elementFilter = """
nodes with
emergency = defibrillator
and !location and !defibrillator:location
and access !~ private|no"
"""
override val changesetComment = "Specify defibrillator location"
override val wikiLink = "Tag:emergency=defibrillator"
override val icon = R.drawable.ic_quest_defibrillator
override val isDeleteElementEnabled = false
override val achievements = listOf(LIFESAVER)

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

override fun getHighlightedElements(element: Element, getMapData: () -> MapDataWithGeometry) =
getMapData().filter("nodes with emergency = defibrillator")

override fun createForm() = AddDefibrillatorLocationForm()

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

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

class AddDefibrillatorLocationForm : AbstractOsmQuestForm<String>() {

override val contentLayoutResId = R.layout.quest_location
private val binding by contentViewBinding(QuestLocationBinding::bind)

private val location get() = binding.locationInput.nonBlankTextOrNull

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

override fun onClickOk() {
applyAnswer(location!!)
}

override fun isFormComplete() = location != null
}
24 changes: 24 additions & 0 deletions app/src/main/res/layout/quest_location.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingStart="24dp"
android:paddingEnd="24dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/quest_defibrillator_location_description"
android:labelFor="@+id/commentInput"/>

<EditText xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/locationInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine|textCapSentences"
android:minLines="3"
android:maxLength="253"
android:background="@drawable/background_edittext_outline"
/>
</LinearLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,8 @@ Before uploading your changes, the app checks with a &lt;a href=\"https://www.we
<string name="quest_internet_access_no">No connection</string>

<string name="quest_is_amenity_inside_title">Is this inside a building?</string>
<string name="quest_defibrillator_location">Where is this defibrillator located?</string>
<string name="quest_defibrillator_location_description">"Please provide a concise description of its position (e.g. \"in the porter's lounge\")."</string>

<string name="quest_kerb_height_title">What’s the height of this curb?</string>
<string name="quest_kerb_height_flush">Same level as road surface</string>
Expand Down

0 comments on commit 97276b9

Please sign in to comment.