Add elevation and number of GPS satellites to node info (#895)

* Move battery info to compose - always show voltage level and icons to match battery percentage
Use tool text in preview, rather than actually set text value
Simplify node info layout to avoid defining margins on everything

* Move node position to Compose

* Update hyperlink color to match previous value

* Use compose preview in layout editor

* Use compose preview in layout editor

* Add simple preview for use in layout

* Move last heard node info to Compose
Clean up layout of node info

* Move signal info to Compose and simplify bind

* Prevent long coordinates from colliding with signal info

* Move the rest of the node info card to compose
Breaks the blinking feature when navigating from chat
Wrap position to new line if overflow

* Adjust layout and text sizing to closer match original

* Use constraint layout for tighter display on busy nodes

* Construct environment metrics so that there aren't trailing spaces if current is zero

* Swap viewholder root for compose view rather than inflating layout
Fix padding lost when changing out view holder root
Intelligently update the list with only nodes that changed

* Remove unused method, and adjust replacement method to match the same decimal precisions as before

* Add elevation and number of GPS satellites to node info list
Add some extension functions for easier conversion between units and systems

* Dispose composition on recycle to avoid lingering spacing from previous layouts
Remove comments explaning adapter functionality
Remove unused methods

* Use previous string for denoting unknown node names

* Align properly if altitude but no signal info
This commit is contained in:
Davis 2024-03-07 02:34:43 -07:00 committed by GitHub
parent 1468b26d3b
commit 248982d14c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 240 additions and 77 deletions

View file

@ -0,0 +1,46 @@
package com.geeksville.mesh.ui.compose
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview
import com.geeksville.mesh.ConfigProtos.Config.DisplayConfig.DisplayUnits
import com.geeksville.mesh.util.toString
@Composable
fun ElevationInfo(
modifier: Modifier = Modifier,
altitude: Float,
system: DisplayUnits,
suffix: String
) {
val annotatedString = buildAnnotatedString {
append(altitude.toString(system))
MaterialTheme.typography.overline.toSpanStyle().let { style ->
withStyle(style) {
append(" $suffix")
}
}
}
Text(
modifier = modifier,
fontSize = MaterialTheme.typography.button.fontSize,
text = annotatedString,
)
}
@Composable
@Preview
fun ElevationInfoPreview() {
MaterialTheme {
ElevationInfo(
altitude = 100.0f,
system = DisplayUnits.METRIC,
suffix = "ASL"
)
}
}

View file

@ -0,0 +1,57 @@
package com.geeksville.mesh.ui.compose
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.height
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.geeksville.mesh.R
import com.geeksville.mesh.ui.theme.AppTheme
@Composable
fun SatelliteCountInfo(
modifier: Modifier = Modifier,
satCount: Int,
) {
Row(
modifier = modifier,
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(4.dp)
) {
Icon(
modifier = Modifier.height(18.dp),
imageVector = ImageVector.vectorResource(id = R.drawable.ic_satellite),
contentDescription = null,
tint = MaterialTheme.colors.onSurface,
)
Text(
text = "$satCount",
fontSize = MaterialTheme.typography.button.fontSize,
color = MaterialTheme.colors.onSurface,
)
}
}
@Composable
@Preview(
showBackground = true,
uiMode = android.content.res.Configuration.UI_MODE_NIGHT_YES
)
@Preview(
showBackground = true,
)
fun SatelliteCountInfoPreview() {
AppTheme {
SatelliteCountInfo(
satCount = 5,
)
}
}