From 2c42f3b54bdd80d743a60756731e2a3a3d07bcfe Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Thu, 19 Sep 2024 12:59:18 +0200 Subject: [PATCH] feat: refs #7827 responseItem --- .../presentation/common/ResponseItemVO.kt | 7 +- .../delivery/activity/SignedActivity.kt | 4 +- .../delivery/fragments/LoadUnloadFragment.kt | 16 +--- .../delivery/fragments/RoutesFragment.kt | 24 ++--- .../delivery/fragments/SummaryFragment.kt | 2 +- .../delivery/fragments/TicketsFragment.kt | 19 +--- .../delivery/viewmodels/DeliveryViewModel.kt | 39 ++++---- .../inventario/fragment/InventaryViewModel.kt | 5 - .../feature/login/fragment/LoginFragment.kt | 22 ++--- .../feature/login/fragment/LoginViewModel.kt | 5 - .../pasillero/fragment/PasilleroViewModel.kt | 8 +- .../res/layout/component_custom_dialog.xml | 96 ++++++++++--------- 12 files changed, 102 insertions(+), 145 deletions(-) diff --git a/app/src/main/java/es/verdnatura/presentation/common/ResponseItemVO.kt b/app/src/main/java/es/verdnatura/presentation/common/ResponseItemVO.kt index a78a163b..7e4e4ccb 100644 --- a/app/src/main/java/es/verdnatura/presentation/common/ResponseItemVO.kt +++ b/app/src/main/java/es/verdnatura/presentation/common/ResponseItemVO.kt @@ -9,6 +9,12 @@ class ResponseItemVO( var data: Any? = null ) +data class ResponseSign( + val fileToSign: String = "", + val isError: Boolean = false, + val message: String = "" +) + class ResponseHasOlder( var shelvingFkIn: String, var parking: String? = null, @@ -36,7 +42,6 @@ class ResponseItemMachineControl( var type: String ) - class GeneralItem( var code: String? = "", var text: String? = "" diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/activity/SignedActivity.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/activity/SignedActivity.kt index 54f9b4d9..6294477a 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/activity/SignedActivity.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/activity/SignedActivity.kt @@ -259,11 +259,11 @@ class SignedActivity : BaseActivity(), LocationUpdateCallba ) deliveryViewModel.responseSign.observe(this) { + if (!it.isError) { - getString(R.string.ok).toast(this) finish() } else { - it.errorMessage.toast(this) + it.message.toast(this) lifecycleScope.launch { withContext(Dispatchers.IO) { db.signedTicketDao().insert(mySign) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/LoadUnloadFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/LoadUnloadFragment.kt index 8bbca886..d6aa5268 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/LoadUnloadFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/LoadUnloadFragment.kt @@ -350,7 +350,7 @@ class LoadUnloadFragment( } } responseStateAdd.observe(viewLifecycleOwner) { - if (!it.isError) { + if (it) { counterResponse += 1 if (counterResponse == counterCalls) { if (!binding.mainToolbar.switchButton.isChecked) { @@ -366,25 +366,11 @@ class LoadUnloadFragment( counterCalls = 0 } } else { - ma.messageWithSound( - it.errorMessage, - isError = true, - isPlayed = true, - titleWithError = "Error", - isToasted = true - ) openSignActivity() } } responseStateList.observe(viewLifecycleOwner) { - ma.messageWithSound( - it.errorMessage, - isError = true, - isPlayed = true, - titleWithError = "", - isToasted = true - ) savePendingExpeditions() openSignActivity() } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/RoutesFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/RoutesFragment.kt index 4a6c0448..c01dea76 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/RoutesFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/RoutesFragment.kt @@ -14,6 +14,7 @@ import es.verdnatura.databinding.FragmentRouteBinding import es.verdnatura.db.DeliveryDatabase import es.verdnatura.domain.notNull import es.verdnatura.domain.toDateString +import es.verdnatura.domain.toast import es.verdnatura.presentation.base.BaseFragment import es.verdnatura.presentation.base.database import es.verdnatura.presentation.common.ItemDescorationCustomized @@ -244,35 +245,24 @@ class RoutesFragment( if (it.isError) { binding.mainToolbar.toolbarIcons.visibility = View.VISIBLE - ma.messageWithSound( - it.errorMessage, - isError = false, - isPlayed = false, - titleWithError = "", - isToasted = true - ) + it.message.toast(context) + } else { - deleteSignTickets(it.response) + deleteSignTickets(it.fileToSign) } } responseLoadList.observe(viewLifecycleOwner) { - ma.messageWithSound( - getString(R.string.offline), - isError = false, - isPlayed = false, - titleWithError = "", - isToasted = true - ) + ma.onApplicationEventAnimation(View.INVISIBLE) createListRoutes(mutableListOf(), getSaved = true) } responseStateAdd.observe(viewLifecycleOwner) { - if (!it.isError) { + if (it) { binding.mainToolbar.toolbarIcons.visibility = View.VISIBLE - deleteExpeditionsPending(it.response) + deleteExpeditionsPending("") } } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/SummaryFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/SummaryFragment.kt index c0d6e846..dbb54ca8 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/SummaryFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/SummaryFragment.kt @@ -278,7 +278,7 @@ class SummaryFragment( } } responseStateAdd.observe(viewLifecycleOwner) { - if (!it.isError) { + if (it) { counterResponse += 1 if (counterResponse == counterCalls) { viewModel.routeGetExpeditionSummary(routeSelected) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/TicketsFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/TicketsFragment.kt index bb15b2b5..31b31f40 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/TicketsFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/fragments/TicketsFragment.kt @@ -315,30 +315,13 @@ class TicketsFragment : BaseFragment( } } responseStateAdd.observe(viewLifecycleOwner) {} - response.observe(viewLifecycleOwner) { - if (!it.isError) { - ma.messageWithSound( - it.response, - isError = false, - isPlayed = false, - titleWithError = "", - isToasted = true - ) - } - } + responseUpdateRoute.observe(viewLifecycleOwner) { showSigned = !showSigned changeVisibleSettings(false) setToolBar() } responseLoadList.observe(viewLifecycleOwner) { - ma.messageWithSound( - getString(R.string.offline), - isError = true, - isPlayed = false, - titleWithError = "", - isToasted = true - ) createLisTickets(mutableListOf(), getSaved = true) } } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/viewmodels/DeliveryViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/viewmodels/DeliveryViewModel.kt index a4be8129..60b0463c 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/viewmodels/DeliveryViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/delivery/viewmodels/DeliveryViewModel.kt @@ -4,10 +4,11 @@ import android.content.Context import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.map +import es.verdnatura.R import es.verdnatura.domain.SalixCallback import es.verdnatura.presentation.base.BaseViewModel 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.ClientTicketSalix 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() } val companyInfoList: LiveData = _companyInfoList - private val _responseStateAdd by lazy { MutableLiveData() } - val responseStateAdd: LiveData + private val _responseStateAdd by lazy { MutableLiveData() } + val responseStateAdd: LiveData get() = _responseStateAdd private val _responseUpdateRoute by lazy { MutableLiveData() } val responseUpdateRoute: LiveData get() = _responseUpdateRoute - private val _response by lazy { MutableLiveData() } - val response: LiveData = _response - - private val _responseSign by lazy { MutableLiveData() } - val responseSign: LiveData = _responseSign + private val _responseSign by lazy { MutableLiveData() } + val responseSign: LiveData = _responseSign private val _responseNotes by lazy { MutableLiveData() } val responseNotes: LiveData = _responseNotes @@ -88,8 +86,8 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) { private val _responseLoadList by lazy { MutableLiveData() } val responseLoadList: LiveData = _responseLoadList - private val _responseStateList by lazy { MutableLiveData() } - val responseStateList: LiveData = _responseStateList + private val _responseStateList by lazy { MutableLiveData() } + val responseStateList: LiveData = _responseStateList fun getTicketObservations( listTickets: List @@ -213,17 +211,18 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) { salix.addExpeditionState(expeditions).enqueue(object : SalixCallback(context) { override fun onSuccess(response: Response) { super.onSuccess(response) - _responseStateAdd.value = ResponseItemVO("", false, "", 0) + _responseStateAdd.value = true } override fun onError(t: Throwable) { super.onError(t) - _responseStateAdd.value = ResponseItemVO() + _responseStateAdd.value = false } override fun onFailure(call: Call, t: Throwable) { //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(context) { override fun onSuccess(response: Response) { - _responseSign.value = ResponseItemVO(filePath, false, "", 0) + _responseSign.value = ResponseSign(fileToSign = filePath, isError = false) + super.onSuccess(response) } //Otro fallo override fun onError(t: Throwable) { - _responseSign.value = ResponseItemVO( - "", true, "Tickets:" + File(filePath).name + "→" + t.message.toString(), 0 + _responseSign.value = ResponseSign( + fileToSign = "", + isError = true, + message = "Tickets:${File(filePath).name}→${t.message.toString()}" ) - // super.onError(t) + } //Fallo de red override fun onFailure(call: Call, t: Throwable) { - _responseSign.value = ResponseItemVO("NetWork Error", true, t.message.toString(), 0) + _responseSign.value = ResponseSign(fileToSign = "", isError = true) + super.onFailure(call, t) } }) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/inventario/fragment/InventaryViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/inventario/fragment/InventaryViewModel.kt index 36a9cfe6..019dcc2b 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/inventario/fragment/InventaryViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/inventario/fragment/InventaryViewModel.kt @@ -11,7 +11,6 @@ import es.verdnatura.domain.userCases.GetItemFromBarcodeUseCase import es.verdnatura.presentation.base.BaseViewModel import es.verdnatura.presentation.common.Event 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.BuyerVO import es.verdnatura.presentation.view.feature.inventario.model.InventaryListVO @@ -59,10 +58,6 @@ class InventaryViewModel(val context: Context) : BaseViewModel(context) { val mistakeWorkerList: LiveData get() = _mistakeWorkerList - private val _responseAddMistake by lazy { MutableLiveData() } - val responseAddMistake: LiveData - get() = _responseAddMistake - private val _inventoryListParking by lazy { MutableLiveData() } val inventoryListParking: LiveData get() = _inventoryListParking diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginFragment.kt index 8123d53e..46615c5f 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginFragment.kt @@ -424,18 +424,18 @@ class LoginFragment(private var imageUri: Uri?) : } } - devicelogresponse.observe(viewLifecycleOwner) { + /* devicelogresponse.observe(viewLifecycleOwner) { - if (it.isError) { - customDialog.setTitle(getString(R.string.error)).setDescription(it.errorMessage) - .setOkButton( - getString(R.string.accept) - ) { - customDialog.dismiss() - getVersion() - }.show() - } - } + if (it.isError) { + customDialog.setTitle(getString(R.string.error)).setDescription(it.errorMessage) + .setOkButton( + getString(R.string.accept) + ) { + customDialog.dismiss() + getVersion() + }.show() + } + }*/ loginSalixItem.observe(viewLifecycleOwner) { diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginViewModel.kt index 06aa1795..36e62714 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginViewModel.kt @@ -17,7 +17,6 @@ import es.verdnatura.presentation.base.BaseViewModel import es.verdnatura.presentation.base.getMessageFromAllResponse import es.verdnatura.presentation.base.nameofFunction 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.login.model.AccessConfigSalix 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() } val loginApp: LiveData = _loginApp - private val _devicelogresponse by lazy { MutableLiveData() } - val devicelogresponse: LiveData - get() = _devicelogresponse - private val _serialNumber by lazy { MutableLiveData() } val serialNumber: LiveData = _serialNumber diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/pasillero/fragment/PasilleroViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/pasillero/fragment/PasilleroViewModel.kt index 76ef0a4d..d4a2ab7a 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/pasillero/fragment/PasilleroViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/pasillero/fragment/PasilleroViewModel.kt @@ -2,14 +2,11 @@ package es.verdnatura.presentation.view.feature.pasillero.fragment import android.annotation.SuppressLint import android.content.Context -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData import es.verdnatura.MobileApplication import es.verdnatura.R import es.verdnatura.domain.ConstAndValues.RESERVATIONMODE import es.verdnatura.domain.SalixCallback 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.PasillerosItemVO import es.verdnatura.presentation.view.feature.pasillero.model.WorkerActionSalix @@ -24,10 +21,7 @@ class PasilleroViewModel(context: Context) : BaseViewModel(context) { val userId = (contextApp as MobileApplication).userId private val isOnReservationMode = (contextApp as MobileApplication).dataStoreApp.readDataStoreKey(RESERVATIONMODE) - - private val _response by lazy { MutableLiveData() } - val inventaryList: LiveData get() = _response - + fun inititializeDefaultData() { workerActivityAdd(CodeWorkerAction.STORAGE) _pasillerositem.add( diff --git a/app/src/main/res/layout/component_custom_dialog.xml b/app/src/main/res/layout/component_custom_dialog.xml index ab2cdfbc..768d8b39 100644 --- a/app/src/main/res/layout/component_custom_dialog.xml +++ b/app/src/main/res/layout/component_custom_dialog.xml @@ -8,57 +8,63 @@ app:cardBackgroundColor="@color/verdnatura_black_8" app:cardCornerRadius="@dimen/dialog_radius"> - + android:fillViewport="true"> - + android:orientation="vertical" + android:padding="@dimen/default_layout_margin"> - + -