From 75a621094ceb21fd8bbf4a950ed9346a1decb6c0 Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Fri, 13 Sep 2024 11:41:45 +0200 Subject: [PATCH] feat: multipleShelvingsAdd refs #7805 --- .../java/es/verdnatura/di/viewModelModule.kt | 6 - .../presentation/base/BaseFragment.kt | 1 + .../feature/main/activity/MainActivity.kt | 30 ++-- .../fragment/AutomaticAddItemFragment.kt | 142 +++++++++++++++--- .../fragment/AutomaticAddItemViewModel.kt | 52 ------- .../ubicador/fragment/UbicadorFragmentNew.kt | 29 ++-- .../ubicador/fragment/UbicadorViewModel.kt | 24 ++- app/src/main/res/drawable/ic_add_multiple.xml | 9 ++ app/src/main/res/values-es/strings.xml | 5 +- app/src/main/res/values-fr/strings.xml | 5 +- app/src/main/res/values-pt/strings.xml | 5 +- app/src/main/res/values/strings.xml | 5 +- 12 files changed, 209 insertions(+), 104 deletions(-) delete mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/AutomaticAddItemViewModel.kt create mode 100644 app/src/main/res/drawable/ic_add_multiple.xml diff --git a/app/src/main/java/es/verdnatura/di/viewModelModule.kt b/app/src/main/java/es/verdnatura/di/viewModelModule.kt index 4aad49c1..cf2a7d8a 100644 --- a/app/src/main/java/es/verdnatura/di/viewModelModule.kt +++ b/app/src/main/java/es/verdnatura/di/viewModelModule.kt @@ -34,7 +34,6 @@ import es.verdnatura.presentation.view.feature.roadmap.fragment.RoadMapListViewM import es.verdnatura.presentation.view.feature.sacador.fragment.SacadorViewModel import es.verdnatura.presentation.view.feature.sacador.fragment.showticket.ShowTicketViewModel import es.verdnatura.presentation.view.feature.ticket.fragment.TicketViewModel -import es.verdnatura.presentation.view.feature.ubicador.fragment.AutomaticAddItemViewModel import es.verdnatura.presentation.view.feature.ubicador.fragment.UbicadorViewModel import org.koin.android.ext.koin.androidContext import org.koin.androidx.viewmodel.dsl.viewModel @@ -91,11 +90,6 @@ val viewModelModule = module { UbicadorViewModel(androidContext()) } - // Ubicador // Automatic - viewModel { - AutomaticAddItemViewModel(androidContext()) - } - // Ajustes viewModel { AjustesViewModel(androidContext()) diff --git a/app/src/main/java/es/verdnatura/presentation/base/BaseFragment.kt b/app/src/main/java/es/verdnatura/presentation/base/BaseFragment.kt index 680f0143..819ec77a 100644 --- a/app/src/main/java/es/verdnatura/presentation/base/BaseFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/base/BaseFragment.kt @@ -131,6 +131,7 @@ abstract class BaseFragment( R.drawable.ic_sort -> getString(R.string.sortRouteSalix) R.drawable.ic_sign_ticket -> getString(R.string.signed) R.drawable.ic_send -> getString(R.string.sendDriverRoute) + R.drawable.ic_add_multiple -> getString(R.string.addItemMultipleShelvings) else -> { "" } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt index 7735f069..77ad4f90 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt @@ -275,7 +275,7 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL PasillerosItemVO( R.drawable.photo_camera, R.string.titlePhotos, - R.string.titlePhotosDescrip + R.string.titlePhotosDescrip ), uriImage.toString() ) @@ -589,8 +589,8 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL getString(R.string.titleUserControlVehicle) -> { try { addFragmentOnTop(ControlVehiculoUsuarioFragment.newInstance(entryPoint.toInt())) - }catch (ex:Exception){ - e("Crashlytics",ex.message.toString()) + } catch (ex: Exception) { + e("Crashlytics", ex.message.toString()) } } @@ -665,9 +665,13 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL addFragmentOnTop(AutomaticAddItemFragment.newInstance(entryPoint, itemTitle)) } - /* getString(R.string.titleControllersAction) -> { - addFragmentOnTop(AutomaticAddItemFragment.newInstance(entryPoint, itemTitle)) - }*/ + getString(R.string.addItemMultipleShelving) -> { + addFragmentOnTop(AutomaticAddItemFragment.newInstance(entryPoint, itemTitle)) + } + + /* getString(R.string.titleControllersAction) -> { + addFragmentOnTop(AutomaticAddItemFragment.newInstance(entryPoint, itemTitle)) + }*/ getString(R.string.titlePickers) -> { //addFragmentOnTop(SacadorFragment.newInstance()) @@ -718,7 +722,12 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL } getString(R.string.titlePreControlTest) -> { - addFragmentOnTop(CollectionFragmentPreCheckerNew.newInstance(null, type = PRECHECKERNEW)) + addFragmentOnTop( + CollectionFragmentPreCheckerNew.newInstance( + null, + type = PRECHECKERNEW + ) + ) } getString(R.string.titleShelvingHistorical) -> { @@ -997,7 +1006,7 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL } override fun onCollectionSelected( - collection: CollectionTicket, type: String, hasPicking: Boolean, hasToAdd:Boolean + collection: CollectionTicket, type: String, hasPicking: Boolean, hasToAdd: Boolean ) { when (type) { "PREITEMPICKERTEST" -> { @@ -1153,8 +1162,9 @@ class MainActivity : BaseActivity(), OnPasillerosItemClickL versionApp = (application as MobileApplication).versionName, androidId = (application as MobileApplication).androidId, serialnumber = (application as MobileApplication).serialNumber ?: "", - userFk = (application as MobileApplication).userId!!) - }catch (ex:Exception){ + userFk = (application as MobileApplication).userId!! + ) + } catch (ex: Exception) { d(ex.message.toString()) } } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/AutomaticAddItemFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/AutomaticAddItemFragment.kt index c1f2cb1a..9c093853 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/AutomaticAddItemFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/AutomaticAddItemFragment.kt @@ -6,9 +6,14 @@ import androidx.recyclerview.widget.LinearLayoutManager import es.verdnatura.R import es.verdnatura.databinding.FragmentAutomaticAddItemBinding import es.verdnatura.domain.ConstAndValues.WAREHOUSEFK +import es.verdnatura.domain.isShelving import es.verdnatura.presentation.base.BaseFragment import es.verdnatura.presentation.common.OnAutomaticItemClickListener +import es.verdnatura.presentation.common.OnBarcodeRowClickListener import es.verdnatura.presentation.common.itemScanValue +import es.verdnatura.presentation.view.component.CustomDialogList +import es.verdnatura.presentation.view.feature.articulo.adapter.BarcodeAdapter +import es.verdnatura.presentation.view.feature.articulo.model.BarcodeVO import es.verdnatura.presentation.view.feature.ubicador.adapter.AutomaticAdapter import java.lang.Boolean.TRUE @@ -16,13 +21,16 @@ import java.lang.Boolean.TRUE class AutomaticAddItemFragment( private var shelvingFk: String = "", private var titleAction: String? = null -) : BaseFragment( - AutomaticAddItemViewModel::class +) : BaseFragment( + UbicadorViewModel::class ) { private var adapter: AutomaticAdapter? = null private var listItems: ArrayList = ArrayList() private var contador = 0 + private lateinit var customDialogList: CustomDialogList + private var listShelvings: ArrayList = ArrayList() + private var listShelvingsAdapter: BarcodeAdapter? = null companion object { fun newInstance(entryPoint: String, titleAction: String) = @@ -106,28 +114,36 @@ class AutomaticAddItemFragment( } binding.buttonFinalizar.setOnClickListener { - val listString: ArrayList = ArrayList() - val listInt: ArrayList = ArrayList() - listItems.forEach { - listString.add(it) - listInt.add(it) - } - - - if (binding.mainToolbar.toolbarTitle.text.equals(getString(R.string.titleChecker))) { - - viewModel.itemShelvingAddList( - shelvingFk, - "" + listInt + "", - TRUE, - mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK) + if (listItems.isEmpty()) { + ma.messageWithSound( + getString(R.string.scanItem), + isError = false, + isPlayed = false, + isToasted = true ) } else { - viewModel.itemShelvingMakeMulti( - shelvingFk, - listString, - mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK) - ) + when (titleAction) { + getString(R.string.titleChecker) -> { + viewModel.itemShelvingAddList( + shelvingFk, + listItems.joinToString(), + TRUE, + mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK) + ) + } + + getString(R.string.addItemMultipleShelving) -> { + inputMultipleShelvingsForUbicator() + } + + else -> { + viewModel.itemShelvingMakeMulti( + shelvingFk, + ArrayList(listItems), + mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK) + ) + } + } } } @@ -136,6 +152,88 @@ class AutomaticAddItemFragment( } } + private fun inputMultipleShelvingsForUbicator() { + if (listShelvings.isNotEmpty()) listShelvings.clear() + customDialogList = CustomDialogList(requireContext()) + customDialogList.setTitle( + getString(R.string.shelvingsLocate) + ) + customDialogList.setDescription( + getString(R.string.scanShelvingsLocate) + ).setOkButton(getString(R.string.locate)) { + + listShelvings.forEach { + viewModel.itemShelvingMakeMulti( + it.code!!, + ArrayList(listItems), + mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK) + ) + + } + customDialogList.dismiss() + + }.setKoButton(getString(R.string.cancel)) { + ma.hideKeyboard(customDialogList.getEditText()) + customDialogList.dismiss() + + }.setValue("").show() + + customDialogList.getEditText().requestFocus() + ma.hideKeyboard(customDialogList.getEditText()) + + customDialogList.getEditText().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { + if (customDialogList.getValue().isNotEmpty()) { + + try { + customDialogList.setValue( + itemScanValue( + customDialogList.getValue(), arrayOf("buy"), field = "id" + ).toString() + ) + if (customDialogList.getValue().isShelving()) { + if (listShelvings.firstOrNull { it.code == customDialogList.getValue() } == null) { + listShelvings.add(BarcodeVO(code = customDialogList.getValue())) + } else { + throw Exception(getString(R.string.errorRepeatedShelving)) + } + } else { + throw Exception() + } + + } catch (ex: Exception) { + ma.messageWithSound( + getString(R.string.errorInput), + isError = true, + isPlayed = true, + isToasted = true + ) + listShelvings.removeAt(0) + } + + listShelvingsAdapter!!.notifyItemChanged(0) + } + customDialogList.setValue("") + ma.hideKeyboard(customDialogList.getEditText()) + return@setOnEditorActionListener true + } + false + } + + listShelvingsAdapter = BarcodeAdapter( + listShelvings, object : OnBarcodeRowClickListener { + override fun onBarcodeRowClickListener(item: BarcodeVO) { + + } + }, showDelete = false + ) + customDialogList.getRecyclerView().adapter = listShelvingsAdapter + + customDialogList.getRecyclerView().layoutManager = + LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + + } + override fun observeViewModel() { with(viewModel) { response.observe(viewLifecycleOwner) { diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/AutomaticAddItemViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/AutomaticAddItemViewModel.kt deleted file mode 100644 index 7b93f37f..00000000 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/AutomaticAddItemViewModel.kt +++ /dev/null @@ -1,52 +0,0 @@ -package es.verdnatura.presentation.view.feature.ubicador.fragment - -import android.content.Context -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData -import es.verdnatura.domain.SalixCallback -import es.verdnatura.domain.formatWithQuotes -import es.verdnatura.presentation.base.BaseViewModel -import es.verdnatura.presentation.view.feature.workermistake.model.MakeMultiSalix -import retrofit2.Response - -class AutomaticAddItemViewModel(val context: Context) : BaseViewModel(context) { - - private val _response by lazy { MutableLiveData() } - val response: LiveData = _response - - fun itemShelvingMakeMulti( - shelvingFk: String, items: List, warehouseFk: Int - ) { - - salix.upsertItem(MakeMultiSalix(shelvingFk, items, warehouseFk)) - .enqueue(object : SalixCallback(context) { - override fun onError(t: Throwable) { - _response.value = false - } - - override fun onSuccess(response: Response) { - _response.value = true - - } - }) - - } - - fun itemShelvingAddList( - shelving: String, items: Any, isChecking: Boolean, warehouse: Int - ) { - salix.itemShelvingAddList( - arrayListOf(shelving, items, isChecking, warehouse).formatWithQuotes() - ).enqueue(object : SalixCallback(context) { - override fun onSuccess(response: Response) { - _response.value = true - } - - override fun onError(t: Throwable) { - _response.value = false - } - - }) - } - -} diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragmentNew.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragmentNew.kt index f4a6c1a8..8e8b85c8 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragmentNew.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragmentNew.kt @@ -127,7 +127,7 @@ class UbicadorFragmentNew : BaseFragment + ma.onPasillerosItemClickListener( + PasillerosItemVO( + title = R.string.addItemMultipleShelving, + ), entryPoint = getString(R.string.addItemMultipleShelving) + ) + iconReload.drawable -> { if (shelvingFk.isNotBlank()) { @@ -794,8 +807,6 @@ class UbicadorFragmentNew : BaseFragment(context) { override fun onSuccess(response: Response) { - _response.value = ResponseItemVO(isError = false, response = response.message()!!) + _responseUbicator.value = true super.onSuccess(response) } }) @@ -450,4 +451,25 @@ class UbicadorViewModel(val context: Context) : BaseViewModel(context) { }) } + fun itemShelvingMakeMulti( + shelvingFk: String, items: List, warehouseFk: Int + ) { + + salix.upsertItem(MakeMultiSalix(shelvingFk, items, warehouseFk)) + .enqueue(object : SalixCallback(context) { + override fun onError(t: Throwable) { + super.onError(t) + _response.value = + ResponseItemVO(isError = true, response = t.message.toString()) + } + + override fun onSuccess(response: Response) { + super.onSuccess(response) + _response.value = ResponseItemVO(isError = false, response = response.message()) + + } + }) + + } + } diff --git a/app/src/main/res/drawable/ic_add_multiple.xml b/app/src/main/res/drawable/ic_add_multiple.xml new file mode 100644 index 00000000..70c17fa6 --- /dev/null +++ b/app/src/main/res/drawable/ic_add_multiple.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index e8890b9d..fe2569ef 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -843,7 +843,7 @@ Renombrar Nuevo artículo Ubicar - Escanea carros para ubicar el artículo + Escanea carros para ubicar el artículo/s Carros a ubicar Carro ya introducido errorGetData @@ -862,6 +862,9 @@ Escanear cajas titlePrePickerTest PREITEMPICKERTEST + Revisa el SECTOR + Añade artículo en varios carros + Añade artículos en varios carros diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 5e23ad68..36299eef 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -844,7 +844,7 @@ Nuevo artículo Carro ya introducido Ubicar - Escanea carros para ubicar el artículo + Escanea carros para ubicar el artículo/s Carros a ubicar Fallo al intentar obtener datos. Avise a Informática No tienes sector seleccionado. Ve a pantalla ajustes y selecciona uno @@ -862,5 +862,8 @@ Escanear cajas titlePrePickerTest PREITEMPICKERTEST + Revisa el SECTOR + Añade artículo en varios carros + Añade artículos en varios carros diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 61043423..c2002b7a 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -844,7 +844,7 @@ Nuevo artículo Carro ya introducido Ubicar - Escanea carros para ubicar el artículo + Escanea carros para ubicar el artículo/s Carros a ubicar Fallo al intentar obtener datos. Avise a Informática No tienes sector seleccionado. Ve a pantalla ajustes y selecciona uno @@ -862,6 +862,9 @@ Escanear cajas titlePrePickerTest PREITEMPICKERTEST + Revisa el SECTOR + Añade artículo en varios carros + Añade artículos en varios carros diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0d72edf5..b3287645 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -846,7 +846,7 @@ Nuevo artículo Carro ya introducido Ubicar - Escanea carros para ubicar el artículo + Escanea carros para ubicar el artículo/s Carros a ubicar Fallo al intentar obtener datos. Avise a Informática No tienes sector seleccionado. Ve a pantalla ajustes y selecciona uno @@ -865,5 +865,8 @@ titlePrePickerTest PREITEMPICKERTEST %1$s %2$s + Revisa el SECTOR + Añade artículo en varios carros + Añade artículos en varios carros