Redundant methods in RadioConfigRepository (#3198)

This commit is contained in:
Phil Oliver 2025-09-25 09:57:26 -04:00 committed by GitHub
parent 8be9c38ae6
commit 8317b704ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 97 additions and 171 deletions

View file

@ -28,7 +28,7 @@ import com.geeksville.mesh.StoreAndForwardProtos
import com.geeksville.mesh.TelemetryProtos
import com.geeksville.mesh.android.Logging
import com.geeksville.mesh.database.MeshLogRepository
import com.geeksville.mesh.repository.datastore.RadioConfigRepository
import com.geeksville.mesh.database.NodeRepository
import com.geeksville.mesh.ui.debug.FilterMode
import com.google.protobuf.InvalidProtocolBufferException
import dagger.hilt.android.lifecycle.HiltViewModel
@ -202,7 +202,7 @@ class DebugViewModel
@Inject
constructor(
private val meshLogRepository: MeshLogRepository,
private val radioConfigRepository: RadioConfigRepository,
private val nodeRepository: NodeRepository,
) : ViewModel(),
Logging {
@ -345,7 +345,7 @@ constructor(
val presetFilters: List<String>
get() = buildList {
// Our address if available
radioConfigRepository.myNodeInfo.value?.myNodeNum?.let { add("!%08x".format(it)) }
nodeRepository.myNodeInfo.value?.myNodeNum?.let { add("!%08x".format(it)) }
// broadcast
add("!ffffffff")
// decoded

View file

@ -36,10 +36,12 @@ import com.geeksville.mesh.Portnums.PortNum
import com.geeksville.mesh.TelemetryProtos.Telemetry
import com.geeksville.mesh.android.Logging
import com.geeksville.mesh.database.MeshLogRepository
import com.geeksville.mesh.database.NodeRepository
import com.geeksville.mesh.repository.api.DeviceHardwareRepository
import com.geeksville.mesh.repository.api.FirmwareReleaseRepository
import com.geeksville.mesh.repository.datastore.RadioConfigRepository
import com.geeksville.mesh.service.ServiceAction
import com.geeksville.mesh.service.ServiceRepository
import com.geeksville.mesh.util.safeNumber
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
@ -203,7 +205,9 @@ constructor(
private val app: Application,
private val dispatchers: CoroutineDispatchers,
private val meshLogRepository: MeshLogRepository,
private val radioConfigRepository: RadioConfigRepository,
radioConfigRepository: RadioConfigRepository,
private val serviceRepository: ServiceRepository,
private val nodeRepository: NodeRepository,
private val deviceHardwareRepository: DeviceHardwareRepository,
private val firmwareReleaseRepository: FirmwareReleaseRepository,
private val mapPrefs: MapPrefs,
@ -233,7 +237,7 @@ constructor(
return Node(num = nodeNum, user = defaultUser)
}
fun getUser(nodeNum: Int) = radioConfigRepository.getUser(nodeNum)
fun getUser(nodeNum: Int) = nodeRepository.getUser(nodeNum)
val tileSource
get() = CustomTileSource.getTileSource(mapPrefs.mapStyle)
@ -244,7 +248,7 @@ constructor(
destNum?.let { meshLogRepository.deleteLogs(it, PortNum.POSITION_APP_VALUE) }
}
fun onServiceAction(action: ServiceAction) = viewModelScope.launch { radioConfigRepository.onServiceAction(action) }
fun onServiceAction(action: ServiceAction) = viewModelScope.launch { serviceRepository.onServiceAction(action) }
private val _state = MutableStateFlow(MetricsState.Empty)
val state: StateFlow<MetricsState> = _state
@ -257,7 +261,7 @@ constructor(
init {
if (destNum != null) {
radioConfigRepository.nodeDBbyNum
nodeRepository.nodeDBbyNum
.mapLatest { nodes -> nodes[destNum] to nodes.keys.firstOrNull() }
.distinctUntilChanged()
.onEach { (node, ourNode) ->

View file

@ -53,6 +53,7 @@ import com.geeksville.mesh.repository.radio.MeshActivity
import com.geeksville.mesh.repository.radio.RadioInterfaceService
import com.geeksville.mesh.service.MeshServiceNotifications
import com.geeksville.mesh.service.ServiceAction
import com.geeksville.mesh.service.ServiceRepository
import com.geeksville.mesh.ui.node.components.NodeMenuAction
import com.geeksville.mesh.util.safeNumber
import dagger.hilt.android.lifecycle.HiltViewModel
@ -185,6 +186,7 @@ constructor(
private val app: Application,
private val nodeDB: NodeRepository,
private val radioConfigRepository: RadioConfigRepository,
private val serviceRepository: ServiceRepository,
radioInterfaceService: RadioInterfaceService,
private val meshLogRepository: MeshLogRepository,
private val deviceHardwareRepository: DeviceHardwareRepository,
@ -215,10 +217,10 @@ constructor(
}
.stateIn(scope = viewModelScope, started = SharingStarted.WhileSubscribed(5_000), initialValue = null)
val clientNotification: StateFlow<MeshProtos.ClientNotification?> = radioConfigRepository.clientNotification
val clientNotification: StateFlow<MeshProtos.ClientNotification?> = serviceRepository.clientNotification
fun clearClientNotification(notification: MeshProtos.ClientNotification) {
radioConfigRepository.clearClientNotification()
serviceRepository.clearClientNotification()
meshServiceNotifications.clearClientNotification(notification)
}
@ -275,7 +277,7 @@ constructor(
}
val meshService: IMeshService?
get() = radioConfigRepository.meshService
get() = serviceRepository.meshService
private val localConfig = MutableStateFlow<LocalConfig>(LocalConfig.getDefaultInstance())
@ -447,13 +449,13 @@ constructor(
}
init {
radioConfigRepository.errorMessage
serviceRepository.errorMessage
.filterNotNull()
.onEach {
showAlert(
title = app.getString(R.string.client_notification),
message = it,
onConfirm = { radioConfigRepository.clearErrorMessage() },
onConfirm = { serviceRepository.clearErrorMessage() },
dismissable = false,
)
}
@ -590,9 +592,8 @@ constructor(
}
}
fun sendReaction(emoji: String, replyId: Int, contactKey: String) = viewModelScope.launch {
radioConfigRepository.onServiceAction(ServiceAction.Reaction(emoji, replyId, contactKey))
}
fun sendReaction(emoji: String, replyId: Int, contactKey: String) =
viewModelScope.launch { serviceRepository.onServiceAction(ServiceAction.Reaction(emoji, replyId, contactKey)) }
private val _sharedContactRequested: MutableStateFlow<AdminProtos.SharedContact?> = MutableStateFlow(null)
val sharedContactRequested: StateFlow<AdminProtos.SharedContact?>
@ -603,7 +604,7 @@ constructor(
}
fun addSharedContact(sharedContact: AdminProtos.SharedContact) =
viewModelScope.launch { radioConfigRepository.onServiceAction(ServiceAction.AddSharedContact(sharedContact)) }
viewModelScope.launch { serviceRepository.onServiceAction(ServiceAction.AddSharedContact(sharedContact)) }
fun requestTraceroute(destNum: Int) {
info("Requesting traceroute for '$destNum'")
@ -663,10 +664,10 @@ constructor(
// Connection state to our radio device
val connectionState
get() = radioConfigRepository.connectionState
get() = serviceRepository.connectionState
val isConnectedStateFlow =
radioConfigRepository.connectionState
serviceRepository.connectionState
.map { it.isConnected() }
.stateIn(viewModelScope, SharingStarted.Eagerly, false)
@ -701,7 +702,7 @@ constructor(
fun favoriteNode(node: Node) = viewModelScope.launch {
try {
radioConfigRepository.onServiceAction(ServiceAction.Favorite(node))
serviceRepository.onServiceAction(ServiceAction.Favorite(node))
} catch (ex: RemoteException) {
errormsg("Favorite node error:", ex)
}
@ -709,7 +710,7 @@ constructor(
fun ignoreNode(node: Node) = viewModelScope.launch {
try {
radioConfigRepository.onServiceAction(ServiceAction.Ignore(node))
serviceRepository.onServiceAction(ServiceAction.Ignore(node))
} catch (ex: RemoteException) {
errormsg("Ignore node error:", ex)
}
@ -817,10 +818,10 @@ constructor(
}
val tracerouteResponse: LiveData<String?>
get() = radioConfigRepository.tracerouteResponse.asLiveData()
get() = serviceRepository.tracerouteResponse.asLiveData()
fun clearTracerouteResponse() {
radioConfigRepository.clearTracerouteResponse()
serviceRepository.clearTracerouteResponse()
}
fun setNodeFilterText(text: String) {