feat: refs #7827 responseItem

This commit is contained in:
Sergio De la torre 2024-09-19 12:59:18 +02:00
parent f79292d4e2
commit 2c42f3b54b
12 changed files with 102 additions and 145 deletions

View File

@ -9,6 +9,12 @@ class ResponseItemVO(
var data: Any? = null var data: Any? = null
) )
data class ResponseSign(
val fileToSign: String = "",
val isError: Boolean = false,
val message: String = ""
)
class ResponseHasOlder( class ResponseHasOlder(
var shelvingFkIn: String, var shelvingFkIn: String,
var parking: String? = null, var parking: String? = null,
@ -36,7 +42,6 @@ class ResponseItemMachineControl(
var type: String var type: String
) )
class GeneralItem( class GeneralItem(
var code: String? = "", var code: String? = "",
var text: String? = "" var text: String? = ""

View File

@ -259,11 +259,11 @@ class SignedActivity : BaseActivity<ActivitySignBinding>(), LocationUpdateCallba
) )
deliveryViewModel.responseSign.observe(this) { deliveryViewModel.responseSign.observe(this) {
if (!it.isError) { if (!it.isError) {
getString(R.string.ok).toast(this)
finish() finish()
} else { } else {
it.errorMessage.toast(this) it.message.toast(this)
lifecycleScope.launch { lifecycleScope.launch {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
db.signedTicketDao().insert(mySign) db.signedTicketDao().insert(mySign)

View File

@ -350,7 +350,7 @@ class LoadUnloadFragment(
} }
} }
responseStateAdd.observe(viewLifecycleOwner) { responseStateAdd.observe(viewLifecycleOwner) {
if (!it.isError) { if (it) {
counterResponse += 1 counterResponse += 1
if (counterResponse == counterCalls) { if (counterResponse == counterCalls) {
if (!binding.mainToolbar.switchButton.isChecked) { if (!binding.mainToolbar.switchButton.isChecked) {
@ -366,25 +366,11 @@ class LoadUnloadFragment(
counterCalls = 0 counterCalls = 0
} }
} else { } else {
ma.messageWithSound(
it.errorMessage,
isError = true,
isPlayed = true,
titleWithError = "Error",
isToasted = true
)
openSignActivity() openSignActivity()
} }
} }
responseStateList.observe(viewLifecycleOwner) { responseStateList.observe(viewLifecycleOwner) {
ma.messageWithSound(
it.errorMessage,
isError = true,
isPlayed = true,
titleWithError = "",
isToasted = true
)
savePendingExpeditions() savePendingExpeditions()
openSignActivity() openSignActivity()
} }

View File

@ -14,6 +14,7 @@ import es.verdnatura.databinding.FragmentRouteBinding
import es.verdnatura.db.DeliveryDatabase import es.verdnatura.db.DeliveryDatabase
import es.verdnatura.domain.notNull import es.verdnatura.domain.notNull
import es.verdnatura.domain.toDateString import es.verdnatura.domain.toDateString
import es.verdnatura.domain.toast
import es.verdnatura.presentation.base.BaseFragment import es.verdnatura.presentation.base.BaseFragment
import es.verdnatura.presentation.base.database import es.verdnatura.presentation.base.database
import es.verdnatura.presentation.common.ItemDescorationCustomized import es.verdnatura.presentation.common.ItemDescorationCustomized
@ -244,35 +245,24 @@ class RoutesFragment(
if (it.isError) { if (it.isError) {
binding.mainToolbar.toolbarIcons.visibility = View.VISIBLE binding.mainToolbar.toolbarIcons.visibility = View.VISIBLE
ma.messageWithSound( it.message.toast(context)
it.errorMessage,
isError = false,
isPlayed = false,
titleWithError = "",
isToasted = true
)
} else { } else {
deleteSignTickets(it.response) deleteSignTickets(it.fileToSign)
} }
} }
responseLoadList.observe(viewLifecycleOwner) { responseLoadList.observe(viewLifecycleOwner) {
ma.messageWithSound(
getString(R.string.offline),
isError = false,
isPlayed = false,
titleWithError = "",
isToasted = true
)
ma.onApplicationEventAnimation(View.INVISIBLE) ma.onApplicationEventAnimation(View.INVISIBLE)
createListRoutes(mutableListOf(), getSaved = true) createListRoutes(mutableListOf(), getSaved = true)
} }
responseStateAdd.observe(viewLifecycleOwner) { responseStateAdd.observe(viewLifecycleOwner) {
if (!it.isError) { if (it) {
binding.mainToolbar.toolbarIcons.visibility = View.VISIBLE binding.mainToolbar.toolbarIcons.visibility = View.VISIBLE
deleteExpeditionsPending(it.response) deleteExpeditionsPending("")
} }
} }

View File

@ -278,7 +278,7 @@ class SummaryFragment(
} }
} }
responseStateAdd.observe(viewLifecycleOwner) { responseStateAdd.observe(viewLifecycleOwner) {
if (!it.isError) { if (it) {
counterResponse += 1 counterResponse += 1
if (counterResponse == counterCalls) { if (counterResponse == counterCalls) {
viewModel.routeGetExpeditionSummary(routeSelected) viewModel.routeGetExpeditionSummary(routeSelected)

View File

@ -315,30 +315,13 @@ class TicketsFragment : BaseFragment<FragmentTicketsBinding, DeliveryViewModel>(
} }
} }
responseStateAdd.observe(viewLifecycleOwner) {} responseStateAdd.observe(viewLifecycleOwner) {}
response.observe(viewLifecycleOwner) {
if (!it.isError) {
ma.messageWithSound(
it.response,
isError = false,
isPlayed = false,
titleWithError = "",
isToasted = true
)
}
}
responseUpdateRoute.observe(viewLifecycleOwner) { responseUpdateRoute.observe(viewLifecycleOwner) {
showSigned = !showSigned showSigned = !showSigned
changeVisibleSettings(false) changeVisibleSettings(false)
setToolBar() setToolBar()
} }
responseLoadList.observe(viewLifecycleOwner) { responseLoadList.observe(viewLifecycleOwner) {
ma.messageWithSound(
getString(R.string.offline),
isError = true,
isPlayed = false,
titleWithError = "",
isToasted = true
)
createLisTickets(mutableListOf(), getSaved = true) createLisTickets(mutableListOf(), getSaved = true)
} }
} }

View File

@ -4,10 +4,11 @@ import android.content.Context
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.map import androidx.lifecycle.map
import es.verdnatura.R
import es.verdnatura.domain.SalixCallback import es.verdnatura.domain.SalixCallback
import es.verdnatura.presentation.base.BaseViewModel import es.verdnatura.presentation.base.BaseViewModel
import es.verdnatura.presentation.common.Event import es.verdnatura.presentation.common.Event
import es.verdnatura.presentation.common.ResponseItemVO import es.verdnatura.presentation.common.ResponseSign
import es.verdnatura.presentation.view.feature.delivery.model.ClientTicketList import es.verdnatura.presentation.view.feature.delivery.model.ClientTicketList
import es.verdnatura.presentation.view.feature.delivery.model.ClientTicketSalix import es.verdnatura.presentation.view.feature.delivery.model.ClientTicketSalix
import es.verdnatura.presentation.view.feature.delivery.model.DeliveryInfo import es.verdnatura.presentation.view.feature.delivery.model.DeliveryInfo
@ -59,19 +60,16 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) {
private val _companyInfoList by lazy { MutableLiveData<FreeLanceDeliveryInfoList>() } private val _companyInfoList by lazy { MutableLiveData<FreeLanceDeliveryInfoList>() }
val companyInfoList: LiveData<FreeLanceDeliveryInfoList> = _companyInfoList val companyInfoList: LiveData<FreeLanceDeliveryInfoList> = _companyInfoList
private val _responseStateAdd by lazy { MutableLiveData<ResponseItemVO>() } private val _responseStateAdd by lazy { MutableLiveData<Boolean>() }
val responseStateAdd: LiveData<ResponseItemVO> val responseStateAdd: LiveData<Boolean>
get() = _responseStateAdd get() = _responseStateAdd
private val _responseUpdateRoute by lazy { MutableLiveData<Boolean>() } private val _responseUpdateRoute by lazy { MutableLiveData<Boolean>() }
val responseUpdateRoute: LiveData<Boolean> val responseUpdateRoute: LiveData<Boolean>
get() = _responseUpdateRoute get() = _responseUpdateRoute
private val _response by lazy { MutableLiveData<ResponseItemVO>() } private val _responseSign by lazy { MutableLiveData<ResponseSign>() }
val response: LiveData<ResponseItemVO> = _response val responseSign: LiveData<ResponseSign> = _responseSign
private val _responseSign by lazy { MutableLiveData<ResponseItemVO>() }
val responseSign: LiveData<ResponseItemVO> = _responseSign
private val _responseNotes by lazy { MutableLiveData<Boolean>() } private val _responseNotes by lazy { MutableLiveData<Boolean>() }
val responseNotes: LiveData<Boolean> = _responseNotes val responseNotes: LiveData<Boolean> = _responseNotes
@ -88,8 +86,8 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) {
private val _responseLoadList by lazy { MutableLiveData<Boolean>() } private val _responseLoadList by lazy { MutableLiveData<Boolean>() }
val responseLoadList: LiveData<Boolean> = _responseLoadList val responseLoadList: LiveData<Boolean> = _responseLoadList
private val _responseStateList by lazy { MutableLiveData<ResponseItemVO>() } private val _responseStateList by lazy { MutableLiveData<Boolean>() }
val responseStateList: LiveData<ResponseItemVO> = _responseStateList val responseStateList: LiveData<Boolean> = _responseStateList
fun getTicketObservations( fun getTicketObservations(
listTickets: List<Long> listTickets: List<Long>
@ -213,17 +211,18 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) {
salix.addExpeditionState(expeditions).enqueue(object : SalixCallback<Unit>(context) { salix.addExpeditionState(expeditions).enqueue(object : SalixCallback<Unit>(context) {
override fun onSuccess(response: Response<Unit>) { override fun onSuccess(response: Response<Unit>) {
super.onSuccess(response) super.onSuccess(response)
_responseStateAdd.value = ResponseItemVO("", false, "", 0) _responseStateAdd.value = true
} }
override fun onError(t: Throwable) { override fun onError(t: Throwable) {
super.onError(t) super.onError(t)
_responseStateAdd.value = ResponseItemVO() _responseStateAdd.value = false
} }
override fun onFailure(call: Call<Unit>, t: Throwable) { override fun onFailure(call: Call<Unit>, t: Throwable) {
//Fallo de red guardamos pendientes //Fallo de red guardamos pendientes
_responseStateList.value = ResponseItemVO("", true, t.message.toString(), 0) _responseStateList.value = false
super.onFailure(call, Throwable(context.getString(R.string.offline)))
} }
}) })
@ -371,21 +370,25 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) {
salix.saveSign(filePart, mapQuery).enqueue(object : SalixCallback<Any>(context) { salix.saveSign(filePart, mapQuery).enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) { override fun onSuccess(response: Response<Any>) {
_responseSign.value = ResponseItemVO(filePath, false, "", 0) _responseSign.value = ResponseSign(fileToSign = filePath, isError = false)
super.onSuccess(response)
} }
//Otro fallo //Otro fallo
override fun onError(t: Throwable) { override fun onError(t: Throwable) {
_responseSign.value = ResponseItemVO( _responseSign.value = ResponseSign(
"", true, "Tickets:" + File(filePath).name + "" + t.message.toString(), 0 fileToSign = "",
isError = true,
message = "Tickets:${File(filePath).name}${t.message.toString()}"
) )
// super.onError(t)
} }
//Fallo de red //Fallo de red
override fun onFailure(call: Call<Any>, t: Throwable) { override fun onFailure(call: Call<Any>, t: Throwable) {
_responseSign.value = ResponseItemVO("NetWork Error", true, t.message.toString(), 0) _responseSign.value = ResponseSign(fileToSign = "", isError = true)
super.onFailure(call, t)
} }
}) })

View File

@ -11,7 +11,6 @@ import es.verdnatura.domain.userCases.GetItemFromBarcodeUseCase
import es.verdnatura.presentation.base.BaseViewModel import es.verdnatura.presentation.base.BaseViewModel
import es.verdnatura.presentation.common.Event import es.verdnatura.presentation.common.Event
import es.verdnatura.presentation.common.ItemDiscardSalixShortage import es.verdnatura.presentation.common.ItemDiscardSalixShortage
import es.verdnatura.presentation.common.ResponseItemVO
import es.verdnatura.presentation.view.feature.calidad.model.BuyerListVO import es.verdnatura.presentation.view.feature.calidad.model.BuyerListVO
import es.verdnatura.presentation.view.feature.calidad.model.BuyerVO import es.verdnatura.presentation.view.feature.calidad.model.BuyerVO
import es.verdnatura.presentation.view.feature.inventario.model.InventaryListVO import es.verdnatura.presentation.view.feature.inventario.model.InventaryListVO
@ -59,10 +58,6 @@ class InventaryViewModel(val context: Context) : BaseViewModel(context) {
val mistakeWorkerList: LiveData<WorkerMistakeTypeList> val mistakeWorkerList: LiveData<WorkerMistakeTypeList>
get() = _mistakeWorkerList get() = _mistakeWorkerList
private val _responseAddMistake by lazy { MutableLiveData<ResponseItemVO>() }
val responseAddMistake: LiveData<ResponseItemVO>
get() = _responseAddMistake
private val _inventoryListParking by lazy { MutableLiveData<InventoryParkingList>() } private val _inventoryListParking by lazy { MutableLiveData<InventoryParkingList>() }
val inventoryListParking: LiveData<InventoryParkingList> val inventoryListParking: LiveData<InventoryParkingList>
get() = _inventoryListParking get() = _inventoryListParking

View File

@ -424,7 +424,7 @@ class LoginFragment(private var imageUri: Uri?) :
} }
} }
devicelogresponse.observe(viewLifecycleOwner) { /* devicelogresponse.observe(viewLifecycleOwner) {
if (it.isError) { if (it.isError) {
customDialog.setTitle(getString(R.string.error)).setDescription(it.errorMessage) customDialog.setTitle(getString(R.string.error)).setDescription(it.errorMessage)
@ -435,7 +435,7 @@ class LoginFragment(private var imageUri: Uri?) :
getVersion() getVersion()
}.show() }.show()
} }
} }*/
loginSalixItem.observe(viewLifecycleOwner) { loginSalixItem.observe(viewLifecycleOwner) {

View File

@ -17,7 +17,6 @@ import es.verdnatura.presentation.base.BaseViewModel
import es.verdnatura.presentation.base.getMessageFromAllResponse import es.verdnatura.presentation.base.getMessageFromAllResponse
import es.verdnatura.presentation.base.nameofFunction import es.verdnatura.presentation.base.nameofFunction
import es.verdnatura.presentation.common.Event import es.verdnatura.presentation.common.Event
import es.verdnatura.presentation.common.ResponseItemVO
import es.verdnatura.presentation.view.feature.historicoshelvinglog.model.DeviceLogSalix import es.verdnatura.presentation.view.feature.historicoshelvinglog.model.DeviceLogSalix
import es.verdnatura.presentation.view.feature.login.model.AccessConfigSalix import es.verdnatura.presentation.view.feature.login.model.AccessConfigSalix
import es.verdnatura.presentation.view.feature.login.model.AccessConfigSalixList import es.verdnatura.presentation.view.feature.login.model.AccessConfigSalixList
@ -44,10 +43,6 @@ class LoginViewModel(val context: Context) : BaseViewModel(context) {
private val _loginApp by lazy { MutableLiveData<LoginAppData>() } private val _loginApp by lazy { MutableLiveData<LoginAppData>() }
val loginApp: LiveData<LoginAppData> = _loginApp val loginApp: LiveData<LoginAppData> = _loginApp
private val _devicelogresponse by lazy { MutableLiveData<ResponseItemVO>() }
val devicelogresponse: LiveData<ResponseItemVO>
get() = _devicelogresponse
private val _serialNumber by lazy { MutableLiveData<String?>() } private val _serialNumber by lazy { MutableLiveData<String?>() }
val serialNumber: LiveData<String?> = _serialNumber val serialNumber: LiveData<String?> = _serialNumber

View File

@ -2,14 +2,11 @@ package es.verdnatura.presentation.view.feature.pasillero.fragment
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import es.verdnatura.MobileApplication import es.verdnatura.MobileApplication
import es.verdnatura.R import es.verdnatura.R
import es.verdnatura.domain.ConstAndValues.RESERVATIONMODE import es.verdnatura.domain.ConstAndValues.RESERVATIONMODE
import es.verdnatura.domain.SalixCallback import es.verdnatura.domain.SalixCallback
import es.verdnatura.presentation.base.BaseViewModel import es.verdnatura.presentation.base.BaseViewModel
import es.verdnatura.presentation.common.ResponseItemVO
import es.verdnatura.presentation.view.feature.pasillero.model.CodeWorkerAction import es.verdnatura.presentation.view.feature.pasillero.model.CodeWorkerAction
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
import es.verdnatura.presentation.view.feature.pasillero.model.WorkerActionSalix import es.verdnatura.presentation.view.feature.pasillero.model.WorkerActionSalix
@ -25,9 +22,6 @@ class PasilleroViewModel(context: Context) : BaseViewModel(context) {
private val isOnReservationMode = private val isOnReservationMode =
(contextApp as MobileApplication).dataStoreApp.readDataStoreKey<Boolean>(RESERVATIONMODE) (contextApp as MobileApplication).dataStoreApp.readDataStoreKey<Boolean>(RESERVATIONMODE)
private val _response by lazy { MutableLiveData<ResponseItemVO>() }
val inventaryList: LiveData<ResponseItemVO> get() = _response
fun inititializeDefaultData() { fun inititializeDefaultData() {
workerActivityAdd(CodeWorkerAction.STORAGE) workerActivityAdd(CodeWorkerAction.STORAGE)
_pasillerositem.add( _pasillerositem.add(

View File

@ -8,6 +8,11 @@
app:cardBackgroundColor="@color/verdnatura_black_8" app:cardBackgroundColor="@color/verdnatura_black_8"
app:cardCornerRadius="@dimen/dialog_radius"> app:cardCornerRadius="@dimen/dialog_radius">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout <LinearLayout
android:id="@+id/dynamic" android:id="@+id/dynamic"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -21,26 +26,26 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_margin_3" android:layout_marginTop="@dimen/layout_margin_3"
android:layout_marginBottom="@dimen/default_layout_margin" android:layout_marginBottom="@dimen/default_layout_margin"
android:gravity="center_horizontal"
android:textAlignment="center" android:textAlignment="center"
android:textColor="@color/verdnatura_white" android:textColor="@color/verdnatura_white"
android:textSize="@dimen/h6" android:textSize="@dimen/h6"
android:textStyle="bold" android:textStyle="bold"
android:visibility="gone" android:visibility="gone"
tools:text="¿Estás seguro de que deseas eliminar el dispositivo de celia?" tools:text="¿Estás seguro de que deseas eliminar el dispositivo de celia?"
tools:visibility="visible" tools:visibility="visible" />
android:gravity="center_horizontal" />
<TextView <TextView
android:id="@+id/custom_dialog_description" android:id="@+id/custom_dialog_description"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textAlignment="center" android:textAlignment="center"
android:textColor="@color/verdnatura_white" android:textColor="@color/verdnatura_white"
android:textSize="@dimen/body1" android:textSize="@dimen/body1"
android:visibility="gone" android:visibility="gone"
tools:text="Este cambio no podrá deshacerse a no ser que vuelvas a vincular el dispositivo" tools:text="Este cambio no podrá deshacerse a no ser que vuelvas a vincular el dispositivo"
tools:visibility="visible" tools:visibility="visible" />
android:gravity="center_horizontal" />
<Button <Button
android:id="@+id/custom_dialog_button_ok" android:id="@+id/custom_dialog_button_ok"
@ -61,4 +66,5 @@
tools:text="@string/cancel" tools:text="@string/cancel"
tools:visibility="visible" /> tools:visibility="visible" />
</LinearLayout> </LinearLayout>
</ScrollView>
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>