From 1a11c3351b85b9b51abe3a79088446490022184e Mon Sep 17 00:00:00 2001 From: James Rich <2199651+jamesarich@users.noreply.github.com> Date: Sun, 2 Mar 2025 06:12:07 -0600 Subject: [PATCH] Refactor NodeDetail.kt to use has*() functions (#1627) Modified NodeDetail.kt to replace direct comparisons with 0f or 0 for sensor values with corresponding has*() functions. This change improves code readability by clearly indicating the presence or absence of sensor data. --- .../java/com/geeksville/mesh/ui/NodeDetail.kt | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/ui/NodeDetail.kt b/app/src/main/java/com/geeksville/mesh/ui/NodeDetail.kt index c14de547..e416af9e 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/NodeDetail.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/NodeDetail.kt @@ -439,21 +439,21 @@ private fun EnvironmentMetrics( horizontalArrangement = Arrangement.SpaceBetween, verticalArrangement = Arrangement.SpaceEvenly, ) { - if (temperature != 0f) { + if (hasTemperature()) { InfoCard( icon = Icons.Default.Thermostat, text = "Temperature", value = temperature.toTempString(isFahrenheit) ) } - if (relativeHumidity != 0f) { + if (hasRelativeHumidity()) { InfoCard( icon = Icons.Default.WaterDrop, text = "Humidity", value = "%.0f%%".format(relativeHumidity) ) } - if (temperature != 0f && relativeHumidity != 0f) { + if (hasTemperature() && hasRelativeHumidity()) { val dewPoint = calculateDewPoint(temperature, relativeHumidity) InfoCard( icon = ImageVector.vectorResource(R.drawable.ic_outlined_dew_point_24), @@ -461,49 +461,49 @@ private fun EnvironmentMetrics( value = dewPoint.toTempString(isFahrenheit) ) } - if (barometricPressure != 0f) { + if (hasBarometricPressure()) { InfoCard( icon = Icons.Default.Speed, text = "Pressure", value = "%.0f hPa".format(barometricPressure) ) } - if (gasResistance != 0f) { + if (hasGasResistance()) { InfoCard( icon = Icons.Default.BlurOn, text = "Gas Resistance", value = "%.0f MΩ".format(gasResistance) ) } - if (voltage != 0f) { + if (hasVoltage()) { InfoCard( icon = Icons.Default.Bolt, text = "Voltage", value = "%.2fV".format(voltage) ) } - if (current != 0f) { + if (hasCurrent()) { InfoCard( icon = Icons.Default.Power, text = "Current", value = "%.1fmA".format(current) ) } - if (iaq != 0) { + if (hasIaq()) { InfoCard( icon = Icons.Default.Air, text = "IAQ", value = iaq.toString() ) } - if (distance != 0f) { + if (hasDistance()) { InfoCard( icon = Icons.Default.Height, text = "Distance", value = "%.0f mm".format(distance) ) } - if (lux != 0f) { + if (hasLux()) { InfoCard( icon = Icons.Default.LightMode, text = "Lux", @@ -520,14 +520,14 @@ private fun EnvironmentMetrics( rotateIcon = normalizedBearing.toFloat(), ) } - if (weight != 0f) { + if (hasWeight()) { InfoCard( icon = Icons.Default.Scale, text = "Weight", value = "%.2f kg".format(weight) ) } - if (radiation != 0f) { + if (hasRadiation()) { InfoCard( icon = ImageVector.vectorResource(R.drawable.ic_filled_radioactive_24), text = "Radiation",