feat: refs#8624 cleanAction

This commit is contained in:
Sergio De la torre 2025-02-28 09:06:23 +01:00
parent 8d1110d09e
commit 04380327ab
1 changed files with 118 additions and 21 deletions

View File

@ -1,6 +1,7 @@
package es.verdnatura.presentation.view.feature.collection.fragment
import android.content.Context
import android.graphics.PorterDuff
import android.graphics.drawable.Drawable
import android.media.MediaPlayer
import android.os.Build
@ -18,6 +19,7 @@ import android.view.inputmethod.InputMethodManager
import android.widget.ImageView
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
@ -62,6 +64,8 @@ import es.verdnatura.presentation.view.feature.articulo.model.BarcodeVO
import es.verdnatura.presentation.view.feature.collection.ItemVO
import es.verdnatura.presentation.view.feature.collection.adapter.SaleAdapter
import es.verdnatura.presentation.view.feature.main.activity.MainActivity
import es.verdnatura.presentation.view.feature.pasillero.model.CleanAction
import es.verdnatura.presentation.view.feature.pasillero.model.CodeWorkerAction
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO
import es.verdnatura.presentation.view.feature.sacador.model.MistakeTypeVO
@ -69,6 +73,7 @@ import es.verdnatura.presentation.view.feature.sacador.model.PlacementSupplyList
import es.verdnatura.presentation.view.feature.sacador.model.PlacementSupplyVO
import es.verdnatura.presentation.view.feature.sacador.model.PlacementVO
import es.verdnatura.presentation.view.feature.sacador.model.SaleVO
import kotlinx.coroutines.runBlocking
import org.json.JSONObject
@Suppress("UNUSED_ANONYMOUS_PARAMETER")
@ -134,6 +139,7 @@ class CollectionFragmentPicker(
private var isVerifiedCollection = false
private var hasFilterByLevel = false
private lateinit var iconClean: ImageView
companion object {
fun newInstance(collection: CollectionVO, type: String) =
@ -207,8 +213,8 @@ class CollectionFragmentPicker(
collection.collectionFk.let {
binding.mainToolbar.toolbarTitle.text = collection.collectionFk.toString()
}
val listIcons: ArrayList<ImageView> = ArrayList()
val iconPrint = ImageView(context)
iconPrint.setImageResource(R.drawable.ic_print_black_24dp)
val iconAdd = ImageView(context)
@ -221,6 +227,9 @@ class CollectionFragmentPicker(
iconPhone.setImageResource(R.drawable.phone_call)
val iconParking = ImageView(context)
iconParking.setImageResource(R.drawable.ic_local_parking_black_24dp)
iconClean = ImageView(context)
iconClean.setImageResource(R.drawable.ic_clean_shelving)
val iconUpdate = ImageView(context)
iconUpdate.setImageResource(R.drawable.ic_autorenew_black_24dp)
@ -231,7 +240,7 @@ class CollectionFragmentPicker(
iconPhone.tooltipText = getTooltip(R.drawable.phone_call)
iconParking.tooltipText = getTooltip(R.drawable.ic_local_parking_black_24dp)
iconUpdate.tooltipText = getTooltip(R.drawable.ic_autorenew_black_24dp)
iconClean.tooltipText = getTooltip(R.drawable.ic_clean_shelving)
}
listIcons.add(iconPrint)
if (type == CONTROLADOR) {
@ -246,6 +255,8 @@ class CollectionFragmentPicker(
listIcons.add(iconAdd)
if (type == SACADOR) {
//Tarea 8624
// listIcons.add(iconClean)
listIcons.add(iconUpdate)
listIcons.remove(iconWorker)
}
@ -260,6 +271,7 @@ class CollectionFragmentPicker(
override fun onOptionsItemSelected(item: Drawable) {
when (item) {
iconClean.drawable -> clean()
iconPrint.drawable -> print()
iconAdd.drawable -> addItem()
iconWorker.drawable -> showUser()
@ -272,9 +284,86 @@ class CollectionFragmentPicker(
}
}
})
binding.mainToolbar.toolbarIcons.layoutManager =
LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
updateIconColor()
}
private fun updateIconColor() {
val newColor =
ContextCompat.getColor(
requireContext(),
if (mobileApplication.dataStoreApp.readDataStoreKey<String>("SHELVINGACTION")
.isNotBlank()
) R.color.verdnatura_orange_salix else R.color.verdnatura_white
)
iconClean.setColorFilter(newColor, PorterDuff.Mode.SRC_IN)
binding.mainToolbar.toolbarIcons.adapter?.notifyDataSetChanged()
}
private fun addWorkerActivity(codeWorkerAction: CodeWorkerAction, shelving: String) {
viewModel.addWorkerActivity(
CleanAction(
codeWorkerAction = codeWorkerAction,
shelving = shelving.uppercase(),
description = shelving.uppercase()
)
)
}
private fun clean() {
val shelving = mobileApplication.dataStoreApp.readDataStoreKey<String>(
"SHELVINGACTION"
)
if (
shelving.isNotBlank()
) {
addWorkerActivity(
CodeWorkerAction.SHELVING_CLEAN_STOP,
shelving = shelving
)
} else {
customDialogInput.setTitle(getString(R.string.titleCleanShelving))
.setDescription(getString(R.string.descripOrganize))
.setOkButton(getString(R.string.organize)) {
ma.hideKeyboard(customDialogInput.getEditText())
actionOrganizeClean(customDialogInput.getValue())
}.setKoButton(getString(R.string.cancel)) {
customDialogInput.dismiss()
}.setValue("").show()
customDialogInput.getEditText().requestFocus()
customDialogInput.getEditText().setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) {
actionOrganizeClean(customDialogInput.getValue())
return@setOnEditorActionListener true
}
false
}
}
}
private fun actionOrganizeClean(input: String) {
if (input.isShelving()) {
addWorkerActivity(
CodeWorkerAction.SHELVING_CLEAN_START,
shelving = input
)
} else {
ma.messageWithSound(
message = getString(R.string.errorInput),
isError = true,
isPlayed = true,
isToasted = true
)
}
customDialogInput.dismiss()
}
private fun updateScreen() {
@ -331,9 +420,7 @@ class CollectionFragmentPicker(
ma.hideKeyboard(customDialogList.getEditText())
try {
val saleGroupScanned = itemScanValue(
customDialogList.getValue(),
arrayOf("saleGroup"),
"id"
customDialogList.getValue(), arrayOf("saleGroup"), "id"
).toString()
isScanned =
event != null && event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER
@ -464,7 +551,22 @@ class CollectionFragmentPicker(
@RequiresApi(Build.VERSION_CODES.O)
override fun observeViewModel() {
with(viewModel) {
loadResponseActivity.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull {
println("shelvinAction ${it}")
runBlocking {
mobileApplication.dataStoreApp.editDataStoreKey(
"SHELVINGACTION",
if (it.codeWorkerAction == CodeWorkerAction.SHELVING_CLEAN_START) it.shelving else ""
)
}
updateIconColor()
}
}
collectionTicketList.observe(viewLifecycleOwner, Observer {
if (!it.isError) {
@ -929,8 +1031,7 @@ class CollectionFragmentPicker(
}
saleAdapter = SaleAdapter(
myGroupList as MutableList,
saleAdapter = SaleAdapter(myGroupList as MutableList,
pasillerosItemClickListener!!,
object : OnQuantityClickListener {
@ -1010,8 +1111,7 @@ class CollectionFragmentPicker(
override fun onTicketColorListener(sale: SaleVO) {
}
}
)
})
lm = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
@ -1039,7 +1139,7 @@ class CollectionFragmentPicker(
}
printObservations(observations)
if (!isVerifiedCollection) {
if (!isVerifiedCollection && mobileApplication.userId != 19591) {
binding.fragmentSacadorCollections.visibility = View.INVISIBLE
verifyCollection()
}
@ -2347,18 +2447,15 @@ class CollectionFragmentPicker(
}
if (isTicket) {
val labelDialogHelper = LabelDialogHelper(requireContext())
labelDialogHelper.showLabelDialog(
onItemSelected = { labelCount ->
viewModel.collectionStickerPrint(
collectionFk = collection.collectionFk,
labelCount = labelCount
)
labelDialogHelper.showLabelDialog(onItemSelected = { labelCount ->
viewModel.collectionStickerPrint(
collectionFk = collection.collectionFk, labelCount = labelCount
)
(getString(R.string.Imprimiendo) + mobileApplication.dataStoreApp.readDataStoreKey<String>(
PRINTERNAME
)).toast(requireContext())
}
)
(getString(R.string.Imprimiendo) + mobileApplication.dataStoreApp.readDataStoreKey<String>(
PRINTERNAME
)).toast(requireContext())
})
} else {
viewModel.collectionStickerPrint(
collectionFk = collection.collectionFk, null