Skip to content

Commit c2a85a7

Browse files
authored
Quest title in compose (#6784)
1 parent aadd1b6 commit c2a85a7

File tree

331 files changed

+1813
-1952
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

331 files changed

+1813
-1952
lines changed

app/src/androidInstrumentedTest/kotlin/de/westnordost/streetcomplete/data/osm/edits/ElementEditsDaoTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import de.westnordost.streetcomplete.data.overlays.OverlayRegistry
3030
import de.westnordost.streetcomplete.data.overlays.OverlayStyle
3131
import de.westnordost.streetcomplete.data.quest.QuestTypeRegistry
3232
import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement
33+
import de.westnordost.streetcomplete.resources.*
3334
import kotlin.test.BeforeTest
3435
import kotlin.test.Test
3536
import kotlin.test.assertEquals
@@ -342,7 +343,7 @@ private object TestOverlay : Overlay {
342343
override fun getStyledElements(mapData: MapDataWithGeometry) = sequenceOf<Pair<Element, OverlayStyle>>()
343344
override val changesetComment = "bla"
344345
override val icon = 0
345-
override val title = 0
346+
override val title = Res.string.quest_address_title
346347
override val wikiLink = null
347348
override val achievements = listOf<EditTypeAchievement>()
348349
}

app/src/androidInstrumentedTest/kotlin/de/westnordost/streetcomplete/data/osm/osmquests/TestQuestType.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import de.westnordost.streetcomplete.data.osm.mapdata.Element
55
import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry
66
import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement
77
import de.westnordost.streetcomplete.osm.Tags
8+
import de.westnordost.streetcomplete.resources.*
89

910
open class TestQuestType : OsmElementQuestType<String> {
1011

1112
override fun isApplicableTo(element: Element): Boolean? = null
1213
override fun applyAnswerTo(answer: String, tags: Tags, geometry: ElementGeometry, timestampEdited: Long) {}
1314
override val icon = 0
1415
override val changesetComment = ""
15-
override fun getTitle(tags: Map<String, String>) = 0
16+
override val title = Res.string.quest_address_title
1617
override fun getApplicableElements(mapData: MapDataWithGeometry) = emptyList<Element>()
1718
override val wikiLink: String? = null
1819
override val achievements = emptyList<EditTypeAchievement>()

app/src/androidInstrumentedTest/kotlin/de/westnordost/streetcomplete/util/NameAndLocationLabelTest.kt

Lines changed: 128 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2,129 +2,179 @@ package de.westnordost.streetcomplete.util
22

33
import android.content.res.Configuration
44
import android.content.res.Resources
5+
import androidx.compose.ui.text.AnnotatedString
6+
import androidx.compose.ui.unit.LayoutDirection
57
import androidx.test.platform.app.InstrumentationRegistry
68
import de.westnordost.osmfeatures.FeatureDictionary
79
import de.westnordost.osmfeatures.create
810
import de.westnordost.streetcomplete.data.osm.mapdata.LatLon
911
import de.westnordost.streetcomplete.data.osm.mapdata.Node
1012
import de.westnordost.streetcomplete.data.osm.mapdata.Way
13+
import kotlinx.coroutines.CoroutineDispatcher
14+
import kotlinx.coroutines.Dispatchers
15+
import kotlinx.coroutines.GlobalScope
16+
import kotlinx.coroutines.launch
17+
import kotlinx.coroutines.runBlocking
18+
import org.jetbrains.compose.resources.DensityQualifier
19+
import org.jetbrains.compose.resources.InternalResourceApi
20+
import org.jetbrains.compose.resources.LanguageQualifier
21+
import org.jetbrains.compose.resources.RegionQualifier
22+
import org.jetbrains.compose.resources.ResourceEnvironment
23+
import org.jetbrains.compose.resources.ThemeQualifier
1124
import java.util.Locale
1225
import kotlin.test.Test
1326
import kotlin.test.assertEquals
1427

1528
class NameAndLocationLabelTest {
16-
private var featureDictionary: FeatureDictionary
17-
private var englishResources: Resources
18-
19-
init {
20-
val context = InstrumentationRegistry.getInstrumentation().targetContext
21-
featureDictionary = FeatureDictionary.create(context.assets, "osmfeatures/default", "osmfeatures/brands")
22-
23-
val conf = Configuration(context.resources.configuration)
24-
conf.setLocale(Locale.ENGLISH)
25-
val localizedContext = context.createConfigurationContext(conf)
26-
englishResources = localizedContext.resources
27-
}
29+
private val featureDictionary = FeatureDictionary.create(
30+
assetManager = InstrumentationRegistry.getInstrumentation().targetContext.assets,
31+
presetsBasePath = "osmfeatures/default",
32+
brandPresetsBasePath = "osmfeatures/brands"
33+
)
34+
/*
35+
TODO KMP upstream
36+
Unfortunately, ResourceEnvironment's constructor is internal, so we cannot use this
37+
see https://youtrack.jetbrains.com/issue/CMP-9959/Access-resources-in-specific-language-outside-of-composition
38+
Without using specifically English resources, most tests will fail
39+
40+
@OptIn(InternalResourceApi::class)
41+
private val resourceEnvironment = ResourceEnvironment(
42+
language = LanguageQualifier("en"),
43+
region = RegionQualifier(""),
44+
theme = ThemeQualifier.LIGHT,
45+
density = DensityQualifier.MDPI,
46+
)
2847
2948
// https://github.com/streetcomplete/StreetComplete/issues/2512
30-
@Test fun newspaperVendingMachineWithName() {
31-
assertEquals("Bild (Newspaper\u00A0Vending\u00A0Machine)", getQuestLabelForNode(mapOf(
32-
"amenity" to "vending_machine",
33-
"vending" to "newspapers",
34-
"name" to "Bild",
35-
)))
49+
@Test fun newspaperVendingMachineWithName() = runBlocking {
50+
assertEquals(
51+
"Bild (Newspaper\u00A0Vending\u00A0Machine)",
52+
getQuestLabelForNode(mapOf(
53+
"amenity" to "vending_machine",
54+
"vending" to "newspapers",
55+
"name" to "Bild",
56+
))
57+
)
3658
}
3759
3860
// https://github.com/streetcomplete/StreetComplete/issues/2512
39-
@Test fun newspaperVendingMachineWithBrand() {
40-
assertEquals("Abendzeitung (Newspaper\u00A0Vending\u00A0Machine)", getQuestLabelForNode(mapOf(
41-
"amenity" to "vending_machine",
42-
"vending" to "newspapers",
43-
"brand" to "Abendzeitung",
44-
)))
61+
@Test fun newspaperVendingMachineWithBrand() = runBlocking {
62+
assertEquals(
63+
"Abendzeitung (Newspaper\u00A0Vending\u00A0Machine)",
64+
getQuestLabelForNode(mapOf(
65+
"amenity" to "vending_machine",
66+
"vending" to "newspapers",
67+
"brand" to "Abendzeitung",
68+
))
69+
)
4570
}
4671
4772
// https://github.com/streetcomplete/StreetComplete/issues/2640
48-
@Test fun postBox() {
49-
assertEquals("Deutsche\u00A0Post (Mail\u00A0Drop\u00A0Box)", getQuestLabelForNode(mapOf(
50-
"amenity" to "post_box",
51-
"brand" to "Deutsche Post",
52-
"operator" to "Deutsche Post AG",
53-
"ref" to "Hauptsmoorstr. 101, 96052 Bamberg",
54-
)))
73+
@Test fun postBox() = runBlocking {
74+
assertEquals(
75+
"Deutsche\u00A0Post (Mail\u00A0Drop\u00A0Box)",
76+
getQuestLabelForNode(mapOf(
77+
"amenity" to "post_box",
78+
"brand" to "Deutsche Post",
79+
"operator" to "Deutsche Post AG",
80+
"ref" to "Hauptsmoorstr. 101, 96052 Bamberg",
81+
))
82+
)
5583
}
5684
5785
// https://github.com/streetcomplete/StreetComplete/issues/2806
58-
@Test fun namedBench() {
59-
assertEquals("Sergey's\u00A0Seat (Bench)", getQuestLabelForNode(mapOf(
60-
"amenity" to "bench",
61-
"name" to "Sergey's Seat",
62-
"ref" to "600913",
63-
"brand" to "Google",
64-
"operator" to "Google RESTful",
65-
)))
86+
@Test fun namedBench() = runBlocking {
87+
assertEquals(
88+
"Sergey's\u00A0Seat (Bench)",
89+
getQuestLabelForNode(mapOf(
90+
"amenity" to "bench",
91+
"name" to "Sergey's Seat",
92+
"ref" to "600913",
93+
"brand" to "Google",
94+
"operator" to "Google RESTful",
95+
))
96+
)
6697
}
6798
6899
// https://github.com/streetcomplete/StreetComplete/issues/2806
69-
@Test fun unnamedBench() {
70-
assertEquals("Bench", getQuestLabelForNode(mapOf(
71-
"amenity" to "bench",
72-
)))
100+
@Test fun unnamedBench() = runBlocking {
101+
assertEquals(
102+
"Bench",
103+
getQuestLabelForNode(mapOf("amenity" to "bench"))
104+
)
73105
}
74106
75107
// https://github.com/streetcomplete/StreetComplete/issues/2840#issuecomment-831245075
76-
@Test fun schoki() {
77-
assertEquals("Schoko\u00A0Lädchen\u00A0[3680] (Vending\u00A0Machine)", getQuestLabelForNode(mapOf(
78-
"amenity" to "vending_machine",
79-
"ref" to "3680",
80-
"operator" to "Schoko Lädchen",
81-
)))
108+
@Test fun schoki() = runBlocking {
109+
assertEquals(
110+
"Schoko\u00A0Lädchen\u00A0[3680] (Vending\u00A0Machine)",
111+
getQuestLabelForNode(mapOf(
112+
"amenity" to "vending_machine",
113+
"ref" to "3680",
114+
"operator" to "Schoko Lädchen",
115+
))
116+
)
82117
}
83118
84119
// https://github.com/streetcomplete/StreetComplete/issues/5549
85-
@Test fun pointNotVertex() {
86-
assertEquals("Bollard", getQuestLabelForNode(mapOf(
87-
"barrier" to "bollard",
88-
)))
120+
@Test fun pointNotVertex() = runBlocking {
121+
assertEquals(
122+
"Bollard",
123+
getQuestLabelForNode(mapOf(
124+
"barrier" to "bollard",
125+
))
126+
)
89127
}
90128
91129
// https://github.com/streetcomplete/StreetComplete/issues/5427
92-
@Test fun roadWithName() {
93-
assertEquals("Main\u00A0Street (Residential\u00A0Road)", getQuestLabelForWay(mapOf(
94-
"highway" to "residential",
95-
"name" to "Main Street",
96-
"operator" to "Road Agency",
97-
)))
130+
@Test fun roadWithName() = runBlocking {
131+
assertEquals(
132+
"Main\u00A0Street (Residential\u00A0Road)",
133+
getQuestLabelForWay(mapOf(
134+
"highway" to "residential",
135+
"name" to "Main Street",
136+
"operator" to "Road Agency",
137+
))
138+
)
98139
}
99140
100-
@Test fun roadWitRef() {
101-
assertEquals("A1 (Residential\u00A0Road)", getQuestLabelForWay(mapOf(
102-
"highway" to "residential",
103-
"ref" to "A1",
104-
"operator" to "Road Agency",
105-
)))
141+
@Test fun roadWitRef() = runBlocking {
142+
assertEquals(
143+
"A1 (Residential\u00A0Road)",
144+
getQuestLabelForWay(mapOf(
145+
"highway" to "residential",
146+
"ref" to "A1",
147+
"operator" to "Road Agency",
148+
))
149+
)
106150
}
107151
108-
@Test fun roadWithNameAndRef() {
109-
assertEquals("Main\u00A0Street\u00A0[A1] (Residential\u00A0Road)", getQuestLabelForWay(mapOf(
110-
"highway" to "residential",
111-
"name" to "Main Street",
112-
"ref" to "A1",
113-
"operator" to "Road Agency",
114-
)))
152+
@Test fun roadWithNameAndRef() = runBlocking {
153+
assertEquals(
154+
"Main\u00A0Street\u00A0[A1] (Residential\u00A0Road)",
155+
getQuestLabelForWay(mapOf(
156+
"highway" to "residential",
157+
"name" to "Main Street",
158+
"ref" to "A1",
159+
"operator" to "Road Agency",
160+
))
161+
)
115162
}
116163
117-
private fun getQuestLabelForNode(tags: Map<String, String>): String? =
118-
getNameAndLocationSpanned(
164+
private suspend fun getQuestLabelForNode(tags: Map<String, String>): String? =
165+
getNameAndLocationLabel(
166+
resourceEnvironment,
167+
LayoutDirection.Ltr,
119168
Node(0, LatLon(0.0, 0.0), tags),
120-
englishResources,
121169
featureDictionary
122170
)?.toString()
123171
124-
private fun getQuestLabelForWay(tags: Map<String, String>): String? =
125-
getNameAndLocationSpanned(
172+
private suspend fun getQuestLabelForWay(tags: Map<String, String>): String? =
173+
getNameAndLocationLabel(
174+
resourceEnvironment,
175+
LayoutDirection.Ltr,
126176
Way(0, listOf(), tags),
127-
englishResources,
128177
featureDictionary
129178
)?.toString()
179+
*/
130180
}

app/src/androidMain/kotlin/de/westnordost/streetcomplete/ApplicationModule.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import android.content.res.AssetManager
44
import android.content.res.Resources
55
import de.westnordost.streetcomplete.resources.Res
66
import de.westnordost.streetcomplete.util.CrashReportExceptionHandler
7-
import de.westnordost.streetcomplete.util.DefaultResourceProvider
8-
import de.westnordost.streetcomplete.util.ResourceProvider
97
import de.westnordost.streetcomplete.util.SoundFx
108
import de.westnordost.streetcomplete.util.logs.DatabaseLogger
119
import io.ktor.client.HttpClient
@@ -37,5 +35,4 @@ val appModule = module {
3735
} }
3836
single<Res> { Res }
3937
single<FileSystem> { SystemFileSystem }
40-
single<ResourceProvider> { DefaultResourceProvider(androidContext(), get()) }
4138
}

0 commit comments

Comments
 (0)