forked from streetcomplete/StreetComplete
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
345 additions
and
0 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
36 changes: 36 additions & 0 deletions
36
...src/main/java/de/westnordost/streetcomplete/quests/trail_visibility/AddTrailVisibility.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,36 @@ | ||
package de.westnordost.streetcomplete.quests.trail_visibility | ||
|
||
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.osm.Tags | ||
|
||
class AddTrailVisibility : OsmFilterQuestType<TrailVisibility>() { | ||
|
||
override val elementFilter = """ | ||
ways with | ||
highway ~ path|footway|cycleway|bridleway | ||
and !trail_visibility | ||
and (sac_scale and sac_scale != hiking) | ||
and (!lit or lit = no) | ||
and surface ~ "ground|earth|dirt|soil|grass|sand|mud|ice|salt|snow|rock|stone" | ||
""" | ||
override val changesetComment = "Specify Trail Visibility" | ||
override val wikiLink = "Key:trail_visibility" | ||
override val icon = R.drawable.ic_quest_trail_visibility | ||
override val defaultDisabledMessage = R.string.default_disabled_msg_trail_visibility | ||
|
||
override fun getTitle(tags: Map<String, String>) = R.string.quest_trail_visibility_title | ||
|
||
override fun getHighlightedElements(element: Element, getMapData: () -> MapDataWithGeometry) = | ||
getMapData().filter("ways with highway and trail_visibility") | ||
|
||
override fun createForm() = AddTrailVisibilityForm() | ||
|
||
override fun applyAnswerTo(answer: TrailVisibility, tags: Tags, geometry: ElementGeometry, timestampEdited: Long) { | ||
tags["trail_visibility"] = answer.osmValue | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...main/java/de/westnordost/streetcomplete/quests/trail_visibility/AddTrailVisibilityForm.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,30 @@ | ||
package de.westnordost.streetcomplete.quests.trail_visibility | ||
|
||
import android.os.Bundle | ||
import de.westnordost.streetcomplete.R | ||
import de.westnordost.streetcomplete.quests.AImageListQuestForm | ||
import de.westnordost.streetcomplete.view.image_select.DisplayItem | ||
|
||
class AddTrailVisibilityForm : AImageListQuestForm<TrailVisibility, TrailVisibility>() { | ||
|
||
override val items: List<DisplayItem<TrailVisibility>> get() = listOf( | ||
TrailVisibility.EXCELLENT, | ||
TrailVisibility.GOOD, | ||
TrailVisibility.INTERMEDIATE, | ||
TrailVisibility.BAD, | ||
TrailVisibility.HORRIBLE, | ||
TrailVisibility.NO | ||
).toItems() | ||
|
||
override val itemsPerRow = 2 | ||
override val moveFavoritesToFront = false | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
imageSelector.cellLayoutId = R.layout.cell_labeled_icon_select_trail_visibility | ||
} | ||
|
||
override fun onClickOk(selectedItems: List<TrailVisibility>) { | ||
applyAnswer(selectedItems.first()) | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
app/src/main/java/de/westnordost/streetcomplete/quests/trail_visibility/TrailVisibility.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,39 @@ | ||
package de.westnordost.streetcomplete.quests.trail_visibility | ||
|
||
import de.westnordost.streetcomplete.R | ||
import de.westnordost.streetcomplete.quests.trail_visibility.TrailVisibility.* | ||
import de.westnordost.streetcomplete.view.image_select.GroupableDisplayItem | ||
import de.westnordost.streetcomplete.view.image_select.Item | ||
|
||
enum class TrailVisibility(val osmValue: String) { | ||
EXCELLENT("excellent"), | ||
GOOD("good"), | ||
INTERMEDIATE("intermediate"), | ||
BAD("bad"), | ||
HORRIBLE("horrible"), | ||
NO("no") | ||
} | ||
fun Collection<TrailVisibility>.toItems() = map { it.asItem() } | ||
|
||
fun TrailVisibility.asItem(): GroupableDisplayItem<TrailVisibility> { | ||
return Item(this, titleId = titleResId, descriptionId = descriptionResId) | ||
} | ||
|
||
private val TrailVisibility.titleResId: Int get() = when (this) { | ||
EXCELLENT -> R.string.quest_trail_visibility_excellent | ||
GOOD -> R.string.quest_trail_visibility_good | ||
INTERMEDIATE -> R.string.quest_trail_visibility_intermediate | ||
BAD -> R.string.quest_trail_visibility_bad | ||
HORRIBLE -> R.string.quest_trail_visibility_horrible | ||
NO -> R.string.quest_trail_visibility_no | ||
} | ||
|
||
private val TrailVisibility.descriptionResId: Int? get() = when (this) { | ||
EXCELLENT -> R.string.quest_trail_visibility_excellent_description | ||
GOOD -> R.string.quest_trail_visibility_good_description | ||
INTERMEDIATE -> R.string.quest_trail_visibility_intermediate_description | ||
BAD -> R.string.quest_trail_visibility_bad_description | ||
HORRIBLE -> R.string.quest_trail_visibility_horrible_description | ||
NO -> R.string.quest_trail_visibility_no_description | ||
else -> null | ||
} |
Oops, something went wrong.