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

@ -35,6 +35,18 @@ class ChannelSetRepository @Inject constructor(
}
}
suspend fun clearSettings() {
channelSetStore.updateData { preference ->
preference.toBuilder().clearSettings().build()
}
}
suspend fun addAllSettings(settingsList: List<ChannelSettings>) {
channelSetStore.updateData { preference ->
preference.toBuilder().addAllSettings(settingsList).build()
}
}
/**
* Updates the [ChannelSettings] list with the provided channel and returns the index of the
* admin channel after the update (if not found, returns 0).
@ -42,11 +54,7 @@ class ChannelSetRepository @Inject constructor(
suspend fun updateChannelSettings(channel: Channel): Int {
channelSetStore.updateData { preference ->
if (preference.settingsCount > channel.index) {
if (channel.role == Channel.Role.DISABLED) {
preference.toBuilder().removeSettings(channel.index).build()
} else {
preference.toBuilder().setSettings(channel.index, channel.settings).build()
}
preference.toBuilder().setSettings(channel.index, channel.settings).build()
} else {
preference.toBuilder().addSettings(channel.settings).build()
}

View file

@ -31,6 +31,14 @@ class RadioConfigRepository @Inject constructor(
channelSetRepository.clearChannelSet()
}
/**
* Replaces the [ChannelSettings] list with a new [settingsList].
*/
suspend fun replaceAllSettings(settingsList: List<ChannelSettings>) {
channelSetRepository.clearSettings()
channelSetRepository.addAllSettings(settingsList)
}
/**
* Updates the [ChannelSettings] list with the provided channel and returns the index of the
* admin channel after the update (if not found, returns 0).