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
pull/879/head^2
Davis 2024-02-28 07:29:13 -07:00 zatwierdzone przez GitHub
rodzic 0095fc95d7
commit 8f312e5d16
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
3 zmienionych plików z 75 dodań i 30 usunięć

Wyświetl plik

@ -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)
}
}

Wyświetl plik

@ -27,7 +27,6 @@ import com.geeksville.mesh.databinding.AdapterNodeLayoutBinding
import com.geeksville.mesh.databinding.NodelistFragmentBinding import com.geeksville.mesh.databinding.NodelistFragmentBinding
import com.geeksville.mesh.model.UIViewModel import com.geeksville.mesh.model.UIViewModel
import com.geeksville.mesh.ui.theme.AppTheme import com.geeksville.mesh.ui.theme.AppTheme
import com.geeksville.mesh.util.formatAgo
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -55,12 +54,12 @@ class UsersFragment : ScreenFragment("Users"), Logging {
val chipNode = itemView.chipNode val chipNode = itemView.chipNode
val nodeNameView = itemView.nodeNameView val nodeNameView = itemView.nodeNameView
val distanceView = itemView.distanceView val distanceView = itemView.distanceView
val lastTime = itemView.lastConnectionView
val signalView = itemView.signalView val signalView = itemView.signalView
val envMetrics = itemView.envMetrics val envMetrics = itemView.envMetrics
val background = itemView.nodeCard val background = itemView.nodeCard
val nodePosition = itemView.nodePosition val nodePosition = itemView.nodePosition
val batteryInfo = itemView.batteryInfo val batteryInfo = itemView.batteryInfo
val lastHeard = itemView.lastHeardInfo
fun blink() { fun blink() {
val bg = background.backgroundTintList val bg = background.backgroundTintList
@ -88,7 +87,8 @@ class UsersFragment : ScreenFragment("Users"), Logging {
voltage: Float?, voltage: Float?,
position: Position?, position: Position?,
gpsFormat: Int, gpsFormat: Int,
nodeName: String? nodeName: String?,
lastHeard: Int
) { ) {
batteryInfo.setContent { batteryInfo.setContent {
AppTheme { AppTheme {
@ -100,6 +100,11 @@ class UsersFragment : ScreenFragment("Users"), Logging {
LinkedCoordinates(position, gpsFormat, nodeName) 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 isIgnored: Boolean = ignoreIncomingList.contains(n.num)
val name = user?.longName 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) { with(holder.chipNode) {
text = (user?.shortName ?: "UNK").strikeIf(isIgnored) text = (user?.shortName ?: "UNK").strikeIf(isIgnored)
chipBackgroundColor = ColorStateList.valueOf(nodeColor) chipBackgroundColor = ColorStateList.valueOf(nodeColor)
setTextColor(textColor) setTextColor(textColor)
} }
holder.nodeNameView.text = name
val ourNodeInfo = nodes[0] val ourNodeInfo = nodes[0]
val distance = ourNodeInfo.distanceStr(n, displayUnits) val distance = ourNodeInfo.distanceStr(n, displayUnits)
@ -268,8 +274,6 @@ class UsersFragment : ScreenFragment("Users"), Logging {
holder.distanceView.visibility = View.INVISIBLE holder.distanceView.visibility = View.INVISIBLE
} }
holder.lastTime.text = formatAgo(n.lastHeard)
val envMetrics = n.envMetricStr(displayFahrenheit) val envMetrics = n.envMetricStr(displayFahrenheit)
if (envMetrics.isNotEmpty()) { if (envMetrics.isNotEmpty()) {
holder.envMetrics.text = envMetrics holder.envMetrics.text = envMetrics

Wyświetl plik

@ -47,9 +47,11 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/chip_node" 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" 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" tools:text="@string/sample_distance"
/> />
@ -73,36 +75,26 @@
tools:composableName="com.geeksville.mesh.ui.BatteryInfoKt.BatteryInfoPreviewSimple" tools:composableName="com.geeksville.mesh.ui.BatteryInfoKt.BatteryInfoPreviewSimple"
/> />
<ImageView <androidx.compose.ui.platform.ComposeView
android:id="@+id/lastCommIcon" android:id="@+id/lastHeardInfo"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="2dp" app:layout_constraintTop_toBottomOf="@+id/batteryInfo"
android:layout_marginBottom="8dp"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="@id/signalView"
app:layout_constraintEnd_toStartOf="@+id/lastConnectionView"
app:layout_constraintTop_toBottomOf="@id/batteryInfo"
app:srcCompat="@drawable/ic_antenna_24" />
<TextView
android:id="@+id/lastConnectionView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
app:layout_constraintTop_toTopOf="@+id/lastCommIcon"
app:layout_constraintBottom_toBottomOf="@+id/lastCommIcon"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
tools:text="11h01 PM" android:layout_marginTop="4dp"
tools:composableName="com.geeksville.mesh.ui.LastHeardInfoKt.LastHeardInfoPreview"
/> />
<TextView <TextView
android:id="@+id/signalView" android:id="@+id/signalView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/lastConnectionView" app:layout_constraintTop_toBottomOf="@id/lastHeardInfo"
app:layout_constraintBottom_toTopOf="@id/envMetrics" app:layout_constraintBottom_toTopOf="@id/envMetrics"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintVertical_bias="0"
android:layout_marginTop="4dp"
android:layout_marginBottom="8dp"
tools:text="RSSI: -40 SNR: -8" tools:text="RSSI: -40 SNR: -8"
/> />
@ -110,12 +102,12 @@
android:id="@+id/envMetrics" android:id="@+id/envMetrics"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:visibility="gone" android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:visibility="visible" tools:visibility="visible"
tools:background="@android:color/holo_red_light"
/> />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>