forked from streetcomplete/StreetComplete
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
partial implementation of streetcomplete#83
- Loading branch information
1 parent
c0954cb
commit b66f4e8
Showing
6 changed files
with
74 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
34 changes: 34 additions & 0 deletions
34
app/src/main/java/de/westnordost/streetcomplete/quests/leaf_detail/AddTreeLeafType.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,34 @@ | ||
package de.westnordost.streetcomplete.quests.leaf_detail | ||
|
||
import de.westnordost.streetcomplete.R | ||
import de.westnordost.streetcomplete.data.elementfilter.toElementFilterExpression | ||
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.OUTDOORS | ||
import de.westnordost.streetcomplete.osm.Tags | ||
|
||
class AddTreeLeafType : OsmFilterQuestType<TreeLeafType>() { | ||
override val elementFilter = """ | ||
nodes with natural = tree and !leaf_type | ||
""" | ||
override val changesetComment = "Specify leaf types" | ||
override val wikiLink = "Key:leaf_type" | ||
override val icon = R.drawable.ic_quest_leaf | ||
override val achievements = listOf(OUTDOORS) | ||
|
||
override fun getTitle(tags: Map<String, String>) = R.string.quest_leafType_tree_title | ||
|
||
override fun getHighlightedElements(element: Element, getMapData: () -> MapDataWithGeometry) = | ||
getMapData().filter(""" | ||
nodes with natural=tree | ||
""".toElementFilterExpression()) | ||
|
||
override fun createForm() = AddTreeLeafTypeForm() | ||
|
||
override fun applyAnswerTo(answer: TreeLeafType, tags: Tags, geometry: ElementGeometry, timestampEdited: Long) { | ||
tags["leaf_type"] = answer.osmValue | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/de/westnordost/streetcomplete/quests/leaf_detail/AddTreeLeafTypeForm.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,13 @@ | ||
package de.westnordost.streetcomplete.quests.leaf_detail | ||
|
||
import de.westnordost.streetcomplete.quests.AImageListQuestForm | ||
|
||
class AddTreeLeafTypeForm : AImageListQuestForm<TreeLeafType, TreeLeafType>() { | ||
|
||
override val items = TreeLeafType.entries.map { it.asItem() } | ||
override val itemsPerRow = 2 | ||
|
||
override fun onClickOk(selectedItems: List<TreeLeafType>) { | ||
applyAnswer(selectedItems.single()) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
app/src/main/java/de/westnordost/streetcomplete/quests/leaf_detail/TreeLeafType.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,6 @@ | ||
package de.westnordost.streetcomplete.quests.leaf_detail | ||
|
||
enum class TreeLeafType(val osmValue: String) { | ||
NEEDLELEAVED("needleleaved"), | ||
BROADLEAVED("broadleaved"), | ||
} |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/de/westnordost/streetcomplete/quests/leaf_detail/TreeLeafTypeItem.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,18 @@ | ||
package de.westnordost.streetcomplete.quests.leaf_detail | ||
|
||
import de.westnordost.streetcomplete.R | ||
import de.westnordost.streetcomplete.quests.leaf_detail.TreeLeafType.BROADLEAVED | ||
import de.westnordost.streetcomplete.quests.leaf_detail.TreeLeafType.NEEDLELEAVED | ||
import de.westnordost.streetcomplete.view.image_select.Item | ||
|
||
fun TreeLeafType.asItem() = Item(this, iconResId, titleResId) | ||
|
||
private val TreeLeafType.titleResId: Int get() = when (this) { | ||
NEEDLELEAVED -> R.string.quest_leaf_type_needles | ||
BROADLEAVED -> R.string.quest_leaf_type_broadleaved | ||
} | ||
|
||
private val TreeLeafType.iconResId: Int get() = when (this) { | ||
NEEDLELEAVED -> R.drawable.leaf_type_needleleaved | ||
BROADLEAVED -> R.drawable.leaf_type_broadleaved | ||
} |
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