feat: refactorResponse WebFragment && sipExtension refs #7827

This commit is contained in:
Sergio De la torre 2024-08-14 08:50:07 +02:00
parent d2e875c812
commit bcecf2ed6c
1 changed files with 8 additions and 91 deletions

View File

@ -9,12 +9,9 @@ import es.verdnatura.domain.SalixCallback
import es.verdnatura.domain.formatWithQuotes
import es.verdnatura.domain.model.Filter
import es.verdnatura.presentation.base.BaseViewModel
import es.verdnatura.presentation.base.getMessageFromAllResponse
import es.verdnatura.presentation.base.nameofFunction
import es.verdnatura.presentation.common.ResponseItemMachineControl
import es.verdnatura.presentation.view.feature.controlvehiculo.fragment.model.DeviceId
import es.verdnatura.presentation.view.feature.login.model.NameWorker
import org.json.JSONObject
import retrofit2.Response
class ControlVehiculoViewModel(val context: Context) : BaseViewModel(context) {
@ -27,13 +24,9 @@ class ControlVehiculoViewModel(val context: Context) : BaseViewModel(context) {
val responseControl: LiveData<String>
get() = _responseControl
private val _responsemachine by lazy { MutableLiveData<ResponseItemMachineControl>() }
val responsemachine: LiveData<ResponseItemMachineControl>
get() = _responsemachine
private val _responseGetExtensionFromUserId by lazy { MutableLiveData<Any>() }
val responseGetExtensionFromUserId: LiveData<Any>
get() = _responseGetExtensionFromUserId
private val _responseMachine by lazy { MutableLiveData<ResponseItemMachineControl>() }
val responseMachine: LiveData<ResponseItemMachineControl>
get() = _responseMachine
private val _responseGetName by lazy { MutableLiveData<NameWorker>() }
val responseGetName: LiveData<NameWorker> = _responseGetName
@ -53,43 +46,6 @@ class ControlVehiculoViewModel(val context: Context) : BaseViewModel(context) {
})
}
/* fun machineWorker_update(
plate: String
) {
//Tarea 6276 //vehiculo
salix.machineWorkerUpdateInTime( params = hashMapOf("plate" to plate))
.enqueue(object : SalixCallback<Any>(context) {
override fun onError(t: Throwable) {
_responseinsert.value = ResponseItemVO(
isError = true,
errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
)
}
override fun onSuccess(response: Response<Any>) {
//sergio devuelve true o false
if (response.body().toString() == "false") {
_responseinsert.value = ResponseItemVO(
isError = true,
errorMessage = getMessageFromAllResponse(
nameofFunction(this),
response.message()
)
)
} else {
_responseinsert.value =
ResponseItemVO(isError = false, response = "")
}
}
})
}*/
fun workerMachineryIsRegistered(userId: Int) {
salix.workerMachineryIsRegistered(arrayListOf(userId))
.enqueue(object : SalixCallback<String>(context) {
@ -111,20 +67,12 @@ class ControlVehiculoViewModel(val context: Context) : BaseViewModel(context) {
)
)
.enqueue(object : SalixCallback<List<DeviceId>>(context) {
override fun onError(t: Throwable) {
_responsemachine.value = ResponseItemMachineControl(
isError = true,
errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!),
type = ""
)
}
override fun onSuccess(response: Response<List<DeviceId>>) {
if (response.body() != null) {
_responsemachine.value =
_responseMachine.value =
ResponseItemMachineControl(
isError = false,
response = if (response.body()!!.isEmpty()) {
""
} else {
@ -146,9 +94,8 @@ class ControlVehiculoViewModel(val context: Context) : BaseViewModel(context) {
).formatWithQuotes()
).enqueue(object : SalixCallback<List<JsonObject>>(context) {
override fun onSuccess(response: Response<List<JsonObject>>) {
_responsemachine.value =
_responseMachine.value =
ResponseItemMachineControl(
isError = false,
response = if (response.body()!!.isEmpty()) {
""
} else {
@ -161,13 +108,6 @@ class ControlVehiculoViewModel(val context: Context) : BaseViewModel(context) {
)
}
override fun onError(t: Throwable) {
_responsemachine.value = ResponseItemMachineControl(
isError = true,
errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!),
type = ""
)
}
})
}
@ -176,14 +116,12 @@ class ControlVehiculoViewModel(val context: Context) : BaseViewModel(context) {
arrayListOf(userId)
).enqueue(object : SalixCallback<List<JsonObject>>(context) {
override fun onSuccess(response: Response<List<JsonObject>>) {
val myArray = response.body()
_responsemachine.value =
_responseMachine.value =
ResponseItemMachineControl(
isError = false,
response = if (myArray!!.isEmpty()) {
response = if (response.body()!!.isEmpty()) {
""
} else {
myArray[0].entrySet().first().value.toString().replace("\"", "")
response.body()!![0].entrySet().first().value.toString().replace("\"", "")
},
type = "getWorkerPlate"
)
@ -203,30 +141,9 @@ class ControlVehiculoViewModel(val context: Context) : BaseViewModel(context) {
_responseGetName.value = response.body()
}
override fun onError(t: Throwable) {
}
})
}
fun sipGetExtensionSalix(
workerId: Int
) {
salix.sipGetExtension(
workerId
).enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
_responseGetExtensionFromUserId.value = if (response.body() != null) {
JSONObject(response.body()!!.toString()).get("extension").toString()
} else {
""
}
}
})
}
}