feat: refactorResponse WebFragment && sipExtension refs #7827
This commit is contained in:
parent
d2e875c812
commit
bcecf2ed6c
|
@ -9,12 +9,9 @@ import es.verdnatura.domain.SalixCallback
|
||||||
import es.verdnatura.domain.formatWithQuotes
|
import es.verdnatura.domain.formatWithQuotes
|
||||||
import es.verdnatura.domain.model.Filter
|
import es.verdnatura.domain.model.Filter
|
||||||
import es.verdnatura.presentation.base.BaseViewModel
|
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.common.ResponseItemMachineControl
|
||||||
import es.verdnatura.presentation.view.feature.controlvehiculo.fragment.model.DeviceId
|
import es.verdnatura.presentation.view.feature.controlvehiculo.fragment.model.DeviceId
|
||||||
import es.verdnatura.presentation.view.feature.login.model.NameWorker
|
import es.verdnatura.presentation.view.feature.login.model.NameWorker
|
||||||
import org.json.JSONObject
|
|
||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
|
|
||||||
class ControlVehiculoViewModel(val context: Context) : BaseViewModel(context) {
|
class ControlVehiculoViewModel(val context: Context) : BaseViewModel(context) {
|
||||||
|
@ -27,13 +24,9 @@ class ControlVehiculoViewModel(val context: Context) : BaseViewModel(context) {
|
||||||
val responseControl: LiveData<String>
|
val responseControl: LiveData<String>
|
||||||
get() = _responseControl
|
get() = _responseControl
|
||||||
|
|
||||||
private val _responsemachine by lazy { MutableLiveData<ResponseItemMachineControl>() }
|
private val _responseMachine by lazy { MutableLiveData<ResponseItemMachineControl>() }
|
||||||
val responsemachine: LiveData<ResponseItemMachineControl>
|
val responseMachine: LiveData<ResponseItemMachineControl>
|
||||||
get() = _responsemachine
|
get() = _responseMachine
|
||||||
|
|
||||||
private val _responseGetExtensionFromUserId by lazy { MutableLiveData<Any>() }
|
|
||||||
val responseGetExtensionFromUserId: LiveData<Any>
|
|
||||||
get() = _responseGetExtensionFromUserId
|
|
||||||
|
|
||||||
private val _responseGetName by lazy { MutableLiveData<NameWorker>() }
|
private val _responseGetName by lazy { MutableLiveData<NameWorker>() }
|
||||||
val responseGetName: LiveData<NameWorker> = _responseGetName
|
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) {
|
fun workerMachineryIsRegistered(userId: Int) {
|
||||||
salix.workerMachineryIsRegistered(arrayListOf(userId))
|
salix.workerMachineryIsRegistered(arrayListOf(userId))
|
||||||
.enqueue(object : SalixCallback<String>(context) {
|
.enqueue(object : SalixCallback<String>(context) {
|
||||||
|
@ -111,20 +67,12 @@ class ControlVehiculoViewModel(val context: Context) : BaseViewModel(context) {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.enqueue(object : SalixCallback<List<DeviceId>>(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>>) {
|
override fun onSuccess(response: Response<List<DeviceId>>) {
|
||||||
if (response.body() != null) {
|
if (response.body() != null) {
|
||||||
|
|
||||||
_responsemachine.value =
|
_responseMachine.value =
|
||||||
ResponseItemMachineControl(
|
ResponseItemMachineControl(
|
||||||
isError = false,
|
|
||||||
response = if (response.body()!!.isEmpty()) {
|
response = if (response.body()!!.isEmpty()) {
|
||||||
""
|
""
|
||||||
} else {
|
} else {
|
||||||
|
@ -146,9 +94,8 @@ class ControlVehiculoViewModel(val context: Context) : BaseViewModel(context) {
|
||||||
).formatWithQuotes()
|
).formatWithQuotes()
|
||||||
).enqueue(object : SalixCallback<List<JsonObject>>(context) {
|
).enqueue(object : SalixCallback<List<JsonObject>>(context) {
|
||||||
override fun onSuccess(response: Response<List<JsonObject>>) {
|
override fun onSuccess(response: Response<List<JsonObject>>) {
|
||||||
_responsemachine.value =
|
_responseMachine.value =
|
||||||
ResponseItemMachineControl(
|
ResponseItemMachineControl(
|
||||||
isError = false,
|
|
||||||
response = if (response.body()!!.isEmpty()) {
|
response = if (response.body()!!.isEmpty()) {
|
||||||
""
|
""
|
||||||
} else {
|
} 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)
|
arrayListOf(userId)
|
||||||
).enqueue(object : SalixCallback<List<JsonObject>>(context) {
|
).enqueue(object : SalixCallback<List<JsonObject>>(context) {
|
||||||
override fun onSuccess(response: Response<List<JsonObject>>) {
|
override fun onSuccess(response: Response<List<JsonObject>>) {
|
||||||
val myArray = response.body()
|
_responseMachine.value =
|
||||||
_responsemachine.value =
|
|
||||||
ResponseItemMachineControl(
|
ResponseItemMachineControl(
|
||||||
isError = false,
|
response = if (response.body()!!.isEmpty()) {
|
||||||
response = if (myArray!!.isEmpty()) {
|
|
||||||
""
|
""
|
||||||
} else {
|
} else {
|
||||||
myArray[0].entrySet().first().value.toString().replace("\"", "")
|
response.body()!![0].entrySet().first().value.toString().replace("\"", "")
|
||||||
},
|
},
|
||||||
type = "getWorkerPlate"
|
type = "getWorkerPlate"
|
||||||
)
|
)
|
||||||
|
@ -203,30 +141,9 @@ class ControlVehiculoViewModel(val context: Context) : BaseViewModel(context) {
|
||||||
_responseGetName.value = response.body()
|
_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 {
|
|
||||||
""
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue