feat: boxPickingPrepared refs #7855

This commit is contained in:
Sergio De la torre 2024-09-24 10:25:52 +02:00
parent 3f8292c261
commit 9ce0349f41
1 changed files with 60 additions and 27 deletions

View File

@ -15,7 +15,7 @@ import es.verdnatura.presentation.view.feature.delivery.viewmodels.DeliveryViewM
import es.verdnatura.presentation.view.feature.ubicador.adapter.AutomaticAdapter
@Suppress("UNUSED_ANONYMOUS_PARAMETER")
class ExpeditionPreparedStateFragment :
class ExpeditionPreparedStateFragment(var codeState: String, var title: String) :
BaseFragment<FragmentAutomaticAddExpeditionBinding, DeliveryViewModel>(
DeliveryViewModel::class
) {
@ -24,19 +24,22 @@ class ExpeditionPreparedStateFragment :
private var contador = 0
private var isScanned = false
private val listExpeditions: ArrayList<ExpeditionSalix> = arrayListOf()
private var expeditionStateTypeId: Number = 0
companion object {
fun newInstance() = ExpeditionPreparedStateFragment()
fun newInstance(codeState: String, title: String) =
ExpeditionPreparedStateFragment(codeState = codeState, title = title)
}
override fun getLayoutId(): Int = R.layout.fragment_automatic_add_expedition
override fun init() {
ma.hideBottomNavigation(View.GONE)
binding.mainToolbar.toolbarTitle.text = getString(R.string.scanExpeditions)
binding.mainToolbar.toolbarTitle.text = title
setEvents()
setViews()
setToolBar()
viewModel.getExpeditionStateId(codeState)
super.init()
}
@ -46,7 +49,7 @@ class ExpeditionPreparedStateFragment :
private fun setSubtitle() {
binding.mainToolbar.toolbarSubtitle.text =
getString(R.string.countNumber, getString(R.string.label), contador)
getString(R.string.countNumber, getString(R.string.label), listExpeditions.size)
}
private fun setViews() {
@ -54,12 +57,12 @@ class ExpeditionPreparedStateFragment :
AutomaticAdapter(listExpeditions.map { it.expeditionFk.toLong() } as ArrayList<Long>,
object : OnAutomaticItemClickListener {
override fun onAutomaticItemClickListener(position: Int) {
contador -= 1
setSubtitle()
if (listExpeditions.size > position) {
listExpeditions.removeAt(position)
}
adapter!!.updateItems(listExpeditions.map { it.expeditionFk.toLong() } as ArrayList<Long>)
setSubtitle()
}
})
binding.itemsRecyclerview.adapter = adapter
@ -75,21 +78,25 @@ class ExpeditionPreparedStateFragment :
isScanned =
event != null && event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER
if (binding.editMatricula.text.toString().isNotEmpty()) {
contador += 1
setSubtitle()
try {
listExpeditions.add(
ExpeditionSalix(
expeditionFk = itemScanValue(
textScanned_filterDouble(binding.editMatricula.text.toString()),
arrayOf("expedition"),
"id"
).toString().toLong(), stateCode = "PREPARED", isScanned = 0
val itemScaned = itemScanValue(
textScanned_filterDouble(binding.editMatricula.text.toString()),
arrayOf("expedition"),
"id"
).toString().toLong()
if (!(listExpeditions.any { it.expeditionFk == itemScaned })) {
viewModel.findExpedition(
itemScaned, expeditionStateTypeId
)
)
adapter!!.updateItems(listExpeditions.map { it.expeditionFk.toLong() } as ArrayList<Long>)
binding.itemsRecyclerview.scrollToPosition(0)
binding.itemsRecyclerview.scrollToPosition(0)
} else {
ma.messageWithSound(
message = getString(R.string.boxDuplicated),
isError = true,
isPlayed = true,
isToasted = true
)
}
} catch (ex: Exception) {
ma.messageWithSound(ex.message.toString(), isError = true, isPlayed = true)
}
@ -108,12 +115,12 @@ class ExpeditionPreparedStateFragment :
}
binding.buttonFinalizar.setOnClickListener {
if (listExpeditions.isNotEmpty()) viewModel.expeditionStateAddSalix(
Expeditions(
listExpeditions
)
) else ma.onMyBackPressed()
if (listExpeditions.isNotEmpty())
viewModel.expeditionStateAddSalix(
Expeditions(
listExpeditions
)
) else ma.onMyBackPressed()
}
binding.mainToolbar.backButton.setOnClickListener {
@ -126,8 +133,34 @@ class ExpeditionPreparedStateFragment :
responseStateAdd.observe(viewLifecycleOwner) {
ma.onMyBackPressed()
}
responseExpeditionStateId.observe(viewLifecycleOwner) {
expeditionStateTypeId = it
}
responseFindExpeditionId.observe(viewLifecycleOwner) {
if (it != 0) {
listExpeditions.add(
ExpeditionSalix(
expeditionFk = it,
stateCode = codeState,
isScanned = if (isScanned) 1 else 0
)
)
setSubtitle()
adapter!!.updateItems(listExpeditions.map { it.expeditionFk.toLong() } as ArrayList<Long>)
} else {
ma.messageWithSound(
if (codeState == "PREPARED") getString(R.string.expeditionPrepared) else getString(
R.string.errorBoxPicking
),
isError = true,
isPlayed = true,
isToasted = true
)
}
}
}
}
}