Skip to content

Commit

Permalink
add steps incline quest (fixes #1817)
Browse files Browse the repository at this point in the history
  • Loading branch information
westnordost committed Sep 26, 2020
1 parent 2dfb419 commit 4578c2c
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import de.westnordost.streetcomplete.quests.segregated.AddCyclewaySegregation
import de.westnordost.streetcomplete.quests.self_service.AddSelfServiceLaundry
import de.westnordost.streetcomplete.quests.sidewalk.AddSidewalk
import de.westnordost.streetcomplete.quests.sport.AddSport
import de.westnordost.streetcomplete.quests.steps_incline.AddStepsIncline
import de.westnordost.streetcomplete.quests.surface.*
import de.westnordost.streetcomplete.quests.tactile_paving.AddTactilePavingBusStop
import de.westnordost.streetcomplete.quests.tactile_paving.AddTactilePavingCrosswalk
Expand Down Expand Up @@ -178,6 +179,7 @@ object QuestModule
AddGeneralFee(o),
AddSelfServiceLaundry(o),
AddHandrail(o, r), // for accessibility of pedestrian routing
AddStepsIncline(o),
AddInformationToTourism(o),

// ↓ 8. defined in the wiki, but not really used by anyone yet. Just collected for
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package de.westnordost.streetcomplete.quests.steps_incline

import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder
import de.westnordost.streetcomplete.data.osm.mapdata.OverpassMapDataAndGeometryApi
import de.westnordost.streetcomplete.data.osm.osmquest.SimpleOverpassQuestType
import de.westnordost.streetcomplete.quests.steps_incline.StepsIncline.*

class AddStepsIncline(o: OverpassMapDataAndGeometryApi) : SimpleOverpassQuestType<StepsIncline>(o) {

override val tagFilters = """
ways with highway = steps
and (!indoor or indoor = no)
and area != yes
and access !~ private|no
and !incline
"""

override val commitMessage = "Add which way leads up for these steps"
override val wikiLink = "Key:incline"
override val icon = R.drawable.ic_quest_steps
override val isSplitWayEnabled = true

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

override fun createForm() = AddStepsInclineForm()

override fun applyAnswerTo(answer: StepsIncline, changes: StringMapChangesBuilder) {
changes.add("incline", when(answer) {
UP -> "up"
UP_REVERSED -> "down"
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package de.westnordost.streetcomplete.quests.steps_incline

import android.os.Bundle
import androidx.annotation.AnyThread
import android.view.View

import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.data.osm.elementgeometry.ElementPolylinesGeometry
import de.westnordost.streetcomplete.quests.AbstractQuestFormAnswerFragment
import de.westnordost.streetcomplete.quests.StreetSideRotater
import de.westnordost.streetcomplete.quests.steps_incline.StepsIncline.*
import de.westnordost.streetcomplete.view.Item
import de.westnordost.streetcomplete.view.dialogs.ImageListPickerDialog
import kotlinx.android.synthetic.main.quest_street_side_puzzle.*
import kotlinx.android.synthetic.main.view_little_compass.*

class AddStepsInclineForm : AbstractQuestFormAnswerFragment<StepsIncline>() {

override val contentLayoutResId = R.layout.quest_oneway
override val contentPadding = false

private var streetSideRotater: StreetSideRotater? = null

private var selection: StepsIncline? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

savedInstanceState?.getString(SELECTION)?.let { selection = valueOf(it) }
}

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

puzzleView.showOnlyRightSide()
puzzleView.listener = { showDirectionSelectionDialog() }

val defaultResId = R.drawable.ic_steps_incline_unknown
val defaultTitleId = R.string.quest_street_side_puzzle_select

puzzleView.setRightSideImageResource(selection?.iconResId ?: defaultResId)
puzzleView.setRightSideText(resources.getString( selection?.titleResId ?: defaultTitleId ))

streetSideRotater = StreetSideRotater(puzzleView, compassNeedleView, elementGeometry as ElementPolylinesGeometry)
}

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
selection?.let { outState.putString(SELECTION, it.name) }
}

override fun isFormComplete() = selection != null

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

@AnyThread override fun onMapOrientation(rotation: Float, tilt: Float) {
streetSideRotater?.onMapOrientation(rotation, tilt)
}

private fun showDirectionSelectionDialog() {
val ctx = context ?: return
val items = StepsIncline.values().map { it.toItem() }
ImageListPickerDialog(ctx, items, R.layout.labeled_icon_button_cell, 2) { selected ->
val dir = selected.value!!
puzzleView.replaceRightSideImageResource(dir.iconResId)
puzzleView.setRightSideText(resources.getString(dir.titleResId))
selection = dir
checkIsFormComplete()
}.show()
}

companion object {
private const val SELECTION = "selection"
}
}

private fun StepsIncline.toItem(): Item<StepsIncline> = Item(this, iconResId, titleResId)

private val StepsIncline.titleResId: Int get() = R.string.quest_steps_incline_up

private val StepsIncline.iconResId: Int get() = when(this) {
UP -> R.drawable.ic_steps_incline_up
UP_REVERSED -> R.drawable.ic_steps_incline_up_reversed
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package de.westnordost.streetcomplete.quests.steps_incline

enum class StepsIncline {
UP, UP_REVERSED
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable-night/ic_steps_incline_unknown.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="256dp" android:viewportHeight="64"
android:viewportWidth="64" android:width="256dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#e6e6e6" android:pathData="m34,19h-4c-0.5922,-3.2596 3.9754,-3.6312 3.935,-6.0951 -0.0734,-0.9014 -0.6641,-1.1186 -1.3673,-1.2108 -1.3053,0.1077 -1.7281,1.1897 -1.8474,2.2023l-4.0498,-0.501c0.3481,-3.4373 2.3296,-5.3954 5.3296,-5.3954 4,0 6,2 6,5s-3.9818,3.1536 -4,6zM30,21h4v3h-4z"/>
<path android:fillColor="#e6e6e6" android:pathData="m34,51h-4c-0.5922,-3.2596 3.9754,-3.6312 3.935,-6.0951 -0.0734,-0.9014 -0.6641,-1.1186 -1.3673,-1.2108 -1.3053,0.1077 -1.7281,1.1897 -1.8474,2.2023l-4.0498,-0.501c0.3481,-3.4373 2.3296,-5.3954 5.3296,-5.3954 4,0 6,2 6,5 0,3 -3.9818,3.1536 -4,6zM30,53h4v3h-4z"/>
</vector>
38 changes: 38 additions & 0 deletions app/src/main/res/drawable/ic_quest_steps.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="128dp"
android:height="128dp"
android:viewportWidth="128"
android:viewportHeight="128">
<path
android:pathData="m128,64c0,35.346 -28.654,64 -64,64s-64,-28.654 -64,-64 28.654,-64 64,-64 64,28.654 64,64"
android:fillColor="#529add"/>
<path
android:pathData="m39.99,120v-16h24v-16h24v-16h24"
android:strokeAlpha="0.2"
android:strokeWidth="8"
android:strokeColor="#000"/>
<path
android:pathData="m43.272,55.529c-0.068,-7.573 5.492,-11.485 13.801,-14.828 5.956,5.09 11.023,15.172 18.915,3.301m-25.983,44c6.495,-12.989 2.996,-20.279 7.068,-29.883 10.305,7.791 17.174,-0.718 14.915,17.882m-14.915,-35.3c-1.427,5.412 -0.352,12.663 0.657,18.075"
android:strokeAlpha="0.2"
android:strokeLineJoin="round"
android:strokeWidth="8"
android:strokeColor="#000"
android:strokeLineCap="round"/>
<path
android:fillColor="#000"
android:pathData="m68.699,25.265a8.548,8.548 0,0 1,-8.548 8.548,8.548 8.548,0 0,1 -8.548,-8.548 8.548,8.548 0,0 1,8.548 -8.548,8.548 8.548,0 0,1 8.548,8.548"
android:fillAlpha="0.2"/>
<path
android:pathData="m39.99,116v-16h24v-16h24v-16h24"
android:strokeWidth="8"
android:strokeColor="#fff"/>
<path
android:pathData="m68.699,21.265a8.548,8.548 0,0 1,-8.548 8.548,8.548 8.548,0 0,1 -8.548,-8.548 8.548,8.548 0,0 1,8.548 -8.548,8.548 8.548,0 0,1 8.548,8.548"
android:fillColor="#fff"/>
<path
android:pathData="m43.284,51.527c-0.068,-7.573 5.492,-11.485 13.801,-14.828 5.956,5.09 11.023,15.172 18.915,3.301m-25.983,44c6.495,-12.989 2.996,-20.279 7.068,-29.883 10.305,7.791 17.174,-0.718 14.915,17.882m-14.915,-35.3c-1.427,5.412 -0.352,12.663 0.657,18.075"
android:strokeLineJoin="round"
android:strokeWidth="8"
android:strokeColor="#fff"
android:strokeLineCap="round"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_steps_incline_unknown.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="256dp" android:viewportHeight="64"
android:viewportWidth="64" android:width="256dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#666" android:pathData="m34,19h-4c-0.5922,-3.2596 3.9754,-3.6312 3.935,-6.0951 -0.0734,-0.9014 -0.6641,-1.1186 -1.3673,-1.2108 -1.3053,0.1077 -1.7281,1.1897 -1.8474,2.2023l-4.0498,-0.501c0.3481,-3.4373 2.3296,-5.3954 5.3296,-5.3954 4,0 6,2 6,5s-3.9818,3.1536 -4,6zM30,21h4v3h-4z"/>
<path android:fillColor="#666" android:pathData="m34,51h-4c-0.5922,-3.2596 3.9754,-3.6312 3.935,-6.0951 -0.0734,-0.9014 -0.6641,-1.1186 -1.3673,-1.2108 -1.3053,0.1077 -1.7281,1.1897 -1.8474,2.2023l-4.0498,-0.501c0.3481,-3.4373 2.3296,-5.3954 5.3296,-5.3954 4,0 6,2 6,5 0,3 -3.9818,3.1536 -4,6zM30,53h4v3h-4z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_steps_incline_up.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="256dp" android:viewportHeight="64"
android:viewportWidth="64" android:width="256dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#808080" android:pathData="m0,0h64v64h-64z"/>
<path android:fillColor="#fff" android:pathData="m32,18 l-14,16h8l2,12h8l2,-12h8z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_steps_incline_up_reversed.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="256dp" android:viewportHeight="64"
android:viewportWidth="64" android:width="256dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#808080" android:pathData="m0,0h64v64h-64z"/>
<path android:fillColor="#fff" android:pathData="m32,46 l-14,-16h8l2,-12h8l2,12h8z"/>
</vector>
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 @@ -738,6 +738,8 @@ Otherwise, you can download another keyboard in the app store. Popular keyboards
<string name="quest_generalFee_title">Does it cost a fee to enter %s?</string>
<string name="quest_laundrySelfService_title">Is this laundry a self service laundry?</string>
<string name="quest_handrail_title">Do these steps have a handrail?</string>
<string name="quest_steps_incline_title">Which way leads upwards for these steps?</string>
<string name="quest_steps_incline_up">This way up</string>
<string name="quest_address_street_title">What street does the (house) number %s belong to?</string>
<string name="quest_address_street_no_named_streets">It does not belong to a named street</string>
<string name="quest_address_street_place_name_label">Place name:</string>
Expand Down

0 comments on commit 4578c2c

Please sign in to comment.