feat: refactorResponse Paletizado refs #7827

This commit is contained in:
Sergio De la torre 2024-09-10 07:18:42 +02:00
parent e18125420b
commit 5b8c089734
11 changed files with 185 additions and 512 deletions

View File

@ -3,7 +3,7 @@ package es.verdnatura.presentation.view.feature.paletizador.fragment
import android.content.Context
import android.graphics.drawable.Drawable
import android.view.View
import androidx.lifecycle.Observer
import androidx.core.content.res.ResourcesCompat
import androidx.recyclerview.widget.LinearLayoutManager
import es.verdnatura.R
import es.verdnatura.databinding.FragmentExpeditionPalletDetailBinding
@ -19,8 +19,6 @@ import es.verdnatura.presentation.view.feature.paletizador.adapter.ExpeditionPal
import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionTruckVO
import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletVO
import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletViewListVO
import java.text.SimpleDateFormat
import java.util.Calendar
class ExpeditionPalletDetailFragment(
var itemExpeditionTruckVO: ItemExpeditionTruckVO? = null,
@ -46,6 +44,7 @@ class ExpeditionPalletDetailFragment(
override fun getLayoutId(): Int = R.layout.fragment_expedition_pallet_detail
override fun init() {
println("ExpeditionPalletDetail")
customDialog = CustomDialog(requireContext())
binding.expeditionPalletDetailPallet.text =
buildString {
@ -59,12 +58,7 @@ class ExpeditionPalletDetailFragment(
append(itemExpeditionTruckVO!!.eta)
append(" ")
append(
if (itemExpeditionTruckVO!!.Destino.isNullOrEmpty()) {
itemExpeditionTruckVO!!.description
} else {
itemExpeditionTruckVO!!.Destino
}
itemExpeditionTruckVO!!.description
)
}
@ -90,13 +84,14 @@ class ExpeditionPalletDetailFragment(
private fun setToolBar() {
val listIcons: ArrayList<Drawable> = ArrayList()
val iconReload: Drawable =
resources.getDrawable(R.drawable.ic_autorenew_black_24dp, resources.newTheme())
ResourcesCompat.getDrawable(resources, R.drawable.ic_autorenew_black_24dp, null)!!
val iconEditar: Drawable =
resources.getDrawable(R.drawable.ic_mode_edit_black_24dp, resources.newTheme())
ResourcesCompat.getDrawable(resources, R.drawable.ic_mode_edit_black_24dp, null)!!
val iconBorrar: Drawable =
resources.getDrawable(R.drawable.ic_delete_forever_black_24dp, resources.newTheme())
ResourcesCompat.getDrawable(resources, R.drawable.ic_delete_forever_black_24dp, null)!!
val iconPrint: Drawable =
resources.getDrawable(R.drawable.ic_print_black_24dp, resources.newTheme())
ResourcesCompat.getDrawable(resources, R.drawable.ic_print_black_24dp, null)!!
listIcons.add(iconEditar)
listIcons.add(iconBorrar)
listIcons.add(iconPrint)
@ -130,7 +125,9 @@ class ExpeditionPalletDetailFragment(
} else if (item == iconPrint) {
if (ma.havePrinter() && ma.haveSector()) {
(getString(R.string.Imprimiendo) + mobileApplication.dataStoreApp.readDataStoreKey<String>(PRINTERNAME)).toast(
(getString(R.string.Imprimiendo) + mobileApplication.dataStoreApp.readDataStoreKey<String>(
PRINTERNAME
)).toast(
requireContext()
)
viewModel.expeditionPalletPrintSet(
@ -152,40 +149,22 @@ class ExpeditionPalletDetailFragment(
LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
}
private fun getCURDATE(date: String): String {
val c = Calendar.getInstance()
val df = SimpleDateFormat(getString(R.string.dateCompleteFormat))
val df2 = SimpleDateFormat(getString(R.string.timeFormat))
c.time = df.parse(date)!!
return df2.format(c.time)
}
override fun observeViewModel() {
with(viewModel) {
loadExpeditionPalletList.observe(viewLifecycleOwner, Observer { event ->
loadExpeditionPalletList.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull { printExpeditionList(it) }
})
}
response.observe(viewLifecycleOwner, Observer {
if (it.isError) {
ma.messageWithSound(it.errorMessage, true, false)
} else {
ma.openFragmentTruckFragment()
}
})
response.observe(viewLifecycleOwner) {
ma.openFragmentTruckFragment()
}
responsePrintPallet.observe(viewLifecycleOwner, Observer {
if (it.isError) {
ma.messageWithSound(it.errorMessage, true, true, isToasted = false)
} else {
viewModel.expeditionStateAddByPallet(
itemPallet!!.Pallet,
"PALLETIZED"
)
}
})
responsePrintPallet.observe(viewLifecycleOwner) {
viewModel.expeditionStateAddByPallet(
itemPallet!!.Pallet,
"PALLETIZED"
)
}
}
}

View File

@ -7,10 +7,7 @@ import androidx.lifecycle.map
import es.verdnatura.domain.SalixCallback
import es.verdnatura.domain.formatWithQuotes
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.paletizador.model.ItemPalletViewListVO
import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletViewVO
import retrofit2.Response
@ -18,72 +15,31 @@ import retrofit2.Response
class ExpeditionPalletDetailViewModel(var context: Context) : BaseViewModel(context) {
private val _expeditionPalletList by lazy { MutableLiveData<ItemPalletViewListVO>() }
val loadExpeditionPalletList: LiveData<Event<ItemPalletViewListVO>> = _expeditionPalletList.map { Event(it) }
val loadExpeditionPalletList: LiveData<Event<ItemPalletViewListVO>> =
_expeditionPalletList.map { Event(it) }
private val _response by lazy { MutableLiveData<ResponseItemVO>() }
val response: LiveData<ResponseItemVO>
private val _response by lazy { MutableLiveData<Boolean>() }
val response: LiveData<Boolean>
get() = _response
private val _responsePrintPallet by lazy { MutableLiveData<ResponseItemVO>() }
val responsePrintPallet: LiveData<ResponseItemVO>
private val _responsePrintPallet by lazy { MutableLiveData<Boolean>() }
val responsePrintPallet: LiveData<Boolean>
get() = _responsePrintPallet
fun expeditionPalletView(vPalletFk: Int) {
salix.expeditionPalletView(arrayListOf(vPalletFk))
.enqueue(object :
SalixCallback<List<ItemPalletViewVO>>(context) {
.enqueue(object : SalixCallback<List<ItemPalletViewVO>>(context) {
override fun onSuccess(response: Response<List<ItemPalletViewVO>>) {
if (response.body() != null) {
_expeditionPalletList.value =
response.body()?.let { ItemPalletViewListVO(it) }
} else {
val listError: ArrayList<ItemPalletViewVO> = ArrayList()
listError.add(
ItemPalletViewVO(
isError = true,
errorMessage = getMessageFromAllResponse(
nameofFunction(this),
response.message()
)
)
)
_expeditionPalletList.value = ItemPalletViewListVO(listError)
}
}
override fun onError(t: Throwable) {
val listError: ArrayList<ItemPalletViewVO> = ArrayList()
listError.add(
ItemPalletViewVO(
isError = true,
errorMessage = getMessageFromAllResponse(
nameofFunction(this),
t.message!!
)
)
)
_expeditionPalletList.value = ItemPalletViewListVO(listError)
_expeditionPalletList.value = response.body()?.let { ItemPalletViewListVO(it) }
}
})
}
fun expeditionPalletDel(vPalletFk: Int) {
salix.expeditionPalletDel(vPalletFk).enqueue(object : SalixCallback<Any>(context) {
override fun onError(t: Throwable) {
_response.value = ResponseItemVO(
isError = true,
errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
)
}
override fun onSuccess(response: Response<Any>) {
_response.value = ResponseItemVO(
isError = false,
errorMessage = getMessageFromAllResponse(
nameofFunction(this),
response.message()
)
)
_response.value = true
}
})
}
@ -94,16 +50,9 @@ class ExpeditionPalletDetailViewModel(var context: Context) : BaseViewModel(cont
salix.expeditionPalletPrintLabel(arrayListOf(vPalletFk))
.enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
_responsePrintPallet.value =
ResponseItemVO(isError = false, response = response.message())
_responsePrintPallet.value = true
}
override fun onError(t: Throwable) {
_responsePrintPallet.value = ResponseItemVO(
isError = true,
errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
)
}
})
}
@ -113,19 +62,12 @@ class ExpeditionPalletDetailViewModel(var context: Context) : BaseViewModel(cont
) {
salix.expeditionStateAddByPallet(
arrayListOf(vPalletFk, vStateCode).formatWithQuotes()
)
.enqueue(object : SalixCallback<Unit>(context) {
override fun onSuccess(response: Response<Unit>) {
_response.value = ResponseItemVO(isError = false, response = response.message())
}
).enqueue(object : SalixCallback<Unit>(context) {
override fun onSuccess(response: Response<Unit>) {
_response.value = true
}
override fun onError(t: Throwable) {
_response.value = ResponseItemVO(
isError = true,
errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
)
}
})
})
}
}

View File

@ -6,7 +6,7 @@ import android.media.MediaPlayer
import android.os.Bundle
import android.view.View
import android.view.inputmethod.EditorInfo
import androidx.lifecycle.Observer
import androidx.core.content.res.ResourcesCompat
import androidx.recyclerview.widget.LinearLayoutManager
import es.verdnatura.R
import es.verdnatura.databinding.FragmentExpeditionPalletBinding
@ -27,14 +27,12 @@ import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionT
import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletListVO
import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletVO
import es.verdnatura.presentation.view.feature.paletizador.model.ItemScanList
import java.text.SimpleDateFormat
import java.util.*
@Suppress("UNUSED_ANONYMOUS_PARAMETER")
class ExpeditionPalletFragment(
var itemExpeditionTruckVO: ItemExpeditionTruckVO? = null
) : BaseFragment<FragmentExpeditionPalletBinding, ExpeditionPalletViewModel>(
ExpeditionPalletViewModel::class
) : BaseFragment<FragmentExpeditionPalletBinding, ExpeditionScanViewModel>(
ExpeditionScanViewModel::class
) {
private var adapter: ExpeditionPalletAdapter? = null
@ -61,6 +59,7 @@ class ExpeditionPalletFragment(
override fun getLayoutId(): Int = R.layout.fragment_expedition_pallet
override fun onCreate(savedInstanceState: Bundle?) {
println("ExpeditionPalletFragment")
mperror = MediaPlayer.create((activity as MainActivity), R.raw.error)
mpok = MediaPlayer.create((activity as MainActivity), R.raw.ok)
super.onCreate(savedInstanceState)
@ -70,12 +69,11 @@ class ExpeditionPalletFragment(
customDialog = CustomDialog(requireContext())
customDialogList = CustomDialogList(requireContext())
ma.hideBottomNavigation(View.GONE)
binding.mainToolbar.toolbarTitle.text =
itemExpeditionTruckVO!!.eta + " " + if (itemExpeditionTruckVO!!.Destino.isNullOrBlank()) {
itemExpeditionTruckVO!!.description
} else {
itemExpeditionTruckVO!!.Destino
}
binding.mainToolbar.toolbarTitle.text = getString(
R.string.expeditionInfo,
itemExpeditionTruckVO!!.eta,
itemExpeditionTruckVO!!.description
)
setToolBar()
setEvents()
viewModel.expeditionPalletList(
@ -95,9 +93,9 @@ class ExpeditionPalletFragment(
private fun setToolBar() {
val listIcons: ArrayList<Drawable> = ArrayList()
val iconReload: Drawable =
resources.getDrawable(R.drawable.ic_autorenew_black_24dp, resources.newTheme())
ResourcesCompat.getDrawable(resources, R.drawable.ic_autorenew_black_24dp, null)!!
val iconPlus: Drawable =
resources.getDrawable(R.drawable.ic_add_black_24dp, resources.newTheme())
ResourcesCompat.getDrawable(resources, R.drawable.ic_add_black_24dp, null)!!
listIcons.add(iconReload)
listIcons.add(iconPlus)
binding.mainToolbar.toolbarIcons.adapter =
@ -108,7 +106,9 @@ class ExpeditionPalletFragment(
itemExpeditionTruckVO!!.id
)
} else if (item == iconPlus) {
expeditionScanAdd()
viewModel.expeditionScanAdd(
vPalletFk = 0, vTruckFk = itemExpeditionTruckVO!!.id
)
}
}
})
@ -116,31 +116,29 @@ class ExpeditionPalletFragment(
LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
}
private fun getCURDATE(date: String): String {
val c = Calendar.getInstance()
val df = SimpleDateFormat(getString(R.string.dateCompleteFormat))
val df2 = SimpleDateFormat(getString(R.string.timeFormat))
c.time = df.parse(date)!!
return df2.format(c.time)
}
override fun observeViewModel() {
with(viewModel) {
loadExpeditionPalletList.observe(viewLifecycleOwner, Observer { event ->
loadExpeditionPalletList.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull { printExpeditionList(it) }
})
}
loadScanList.observe(viewLifecycleOwner, Observer { event ->
loadScanList.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull { showScanExpeditions(it) }
})
}
responseCheckexpeditionScanPut.observe(viewLifecycleOwner, Observer {
if (it.response == "1") {
responseExpeditionAddHasNotSameRoute.observe(viewLifecycleOwner) {
if (it) {
mperror?.start()
}
})
}
loadResponseScanPut.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull {
listExpeditions.add(0, BarcodeVO(code = responseScanPut.value.toString()))
customDialogList.setDescription(getString(R.string.total) + listExpeditions.size)
expeditionAdapter!!.notifyItemInserted(0)
}
}
}
@ -159,12 +157,6 @@ class ExpeditionPalletFragment(
}
private fun expeditionScanAdd() {
viewModel.expeditionScanAdd(
vPalletFk = 0, vTruckFk = itemExpeditionTruckVO!!.id
)
}
private fun showScanExpeditions(it: ItemScanList) {
listExpeditions = ArrayList()
@ -183,7 +175,7 @@ class ExpeditionPalletFragment(
if (listExpeditions.size > 0) {
onComprobarPalletViewClickListener!!.onComprobarPalletViewClickListener(
itemExpeditionTruckVO!!, ItemPalletVO(Pallet = it.list.get(0).palletFk)
itemExpeditionTruckVO!!, ItemPalletVO(Pallet = it.list[0].palletFk)
)
} else {
customDialog.setTitle(getString(R.string.info))
@ -208,27 +200,22 @@ class ExpeditionPalletFragment(
customDialogList.getEditText().setOnEditorActionListener { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) {
if (!customDialogList.getValue().isNullOrEmpty()) {
if (customDialogList.getValue().isNotEmpty()) {
try {
if (customDialogList.getValue().length >= 7) {
listExpeditions.add(0, BarcodeVO(code = customDialogList.getValue()))
customDialogList.setDescription(getString(R.string.total) + listExpeditions.size)
viewModel.expeditionScanPut(
it.list.get(0).palletFk, customDialogList.getValue().toInt()
)
viewModel.expeditionCheckRoute(
it.list[0].palletFk, customDialogList.getValue().toInt()
)
} else {
if (mperror != null) mperror!!.start()
}
viewModel.expeditionScanPut(
it.list[0].palletFk, customDialogList.getValue().toInt()
)
viewModel.checkRouteExpeditionScanPut(
it.list[0].palletFk, customDialogList.getValue().toInt()
)
} catch (e: Exception) {
if (mperror != null) mperror!!.start()
}
expeditionAdapter!!.notifyDataSetChanged()
}
customDialogList.setValue("")
ma.hideKeyboard(customDialogList.getEditText())

View File

@ -1,96 +0,0 @@
package es.verdnatura.presentation.view.feature.paletizador.fragment
import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.map
import es.verdnatura.domain.SalixCallback
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.paletizador.model.ItemPalletListVO
import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletVO
import es.verdnatura.presentation.view.feature.paletizador.model.ItemScanList
import es.verdnatura.presentation.view.feature.paletizador.model.ItemScanVO
import retrofit2.Call
import retrofit2.Response
class ExpeditionPalletViewModel(val context: Context) : BaseViewModel(context) {
private val _expeditionPalletList by lazy { MutableLiveData<ItemPalletListVO>() }
val loadExpeditionPalletList: LiveData<Event<ItemPalletListVO>> =
_expeditionPalletList.map { Event(it) }
private val _scanList by lazy { MutableLiveData<ItemScanList>() }
val loadScanList: LiveData<Event<ItemScanList>> = _scanList.map { Event(it) }
private val _response by lazy { MutableLiveData<ResponseItemVO>() }
val response: LiveData<ResponseItemVO>
get() = _response
//sergio: añadido para comprobar rutas escaneado desde PalletFragment
private val _responseCheckexpeditionScanPut by lazy { MutableLiveData<ResponseItemVO>() }
val responseCheckexpeditionScanPut: LiveData<ResponseItemVO>
get() = _responseCheckexpeditionScanPut
fun expeditionPalletList(vTruckFk: Int) {
salix.expeditionPalletList(
arrayListOf(vTruckFk)
)
.enqueue(object :
SalixCallback<List<ItemPalletVO>>(context) {
override fun onSuccess(response: Response<List<ItemPalletVO>>) {
_expeditionPalletList.value =
response.body()?.let { ItemPalletListVO(it) }
}
})
}
fun expeditionScanAdd(vPalletFk: Int, vTruckFk: Int) {
salix.expeditionScanAdd(
arrayListOf(vPalletFk, vTruckFk)
)
.enqueue(object :
SalixCallback<List<ItemScanVO>>(context) {
override fun onSuccess(response: Response<List<ItemScanVO>>) {
_scanList.value = response.body()?.let { ItemScanList(it) }
}
})
}
fun expeditionScanPut(vPalletFk: Int, vExpeditionFk: Int) {
salix.expeditionScanPut(arrayListOf(vPalletFk, vExpeditionFk))
.enqueue(object : SalixCallback<Any>(context) {
override fun onResponse(call: Call<Any>, response: Response<Any>) {
_response.value = ResponseItemVO(isError = false, response = response.message())
}
override fun onError(t: Throwable) {
_response.value = ResponseItemVO(
isError = true,
errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
)
}
})
}
fun expeditionCheckRoute(vPalletFk: Int, vExpeditionFk: Int) {
salix.expeditionCheckRoute(arrayListOf(vPalletFk, vExpeditionFk))
.enqueue(object : SalixCallback<String>(context) {
override fun onSuccess(response: Response<String>) {
_responseCheckexpeditionScanPut.value =
ResponseItemVO(isError = false, response = response.body()!!)
}
})
}
}

View File

@ -15,10 +15,10 @@ import es.verdnatura.presentation.view.feature.delivery.viewmodels.DeliveryViewM
import es.verdnatura.presentation.view.feature.ubicador.adapter.AutomaticAdapter
@Suppress("UNUSED_ANONYMOUS_PARAMETER")
class ExpeditionPreparedStateFragment(
) : BaseFragment<FragmentAutomaticAddExpeditionBinding, DeliveryViewModel>(
DeliveryViewModel::class
) {
class ExpeditionPreparedStateFragment :
BaseFragment<FragmentAutomaticAddExpeditionBinding, DeliveryViewModel>(
DeliveryViewModel::class
) {
private var adapter: AutomaticAdapter? = null
private var contador = 0

View File

@ -6,13 +6,17 @@ import android.media.MediaPlayer
import android.os.Bundle
import android.view.View
import android.view.inputmethod.EditorInfo
import androidx.lifecycle.Observer
import androidx.core.content.res.ResourcesCompat
import androidx.recyclerview.widget.LinearLayoutManager
import es.verdnatura.R
import es.verdnatura.databinding.FragmentExpeditionScanBinding
import es.verdnatura.domain.notNull
import es.verdnatura.presentation.base.BaseFragment
import es.verdnatura.presentation.common.*
import es.verdnatura.presentation.common.OnBarcodeRowClickListener
import es.verdnatura.presentation.common.OnComprobarPalletViewClickListener
import es.verdnatura.presentation.common.OnOptionsSelectedListener
import es.verdnatura.presentation.common.OnPalletClickListener
import es.verdnatura.presentation.common.OnScanLongClickListener
import es.verdnatura.presentation.view.component.CustomDialog
import es.verdnatura.presentation.view.component.CustomDialogList
import es.verdnatura.presentation.view.component.CustomDialogTwoButtons
@ -21,9 +25,11 @@ import es.verdnatura.presentation.view.feature.articulo.model.BarcodeVO
import es.verdnatura.presentation.view.feature.inventario.adapter.ToolBarAdapter
import es.verdnatura.presentation.view.feature.main.activity.MainActivity
import es.verdnatura.presentation.view.feature.paletizador.adapter.ExpeditionScanAdapter
import es.verdnatura.presentation.view.feature.paletizador.model.*
import java.text.SimpleDateFormat
import java.util.*
import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionScanList
import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionScanVO
import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionTruckVO
import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletVO
import es.verdnatura.presentation.view.feature.paletizador.model.ItemScanList
@Suppress("UNUSED_ANONYMOUS_PARAMETER")
class ExpeditionScanFragment(
@ -65,20 +71,16 @@ class ExpeditionScanFragment(
}
override fun init() {
println("ExpeditionScanFragment")
customDialog = CustomDialog(requireContext())
customDialogList = CustomDialogList(requireContext())
customDialogTwoButtons = CustomDialogTwoButtons(requireContext())
binding.expeditionScanDetailPallet.text =
getString(R.string.pallet) + " " + itemPalletVO!!.Pallet
binding.expeditionScanDetailPallet.text = getString(
R.string.expeditionInfo, getString(R.string.pallet), itemPalletVO!!.Pallet.toString()
)
ma.hideBottomNavigation(View.GONE)
binding.mainToolbar.toolbarTitle.text =
itemExpeditionTruckVO!!.eta.toString() + " " + if (itemExpeditionTruckVO!!.Destino.isNullOrBlank()) {
itemExpeditionTruckVO!!.description
} else {
itemExpeditionTruckVO!!.Destino
}
getString(R.string.expeditionInfo, itemExpeditionTruckVO?.eta.orEmpty(), itemExpeditionTruckVO?.description.orEmpty())
setToolBar()
setEvents()
viewModel.expeditionScanList(
@ -97,9 +99,9 @@ class ExpeditionScanFragment(
private fun setToolBar() {
val listIcons: ArrayList<Drawable> = ArrayList()
val iconReload: Drawable =
resources.getDrawable(R.drawable.ic_autorenew_black_24dp, resources.newTheme())
ResourcesCompat.getDrawable(resources, R.drawable.ic_autorenew_black_24dp, null)!!
val iconPlus: Drawable =
resources.getDrawable(R.drawable.ic_add_black_24dp, resources.newTheme())
ResourcesCompat.getDrawable(resources, R.drawable.ic_add_black_24dp, null)!!
listIcons.add(iconReload)
listIcons.add(iconPlus)
binding.mainToolbar.toolbarIcons.adapter =
@ -108,7 +110,9 @@ class ExpeditionScanFragment(
if (item == iconReload) {
viewModel.expeditionScanList(itemPalletVO!!.Pallet)
} else if (item == iconPlus) {
expeditionScanAdd()
viewModel.expeditionScanAdd(
vPalletFk = itemPalletVO!!.Pallet, vTruckFk = itemExpeditionTruckVO!!.id
)
}
}
@ -117,54 +121,25 @@ class ExpeditionScanFragment(
LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
}
private fun getCURDATE(date: String): String {
val c = Calendar.getInstance()
val df = SimpleDateFormat(getString(R.string.dateCompleteFormat))
val df2 = SimpleDateFormat(getString(R.string.timeFormat))
c.time = df.parse(date)!!
return df2.format(c.time)
}
override fun observeViewModel() {
with(viewModel) {
loadExpeditionScanList.observe(viewLifecycleOwner, Observer { event ->
loadExpeditionScanList.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull { printExpeditionList(it) }
})
loadScanList.observe(viewLifecycleOwner, Observer { event ->
event.getContentIfNotHandled().notNull { showScanExpeditions(it) }
})
response.observe(viewLifecycleOwner, Observer {
if (it.isError) {
ma.messageWithSound(it.errorMessage, true, false)
}
loadScanList.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull {
showScanExpeditions(it)
}
})
}
responseCheckexpeditionScanPut.observe(viewLifecycleOwner, Observer {
if (it.isError) {
ma.messageWithSound(it.errorMessage, true, false)
} else {
if (it.response == "1") {
mperror?.start()
}
responseExpeditionAddHasNotSameRoute.observe(viewLifecycleOwner) {
if (it) {
mperror?.start()
}
})
}
responseDeleteScan.observe(viewLifecycleOwner, Observer {
if (it.isError) {
ma.messageWithSound(it.errorMessage, true, false)
} else {
viewModel.expeditionScanList(itemPalletVO!!.Pallet)
}
})
}
}
@ -172,16 +147,15 @@ class ExpeditionScanFragment(
val lm = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
adapter = ExpeditionScanAdapter(it.list, object : OnScanLongClickListener {
override fun onScanLongClickListener(itemExpeditionScan: ItemExpeditionScanVO) {
override fun onScanLongClickListener(itemExpeditionScanVO: ItemExpeditionScanVO) {
customDialogTwoButtons.setTitle(
getString(R.string.ticket) + itemExpeditionScan.Ticket + getString(
getString(R.string.ticket) + itemExpeditionScanVO.Ticket + getString(
R.string.pallet
) + itemPalletVO!!.Pallet
)
.setDescription(getString(R.string.expedit) + itemExpeditionScan.expeditionFk)
).setDescription(getString(R.string.expedit) + itemExpeditionScanVO.expeditionFk)
.setOkButton(getString(R.string.delete)) {
viewModel.expeditionScanDel(
itemExpeditionScan.id
itemExpeditionScanVO.id, itemPalletVO!!.Pallet
)
customDialogTwoButtons.dismiss()
}.setKoButton(getString(R.string.cancel)) {
@ -193,23 +167,13 @@ class ExpeditionScanFragment(
binding.expeditionPalletRecyclerview.adapter = adapter
binding.expeditionPalletRecyclerview.layoutManager = lm
}
private fun expeditionScanAdd() {
viewModel.expeditionScanAdd(
vPalletFk = itemPalletVO!!.Pallet,
vTruckFk = itemExpeditionTruckVO!!.id
)
}
private fun showScanExpeditions(it: ItemScanList) {
listExpeditions = ArrayList()
it.list.forEach {
if (it.expeditionFk != "0")
listExpeditions.add(BarcodeVO(code = it.expeditionFk))
if (it.expeditionFk != "0") listExpeditions.add(BarcodeVO(code = it.expeditionFk))
}
customDialogList.setTitle(getString(R.string.pallet) + " " + itemPalletVO!!.Pallet + " \n(" + binding.mainToolbar.toolbarTitle.text + ")")
.setOkButton(getString(R.string.test)) {
@ -219,8 +183,7 @@ class ExpeditionScanFragment(
if (listExpeditions.size > 0) {
onComprobarPalletViewClickListener!!.onComprobarPalletViewClickListener(
itemExpeditionTruckVO!!,
ItemPalletVO(Pallet = it.list.get(0).palletFk)
itemExpeditionTruckVO!!, ItemPalletVO(Pallet = it.list[0].palletFk)
)
} else {
@ -236,7 +199,6 @@ class ExpeditionScanFragment(
customDialogList.dismiss()
}.setKoButton(getString(R.string.close)) {
ma.hideKeyboard(customDialogList.getEditText())
listExpeditions = ArrayList()
@ -248,24 +210,22 @@ class ExpeditionScanFragment(
customDialogList.getEditText().setOnEditorActionListener { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) {
if (!customDialogList.getValue().isNullOrEmpty()) {
if (customDialogList.getValue().isNotEmpty()) {
try {
listExpeditions.add(BarcodeVO(code = customDialogList.getValue()))
viewModel.expeditionScanPut(
it.list[0].palletFk,
customDialogList.getValue().toInt()
)
checkRouteExpeditionScanPut(
it.list[0].palletFk,
customDialogList.getValue().toInt()
it.list[0].palletFk, customDialogList.getValue().toInt()
)
expeditionAdapter!!.notifyDataSetChanged()
viewModel.checkRouteExpeditionScanPut(
it.list[0].palletFk, customDialogList.getValue().toInt()
)
expeditionAdapter!!.notifyItemInserted(listExpeditions.size - 1)
} catch (ex: Exception) {
getString(R.string.errorInput)
}
}
customDialogList.setValue("")
ma.hideKeyboard(customDialogList.getEditText())
@ -284,14 +244,6 @@ class ExpeditionScanFragment(
customDialogList.getRecyclerView().layoutManager =
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
}
private fun checkRouteExpeditionScanPut(palletFk: Int, expedition: Int) {
viewModel.checkRouteExpeditionScanPut(palletFk, expedition)
}
}

View File

@ -52,7 +52,7 @@ class ExpeditionScanSorterFragment(
override fun observeViewModel() {
with(viewModel) {
responsescan.observe(viewLifecycleOwner) {
loadResponseScan.observe(viewLifecycleOwner) {
listExpeditionScan.add(GeneralItem(itemScaned, itemScaned))
customDialogList.setDescription(getString(R.string.total) + ":" + listExpeditionScan.size)
expeditionScanAdapter!!.notifyItemInserted(listExpeditionScan.size - 1)
@ -91,7 +91,7 @@ class ExpeditionScanSorterFragment(
expeditionScanAdapter =
GeneralAdapter(listExpeditionScan, object : OnGeneralItemRowClickListener {
override fun OnGeneralItemRowClickListener(item: GeneralItem) {
override fun onGeneralItemRowClickListener(item: GeneralItem) {
}
})

View File

@ -9,8 +9,8 @@ import retrofit2.Response
class ExpeditionScanSorterViewModel(val context: Context) : BaseViewModel(context) {
private val _responseScan by lazy { MutableLiveData<String>() }
val responsescan: LiveData<String>
private val _responseScan by lazy { MutableLiveData<Any>() }
val loadResponseScan: LiveData<Any>
get() = _responseScan
fun expeditionScan(vExpeditionId: String) {

View File

@ -6,73 +6,58 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.map
import es.verdnatura.domain.SalixCallback
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.paletizador.model.ItemExpeditionScanList
import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionScanVO
import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletListVO
import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletVO
import es.verdnatura.presentation.view.feature.paletizador.model.ItemScanList
import es.verdnatura.presentation.view.feature.paletizador.model.ItemScanVO
import retrofit2.Response
class ExpeditionScanViewModel(val context: Context) : BaseViewModel(context) {
private val _expeditionPalletList by lazy { MutableLiveData<ItemPalletListVO>() }
val loadExpeditionPalletList: LiveData<Event<ItemPalletListVO>> =
_expeditionPalletList.map { Event(it) }
private val _expeditionScanList by lazy { MutableLiveData<ItemExpeditionScanList>() }
val loadExpeditionScanList: LiveData<Event<ItemExpeditionScanList>> = _expeditionScanList.map { Event(it) }
val loadExpeditionScanList: LiveData<Event<ItemExpeditionScanList>> =
_expeditionScanList.map { Event(it) }
private val _scanList by lazy { MutableLiveData<ItemScanList>() }
val loadScanList: LiveData<Event<ItemScanList>> = _scanList.map { Event(it) }
private val _response by lazy { MutableLiveData<ResponseItemVO>() }
val response: LiveData<ResponseItemVO>
get() = _response
private val _responseExpeditionAddHasNotSameRoute by lazy { MutableLiveData<Boolean>() }
val responseExpeditionAddHasNotSameRoute: LiveData<Boolean>
get() = _responseExpeditionAddHasNotSameRoute
private val _responseDeleteScan by lazy { MutableLiveData<ResponseItemVO>() }
val responseDeleteScan: LiveData<ResponseItemVO>
get() = _responseDeleteScan
private val _responseScanPut by lazy { MutableLiveData<Int>() }
val responseScanPut: LiveData<Int> = _responseScanPut
private val _responseCheckexpeditionScanPut by lazy { MutableLiveData<ResponseItemVO>() }
val responseCheckexpeditionScanPut: LiveData<ResponseItemVO>
get() = _responseCheckexpeditionScanPut
val loadResponseScanPut: LiveData<Event<Int>> =
_responseScanPut.map { Event(it) }
fun expeditionPalletList(vTruckFk: Int) {
salix.expeditionPalletList(
arrayListOf(vTruckFk)
)
.enqueue(object :
SalixCallback<List<ItemPalletVO>>(context) {
override fun onSuccess(response: Response<List<ItemPalletVO>>) {
_expeditionPalletList.value =
response.body()?.let { ItemPalletListVO(it) }
}
})
}
fun expeditionScanList(vPalletFk: Int) {
salix.expeditionScanList(arrayListOf(vPalletFk))
.enqueue(object :
SalixCallback<List<ItemExpeditionScanVO>>(context) {
.enqueue(object : SalixCallback<List<ItemExpeditionScanVO>>(context) {
override fun onSuccess(response: Response<List<ItemExpeditionScanVO>>) {
if (response.body() != null) {
_expeditionScanList.value =
response.body()?.let { ItemExpeditionScanList(it) }
} else {
val listError: ArrayList<ItemExpeditionScanVO> = ArrayList()
listError.add(
ItemExpeditionScanVO(
0,
isError = true,
errorMessage = getMessageFromAllResponse(
nameofFunction(this),
response.message()
)
)
)
_expeditionScanList.value = ItemExpeditionScanList(listError)
}
}
override fun onError(t: Throwable) {
val listError: ArrayList<ItemExpeditionScanVO> = ArrayList()
listError.add(
ItemExpeditionScanVO(
0,
isError = true,
errorMessage = getMessageFromAllResponse(
nameofFunction(this),
t.message!!
)
)
)
_expeditionScanList.value = ItemExpeditionScanList(listError)
_expeditionScanList.value = response.body()?.let { ItemExpeditionScanList(it) }
}
})
@ -80,120 +65,51 @@ class ExpeditionScanViewModel(val context: Context) : BaseViewModel(context) {
fun expeditionScanAdd(vPalletFk: Int, vTruckFk: Int) {
salix.expeditionScanAdd(arrayListOf(vPalletFk, vTruckFk))
.enqueue(object :
SalixCallback<List<ItemScanVO>>(context) {
.enqueue(object : SalixCallback<List<ItemScanVO>>(context) {
override fun onSuccess(response: Response<List<ItemScanVO>>) {
if (response.body() != null) {
_scanList.value = response.body()?.let { ItemScanList(it) }
} else {
val listError: ArrayList<ItemScanVO> = ArrayList()
listError.add(
ItemScanVO(
"", 0,
isError = true,
errorMessage = getMessageFromAllResponse(
nameofFunction(this),
response.message()
)
)
)
_scanList.value = ItemScanList(listError)
}
}
override fun onError(t: Throwable) {
val listError: ArrayList<ItemScanVO> = ArrayList()
listError.add(
ItemScanVO(
"", 0,
isError = true,
errorMessage = getMessageFromAllResponse(
nameofFunction(this),
t.message!!
)
)
)
_scanList.value = ItemScanList(listError)
_scanList.value = response.body()?.let { ItemScanList(it) }
}
})
}
fun expeditionScanPut(
vPalletFk: Int,
vExpeditionFk: Int
vPalletFk: Int, vExpeditionFk: Int
) {
salix.expeditionScanPut(
arrayListOf(vPalletFk, vExpeditionFk)
)
.enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
_response.value =
ResponseItemVO(isError = false, response = response.message())
).enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
_responseScanPut.value = vExpeditionFk
}
}
override fun onError(t: Throwable) {
_response.value = ResponseItemVO(
isError = true, errorMessage = getMessageFromAllResponse(
nameofFunction(this), t.message!!
)
)
}
})
})
}
fun checkRouteExpeditionScanPut(
vPalletFk: Int,
vExpeditionFk: Int
vPalletFk: Int, vExpeditionFk: Int
) {
salix.expeditionCheckRoute(
arrayListOf(
vPalletFk,
vExpeditionFk
vPalletFk, vExpeditionFk
)
).enqueue(object : SalixCallback<String>(context) {
override fun onSuccess(response: Response<String>) {
if (response.body() == null) {
_responseCheckexpeditionScanPut.value = ResponseItemVO(
isError = true,
errorMessage = getMessageFromAllResponse(
nameofFunction(this),
response.message()
)
)
} else {
_responseCheckexpeditionScanPut.value =
ResponseItemVO(isError = false, response = response.body()!!)
).enqueue(object : SalixCallback<Int>(context) {
override fun onSuccess(response: Response<Int>) {
}
_responseExpeditionAddHasNotSameRoute.value = response.body()!! == 1
}
override fun onError(t: Throwable) {
_responseCheckexpeditionScanPut.value = ResponseItemVO(
isError = true,
errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
)
})
}
fun expeditionScanDel(expeditionFk: Int, palletId: Int) {
salix.expeditionScanDel(expeditionFk).enqueue(object : SalixCallback<Any>(context) {
override fun onSuccess(response: Response<Any>) {
expeditionScanList(palletId)
}
})
}
fun expeditionScanDel(vScanFk: Int) {
salix.expeditionScanDel(vScanFk)
.enqueue(object : SalixCallback<Any>(context) {
override fun onError(t: Throwable) {
_responseDeleteScan.value = ResponseItemVO(
isError = true, errorMessage = getMessageFromAllResponse(
nameofFunction(this), t.message!!
)
)
}
override fun onSuccess(response: Response<Any>) {
_responseDeleteScan.value =
ResponseItemVO(isError = false, response = response.message())
}
})
}
}

View File

@ -91,9 +91,7 @@ class ExpeditionTruckListFragment :
loadExpeditionTruckList.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull { printExpeditionList(it) }
}
loadResponseExpeditionAdd.observe(viewLifecycleOwner) { event ->
viewModel.expeditionTruckList()
}
}
}

View File

@ -21,9 +21,6 @@ class ExpeditionTruckListViewModel(val context: Context) : BaseViewModel(context
val loadExpeditionTruckList: LiveData<Event<ItemExpeditionTruckList>> =
_expeditionTruckList.map { Event(it) }
private val _response by lazy { MutableLiveData<String>() }
val loadResponseExpeditionAdd: LiveData<Event<String>> = _response.map { Event(it) }
fun expeditionTruckList() {
salix.roadMapStopGet(
"""{"where": { "eta": {
@ -33,8 +30,7 @@ class ExpeditionTruckListViewModel(val context: Context) : BaseViewModel(context
}"]}},"order": "eta ASC"}"""
).enqueue(object : SalixCallback<List<ItemExpeditionTruckVO>>(context) {
override fun onSuccess(response: Response<List<ItemExpeditionTruckVO>>) {
_expeditionTruckList.value =
response.body()?.let { ItemExpeditionTruckList(it) }
_expeditionTruckList.value = response.body()?.let { ItemExpeditionTruckList(it) }
}
})
}
@ -42,12 +38,11 @@ class ExpeditionTruckListViewModel(val context: Context) : BaseViewModel(context
fun roadMapStopAdd(vHour: String, vDescription: String) {
salix.roadMapStopAdd(
ExpeditionTruckSalix(
eta = "${LocalDate.now()} $vHour",
description = vDescription
eta = "${LocalDate.now()} $vHour", description = vDescription
)
).enqueue(object : SalixCallback<Any>(context) {
override fun onResponse(call: Call<Any>, response: Response<Any>) {
_response.value = response.message()
expeditionTruckList()
}
})