Merge pull request #482 from meshtastic/env

add EnvironmentMetrics to nodes tab
pull/483/head
Andre K 2022-09-12 18:30:02 -03:00 zatwierdzone przez GitHub
commit 382535da47
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 30 dodań i 2 usunięć

Wyświetl plik

@ -156,6 +156,17 @@ data class NodeInfo(
val voltage get() = deviceMetrics?.voltage
val batteryStr get() = if (batteryLevel in 1..100) String.format("%d%%", batteryLevel) else ""
private fun envFormat(f: String, unit: String, env: Float?): String =
if (env != null && env > 0f) String.format(f + unit, env) else ""
val envMetricStr
get() = envFormat("%.1f", "°C ", environmentMetrics?.temperature) +
envFormat("%.0f", "%% ", environmentMetrics?.relativeHumidity) +
envFormat("%.1f", "hPa ", environmentMetrics?.barometricPressure) +
envFormat("%.0f", "", environmentMetrics?.gasResistance) +
envFormat("%.2f", "V ", environmentMetrics?.voltage) +
envFormat("%.1f", "mA", environmentMetrics?.current)
/**
* true if the device was heard from recently
*

Wyświetl plik

@ -42,6 +42,7 @@ class UsersFragment : ScreenFragment("Users"), Logging {
val lastTime = itemView.lastConnectionView
val powerIcon = itemView.batteryIcon
val signalView = itemView.signalView
val envMetrics = itemView.envMetrics
}
private val nodesAdapter = object : RecyclerView.Adapter<ViewHolder>() {
@ -136,6 +137,13 @@ class UsersFragment : ScreenFragment("Users"), Logging {
holder.lastTime.text = formatAgo(n.lastHeard)
if (n.envMetricStr.isNotEmpty()) {
holder.envMetrics.text = n.envMetricStr
holder.envMetrics.visibility = View.VISIBLE
} else {
holder.envMetrics.visibility = View.GONE
}
if (n.num == ourNodeInfo?.num) {
val info = model.myNodeInfo.value
if (info != null) {

Wyświetl plik

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false">
@ -116,7 +115,17 @@
android:text="rssi:-40 snr:-8"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/lastConnectionView"
app:layout_constraintBottom_toBottomOf="parent" />
app:layout_constraintBottom_toTopOf="@id/envMetrics" />
<TextView
android:id="@+id/envMetrics"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>