From 8f312e5d16c04f71412a77058ab88e81ebbd44bf Mon Sep 17 00:00:00 2001 From: Davis Date: Wed, 28 Feb 2024 07:29:13 -0700 Subject: [PATCH] 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 --- .../com/geeksville/mesh/ui/LastHeardInfo.kt | 49 +++++++++++++++++++ .../com/geeksville/mesh/ui/UsersFragment.kt | 18 ++++--- .../main/res/layout/adapter_node_layout.xml | 38 ++++++-------- 3 files changed, 75 insertions(+), 30 deletions(-) create mode 100644 app/src/main/java/com/geeksville/mesh/ui/LastHeardInfo.kt diff --git a/app/src/main/java/com/geeksville/mesh/ui/LastHeardInfo.kt b/app/src/main/java/com/geeksville/mesh/ui/LastHeardInfo.kt new file mode 100644 index 000000000..4fe38330e --- /dev/null +++ b/app/src/main/java/com/geeksville/mesh/ui/LastHeardInfo.kt @@ -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) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/geeksville/mesh/ui/UsersFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/UsersFragment.kt index 396ff9f73..a573d2afa 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/UsersFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/UsersFragment.kt @@ -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 diff --git a/app/src/main/res/layout/adapter_node_layout.xml b/app/src/main/res/layout/adapter_node_layout.xml index 9753c3c5f..15c15b4e5 100644 --- a/app/src/main/res/layout/adapter_node_layout.xml +++ b/app/src/main/res/layout/adapter_node_layout.xml @@ -47,9 +47,11 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintTop_toBottomOf="@+id/chip_node" - app:layout_constraintEnd_toEndOf="@+id/chip_node" + app:layout_constraintBottom_toTopOf="@id/envMetrics" app:layout_constraintStart_toStartOf="@+id/chip_node" - android:layout_marginTop="8dp" + app:layout_constraintEnd_toEndOf="@+id/chip_node" + android:layout_marginVertical="8dp" + app:layout_constraintVertical_bias="0" tools:text="@string/sample_distance" /> @@ -73,36 +75,26 @@ tools:composableName="com.geeksville.mesh.ui.BatteryInfoKt.BatteryInfoPreviewSimple" /> - - - @@ -110,12 +102,12 @@ android:id="@+id/envMetrics" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_marginTop="8dp" android:visibility="gone" app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent" tools:visibility="visible" + tools:background="@android:color/holo_red_light" />