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