Skip to content

Commit 41f45c3

Browse files
authored
Merge pull request #154 from NordicPlayground/bugfix/scanner
Bug fix: Long device names take too much space
2 parents e7c046f + 65548a5 commit 41f45c3

File tree

1 file changed

+21
-26
lines changed
  • scanner-ble/src/main/java/no/nordicsemi/android/common/scanner/view

1 file changed

+21
-26
lines changed

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

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import androidx.compose.foundation.layout.Arrangement
3737
import androidx.compose.foundation.layout.Box
3838
import androidx.compose.foundation.layout.Column
3939
import androidx.compose.foundation.layout.Row
40-
import androidx.compose.foundation.layout.Spacer
4140
import androidx.compose.foundation.layout.WindowInsets
4241
import androidx.compose.foundation.layout.WindowInsetsSides
4342
import androidx.compose.foundation.layout.asPaddingValues
@@ -67,6 +66,7 @@ import androidx.compose.ui.Modifier
6766
import androidx.compose.ui.draw.clip
6867
import androidx.compose.ui.res.painterResource
6968
import androidx.compose.ui.res.stringResource
69+
import androidx.compose.ui.text.style.TextOverflow
7070
import androidx.compose.ui.unit.dp
7171
import androidx.hilt.navigation.compose.hiltViewModel
7272
import androidx.lifecycle.compose.collectAsStateWithLifecycle
@@ -234,33 +234,28 @@ internal fun DeviceListItem(
234234
}
235235

236236
Column(
237-
horizontalAlignment = Alignment.Start,
238237
verticalArrangement = Arrangement.spacedBy(4.dp),
238+
modifier = Modifier.weight(1.0f)
239239
) {
240-
Row {
241-
Column(
242-
verticalArrangement = Arrangement.spacedBy(4.dp)
243-
) {
244-
val name = result.advertisingData.name ?: result.peripheral.name
245-
Text(
246-
text = name ?: stringResource(R.string.no_name),
247-
color = if (name != null) {
248-
MaterialTheme.colorScheme.onSurface
249-
} else {
250-
MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
251-
},
252-
style = MaterialTheme.typography.titleMedium,
253-
)
254-
Text(
255-
text = result.peripheral.address,
256-
style = MaterialTheme.typography.bodyMedium,
257-
)
258-
}
259-
Spacer(modifier = Modifier.weight(1f))
260-
261-
// Show RSSI if available
262-
RssiIcon(result.rssi)
263-
}
240+
val name = result.advertisingData.name ?: result.peripheral.name
241+
Text(
242+
text = name ?: stringResource(R.string.no_name),
243+
color = if (name != null) {
244+
MaterialTheme.colorScheme.onSurface
245+
} else {
246+
MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
247+
},
248+
maxLines = 2,
249+
overflow = TextOverflow.Ellipsis,
250+
style = MaterialTheme.typography.titleMedium,
251+
)
252+
Text(
253+
text = result.peripheral.address,
254+
style = MaterialTheme.typography.bodyMedium,
255+
)
264256
}
257+
258+
// Show RSSI if available
259+
RssiIcon(result.rssi)
265260
}
266261
}

0 commit comments

Comments
 (0)