mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Move last heard in node info to compose (#878)
* 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
This commit is contained in:
parent
0095fc95d7
commit
8f312e5d16
3 changed files with 75 additions and 30 deletions
49
app/src/main/java/com/geeksville/mesh/ui/LastHeardInfo.kt
Normal file
49
app/src/main/java/com/geeksville/mesh/ui/LastHeardInfo.kt
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
package com.geeksville.mesh.ui
|
||||
|
||||
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
|
||||
import com.geeksville.mesh.util.formatAgo
|
||||
|
||||
@Composable
|
||||
fun LastHeardInfo(
|
||||
lastHeard: Int
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(2.dp)
|
||||
) {
|
||||
Icon(
|
||||
modifier = Modifier.height(18.dp),
|
||||
imageVector = ImageVector.vectorResource(id = R.drawable.ic_antenna_24),
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colors.onSurface,
|
||||
)
|
||||
Text(
|
||||
text = formatAgo(lastHeard),
|
||||
color = MaterialTheme.colors.onSurface,
|
||||
fontSize = MaterialTheme.typography.button.fontSize
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
@Preview(showBackground = true)
|
||||
@Preview(showBackground = true, uiMode = android.content.res.Configuration.UI_MODE_NIGHT_YES)
|
||||
fun LastHeardInfoPreview() {
|
||||
AppTheme {
|
||||
LastHeardInfo((System.currentTimeMillis() / 1000).toInt() - 8600)
|
||||
}
|
||||
}
|
||||
|
|
@ -27,7 +27,6 @@ import com.geeksville.mesh.databinding.AdapterNodeLayoutBinding
|
|||
import com.geeksville.mesh.databinding.NodelistFragmentBinding
|
||||
import com.geeksville.mesh.model.UIViewModel
|
||||
import com.geeksville.mesh.ui.theme.AppTheme
|
||||
import com.geeksville.mesh.util.formatAgo
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
|
@ -55,12 +54,12 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
|||
val chipNode = itemView.chipNode
|
||||
val nodeNameView = itemView.nodeNameView
|
||||
val distanceView = itemView.distanceView
|
||||
val lastTime = itemView.lastConnectionView
|
||||
val signalView = itemView.signalView
|
||||
val envMetrics = itemView.envMetrics
|
||||
val background = itemView.nodeCard
|
||||
val nodePosition = itemView.nodePosition
|
||||
val batteryInfo = itemView.batteryInfo
|
||||
val lastHeard = itemView.lastHeardInfo
|
||||
|
||||
fun blink() {
|
||||
val bg = background.backgroundTintList
|
||||
|
|
@ -88,7 +87,8 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
|||
voltage: Float?,
|
||||
position: Position?,
|
||||
gpsFormat: Int,
|
||||
nodeName: String?
|
||||
nodeName: String?,
|
||||
lastHeard: Int
|
||||
) {
|
||||
batteryInfo.setContent {
|
||||
AppTheme {
|
||||
|
|
@ -100,6 +100,11 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
|||
LinkedCoordinates(position, gpsFormat, nodeName)
|
||||
}
|
||||
}
|
||||
this.lastHeard.setContent {
|
||||
AppTheme {
|
||||
LastHeardInfo(lastHeard)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -250,14 +255,15 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
|||
val isIgnored: Boolean = ignoreIncomingList.contains(n.num)
|
||||
val name = user?.longName
|
||||
|
||||
holder.bind(n.batteryLevel, n.voltage, n.validPosition, gpsFormat, name)
|
||||
holder.bind(n.batteryLevel, n.voltage, n.validPosition, gpsFormat, name, n.lastHeard)
|
||||
|
||||
holder.nodeNameView.text = name
|
||||
|
||||
with(holder.chipNode) {
|
||||
text = (user?.shortName ?: "UNK").strikeIf(isIgnored)
|
||||
chipBackgroundColor = ColorStateList.valueOf(nodeColor)
|
||||
setTextColor(textColor)
|
||||
}
|
||||
holder.nodeNameView.text = name
|
||||
|
||||
val ourNodeInfo = nodes[0]
|
||||
val distance = ourNodeInfo.distanceStr(n, displayUnits)
|
||||
|
|
@ -268,8 +274,6 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
|||
holder.distanceView.visibility = View.INVISIBLE
|
||||
}
|
||||
|
||||
holder.lastTime.text = formatAgo(n.lastHeard)
|
||||
|
||||
val envMetrics = n.envMetricStr(displayFahrenheit)
|
||||
if (envMetrics.isNotEmpty()) {
|
||||
holder.envMetrics.text = envMetrics
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue