kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
refactor: move error message handling to `ServiceRepository`
rodzic
cf239e3634
commit
76151e153f
|
@ -194,7 +194,7 @@ class BTScanModel @Inject constructor(
|
|||
addDevice(entry)
|
||||
}
|
||||
}.catch { ex ->
|
||||
radioInterfaceService.setErrorMessage("Unexpected Bluetooth scan failure: ${ex.message}")
|
||||
serviceRepository.setErrorMessage("Unexpected Bluetooth scan failure: ${ex.message}")
|
||||
}.launchIn(viewModelScope)
|
||||
}
|
||||
|
||||
|
|
|
@ -159,9 +159,9 @@ class UIViewModel @Inject constructor(
|
|||
val snackbarText: LiveData<Any?> get() = _snackbarText
|
||||
|
||||
init {
|
||||
radioInterfaceService.errorMessage.filterNotNull().onEach {
|
||||
radioConfigRepository.errorMessage.filterNotNull().onEach {
|
||||
_snackbarText.value = it
|
||||
radioInterfaceService.clearErrorMessage()
|
||||
radioConfigRepository.clearErrorMessage()
|
||||
}.launchIn(viewModelScope)
|
||||
|
||||
viewModelScope.launch {
|
||||
|
|
|
@ -157,6 +157,16 @@ class RadioConfigRepository @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
val errorMessage: StateFlow<String?> get() = serviceRepository.errorMessage
|
||||
|
||||
fun setErrorMessage(text: String) {
|
||||
serviceRepository.setErrorMessage(text)
|
||||
}
|
||||
|
||||
fun clearErrorMessage() {
|
||||
serviceRepository.clearErrorMessage()
|
||||
}
|
||||
|
||||
val tracerouteResponse: StateFlow<String?> get() = serviceRepository.tracerouteResponse
|
||||
|
||||
fun setTracerouteResponse(value: String?) {
|
||||
|
|
|
@ -56,18 +56,6 @@ class RadioInterfaceService @Inject constructor(
|
|||
private val _receivedData = MutableSharedFlow<ByteArray>()
|
||||
val receivedData: SharedFlow<ByteArray> = _receivedData
|
||||
|
||||
private val _errorMessage = MutableStateFlow<String?>(null)
|
||||
val errorMessage: SharedFlow<String?> = _errorMessage
|
||||
|
||||
fun setErrorMessage(text: String) {
|
||||
errormsg(text)
|
||||
_errorMessage.value = text
|
||||
}
|
||||
|
||||
fun clearErrorMessage() {
|
||||
_errorMessage.value = null
|
||||
}
|
||||
|
||||
private val logSends = false
|
||||
private val logReceives = false
|
||||
private lateinit var sentPacketsLog: BinaryLogFile // inited in onCreate
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue