From 9648d0af7734a179f5880855ceda59574f1a1065 Mon Sep 17 00:00:00 2001 From: James Rich <2199651+jamesarich@users.noreply.github.com> Date: Thu, 1 May 2025 19:05:32 -0500 Subject: [PATCH] refactor: extract more hardcoded strings (#1814) --- .../com/geeksville/mesh/ui/ChannelFragment.kt | 2 +- .../java/com/geeksville/mesh/ui/NodeDetail.kt | 38 +++++++++---------- .../mesh/ui/components/IndoorAirQuality.kt | 2 +- .../components/StoreForwardConfigItemList.kt | 2 +- app/src/main/res/values/strings.xml | 11 ++++++ 5 files changed, 33 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt index 330b3c9a6..aac7cf548 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt @@ -439,7 +439,7 @@ private fun EditChannelUrl( }, modifier = modifier.fillMaxWidth(), enabled = enabled, - label = { Text("URL") }, + label = { Text(stringResource(R.string.url)) }, isError = isError, trailingIcon = { val isUrlEqual = valueState == channelUrl 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 4bb51421b..b207346df 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/NodeDetail.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/NodeDetail.kt @@ -466,14 +466,14 @@ private fun EnvironmentMetrics( if (hasTemperature()) { InfoCard( icon = Icons.Default.Thermostat, - text = "Temperature", + text = stringResource(R.string.temperature), value = temperature.toTempString(isFahrenheit) ) } if (hasRelativeHumidity()) { InfoCard( icon = Icons.Default.WaterDrop, - text = "Humidity", + text = stringResource(R.string.humidity), value = "%.0f%%".format(relativeHumidity) ) } @@ -481,56 +481,56 @@ private fun EnvironmentMetrics( val dewPoint = calculateDewPoint(temperature, relativeHumidity) InfoCard( icon = ImageVector.vectorResource(R.drawable.ic_outlined_dew_point_24), - text = "Dew Point", + text = stringResource(R.string.dew_point), value = dewPoint.toTempString(isFahrenheit) ) } if (hasBarometricPressure()) { InfoCard( icon = Icons.Default.Speed, - text = "Pressure", + text = stringResource(R.string.pressure), value = "%.0f hPa".format(barometricPressure) ) } if (hasGasResistance()) { InfoCard( icon = Icons.Default.BlurOn, - text = "Gas Resistance", + text = stringResource(R.string.gas_resistance), value = "%.0f MΩ".format(gasResistance) ) } if (hasVoltage()) { InfoCard( icon = Icons.Default.Bolt, - text = "Voltage", + text = stringResource(R.string.voltage), value = "%.2fV".format(voltage) ) } if (hasCurrent()) { InfoCard( icon = Icons.Default.Power, - text = "Current", + text = stringResource(R.string.current), value = "%.1fmA".format(current) ) } if (hasIaq()) { InfoCard( icon = Icons.Default.Air, - text = "IAQ", + text = stringResource(R.string.iaq), value = iaq.toString() ) } if (hasDistance()) { InfoCard( icon = Icons.Default.Height, - text = "Distance", + text = stringResource(R.string.distance), value = "%.0f mm".format(distance) ) } if (hasLux()) { InfoCard( icon = Icons.Default.LightMode, - text = "Lux", + text = stringResource(R.string.lux), value = "%.0f lx".format(lux) ) } @@ -539,7 +539,7 @@ private fun EnvironmentMetrics( val normalizedBearing = (windDirection % 360 + 360) % 360 InfoCard( icon = Icons.Outlined.Navigation, - text = "Wind", + text = stringResource(R.string.wind), value = windSpeed.toSpeedString(), rotateIcon = normalizedBearing.toFloat(), ) @@ -547,14 +547,14 @@ private fun EnvironmentMetrics( if (hasWeight()) { InfoCard( icon = Icons.Default.Scale, - text = "Weight", + text = stringResource(R.string.weight), value = "%.2f kg".format(weight) ) } if (hasRadiation()) { InfoCard( icon = ImageVector.vectorResource(R.drawable.ic_filled_radioactive_24), - text = "Radiation", + text = stringResource(R.string.radiation), value = "%.1f µR/h".format(radiation) ) } @@ -595,12 +595,12 @@ private fun PowerMetrics(node: Node) = with(node.powerMetrics) { Column { InfoCard( icon = Icons.Default.Bolt, - text = "Channel 1", + text = stringResource(R.string.channel_1), value = "%.2fV".format(ch1Voltage) ) InfoCard( icon = Icons.Default.Power, - text = "Channel 1", + text = stringResource(R.string.channel_1), value = "%.1fmA".format(ch1Current) ) } @@ -609,12 +609,12 @@ private fun PowerMetrics(node: Node) = with(node.powerMetrics) { Column { InfoCard( icon = Icons.Default.Bolt, - text = "Channel 2", + text = stringResource(R.string.channel_2), value = "%.2fV".format(ch2Voltage) ) InfoCard( icon = Icons.Default.Power, - text = "Channel 2", + text = stringResource(R.string.channel_2), value = "%.1fmA".format(ch2Current) ) } @@ -623,12 +623,12 @@ private fun PowerMetrics(node: Node) = with(node.powerMetrics) { Column { InfoCard( icon = Icons.Default.Bolt, - text = "Channel 3", + text = stringResource(R.string.channel_3), value = "%.2fV".format(ch3Voltage) ) InfoCard( icon = Icons.Default.Power, - text = "Channel 3", + text = stringResource(R.string.channel_3), value = "%.1fmA".format(ch3Current) ) } diff --git a/app/src/main/java/com/geeksville/mesh/ui/components/IndoorAirQuality.kt b/app/src/main/java/com/geeksville/mesh/ui/components/IndoorAirQuality.kt index 4c578eece..271a95bd8 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/components/IndoorAirQuality.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/components/IndoorAirQuality.kt @@ -217,7 +217,7 @@ fun IAQScale(modifier: Modifier = Modifier) { horizontalAlignment = Alignment.Start ) { Text( - text = "Indoor Air Quality (IAQ)", + text = stringResource(R.string.indoor_air_quality_iaq), style = MaterialTheme.typography.h6.copy( fontWeight = FontWeight.Bold, textAlign = TextAlign.Center, diff --git a/app/src/main/java/com/geeksville/mesh/ui/radioconfig/components/StoreForwardConfigItemList.kt b/app/src/main/java/com/geeksville/mesh/ui/radioconfig/components/StoreForwardConfigItemList.kt index 6f8db329b..93deeb443 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/radioconfig/components/StoreForwardConfigItemList.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/radioconfig/components/StoreForwardConfigItemList.kt @@ -77,7 +77,7 @@ fun StoreForwardConfigItemList( LazyColumn( modifier = Modifier.fillMaxSize() ) { - item { PreferenceCategory(text = "Store & Forward Config") } + item { PreferenceCategory(text = stringResource(R.string.store_forward_config)) } item { SwitchPreference( diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 79871e81c..667d63d62 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -581,4 +581,15 @@ Short name Hardware model Licensed amateur radio + Dew Point + Pressure + Gas Resistance + Distance + Lux + Wind + Weight + Radiation + + Indoor Air Quality (IAQ) + URL