kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
refactor: ensure `Channel` and `ChannelSettings` indexes match
rodzic
76d01af995
commit
67fedb9ff8
|
@ -51,12 +51,15 @@ class ChannelSetRepository @Inject constructor(
|
||||||
* Updates the [ChannelSettings] list with the provided channel.
|
* Updates the [ChannelSettings] list with the provided channel.
|
||||||
*/
|
*/
|
||||||
suspend fun updateChannelSettings(channel: Channel) {
|
suspend fun updateChannelSettings(channel: Channel) {
|
||||||
|
if (channel.role == Channel.Role.DISABLED) return
|
||||||
channelSetStore.updateData { preference ->
|
channelSetStore.updateData { preference ->
|
||||||
if (preference.settingsCount > channel.index) {
|
val builder = preference.toBuilder()
|
||||||
preference.toBuilder().setSettings(channel.index, channel.settings).build()
|
// Resize to fit channel
|
||||||
} else {
|
while (builder.settingsCount <= channel.index) {
|
||||||
preference.toBuilder().addSettings(channel.settings).build()
|
builder.addSettings(ChannelSettings.getDefaultInstance())
|
||||||
}
|
}
|
||||||
|
// use setSettings() to ensure settingsList and channel indexes match
|
||||||
|
builder.setSettings(channel.index, channel.settings).build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue