diff --git a/app/src/main/java/com/geeksville/mesh/model/UIState.kt b/app/src/main/java/com/geeksville/mesh/model/UIState.kt index 841c4804..6bb24106 100644 --- a/app/src/main/java/com/geeksville/mesh/model/UIState.kt +++ b/app/src/main/java/com/geeksville/mesh/model/UIState.kt @@ -509,7 +509,6 @@ class UIViewModel @Inject constructor( private fun setRemoteChannel(destNum: Int, channel: ChannelProtos.Channel) { try { - debug("Sending channel ${channel.index} to $destNum") meshService?.setRemoteChannel(destNum, channel.toByteArray()) } catch (ex: RemoteException) { errormsg("Can't set channel on radio ${ex.message}") diff --git a/app/src/main/java/com/geeksville/mesh/ui/DeviceSettingsFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/DeviceSettingsFragment.kt index 894c72f2..c7fd91a5 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/DeviceSettingsFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/DeviceSettingsFragment.kt @@ -69,6 +69,7 @@ import com.geeksville.mesh.R import com.geeksville.mesh.android.Logging import com.geeksville.mesh.config import com.geeksville.mesh.deviceProfile +import com.geeksville.mesh.model.Channel import com.geeksville.mesh.model.UIViewModel import com.geeksville.mesh.moduleConfig import com.geeksville.mesh.service.MeshService @@ -256,22 +257,20 @@ fun RadioConfigNavHost(node: NodeInfo, viewModel: UIViewModel = viewModel()) { when (parsed.payloadVariantCase) { AdminProtos.AdminMessage.PayloadVariantCase.GET_CHANNEL_RESPONSE -> { val response = parsed.getChannelResponse + channelList.add(response.index, response.settings) + (packetResponseState as PacketResponseState.Loading).completed++ if (response.index + 1 < maxChannels) { // Stop once we get to the first disabled entry if (response.role != ChannelProtos.Channel.Role.DISABLED) { // Not done yet, request next channel - (packetResponseState as PacketResponseState.Loading).completed++ - channelList.add(response.index, response.settings) viewModel.getChannel(destNum, response.index + 1) } else { - // Received the last channel, start channel editor - packetResponseState = PacketResponseState.Empty - navController.navigate("channels") + // Received last channel, get lora config (for default channel names) + viewModel.getConfig(destNum, ConfigType.LORA_CONFIG_VALUE) } } else { - // Received max channels, start channel editor - packetResponseState = PacketResponseState.Empty - navController.navigate("channels") + // Received max channels, get lora config (for default channel names) + viewModel.getConfig(destNum, ConfigType.LORA_CONFIG_VALUE) } } @@ -282,10 +281,13 @@ fun RadioConfigNavHost(node: NodeInfo, viewModel: UIViewModel = viewModel()) { } AdminProtos.AdminMessage.PayloadVariantCase.GET_CONFIG_RESPONSE -> { + // check destination: lora config or channel editor + val goChannels = (packetResponseState as PacketResponseState.Loading).total > 1 packetResponseState = PacketResponseState.Empty val response = parsed.getConfigResponse radioConfig = response - enumValues().find { it.name == "${response.payloadVariantCase}" } + if (goChannels) navController.navigate("channels") + else enumValues().find { it.name == "${response.payloadVariantCase}" } ?.let { navController.navigate(it.route) } } @@ -329,7 +331,8 @@ fun RadioConfigNavHost(node: NodeInfo, viewModel: UIViewModel = viewModel()) { when (configType) { "USER" -> { viewModel.getOwner(destNum) } "CHANNELS" -> { - (packetResponseState as PacketResponseState.Loading).total = maxChannels + val maxPackets = maxChannels + 1 // for lora config + (packetResponseState as PacketResponseState.Loading).total = maxPackets channelList.clear() viewModel.getChannel(destNum, 0) } @@ -384,15 +387,16 @@ fun RadioConfigNavHost(node: NodeInfo, viewModel: UIViewModel = viewModel()) { composable("channels") { ChannelSettingsItemList( settingsList = channelList, + modemPresetName = Channel(Channel.default.settings, radioConfig.lora).name, enabled = connected, maxChannels = maxChannels, focusManager = focusManager, - onSaveClicked = { channelListInput -> + onPositiveClicked = { channelListInput -> focusManager.clearFocus() viewModel.updateChannels(destNum, channelList, channelListInput) channelList.clear() channelList.addAll(channelListInput) - } + }, ) } composable("user") { diff --git a/app/src/main/java/com/geeksville/mesh/ui/components/config/ChannelSettingsItemList.kt b/app/src/main/java/com/geeksville/mesh/ui/components/config/ChannelSettingsItemList.kt index 24a739e3..910d2a67 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/components/config/ChannelSettingsItemList.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/components/config/ChannelSettingsItemList.kt @@ -86,24 +86,6 @@ fun ChannelCard( } } -@Composable -fun ChannelSettingsItemList( - settingsList: List, - maxChannels: Int = 8, - enabled: Boolean, - focusManager: FocusManager, - onSaveClicked: (List) -> Unit, -) { - ChannelSettingsItemList( - settingsList = settingsList, - maxChannels = maxChannels, - enabled = enabled, - focusManager = focusManager, - onPositiveClicked = onSaveClicked, - onNegativeClicked = { } - ) -} - @Composable fun ChannelSettingsItemList( settingsList: List, @@ -111,7 +93,7 @@ fun ChannelSettingsItemList( maxChannels: Int = 8, enabled: Boolean, focusManager: FocusManager, - onNegativeClicked: () -> Unit, + onNegativeClicked: () -> Unit = { }, @StringRes positiveText: Int = R.string.send, onPositiveClicked: (List) -> Unit, ) { @@ -215,6 +197,6 @@ fun ChannelSettingsPreview() { ), enabled = true, focusManager = LocalFocusManager.current, - onSaveClicked = { }, + onPositiveClicked = { }, ) }