mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-02-15 10:14:30 -05:00
refactor: Improve IAQ display to add ranges, update colors (#1300)
* Refactor: Improve IAQ display and add ranges Adds IAQ ranges to the `Iaq` enum and updates the display to show the ranges alongside the descriptions, improving clarity for users. This change enhances the indoor air quality information by providing context for the different IAQ levels. * Refactor: Improve IAQ color scheme and add range to description This commit refactors the Indoor Air Quality (IAQ) component by: - Updating the color scheme to better reflect air quality levels, using a more standardized and recognizable color palette. - Adding the IAQ range to the description, providing more context and clarity to the user. - Adding a preview for the IAQ scale. - Minor code cleanup and improvements.
This commit is contained in:
@@ -42,40 +42,41 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.geeksville.mesh.R
|
||||
|
||||
enum class Iaq(val color: Color, val description: String) {
|
||||
Excellent(Color.Green, "Excellent"),
|
||||
Good(Color.Green, "Good"),
|
||||
LightlyPolluted(Color.Yellow, "Lightly Polluted"),
|
||||
ModeratelyPolluted(Color.Orange, "Moderately Polluted"),
|
||||
HeavilyPolluted(Color.Red, "Heavily Polluted"),
|
||||
SeverelyPolluted(Color.Purple, "Severely Polluted"),
|
||||
ExtremelyPolluted(Color.Purple, "Extremely Polluted"),
|
||||
DangerouslyPolluted(Color.Brown, "Dangerously Polluted")
|
||||
@Suppress("MagicNumber")
|
||||
enum class Iaq(val color: Color, val description: String, val range: IntRange) {
|
||||
Excellent(Color(0xFF00E400), "Excellent", 0..50),
|
||||
Good(Color(0xFF92D050), "Good", 51..100),
|
||||
LightlyPolluted(Color(0xFFFFFF00), "Lightly Polluted", 101..150),
|
||||
ModeratelyPolluted(Color(0xFFFF7300), "Moderately Polluted", 151..200),
|
||||
HeavilyPolluted(Color(0xFFFF0000), "Heavily Polluted", 201..300),
|
||||
SeverelyPolluted(Color(0xFF99004C), "Severely Polluted", 301..400),
|
||||
ExtremelyPolluted(Color(0xFF663300), "Extremely Polluted", 401..500),
|
||||
DangerouslyPolluted(Color(0xFF663300), "Dangerously Polluted", 501..Int.MAX_VALUE)
|
||||
}
|
||||
|
||||
val Color.Companion.Mint: Color
|
||||
get() = Color(0xFF98FB98)
|
||||
val Color.Companion.Purple: Color
|
||||
get() = Color(0xFF800080)
|
||||
val Color.Companion.Brown: Color
|
||||
get() = Color(0xFFA52A2A)
|
||||
val Color.Companion.Orange: Color
|
||||
get() = Color(0xFFFFA500)
|
||||
|
||||
@Suppress("MagicNumber")
|
||||
|
||||
fun getIaq(iaq: Int): Iaq {
|
||||
return when {
|
||||
iaq <= 50 -> Iaq.Excellent
|
||||
iaq <= 100 -> Iaq.Good
|
||||
iaq <= 150 -> Iaq.LightlyPolluted
|
||||
iaq <= 200 -> Iaq.ModeratelyPolluted
|
||||
iaq <= 300 -> Iaq.HeavilyPolluted
|
||||
iaq <= 400 -> Iaq.SeverelyPolluted
|
||||
iaq <= 500 -> Iaq.ExtremelyPolluted
|
||||
iaq in Iaq.Excellent.range -> Iaq.Excellent
|
||||
iaq in Iaq.Good.range -> Iaq.Good
|
||||
iaq in Iaq.LightlyPolluted.range -> Iaq.LightlyPolluted
|
||||
iaq in Iaq.ModeratelyPolluted.range -> Iaq.ModeratelyPolluted
|
||||
iaq in Iaq.HeavilyPolluted.range -> Iaq.HeavilyPolluted
|
||||
iaq in Iaq.SeverelyPolluted.range -> Iaq.SeverelyPolluted
|
||||
iaq in Iaq.ExtremelyPolluted.range -> Iaq.ExtremelyPolluted
|
||||
else -> Iaq.DangerouslyPolluted
|
||||
}
|
||||
}
|
||||
|
||||
private fun getIaqDescriptionWithRange(iaqEnum: Iaq): String {
|
||||
return if (iaqEnum.range.last == Int.MAX_VALUE){
|
||||
"${iaqEnum.description} (${iaqEnum.range.first}+)"
|
||||
} else {
|
||||
"${iaqEnum.description} (${iaqEnum.range.first}-${iaqEnum.range.last})"
|
||||
}
|
||||
}
|
||||
|
||||
enum class IaqDisplayMode {
|
||||
Pill, Dot, Text, Gauge, Gradient
|
||||
}
|
||||
@@ -86,10 +87,7 @@ fun IndoorAirQuality(iaq: Int, displayMode: IaqDisplayMode = IaqDisplayMode.Pill
|
||||
var isLegendOpen by remember { mutableStateOf(false) }
|
||||
val iaqEnum = getIaq(iaq)
|
||||
val gradient = Brush.linearGradient(
|
||||
colors = listOf(
|
||||
Color.Green, Color.Mint, Color.Yellow, Color.Orange, Color.Red,
|
||||
Color.Purple, Color.Purple, Color.Brown, Color.Brown, Color.Brown, Color.Brown
|
||||
)
|
||||
colors = Iaq.entries.map { it.color },
|
||||
)
|
||||
|
||||
Column {
|
||||
@@ -139,7 +137,7 @@ fun IndoorAirQuality(iaq: Int, displayMode: IaqDisplayMode = IaqDisplayMode.Pill
|
||||
|
||||
IaqDisplayMode.Text -> {
|
||||
Text(
|
||||
text = iaqEnum.description,
|
||||
text = getIaqDescriptionWithRange(iaqEnum),
|
||||
fontSize = 12.sp,
|
||||
modifier = Modifier.clickable { isLegendOpen = true }
|
||||
)
|
||||
@@ -221,13 +219,19 @@ fun IAQScale(modifier: Modifier = Modifier) {
|
||||
.background(iaq.color)
|
||||
)
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
Text(iaq.description, style = MaterialTheme.typography.body2)
|
||||
Text(getIaqDescriptionWithRange(iaq), style = MaterialTheme.typography.body2)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
fun IAQScalePreview() {
|
||||
IAQScale()
|
||||
}
|
||||
|
||||
@Suppress("LongMethod")
|
||||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
|
||||
Reference in New Issue
Block a user