-
-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add quest about tree leaf type (#5496)
* better file name * ask about leaf type of natural=tree partial implementation of #83 * better English Co-authored-by: Flo Edelmann <git@flo-edelmann.de> * exclude cases where this info is implied by other tags * add test to common test base * skip more tags indicating leaf_type * fix code and tests * more readable filter Co-authored-by: Flo Edelmann <git@flo-edelmann.de> * collapse line Co-authored-by: Flo Edelmann <git@flo-edelmann.de> * smarter filter of already tagged data Co-authored-by: Tobias Zwick <newton@westnordost.de> * enable deleting trees in leaf type quest * disable tree quest by default * remove tests as requested --------- Co-authored-by: Flo Edelmann <git@flo-edelmann.de> Co-authored-by: Tobias Zwick <newton@westnordost.de>
- Loading branch information
1 parent
72b958b
commit 77a19d3
Showing
8 changed files
with
95 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
37 changes: 37 additions & 0 deletions
37
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,37 @@ | ||
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 | ||
and !~"(taxon|genus|species).*" | ||
""" | ||
override val changesetComment = "Specify leaf types" | ||
override val wikiLink = "Key:leaf_type" | ||
override val icon = R.drawable.ic_quest_leaf | ||
override val isDeleteElementEnabled = true | ||
override val achievements = listOf(OUTDOORS) | ||
override val defaultDisabledMessage = R.string.default_disabled_msg_difficult_and_time_consuming | ||
|
||
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()) | ||
} | ||
} |
File renamed without changes.
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
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