From df9025695980859691f08c6853b7d01b8c2d42ea Mon Sep 17 00:00:00 2001 From: Phil Oliver <3497406+poliver@users.noreply.github.com> Date: Wed, 17 Sep 2025 17:05:59 -0400 Subject: [PATCH] Re-add "set region" CTA (#3129) --- .../mesh/ui/common/components/TitledCard.kt | 14 ++++--- .../mesh/ui/connections/ConnectionsScreen.kt | 39 ++++++++++--------- app/src/main/res/values/strings.xml | 1 - 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/ui/common/components/TitledCard.kt b/app/src/main/java/com/geeksville/mesh/ui/common/components/TitledCard.kt index a84724df0..90573b3c1 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/common/components/TitledCard.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/common/components/TitledCard.kt @@ -35,13 +35,15 @@ import androidx.compose.ui.unit.dp import com.geeksville.mesh.ui.common.theme.AppTheme @Composable -fun TitledCard(title: String, modifier: Modifier = Modifier, content: @Composable ColumnScope.() -> Unit) { +fun TitledCard(title: String?, modifier: Modifier = Modifier, content: @Composable ColumnScope.() -> Unit) { Column(modifier = modifier, verticalArrangement = Arrangement.spacedBy(8.dp)) { - Text( - title, - modifier = Modifier.padding(horizontal = 16.dp).fillMaxWidth(), - style = MaterialTheme.typography.titleLarge, - ) + title?.let { + Text( + text = it, + modifier = Modifier.padding(horizontal = 16.dp).fillMaxWidth(), + style = MaterialTheme.typography.titleLarge, + ) + } Card(content = content) } diff --git a/app/src/main/java/com/geeksville/mesh/ui/connections/ConnectionsScreen.kt b/app/src/main/java/com/geeksville/mesh/ui/connections/ConnectionsScreen.kt index aa31e4a9d..0200c8199 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/connections/ConnectionsScreen.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/connections/ConnectionsScreen.kt @@ -21,6 +21,7 @@ import android.net.InetAddresses import android.os.Build import android.util.Patterns import androidx.compose.animation.AnimatedVisibility +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.IntrinsicSize @@ -34,6 +35,8 @@ import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.selection.selectable import androidx.compose.foundation.selection.selectableGroup import androidx.compose.foundation.verticalScroll +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.rounded.Language import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.Text @@ -61,15 +64,18 @@ import com.geeksville.mesh.model.BTScanModel import com.geeksville.mesh.model.BluetoothViewModel import com.geeksville.mesh.model.DeviceListEntry import com.geeksville.mesh.model.Node +import com.geeksville.mesh.navigation.ConfigRoute import com.geeksville.mesh.navigation.Route import com.geeksville.mesh.navigation.SettingsRoutes import com.geeksville.mesh.navigation.getNavRouteFrom import com.geeksville.mesh.service.ConnectionState +import com.geeksville.mesh.ui.common.components.TitledCard import com.geeksville.mesh.ui.connections.components.BLEDevices import com.geeksville.mesh.ui.connections.components.ConnectionsSegmentedBar import com.geeksville.mesh.ui.connections.components.CurrentlyConnectedCard import com.geeksville.mesh.ui.connections.components.NetworkDevices import com.geeksville.mesh.ui.connections.components.UsbDevices +import com.geeksville.mesh.ui.settings.components.SettingsItem import com.geeksville.mesh.ui.settings.radio.RadioConfigViewModel import com.geeksville.mesh.ui.settings.radio.components.PacketResponseStateDialog import com.geeksville.mesh.ui.sharing.SharedContactDialog @@ -101,7 +107,6 @@ fun ConnectionsScreen( ) { val radioConfigState by radioConfigViewModel.radioConfigState.collectAsStateWithLifecycle() val config by connectionsViewModel.localConfig.collectAsStateWithLifecycle() - val currentRegion = config.lora.region val scrollState = rememberScrollState() val scanStatusText by scanModel.errorText.observeAsState("") val connectionState by @@ -111,8 +116,7 @@ fun ConnectionsScreen( val info by connectionsViewModel.myNodeInfo.collectAsStateWithLifecycle() val selectedDevice by scanModel.selectedNotNullFlow.collectAsStateWithLifecycle() val bluetoothEnabled by bluetoothViewModel.enabled.collectAsStateWithLifecycle(false) - val regionUnset = - currentRegion == ConfigProtos.Config.LoRaConfig.RegionCode.UNSET && connectionState == ConnectionState.CONNECTED + val regionUnset = config.lora.region == ConfigProtos.Config.LoRaConfig.RegionCode.UNSET val bleDevices by scanModel.bleDevicesForUi.collectAsStateWithLifecycle() val discoveredTcpDevices by scanModel.discoveredTcpDevicesForUi.collectAsStateWithLifecycle() @@ -186,7 +190,7 @@ fun ConnectionsScreen( visible = connectionState.isConnected(), modifier = Modifier.padding(bottom = 16.dp), ) { - Column { + Column(verticalArrangement = Arrangement.spacedBy(16.dp)) { ourNode?.let { node -> Text( stringResource(R.string.connected_device), @@ -204,24 +208,21 @@ fun ConnectionsScreen( onClickDisconnect = { scanModel.disconnect() }, ) } + + if (regionUnset && selectedDevice != "m") { + TitledCard(title = null) { + SettingsItem( + leadingIcon = Icons.Rounded.Language, + text = stringResource(id = R.string.set_your_region), + ) { + isWaiting = true + radioConfigViewModel.setResponseStateLoading(ConfigRoute.LORA) + } + } + } } } - /*val setRegionText = stringResource(id = R.string.set_your_region) - val actionText = stringResource(id = R.string.action_go) - LaunchedEffect(connectionState.isConnected() && regionUnset && selectedDevice != "m") { - if (connectionState.isConnected() && regionUnset && selectedDevice != "m") { - uiViewModel.showSnackBar( - text = setRegionText, - actionLabel = actionText, - onActionPerformed = { - isWaiting = true - radioConfigViewModel.setResponseStateLoading(ConfigRoute.LORA) - }, - ) - } - }*/ - var selectedDeviceType by remember { mutableStateOf(DeviceType.BLE) } LaunchedEffect(selectedDevice) { DeviceType.fromAddress(selectedDevice)?.let { type -> selectedDeviceType = type } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3e03f5b77..006942df7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -728,7 +728,6 @@ BLE Devices Paired Devices Connected Device - Go Rate Limit Exceeded. Please try again later. View Release