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
)
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? = ""

View File

@ -259,11 +259,11 @@ class SignedActivity : BaseActivity<ActivitySignBinding>(), 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)

View File

@ -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()
}

View File

@ -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("")
}
}

View File

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

View File

@ -315,30 +315,13 @@ class TicketsFragment : BaseFragment<FragmentTicketsBinding, DeliveryViewModel>(
}
}
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)
}
}

View File

@ -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<FreeLanceDeliveryInfoList>() }
val companyInfoList: LiveData<FreeLanceDeliveryInfoList> = _companyInfoList
private val _responseStateAdd by lazy { MutableLiveData<ResponseItemVO>() }
val responseStateAdd: LiveData<ResponseItemVO>
private val _responseStateAdd by lazy { MutableLiveData<Boolean>() }
val responseStateAdd: LiveData<Boolean>
get() = _responseStateAdd
private val _responseUpdateRoute by lazy { MutableLiveData<Boolean>() }
val responseUpdateRoute: LiveData<Boolean>
get() = _responseUpdateRoute
private val _response by lazy { MutableLiveData<ResponseItemVO>() }
val response: LiveData<ResponseItemVO> = _response
private val _responseSign by lazy { MutableLiveData<ResponseItemVO>() }
val responseSign: LiveData<ResponseItemVO> = _responseSign
private val _responseSign by lazy { MutableLiveData<ResponseSign>() }
val responseSign: LiveData<ResponseSign> = _responseSign
private val _responseNotes by lazy { MutableLiveData<Boolean>() }
val responseNotes: LiveData<Boolean> = _responseNotes
@ -88,8 +86,8 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) {
private val _responseLoadList by lazy { MutableLiveData<Boolean>() }
val responseLoadList: LiveData<Boolean> = _responseLoadList
private val _responseStateList by lazy { MutableLiveData<ResponseItemVO>() }
val responseStateList: LiveData<ResponseItemVO> = _responseStateList
private val _responseStateList by lazy { MutableLiveData<Boolean>() }
val responseStateList: LiveData<Boolean> = _responseStateList
fun getTicketObservations(
listTickets: List<Long>
@ -213,17 +211,18 @@ class DeliveryViewModel(val context: Context) : BaseViewModel(context) {
salix.addExpeditionState(expeditions).enqueue(object : SalixCallback<Unit>(context) {
override fun onSuccess(response: Response<Unit>) {
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<Unit>, 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<Any>(context) {
override fun onSuccess(response: Response<Any>) {
_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<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.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<WorkerMistakeTypeList>
get() = _mistakeWorkerList
private val _responseAddMistake by lazy { MutableLiveData<ResponseItemVO>() }
val responseAddMistake: LiveData<ResponseItemVO>
get() = _responseAddMistake
private val _inventoryListParking by lazy { MutableLiveData<InventoryParkingList>() }
val inventoryListParking: LiveData<InventoryParkingList>
get() = _inventoryListParking

View File

@ -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) {

View File

@ -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<LoginAppData>() }
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?>() }
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.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<Boolean>(RESERVATIONMODE)
private val _response by lazy { MutableLiveData<ResponseItemVO>() }
val inventaryList: LiveData<ResponseItemVO> get() = _response
fun inititializeDefaultData() {
workerActivityAdd(CodeWorkerAction.STORAGE)
_pasillerositem.add(

View File

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