diff --git a/app/src/main/java/com/geeksville/mesh/repository/datastore/ChannelSetRepository.kt b/app/src/main/java/com/geeksville/mesh/repository/datastore/ChannelSetRepository.kt index 7d476222..8ab147b7 100644 --- a/app/src/main/java/com/geeksville/mesh/repository/datastore/ChannelSetRepository.kt +++ b/app/src/main/java/com/geeksville/mesh/repository/datastore/ChannelSetRepository.kt @@ -48,10 +48,9 @@ class ChannelSetRepository @Inject constructor( } /** - * Updates the [ChannelSettings] list with the provided channel and returns the index of the - * admin channel after the update (if not found, returns 0). + * Updates the [ChannelSettings] list with the provided channel. */ - suspend fun updateChannelSettings(channel: Channel): Int { + suspend fun updateChannelSettings(channel: Channel) { channelSetStore.updateData { preference -> if (preference.settingsCount > channel.index) { preference.toBuilder().setSettings(channel.index, channel.settings).build() @@ -59,7 +58,6 @@ class ChannelSetRepository @Inject constructor( preference.toBuilder().addSettings(channel.settings).build() } } - return getAdminChannel() } suspend fun setLoraConfig(config: ConfigProtos.Config.LoRaConfig) { @@ -68,13 +66,6 @@ class ChannelSetRepository @Inject constructor( } } - /** - * Returns the index of the admin channel (or 0 if not found). - */ - private suspend fun getAdminChannel(): Int = fetchInitialChannelSet()?.settingsList - ?.indexOfFirst { it.name.lowercase() == "admin" } - ?.coerceAtLeast(0) ?: 0 - suspend fun fetchInitialChannelSet() = channelSetStore.data.firstOrNull() } diff --git a/app/src/main/java/com/geeksville/mesh/repository/datastore/RadioConfigRepository.kt b/app/src/main/java/com/geeksville/mesh/repository/datastore/RadioConfigRepository.kt index fd0cc9fa..f8131754 100644 --- a/app/src/main/java/com/geeksville/mesh/repository/datastore/RadioConfigRepository.kt +++ b/app/src/main/java/com/geeksville/mesh/repository/datastore/RadioConfigRepository.kt @@ -45,7 +45,7 @@ class RadioConfigRepository @Inject constructor( * @param channel The [Channel] provided. * @return the index of the admin channel after the update (if not found, returns 0). */ - suspend fun updateChannelSettings(channel: Channel): Int { + suspend fun updateChannelSettings(channel: Channel) { return channelSetRepository.updateChannelSettings(channel) } diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt index 858b5f3d..e14d7437 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -456,7 +456,8 @@ class MeshService : Service(), Logging { private val myNodeID get() = toNodeID(myNodeNum) /// Admin channel index - private var adminChannelIndex: Int = 0 + private val adminChannelIndex: Int + get() = channelSet.settingsList.map { it.name.lowercase() }.indexOf("admin") /// Generate a new mesh packet builder with our node as the sender, and the specified node num private fun newMeshPacketTo(idNum: Int) = MeshPacket.newBuilder().apply { @@ -958,7 +959,7 @@ class MeshService : Service(), Logging { } private fun updateChannelSettings(ch: ChannelProtos.Channel) = serviceScope.handledLaunch { - adminChannelIndex = radioConfigRepository.updateChannelSettings(ch) + radioConfigRepository.updateChannelSettings(ch) } private fun currentSecond() = (System.currentTimeMillis() / 1000).toInt()