mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Redundant methods in RadioConfigRepository (#3198)
This commit is contained in:
parent
8be9c38ae6
commit
8317b704ea
13 changed files with 97 additions and 171 deletions
|
|
@ -22,29 +22,14 @@ import com.geeksville.mesh.ChannelProtos.Channel
|
|||
import com.geeksville.mesh.ChannelProtos.ChannelSettings
|
||||
import com.geeksville.mesh.ClientOnlyProtos.DeviceProfile
|
||||
import com.geeksville.mesh.ConfigProtos.Config
|
||||
import com.geeksville.mesh.IMeshService
|
||||
import com.geeksville.mesh.LocalOnlyProtos.LocalConfig
|
||||
import com.geeksville.mesh.LocalOnlyProtos.LocalModuleConfig
|
||||
import com.geeksville.mesh.MeshProtos
|
||||
import com.geeksville.mesh.MeshProtos.DeviceMetadata
|
||||
import com.geeksville.mesh.MeshProtos.MeshPacket
|
||||
import com.geeksville.mesh.ModuleConfigProtos.ModuleConfig
|
||||
import com.geeksville.mesh.database.NodeRepository
|
||||
import com.geeksville.mesh.deviceProfile
|
||||
import com.geeksville.mesh.model.getChannelUrl
|
||||
import com.geeksville.mesh.service.ConnectionState
|
||||
import com.geeksville.mesh.service.ServiceAction
|
||||
import com.geeksville.mesh.service.ServiceRepository
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.first
|
||||
import org.meshtastic.core.database.entity.MetadataEntity
|
||||
import org.meshtastic.core.database.entity.MyNodeEntity
|
||||
import org.meshtastic.core.database.entity.NodeEntity
|
||||
import org.meshtastic.core.database.model.Node
|
||||
import org.meshtastic.core.datastore.ChannelSetDataSource
|
||||
import org.meshtastic.core.datastore.LocalConfigDataSource
|
||||
import org.meshtastic.core.datastore.ModuleConfigDataSource
|
||||
|
|
@ -57,54 +42,11 @@ import javax.inject.Inject
|
|||
class RadioConfigRepository
|
||||
@Inject
|
||||
constructor(
|
||||
private val serviceRepository: ServiceRepository,
|
||||
private val nodeDB: NodeRepository,
|
||||
private val channelSetDataSource: ChannelSetDataSource,
|
||||
private val localConfigDataSource: LocalConfigDataSource,
|
||||
private val moduleConfigDataSource: ModuleConfigDataSource,
|
||||
) {
|
||||
val meshService: IMeshService?
|
||||
get() = serviceRepository.meshService
|
||||
|
||||
// Connection state to our radio device
|
||||
val connectionState
|
||||
get() = serviceRepository.connectionState
|
||||
|
||||
fun setConnectionState(state: ConnectionState) = serviceRepository.setConnectionState(state)
|
||||
|
||||
/** Flow representing the unique userId of our node. */
|
||||
val myId: StateFlow<String?>
|
||||
get() = nodeDB.myId
|
||||
|
||||
/** Flow representing the [MyNodeEntity] database. */
|
||||
val myNodeInfo: StateFlow<MyNodeEntity?>
|
||||
get() = nodeDB.myNodeInfo
|
||||
|
||||
/** Flow representing the [Node] database. */
|
||||
val nodeDBbyNum: StateFlow<Map<Int, Node>>
|
||||
get() = nodeDB.nodeDBbyNum
|
||||
|
||||
fun getUser(nodeNum: Int) = nodeDB.getUser(nodeNum)
|
||||
|
||||
suspend fun getNodeDBbyNum() = nodeDB.getNodeDBbyNum().first()
|
||||
|
||||
suspend fun upsert(node: NodeEntity) = nodeDB.upsert(node)
|
||||
|
||||
suspend fun installMyNodeInfo(mi: MyNodeEntity) {
|
||||
nodeDB.installMyNodeInfo(mi)
|
||||
}
|
||||
|
||||
suspend fun installNodeDb(nodes: List<NodeEntity>) {
|
||||
nodeDB.installNodeDb(nodes)
|
||||
}
|
||||
|
||||
suspend fun insertMetadata(fromNum: Int, metadata: DeviceMetadata) {
|
||||
nodeDB.insertMetadata(MetadataEntity(fromNum, metadata))
|
||||
}
|
||||
|
||||
suspend fun clearNodeDB() {
|
||||
nodeDB.clearNodeDB()
|
||||
}
|
||||
|
||||
/** Flow representing the [ChannelSet] data store. */
|
||||
val channelSetFlow: Flow<ChannelSet> = channelSetDataSource.channelSetFlow
|
||||
|
|
@ -185,50 +127,4 @@ constructor(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
val clientNotification = serviceRepository.clientNotification
|
||||
|
||||
fun setClientNotification(notification: MeshProtos.ClientNotification?) {
|
||||
serviceRepository.setClientNotification(notification)
|
||||
}
|
||||
|
||||
fun clearClientNotification() {
|
||||
serviceRepository.clearClientNotification()
|
||||
}
|
||||
|
||||
val errorMessage: StateFlow<String?>
|
||||
get() = serviceRepository.errorMessage
|
||||
|
||||
fun setErrorMessage(text: String) {
|
||||
serviceRepository.setErrorMessage(text)
|
||||
}
|
||||
|
||||
fun clearErrorMessage() {
|
||||
serviceRepository.clearErrorMessage()
|
||||
}
|
||||
|
||||
fun setStatusMessage(text: String) {
|
||||
serviceRepository.setStatusMessage(text)
|
||||
}
|
||||
|
||||
val meshPacketFlow: SharedFlow<MeshPacket>
|
||||
get() = serviceRepository.meshPacketFlow
|
||||
|
||||
suspend fun emitMeshPacket(packet: MeshPacket) = coroutineScope { serviceRepository.emitMeshPacket(packet) }
|
||||
|
||||
val serviceAction: Flow<ServiceAction>
|
||||
get() = serviceRepository.serviceAction
|
||||
|
||||
suspend fun onServiceAction(action: ServiceAction) = coroutineScope { serviceRepository.onServiceAction(action) }
|
||||
|
||||
val tracerouteResponse: StateFlow<String?>
|
||||
get() = serviceRepository.tracerouteResponse
|
||||
|
||||
fun setTracerouteResponse(value: String?) {
|
||||
serviceRepository.setTracerouteResponse(value)
|
||||
}
|
||||
|
||||
fun clearTracerouteResponse() {
|
||||
setTracerouteResponse(null)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package com.geeksville.mesh.repository.network
|
|||
|
||||
import com.geeksville.mesh.MeshProtos.MqttClientProxyMessage
|
||||
import com.geeksville.mesh.android.Logging
|
||||
import com.geeksville.mesh.database.NodeRepository
|
||||
import com.geeksville.mesh.model.subscribeList
|
||||
import com.geeksville.mesh.mqttClientProxyMessage
|
||||
import com.geeksville.mesh.repository.datastore.RadioConfigRepository
|
||||
|
|
@ -44,7 +45,12 @@ import javax.net.ssl.SSLContext
|
|||
import javax.net.ssl.TrustManager
|
||||
|
||||
@Singleton
|
||||
class MQTTRepository @Inject constructor(private val radioConfigRepository: RadioConfigRepository) : Logging {
|
||||
class MQTTRepository
|
||||
@Inject
|
||||
constructor(
|
||||
private val radioConfigRepository: RadioConfigRepository,
|
||||
private val nodeRepository: NodeRepository,
|
||||
) : Logging {
|
||||
|
||||
companion object {
|
||||
/**
|
||||
|
|
@ -73,7 +79,7 @@ class MQTTRepository @Inject constructor(private val radioConfigRepository: Radi
|
|||
}
|
||||
|
||||
val proxyMessageFlow: Flow<MqttClientProxyMessage> = callbackFlow {
|
||||
val ownerId = "MeshtasticAndroidMqttProxy-${radioConfigRepository.myId.value ?: generateClientId()}"
|
||||
val ownerId = "MeshtasticAndroidMqttProxy-${nodeRepository.myId.value ?: generateClientId()}"
|
||||
val channelSet = radioConfigRepository.channelSetFlow.first()
|
||||
val mqttConfig = radioConfigRepository.moduleConfigFlow.first().mqtt
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue