Skip to content

Commit 4bebc0e

Browse files
Fix SparseArray map function
1 parent fc3e816 commit 4bebc0e

File tree

4 files changed

+117
-3
lines changed

4 files changed

+117
-3
lines changed

core/build.gradle.kts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,29 @@ nordicNexusPublishing {
5454

5555
android {
5656
namespace = "no.nordicsemi.android.common.core"
57+
defaultConfig {
58+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
59+
}
5760
}
5861

5962
dependencies {
6063
implementation(platform(libs.androidx.compose.bom))
6164
implementation(libs.androidx.compose.ui)
6265
implementation(libs.androidx.core)
66+
67+
testImplementation(libs.test.mockk)
68+
testImplementation(libs.junit4)
69+
testImplementation(libs.kotlin.junit)
70+
testImplementation(libs.androidx.test.ext)
71+
testImplementation(libs.androidx.test.rules)
72+
testImplementation(libs.kotlinx.coroutines.test)
73+
testImplementation(libs.test.slf4j.simple)
74+
testImplementation(libs.test.robolectric)
75+
testImplementation(libs.hilt.android.testing)
76+
77+
androidTestImplementation(libs.junit4)
78+
androidTestImplementation(libs.kotlin.junit)
79+
androidTestImplementation(libs.androidx.test.ext)
80+
androidTestImplementation(libs.androidx.test.rules)
81+
androidTestImplementation(libs.kotlinx.coroutines.test)
6382
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package no.nordicsemi.android.common.core
2+
3+
import android.util.SparseArray
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
import org.junit.Test
6+
import org.junit.runner.RunWith
7+
import kotlin.test.assertEquals
8+
9+
@RunWith(AndroidJUnit4::class)
10+
class SparseArrayExtTest {
11+
12+
@Test
13+
fun whenMapSparseArrayShouldReturnArrayWithMappedValues() {
14+
val array = SparseArray<String>()
15+
16+
array.put(0, "aaa")
17+
array.put(2, "bbb")
18+
array.put(10, "ccc")
19+
20+
val newArray = array.map { "ddd" }
21+
22+
val expectedArray = SparseArray<String>().apply {
23+
put(0, "ddd")
24+
put(2, "ddd")
25+
put(10, "ddd")
26+
}
27+
28+
assertEquals(true, newArray.contentEquals(expectedArray))
29+
}
30+
}

core/src/main/java/no/nordicsemi/android/common/core/SparseArrayExt.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ fun <T, R> SparseArray<T>.map(
3737
modifier: (T) -> R,
3838
): SparseArray<R> {
3939
val newArray = SparseArray<R>(this.size())
40-
for (i in 0..this.size()) {
41-
newArray[i] = modifier(this[i])
40+
for (i in 0 until this.size()) {
41+
newArray[this.keyAt(i)] = modifier(this.valueAt(i))
4242
}
4343
return newArray
4444
}

gradle/libs.versions.toml

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[versions]
2+
accompanist = "0.32.0"
23
androidDesugarJdkLibs = "2.0.4"
34
androidGradlePlugin = "8.1.3"
45
androidxActivity = "1.8.0"
@@ -13,6 +14,8 @@ androidxDataStore = "1.0.0"
1314
androidxEspresso = "3.5.1"
1415
androidxHiltNavigationCompose = "1.1.0"
1516
androidxLifecycle = "2.6.2"
17+
androidxLocalbroadcastmanager = "1.1.0"
18+
androidxMacroBenchmark = "1.2.0"
1619
androidxNavigation = "2.7.5"
1720
androidxMetrics = "1.0.0-alpha04"
1821
androidxProfileinstaller = "1.3.1"
@@ -25,32 +28,64 @@ androidxTestRules = "1.5.0"
2528
androidxTracing = "1.1.0"
2629
androidxUiAutomator = "2.2.0"
2730
androidxWork = "2.8.1"
31+
coil = "2.5.0"
2832
firebaseBom = "32.5.0"
2933
hilt = "2.48.1"
3034
hiltExt = "1.1.0"
35+
jacoco = "0.8.7"
3136
junit4 = "4.13.2"
3237
kotlin = "1.9.10"
3338
kotlinxCoroutines = "1.7.3"
3439
kotlinxDatetime = "0.4.1"
3540
kotlinxSerializationJson = "1.6.0"
3641
ksp = "1.9.10-1.0.13"
3742
lint = "31.1.3"
43+
memfault-cloud = "2.0.5"
44+
okhttp = "4.12.0"
45+
protobuf = "3.25.0"
46+
protobufPlugin = "0.9.4"
3847
publishPlugin = "1.2.1"
48+
retrofit = "2.9.0"
49+
retrofitKotlinxSerializationJson = "1.0.0"
50+
room = "2.6.0"
51+
secrets = "2.0.1"
52+
turbine = "1.0.0"
3953
markdown = "0.3.6"
54+
wirePlugin = "4.9.1"
55+
timber = "5.0.1"
56+
chart = "v3.1.0"
4057
leakcanary = "2.12"
58+
mockk = "1.13.8"
59+
slf4j = "2.0.9"
60+
robolectric = "4.11.1"
61+
skydovesBallon = "1.6.2"
62+
moshiKotlin = "1.15.0"
63+
moshiAdapters = "1.15.0"
64+
moshiConverter = "2.9.0"
65+
moshi = "1.15.0"
66+
moshiKotlinCodegen = "1.15.0"
4167

4268
nordic-blek = "1.0.8"
69+
nordic-ble = "2.7.2"
70+
nordic-dfu = "2.3.2"
4371
nordic-log = "2.3.0"
4472
nordicPlugins = "1.9.13"
4573
dokkaPlugin = "1.9.10"
4674
googleServicesPlugins = "4.4.0"
4775
firebaseCrashlyticsPlugins = "2.9.9"
4876

4977
[libraries]
78+
accompanist-flowlayout = { group = "com.google.accompanist", name = "accompanist-flowlayout", version.ref = "accompanist" }
79+
accompanist-swiperefresh = { group = "com.google.accompanist", name = "accompanist-swiperefresh", version.ref = "accompanist" }
80+
accompanist-systemuicontroller = { group = "com.google.accompanist", name = "accompanist-systemuicontroller", version.ref = "accompanist" }
81+
accompanist-pager = { group = "com.google.accompanist", name = "accompanist-pager", version.ref = "accompanist" }
82+
accompanist-pagerindicators = { group = "com.google.accompanist", name = "accompanist-pager-indicators", version.ref = "accompanist" }
83+
accompanist-placeholder = { group = "com.google.accompanist", name = "accompanist-placeholder-material", version.ref = "accompanist" }
5084
android-desugarJdkLibs = { group = "com.android.tools", name = "desugar_jdk_libs", version.ref = "androidDesugarJdkLibs" }
5185
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "androidxActivity" }
5286
androidx-annotation = { group = "androidx.annotation", name = "annotation", version.ref = "androidxAnnotation" }
5387
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidxAppCompat" }
88+
androidx-benchmark-macro = { group = "androidx.benchmark", name = "benchmark-macro-junit4", version.ref = "androidxMacroBenchmark" }
5489
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "androidxComposeBom" }
5590
androidx-compose-foundation = { group = "androidx.compose.foundation", name = "foundation" }
5691
androidx-compose-foundation-layout = { group = "androidx.compose.foundation", name = "foundation-layout" }
@@ -67,20 +102,23 @@ androidx-compose-ui-testManifest = { group = "androidx.compose.ui", name = "ui-t
67102
androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
68103
androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
69104
androidx-compose-ui-util = { group = "androidx.compose.ui", name = "ui-util" }
105+
androidx-compose-animation = {group = "androidx.compose.animation", name = "animation"}
70106
androidx-core = { group = "androidx.core", name = "core", version.ref = "androidxCore" }
71107
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "androidxCore" }
72108
androidx-core-splashscreen = { group = "androidx.core", name = "core-splashscreen", version.ref = "androidxCoreSplashscreen" }
73109
androidx-dataStore-core = { group = "androidx.datastore", name = "datastore", version.ref = "androidxDataStore" }
74110
androidx-dataStore-preferences = { group = "androidx.datastore", name = "datastore-preferences", version.ref = "androidxDataStore" }
75111
androidx-hilt-navigation-compose = { group = "androidx.hilt", name = "hilt-navigation-compose", version.ref = "androidxHiltNavigationCompose" }
76112
androidx-lifecycle-livedata-ktx = { group = "androidx.lifecycle", name = "lifecycle-livedata-ktx", version.ref = "androidxLifecycle" }
113+
androidx-lifecycle-livedata = { group = "androidx.lifecycle", name = "lifecycle-livedata", version.ref = "androidxLifecycle" }
77114
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "androidxLifecycle" }
78115
androidx-lifecycle-runtime = { group = "androidx.lifecycle", name = "lifecycle-runtime", version.ref = "androidxLifecycle" }
79116
androidx-lifecycle-runtime-compose = { group = "androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "androidxLifecycle" }
80117
androidx-lifecycle-service = { group = "androidx.lifecycle", name = "lifecycle-service", version.ref = "androidxLifecycle" }
81118
androidx-lifecycle-viewModel-ktx = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-ktx", version.ref = "androidxLifecycle" }
82119
androidx-lifecycle-viewModel-compose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "androidxLifecycle" }
83120
androidx-lifecycle-viewModel-savedState = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-savedstate", version.ref = "androidxLifecycle" }
121+
androidx-localbroadcastmanager = { group = "androidx.localbroadcastmanager", name = "localbroadcastmanager", version.ref = "androidxLocalbroadcastmanager" }
84122
androidx-metrics = { group = "androidx.metrics", name = "metrics-performance", version.ref = "androidxMetrics" }
85123
androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "androidxNavigation" }
86124
androidx-navigation-testing = { group = "androidx.navigation", name = "navigation-testing", version.ref = "androidxNavigation" }
@@ -96,6 +134,9 @@ androidx-test-uiautomator = { group = "androidx.test.uiautomator", name = "uiaut
96134
androidx-tracing-ktx = {group = "androidx.tracing", name="tracing-ktx", version.ref = "androidxTracing" }
97135
androidx-work-ktx = { group = "androidx.work", name = "work-runtime-ktx", version.ref = "androidxWork" }
98136
androidx-work-testing = { group = "androidx.work", name = "work-testing", version.ref = "androidxWork" }
137+
coil-kt = { group = "io.coil-kt", name = "coil", version.ref = "coil"}
138+
coil-kt-compose = { group = "io.coil-kt", name = "coil-compose", version.ref = "coil"}
139+
coil-kt-svg = { group = "io.coil-kt", name = "coil-svg", version.ref = "coil"}
99140
firebase-bom = { group = "com.google.firebase", name = "firebase-bom", version.ref = "firebaseBom"}
100141
firebase-analytics = { group = "com.google.firebase", name = "firebase-analytics-ktx" }
101142
firebase-database = { group = "com.google.firebase", name = "firebase-database-ktx" }
@@ -114,8 +155,29 @@ kotlinx-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-cor
114155
kotlinx-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version.ref = "kotlinxDatetime" }
115156
kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" }
116157
lint-api = { group = "com.android.tools.lint", name = "lint-api", version.ref = "lint" }
158+
okhttp-logging = { group = "com.squareup.okhttp3", name = "logging-interceptor", version.ref = "okhttp" }
159+
protobuf-protoc = { group = "com.google.protobuf", name = "protoc", version.ref = "protobuf" }
160+
protobuf-kotlin-lite = { group = "com.google.protobuf", name = "protobuf-kotlin-lite", version.ref = "protobuf" }
161+
turbine = { group = "app.cash.turbine", name = "turbine", version.ref = "turbine" }
162+
retrofit-core = { group = "com.squareup.retrofit2", name = "retrofit", version.ref = "retrofit" }
163+
retrofit-kotlin-serialization = { group = "com.jakewharton.retrofit", name = "retrofit2-kotlinx-serialization-converter", version.ref = "retrofitKotlinxSerializationJson" }
164+
room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" }
165+
room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" }
166+
room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" }
117167
markdown = { group = "com.github.jeziellago", name = "compose-markdown", version.ref = "markdown" }
168+
memfault-cloud = { group = "com.memfault.cloud", name = "cloud-android", version.ref = "memfault-cloud" }
169+
timber = { group = "com.jakewharton.timber", name = "timber", version.ref = "timber" }
170+
chart = { group = "com.github.PhilJay", name = "MPAndroidChart", version.ref = "chart" }
118171
leakcanary = { group = "com.squareup.leakcanary", name = "leakcanary-android", version.ref = "leakcanary" }
172+
test-slf4j-simple = { group = "org.slf4j", name = "slf4j-simple", version.ref = "slf4j" }
173+
test-mockk = { group = "io.mockk", name = "mockk", version.ref = "mockk" }
174+
test-robolectric = { group = "org.robolectric", name = "robolectric", version.ref = "robolectric" }
175+
skydoves-ballon = {group = "com.github.skydoves", name = "balloon-compose", version.ref = "skydovesBallon"}
176+
moshi-kotlin = {group = "com.squareup.moshi", name = "moshi-kotlin", version.ref = "moshiKotlin"}
177+
moshi-adapters = {group = "com.squareup.moshi", name = "moshi-adapters", version.ref = "moshiAdapters"}
178+
moshi-converter = {group = "com.squareup.retrofit2", name = "converter-moshi", version.ref = "moshiConverter"}
179+
moshi = {group = "com.squareup.moshi", name = "moshi", version.ref = "moshi"}
180+
moshi-kotlin-codegen = {group = "com.squareup.moshi", name = "moshi-kotlin-codegen", version.ref = "moshiKotlinCodegen"}
119181

120182
# Nordic
121183
nordic-log = { group = "no.nordicsemi.android", name = "log", version.ref = "nordic-log" }
@@ -128,7 +190,7 @@ nordic-blek-profile = { group = "no.nordicsemi.android.kotlin.ble", name = "prof
128190
nordic-blek-core = { group = "no.nordicsemi.android.kotlin.ble", name = "core", version.ref = "nordic-blek" }
129191
nordic-blek-scanner = { group = "no.nordicsemi.android.kotlin.ble", name = "scanner", version.ref = "nordic-blek" }
130192
nordic-blek-advertiser = { group = "no.nordicsemi.android.kotlin.ble", name = "advertiser", version.ref = "nordic-blek" }
131-
nordic-blek-logger = { group = "no.nordicsemi.android.kotlin.ble", name = "logger", version.ref = "nordic-blek" }
193+
nordic-blek-uiscanner = { group = "no.nordicsemi.android.kotlin.ble", name = "uiscanner", version.ref = "nordic-blek" }
132194

133195
# Dependencies of the included build-logic
134196
android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "androidGradlePlugin" }
@@ -154,6 +216,9 @@ kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
154216
kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }
155217
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
156218
kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
219+
protobuf = { id = "com.google.protobuf", version.ref = "protobufPlugin" }
220+
secrets = { id = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin", version.ref = "secrets" }
157221
publish = { id = "com.gradle.plugin-publish", version.ref = "publishPlugin" }
222+
wire = { id = "com.squareup.wire", version.ref = "wirePlugin" }
158223
google-services = { id = "com.google.gms.google-services", version.ref = "googleServicesPlugins" }
159224
firebase-crashlytics = { id = "com.google.firebase.crashlytics", version.ref = "firebaseCrashlyticsPlugins" }

0 commit comments

Comments
 (0)