Skip to content

Commit 1b8a0f6

Browse files
authored
Recycling quest UI change (fixes #6613, fixes #6608)
* add class for tree structure * recycling materials in that tree structure + PET -> pet bottles * implement stuff * and solve todo... * actually, let's remove the special case for Czechia - just show "any glass" always. It's just one more item in the list (as opposed to opening of a dialog in the old UI) * no need to convert to list * typo + fix test * remove now unused graphic * order items by common-ness, add last-picked-ordering
1 parent 7b67332 commit 1b8a0f6

File tree

19 files changed

+305
-498
lines changed

19 files changed

+305
-498
lines changed

app/src/androidMain/kotlin/de/westnordost/streetcomplete/quests/recycling_material/AddRecyclingContainerMaterials.kt

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,29 +58,19 @@ class AddRecyclingContainerMaterials : OsmElementQuestType<RecyclingContainerMat
5858
}
5959
}
6060

61-
private fun applyRecyclingMaterialsAnswer(materials: List<RecyclingMaterial>, tags: Tags) {
61+
private fun applyRecyclingMaterialsAnswer(materials: Iterable<RecyclingMaterial>, tags: Tags) {
6262
// first clear recycling:* taggings previously "yes"
6363
for ((key, value) in tags.entries) {
6464
if (key.startsWith("recycling:") && value == "yes") {
6565
tags.remove(key)
6666
}
6767
}
68-
69-
// if the user chose deliberately not "all plastic", also tag it explicitly
70-
val selectedPlastics = materials.filter { it in RecyclingMaterial.allPlastics }
71-
if (selectedPlastics.isNotEmpty()) {
72-
for (plastic in RecyclingMaterial.allPlastics) {
73-
tags.remove("recycling:${plastic.value}")
74-
}
75-
76-
val selectedAndIndirectlySelectedPlastics =
77-
selectedPlastics + selectedPlastics.flatMapTo(HashSet()) { it.subValues }
78-
79-
val notSelectedPlastics =
80-
RecyclingMaterial.allPlastics - selectedAndIndirectlySelectedPlastics.toSet()
81-
82-
for (notSelectedPlastic in notSelectedPlastics) {
83-
tags["recycling:${notSelectedPlastic.value}"] = "no"
68+
// if any parent value is now "yes" all child values may not be "no". E.g. if "Any plastic"
69+
// was selected, "plastic bottles" may not be "no".
70+
for (material in materials) {
71+
for (childMaterial in RecyclingMaterial.tree.yieldChildValues(material).orEmpty()) {
72+
val key = "recycling:${childMaterial.value}"
73+
if (tags[key] == "no") tags.remove(key)
8474
}
8575
}
8676

@@ -89,6 +79,7 @@ class AddRecyclingContainerMaterials : OsmElementQuestType<RecyclingContainerMat
8979
tags["recycling:${material.value}"] = "yes"
9080
}
9181

82+
9283
// only set the check date if nothing was changed
9384
if (!tags.hasChanges || tags.hasCheckDateForKey("recycling")) {
9485
tags.updateCheckDateForKey("recycling")

app/src/androidMain/kotlin/de/westnordost/streetcomplete/quests/recycling_material/AddRecyclingContainerMaterialsForm.kt

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,54 @@ import androidx.appcompat.app.AlertDialog
66
import androidx.compose.material.Surface
77
import androidx.compose.runtime.mutableStateOf
88
import de.westnordost.streetcomplete.R
9+
import de.westnordost.streetcomplete.data.preferences.Preferences
910
import de.westnordost.streetcomplete.databinding.ComposeViewBinding
1011
import de.westnordost.streetcomplete.quests.AbstractOsmQuestForm
1112
import de.westnordost.streetcomplete.quests.AnswerItem
1213
import de.westnordost.streetcomplete.ui.util.content
13-
14+
import de.westnordost.streetcomplete.util.takeFavorites
15+
import org.koin.android.ext.android.inject
16+
import kotlin.getValue
1417

1518
class AddRecyclingContainerMaterialsForm : AbstractOsmQuestForm<RecyclingContainerMaterialsAnswer>() {
1619

1720
override val contentLayoutResId = R.layout.compose_view
1821
private val binding by contentViewBinding(ComposeViewBinding::bind)
1922
override val defaultExpanded = false
2023

24+
private val prefs: Preferences by inject()
25+
2126
override val otherAnswers = listOf(
2227
AnswerItem(R.string.quest_recycling_materials_answer_waste) { confirmJustTrash() }
2328
)
2429

25-
private val items = RecyclingMaterial.selectableValues.map { listOf(it) }
26-
private val selectedItems = mutableStateOf(emptySet<RecyclingMaterialsItem>())
30+
private lateinit var reorderedItems: List<RecyclingMaterial>
31+
private val selectedItems = mutableStateOf(emptySet<RecyclingMaterial>())
32+
33+
override fun onCreate(savedInstanceState: Bundle?) {
34+
super.onCreate(savedInstanceState)
35+
reorderedItems = moveFavouritesToFront(RecyclingMaterial.entries)
36+
}
2737

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

3141
binding.composeViewBase.content { Surface {
3242
RecyclingContainerMaterialsForm(
33-
items = items,
43+
items = reorderedItems,
44+
tree = RecyclingMaterial.tree,
3445
selectedItems = selectedItems.value,
3546
onSelectedItems = {
3647
selectedItems.value = it
3748
checkIsFormComplete()
3849
},
39-
isAnyGlassRecyclable = countryInfo.isUsuallyAnyGlassRecyclableInContainers,
4050
)
4151
} }
4252
}
4353

4454
override fun onClickOk() {
45-
applyAnswer(RecyclingMaterials(selectedItems.value.flatten()))
55+
prefs.addLastPicked(this::class.simpleName!!, selectedItems.value.toList())
56+
applyAnswer(RecyclingMaterials(selectedItems.value))
4657
}
4758

4859
override fun isFormComplete() = selectedItems.value.isNotEmpty()
@@ -55,4 +66,11 @@ class AddRecyclingContainerMaterialsForm : AbstractOsmQuestForm<RecyclingContain
5566
.show()
5667
}
5768
}
69+
70+
private fun moveFavouritesToFront(originalList: List<RecyclingMaterial>): List<RecyclingMaterial> {
71+
val favourites = prefs
72+
.getLastPicked<RecyclingMaterial>(this::class.simpleName!!)
73+
.takeFavorites(4)
74+
return (favourites + originalList).distinct()
75+
}
5876
}

app/src/androidMain/res/values-en/strings.xml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,7 @@ A level counts as a roof level when its windows are in the roof. Subsequently, r
10361036
<string name="quest_carWashType_service">Staff cleans car</string>
10371037

10381038
<string name="quest_charging_station_bicycles_title">Can bicycles be charged here, too?</string>
1039+
<string name="quest_charging_station_bicycles_answer_only">It’s only for bicycles</string>
10391040
<string name="quest_charging_station_bicycles_hint">Bicycle charger power adapters plug into normal household sockets.</string>
10401041

10411042
<string name="quest_charging_station_capacity_title">How many cars can be charged here at the same time?</string>
@@ -1455,15 +1456,13 @@ If there are no signs along the whole street which apply for the highlighted sec
14551456
<string name="quest_recycling_type_glass_bottles">Glass bottles and jars</string>
14561457
<string name="quest_recycling_type_glass_bottles_short">Bottles and jars</string>
14571458
<string name="quest_recycling_type_paper">Paper</string>
1458-
<string name="quest_recycling_type_plastic_generic">Plastic</string>
14591459
<string name="quest_recycling_type_plastic">Any plastic</string>
14601460
<string name="quest_recycling_type_shoes">Shoes</string>
14611461
<string name="quest_recycling_type_electric_appliances">Electric appliances</string>
1462-
<string name="quest_recycling_type_plastic_bottles">Plastic bottles only</string>
1463-
<string name="quest_recycling_type_beverage_cartons">Beverage cartons only</string>
1464-
<string name="quest_recycling_type_pet">PET only</string>
1465-
<string name="quest_recycling_type_plastic_packaging">Plastic packaging only</string>
1466-
<string name="quest_recycling_type_plastic_bottles_and_cartons">Plastic bottles and cartons only</string>
1462+
<string name="quest_recycling_type_plastic_bottles">Plastic bottles</string>
1463+
<string name="quest_recycling_type_beverage_cartons">Beverage cartons</string>
1464+
<string name="quest_recycling_type_pet_bottles">PET bottles</string>
1465+
<string name="quest_recycling_type_plastic_packaging">Any plastic packaging</string>
14671466
<string name="quest_recycling_type_scrap_metal">Scrap metal</string>
14681467
<string name="quest_recycling_type_any_glass">Any glass</string>
14691468
<string name="quest_recycling_type_cooking_oil">Cooking Oil</string>

app/src/androidMain/res/values/strings.xml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,15 +1456,13 @@ If there are no signs along the whole street which apply for the highlighted sec
14561456
<string name="quest_recycling_type_glass_bottles">Glass bottles and jars</string>
14571457
<string name="quest_recycling_type_glass_bottles_short">Bottles and jars</string>
14581458
<string name="quest_recycling_type_paper">Paper</string>
1459-
<string name="quest_recycling_type_plastic_generic">Plastic</string>
14601459
<string name="quest_recycling_type_plastic">Any plastic</string>
14611460
<string name="quest_recycling_type_shoes">Shoes</string>
14621461
<string name="quest_recycling_type_electric_appliances">Electric appliances</string>
1463-
<string name="quest_recycling_type_plastic_bottles">Plastic bottles only</string>
1464-
<string name="quest_recycling_type_beverage_cartons">Beverage cartons only</string>
1465-
<string name="quest_recycling_type_pet">PET only</string>
1466-
<string name="quest_recycling_type_plastic_packaging">Plastic packaging only</string>
1467-
<string name="quest_recycling_type_plastic_bottles_and_cartons">Plastic bottles and cartons only</string>
1462+
<string name="quest_recycling_type_plastic_bottles">Plastic bottles</string>
1463+
<string name="quest_recycling_type_beverage_cartons">Beverage cartons</string>
1464+
<string name="quest_recycling_type_pet_bottles">PET bottles</string>
1465+
<string name="quest_recycling_type_plastic_packaging">Any plastic packaging</string>
14681466
<string name="quest_recycling_type_scrap_metal">Scrap metal</string>
14691467
<string name="quest_recycling_type_any_glass">Any glass</string>
14701468
<string name="quest_recycling_type_cooking_oil">Cooking Oil</string>

0 commit comments

Comments
 (0)