Skip to content

Commit 59e3c1f

Browse files
committed
Migration to AGP 2.12-1 and some other improvements
1 parent c2884d7 commit 59e3c1f

File tree

9 files changed

+65
-194
lines changed

9 files changed

+65
-194
lines changed

scanner-ble/src/main/java/no/nordicsemi/android/common/scanner/view/ScannerView.kt

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,19 @@ import androidx.compose.foundation.background
3838
import androidx.compose.foundation.clickable
3939
import androidx.compose.foundation.layout.Arrangement
4040
import androidx.compose.foundation.layout.Box
41-
import androidx.compose.foundation.layout.Column
42-
import androidx.compose.foundation.layout.Row
4341
import androidx.compose.foundation.layout.WindowInsets
4442
import androidx.compose.foundation.layout.WindowInsetsSides
4543
import androidx.compose.foundation.layout.asPaddingValues
4644
import androidx.compose.foundation.layout.displayCutout
4745
import androidx.compose.foundation.layout.fillMaxSize
48-
import androidx.compose.foundation.layout.heightIn
4946
import androidx.compose.foundation.layout.only
50-
import androidx.compose.foundation.layout.padding
5147
import androidx.compose.foundation.layout.union
5248
import androidx.compose.foundation.lazy.LazyColumn
5349
import androidx.compose.foundation.lazy.LazyListScope
5450
import androidx.compose.foundation.lazy.items
5551
import androidx.compose.foundation.shape.RoundedCornerShape
5652
import androidx.compose.material3.ExperimentalMaterial3Api
53+
import androidx.compose.material3.ListItem
5754
import androidx.compose.material3.MaterialTheme
5855
import androidx.compose.material3.OutlinedCard
5956
import androidx.compose.material3.Text
@@ -65,7 +62,6 @@ import androidx.compose.runtime.LaunchedEffect
6562
import androidx.compose.runtime.getValue
6663
import androidx.compose.runtime.rememberCoroutineScope
6764
import androidx.compose.runtime.rememberUpdatedState
68-
import androidx.compose.ui.Alignment
6965
import androidx.compose.ui.Modifier
7066
import androidx.compose.ui.draw.clip
7167
import androidx.compose.ui.graphics.painter.Painter
@@ -227,7 +223,7 @@ internal fun DeviceListItem(
227223
?: R.drawable.outline_bluetooth_24,
228224
) {
229225
DeviceListItem(
230-
peripheralIcon = peripheralIcon?.let { painterResource(it) },
226+
iconPainter = peripheralIcon?.let { painterResource(it) },
231227
title = result.advertisingData.name ?: result.peripheral.name
232228
?: stringResource(R.string.no_name),
233229
subtitle = result.peripheral.address,
@@ -241,51 +237,63 @@ internal fun DeviceListItem(
241237
@OptIn(ExperimentalUuidApi::class)
242238
@Composable
243239
fun DeviceListItem(
244-
peripheralIcon: Painter?,
240+
iconPainter: Painter?,
245241
title: String,
246242
subtitle: String,
243+
modifier: Modifier = Modifier,
247244
trailingContent: @Composable () -> Unit = { },
248245
) {
249-
OutlinedCard {
250-
Row(
251-
modifier = Modifier
252-
.heightIn(min = 80.dp)
253-
.padding(all = 16.dp),
254-
verticalAlignment = Alignment.CenterVertically,
255-
horizontalArrangement = Arrangement.spacedBy(16.dp)
256-
) {
257-
peripheralIcon?.let {
258-
CircularIcon(
259-
painter = it,
260-
)
261-
}
262-
Column(
263-
verticalArrangement = Arrangement.spacedBy(4.dp),
264-
modifier = Modifier.weight(1.0f)
265-
) {
266-
Text(
267-
text = title,
268-
color = MaterialTheme.colorScheme.onSurface,
269-
maxLines = 2,
270-
overflow = TextOverflow.Ellipsis,
271-
style = MaterialTheme.typography.titleMedium,
272-
)
273-
Text(
274-
text = subtitle,
275-
style = MaterialTheme.typography.bodyMedium,
276-
maxLines = 1,
277-
)
278-
}
279-
trailingContent()
280-
}
246+
DeviceListItem(
247+
modifier = modifier,
248+
iconPainter = iconPainter,
249+
headlineContent = {
250+
Text(
251+
text = title,
252+
maxLines = 1,
253+
overflow = TextOverflow.Ellipsis,
254+
)
255+
},
256+
supportingContent = {
257+
Text(
258+
text = subtitle,
259+
maxLines = 1,
260+
overflow = TextOverflow.Ellipsis,
261+
)
262+
},
263+
trailingContent = trailingContent
264+
)
265+
}
266+
267+
@OptIn(ExperimentalUuidApi::class)
268+
@Composable
269+
fun DeviceListItem(
270+
iconPainter: Painter?,
271+
headlineContent: @Composable () -> Unit,
272+
modifier: Modifier = Modifier,
273+
overlineContent: @Composable () -> Unit = {},
274+
supportingContent: @Composable () -> Unit = {},
275+
trailingContent: @Composable () -> Unit = {},
276+
) {
277+
OutlinedCard(modifier) {
278+
ListItem(
279+
headlineContent = headlineContent,
280+
overlineContent = overlineContent,
281+
supportingContent = supportingContent,
282+
leadingContent = {
283+
iconPainter?.let {
284+
CircularIcon(painter = it)
285+
}
286+
},
287+
trailingContent = trailingContent,
288+
)
281289
}
282290
}
283291

284292
@Preview
285293
@Composable
286294
private fun DeviceListItemPreview() {
287295
DeviceListItem(
288-
peripheralIcon = painterResource(R.drawable.outline_bluetooth_24),
296+
iconPainter = painterResource(R.drawable.outline_bluetooth_24),
289297
title = "Nordic HRM",
290298
subtitle = "12:34:56:78:9A:BC",
291299
trailingContent = {
@@ -354,7 +362,7 @@ private fun ScannerContentPreview() {
354362
peripheral = PreviewPeripheral(
355363
scope = scope,
356364
name = "A device with a very long name",
357-
address = "00:11:22:33:44:55",
365+
address = "00000000-1234-1234-5678-1234567890AB",
358366
),
359367
isConnectable = true,
360368
advertisingData = AdvertisingData(raw = byteArrayOf(0x02, 0x01, 0x06)),

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ dependencyResolutionManagement {
6868
versionCatalogs {
6969
// Use Nordic Gradle Version Catalog with common external libraries versions.
7070
create("libs") {
71-
from("no.nordicsemi.android.gradle:version-catalog:2.12")
71+
from("no.nordicsemi.android.gradle:version-catalog:2.12-1")
7272
}
7373
// Fixed versions for Nordic libraries.
7474
create("nordic") {

theme/src/main/res/drawable/ic_signal_max.xml

Lines changed: 0 additions & 46 deletions
This file was deleted.

theme/src/main/res/drawable/ic_signal_medium.xml

Lines changed: 0 additions & 46 deletions
This file was deleted.

theme/src/main/res/drawable/ic_signal_min.xml

Lines changed: 0 additions & 46 deletions
This file was deleted.

ui/src/main/java/no/nordicsemi/android/common/ui/view/CircularIcon.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fun CircularIcon(
6969
modifier: Modifier = Modifier,
7070
backgroundColor: Color = MaterialTheme.colorScheme.secondary,
7171
enabled: Boolean = true,
72-
size: Dp = 36.dp,
72+
size: Dp = 40.dp,
7373
iconSize: Dp = 24.dp,
7474
) {
7575
val padding = (size - iconSize) / 2

ui/src/main/java/no/nordicsemi/android/common/ui/view/RssiIcon.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ import androidx.compose.foundation.Image
3636
import androidx.compose.foundation.layout.Arrangement
3737
import androidx.compose.foundation.layout.Column
3838
import androidx.compose.foundation.layout.Row
39+
import androidx.compose.foundation.layout.size
3940
import androidx.compose.material3.MaterialTheme
4041
import androidx.compose.material3.Text
4142
import androidx.compose.runtime.Composable
4243
import androidx.compose.ui.Alignment
44+
import androidx.compose.ui.Modifier
4345
import androidx.compose.ui.res.painterResource
4446
import androidx.compose.ui.res.stringResource
4547
import androidx.compose.ui.tooling.preview.Preview
@@ -62,25 +64,24 @@ fun RssiIcon(rssi: Int) {
6264
) {
6365
Image(
6466
painter = painterResource(id = getImageRes(rssi)),
65-
contentDescription = null
67+
contentDescription = null,
68+
modifier = Modifier.size(24.dp),
6669
)
6770
Text(
6871
text = stringResource(id = R.string.dbm, rssi),
69-
style = MaterialTheme.typography.labelSmall
72+
style = MaterialTheme.typography.bodySmall
7073
)
7174
}
7275
}
7376

7477
@DrawableRes
75-
private fun getImageRes(rssi: Int): Int {
76-
return when {
77-
rssi < MEDIUM_RSSI -> R.drawable.ic_signal_min
78-
rssi < MAX_RSSI -> R.drawable.ic_signal_medium
79-
else -> R.drawable.ic_signal_max
80-
}
78+
private fun getImageRes(rssi: Int): Int = when {
79+
rssi < MEDIUM_RSSI -> R.drawable.ic_signal_min
80+
rssi < MAX_RSSI -> R.drawable.ic_signal_medium
81+
else -> R.drawable.ic_signal_max
8182
}
8283

83-
@Preview(showBackground = true, widthDp = 500)
84+
@Preview(showBackground = true, widthDp = 520)
8485
@Composable
8586
private fun RssiIconPreview() {
8687
MaterialTheme {

ui/src/main/res/values-night/colors.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
<resources>
3434

3535
<color name="appBarColor">#333f48</color>
36-
<color name="colorError">#FFB4A9</color>
36+
<!--<color name="colorError">#FFB4A9</color>
3737
<color name="colorWarning">#F58220</color>
38-
<color name="colorSuccess">#00A651</color>
38+
<color name="colorSuccess">#00A651</color>-->
3939
<color name="colorNeutral">#899296</color>
4040
<color name="colorNordicLogo">@android:color/white</color>
4141
<color name="colorNordicLogoText">@android:color/white</color>

ui/src/main/res/values/colors.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434

3535
<color name="appBarColor">#00A9CE</color>
3636
<color name="colorError">#BA1B1B</color>
37-
<color name="colorWarning">#F58220</color>
38-
<color name="colorSuccess">#00A651</color>
37+
<color name="colorWarning">#f1750b</color>
38+
<color name="colorSuccess">#008d45</color>
3939
<color name="colorNeutral">#70787C</color>
4040
<color name="colorNordicLogo">#00A9CE</color>
4141
<color name="colorNordicLogoText">@android:color/black</color>

0 commit comments

Comments
 (0)