diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragment.kt index 140dd8e8..5110ef13 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragment.kt @@ -30,6 +30,7 @@ import es.verdnatura.presentation.view.feature.main.activity.MainActivity import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO import es.verdnatura.presentation.view.feature.ubicador.adapter.UbicadorAdapter import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorVO +import java.lang.Boolean.TRUE @Suppress("UNUSED_ANONYMOUS_PARAMETER") @@ -52,6 +53,7 @@ class UbicadorFragment( private var pasillerosItemClickListener: OnPasillerosItemClickListener? = null private var isShelvinLogfromMainScreen = false private var modeCheckUbication = false + private var itemScannedScreen = 0 var mperror: MediaPlayer? = null var mpok: MediaPlayer? = null var isBack = false @@ -112,7 +114,7 @@ class UbicadorFragment( iconReload.setImageResource(R.drawable.ic_autorenew_black_24dp) - // binding.mainToolbar.switchButton.visibility = VISIBLE + //Tarea#5052 binding.mainToolbar.switchButton.visibility = VISIBLE binding.mainToolbar.switchButton.setOnCheckedChangeListener { buttonView, isChecked -> if (binding.mainToolbar.toolbarTitle.text == getString(R.string.titleUbicator)) { ma.messageWithSound(getString(R.string.scanShelving), false, false) @@ -245,12 +247,9 @@ class UbicadorFragment( ) } - ma.hideKeyboard(binding.editPrioridad) - //return@setOnEditorActionListener false } - //return@setOnEditorActionListener false binding.editMatricula.requestFocus() return@setOnEditorActionListener false } @@ -259,7 +258,6 @@ class UbicadorFragment( binding.automaticImg.setOnClickListener { if (!shelvingFk.isNullOrEmpty()) - //Tarea #4778 Para llamar a Revisar items poner R.string.titleChecker ma.onPasillerosItemClickListener( PasillerosItemVO(title = getString(R.string.titleAuto)), //PasillerosItemVO(title = getString(R.string.titleChecker)), @@ -362,7 +360,8 @@ class UbicadorFragment( customDialog.setTitle(getString(R.string.empty)) .setDescription(getString(R.string.operationNoReturn)) .setOkButton(getString(R.string.empty)) { - viewModel.clearShelvingList(shelvingFk + viewModel.clearShelvingList( + shelvingFk ) listItems.forEach { it.stickers = "0" @@ -382,37 +381,27 @@ class UbicadorFragment( } private fun checkUbications(itemScanned: Int) { - - for (item in listItems) { - if (item.item == itemScanned) { - item.checked = true - ma.messageWithSound("", false, true, "", false) - } - } + itemScannedScreen = itemScanned + val listInt: ArrayList = ArrayList() if (listItems.filter { it.item == itemScanned }.isEmpty()) { - binding.splashProgress.visibility = View.GONE - listItems.add( - ItemUbicadorVO( - item = itemScanned, - visible = "0", - packing = "0", - grouping = "0", - isNew = true - ) - ) - listLocalItems = listItems.clone() as ArrayList + listInt.add(itemScanned) + } else { + listItems.sortedBy { it.isChecked }.forEachIndexed { index, item -> + if (item.item == itemScanned) { + item.checked = true + listInt.add(item.item) + ma.messageWithSound("", false, true, "", false) + } + } - viewModel.itemShelvingMake( - - shelving = shelvingFk, - item = itemScanned, - quantity = 0, - packing = null, - warehouse = getDataInt(WAREHOUSEFK), - grouping = null - ) } + viewModel.itemShelving_addList( + shelvingFk, + "" + listInt + "", + TRUE, + getDataInt(WAREHOUSEFK) + ) adapter!!.notifyDataSetChanged() } @@ -488,7 +477,7 @@ class UbicadorFragment( } adapter = UbicadorAdapter( - listItems, + listItems.sortedBy { it.isChecked }, onPasillerosItemClickListener = pasillerosItemClickListener!!, onVisibleClickListener = object : OnVisibleClickListener { override fun onVisibleClickListener(item: ItemUbicadorVO) { @@ -520,18 +509,38 @@ class UbicadorFragment( LinearLayoutManager( requireContext(), LinearLayoutManager.VERTICAL, - true + false ) if (isShelvinLogfromMainScreen) { - //tarea 4454 viewModel.shelvinLog_add(shelvingFk) } + if (modeCheckUbication) { + listItems.sortedBy { it.isChecked }.forEachIndexed { index, item -> + if (item.item == itemScannedScreen) { + binding.locationRecyclerview.scrollToPosition(index) + } + } + } else { + (binding.locationRecyclerview.layoutManager as LinearLayoutManager).scrollToPosition( + 0 + ) + } } } }) + responseAddList.observe(viewLifecycleOwner, Observer { + if (it.isError) { + ma.messageWithSound(it.errorMessage, it.isError, false) + + } else { + binding.splashProgress.visibility = VISIBLE + viewModel.itemShelvingList(shelvingFk) + + } + }) response.observe(viewLifecycleOwner, Observer { if (it.isError) { @@ -544,7 +553,7 @@ class UbicadorFragment( } }) responseCode.observe(viewLifecycleOwner, Observer { - binding.splashProgress.visibility = View.GONE + binding.splashProgress.visibility = GONE if (it.isError) { ma.messageWithSound(it.errorMessage, true, true) } else { @@ -601,7 +610,11 @@ class UbicadorFragment( } saveNewItem( customDialogUbicador.getItemValue().toInt(), - if (customDialogUbicador.getEtiquetaValue().isNullOrEmpty()) {1}else{customDialogUbicador.getEtiquetaValue().toInt()}, + if (customDialogUbicador.getEtiquetaValue().isNullOrEmpty()) { + 1 + } else { + customDialogUbicador.getEtiquetaValue().toInt() + }, if (customDialogUbicador.getPackingValue().isNullOrEmpty()) { null } else { @@ -676,7 +689,11 @@ class UbicadorFragment( }, if (delete) packingUpdate else null, itemUbicador.id, - if (customDialogUbicador.getGroupingValue().isNullOrEmpty()) {null}else{customDialogUbicador.getGroupingValue().toInt()} + if (customDialogUbicador.getGroupingValue().isNullOrEmpty()) { + null + } else { + customDialogUbicador.getGroupingValue().toInt() + } ) return@setOnEditorActionListener true } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorViewModel.kt index 498691f7..f0afb6a4 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorViewModel.kt @@ -41,6 +41,9 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { val responseCode: LiveData get() = _responseCode + private val _responseAddList by lazy { MutableLiveData() } + val responseAddList: LiveData = _responseAddList + fun itemShelvingList( vShelvingFk: String ) { @@ -105,7 +108,34 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { } }) } + fun itemShelving_addList( + shelving: String, + items: Any, + isChecking: Boolean, + warehouse: Int + ) { + silex.itemShelving_addList( + shelving, + items, + isChecking, + warehouse + ).enqueue(object : + SilexCallback(context) { + override fun onError(t: Throwable) { + _responseAddList.value = ResponseItemVO( + isError = true, errorMessage = getMessageFromAllResponse( + nameofFunction(this), t.message!! + ) + ) + } + override fun onSuccess(response: Response) { + _responseAddList.value = + ResponseItemVO(isError = false, response = response.message()!!) + + } + }) + } fun itemShelvingMake( shelving: String, item: Int,