forked from streetcomplete/StreetComplete
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'mnalis-v38b1-smoothness' into mnalis-v38-smoothness
- Loading branch information
Showing
38 changed files
with
716 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
app/src/main/java/de/westnordost/streetcomplete/quests/smoothness/AddPathSmoothness.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package de.westnordost.streetcomplete.quests.smoothness | ||
|
||
import de.westnordost.streetcomplete.R | ||
import de.westnordost.streetcomplete.data.meta.ALL_ROADS | ||
import de.westnordost.streetcomplete.data.meta.ANYTHING_PAVED | ||
import de.westnordost.streetcomplete.data.meta.updateWithCheckDate | ||
import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType | ||
import de.westnordost.streetcomplete.data.osm.edits.update_tags.StringMapChangesBuilder | ||
import de.westnordost.streetcomplete.ktx.arrayOfNotNull | ||
import de.westnordost.streetcomplete.quests.surface.Surface | ||
import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.BICYCLIST | ||
import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.BLIND | ||
import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.WHEELCHAIR | ||
import de.westnordost.streetcomplete.quests.surface.asItem | ||
|
||
class AddPathSmoothness : OsmFilterQuestType<SmoothnessAnswer>() { | ||
|
||
// maybe exclude service roads? or driveways? | ||
override val elementFilter = """ | ||
ways with highway | ||
and highway ~ ${ALL_PATHS_EXCEPT_STEPS.joinToString("|")} | ||
and surface ~ ${SURFACES_FOR_SMOOTHNESS.joinToString("|")} | ||
and access !~ private|no | ||
and segregated != yes | ||
and (!conveying or conveying = no) | ||
and (!indoor or indoor = no) | ||
and !cycleway:surface and !footway:surface | ||
and ( | ||
!smoothness | ||
or smoothness older today -4 years | ||
) | ||
""" | ||
|
||
override val commitMessage = "Add path smoothness" | ||
override val wikiLink = "Key:smoothness" | ||
override val icon = R.drawable.ic_quest_path_surface_detail | ||
override val isSplitWayEnabled = true | ||
|
||
override val questTypeAchievements = listOf(BLIND, WHEELCHAIR, BICYCLIST) | ||
|
||
override fun getTitle(tags: Map<String, String>): Int { | ||
val hasName = tags.containsKey("name") | ||
val isSquare = tags["area"] == "yes" | ||
return when { | ||
hasName -> R.string.quest_smoothness_name_title | ||
isSquare -> R.string.quest_smoothness_square_title | ||
else -> R.string.quest_smoothness_path_title | ||
} | ||
} | ||
|
||
override fun getTitleArgs(tags: Map<String, String>, featureName: Lazy<String?>): Array<String> { | ||
val surface = Surface.values().find { it.osmValue == tags["surface"] }!! | ||
val surfaceString = surface.asItem().title.toString() | ||
return if (tags.containsKey("name")) | ||
arrayOf(tags["name"]!!, surfaceString) | ||
else | ||
arrayOf(surfaceString) | ||
} | ||
|
||
override fun createForm() = AddSmoothnessForm() | ||
|
||
override fun applyAnswerTo(answer: SmoothnessAnswer, changes: StringMapChangesBuilder) { | ||
when (answer) { | ||
is SmoothnessValueAnswer -> changes.updateWithCheckDate("smoothness", answer.osmValue) | ||
is WrongSurfaceAnswer -> changes.delete("surface") | ||
} | ||
} | ||
} | ||
|
||
// smoothness is not asked for steps | ||
// "pedestrian" is in here so the path answers are shown instead of road answers (which focus on cars) | ||
val ALL_PATHS_EXCEPT_STEPS = listOf("footway", "cycleway", "path", "bridleway", "pedestrian") |
70 changes: 70 additions & 0 deletions
70
app/src/main/java/de/westnordost/streetcomplete/quests/smoothness/AddRoadSmoothness.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
|
||
package de.westnordost.streetcomplete.quests.smoothness | ||
|
||
import de.westnordost.streetcomplete.R | ||
import de.westnordost.streetcomplete.data.meta.ALL_ROADS | ||
import de.westnordost.streetcomplete.data.meta.ANYTHING_PAVED | ||
import de.westnordost.streetcomplete.data.meta.updateWithCheckDate | ||
import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType | ||
import de.westnordost.streetcomplete.data.osm.edits.update_tags.StringMapChangesBuilder | ||
import de.westnordost.streetcomplete.quests.surface.Surface | ||
import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.BICYCLIST | ||
import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.BLIND | ||
import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.WHEELCHAIR | ||
import de.westnordost.streetcomplete.quests.surface.asItem | ||
|
||
class AddRoadSmoothness : OsmFilterQuestType<SmoothnessAnswer>() { | ||
|
||
// maybe exclude service roads? or driveways? | ||
override val elementFilter = """ | ||
ways with highway | ||
and highway ~ ${ALL_ROADS.joinToString("|")} | ||
and surface ~ ${SURFACES_FOR_SMOOTHNESS.joinToString("|")} | ||
and access !~ private|no | ||
and ( | ||
!smoothness | ||
or smoothness older today -4 years | ||
) | ||
""" | ||
|
||
override val commitMessage = "Add road smoothness" | ||
override val wikiLink = "Key:smoothness" | ||
override val icon = R.drawable.ic_quest_street_surface_detail | ||
override val isSplitWayEnabled = true | ||
|
||
override val questTypeAchievements = listOf(BLIND, WHEELCHAIR, BICYCLIST) | ||
|
||
override fun getTitle(tags: Map<String, String>): Int { | ||
val hasName = tags.containsKey("name") | ||
val isSquare = tags["area"] == "yes" | ||
return when { | ||
hasName -> R.string.quest_smoothness_name_title | ||
isSquare -> R.string.quest_smoothness_square_title | ||
else -> R.string.quest_smoothness_road_title | ||
} | ||
} | ||
|
||
override fun getTitleArgs(tags: Map<String, String>, featureName: Lazy<String?>): Array<String> { | ||
val surface = Surface.values().find { it.osmValue == tags["surface"] }!! | ||
val surfaceString = surface.asItem().title.toString() | ||
return if (tags.containsKey("name")) | ||
arrayOf(tags["name"]!!, surfaceString) | ||
else | ||
arrayOf(surfaceString) | ||
} | ||
|
||
override fun createForm() = AddSmoothnessForm() | ||
|
||
override fun applyAnswerTo(answer: SmoothnessAnswer, changes: StringMapChangesBuilder) { | ||
when (answer) { | ||
is SmoothnessValueAnswer -> changes.updateWithCheckDate("smoothness", answer.osmValue) | ||
is WrongSurfaceAnswer -> changes.delete("surface") | ||
} | ||
} | ||
} | ||
|
||
// surfaces that are actually used in AddSmoothnessForm | ||
// should only contain values that are in the Surface class | ||
val SURFACES_FOR_SMOOTHNESS = listOf( | ||
"asphalt", "sett", "paving_stones", "compacted", "gravel" | ||
) |
65 changes: 65 additions & 0 deletions
65
app/src/main/java/de/westnordost/streetcomplete/quests/smoothness/AddSmoothnessForm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package de.westnordost.streetcomplete.quests.smoothness | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import androidx.appcompat.app.AlertDialog | ||
import de.westnordost.streetcomplete.R | ||
import de.westnordost.streetcomplete.quests.AImageListQuestAnswerFragment | ||
import de.westnordost.streetcomplete.quests.AnswerItem | ||
import de.westnordost.streetcomplete.quests.surface.Surface | ||
import de.westnordost.streetcomplete.quests.surface.asItem | ||
import de.westnordost.streetcomplete.view.image_select.Item | ||
import de.westnordost.streetcomplete.view.image_select.ItemViewHolder | ||
|
||
class AddSmoothnessForm : AImageListQuestAnswerFragment<Smoothness, SmoothnessAnswer>() { | ||
|
||
override val otherAnswers = listOf( | ||
AnswerItem(R.string.quest_smoothness_wrong_surface) { surfaceWrong() }, | ||
AnswerItem(R.string.quest_smoothness_obstacle) { showObstacleHint() } | ||
) | ||
|
||
private val surfaceTag get() = osmElement!!.tags["surface"] | ||
|
||
private val highwayTag get() = osmElement!!.tags["highway"] | ||
|
||
override val items get() = Smoothness.values().toItems(surfaceTag!!, highwayTag!!) | ||
|
||
override val itemsPerRow = 1 | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
imageSelector.cellLayoutId = R.layout.cell_labeled_icon_select_smoothness | ||
} | ||
|
||
override val moveFavoritesToFront = false | ||
|
||
override fun onClickOk(selectedItems: List<Smoothness>) { | ||
applyAnswer(SmoothnessValueAnswer(selectedItems.single().osmValue)) | ||
} | ||
|
||
private fun showObstacleHint() { | ||
activity?.let { AlertDialog.Builder(it) | ||
.setMessage(R.string.quest_smoothness_obstacle_hint) | ||
.setPositiveButton(android.R.string.ok, null) | ||
.show() | ||
} | ||
} | ||
|
||
private fun surfaceWrong() { | ||
val surfaceType = Surface.values().find { it.osmValue == surfaceTag }!! | ||
showWrongSurfaceDialog(surfaceType) | ||
} | ||
|
||
private fun showWrongSurfaceDialog(surface: Surface) { | ||
val inflater = LayoutInflater.from(requireContext()) | ||
val inner = inflater.inflate(R.layout.dialog_quest_smoothness_wrong_surface, null, false) | ||
ItemViewHolder(inner.findViewById(R.id.item_view)).bind(surface.asItem()) | ||
|
||
AlertDialog.Builder(requireContext()) | ||
.setView(inner) | ||
.setPositiveButton(R.string.quest_generic_hasFeature_yes_leave_note) { _, _ -> composeNote() } | ||
.setNegativeButton(R.string.quest_generic_hasFeature_no) { _, _ -> applyAnswer(WrongSurfaceAnswer) } | ||
.show() | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/de/westnordost/streetcomplete/quests/smoothness/Smoothness.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package de.westnordost.streetcomplete.quests.smoothness | ||
|
||
enum class Smoothness(val osmValue: String) { | ||
EXCELLENT("excellent"), | ||
GOOD("good"), | ||
INTERMEDIATE("intermediate"), | ||
BAD("bad"), | ||
VERY_BAD("very_bad"), | ||
HORRIBLE("horrible"), | ||
VERY_HORRIBLE("very_horrible"), | ||
IMPASSABLE("impassable"), | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/de/westnordost/streetcomplete/quests/smoothness/SmoothnessAnswer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package de.westnordost.streetcomplete.quests.smoothness | ||
|
||
sealed class SmoothnessAnswer | ||
|
||
data class SmoothnessValueAnswer(val osmValue: String): SmoothnessAnswer() | ||
|
||
object WrongSurfaceAnswer: SmoothnessAnswer() |
125 changes: 125 additions & 0 deletions
125
app/src/main/java/de/westnordost/streetcomplete/quests/smoothness/SmoothnessItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package de.westnordost.streetcomplete.quests.smoothness | ||
|
||
import de.westnordost.streetcomplete.R | ||
import de.westnordost.streetcomplete.quests.smoothness.Smoothness.* | ||
import de.westnordost.streetcomplete.view.image_select.Item | ||
|
||
fun Array<Smoothness>.toItems(surface: String, highway: String) = this.mapNotNull { it.asItem(surface, highway) } | ||
|
||
// return null if not a valid combination | ||
fun Smoothness.asItem(surface: String, highway: String): Item<Smoothness>? { | ||
val imageResId = getImageResId(surface) ?: return null | ||
val descriptionResId = getDescriptionResId(surface, highway) ?: return null | ||
return Item(this, imageResId, getTitleResId(), descriptionResId) | ||
} | ||
|
||
fun Smoothness.getTitleResId() = when (this) { | ||
EXCELLENT -> R.string.quest_smoothness_title_excellent | ||
GOOD -> R.string.quest_smoothness_title_good | ||
INTERMEDIATE -> R.string.quest_smoothness_title_intermediate | ||
BAD -> R.string.quest_smoothness_title_bad | ||
VERY_BAD -> R.string.quest_smoothness_title_very_bad | ||
HORRIBLE -> R.string.quest_smoothness_title_horrible | ||
VERY_HORRIBLE -> R.string.quest_smoothness_title_very_horrible | ||
IMPASSABLE -> R.string.quest_smoothness_title_impassable | ||
} | ||
|
||
fun Smoothness.getDescriptionResId(surface: String, highway: String) = when (this) { | ||
EXCELLENT -> when (surface) { | ||
// no "excellent" for roads with paving stones | ||
"paving_stones" -> R.string.quest_smoothness_description_excellent_paving_stones | ||
"asphalt" -> R.string.quest_smoothness_description_excellent | ||
else -> null | ||
} | ||
GOOD -> when (surface) { | ||
"paving_stones" -> R.string.quest_smoothness_description_good_paving_stones | ||
"sett" -> R.string.quest_smoothness_description_good_sett | ||
"asphalt" -> R.string.quest_smoothness_description_good | ||
else -> null | ||
} | ||
INTERMEDIATE -> when (surface) { | ||
"paving_stones" -> R.string.quest_smoothness_description_intermediate_paving_stones | ||
"sett" -> R.string.quest_smoothness_description_intermediate_sett | ||
"compacted", "gravel" -> R.string.quest_smoothness_description_intermediate_compacted_gravel | ||
"asphalt" -> when (highway) { | ||
in ALL_PATHS_EXCEPT_STEPS -> R.string.quest_smoothness_description_intermediate_path | ||
else -> R.string.quest_smoothness_description_intermediate_road | ||
} | ||
else -> null | ||
} | ||
BAD -> when (surface) { | ||
"sett" -> R.string.quest_smoothness_description_bad_sett | ||
"paving_stones" -> R.string.quest_smoothness_description_bad_paving_stones | ||
"asphalt", "compacted", "gravel" -> when (highway) { | ||
in ALL_PATHS_EXCEPT_STEPS -> R.string.quest_smoothness_description_bad_path | ||
else -> R.string.quest_smoothness_description_bad_road | ||
} | ||
else -> null | ||
} | ||
VERY_BAD -> when (surface) { | ||
"sett" -> R.string.quest_smoothness_description_very_bad_sett | ||
else -> when (highway) { | ||
in ALL_PATHS_EXCEPT_STEPS -> R.string.quest_smoothness_description_very_bad_path | ||
else -> R.string.quest_smoothness_description_very_bad_road | ||
} | ||
} | ||
// split up? | ||
HORRIBLE -> R.string.quest_smoothness_description_horrible | ||
VERY_HORRIBLE -> R.string.quest_smoothness_description_very_horrible | ||
IMPASSABLE -> R.string.quest_smoothness_description_impassable | ||
} | ||
|
||
// should contain all surfaces in AddRoadSmoothness.SURFACES_FOR_SMOOTHNESS | ||
fun Smoothness.getImageResId(surface: String): Int? = when(surface) { | ||
"asphalt" -> getAsphaltImageResId() | ||
"sett" -> getSettImageResId() | ||
"paving_stones" -> getPavingStonesImageResId() | ||
"compacted" -> getCompactedImageResId() | ||
"gravel" -> getGravelImageResId() | ||
else -> throw IllegalStateException() | ||
} | ||
|
||
fun Smoothness.getAsphaltImageResId() = when (this) { | ||
EXCELLENT -> R.drawable.surface_asphalt_excellent | ||
GOOD -> R.drawable.surface_asphalt_good | ||
INTERMEDIATE -> R.drawable.surface_asphalt_intermediate | ||
BAD -> R.drawable.surface_asphalt_bad | ||
VERY_BAD -> R.drawable.surface_asphalt_very_bad | ||
else -> null | ||
} | ||
|
||
fun Smoothness.getSettImageResId() = when (this) { | ||
GOOD -> R.drawable.surface_sett_good | ||
INTERMEDIATE -> R.drawable.surface_sett_intermediate | ||
BAD -> R.drawable.surface_sett_bad | ||
VERY_BAD -> R.drawable.surface_sett_very_bad | ||
else -> null | ||
} | ||
|
||
fun Smoothness.getPavingStonesImageResId() = when (this) { | ||
EXCELLENT -> R.drawable.surface_paving_stones_excellent | ||
GOOD -> R.drawable.surface_paving_stones_good | ||
INTERMEDIATE -> R.drawable.surface_paving_stones_intermediate | ||
BAD -> R.drawable.surface_paving_stones_bad | ||
else -> null | ||
} | ||
|
||
fun Smoothness.getCompactedImageResId() = when (this) { | ||
INTERMEDIATE -> R.drawable.surface_compacted_intermediate | ||
BAD -> R.drawable.surface_compacted_bad | ||
VERY_BAD -> R.drawable.surface_compacted_very_bad | ||
HORRIBLE -> R.drawable.surface_unpaved_horrible | ||
VERY_HORRIBLE -> R.drawable.surface_unpaved_very_horrible | ||
IMPASSABLE -> R.drawable.surface_unpaved_impassable | ||
else -> null | ||
} | ||
|
||
fun Smoothness.getGravelImageResId() = when (this) { | ||
INTERMEDIATE -> R.drawable.surface_gravel_intermediate | ||
BAD -> R.drawable.surface_gravel_bad | ||
VERY_BAD -> R.drawable.surface_gravel_very_bad | ||
HORRIBLE -> R.drawable.surface_gravel_horrible | ||
VERY_HORRIBLE -> R.drawable.surface_unpaved_very_horrible | ||
IMPASSABLE -> R.drawable.surface_unpaved_impassable | ||
else -> null | ||
} |
Oops, something went wrong.