fix: ensure proper channel updates to ChannelSetRepository

This commit is contained in:
andrekir 2023-05-21 06:04:53 -03:00
parent a2388d1d12
commit 8151aceea4
5 changed files with 70 additions and 38 deletions

View file

@ -67,8 +67,6 @@ import com.geeksville.mesh.NodeInfo
import com.geeksville.mesh.Portnums
import com.geeksville.mesh.R
import com.geeksville.mesh.android.Logging
import com.geeksville.mesh.channel
import com.geeksville.mesh.channelSettings
import com.geeksville.mesh.config
import com.geeksville.mesh.deviceProfile
import com.geeksville.mesh.model.UIViewModel
@ -391,20 +389,7 @@ fun RadioConfigNavHost(node: NodeInfo, viewModel: UIViewModel = viewModel()) {
focusManager = focusManager,
onSaveClicked = { channelListInput ->
focusManager.clearFocus()
(0 until channelList.size.coerceAtLeast(channelListInput.size)).map { i ->
channel {
role = when (i) {
0 -> ChannelProtos.Channel.Role.PRIMARY
in 1 until channelListInput.size -> ChannelProtos.Channel.Role.SECONDARY
else -> ChannelProtos.Channel.Role.DISABLED
}
index = i
settings = channelListInput.getOrNull(i) ?: channelSettings { }
}
}.forEach { newChannel ->
if (newChannel.settings != channelList.getOrNull(newChannel.index))
viewModel.setRemoteChannel(destNum, newChannel)
}
viewModel.updateChannels(destNum, channelList, channelListInput)
channelList.clear()
channelList.addAll(channelListInput)
}