From e000ca66bcb3c4f78b12f23ed85dabb7538cc434 Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Thu, 27 Apr 2023 08:09:24 +0200 Subject: [PATCH] refs #4979 --- .../category/ChangeCategoryFragment.kt | 141 ++++++++++++++++++ app/src/main/res/drawable/ic_category.xml | 9 ++ app/src/main/res/drawable/ic_packaging.xml | 2 +- app/src/main/res/values-es/strings.xml | 3 + app/src/main/res/values/strings.xml | 3 + 5 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/category/ChangeCategoryFragment.kt create mode 100644 app/src/main/res/drawable/ic_category.xml diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/category/ChangeCategoryFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/category/ChangeCategoryFragment.kt new file mode 100644 index 00000000..82f6ddd9 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/category/ChangeCategoryFragment.kt @@ -0,0 +1,141 @@ +package es.verdnatura.presentation.view.feature.category + +import android.view.View +import android.view.inputmethod.EditorInfo +import es.verdnatura.R +import es.verdnatura.databinding.FragmentGeneralBlackBinding +import es.verdnatura.domain.toast +import es.verdnatura.presentation.base.BaseFragment +import es.verdnatura.presentation.common.itemScanValue +import es.verdnatura.presentation.view.component.CustomDialogInput +import es.verdnatura.presentation.view.feature.packingHolland.fragment.PackingHollandViewModel + + + //Tarea #4940 + class ChangeCategoryFragment(var entrypoint: String) : + BaseFragment( + PackingHollandViewModel::class + ) { + + override fun getLayoutId(): Int = R.layout.fragment_general_black + private var shelvingScaned: Int = 0 + private lateinit var customDialogInput: CustomDialogInput + + companion object { + fun newInstance(entrypoint: String) = ChangeCategoryFragment(entrypoint = entrypoint) + } + + override fun init() { + + customDialogInput = CustomDialogInput(requireContext()) + binding.mainToolbar.toolbarTitle.text = entrypoint + binding.splashProgress.visibility = View.GONE + binding.scanInput.visibility = View.VISIBLE + setEvents() + + super.init() + } + + private fun setEvents() { + + binding.mainToolbar.backButton.setOnClickListener { + requireActivity().onBackPressed() + } + + binding.scanInput.requestFocus() + binding.scanInput.setOnEditorActionListener { _, actionId, _ -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { + if (!binding.scanInput.text.isNullOrEmpty()) { + + try { + + binding.scanInput.setText( + itemScanValue( + binding.scanInput.text.toString(), + "buy", + "more" + ).toString() + ) + shelvingScaned = binding.scanInput.text.toString().toInt() + showQuantityPacking() + } catch (ex: Exception) { + ex.message!!.toast(requireActivity()) + } + + } + + binding.scanInput.setText("") + ma.hideKeyboard(binding.scanInput) + return@setOnEditorActionListener true + } + false + } + } + + override fun observeViewModel() { + with(viewModel) { + response.observe(viewLifecycleOwner) { + binding.splashProgress.visibility = View.GONE + if (it.isError) { + ma.messageWithSound(it.errorMessage, true, false) + } else { + showQuantityPacking() + } + + } + + } + } + + + private fun showQuantityPacking() { + + + customDialogInput.setTitle(getString(R.string.titleChangeCategory)) + customDialogInput.setDescription(getString(R.string.ubication) + shelvingScaned) + .setValue("") + .setOkButton(getString(R.string.modify)) { + + if (customDialogInput.getValue().isNotEmpty() + ) { + callPacking(customDialogInput.getValue()) + } + + + }.setKoButton(getString(R.string.cancel)) { + customDialogInput.dismiss() + }.show() + + //ma.hideKeyboard(customDialogInput.getEditText()) + + customDialogInput.getEditText().setOnEditorActionListener { _, actionId, _ -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5 || actionId == 6) { + + if (customDialogInput.getValue().isNotEmpty()) { + callPacking(customDialogInput.getValue()) + } + + return@setOnEditorActionListener true + } + false + } + + customDialogInput.setFocusText() + } + + private fun callPacking(value: String) { + try { + binding.splashProgress.visibility = View.VISIBLE + viewModel.travel_updatePacking( + itemFk = shelvingScaned, + packingFk = value.toInt() + ) + + } catch (ex: Exception) { + getString(R.string.errorInput).toast(requireActivity()) + } + customDialogInput.setValue("") + } + } + + diff --git a/app/src/main/res/drawable/ic_category.xml b/app/src/main/res/drawable/ic_category.xml new file mode 100644 index 00000000..f29c30e8 --- /dev/null +++ b/app/src/main/res/drawable/ic_category.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_packaging.xml b/app/src/main/res/drawable/ic_packaging.xml index 6d175516..ee54d304 100644 --- a/app/src/main/res/drawable/ic_packaging.xml +++ b/app/src/main/res/drawable/ic_packaging.xml @@ -4,5 +4,5 @@ android:width="24dp" android:viewportWidth="24" android:viewportHeight="24"> - + \ No newline at end of file diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 5ebf31a9..3e8b4255 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -556,5 +556,8 @@ El número de carros ahora solo se puede modificar por los encargados Va a modificar el número de serie asociado a su dispositivo. Indica la cantidad que coges + Cambiar a A2 + Cambiar a A2 + Indica el carro donde está ubicado el item: diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 875bf8c5..a3d771a1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -396,6 +396,7 @@ Ubicator Packing Holanda Self-autoconsumption + Change to A2 Self-autoconsumption from your warehouse Reubication Add Automatically items to shelving @@ -550,10 +551,12 @@ Insert the amount correctly Operación realizada correctamente Self-consumption + Change to A2 Address Modify It\'s not possible to update. Problem with the download of app "Introduce new packing for the item : " + "Introduce ubication for the item : " The number of wagons can now only be changed by managers