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.
pull/1629/head
James Rich 2025-03-02 06:12:07 -06:00 zatwierdzone przez GitHub
rodzic b316e066ad
commit 1a11c3351b
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
1 zmienionych plików z 12 dodań i 12 usunięć

Wyświetl plik

@ -439,21 +439,21 @@ private fun EnvironmentMetrics(
horizontalArrangement = Arrangement.SpaceBetween, horizontalArrangement = Arrangement.SpaceBetween,
verticalArrangement = Arrangement.SpaceEvenly, verticalArrangement = Arrangement.SpaceEvenly,
) { ) {
if (temperature != 0f) { if (hasTemperature()) {
InfoCard( InfoCard(
icon = Icons.Default.Thermostat, icon = Icons.Default.Thermostat,
text = "Temperature", text = "Temperature",
value = temperature.toTempString(isFahrenheit) value = temperature.toTempString(isFahrenheit)
) )
} }
if (relativeHumidity != 0f) { if (hasRelativeHumidity()) {
InfoCard( InfoCard(
icon = Icons.Default.WaterDrop, icon = Icons.Default.WaterDrop,
text = "Humidity", text = "Humidity",
value = "%.0f%%".format(relativeHumidity) value = "%.0f%%".format(relativeHumidity)
) )
} }
if (temperature != 0f && relativeHumidity != 0f) { if (hasTemperature() && hasRelativeHumidity()) {
val dewPoint = calculateDewPoint(temperature, relativeHumidity) val dewPoint = calculateDewPoint(temperature, relativeHumidity)
InfoCard( InfoCard(
icon = ImageVector.vectorResource(R.drawable.ic_outlined_dew_point_24), icon = ImageVector.vectorResource(R.drawable.ic_outlined_dew_point_24),
@ -461,49 +461,49 @@ private fun EnvironmentMetrics(
value = dewPoint.toTempString(isFahrenheit) value = dewPoint.toTempString(isFahrenheit)
) )
} }
if (barometricPressure != 0f) { if (hasBarometricPressure()) {
InfoCard( InfoCard(
icon = Icons.Default.Speed, icon = Icons.Default.Speed,
text = "Pressure", text = "Pressure",
value = "%.0f hPa".format(barometricPressure) value = "%.0f hPa".format(barometricPressure)
) )
} }
if (gasResistance != 0f) { if (hasGasResistance()) {
InfoCard( InfoCard(
icon = Icons.Default.BlurOn, icon = Icons.Default.BlurOn,
text = "Gas Resistance", text = "Gas Resistance",
value = "%.0f MΩ".format(gasResistance) value = "%.0f MΩ".format(gasResistance)
) )
} }
if (voltage != 0f) { if (hasVoltage()) {
InfoCard( InfoCard(
icon = Icons.Default.Bolt, icon = Icons.Default.Bolt,
text = "Voltage", text = "Voltage",
value = "%.2fV".format(voltage) value = "%.2fV".format(voltage)
) )
} }
if (current != 0f) { if (hasCurrent()) {
InfoCard( InfoCard(
icon = Icons.Default.Power, icon = Icons.Default.Power,
text = "Current", text = "Current",
value = "%.1fmA".format(current) value = "%.1fmA".format(current)
) )
} }
if (iaq != 0) { if (hasIaq()) {
InfoCard( InfoCard(
icon = Icons.Default.Air, icon = Icons.Default.Air,
text = "IAQ", text = "IAQ",
value = iaq.toString() value = iaq.toString()
) )
} }
if (distance != 0f) { if (hasDistance()) {
InfoCard( InfoCard(
icon = Icons.Default.Height, icon = Icons.Default.Height,
text = "Distance", text = "Distance",
value = "%.0f mm".format(distance) value = "%.0f mm".format(distance)
) )
} }
if (lux != 0f) { if (hasLux()) {
InfoCard( InfoCard(
icon = Icons.Default.LightMode, icon = Icons.Default.LightMode,
text = "Lux", text = "Lux",
@ -520,14 +520,14 @@ private fun EnvironmentMetrics(
rotateIcon = normalizedBearing.toFloat(), rotateIcon = normalizedBearing.toFloat(),
) )
} }
if (weight != 0f) { if (hasWeight()) {
InfoCard( InfoCard(
icon = Icons.Default.Scale, icon = Icons.Default.Scale,
text = "Weight", text = "Weight",
value = "%.2f kg".format(weight) value = "%.2f kg".format(weight)
) )
} }
if (radiation != 0f) { if (hasRadiation()) {
InfoCard( InfoCard(
icon = ImageVector.vectorResource(R.drawable.ic_filled_radioactive_24), icon = ImageVector.vectorResource(R.drawable.ic_filled_radioactive_24),
text = "Radiation", text = "Radiation",