mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
refactor: move error message handling to ServiceRepository
This commit is contained in:
parent
cf239e3634
commit
76151e153f
6 changed files with 29 additions and 18 deletions
|
|
@ -671,7 +671,7 @@ class MeshService : Service(), Logging {
|
|||
val isAck = u.errorReasonValue == MeshProtos.Routing.Error.NONE_VALUE
|
||||
|
||||
if (u.errorReason == MeshProtos.Routing.Error.DUTY_CYCLE_LIMIT) {
|
||||
radioInterfaceService.setErrorMessage(getString(R.string.error_duty_cycle))
|
||||
radioConfigRepository.setErrorMessage(getString(R.string.error_duty_cycle))
|
||||
}
|
||||
|
||||
handleAckNak(isAck, fromId, data.requestId)
|
||||
|
|
@ -1446,7 +1446,7 @@ class MeshService : Service(), Logging {
|
|||
mqttMessageFlow = mqttRepository.proxyMessageFlow.onEach { message ->
|
||||
sendToRadio(ToRadio.newBuilder().apply { mqttClientProxyMessage = message })
|
||||
}.catch { throwable ->
|
||||
radioInterfaceService.setErrorMessage("MqttClientProxy failed: $throwable")
|
||||
radioConfigRepository.setErrorMessage("MqttClientProxy failed: $throwable")
|
||||
}.launchIn(serviceScope)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.geeksville.mesh.service
|
||||
|
||||
import com.geeksville.mesh.IMeshService
|
||||
import com.geeksville.mesh.android.Logging
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import javax.inject.Inject
|
||||
|
|
@ -10,7 +11,7 @@ import javax.inject.Singleton
|
|||
* Repository class for managing the [IMeshService] instance and connection state
|
||||
*/
|
||||
@Singleton
|
||||
class ServiceRepository @Inject constructor() {
|
||||
class ServiceRepository @Inject constructor() : Logging {
|
||||
var meshService: IMeshService? = null
|
||||
private set
|
||||
|
||||
|
|
@ -26,6 +27,18 @@ class ServiceRepository @Inject constructor() {
|
|||
_connectionState.value = connectionState
|
||||
}
|
||||
|
||||
private val _errorMessage = MutableStateFlow<String?>(null)
|
||||
val errorMessage: StateFlow<String?> get() = _errorMessage
|
||||
|
||||
fun setErrorMessage(text: String) {
|
||||
errormsg(text)
|
||||
_errorMessage.value = text
|
||||
}
|
||||
|
||||
fun clearErrorMessage() {
|
||||
_errorMessage.value = null
|
||||
}
|
||||
|
||||
private val _tracerouteResponse = MutableStateFlow<String?>(null)
|
||||
val tracerouteResponse: StateFlow<String?> get() = _tracerouteResponse
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue