From 2d48f6687c19821eb51dac1b08658d202c15cf8b Mon Sep 17 00:00:00 2001 From: GiuseppeS Date: Mon, 24 Feb 2025 12:05:39 +0100 Subject: [PATCH] =?UTF-8?q?Aggiunta=20logica=20di=20fast=20picking=20in=20?= =?UTF-8?q?spedizione,=20scansionando=20un=20barcode=20di=20una=20UL=20all?= =?UTF-8?q?'interno=20di=20DialogInputQuantity=20verr=C3=A0=20automaticame?= =?UTF-8?q?nte=20chiusa=20l'ul=20attuale=20e=20riavviato=20il=20processo?= =?UTF-8?q?=20di=20scansione=20del=20barcode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 6 +- .../MainApplicationModule.java | 37 +- .../barcode_reader/BarcodeCallbackDTO.java | 10 + .../core/barcode_reader/BarcodeManager.java | 51 +- .../integrywmsnative/core/di/Converters.java | 72 +- .../core/expansion/BaseActivity.java | 7 +- .../core/expansion/BaseDialog.java | 2 +- .../core/expansion/BaseDialogFragment.java | 11 +- .../core/expansion/BaseFragment.java | 5 +- .../view/ExtendedSectionedRecyclerView.java | 18 +- .../integrywmsnative/core/model/MtbAart.java | 99 ++ .../integrywmsnative/core/model/MtbColr.java | 52 + .../integrywmsnative/core/model/MtbColt.java | 20 +- .../core/model/MtbPartitaMag.java | 64 +- .../core/model/MtbUntMis.java | 12 + .../core/rest/HttpInterceptor.java | 2 +- .../rest/consumers/ArticoloRESTConsumer.java | 88 +- .../rest/consumers/BarcodeRESTConsumer.java | 4 + .../ColliLavorazioneRESTConsumer.java | 149 +- .../consumers/ColliMagazzinoRESTConsumer.java | 302 ++-- .../ColliSpedizioneRESTConsumer.java | 174 +- .../rest/consumers/EntityRESTConsumer.java | 74 +- .../MagazzinoAutomaticoRESTConsumer.java | 33 +- .../rest/consumers/OrdiniRESTConsumer.java | 42 +- .../rest/consumers/PosizioniRESTConsumer.java | 24 +- .../rest/consumers/SystemRESTConsumer.java | 53 +- .../ColliScaricoRESTConsumerInterface.java | 10 + .../MutableLiveDataDeserializer.java | 21 + .../serializer/MutableLiveDataSerializer.java | 16 + .../core/utility/UtilityDialog.java | 1 + .../core/utility/UtilityGson.java | 6 + .../AccettazioneBollaPickingActivity.java | 21 +- .../AccettazioneBollaPickingViewModel.java | 14 +- .../AccettazioneOrdiniPickingActivity.java | 29 +- .../edit_form/DocInterniEditFormActivity.java | 16 +- .../inventario/ElencoInventariFragment.java | 2 +- .../picking/PickingInventarioActivity.java | 18 +- .../picking_libero/PickingLiberoFragment.java | 25 +- .../picking_resi/PickingResiActivity.java | 19 +- .../ProdDettaglioLineaActivity.java | 34 +- .../ProdDettaglioLineaViewModel.java | 5 +- .../dialogs/DialogRecoverUl.java | 8 +- .../dialogs/DialogStartProduction.java | 8 +- .../ProdLineeProduzioneFragment.java | 12 +- .../ProdLineeProduzioneViewModel.java | 4 +- .../ProdRecuperoMaterialeFragment.java | 17 +- .../ProdRientroMerceFragment.java | 4 +- .../ProdRientroMerceOrderListFragment.java | 2 +- .../ProdRiposizionamentoDaProdFragment.java | 10 +- .../ProdVersamentoMaterialeFragment.java | 15 +- .../PVOrdineAcquistoEditActivity.java | 18 +- .../PVOrdineAcquistoEditViewModel.java | 4 +- .../edit_articolo/DialogEditArticoloView.java | 8 +- .../PVOrdiniAcquistoGrigliaFragment.java | 2 +- .../DialogScanGrigliaAcquistoView.java | 14 +- .../RettificaGiacenzeFragment.java | 14 +- .../gest/spedizione/SpedizioneActivity.java | 329 ++-- .../gest/spedizione/SpedizioneModule.java | 8 +- .../gest/spedizione/SpedizioneViewModel.java | 1405 +++++++++-------- .../spedizione/model/PickedQuantityDTO.java | 23 + .../UltimeConsegneClienteFragment.java | 10 +- .../UltimiArriviFornitoreFragment.java | 12 +- .../VersamentoMerceFragment.java | 15 +- ...ttomSheetFragmentLUContentListAdapter.java | 6 +- .../BottomSheetFragmentLUContentView.java | 34 +- .../DialogAskCliente_Page1ViewModel.java | 6 +- .../ask_commessa/DialogAskCommessaView.java | 10 +- .../DialogAskLineaProdView.java | 12 +- .../DialogAskPositionOfLUView.java | 18 +- .../DialogAskUnknownBarcodeNotesView.java | 12 +- ...alogBindProductBarcodeWithPackageView.java | 12 +- .../DialogChooseArtsFromMtbColrList.java | 8 +- .../DialogCreateNewArtView.java | 6 +- ...ialogInputQuantityV2ResponseViewModel.java | 25 + .../DialogInputQuantityV2ResultDTO.java | 35 + .../DialogInputQuantityV2View.java | 66 +- .../DialogInputQuantityV2ViewModel.java | 327 ++-- .../dialogs/scan_art/DialogScanArtView.java | 12 +- .../DialogScanOrCreateLUView.java | 10 +- ...t_main_ordini_uscita__list_group_model.xml | 8 +- 80 files changed, 2538 insertions(+), 1659 deletions(-) create mode 100644 app/src/main/java/it/integry/integrywmsnative/core/rest/deserializer/MutableLiveDataDeserializer.java create mode 100644 app/src/main/java/it/integry/integrywmsnative/core/rest/serializer/MutableLiveDataSerializer.java create mode 100644 app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_quantity_v2/DialogInputQuantityV2ResponseViewModel.java diff --git a/app/build.gradle b/app/build.gradle index 5289fbff..0c903c52 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -110,7 +110,7 @@ dependencies { //Firebase // Import the Firebase BoM - implementation platform('com.google.firebase:firebase-bom:33.8.0') + implementation platform('com.google.firebase:firebase-bom:33.9.0') implementation 'com.google.firebase:firebase-analytics' implementation 'com.google.firebase:firebase-crashlytics' implementation 'com.google.firebase:firebase-perf' @@ -121,6 +121,7 @@ dependencies { runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' + implementation 'com.google.guava:guava:33.4.0-android' implementation 'androidx.appcompat:appcompat:1.7.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' @@ -139,8 +140,7 @@ dependencies { implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-gson:2.9.0' implementation 'com.annimon:stream:1.2.2' - implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.7' -// implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' + implementation 'androidx.lifecycle:lifecycle-runtime:2.8.7' implementation 'org.apache.commons:commons-text:1.9' //MVVM diff --git a/app/src/main/java/it/integry/integrywmsnative/MainApplicationModule.java b/app/src/main/java/it/integry/integrywmsnative/MainApplicationModule.java index 52eb0626..60b404d9 100644 --- a/app/src/main/java/it/integry/integrywmsnative/MainApplicationModule.java +++ b/app/src/main/java/it/integry/integrywmsnative/MainApplicationModule.java @@ -150,8 +150,8 @@ public class MainApplicationModule { @Provides @Singleton - OrdiniRESTConsumer provideOrdiniRESTConsumer(RESTBuilder restBuilder, SystemRESTConsumer systemRESTConsumer, EntityRESTConsumer entityRESTConsumer) { - return new OrdiniRESTConsumer(restBuilder, systemRESTConsumer, entityRESTConsumer); + OrdiniRESTConsumer provideOrdiniRESTConsumer(RESTBuilder restBuilder, ExecutorService executorService, SystemRESTConsumer systemRESTConsumer, EntityRESTConsumer entityRESTConsumer) { + return new OrdiniRESTConsumer(restBuilder, executorService, systemRESTConsumer, entityRESTConsumer); } @Provides @@ -162,8 +162,8 @@ public class MainApplicationModule { @Provides @Singleton - ArticoloRESTConsumer provideArticoloRESTConsumer(RESTBuilder restBuilder, SystemRESTConsumer systemRESTConsumer) { - return new ArticoloRESTConsumer(restBuilder, systemRESTConsumer); + ArticoloRESTConsumer provideArticoloRESTConsumer(RESTBuilder restBuilder, ExecutorService executorService, SystemRESTConsumer systemRESTConsumer) { + return new ArticoloRESTConsumer(restBuilder, executorService, systemRESTConsumer); } @Provides @@ -198,18 +198,19 @@ public class MainApplicationModule { @Provides @Singleton - EntityRESTConsumer provideEntityRESTConsumer(RESTBuilder restBuilder) { - return new EntityRESTConsumer(restBuilder); + EntityRESTConsumer provideEntityRESTConsumer(RESTBuilder restBuilder, ExecutorService executorService) { + return new EntityRESTConsumer(restBuilder, executorService); } @Provides @Singleton - ColliMagazzinoRESTConsumer provideColliMagazzinoRESTConsumer(RESTBuilder restBuilder, + ColliMagazzinoRESTConsumer provideColliMagazzinoRESTConsumer(ExecutorService executorService, + RESTBuilder restBuilder, SystemRESTConsumer systemRESTConsumer, ArticoloRESTConsumer articoloRESTConsumer, EntityRESTConsumer entityRESTConsumer, SettingsManager settingsManager) { - return new ColliMagazzinoRESTConsumer(restBuilder, systemRESTConsumer, articoloRESTConsumer, entityRESTConsumer, settingsManager); + return new ColliMagazzinoRESTConsumer(executorService, restBuilder, systemRESTConsumer, articoloRESTConsumer, entityRESTConsumer, settingsManager); } @Provides @@ -238,8 +239,8 @@ public class MainApplicationModule { @Provides @Singleton - SystemRESTConsumer provideSystemRESTConsumer(RESTBuilder restBuilder) { - return new SystemRESTConsumer(restBuilder); + SystemRESTConsumer provideSystemRESTConsumer(RESTBuilder restBuilder, ExecutorService executorService) { + return new SystemRESTConsumer(restBuilder, executorService); } @Provides @@ -250,8 +251,8 @@ public class MainApplicationModule { @Provides @Singleton - PosizioniRESTConsumer providesPosizioniRESTConsumer(RESTBuilder restBuilder, SystemRESTConsumer systemRESTConsumer) { - return new PosizioniRESTConsumer(restBuilder, systemRESTConsumer); + PosizioniRESTConsumer providesPosizioniRESTConsumer(RESTBuilder restBuilder, SystemRESTConsumer systemRESTConsumer, ExecutorService executorService) { + return new PosizioniRESTConsumer(restBuilder, systemRESTConsumer, executorService); } @Provides @@ -310,20 +311,20 @@ public class MainApplicationModule { @Provides @Singleton - ColliSpedizioneRESTConsumer provideColliSpedizioneRESTConsumer(RESTBuilder restBuilder) { - return new ColliSpedizioneRESTConsumer(restBuilder); + ColliSpedizioneRESTConsumer provideColliSpedizioneRESTConsumer(RESTBuilder restBuilder, ExecutorService executorService) { + return new ColliSpedizioneRESTConsumer(restBuilder, executorService); } @Provides @Singleton - ColliLavorazioneRESTConsumer provideColliLavorazioneRESTConsumer(RESTBuilder restBuilder, SettingsManager settingsManager) { - return new ColliLavorazioneRESTConsumer(restBuilder, settingsManager); + ColliLavorazioneRESTConsumer provideColliLavorazioneRESTConsumer(RESTBuilder restBuilder, ExecutorService executorService, SettingsManager settingsManager) { + return new ColliLavorazioneRESTConsumer(restBuilder, executorService, settingsManager); } @Provides @Singleton - MagazzinoAutomaticoRESTConsumer provideMagazzinoAutomaticoRESTConsumer(RESTBuilder restBuilder) { - return new MagazzinoAutomaticoRESTConsumer(restBuilder); + MagazzinoAutomaticoRESTConsumer provideMagazzinoAutomaticoRESTConsumer(ExecutorService executorService, RESTBuilder restBuilder) { + return new MagazzinoAutomaticoRESTConsumer(executorService, restBuilder); } @Provides diff --git a/app/src/main/java/it/integry/integrywmsnative/core/barcode_reader/BarcodeCallbackDTO.java b/app/src/main/java/it/integry/integrywmsnative/core/barcode_reader/BarcodeCallbackDTO.java index aa0a61d1..d154a9f6 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/barcode_reader/BarcodeCallbackDTO.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/barcode_reader/BarcodeCallbackDTO.java @@ -7,6 +7,7 @@ public class BarcodeCallbackDTO { private int ID = -1; + private boolean enabled = true; private RunnableArgs onScanSuccessfull; private RunnableArgs onScanFailed; @@ -19,6 +20,15 @@ public class BarcodeCallbackDTO { return this; } + public boolean isEnabled() { + return enabled; + } + + public BarcodeCallbackDTO setEnabled(boolean enabled) { + this.enabled = enabled; + return this; + } + public RunnableArgs getOnScanSuccessfull() { return onScanSuccessfull; } diff --git a/app/src/main/java/it/integry/integrywmsnative/core/barcode_reader/BarcodeManager.java b/app/src/main/java/it/integry/integrywmsnative/core/barcode_reader/BarcodeManager.java index 6a426201..ab002713 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/barcode_reader/BarcodeManager.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/barcode_reader/BarcodeManager.java @@ -24,10 +24,15 @@ public class BarcodeManager { private static BarcodeReaderInterface mCurrentBarcodeInterface; private static final List mBarcodeCallbacksStacktrace = new ArrayList<>(); - private static boolean mEnabled = true; +// private static boolean mEnabled = true; - private static final Class[] registeredBarcodeReaderInterfaces = new Class[]{PointMobileBarcodeReader.class, ZebraBarcodeReader.class, HoneyWellBarcodeReader.class, KeyboardEmulatorBarcodeReader.class}; + private static final Class[] registeredBarcodeReaderInterfaces = new Class[]{ + PointMobileBarcodeReader.class, + ZebraBarcodeReader.class, + HoneyWellBarcodeReader.class, + KeyboardEmulatorBarcodeReader.class + }; public static void init(Context applicationContext) throws Exception { @@ -56,12 +61,12 @@ public class BarcodeManager { mCurrentBarcodeInterface.register(data -> { BarcodeCallbackDTO callback = getValidCallback(); - if (callback != null && mEnabled) { + if (callback != null && callback.isEnabled()) { callback.getOnScanSuccessfull().run(data); } }, ex -> { BarcodeCallbackDTO callback = getValidCallback(); - if (callback != null && mEnabled) { + if (callback != null && callback.isEnabled()) { callback.getOnScanFailed().run(ex); } }); @@ -103,7 +108,6 @@ public class BarcodeManager { } public static int addCallback(BarcodeCallbackDTO barcodeCallbackDTO) { - int newID = -1; if (!mBarcodeCallbacksStacktrace.isEmpty()) { @@ -133,18 +137,39 @@ public class BarcodeManager { } - public static void disable() { - mEnabled = false; -// UtilityLogger.info("Barcode reader disabled"); + public static void disable(int instanceId) { + mBarcodeCallbacksStacktrace.stream().filter(x -> x.getID() == instanceId) + .findFirst().ifPresent(x -> x.setEnabled(false)); } - public static void enable() { - mEnabled = true; -// UtilityLogger.info("Barcode reader enabled"); + public static void disableLastCallback() { + BarcodeCallbackDTO validCallback = getValidCallback(); + if (validCallback != null) { + validCallback.setEnabled(false); + } } - public static boolean isEnabled() { - return mEnabled; + public static void enable(int instanceId) { + mBarcodeCallbacksStacktrace.stream().filter(x -> x.getID() == instanceId) + .findFirst().ifPresent(x -> x.setEnabled(true)); + } + + public static void enableLastCallback() { + BarcodeCallbackDTO validCallback = getValidCallback(); + if (validCallback != null) { + validCallback.setEnabled(true); + } + } + + public static boolean isEnabled(int instanceId) { + return mBarcodeCallbacksStacktrace.stream().filter(x -> x.getID() == instanceId) + .findFirst() + .map(BarcodeCallbackDTO::isEnabled) + .orElse(false); + } + + public static boolean isLastCallbackEnabled() { + return getValidCallback() != null && getValidCallback().isEnabled(); } public static void changeSettings(List> settings) { diff --git a/app/src/main/java/it/integry/integrywmsnative/core/di/Converters.java b/app/src/main/java/it/integry/integrywmsnative/core/di/Converters.java index 23dcca26..6b7ece87 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/di/Converters.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/di/Converters.java @@ -24,6 +24,10 @@ import androidx.databinding.BindingAdapter; import androidx.databinding.BindingConversion; import androidx.databinding.Observable; import androidx.databinding.ObservableField; +import androidx.lifecycle.LifecycleOwner; +import androidx.lifecycle.LiveData; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewTreeLifecycleOwner; import com.google.android.material.datepicker.MaterialDatePicker; import com.google.android.material.textfield.TextInputEditText; @@ -820,11 +824,11 @@ public class Converters { @BindingAdapter("visibilityWhenNotNull") - public static void bindViewVisibilityWhenNotNull(View view, ObservableField bindableObject) { + public static void bindViewVisibilityObservableFieldWhenNotNull(View view, ObservableField bindableObject) { if(bindableObject == null) return; - if (view.getTag(R.id.bound_observable) != bindableObject) { - view.setTag(R.id.bound_observable, bindableObject); + if (view.getTag(R.id.bound_observable_visibility) != bindableObject) { + view.setTag(R.id.bound_observable_visibility, bindableObject); } bindableObject.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() { @@ -838,6 +842,36 @@ public class Converters { } + @BindingAdapter("visibilityWhenNotNull") + public static void bindViewVisibilityLiveDataWhenNotNull(View view, LiveData liveData) { + // Se il LiveData è null, nascondi la view e esci + if (liveData == null) { + view.setVisibility(View.GONE); + return; + } + + // Ottieni il LifecycleOwner dalla view + LifecycleOwner lifecycleOwner = ViewTreeLifecycleOwner.get(view); + if (lifecycleOwner == null) return; + + // Rimuovi eventuali observer precedenti + Observer oldObserver = (Observer) view.getTag(R.id.bound_observable_visibility); + if (oldObserver != null) { + liveData.removeObserver(oldObserver); + } + + // Crea e registra il nuovo observer + Observer newObserver = value -> + view.setVisibility(value == null ? View.GONE : View.VISIBLE); + + liveData.observe(lifecycleOwner, newObserver); + view.setTag(R.id.bound_observable_visibility, newObserver); + + // Imposta lo stato iniziale + view.setVisibility(liveData.getValue() == null ? View.GONE : View.VISIBLE); + } + + @BindingAdapter("visibilityWhenNotNull") public static void bindViewVisibilityWhenNotNull(View view, Object genericObject) { view.setVisibility(genericObject == null ? View.GONE : View.VISIBLE); @@ -845,7 +879,7 @@ public class Converters { @BindingAdapter("visibilityWhenNull") - public static void bindViewVisibilityWhenNull(View view, ObservableField bindableObject) { + public static void bindViewVisibilityObservableFieldWhenNull(View view, ObservableField bindableObject) { if (view.getTag(R.id.bound_observable_visibility) != bindableObject) { view.setTag(R.id.bound_observable_visibility, bindableObject); @@ -864,6 +898,36 @@ public class Converters { } + @BindingAdapter("visibilityWhenNull") + public static void bindViewVisibilityLiveDataWhenNull(View view, LiveData liveData) { + // Se il LiveData è null, nascondi la view e esci + if (liveData == null) { + view.setVisibility(View.VISIBLE); + return; + } + + // Ottieni il LifecycleOwner dalla view + LifecycleOwner lifecycleOwner = ViewTreeLifecycleOwner.get(view); + if (lifecycleOwner == null) return; + + // Rimuovi eventuali observer precedenti + Observer oldObserver = (Observer) view.getTag(R.id.bound_observable_visibility); + if (oldObserver != null) { + liveData.removeObserver(oldObserver); + } + + // Crea e registra il nuovo observer + Observer newObserver = value -> + view.setVisibility(value == null ? View.VISIBLE : View.GONE); + + liveData.observe(lifecycleOwner, newObserver); + view.setTag(R.id.bound_observable_visibility, newObserver); + + // Imposta lo stato iniziale + view.setVisibility(liveData.getValue() == null ? View.VISIBLE : View.GONE); + } + + @BindingAdapter({"reverse_visibility"}) public static void bindViewReverseVisibility(View view, final BindableBoolean bindableBoolean) { if (view.getTag(R.id.bound_reverse_visibility) != bindableBoolean) { diff --git a/app/src/main/java/it/integry/integrywmsnative/core/expansion/BaseActivity.java b/app/src/main/java/it/integry/integrywmsnative/core/expansion/BaseActivity.java index 7dd9641e..f7a358ef 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/expansion/BaseActivity.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/expansion/BaseActivity.java @@ -34,7 +34,6 @@ public class BaseActivity extends AppCompatActivity { } public void onLoadingStarted() { - BarcodeManager.disable(); this.openProgress(); } @@ -52,14 +51,14 @@ public class BaseActivity extends AppCompatActivity { private void openProgress() { - BarcodeManager.disable(); + BarcodeManager.disableLastCallback(); // executorService.execute(() -> { this.mCurrentProgress.show(getSupportFragmentManager()); // }); } private void closeProgress() { - BarcodeManager.enable(); + BarcodeManager.enableLastCallback(); // executorService.execute(() -> { mCurrentProgress.dismiss(); // }); @@ -67,7 +66,7 @@ public class BaseActivity extends AppCompatActivity { @Override public boolean dispatchKeyEvent(KeyEvent event) { - if (BarcodeManager.isEnabled() && BarcodeManager.isKeyboardEmulator()) { + if (BarcodeManager.isLastCallbackEnabled() && BarcodeManager.isKeyboardEmulator()) { if (event.getAction() == KeyEvent.ACTION_DOWN || event.getAction() == KeyEvent.ACTION_MULTIPLE && !isControlKey(event)) { return BarcodeManager.onKeyDown(event.getKeyCode(), event); } diff --git a/app/src/main/java/it/integry/integrywmsnative/core/expansion/BaseDialog.java b/app/src/main/java/it/integry/integrywmsnative/core/expansion/BaseDialog.java index f1473f04..2ffdc550 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/expansion/BaseDialog.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/expansion/BaseDialog.java @@ -14,7 +14,7 @@ public class BaseDialog extends Dialog { public BaseDialog(@NonNull Context context) { super(context); - if (BarcodeManager.isEnabled() && BarcodeManager.isKeyboardEmulator()) { + if (BarcodeManager.isLastCallbackEnabled() && BarcodeManager.isKeyboardEmulator()) { setOnKeyListener((dialog, keyCode, event) -> { if (mBarcodeListener && (event.getAction() == KeyEvent.ACTION_DOWN || event.getAction() == KeyEvent.ACTION_MULTIPLE) && !isControlKey(event)) { return BarcodeManager.onKeyDown(event.getKeyCode(), event); diff --git a/app/src/main/java/it/integry/integrywmsnative/core/expansion/BaseDialogFragment.java b/app/src/main/java/it/integry/integrywmsnative/core/expansion/BaseDialogFragment.java index 42b9c1c0..eef851fd 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/expansion/BaseDialogFragment.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/expansion/BaseDialogFragment.java @@ -65,25 +65,23 @@ public abstract class BaseDialogFragment extends DialogFragment implements Dialo } public void onLoadingStarted() { - BarcodeManager.disable(); this.openProgress(); } public void onLoadingEnded() { this.closeProgress(); - BarcodeManager.enable(); } private void openProgress() { - BarcodeManager.disable(); + BarcodeManager.disableLastCallback(); // executorService.execute(() -> { this.mCurrentProgress.show(requireActivity().getSupportFragmentManager()); // }); } private void closeProgress() { - BarcodeManager.enable(); + BarcodeManager.enableLastCallback(); // executorService.execute(() -> { mCurrentProgress.dismiss(); // }); @@ -91,9 +89,8 @@ public abstract class BaseDialogFragment extends DialogFragment implements Dialo public void onError(Exception ex) { - this.onLoadingEnded(); - requireActivity().runOnUiThread(() -> { + this.onLoadingEnded(); UtilityExceptions.defaultException(requireActivity(), ex); }); } @@ -130,7 +127,7 @@ public abstract class BaseDialogFragment extends DialogFragment implements Dialo .create() .inject(this); - if (BarcodeManager.isEnabled() && BarcodeManager.isKeyboardEmulator() && getDialog() != null) { + if (BarcodeManager.isLastCallbackEnabled() && BarcodeManager.isKeyboardEmulator() && getDialog() != null) { getDialog().setOnKeyListener((dialog, keyCode, event) -> { if (mBarcodeListener && (event.getAction() == KeyEvent.ACTION_DOWN || event.getAction() == KeyEvent.ACTION_MULTIPLE) && !isControlKey(event)) { return BarcodeManager.onKeyDown(event.getKeyCode(), event); diff --git a/app/src/main/java/it/integry/integrywmsnative/core/expansion/BaseFragment.java b/app/src/main/java/it/integry/integrywmsnative/core/expansion/BaseFragment.java index b3b79372..4f7c671d 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/expansion/BaseFragment.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/expansion/BaseFragment.java @@ -65,14 +65,14 @@ public abstract class BaseFragment extends Fragment { } private void openProgress() { - BarcodeManager.disable(); + BarcodeManager.disableLastCallback(); // executorService.execute(() -> { this.mCurrentProgress.show(requireActivity().getSupportFragmentManager()); // }); } private void closeProgress() { - BarcodeManager.enable(); + BarcodeManager.enableLastCallback(); // executorService.execute(() -> { mCurrentProgress.dismiss(); // }); @@ -82,7 +82,6 @@ public abstract class BaseFragment extends Fragment { requireActivity().runOnUiThread(() -> { this.closeProgress(); UtilityExceptions.defaultException(getActivity(), ex); - BarcodeManager.enable(); }); } diff --git a/app/src/main/java/it/integry/integrywmsnative/core/expansion/view/ExtendedSectionedRecyclerView.java b/app/src/main/java/it/integry/integrywmsnative/core/expansion/view/ExtendedSectionedRecyclerView.java index e07b7bff..da2c4b51 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/expansion/view/ExtendedSectionedRecyclerView.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/expansion/view/ExtendedSectionedRecyclerView.java @@ -6,28 +6,19 @@ import androidx.databinding.ObservableArrayList; import androidx.databinding.ObservableList; import androidx.recyclerview.widget.RecyclerView; -import com.zhukic.sectionedrecyclerview.SectionedRecyclerViewAdapter; - -import java.util.ArrayList; - import it.integry.integrywmsnative.core.expansion.OnListGeneralChangedCallback; public abstract class ExtendedSectionedRecyclerView extends SectionedRecyclerViewAdapter { - protected ArrayList mDataset = new ArrayList<>(); private View mEmptyView; public ExtendedSectionedRecyclerView(ObservableArrayList myDataset) { - mDataset.addAll(myDataset); + super(); myDataset.addOnListChangedCallback(new OnListGeneralChangedCallback() { @Override public void onChanged(ObservableList sender) { - mDataset.clear(); - mDataset.addAll(sender); - notifyDataChanged(); - notifyDataSetChanged(); checkIfEmpty(); } }); @@ -41,14 +32,11 @@ public abstract class ExtendedSectionedRecyclerView(); + for (MtbUntMis untMis : other.mtbUntMis) { + this.mtbUntMis.add(new MtbUntMis(untMis)); // Assicurati che MtbUntMis abbia un costruttore di copia + } + } + } + + + + public boolean isFlagTracciabilitaBoolean() { return flagTracciabilita != null && flagTracciabilita.equalsIgnoreCase("S"); } diff --git a/app/src/main/java/it/integry/integrywmsnative/core/model/MtbColr.java b/app/src/main/java/it/integry/integrywmsnative/core/model/MtbColr.java index 69667c4d..dec4ae35 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/model/MtbColr.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/model/MtbColr.java @@ -67,6 +67,58 @@ public class MtbColr extends EntityBase { } } + public MtbColr(MtbColr other) { + this(); + + this.gestione = other.gestione; + this.serCollo = other.serCollo; + this.numCollo = other.numCollo; + this.dataCollo = other.dataCollo; + this.riga = other.riga; + this.rigaOrd = other.rigaOrd; + this.codMart = other.codMart; + this.codBarre = other.codBarre; + this.codCol = other.codCol; + this.codTagl = other.codTagl; + this.partitaMag = other.partitaMag; + this.gestioneRif = other.gestioneRif; + this.serColloRif = other.serColloRif; + this.note = other.note; + this.dataOrd = other.dataOrd; // LocalDate è immutabile + this.dataColloRif = other.dataColloRif; + this.qtaCnf = other.qtaCnf; // BigDecimal è immutabile + this.qtaCol = other.qtaCol; + this.numOrd = other.numOrd; + this.numEtich = other.numEtich; + this.numColloRif = other.numColloRif; + this.datetimeRow = other.datetimeRow; + this.codJcom = other.codJcom; + this.numCnf = other.numCnf; + this.insPartitaMag = other.insPartitaMag; + this.mtbPartitaMag_descrizione = other.mtbPartitaMag_descrizione; + this.dataScadPartita = other.dataScadPartita; + this.descrizione = other.descrizione; + this.untMis = other.untMis; + this.causale = other.causale; + this.utente = other.utente; + this.codAnagDoc = other.codAnagDoc; + this.codDtipDoc = other.codDtipDoc; + this.dataDoc = other.dataDoc; + this.serDoc = other.serDoc; + this.numDoc = other.numDoc; + this.idRigaDoc = other.idRigaDoc; + this.pesoNettoKg = other.pesoNettoKg; + this.pesoLordoKg = other.pesoLordoKg; + + // Deep copy degli oggetti complessi + this.mtbAart = other.mtbAart != null ? new MtbAart(other.mtbAart) : null; + this.mtbPartitaMag = other.mtbPartitaMag != null ? new MtbPartitaMag(other.mtbPartitaMag) : null; + + // Non copiamo i campi transient + // this.id = other.id; + // this.refMtbColr = other.refMtbColr; + } + public static class Causale { public static final int DEFAULT = 0; diff --git a/app/src/main/java/it/integry/integrywmsnative/core/model/MtbColt.java b/app/src/main/java/it/integry/integrywmsnative/core/model/MtbColt.java index 8fe74188..3c482f8d 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/model/MtbColt.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/model/MtbColt.java @@ -3,7 +3,7 @@ package it.integry.integrywmsnative.core.model; import android.text.TextUtils; import androidx.databinding.ObservableArrayList; -import androidx.databinding.ObservableField; +import androidx.lifecycle.MutableLiveData; import com.annimon.stream.Optional; import com.annimon.stream.Stream; @@ -66,7 +66,7 @@ public class MtbColt extends EntityBase { private BigDecimal altezzaCm; private String codJcom; - private final ObservableField mtbTCol = new ObservableField<>(); + private final transient MutableLiveData mtbTCol = new MutableLiveData<>(); private Boolean disablePrint; private String ragSocCliente; @@ -261,7 +261,7 @@ public class MtbColt extends EntityBase { public MtbColt setCodTcol(String codTcol) { this.codTcol = codTcol; - if(!UtilityString.isNullOrEmpty(codTcol)) { + if (!UtilityString.isNullOrEmpty(codTcol)) { var fountMtbTcolObservable = SettingsManager.iDB().getInternalImballi().stream() .filter(x -> x.getCodTcol().equalsIgnoreCase(codTcol)) .findFirst() @@ -545,15 +545,15 @@ public class MtbColt extends EntityBase { } public ObservableMtbTcol getMtbTCol() { - return mtbTCol.get(); + return mtbTCol.getValue(); } public MtbColt setMtbTCol(ObservableMtbTcol mtbTCol) { - this.mtbTCol.set(mtbTCol); + this.mtbTCol.postValue(mtbTCol); return this; } - public ObservableField mtbTcolProperty() { + public MutableLiveData mtbTcolProperty() { return mtbTCol; } @@ -632,7 +632,13 @@ public class MtbColt extends EntityBase { @Override public EntityBase clone() { MtbColt mtbColt = (MtbColt) super.clone(); - mtbColt.setMtbColr((ObservableArrayList) mtbColt.getMtbColr().clone()); + mtbColt.setMtbColr(new ObservableArrayList<>()); + + this.getMtbColr().stream() + .map(MtbColr::new) //Genera un clone + .forEach(mtbColr -> { + mtbColt.getMtbColr().add(mtbColr); + }); return mtbColt; } } diff --git a/app/src/main/java/it/integry/integrywmsnative/core/model/MtbPartitaMag.java b/app/src/main/java/it/integry/integrywmsnative/core/model/MtbPartitaMag.java index 909930c0..5fd2429d 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/model/MtbPartitaMag.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/model/MtbPartitaMag.java @@ -4,34 +4,60 @@ import java.math.BigDecimal; import java.time.LocalDate; import java.time.LocalDateTime; -public class MtbPartitaMag extends EntityBase{ - private String codMart; - - private String partitaMag; - private String descrizione; +public class MtbPartitaMag extends EntityBase { + private String codMart; + + private String partitaMag; + private String descrizione; private LocalDateTime dataIns; private LocalDate dataScad; - private Integer scelta; + private Integer scelta; private BigDecimal costoUntUmMag; - private BigDecimal valUntUmMag; - private BigDecimal taraCnfKg; - private BigDecimal qtaCnf; - private String flagImballoArendere; - private String flagStato; - private String codDiviCont; - private BigDecimal cambioDiviCont; - private String barcode; - private String note; - private BigDecimal rapConv2; - private BigDecimal rapConv3; - private String posizione; + private BigDecimal valUntUmMag; + private BigDecimal taraCnfKg; + private BigDecimal qtaCnf; + private String flagImballoArendere; + private String flagStato; + private String codDiviCont; + private BigDecimal cambioDiviCont; + private String barcode; + private String note; + private BigDecimal rapConv2; + private BigDecimal rapConv3; + private String posizione; private String dataAggPrz; - private String partitaMagSec; + private String partitaMagSec; private BigDecimal qtaAttesa; public MtbPartitaMag() { this.type = "mtb_partita_mag"; } + public MtbPartitaMag(MtbPartitaMag other) { + this(); + + this.codMart = other.codMart; + this.partitaMag = other.partitaMag; + this.descrizione = other.descrizione; + this.dataIns = other.dataIns; // LocalDateTime è immutabile + this.dataScad = other.dataScad; // LocalDate è immutabile + this.scelta = other.scelta; + this.costoUntUmMag = other.costoUntUmMag; // BigDecimal è immutabile + this.valUntUmMag = other.valUntUmMag; + this.taraCnfKg = other.taraCnfKg; + this.qtaCnf = other.qtaCnf; + this.flagImballoArendere = other.flagImballoArendere; + this.flagStato = other.flagStato; + this.codDiviCont = other.codDiviCont; + this.cambioDiviCont = other.cambioDiviCont; + this.barcode = other.barcode; + this.note = other.note; + this.rapConv2 = other.rapConv2; + this.rapConv3 = other.rapConv3; + this.posizione = other.posizione; + this.dataAggPrz = other.dataAggPrz; + this.partitaMagSec = other.partitaMagSec; + this.qtaAttesa = other.qtaAttesa; + } public String getCodMart() { diff --git a/app/src/main/java/it/integry/integrywmsnative/core/model/MtbUntMis.java b/app/src/main/java/it/integry/integrywmsnative/core/model/MtbUntMis.java index 8507338e..69b528d5 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/model/MtbUntMis.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/model/MtbUntMis.java @@ -15,6 +15,18 @@ public class MtbUntMis extends EntityBase { this.type = "mtb_unt_mis"; } + // Costruttore di copia + public MtbUntMis(MtbUntMis other) { + this(); + + this.untMis = other.untMis; + this.flagDig = other.flagDig; + this.cifreDec = other.cifreDec; // BigDecimal è immutabile + this.tipoUm = other.tipoUm; + this.flagUnitaKg = other.flagUnitaKg; + this.flagAttivo = other.flagAttivo; + } + public String getUntMis() { return untMis; } diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/HttpInterceptor.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/HttpInterceptor.java index db1cda35..18a26043 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/rest/HttpInterceptor.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/HttpInterceptor.java @@ -36,7 +36,7 @@ public class HttpInterceptor implements Interceptor { //Nel caso in cui il token è scaduto e devo richiamare la refresh non bisogna passare il vecchio token if(SettingsManager.i().getUserSession().getAccessTokenExpiryDate() != null && - UtilityDate.getNowTime().isBefore(SettingsManager.i().getUserSession().getAccessTokenExpiryDate())) { + UtilityDate.getNowTime().isBefore(SettingsManager.i().getUserSession().getAccessTokenExpiryDate().minusSeconds(20))) { accessToken = SettingsManager.i().getUserSession().getAccessToken(); } diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ArticoloRESTConsumer.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ArticoloRESTConsumer.java index 3f1cf2a4..fa024ef8 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ArticoloRESTConsumer.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ArticoloRESTConsumer.java @@ -10,6 +10,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.concurrent.ExecutorService; import javax.inject.Singleton; @@ -26,7 +27,6 @@ import it.integry.integrywmsnative.core.rest.model.articolo.RetrieveArticoloByCo import it.integry.integrywmsnative.core.rest.model.articolo.SaveArticoloRequestDTO; import it.integry.integrywmsnative.core.rest.model.articolo.SaveArticoloResponseDTO; import it.integry.integrywmsnative.core.rest.model.articolo.SearchArticoloByBarcodeRequestDTO; -import it.integry.integrywmsnative.core.rest.model.articolo.SearchArticoloByBarcodeResponseDTO; import it.integry.integrywmsnative.core.rest.model.articolo.UpdateBarcodeImballoRequestDTO; import it.integry.integrywmsnative.core.utility.UtilityQuery; import retrofit2.Call; @@ -36,10 +36,12 @@ import retrofit2.Response; public class ArticoloRESTConsumer extends _BaseRESTConsumer { private final RESTBuilder restBuilder; + private final ExecutorService executorService; private final SystemRESTConsumer systemRESTConsumer; - public ArticoloRESTConsumer(RESTBuilder restBuilder, SystemRESTConsumer systemRESTConsumer) { + public ArticoloRESTConsumer(RESTBuilder restBuilder, ExecutorService executorService, SystemRESTConsumer systemRESTConsumer) { this.restBuilder = restBuilder; + this.executorService = executorService; this.systemRESTConsumer = systemRESTConsumer; } @@ -78,28 +80,30 @@ public class ArticoloRESTConsumer extends _BaseRESTConsumer { }); } - public void searchByBarcode(String barcodeProd, RunnableArgs> onComplete, RunnableArgs onFailed) { + public List searchByBarcodeSynchronized(String barcodeProd) throws Exception { ArticoloRESTConsumerService articoloRESTConsumerService = restBuilder.getService(ArticoloRESTConsumerService.class); var request = new SearchArticoloByBarcodeRequestDTO() .setBarcode(barcodeProd) .setOnlyActive(true); - articoloRESTConsumerService + var response = articoloRESTConsumerService .searchByBarcode(request) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "searchByBarcode", (m) -> { - onComplete.run(response.body().getDto().getArts()); - }, onFailed); - } + .execute(); - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - onFailed.run(e); - } - }); + analyzeAnswer(response, "searchByBarcode"); + return response.body().getDto().getArts(); + } + + public void searchByBarcode(String barcodeProd, RunnableArgs> onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + var mtbAarts = searchByBarcodeSynchronized(barcodeProd); + if (onComplete != null) onComplete.run(mtbAarts); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); } public void findIfIsKit(MtbAart mtbAart, RunnableArgs onComplete, RunnableArgs onFailed){ @@ -122,45 +126,47 @@ public class ArticoloRESTConsumer extends _BaseRESTConsumer { }); } - public void getByCodMarts(List codMartToFind, RunnableArgs> onComplete, RunnableArgs onFailed) { + public List getByCodMartsSynchronized(List codMartToFind) throws Exception { var codMarts = Stream.of(codMartToFind) .withoutNulls() .distinct().toList(); - ArticoloRESTConsumerService articoloRESTConsumer = restBuilder.getService(ArticoloRESTConsumerService.class); - articoloRESTConsumer + var response = articoloRESTConsumer .getByCodMart(new RetrieveArticoloByCodMartRequestDTO() .setCodMarts(codMarts)) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call>> call, Response>> response) { - analyzeAnswer(response, "getByCodMart", onComplete, onFailed); - } + .execute(); + return analyzeAnswer(response, "getByCodMart"); + } - @Override - public void onFailure(Call>> call, @NonNull final Exception e) { - onFailed.run(e); - } - }); + public void getByCodMarts(List codMartToFind, RunnableArgs> onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + var mtbAarts = getByCodMartsSynchronized(codMartToFind); + if (onComplete != null) onComplete.run(mtbAarts); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); + } + public List getStatoPartitaSynchronized(String codMart, String partitaMag) throws Exception { + ArticoloRESTConsumerService articoloRESTConsumer = restBuilder.getService(ArticoloRESTConsumerService.class); + var response = articoloRESTConsumer.getStatoPartita(codMart, partitaMag).execute(); + + var data = analyzeAnswer(response, "getStatoPartita"); + return data; } public void getStatoPartita(String codMart, String partitaMag, RunnableArgs> onComplete, RunnableArgs onFailed) { - - ArticoloRESTConsumerService articoloRESTConsumer = restBuilder.getService(ArticoloRESTConsumerService.class); - articoloRESTConsumer.getStatoPartita(codMart, partitaMag).enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call>> call, Response>> response) { - analyzeAnswer(response, "getStatoPartita", onComplete, onFailed); - } - - @Override - public void onFailure(Call>> call, @NonNull final Exception e) { - onFailed.run(e); + executorService.execute(() -> { + try { + var response = getStatoPartitaSynchronized(codMart, partitaMag); + if (onComplete != null) onComplete.run(response); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); } }); - } diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/BarcodeRESTConsumer.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/BarcodeRESTConsumer.java index 51474031..cb781a56 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/BarcodeRESTConsumer.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/BarcodeRESTConsumer.java @@ -16,6 +16,10 @@ public class BarcodeRESTConsumer extends _BaseRESTConsumer { this.ean128Service = ean128Service; } + public Ean128Model decodeEan128Synchronized(BarcodeScanDTO barcodeScanDTO) throws Exception { + return this.ean128Service.decode(barcodeScanDTO); + } + public void decodeEan128(BarcodeScanDTO barcodeObj, RunnableArgs onComplete, RunnableArgs onFailed) { try { onComplete.run(this.ean128Service.decode(barcodeObj)); diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliLavorazioneRESTConsumer.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliLavorazioneRESTConsumer.java index 9a708bb4..a4e3de1d 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliLavorazioneRESTConsumer.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliLavorazioneRESTConsumer.java @@ -3,6 +3,7 @@ package it.integry.integrywmsnative.core.rest.consumers; import androidx.annotation.NonNull; import java.math.BigDecimal; +import java.util.concurrent.ExecutorService; import javax.inject.Singleton; @@ -27,10 +28,8 @@ import it.integry.integrywmsnative.core.rest.model.uds.CloseUDSRequestDTO; import it.integry.integrywmsnative.core.rest.model.uds.CloseUDSResponseDTO; import it.integry.integrywmsnative.core.rest.model.uds.CreateUDSFromArtRequestDTO; import it.integry.integrywmsnative.core.rest.model.uds.CreateUDSRequestDTO; -import it.integry.integrywmsnative.core.rest.model.uds.CreateUDSResponseDTO; import it.integry.integrywmsnative.core.rest.model.uds.DeleteUDSRowRequestDTO; import it.integry.integrywmsnative.core.rest.model.uds.EditUDSRowRequestDTO; -import it.integry.integrywmsnative.core.rest.model.uds.EditUDSRowResponseDTO; import it.integry.integrywmsnative.core.rest.model.uds.InsertUDCRowRequestDTO; import it.integry.integrywmsnative.core.rest.model.uds.InsertUDCRowResponseDTO; import it.integry.integrywmsnative.core.rest.model.uds.InsertUDSRowRequestDTO; @@ -44,10 +43,12 @@ public class ColliLavorazioneRESTConsumer extends _BaseRESTConsumer implements C private final RESTBuilder restBuilder; + private final ExecutorService executorService; private final SettingsManager settingsManager; - public ColliLavorazioneRESTConsumer(RESTBuilder restBuilder, SettingsManager settingsManager) { + public ColliLavorazioneRESTConsumer(RESTBuilder restBuilder, ExecutorService executorService, SettingsManager settingsManager) { this.restBuilder = restBuilder; + this.executorService = executorService; this.settingsManager = settingsManager; } @@ -123,93 +124,111 @@ public class ColliLavorazioneRESTConsumer extends _BaseRESTConsumer implements C }); } - public void createUDS(CreateUDSRequestDTO createUDSRequestDTO, RunnableArgs onComplete, RunnableArgs onFailed) { + public MtbColt createUDSSynchronized(CreateUDSRequestDTO createUDSRequestDTO) throws Exception { ColliLavorazioneRESTConsumerService colliLavorazioneRESTConsumerService = restBuilder.getService(ColliLavorazioneRESTConsumerService.class); - colliLavorazioneRESTConsumerService.createUDS(createUDSRequestDTO) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "lavorazione/createUDS", data -> onComplete.run(data.getMtbColt()), onFailed); - } + var response = colliLavorazioneRESTConsumerService.createUDS(createUDSRequestDTO) + .execute(); - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - onFailed.run(e); - } - }); + var data = analyzeAnswer(response, "lavorazione/createUDS"); + return data.getMtbColt(); + } + public void createUDS(CreateUDSRequestDTO createUDSRequestDTO, RunnableArgs onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + var response = createUDSSynchronized(createUDSRequestDTO); + if (onComplete != null) onComplete.run(response); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); + } + + public CloseUDSResponseDTO closeUDSSynchronized(CloseUDSRequestDTO closeUDSRequestDTO) throws Exception { + ColliLavorazioneRESTConsumerService colliLavorazioneRESTConsumerService = restBuilder.getService(ColliLavorazioneRESTConsumerService.class); + + var response = colliLavorazioneRESTConsumerService.closeUDS(closeUDSRequestDTO) + .execute(); + + var data = analyzeAnswer(response, "lavorazione/closeUDS"); + return data; + } + + public void closeUDS(CloseUDSRequestDTO closeUDSRequestDTO, RunnableArgs onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + var response = closeUDSSynchronized(closeUDSRequestDTO); + if (onComplete != null) onComplete.run(response); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); } @Override - public void closeUDS(CloseUDSRequestDTO closeUDSRequestDTO, RunnableArgs onComplete, RunnableArgs onFailed) { + public MtbColr insertUDSRowSynchronized(InsertUDSRowRequestDTO insertUDSRowRequestDTO) throws Exception { ColliLavorazioneRESTConsumerService colliLavorazioneRESTConsumerService = restBuilder.getService(ColliLavorazioneRESTConsumerService.class); - colliLavorazioneRESTConsumerService.closeUDS(closeUDSRequestDTO) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "lavorazione/closeUDS", onComplete, onFailed); - } + Response> response = colliLavorazioneRESTConsumerService.insertUDSRow(insertUDSRowRequestDTO) + .execute(); - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - onFailed.run(e); - } - }); + var data = analyzeAnswer(response, "lavorazione/insertUDSRow"); + return data.getSavedMtbColr(); } + @Override public void insertUDSRow(InsertUDSRowRequestDTO insertUDSRowRequestDTO, RunnableArgs onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + var response = insertUDSRowSynchronized(insertUDSRowRequestDTO); + if (onComplete != null) onComplete.run(response); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); + } + + public MtbColr editUDSRowSynchronized(EditUDSRowRequestDTO editUDSRowRequestDTO) throws Exception { ColliLavorazioneRESTConsumerService colliLavorazioneRESTConsumerService = restBuilder.getService(ColliLavorazioneRESTConsumerService.class); - colliLavorazioneRESTConsumerService.insertUDSRow(insertUDSRowRequestDTO) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "lavorazione/insertUDSRow", data -> onComplete.run(data.getSavedMtbColr()), onFailed); - } + var response = colliLavorazioneRESTConsumerService.editUDSRow(editUDSRowRequestDTO) + .execute(); - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - onFailed.run(e); - } - }); + var data = analyzeAnswer(response, "lavorazione/editUDSRow"); + return data.getSavedMtbColr(); } public void editUDSRow(EditUDSRowRequestDTO editUDSRowRequestDTO, RunnableArgs onComplete, RunnableArgs onFailed) { - ColliLavorazioneRESTConsumerService colliLavorazioneRESTConsumerService = restBuilder.getService(ColliLavorazioneRESTConsumerService.class); - - colliLavorazioneRESTConsumerService.editUDSRow(editUDSRowRequestDTO) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "lavorazione/editUDSRow", data -> onComplete.run(data.getSavedMtbColr()), onFailed); - } - - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - onFailed.run(e); - } - }); + executorService.execute(() -> { + try { + var response = editUDSRowSynchronized(editUDSRowRequestDTO); + if (onComplete != null) onComplete.run(response); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); } - @Override - public void deleteUDSRow(DeleteUDSRowRequestDTO deleteUDSRowRequestDTO, Runnable onComplete, RunnableArgs onFailed) { + public void deleteUDSRowSynchronized(DeleteUDSRowRequestDTO deleteUDSRowRequestDTO) throws Exception { ColliLavorazioneRESTConsumerService colliLavorazioneRESTConsumerService = restBuilder.getService(ColliLavorazioneRESTConsumerService.class); - colliLavorazioneRESTConsumerService.deleteUDSRow(deleteUDSRowRequestDTO) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "lavorazione/deleteUDSRow", data -> onComplete.run(), onFailed); - } + var response = colliLavorazioneRESTConsumerService.deleteUDSRow(deleteUDSRowRequestDTO) + .execute(); - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - onFailed.run(e); - } - }); + analyzeAnswer(response, "lavorazione/deleteUDSRow"); + } + + public void deleteUDSRow(DeleteUDSRowRequestDTO deleteUDSRowRequestDTO, Runnable onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + deleteUDSRowSynchronized(deleteUDSRowRequestDTO); + if (onComplete != null) onComplete.run(); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); } @Override diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliMagazzinoRESTConsumer.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliMagazzinoRESTConsumer.java index d869846f..7b79318f 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliMagazzinoRESTConsumer.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliMagazzinoRESTConsumer.java @@ -16,6 +16,8 @@ import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.stream.Collectors; import javax.inject.Singleton; @@ -58,8 +60,9 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { private final ArticoloRESTConsumer mArticoloRESTConsumer; private final EntityRESTConsumer mEntityRESTConsumer; private final SettingsManager mSettingsManager; + private final ExecutorService executorService; - public ColliMagazzinoRESTConsumer(RESTBuilder restBuilder, SystemRESTConsumer systemRESTConsumer, + public ColliMagazzinoRESTConsumer(ExecutorService executorService, RESTBuilder restBuilder, SystemRESTConsumer systemRESTConsumer, ArticoloRESTConsumer articoloRESTConsumer, EntityRESTConsumer entityRESTConsumer, SettingsManager settingsManager) { @@ -68,6 +71,7 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { this.mArticoloRESTConsumer = articoloRESTConsumer; this.mEntityRESTConsumer = entityRESTConsumer; this.mSettingsManager = settingsManager; + this.executorService = executorService; } public void saveCollo(MtbColt mtbColtToSave, RunnableArgs onComplete, RunnableArgs onFailed) { @@ -75,14 +79,10 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { mtbColtToSaveClone.setOperation(CommonModelConsts.OPERATION.INSERT_OR_UPDATE); mtbColtToSaveClone.setOnlyPkMaster(false); - - mtbColtToSaveClone.setMtbColr(new ObservableArrayList<>()); - for (int i = 0; i < mtbColtToSave.getMtbColr().size(); i++) { - mtbColtToSaveClone.getMtbColr().add( - ((MtbColr) mtbColtToSave.getMtbColr().get(i).clone()) - .setMtbAart(null) - .setMtbPartitaMag(null)); + mtbColtToSaveClone.getMtbColr().get(i) + .setMtbAart(null) + .setMtbPartitaMag(null); } this.mEntityRESTConsumer.processEntity(mtbColtToSaveClone, new ISimpleOperationCallback<>() { @@ -99,6 +99,19 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { } + public List saveColliSynchronized(List mtbColtsToSave) throws Exception { + + for (MtbColt mtbColt : mtbColtsToSave) { + for (int i = 0; i < mtbColt.getMtbColr().size(); i++) { + mtbColt.getMtbColr().get(i) + .setMtbAart(null) + .setMtbPartitaMag(null); + } + } + + return this.mEntityRESTConsumer.processEntityListSynchronized(mtbColtsToSave, true, MtbColt.class); + } + public void saveColli(List mtbColtsToSave, RunnableArgs> onComplete, RunnableArgs onFailed) { for (MtbColt mtbColt : mtbColtsToSave) { @@ -210,7 +223,7 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { } -// if (sourceMtbColt.getMtbColr().size() != 1) { +// if (sourceMtbColt.getMtbColr().getValue().size() != 1) { // onFailed.run(new Exception()); // return; // } @@ -286,69 +299,82 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { saveCollo(mtbColtToCreate, onComplete, onFailed); } - public void getBySSCC(String ssccString, boolean onlyResiduo, boolean throwExcIfNull, RunnableArgs onComplete, RunnableArgs onFailed) { + public MtbColt getBySsccSynchronized(String ssccString, boolean onlyResiduo, boolean throwExcIfNull) throws Exception { ColliMagazzinoRESTConsumerService colliMagazzinoRESTConsumerService = restBuilder.getService(ColliMagazzinoRESTConsumerService.class); - colliMagazzinoRESTConsumerService.getColloByBarcode(ssccString, onlyResiduo, throwExcIfNull).enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "GetBySSCC", mtbColt -> { + var colloResponse = colliMagazzinoRESTConsumerService.getColloByBarcode(ssccString, onlyResiduo, throwExcIfNull) + .execute(); + var mtbColt = analyzeAnswer(colloResponse, "GetBySSCC"); - if (mtbColt != null && mtbColt.getMtbColr() != null && !mtbColt.getMtbColr().isEmpty()) { - List mtbColtList = new ArrayList<>(); - mtbColtList.add(mtbColt); - fillMtbAartsOfMtbColts(mtbColtList, mtbColts -> onComplete.run(mtbColts.get(0)), onFailed); - } else { - onComplete.run(mtbColt); - } + if (mtbColt != null && mtbColt.getMtbColr() != null && !mtbColt.getMtbColr().isEmpty()) { + List mtbColtList = new ArrayList<>(); + mtbColtList.add(mtbColt); + var mtbColts = fillMtbAartsOfMtbColtsSynchronized(mtbColtList); + return mtbColts.get(0); + } - }, onFailed); - } + return mtbColt; + } - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - onFailed.run(e); + public void getBySSCC(String ssccString, boolean onlyResiduo, boolean throwExcIfNull, RunnableArgs onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + var mtbColt = getBySsccSynchronized(ssccString, onlyResiduo, throwExcIfNull); + if (onComplete != null) onComplete.run(mtbColt); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); } }); } - public void fillMtbAartsOfMtbColts(List mtbColts, RunnableArgs> onComplete, RunnableArgs onFailed) { + public List fillMtbAartsOfMtbColtsSynchronized(List mtbColts) throws Exception { List codMarts = new ArrayList<>(); for (MtbColt mtbColt : mtbColts) { - codMarts.addAll(Stream.of(mtbColt.getMtbColr()) + codMarts.addAll(mtbColt.getMtbColr().stream() .map(MtbColr::getCodMart) - .withoutNulls() + .filter(x -> !UtilityString.isNullOrEmpty(x)) .distinct() - .toList()); + .collect(Collectors.toList())); } + List mtbAarts = mArticoloRESTConsumer.getByCodMartsSynchronized(codMarts); - mArticoloRESTConsumer.getByCodMarts(codMarts, arts -> { + for (MtbColt mtbColt : mtbColts) { + for (MtbColr mtbColr : mtbColt.getMtbColr()) { - if (arts != null && !arts.isEmpty()) { - for (MtbColt mtbColt : mtbColts) { - for (MtbColr mtbColr : mtbColt.getMtbColr()) { + if (mtbAarts != null && !mtbAarts.isEmpty()) { + MtbAart foundMtbAart = null; - MtbAart foundMtbAart = null; + List mtbAartStream = mtbAarts.parallelStream() + .filter(x -> x.getCodMart().equalsIgnoreCase(mtbColr.getCodMart())) + .collect(Collectors.toList()); - List mtbAartStream = Stream.of(arts) - .filter(x -> x.getCodMart().equalsIgnoreCase(mtbColr.getCodMart())).toList(); - - if (mtbAartStream != null && !mtbAartStream.isEmpty()) { - foundMtbAart = mtbAartStream.get(0); - } - - mtbColr.setMtbAart(foundMtbAart); - mtbColr.setGestione(mtbColt.getGestione()); - mtbColr.setSerCollo(mtbColt.getSerCollo()); - mtbColr.setNumCollo(mtbColt.getNumCollo()); - mtbColr.setDataCollo(mtbColt.getDataColloS()); + if (!mtbAartStream.isEmpty()) { + foundMtbAart = mtbAartStream.get(0); } - } - } - onComplete.run(mtbColts); - }, onFailed); + mtbColr.setMtbAart(foundMtbAart); + } + + mtbColr.setGestione(mtbColt.getGestione()); + mtbColr.setSerCollo(mtbColt.getSerCollo()); + mtbColr.setNumCollo(mtbColt.getNumCollo()); + mtbColr.setDataCollo(mtbColt.getDataColloS()); + } + } + + return mtbColts; + } + + public void fillMtbAartsOfMtbColts(List mtbColts, RunnableArgs> onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + List returnedMtbColts = fillMtbAartsOfMtbColtsSynchronized(mtbColts); + if (onComplete != null) onComplete.run(returnedMtbColts); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); } public void getMultipleByTestate(List testate, boolean onlyResiduo, RunnableArgs> onComplete, RunnableArgs onFailed) { @@ -369,6 +395,15 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { } } + public MtbColt getByChiaveColloSynchronized(GestioneEnum gestione, int numCollo, String dataCollo, String serCollo, boolean onlyResiduo, boolean throwExcIfNull) throws Exception { + MtbColt mtbColtToRetrieve = new MtbColt() + .setGestione(gestione) + .setNumCollo(numCollo) + .setDataCollo(dataCollo) + .setSerCollo(serCollo); + + return getByTestataSynchronized(mtbColtToRetrieve, onlyResiduo, throwExcIfNull); + } public void getByChiaveCollo(GestioneEnum gestione, int numCollo, String dataCollo, String serCollo, boolean onlyResiduo, boolean throwExcIfNull, RunnableArgs onComplete, RunnableArgs onFailed) { MtbColt mtbColtToRetrieve = new MtbColt() .setGestione(gestione) @@ -379,36 +414,36 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { getByTestata(mtbColtToRetrieve, onlyResiduo, throwExcIfNull, onComplete, onFailed); } - public void getByTestata(MtbColt testata, boolean onlyResiduo, boolean throwExcIfNull, RunnableArgs onComplete, RunnableArgs onFailed) { + public MtbColt getByTestataSynchronized(MtbColt testata, boolean onlyResiduo, boolean throwExcIfNull) throws Exception { testata.setMtbColr(new ObservableArrayList<>()); ColliMagazzinoRESTConsumerService colliMagazzinoRESTConsumerService = restBuilder.getService(ColliMagazzinoRESTConsumerService.class); - colliMagazzinoRESTConsumerService.getColloInGiac(onlyResiduo, throwExcIfNull, testata) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "getColloInGiac", mtbColt -> { + var response = colliMagazzinoRESTConsumerService.getColloInGiac(onlyResiduo, throwExcIfNull, testata) + .execute(); + var mtbColt = analyzeAnswer(response, "getColloInGiac"); + if (mtbColt != null && mtbColt.getMtbColr() != null && !mtbColt.getMtbColr().isEmpty()) { + List mtbColtList = new ArrayList<>(); + mtbColtList.add(mtbColt); + var mtbColts = fillMtbAartsOfMtbColtsSynchronized(mtbColtList); + return mtbColts.get(0); + } - if (mtbColt != null && mtbColt.getMtbColr() != null && !mtbColt.getMtbColr().isEmpty()) { - List mtbColtList = new ArrayList<>(); - mtbColtList.add(mtbColt); - fillMtbAartsOfMtbColts(mtbColtList, mtbColts -> onComplete.run(mtbColts.get(0)), onFailed); - } else { - onComplete.run(mtbColt); - } - - }, onFailed); - } - - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - onFailed.run(e); - } - }); + return mtbColt; } - public void spostaUL(MtbColt mtbColtToMove, String codMdep, String posizione, boolean createDocAutomatically, Runnable onComplete, RunnableArgs onFailed) { + public void getByTestata(MtbColt testata, boolean onlyResiduo, boolean throwExcIfNull, RunnableArgs onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + var data = getByTestataSynchronized(testata, onlyResiduo, throwExcIfNull); + if (onComplete != null) onComplete.run(data); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); + } + + public void spostaUlSynchronized(MtbColt mtbColtToMove, String codMdep, String posizione, boolean createDocAutomatically) throws Exception { MtbColt mtbColtToMoveClone = (MtbColt) mtbColtToMove.clone(); for (int i = 0; i < mtbColtToMoveClone.getMtbColr().size(); i++) { @@ -424,21 +459,23 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { .setCreateDocAutomatically(createDocAutomatically); ColliMagazzinoRESTConsumerService colliMagazzinoRESTConsumerService = restBuilder.getService(ColliMagazzinoRESTConsumerService.class); - colliMagazzinoRESTConsumerService + Response> response = colliMagazzinoRESTConsumerService .spostaUL(spostaUlRequestDTO) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "spostaUL", mtbColts -> { - onComplete.run(); - }, onFailed); - } + .execute(); - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - if (onFailed != null) onFailed.run(e); - } - }); + analyzeAnswer(response, "spostaUL"); + } + + + public void spostaUL(MtbColt mtbColtToMove, String codMdep, String posizione, boolean createDocAutomatically, Runnable onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + spostaUlSynchronized(mtbColtToMove, codMdep, posizione, createDocAutomatically); + if (onComplete != null) onComplete.run(); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); } public void spostaUL(MtbColt mtbColtToMove, MtbDepoPosizione posizione, Runnable onComplete, RunnableArgs onFailed) { @@ -449,7 +486,7 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { spostaUL(mtbColtToMove, codMdep, posizioneString, true, onComplete, onFailed); } - public void updateTipoUL(MtbColt mtbColt, String codTcol, Runnable onComplete, RunnableArgs onFailed) { + public void updateTipoULSynchronized(MtbColt mtbColt, String codTcol) throws Exception { MtbColt mtbColtClone = (MtbColt) mtbColt.clone(); mtbColtClone.setMtbColr(new ObservableArrayList<>()); @@ -459,22 +496,23 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { .setCodTcol(codTcol); ColliMagazzinoRESTConsumerService colliMagazzinoRESTConsumerService = restBuilder.getService(ColliMagazzinoRESTConsumerService.class); - colliMagazzinoRESTConsumerService + Response> response = colliMagazzinoRESTConsumerService .updateTipoUL(updateTipoULRequest) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "updateTipoUL", mtbColts -> { - onComplete.run(); - }, onFailed); - } + .execute(); - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - if (onFailed != null) onFailed.run(e); - } - }); + analyzeAnswer(response, "updateTipoUL"); + } + + public void updateTipoUL(MtbColt mtbColt, String codTcol, Runnable onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + updateTipoULSynchronized(mtbColt, codTcol); + if (onComplete != null) onComplete.run(); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); } public void updateDataFine(MtbColt mtbColt, Runnable onComplete, RunnableArgs onFailed) { @@ -538,7 +576,7 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { } public void spostaArtsTraUL(MtbColt sourceMtbColt, MtbColt destMtbColt, boolean flagForceUseRefs, RunnableArgs> onComplete, RunnableArgs onFailed) { - new Thread(() -> { + executorService.execute(() -> { MtbColt mtbColtToMoveClone = (MtbColt) sourceMtbColt.clone(); MtbColt mtbColtDestClone = (MtbColt) destMtbColt.clone(); @@ -569,7 +607,7 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { if (onFailed != null) onFailed.run(e); } }); - }).start(); + }); } public void assegnaLottoSuColloScarico(MtbColt sourceMtbColt, Runnable onComplete, RunnableArgs onFailed) { @@ -698,42 +736,48 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer { } - public void canULBeDeleted(MtbColt mtbColt, RunnableArgs onComplete, RunnableArgs onFailed) { + public Boolean canULBeDeletedSynchronized(MtbColt mtbColt) throws Exception { CanULBeDeletedRequestDTO canULBeDeletedRequestDTO = new CanULBeDeletedRequestDTO() .setMtbColt(mtbColt); ColliMagazzinoRESTConsumerService colliMagazzinoRESTConsumerService = restBuilder.getService(ColliMagazzinoRESTConsumerService.class); - colliMagazzinoRESTConsumerService.canULBeDeleted(canULBeDeletedRequestDTO) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "generic/canULBeDeleted", onComplete, onFailed); - } + var response = colliMagazzinoRESTConsumerService.canULBeDeleted(canULBeDeletedRequestDTO) + .execute(); - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - onFailed.run(e); - } - }); + var data = analyzeAnswer(response, "generic/canULBeDeleted"); + return data; + } + public void canULBeDeleted(MtbColt mtbColt, RunnableArgs onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + var result = canULBeDeletedSynchronized(mtbColt); + if (onComplete != null) onComplete.run(result); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); + } + + public void deleteULSynchronized(DeleteULRequestDTO deleteULRequestDTO) throws Exception { + ColliMagazzinoRESTConsumerService colliMagazzinoRESTConsumerService = restBuilder.getService(ColliMagazzinoRESTConsumerService.class); + + var response = colliMagazzinoRESTConsumerService.deleteUL(deleteULRequestDTO) + .execute(); + + analyzeAnswer(response, "generic/deleteUL"); } public void deleteUL(DeleteULRequestDTO deleteULRequestDTO, Runnable onComplete, RunnableArgs onFailed) { - ColliMagazzinoRESTConsumerService colliMagazzinoRESTConsumerService = restBuilder.getService(ColliMagazzinoRESTConsumerService.class); - - colliMagazzinoRESTConsumerService.deleteUL(deleteULRequestDTO) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "generic/deleteUL", Void -> onComplete.run(), onFailed); - } - - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - onFailed.run(e); - } - }); + executorService.execute(() -> { + try { + deleteULSynchronized(deleteULRequestDTO); + if (onComplete != null) onComplete.run(); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); } diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliSpedizioneRESTConsumer.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliSpedizioneRESTConsumer.java index 4744758f..e86df307 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliSpedizioneRESTConsumer.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/ColliSpedizioneRESTConsumer.java @@ -1,6 +1,6 @@ package it.integry.integrywmsnative.core.rest.consumers; -import androidx.annotation.NonNull; +import java.util.concurrent.ExecutorService; import javax.inject.Singleton; @@ -9,134 +9,152 @@ import it.integry.integrywmsnative.core.model.MtbColr; import it.integry.integrywmsnative.core.model.MtbColt; import it.integry.integrywmsnative.core.rest.RESTBuilder; import it.integry.integrywmsnative.core.rest.consumers.interfaces.ColliScaricoRESTConsumerInterface; -import it.integry.integrywmsnative.core.rest.handler.ManagedErrorCallback; import it.integry.integrywmsnative.core.rest.model.ServiceRESTResponse; import it.integry.integrywmsnative.core.rest.model.uds.CloseUDSRequestDTO; import it.integry.integrywmsnative.core.rest.model.uds.CloseUDSResponseDTO; import it.integry.integrywmsnative.core.rest.model.uds.CreateUDSRequestDTO; -import it.integry.integrywmsnative.core.rest.model.uds.CreateUDSResponseDTO; import it.integry.integrywmsnative.core.rest.model.uds.DeleteUDSRowRequestDTO; import it.integry.integrywmsnative.core.rest.model.uds.DuplicateUDSRequestDTO; import it.integry.integrywmsnative.core.rest.model.uds.DuplicateUDSResponseDTO; import it.integry.integrywmsnative.core.rest.model.uds.EditUDSRowRequestDTO; -import it.integry.integrywmsnative.core.rest.model.uds.EditUDSRowResponseDTO; import it.integry.integrywmsnative.core.rest.model.uds.InsertUDSRowRequestDTO; import it.integry.integrywmsnative.core.rest.model.uds.InsertUDSRowResponseDTO; -import retrofit2.Call; import retrofit2.Response; @Singleton public class ColliSpedizioneRESTConsumer extends _BaseRESTConsumer implements ColliScaricoRESTConsumerInterface { private final RESTBuilder restBuilder; + private final ExecutorService executorService; - public ColliSpedizioneRESTConsumer(RESTBuilder restBuilder) { + public ColliSpedizioneRESTConsumer(RESTBuilder restBuilder, ExecutorService executorService) { this.restBuilder = restBuilder; + this.executorService = executorService; + } + + public MtbColt createUDSSynchronized(CreateUDSRequestDTO createUDSRequestDTO) throws Exception { + ColliSpedizioneRESTConsumerService colliSpedizioneRESTConsumerService = restBuilder.getService(ColliSpedizioneRESTConsumerService.class); + + var response = colliSpedizioneRESTConsumerService.createUDS(createUDSRequestDTO) + .execute(); + + var data = analyzeAnswer(response, "spedizione/createUDS"); + return data.getMtbColt(); } public void createUDS(CreateUDSRequestDTO createUDSRequestDTO, RunnableArgs onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + var response = createUDSSynchronized(createUDSRequestDTO); + if (onComplete != null) onComplete.run(response); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); + } + + public CloseUDSResponseDTO closeUDSSynchronized(CloseUDSRequestDTO closeUDSRequestDTO) throws Exception { ColliSpedizioneRESTConsumerService colliSpedizioneRESTConsumerService = restBuilder.getService(ColliSpedizioneRESTConsumerService.class); - colliSpedizioneRESTConsumerService.createUDS(createUDSRequestDTO) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "spedizione/createUDS", data -> onComplete.run(data.getMtbColt()), onFailed); - } - - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - onFailed.run(e); - } - }); + var response = colliSpedizioneRESTConsumerService.closeUDS(closeUDSRequestDTO) + .execute(); + var data = analyzeAnswer(response, "spedizione/closeUDS"); + return data; } public void closeUDS(CloseUDSRequestDTO closeUDSRequestDTO, RunnableArgs onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + var response = closeUDSSynchronized(closeUDSRequestDTO); + if (onComplete != null) onComplete.run(response); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); + } + + public MtbColr insertUDSRowSynchronized(InsertUDSRowRequestDTO insertUDSRowRequestDTO) throws Exception { ColliSpedizioneRESTConsumerService colliSpedizioneRESTConsumerService = restBuilder.getService(ColliSpedizioneRESTConsumerService.class); - colliSpedizioneRESTConsumerService.closeUDS(closeUDSRequestDTO) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "spedizione/closeUDS", onComplete, onFailed); - } - - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - onFailed.run(e); - } - }); + Response> response = colliSpedizioneRESTConsumerService.insertUDSRow(insertUDSRowRequestDTO) + .execute(); + var data = analyzeAnswer(response, "spedizione/insertUDSRow"); + return data.getSavedMtbColr(); } public void insertUDSRow(InsertUDSRowRequestDTO insertUDSRowRequestDTO, RunnableArgs onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + var response = insertUDSRowSynchronized(insertUDSRowRequestDTO); + if (onComplete != null) onComplete.run(response); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); + } + + public MtbColr editUDSRowSynchronized(EditUDSRowRequestDTO editUDSRowRequestDTO) throws Exception { ColliSpedizioneRESTConsumerService colliSpedizioneRESTConsumerService = restBuilder.getService(ColliSpedizioneRESTConsumerService.class); - colliSpedizioneRESTConsumerService.insertUDSRow(insertUDSRowRequestDTO) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "spedizione/insertUDSRow", data -> onComplete.run(data.getSavedMtbColr()), onFailed); - } + var response = colliSpedizioneRESTConsumerService.editUDSRow(editUDSRowRequestDTO) + .execute(); - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - onFailed.run(e); - } - }); + var data = analyzeAnswer(response, "spedizione/editUDSRow"); + return data.getSavedMtbColr(); } public void editUDSRow(EditUDSRowRequestDTO editUDSRowRequestDTO, RunnableArgs onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + var response = editUDSRowSynchronized(editUDSRowRequestDTO); + if (onComplete != null) onComplete.run(response); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); + } + + public void deleteUDSRowSynchronized(DeleteUDSRowRequestDTO deleteUDSRowRequestDTO) throws Exception { ColliSpedizioneRESTConsumerService colliSpedizioneRESTConsumerService = restBuilder.getService(ColliSpedizioneRESTConsumerService.class); - colliSpedizioneRESTConsumerService.editUDSRow(editUDSRowRequestDTO) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "spedizione/editUDSRow", data -> onComplete.run(data.getSavedMtbColr()), onFailed); - } + var response = colliSpedizioneRESTConsumerService.deleteUDSRow(deleteUDSRowRequestDTO) + .execute(); - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - onFailed.run(e); - } - }); + analyzeAnswer(response, "spedizione/deleteUDSRow"); } public void deleteUDSRow(DeleteUDSRowRequestDTO deleteUDSRowRequestDTO, Runnable onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + deleteUDSRowSynchronized(deleteUDSRowRequestDTO); + if (onComplete != null) onComplete.run(); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); + } + + public DuplicateUDSResponseDTO duplicateUDSSynchronized(DuplicateUDSRequestDTO duplicateUDSRequestDTO) throws Exception { ColliSpedizioneRESTConsumerService colliSpedizioneRESTConsumerService = restBuilder.getService(ColliSpedizioneRESTConsumerService.class); - colliSpedizioneRESTConsumerService.deleteUDSRow(deleteUDSRowRequestDTO) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "spedizione/deleteUDSRow", data -> onComplete.run(), onFailed); - } - - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - onFailed.run(e); - } - }); + var response = colliSpedizioneRESTConsumerService.duplicateUDS(duplicateUDSRequestDTO) + .execute(); + var data = analyzeAnswer(response, "spedizione/duplicateUDS"); + return data; } public void duplicateUDS(DuplicateUDSRequestDTO duplicateUDSRequestDTO, RunnableArgs onComplete, RunnableArgs onFailed) { - ColliSpedizioneRESTConsumerService colliSpedizioneRESTConsumerService = restBuilder.getService(ColliSpedizioneRESTConsumerService.class); - - colliSpedizioneRESTConsumerService.duplicateUDS(duplicateUDSRequestDTO) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(@NonNull Call> call, @NonNull Response> response) { - analyzeAnswer(response, "spedizione/duplicateUDS", onComplete, onFailed); - } - - @Override - public void onFailure(@NonNull Call> call, @NonNull final Exception e) { - onFailed.run(new Exception()); - } - }); + executorService.execute(() -> { + try { + var data = duplicateUDSSynchronized(duplicateUDSRequestDTO); + if (onComplete != null) onComplete.run(data); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); } } diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/EntityRESTConsumer.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/EntityRESTConsumer.java index 964043b2..00e1abeb 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/EntityRESTConsumer.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/EntityRESTConsumer.java @@ -9,6 +9,7 @@ import com.google.gson.JsonObject; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ExecutorService; import javax.inject.Singleton; @@ -26,9 +27,11 @@ import retrofit2.Response; public class EntityRESTConsumer extends _BaseRESTConsumer { private final RESTBuilder restBuilder; + private final ExecutorService executorService; - public EntityRESTConsumer(RESTBuilder restBuilder) { + public EntityRESTConsumer(RESTBuilder restBuilder, ExecutorService executorService) { this.restBuilder = restBuilder; + this.executorService = executorService; } public void processEntity(T entityToSave, final ISimpleOperationCallback callback, Class type) { @@ -73,53 +76,48 @@ public class EntityRESTConsumer extends _BaseRESTConsumer { } - public void processEntityList(List entitiesToSave, boolean singleTransaction, Class type, final RunnableArgs> onComplete, final RunnableArgs onFailed) { - - RunnableArgs tmpFailed = ex -> { -// UtilityExceptions.defaultException(null, ex); - if (onFailed != null) onFailed.run(ex); - }; - + public List processEntityListSynchronized(List entitiesToSave, boolean singleTransaction, Class type) throws Exception { EntityRESTConsumerService service = restBuilder.getService(EntityRESTConsumerService.class); - Call>> request = service.processEntityList(singleTransaction, entitiesToSave); - request.enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call>> call, Response>> response) { - if (response.isSuccessful()) { + var response = service.processEntityList(singleTransaction, entitiesToSave) + .execute(); - if (response.body() != null) { + if (response.isSuccessful()) { - ArrayList responseList = new ArrayList<>(); - Gson gson = UtilityGson.createObject(); -// Type typeOfObjectsList = new TypeToken() {}.getType(); + if (response.body() != null) { - for (ServiceRESTResponse jsonSingleObject : response.body()) { + ArrayList responseList = new ArrayList<>(); + Gson gson = UtilityGson.createObject(); - if (jsonSingleObject.getEsito() == EsitoType.OK) { - String jsonText = gson.toJson(jsonSingleObject.getEntity()); - responseList.add(gson.fromJson(jsonText, type)); - } else { - Log.e("EntityRESTConsumer", jsonSingleObject.getErrorMessage()); - tmpFailed.run(new Exception(jsonSingleObject.getErrorMessage())); + for (ServiceRESTResponse jsonSingleObject : response.body()) { - return; - } - } - - onComplete.run(responseList); + if (jsonSingleObject.getEsito() == EsitoType.OK) { + String jsonText = gson.toJson(jsonSingleObject.getEntity()); + responseList.add(gson.fromJson(jsonText, type)); } else { - Log.e("EntityRESTConsumer", response.message()); - tmpFailed.run(new Exception(response.message())); + Log.e("EntityRESTConsumer", jsonSingleObject.getErrorMessage()); + throw new Exception(jsonSingleObject.getErrorMessage()); } - } else { - Log.e("EntityRESTConsumer", "Status " + response.code() + ": " + response.message()); - tmpFailed.run(new Exception("Status " + response.code() + ": " + response.message())); } - } - @Override - public void onFailure(Call>> call, @NonNull final Exception e) { - tmpFailed.run(e); + return responseList; + } else { + Log.e("EntityRESTConsumer", response.message()); + throw new Exception(response.message()); + } + } else { + Log.e("EntityRESTConsumer", "Status " + response.code() + ": " + response.message()); + throw new Exception("Status " + response.code() + ": " + response.message()); + } + + } + + public void processEntityList(List entitiesToSave, boolean singleTransaction, Class type, final RunnableArgs> onComplete, final RunnableArgs onFailed) { + executorService.execute(() -> { + try { + var data = processEntityListSynchronized(entitiesToSave, singleTransaction, type); + if (onComplete != null) onComplete.run(data); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); } }); diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/MagazzinoAutomaticoRESTConsumer.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/MagazzinoAutomaticoRESTConsumer.java index c938a532..fcd79249 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/MagazzinoAutomaticoRESTConsumer.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/MagazzinoAutomaticoRESTConsumer.java @@ -2,6 +2,8 @@ package it.integry.integrywmsnative.core.rest.consumers; import androidx.annotation.NonNull; +import java.util.concurrent.ExecutorService; + import javax.inject.Singleton; import it.integry.integrywmsnative.core.expansion.RunnableArgs; @@ -18,26 +20,31 @@ import retrofit2.Response; public class MagazzinoAutomaticoRESTConsumer extends _BaseRESTConsumer { + private final ExecutorService executorService; private final RESTBuilder restBuilder; - public MagazzinoAutomaticoRESTConsumer(RESTBuilder restBuilder) { + public MagazzinoAutomaticoRESTConsumer(ExecutorService executorService, RESTBuilder restBuilder) { + this.executorService = executorService; this.restBuilder = restBuilder; } - public void pickItems(MtbDepoPosizione posizione, MagazzinoAutomaticoPickItemsRequestDTO magazzinoAutomaticoPickItemsRequestDTO, Runnable onComplete, RunnableArgs onFailed) { + public void pickItemsSynchronous(MtbDepoPosizione posizione, MagazzinoAutomaticoPickItemsRequestDTO magazzinoAutomaticoPickItemsRequestDTO) throws Exception { MagazzinoAutomaticoRESTConsumerService magazzinoAutomaticoRESTConsumerService = restBuilder.getService(MagazzinoAutomaticoRESTConsumerService.class); - magazzinoAutomaticoRESTConsumerService.pickItems(posizione.getPosizione(), magazzinoAutomaticoPickItemsRequestDTO) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "magazzino-automatico/pickItems", data -> onComplete.run(), onFailed); - } + var response = magazzinoAutomaticoRESTConsumerService.pickItems(posizione.getPosizione(), magazzinoAutomaticoPickItemsRequestDTO) + .execute(); - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - onFailed.run(e); - } - }); + analyzeAnswer(response, "magazzino-automatico/pickItems"); + } + + public void pickItems(MtbDepoPosizione posizione, MagazzinoAutomaticoPickItemsRequestDTO magazzinoAutomaticoPickItemsRequestDTO, Runnable onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + pickItemsSynchronous(posizione, magazzinoAutomaticoPickItemsRequestDTO); + if (onComplete != null) onComplete.run(); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); } diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/OrdiniRESTConsumer.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/OrdiniRESTConsumer.java index 0aa4af9f..c545f96e 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/OrdiniRESTConsumer.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/OrdiniRESTConsumer.java @@ -5,13 +5,13 @@ import androidx.annotation.NonNull; import com.annimon.stream.Optional; import com.annimon.stream.Stream; import com.google.gson.reflect.TypeToken; -import com.orhanobut.logger.Logger; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Random; +import java.util.concurrent.ExecutorService; import javax.inject.Singleton; @@ -39,12 +39,14 @@ import retrofit2.Response; public class OrdiniRESTConsumer extends _BaseRESTConsumer { private final RESTBuilder restBuilder; + private final ExecutorService executorService; private final SystemRESTConsumer mSystemRESTConsumer; private final EntityRESTConsumer mEntityRESTConsumer; - public OrdiniRESTConsumer(RESTBuilder restBuilder, SystemRESTConsumer systemRESTConsumer, EntityRESTConsumer entityRESTConsumer) { + public OrdiniRESTConsumer(RESTBuilder restBuilder, ExecutorService executorService,SystemRESTConsumer systemRESTConsumer, EntityRESTConsumer entityRESTConsumer) { this.restBuilder = restBuilder; + this.executorService = executorService; this.mSystemRESTConsumer = systemRESTConsumer; this.mEntityRESTConsumer = entityRESTConsumer; } @@ -61,7 +63,7 @@ public class OrdiniRESTConsumer extends _BaseRESTConsumer { for (PickingObjectDTO pickingObjectDTO : pickingObjects) { for (MtbColt mtbColt : pickingObjectDTO.getMtbColts()) { - Stream.of(mtbColt.getMtbColr()) + mtbColt.getMtbColr().stream() .filter(x -> !UtilityString.isNullOrEmpty(x.getPartitaMag())) .forEach(x -> { @@ -125,28 +127,24 @@ public class OrdiniRESTConsumer extends _BaseRESTConsumer { this.mEntityRESTConsumer.processEntityList(partitaMag, true, MtbPartitaMag.class, onComplete, onFailed); } - public void getOrdiniInevasi(String codMdep, GestioneEnum gestione, RunnableArgs> onComplete, RunnableArgs onFailed) { - + public List getOrdiniInevasiSynchronized(String codMdep, GestioneEnum gestione) throws Exception { OrdiniRESTConsumerService service = restBuilder.getService(OrdiniRESTConsumerService.class); - service.getOrdiniInevasi(codMdep, gestione.getText()) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call>> call, Response>> response) { - analyzeAnswer(response, "getOrdiniInevasi", responseDtoList -> { - if (responseDtoList == null) responseDtoList = new ArrayList<>(); - onComplete.run(responseDtoList); - }, ex -> { - Logger.e(ex, "Errore durante il caricamento degli ordini di lavorazione"); - if (onFailed != null) onFailed.run(ex); - }); - } + var response = service.getOrdiniInevasi(codMdep, gestione.getText()) + .execute(); + var data = analyzeAnswer(response, "getOrdiniInevasi"); + return data == null ? new ArrayList<>() : data; + } - @Override - public void onFailure(Call>> call, @NonNull final Exception e) { - if (onFailed != null) onFailed.run(e); - } - }); + public void getOrdiniInevasi(String codMdep, GestioneEnum gestione, RunnableArgs> onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + var result = getOrdiniInevasiSynchronized(codMdep, gestione); + if (onComplete != null) onComplete.run(result); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); } public void retrieveListaArticoliFromOrdiniUscita(String codMdep, List orders, RunnableArgs> onComplete, RunnableArgs onFailed) { diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/PosizioniRESTConsumer.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/PosizioniRESTConsumer.java index 59e276e1..eceb8263 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/PosizioniRESTConsumer.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/PosizioniRESTConsumer.java @@ -7,6 +7,7 @@ import com.google.gson.reflect.TypeToken; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ExecutorService; import javax.inject.Singleton; @@ -25,10 +26,12 @@ public class PosizioniRESTConsumer extends _BaseRESTConsumer { private final RESTBuilder restBuilder; private final SystemRESTConsumer mSystemRESTConsumer; + private final ExecutorService executorService; - public PosizioniRESTConsumer(RESTBuilder restBuilder, SystemRESTConsumer systemRESTConsumer) { + public PosizioniRESTConsumer(RESTBuilder restBuilder, SystemRESTConsumer systemRESTConsumer, ExecutorService executorService) { this.restBuilder = restBuilder; this.mSystemRESTConsumer = systemRESTConsumer; + this.executorService = executorService; } public void getAvailablePosizioni(RunnableArgs> onComplete, RunnableArgs onFailed) { @@ -50,8 +53,7 @@ public class PosizioniRESTConsumer extends _BaseRESTConsumer { }); } - - public void getBancaliInPosizione(MtbDepoPosizione mtbDepoPosizione, RunnableArgs> onComplete, RunnableArgs onFailed) { + public ArrayList getBancaliInPosizioneSynchronized(MtbDepoPosizione mtbDepoPosizione) throws Exception { String sql = "SELECT * FROM mtb_colt " + "WHERE segno > 0 " + "AND cod_mdep = " + UtilityDB.valueToString(mtbDepoPosizione.getCodMdep()) + " " + @@ -61,10 +63,18 @@ public class PosizioniRESTConsumer extends _BaseRESTConsumer { Type typeOfObjectsList = new TypeToken>() { }.getType(); - mSystemRESTConsumer.>processSql(sql, typeOfObjectsList, value -> { - if (onComplete != null) onComplete.run(value); - }, ex -> { - if (onFailed != null) onFailed.run(ex); + var value = mSystemRESTConsumer.>processSqlSynchronized(sql, typeOfObjectsList); + return value; + } + + public void getBancaliInPosizione(MtbDepoPosizione mtbDepoPosizione, RunnableArgs> onComplete, RunnableArgs onFailed) { + executorService.execute(() -> { + try { + var result = getBancaliInPosizioneSynchronized(mtbDepoPosizione); + if (onComplete != null) onComplete.run(result); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } }); } diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/SystemRESTConsumer.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/SystemRESTConsumer.java index 6267f717..0f6eda07 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/SystemRESTConsumer.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/SystemRESTConsumer.java @@ -13,6 +13,7 @@ import java.io.InputStreamReader; import java.io.Reader; import java.lang.reflect.Type; import java.util.List; +import java.util.concurrent.ExecutorService; import javax.inject.Singleton; @@ -37,9 +38,11 @@ import retrofit2.Response; public class SystemRESTConsumer extends _BaseRESTConsumer { private final RESTBuilder restBuilder; + private final ExecutorService executorService; - public SystemRESTConsumer(RESTBuilder restBuilder) { + public SystemRESTConsumer(RESTBuilder restBuilder, ExecutorService executorService) { this.restBuilder = restBuilder; + this.executorService = executorService; } public void retrieveUpdatesInfo(final RunnableArgs onSuccess, final RunnableArgs onFailed) { @@ -48,7 +51,7 @@ public class SystemRESTConsumer extends _BaseRESTConsumer { .enqueue(new ManagedErrorCallback<>() { @Override public void onResponse(Call call, Response response) { - if(response.code() == 404) { + if (response.code() == 404) { onSuccess.run(null); return; } @@ -84,35 +87,37 @@ public class SystemRESTConsumer extends _BaseRESTConsumer { } - public void processSql(String nativeSql, final Type clazz, final RunnableArgs onComplete, final RunnableArgs onFailed) { + public T processSqlSynchronized(String nativeSql, final Type clazz) throws Exception { NativeSqlRequestDTO nativeSqlDTO = new NativeSqlRequestDTO() .setNativeSql(nativeSql); SystemRESTConsumerService service = restBuilder.getService(SystemRESTConsumerService.class); - service + var response = service .processSql(nativeSqlDTO) - .enqueue(new ManagedErrorCallback<>() { - @Override - public void onResponse(Call> call, Response> response) { - analyzeAnswer(response, "ProcessSql", o -> { - Gson gson = UtilityGson.createObject(); + .execute(); + + var data = analyzeAnswer(response, "processSql"); + + Gson gson = UtilityGson.createObject(); + String json = gson.toJson(data); + + InputStream ims = new ByteArrayInputStream(json.getBytes()); + Reader reader = new InputStreamReader(ims); + T gsonObj = gson.fromJson(reader, clazz); + + return gsonObj; + } - String json = gson.toJson(o); - - InputStream ims = new ByteArrayInputStream(json.getBytes()); - Reader reader = new InputStreamReader(ims); - T gsonObj = gson.fromJson(reader, clazz); - - onComplete.run(gsonObj); - }, onFailed); - } - - @Override - public void onFailure(Call> call, @NonNull final Exception e) { - onFailed.run(e); - } - }); + public void processSql(String nativeSql, final Type clazz, final RunnableArgs onComplete, final RunnableArgs onFailed) { + executorService.execute(() -> { + try { + T result = processSqlSynchronized(nativeSql, clazz); + if (onComplete != null) onComplete.run(result); + } catch (Exception ex) { + if (onFailed != null) onFailed.run(ex); + } + }); } diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/interfaces/ColliScaricoRESTConsumerInterface.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/interfaces/ColliScaricoRESTConsumerInterface.java index 103887aa..82babeb2 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/interfaces/ColliScaricoRESTConsumerInterface.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/consumers/interfaces/ColliScaricoRESTConsumerInterface.java @@ -12,13 +12,23 @@ import it.integry.integrywmsnative.core.rest.model.uds.InsertUDSRowRequestDTO; public interface ColliScaricoRESTConsumerInterface { + MtbColt createUDSSynchronized(CreateUDSRequestDTO createUDSRequestDTO) throws Exception; + void createUDS(CreateUDSRequestDTO createUDSRequestDTO, RunnableArgs onComplete, RunnableArgs onFailed); + CloseUDSResponseDTO closeUDSSynchronized(CloseUDSRequestDTO closeUDSRequestDTO) throws Exception; + void closeUDS(CloseUDSRequestDTO closeUDSRequestDTO, RunnableArgs onComplete, RunnableArgs onFailed); + MtbColr insertUDSRowSynchronized(InsertUDSRowRequestDTO insertUDSRowRequestDTO) throws Exception; + void insertUDSRow(InsertUDSRowRequestDTO insertUDSRowRequestDTO, RunnableArgs onComplete, RunnableArgs onFailed); + MtbColr editUDSRowSynchronized(EditUDSRowRequestDTO editUDSRowRequestDTO) throws Exception; + void editUDSRow(EditUDSRowRequestDTO editUDSRowRequestDTO, RunnableArgs onComplete, RunnableArgs onFailed); + void deleteUDSRowSynchronized(DeleteUDSRowRequestDTO deleteUDSRequestDTO) throws Exception; + void deleteUDSRow(DeleteUDSRowRequestDTO deleteUDSRequestDTO, Runnable onComplete, RunnableArgs onFailed); } diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/deserializer/MutableLiveDataDeserializer.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/deserializer/MutableLiveDataDeserializer.java new file mode 100644 index 00000000..fb972cfd --- /dev/null +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/deserializer/MutableLiveDataDeserializer.java @@ -0,0 +1,21 @@ +package it.integry.integrywmsnative.core.rest.deserializer; + +import androidx.lifecycle.MutableLiveData; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +public class MutableLiveDataDeserializer implements JsonDeserializer> { + @Override + public MutableLiveData deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + Type type = ((ParameterizedType) typeOfT).getActualTypeArguments()[0]; + MutableLiveData liveData = new MutableLiveData<>(); + liveData.setValue(context.deserialize(json, type)); + return liveData; + } +} diff --git a/app/src/main/java/it/integry/integrywmsnative/core/rest/serializer/MutableLiveDataSerializer.java b/app/src/main/java/it/integry/integrywmsnative/core/rest/serializer/MutableLiveDataSerializer.java new file mode 100644 index 00000000..b6077911 --- /dev/null +++ b/app/src/main/java/it/integry/integrywmsnative/core/rest/serializer/MutableLiveDataSerializer.java @@ -0,0 +1,16 @@ +package it.integry.integrywmsnative.core.rest.serializer; + +import androidx.lifecycle.MutableLiveData; + +import com.google.gson.JsonElement; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; + +public class MutableLiveDataSerializer implements JsonSerializer> { + @Override + public JsonElement serialize(MutableLiveData src, Type typeOfSrc, JsonSerializationContext context) { + return context.serialize(src.getValue()); + } +} diff --git a/app/src/main/java/it/integry/integrywmsnative/core/utility/UtilityDialog.java b/app/src/main/java/it/integry/integrywmsnative/core/utility/UtilityDialog.java index fda1521a..fb00af71 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/utility/UtilityDialog.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/utility/UtilityDialog.java @@ -40,4 +40,5 @@ public class UtilityDialog { // dialog.getWindow().setLayout(width, LinearLayout.LayoutParams.WRAP_CONTENT); // } + } diff --git a/app/src/main/java/it/integry/integrywmsnative/core/utility/UtilityGson.java b/app/src/main/java/it/integry/integrywmsnative/core/utility/UtilityGson.java index 37dc03fa..1fb6ec90 100644 --- a/app/src/main/java/it/integry/integrywmsnative/core/utility/UtilityGson.java +++ b/app/src/main/java/it/integry/integrywmsnative/core/utility/UtilityGson.java @@ -1,5 +1,7 @@ package it.integry.integrywmsnative.core.utility; +import androidx.lifecycle.MutableLiveData; + import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -12,10 +14,12 @@ import it.integry.integrywmsnative.core.model.secondary.StatoPartitaMag; import it.integry.integrywmsnative.core.rest.deserializer.LocalDateDeserializer; import it.integry.integrywmsnative.core.rest.deserializer.LocalDateTimeDeserializer; import it.integry.integrywmsnative.core.rest.deserializer.MtbTcolFlagUiUlDeserializer; +import it.integry.integrywmsnative.core.rest.deserializer.MutableLiveDataDeserializer; import it.integry.integrywmsnative.core.rest.deserializer.StatoPartitaMagDeserializer; import it.integry.integrywmsnative.core.rest.serializer.LocalDateSerializer; import it.integry.integrywmsnative.core.rest.serializer.LocalDateTimeSerializer; import it.integry.integrywmsnative.core.rest.serializer.MtbTcolFlagUiUlSerializer; +import it.integry.integrywmsnative.core.rest.serializer.MutableLiveDataSerializer; import it.integry.integrywmsnative.core.rest.serializer.StatoPartitaMagSerializer; public class UtilityGson { @@ -24,6 +28,8 @@ public class UtilityGson { return new GsonBuilder() .setDateFormat("dd/MM/yyyy HH:mm:ss") .excludeFieldsWithModifiers(Modifier.TRANSIENT) + .registerTypeAdapter(MutableLiveData.class, new MutableLiveDataDeserializer()) + .registerTypeAdapter(MutableLiveData.class, new MutableLiveDataSerializer()) .registerTypeAdapter(LocalDate.class, new LocalDateDeserializer()) .registerTypeAdapter(LocalDate.class, new LocalDateSerializer()) .registerTypeAdapter(LocalDateTime.class, new LocalDateTimeDeserializer()) diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/accettazione_bolla_picking/AccettazioneBollaPickingActivity.java b/app/src/main/java/it/integry/integrywmsnative/gest/accettazione_bolla_picking/AccettazioneBollaPickingActivity.java index 4d222ef8..68b9b03a 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/accettazione_bolla_picking/AccettazioneBollaPickingActivity.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/accettazione_bolla_picking/AccettazioneBollaPickingActivity.java @@ -98,7 +98,7 @@ public class AccettazioneBollaPickingActivity extends BaseActivity implements Ac public BindableBoolean noLUPresent = new BindableBoolean(true); public BindableBoolean bottomSheetEnabled = new BindableBoolean(false); - private int barcodeScannerIstanceID = -1; + private int mBarcodeScannerInstanceID = -1; private boolean mShowSecondaryUntMis = true; private boolean mShouldCloseActivity; private AccettazioneBollaPickingOrderBy.Enum mCurrentOrderBy; @@ -182,10 +182,10 @@ public class AccettazioneBollaPickingActivity extends BaseActivity implements Ac this.mBindings.bottomSheetLuContent.collapse(); } else if (!noLUPresent.get()) { this.mShouldCloseActivity = true; - BarcodeManager.removeCallback(barcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); this.mViewModel.closeLU(); } else { - BarcodeManager.removeCallback(barcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); super.onBackPressed(); } } @@ -199,7 +199,7 @@ public class AccettazioneBollaPickingActivity extends BaseActivity implements Ac } private void initBarcodeReader() { - barcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessful) .setOnScanFailed(ex -> UtilityExceptions.defaultException(this, ex, false))); } @@ -590,7 +590,7 @@ public class AccettazioneBollaPickingActivity extends BaseActivity implements Ac UtilityExceptions.defaultException(this, ex); } - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } @Override @@ -600,7 +600,7 @@ public class AccettazioneBollaPickingActivity extends BaseActivity implements Ac totalQtaToBeTaken, BigDecimal totalNumCnfToBeTaken, BigDecimal qtaCnfToBeTaken, BigDecimal totalQtaAvailable, BigDecimal totalNumCnfAvailable, BigDecimal qtaCnfAvailable, String partitaMag, LocalDate dataScad, boolean canPartitaMagBeChanged, - boolean canOverflowQuantity, RunnableArgss onComplete) { + boolean canOverflowQuantity, RunnableArgs onComplete) { DialogInputQuantityV2DTO dialogInputQuantityV2DTO = new DialogInputQuantityV2DTO() .setMtbAart(mtbAart) .setInitialNumCnf(initialNumCnf) @@ -625,14 +625,19 @@ public class AccettazioneBollaPickingActivity extends BaseActivity implements Ac if (!mDialogInputQuantityV2View.isVisible()) mDialogInputQuantityV2View .setDialogInputQuantityV2DTO(dialogInputQuantityV2DTO) - .setOnComplete((resultDTO, shouldCloseLU) -> { + .setOnComplete(resultDTO -> { + if(resultDTO.isAborted()) { + this.mViewModel.resetMatchedRows(); + return; + } + PickedQuantityDTO pickedQuantityDTO = new PickedQuantityDTO() .setNumCnf(resultDTO.getNumCnf()) .setQtaCnf(resultDTO.getQtaCnf()) .setQtaTot(resultDTO.getQtaTot()) .setPartitaMag(resultDTO.getPartitaMag()) .setDataScad(resultDTO.getDataScad()); - onComplete.run(pickedQuantityDTO, shouldCloseLU); + onComplete.run(pickedQuantityDTO); }) .setOnAbort(() -> this.mViewModel.resetMatchedRows()) .show(getSupportFragmentManager(), "tag"); diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/accettazione_bolla_picking/AccettazioneBollaPickingViewModel.java b/app/src/main/java/it/integry/integrywmsnative/gest/accettazione_bolla_picking/AccettazioneBollaPickingViewModel.java index 3de5f89c..76e2ee06 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/accettazione_bolla_picking/AccettazioneBollaPickingViewModel.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/accettazione_bolla_picking/AccettazioneBollaPickingViewModel.java @@ -594,14 +594,14 @@ public class AccettazioneBollaPickingViewModel { partitaMag, dataScad, true, - (pickedQuantityDTO, shouldCloseLU) -> { + pickedQuantityDTO -> { this.saveNewRow(pickingObjectDTO, pickedQuantityDTO.getNumCnf(), pickedQuantityDTO.getQtaCnf(), pickedQuantityDTO.getQtaTot(), pickedQuantityDTO.getPartitaMag(), pickedQuantityDTO.getDataScad(), - shouldCloseLU); + pickedQuantityDTO.isShouldCloseLu()); }); } else { this.saveNewRow( @@ -694,7 +694,9 @@ public class AccettazioneBollaPickingViewModel { mtbColrToEdit.getPartitaMag(), mtbColrToEdit.getDataScadPartita(), true, - (pickedQuantityDTO, shouldCloseLU) -> { + pickedQuantityDTO -> { + if(pickedQuantityDTO == null) + return; this.saveEditedRow(mtbColrToEdit, pickedQuantityDTO.getNumCnf(), @@ -702,7 +704,7 @@ public class AccettazioneBollaPickingViewModel { pickedQuantityDTO.getQtaTot(), pickedQuantityDTO.getPartitaMag(), pickedQuantityDTO.getDataScad(), - shouldCloseLU); + pickedQuantityDTO.isShouldCloseLu()); }); } @@ -982,7 +984,7 @@ public class AccettazioneBollaPickingViewModel { String partitaMag, LocalDate dataScad, boolean canPartitaMagBeChanged, - RunnableArgss onComplete) { + RunnableArgs onComplete) { if (this.mListener != null) mListener.onItemDispatched(pickingObjectDTO, mtbAart, initialNumCnf, @@ -1065,7 +1067,7 @@ public class AccettazioneBollaPickingViewModel { LocalDate dataScad, boolean canPartitaMagBeChanged, boolean canOverflowQuantity, - RunnableArgss onComplete); + RunnableArgs onComplete); void onFilterCodMartApplied(String codMartToFilter); diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/accettazione_ordini_picking/AccettazioneOrdiniPickingActivity.java b/app/src/main/java/it/integry/integrywmsnative/gest/accettazione_ordini_picking/AccettazioneOrdiniPickingActivity.java index e8c9e98b..c188c0c4 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/accettazione_ordini_picking/AccettazioneOrdiniPickingActivity.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/accettazione_ordini_picking/AccettazioneOrdiniPickingActivity.java @@ -103,7 +103,7 @@ public class AccettazioneOrdiniPickingActivity extends BaseActivity implements A public BindableBoolean noLUPresent = new BindableBoolean(true); public BindableBoolean bottomSheetEnabled = new BindableBoolean(false); - private int barcodeScannerIstanceID = -1; + private int mBarcodeScannerInstanceID = -1; private List mOrders; private List mSitArts; @@ -306,10 +306,10 @@ public class AccettazioneOrdiniPickingActivity extends BaseActivity implements A this.mBindings.bottomSheetLuContent.collapse(); } else if (!noLUPresent.get()) { this.mShouldCloseActivity = true; - BarcodeManager.removeCallback(barcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); this.mViewModel.closeLU(); } else { - BarcodeManager.removeCallback(barcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); super.onBackPressed(); } } @@ -340,7 +340,7 @@ public class AccettazioneOrdiniPickingActivity extends BaseActivity implements A } private void initBarcodeReader() { - barcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO().setOnScanSuccessful(onScanSuccessful).setOnScanFailed(ex -> UtilityExceptions.defaultException(this, ex, false))); + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO().setOnScanSuccessful(onScanSuccessful).setOnScanFailed(ex -> UtilityExceptions.defaultException(this, ex, false))); } private void initRecyclerView() { @@ -753,7 +753,7 @@ public class AccettazioneOrdiniPickingActivity extends BaseActivity implements A UtilityExceptions.defaultException(this, ex); } - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } @Override @@ -771,17 +771,24 @@ public class AccettazioneOrdiniPickingActivity extends BaseActivity implements A DialogInputQuantityV2DTO dialogInputQuantityV2DTO = new DialogInputQuantityV2DTO().setMtbAart(mtbAart).setInitialNumCnf(initialNumCnf).setInitialQtaCnf(initialQtaCnf).setInitialQtaTot(initialQtaTot).setTotalQtaOrd(totalQtaOrd).setTotalNumCnfOrd(totalNumCnfOrd).setQtaCnfOrd(qtaCnfOrd).setTotalQtaToBeTaken(totalQtaToBeTaken).setTotalNumCnfToBeTaken(totalNumCnfToBeTaken).setQtaCnfToBeTaken(qtaCnfToBeTaken).setTotalQtaAvailable(totalQtaAvailable).setTotalNumCnfAvailable(totalNumCnfAvailable).setQtaCnfAvailable(qtaCnfAvailable).setPartitaMag(partitaMag).setDataScad(dataScad).setCanPartitaMagBeChanged(canPartitaMagBeChanged).setCanLUBeClosed(true).setCanOverflowOrderQuantity(canOverflowQuantity).setCustomArtDescription(customArtDescription); if (!mDialogInputQuantityV2View.isVisible()) - mDialogInputQuantityV2View.setDialogInputQuantityV2DTO(dialogInputQuantityV2DTO).setOnComplete((resultDTO, shouldCloseLU) -> { - PickedQuantityDTO pickedQuantityDTO = new PickedQuantityDTO().setNumCnf(resultDTO.getNumCnf()).setQtaCnf(resultDTO.getQtaCnf()).setQtaTot(resultDTO.getQtaTot()).setPartitaMag(resultDTO.getPartitaMag()).setDataScad(resultDTO.getDataScad()); - onComplete.run(pickedQuantityDTO, shouldCloseLU); - }).setOnAbort(() -> this.mViewModel.resetMatchedRows()).show(getSupportFragmentManager(), "tag"); + mDialogInputQuantityV2View + .setDialogInputQuantityV2DTO(dialogInputQuantityV2DTO).setOnComplete(resultDTO -> { + if (resultDTO == null) { + this.mViewModel.resetMatchedRows(); + return; + } + PickedQuantityDTO pickedQuantityDTO = new PickedQuantityDTO().setNumCnf(resultDTO.getNumCnf()).setQtaCnf(resultDTO.getQtaCnf()).setQtaTot(resultDTO.getQtaTot()).setPartitaMag(resultDTO.getPartitaMag()).setDataScad(resultDTO.getDataScad()); + onComplete.run(pickedQuantityDTO, pickedQuantityDTO.isShouldCloseLu()); + }) + .setOnAbort(() -> this.mViewModel.resetMatchedRows()) + .show(getSupportFragmentManager(), "tag"); } @Override public void onRowSaved() { runOnUiThread(() -> { Snackbar.make(mBindings.getRoot(), R.string.data_saved, Snackbar.LENGTH_SHORT) - .setBackgroundTint(getResources().getColor(R. color. green_500)) + .setBackgroundTint(getResources().getColor(R.color.green_500)) .show(); }); } @@ -828,7 +835,7 @@ public class AccettazioneOrdiniPickingActivity extends BaseActivity implements A runOnUiThread(() -> { noLUPresent.set(false); Snackbar.make(mBindings.getRoot(), R.string.data_saved, Snackbar.LENGTH_SHORT) - .setBackgroundTint(getResources().getColor(R. color. green_500)) + .setBackgroundTint(getResources().getColor(R.color.green_500)) .show(); this.mBottomSheetFragmentLUContentViewModel.setMtbColt(mtbColt); diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/contab_doc_interni/edit_form/DocInterniEditFormActivity.java b/app/src/main/java/it/integry/integrywmsnative/gest/contab_doc_interni/edit_form/DocInterniEditFormActivity.java index 818c5109..50dc8c4e 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/contab_doc_interni/edit_form/DocInterniEditFormActivity.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/contab_doc_interni/edit_form/DocInterniEditFormActivity.java @@ -70,7 +70,7 @@ public class DocInterniEditFormActivity extends BaseActivity implements DocInter DialogInputQuantityV2View dialogInputQuantityV2View; - private int mBarcodeScannerIstanceID; + private int mBarcodeScannerInstanceID; private ActivityContabDocInterniEditBinding binding; public BindableString documentHeader = new BindableString(true); public BindableString documentRifHeader = new BindableString(true); @@ -238,12 +238,12 @@ public class DocInterniEditFormActivity extends BaseActivity implements DocInter } public void manualSearch() { - BarcodeManager.disable(); + BarcodeManager.disable(mBarcodeScannerInstanceID); DialogSimpleInputHelper.makeInputDialog(this, "Ricerca articolo", null, "Cod articolo / Barcode", - barcodeProd -> this.viewModel.loadArticoloByCodMartOrBarcode(barcodeProd), BarcodeManager::enable).show(); + barcodeProd -> this.viewModel.loadArticoloByCodMartOrBarcode(barcodeProd), () -> BarcodeManager.enable(mBarcodeScannerInstanceID)).show(); } @@ -263,7 +263,7 @@ public class DocInterniEditFormActivity extends BaseActivity implements DocInter return; } - mBarcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(this.viewModel::processBarcode) .setOnScanFailed(this::onError)); this.viewModel.fetchDocumentRows(); @@ -271,7 +271,7 @@ public class DocInterniEditFormActivity extends BaseActivity implements DocInter @Override protected void onDestroy() { - BarcodeManager.removeCallback(mBarcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); super.onDestroy(); } @@ -356,7 +356,9 @@ public class DocInterniEditFormActivity extends BaseActivity implements DocInter if (!dialogInputQuantityV2View.isAdded()) dialogInputQuantityV2View.setDialogInputQuantityV2DTO(dialogInputQuantityV2DTO) - .setOnComplete((resultDTO, shouldCloseLU) -> { + .setOnComplete(resultDTO -> { + if(resultDTO == null || resultDTO.isAborted()) return; + this.onLoadingStarted(); this.viewModel.saveRow(row, resultDTO); }) @@ -385,7 +387,7 @@ public class DocInterniEditFormActivity extends BaseActivity implements DocInter @Override public void onBackPressed() { - BarcodeManager.removeCallback(mBarcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); super.onBackPressed(); } diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/inventario/ElencoInventariFragment.java b/app/src/main/java/it/integry/integrywmsnative/gest/inventario/ElencoInventariFragment.java index 948a3540..ab05401b 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/inventario/ElencoInventariFragment.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/inventario/ElencoInventariFragment.java @@ -43,7 +43,7 @@ public class ElencoInventariFragment extends BaseFragment implements ITitledFrag public ObservableField canCreateInventario = new ObservableField<>(false); - private int barcodeScannerIstanceID = -1; + private int mBarcodeScannerInstanceID = -1; public ElencoInventariFragment() { // Required empty public constructor diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/inventario/picking/PickingInventarioActivity.java b/app/src/main/java/it/integry/integrywmsnative/gest/inventario/picking/PickingInventarioActivity.java index 7f65b7a4..aebc883a 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/inventario/picking/PickingInventarioActivity.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/inventario/picking/PickingInventarioActivity.java @@ -61,7 +61,7 @@ public class PickingInventarioActivity extends BaseActivity implements PickingIn private static final String KEY_INVENTARIO = "key_inventario"; private static final String KEY_INVENTARIO_ARTS = "key_inventario_arts"; - private int barcodeScannerIstanceID; + private int mBarcodeScannerInstanceID; //Pass here all external parameters public static void startActivity(Context context, InventarioRoomDTO inventarioRoomDTO, List inventarioArts) { @@ -125,7 +125,7 @@ public class PickingInventarioActivity extends BaseActivity implements PickingIn @Override public void onBackPressed() { - BarcodeManager.removeCallback(barcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); super.onBackPressed(); } @@ -177,7 +177,7 @@ public class PickingInventarioActivity extends BaseActivity implements PickingIn } private void initBarcodeReader() { - barcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessful) .setOnScanFailed(ex -> UtilityExceptions.defaultException(this, ex, false))); } @@ -209,14 +209,14 @@ public class PickingInventarioActivity extends BaseActivity implements PickingIn } public void manualSearch() { - BarcodeManager.disable(); + BarcodeManager.disable(mBarcodeScannerInstanceID); DialogSimpleInputHelper.makeInputDialog(this, "Ricerca articolo", null, "Cod articolo / Barcode", barcodeProd -> - this.mViewModel.loadArticoloByCodMartOrBarcode(barcodeProd, BarcodeManager::enable), - BarcodeManager::enable) + this.mViewModel.loadArticoloByCodMartOrBarcode(barcodeProd, () -> BarcodeManager.enable(mBarcodeScannerInstanceID)), + () -> BarcodeManager.enable(mBarcodeScannerInstanceID)) .show(); } @@ -241,7 +241,9 @@ public class PickingInventarioActivity extends BaseActivity implements PickingIn if (!mDialogInputQuantityV2View.isVisible()) mDialogInputQuantityV2View.setDialogInputQuantityV2DTO(dialogInputQuantityV2DTO) - .setOnComplete((resultDTO, shouldCloseLU) -> { + .setOnComplete(resultDTO -> { + if(resultDTO == null || resultDTO.isAborted()) return; + PickedQuantityDTO pickedQuantityDTO = new PickedQuantityDTO() .setNumCnf(resultDTO.getNumCnf()) .setQtaCnf(resultDTO.getQtaCnf()) @@ -249,7 +251,7 @@ public class PickingInventarioActivity extends BaseActivity implements PickingIn .setPartitaMag(resultDTO.getPartitaMag()) .setDataScad(resultDTO.getDataScad()); - onComplete.run(pickedQuantityDTO, shouldCloseLU); + onComplete.run(pickedQuantityDTO, pickedQuantityDTO.isShouldCloseLu()); }) .show(getSupportFragmentManager(), "tag"); } diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoFragment.java b/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoFragment.java index 0c36446b..ac6fcb84 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoFragment.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoFragment.java @@ -87,7 +87,7 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme private PickingLiberoListAdapter mAdapter; - private int barcodeScannerIstanceID = -1; + private int mBarcodeScannerInstanceID = -1; private GestioneEnum mCurrentGestione; private boolean mAskCliente; @@ -171,11 +171,11 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme } private void initBarcodeReader() { - barcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessful) .setOnScanFailed(ex -> UtilityExceptions.defaultException(getActivity(), ex, false))); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } @@ -206,11 +206,11 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme } private final RunnableArgs onScanSuccessful = data -> { - BarcodeManager.disable(); + BarcodeManager.disable(mBarcodeScannerInstanceID); this.onLoadingStarted(); this.mViewModel.processBarcodeDTO(data, () -> { - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); this.onLoadingEnded(); }); }; @@ -294,7 +294,7 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme UtilityExceptions.defaultException(getActivity(), ex); } - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); }); } @@ -321,7 +321,7 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme DialogChooseArtsFromMtbColrList .newInstance(mtbColrsToPick, mtbAart, onComplete, () -> { onAbort.run(); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); }) .show(requireActivity().getSupportFragmentManager(), DialogChooseArtsFromMtbColrList.class.getName()); } @@ -365,7 +365,12 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme if (!mDialogInputQuantityV2View.isVisible()) mDialogInputQuantityV2View.setDialogInputQuantityV2DTO(dialogInputQuantityV2DTO) - .setOnComplete((resultDTO, shouldCloseLU) -> { + .setOnComplete(resultDTO -> { + if(resultDTO == null || resultDTO.isAborted()) { + this.onLoadingEnded(); + return; + } + PickedQuantityDTO pickedQuantityDTO = new PickedQuantityDTO() .setNumCnf(resultDTO.getNumCnf()) .setQtaCnf(resultDTO.getQtaCnf()) @@ -374,7 +379,7 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme .setDataScad(resultDTO.getDataScad()); this.onLoadingStarted(); - onComplete.run(pickedQuantityDTO, shouldCloseLU); + onComplete.run(pickedQuantityDTO, resultDTO.isShouldCloseLu()); }) .setOnAbort(this::onLoadingEnded) .show(requireActivity().getSupportFragmentManager(), "tag"); @@ -402,7 +407,7 @@ public class PickingLiberoFragment extends BaseFragment implements ITitledFragme @Override public void onPreDestroy(Runnable onComplete) { - BarcodeManager.removeCallback(barcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); if (thereIsAnOpenedUL.get()) mViewModel.closeLU(onComplete); else onComplete.run(); } diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/picking_resi/PickingResiActivity.java b/app/src/main/java/it/integry/integrywmsnative/gest/picking_resi/PickingResiActivity.java index ed13e91d..1acacb2f 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/picking_resi/PickingResiActivity.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/picking_resi/PickingResiActivity.java @@ -79,7 +79,7 @@ public class PickingResiActivity extends BaseActivity implements BottomSheetFrag private String mTitle; private List mDocumentiResiList; - private int barcodeScannerIstanceID = -1; + private int mBarcodeScannerInstanceID = -1; private boolean mShouldCloseActivity; @@ -150,10 +150,10 @@ public class PickingResiActivity extends BaseActivity implements BottomSheetFrag this.mBindings.bottomSheetLuContent.collapse(); } else if (!noLUPresent.get()) { this.mShouldCloseActivity = true; - BarcodeManager.removeCallback(barcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); this.mViewmodel.closeLU(true); } else { - BarcodeManager.removeCallback(barcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); super.onBackPressed(); } } @@ -166,7 +166,7 @@ public class PickingResiActivity extends BaseActivity implements BottomSheetFrag } private void initBarcodeReader() { - barcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessful) .setOnScanFailed(ex -> UtilityExceptions.defaultException(this, ex, false))); } @@ -301,7 +301,7 @@ public class PickingResiActivity extends BaseActivity implements BottomSheetFrag UtilityExceptions.defaultException(this, ex); } - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } @Override @@ -332,7 +332,12 @@ public class PickingResiActivity extends BaseActivity implements BottomSheetFrag if (!mDialogInputQuantityV2View.isVisible()) mDialogInputQuantityV2View .setDialogInputQuantityV2DTO(dialogInputQuantityV2DTO) - .setOnComplete((resultDTO, shouldCloseLU) -> { + .setOnComplete(resultDTO -> { + if(resultDTO == null || resultDTO.isAborted()) { + this.mViewmodel.resetMatchedRows(); + return; + } + PickedQuantityDTO pickedQuantityDTO = new PickedQuantityDTO() .setNumCnf(resultDTO.getNumCnf()) .setQtaCnf(resultDTO.getQtaCnf()) @@ -341,7 +346,7 @@ public class PickingResiActivity extends BaseActivity implements BottomSheetFrag .setDataScad(resultDTO.getDataScad()); this.onLoadingStarted(); - onComplete.run(pickedQuantityDTO, shouldCloseLU); + onComplete.run(pickedQuantityDTO, resultDTO.isShouldCloseLu()); }) .setOnAbort(() -> { this.mViewmodel.resetMatchedRows(); diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/prod_dettaglio_linea/ProdDettaglioLineaActivity.java b/app/src/main/java/it/integry/integrywmsnative/gest/prod_dettaglio_linea/ProdDettaglioLineaActivity.java index 1159deb0..20be0869 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/prod_dettaglio_linea/ProdDettaglioLineaActivity.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/prod_dettaglio_linea/ProdDettaglioLineaActivity.java @@ -56,7 +56,7 @@ public class ProdDettaglioLineaActivity extends BaseActivity implements ProdDett public final BindableString productDescription = new BindableString(); private Runnable onResumeRunnable = null; - private int barcodeScannerIstanceID = -1; + private int mBarcodeScannerInstanceID = -1; @Inject ProdDettaglioLineaViewModel mViewModel; @@ -152,7 +152,7 @@ public class ProdDettaglioLineaActivity extends BaseActivity implements ProdDett @Override public void onSettingsRequest(ProdLineStatusDTO lineaProd) { - BottomSheetLineAction.newInstance(lineaProd, this::requestResources, this::requestOrderChange, this::requestProductionStop, this::requestMaterialRecover, BarcodeManager::enable).show(getSupportFragmentManager(), "BottomSheetLineAction"); + BottomSheetLineAction.newInstance(lineaProd, this::requestResources, this::requestOrderChange, this::requestProductionStop, this::requestMaterialRecover, () -> BarcodeManager.enable(mBarcodeScannerInstanceID)).show(getSupportFragmentManager(), "BottomSheetLineAction"); } @Override @@ -166,7 +166,7 @@ public class ProdDettaglioLineaActivity extends BaseActivity implements ProdDett onConfirm, () -> { onLoadingEnded(); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } ).show(getSupportFragmentManager(), "confirmOrderClose"); }); @@ -196,7 +196,12 @@ public class ProdDettaglioLineaActivity extends BaseActivity implements ProdDett onLoadingEnded(); mDialogInputQuantityV2View .setDialogInputQuantityV2DTO(dialogInputQuantityV2DTO) - .setOnComplete((resultDTO, shouldCloseLU) -> { + .setOnComplete(resultDTO -> { + + if(resultDTO == null || resultDTO.isAborted()) { + this.onLoadingEnded(); + return; + } PickedQuantityDTO pickedQuantityDTO = new PickedQuantityDTO() .setNumCnf(resultDTO.getNumCnf()) @@ -220,17 +225,17 @@ public class ProdDettaglioLineaActivity extends BaseActivity implements ProdDett private void initBarcodeReader() { - barcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessful) .setOnScanFailed(this::onError)); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } public void requestResources() { this.onLoadingEnded(); - BarcodeManager.disable(); + BarcodeManager.disable(mBarcodeScannerInstanceID); this.runOnUiThread(() -> { @@ -242,7 +247,7 @@ public class ProdDettaglioLineaActivity extends BaseActivity implements ProdDett } catch (NumberFormatException ex) { this.onError(new Exception("Inserire un numero di risorse valido")); } - }, BarcodeManager::enable, InputType.TYPE_CLASS_NUMBER).show(); + }, () -> BarcodeManager.enable(mBarcodeScannerInstanceID), InputType.TYPE_CLASS_NUMBER).show(); }); } @@ -257,7 +262,7 @@ public class ProdDettaglioLineaActivity extends BaseActivity implements ProdDett public void requestProductionStop() { this.onLoadingEnded(); - BarcodeManager.disable(); + BarcodeManager.disable(mBarcodeScannerInstanceID); ProdLineStatusDTO lineaProd = mViewModel.getLineaProd(); if (UtilityString.isNullOrEmpty(lineaProd.getListaOrd())) { mViewModel.stopProduction(); @@ -272,7 +277,7 @@ public class ProdDettaglioLineaActivity extends BaseActivity implements ProdDett public void requestMaterialRecover() { this.onLoadingEnded(); - BarcodeManager.disable(); + BarcodeManager.disable(mBarcodeScannerInstanceID); this.runOnUiThread(() -> { getSupportFragmentManager() .beginTransaction() @@ -288,7 +293,7 @@ public class ProdDettaglioLineaActivity extends BaseActivity implements ProdDett @Override public void successDialog(String message, Runnable onComplete) { - BarcodeManager.disable(); + BarcodeManager.disable(mBarcodeScannerInstanceID); this.runOnUiThread(() -> DialogSimpleMessageView.makeSuccessDialog(getResources().getString(R.string.success), new SpannableString(message), null, onComplete).show(getSupportFragmentManager(), "successDialog")); @@ -296,10 +301,9 @@ public class ProdDettaglioLineaActivity extends BaseActivity implements ProdDett } @Override - public void showToast(String message, Runnable onComplete) { + public void showToast(String message) { this.runOnUiThread(() -> { UtilityToast.showToast(message); - onComplete.run(); }); } @@ -332,7 +336,7 @@ public class ProdDettaglioLineaActivity extends BaseActivity implements ProdDett onConfirm ).show(getSupportFragmentManager(), "confirmOrderClose"); }, - BarcodeManager::enable + () -> BarcodeManager.enable(mBarcodeScannerInstanceID) ).show(getSupportFragmentManager(), "confirmOrderClose"); }); } @@ -348,7 +352,7 @@ public class ProdDettaglioLineaActivity extends BaseActivity implements ProdDett if (count > 0) { getSupportFragmentManager().popBackStack(); } else { - BarcodeManager.removeCallback(barcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); super.onBackPressed(); } } diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/prod_dettaglio_linea/ProdDettaglioLineaViewModel.java b/app/src/main/java/it/integry/integrywmsnative/gest/prod_dettaglio_linea/ProdDettaglioLineaViewModel.java index adc601d1..8692cc0a 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/prod_dettaglio_linea/ProdDettaglioLineaViewModel.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/prod_dettaglio_linea/ProdDettaglioLineaViewModel.java @@ -5,7 +5,6 @@ import androidx.lifecycle.MutableLiveData; import javax.inject.Inject; import it.integry.barcode_base_android_library.model.BarcodeScanDTO; -import it.integry.integrywmsnative.core.barcode_reader.BarcodeManager; import it.integry.integrywmsnative.core.exception.NoLUFoundException; import it.integry.integrywmsnative.core.expansion.RunnableArgs; import it.integry.integrywmsnative.core.interfaces.viewmodel_listeners.ILoadingListener; @@ -91,7 +90,7 @@ public class ProdDettaglioLineaViewModel { this.colliMagazzinoRESTConsumer.createColloScaricoDaCarico(mtbColt, posizione, generatedMtbColt -> { this.sendOnLoadingEnded(); - this.mListener.showToast("Versamento completato!", BarcodeManager::enable); + this.mListener.showToast("Versamento completato!"); }, this::sendError); }); }); @@ -221,7 +220,7 @@ public class ProdDettaglioLineaViewModel { void successDialog(String message, Runnable onComplete); - void showToast(String message, Runnable onComplete); + void showToast(String message); void requestQtaVersamento(MtbColr mtbColr, RunnableArgs onComplete); diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/prod_dettaglio_linea/dialogs/DialogRecoverUl.java b/app/src/main/java/it/integry/integrywmsnative/gest/prod_dettaglio_linea/dialogs/DialogRecoverUl.java index 6a1c292a..e21633ed 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/prod_dettaglio_linea/dialogs/DialogRecoverUl.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/prod_dettaglio_linea/dialogs/DialogRecoverUl.java @@ -20,7 +20,7 @@ import it.integry.integrywmsnative.core.utility.UtilityBarcode; import it.integry.integrywmsnative.databinding.DialogStartProductionBinding; public class DialogRecoverUl extends BaseDialogFragment { - private int barcodeScannerIstanceID = -1; + private int mBarcodeScannerInstanceID = -1; private RunnableArgs onScanSuccessful; private DialogStartProductionBinding mBinding; @@ -37,7 +37,7 @@ public class DialogRecoverUl extends BaseDialogFragment { @Override public void onDismiss(@NonNull DialogInterface dialog) { - BarcodeManager.removeCallback(barcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); super.onDismiss(dialog); } @@ -60,10 +60,10 @@ public class DialogRecoverUl extends BaseDialogFragment { private void initBarcodeReader() { - barcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(this::processBarcode) .setOnScanFailed(this::onError)); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } private void processBarcode(BarcodeScanDTO barcodeScanDTO) { diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/prod_dettaglio_linea/dialogs/DialogStartProduction.java b/app/src/main/java/it/integry/integrywmsnative/gest/prod_dettaglio_linea/dialogs/DialogStartProduction.java index 6f2d2eb7..c66a88b3 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/prod_dettaglio_linea/dialogs/DialogStartProduction.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/prod_dettaglio_linea/dialogs/DialogStartProduction.java @@ -21,7 +21,7 @@ import it.integry.integrywmsnative.core.utility.UtilityString; import it.integry.integrywmsnative.databinding.DialogStartProductionBinding; public class DialogStartProduction extends BaseDialogFragment { - private int barcodeScannerIstanceID = -1; + private int mBarcodeScannerInstanceID = -1; private RunnableArgs onScanSuccessful; private DialogStartProductionBinding mBinding; private String title; @@ -57,7 +57,7 @@ public class DialogStartProduction extends BaseDialogFragment { @Override public void onDismiss(@NonNull DialogInterface dialog) { - BarcodeManager.removeCallback(barcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); super.onDismiss(dialog); } @@ -88,10 +88,10 @@ public class DialogStartProduction extends BaseDialogFragment { private void initBarcodeReader() { - barcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(this::processBarcode) .setOnScanFailed(this::onError)); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } private void processBarcode(BarcodeScanDTO barcodeScanDTO) { diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/prod_linee_produzione/ProdLineeProduzioneFragment.java b/app/src/main/java/it/integry/integrywmsnative/gest/prod_linee_produzione/ProdLineeProduzioneFragment.java index b1d20c34..ce06cf2a 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/prod_linee_produzione/ProdLineeProduzioneFragment.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/prod_linee_produzione/ProdLineeProduzioneFragment.java @@ -41,7 +41,7 @@ public class ProdLineeProduzioneFragment extends BaseFragment implements ITitled private final ObservableArrayList mLinesObservableList = new ObservableArrayList<>(); private FragmentLineeProdBinding mBinding; private ElevatedToolbar mToolbar; - private int barcodeScannerIstanceID = -1; + private int mBarcodeScannerInstanceID = -1; public static ProdLineeProduzioneFragment newInstance() { return new ProdLineeProduzioneFragment(); @@ -73,7 +73,7 @@ public class ProdLineeProduzioneFragment extends BaseFragment implements ITitled private void initBarcodeReader() { - barcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessful) .setOnScanFailed(this::onError)); } @@ -112,7 +112,7 @@ public class ProdLineeProduzioneFragment extends BaseFragment implements ITitled public void requestResources(ProdLineStatusDTO prodLine) { this.onLoadingEnded(); - BarcodeManager.disable(); + BarcodeManager.disable(mBarcodeScannerInstanceID); requireActivity().runOnUiThread(() -> { DialogSimpleInputHelper.makeInputDialog(requireContext(), "Inserisci il numero di risorse da allocare", prodLine.getQtaAllocate().toString(), "n. risorse", qta -> { @@ -123,13 +123,13 @@ public class ProdLineeProduzioneFragment extends BaseFragment implements ITitled } catch (NumberFormatException ex) { this.onError(new Exception("Inserire un numero di risorse valido")); } - }, BarcodeManager::enable, InputType.TYPE_CLASS_NUMBER).show(); + }, () -> BarcodeManager.enable(mBarcodeScannerInstanceID), InputType.TYPE_CLASS_NUMBER).show(); }); } @Override public void successDialog(String message, Runnable onComplete) { - BarcodeManager.disable(); + BarcodeManager.disable(mBarcodeScannerInstanceID); requireActivity().runOnUiThread(() -> DialogSimpleMessageView.makeSuccessDialog(getResources().getString(R.string.success), new SpannableString(message), null, onComplete).show(getChildFragmentManager(), "successDialog")); @@ -138,7 +138,7 @@ public class ProdLineeProduzioneFragment extends BaseFragment implements ITitled @Override public void selectLine(ProdLineStatusDTO dto) { this.onLoadingEnded(); - BarcodeManager.disable(); + BarcodeManager.disable(mBarcodeScannerInstanceID); if (!dto.isStarted()) { this.requestResources(dto); diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/prod_linee_produzione/ProdLineeProduzioneViewModel.java b/app/src/main/java/it/integry/integrywmsnative/gest/prod_linee_produzione/ProdLineeProduzioneViewModel.java index 326c8ed2..c4d8fb35 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/prod_linee_produzione/ProdLineeProduzioneViewModel.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/prod_linee_produzione/ProdLineeProduzioneViewModel.java @@ -34,9 +34,9 @@ public class ProdLineeProduzioneViewModel { private void reloadLines() { sendOnLoadingStarted(); - BarcodeManager.disable(); + BarcodeManager.disableLastCallback(); this.productionLinesRESTConsumer.getStatoLinee(SettingsManager.i().getUserSession().getDepo().getCodMdep(), lineeProdList -> { - BarcodeManager.enable(); + BarcodeManager.enableLastCallback(); prodLines.postValue(lineeProdList); this.sendOnLoadingEnded(); }, this::sendError); diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/prod_recupero_materiale/ProdRecuperoMaterialeFragment.java b/app/src/main/java/it/integry/integrywmsnative/gest/prod_recupero_materiale/ProdRecuperoMaterialeFragment.java index 7999621e..2a0eefeb 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/prod_recupero_materiale/ProdRecuperoMaterialeFragment.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/prod_recupero_materiale/ProdRecuperoMaterialeFragment.java @@ -56,7 +56,7 @@ public class ProdRecuperoMaterialeFragment extends BaseFragment implements ITitl private FragmentProdRecuperoMaterialeBinding mBinding; - private int barcodeScannerIstanceID = -1; + private int mBarcodeScannerInstanceID = -1; private String codJfas; private String fragmentResultKeyString; @@ -118,8 +118,8 @@ public class ProdRecuperoMaterialeFragment extends BaseFragment implements ITitl public void onStart() { super.onStart(); this.addOnPreDestroy(() -> { - if (barcodeScannerIstanceID > -1) { - BarcodeManager.removeCallback(barcodeScannerIstanceID); + if (mBarcodeScannerInstanceID > -1) { + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); } }); mViewModel.init(codJfas); @@ -133,11 +133,11 @@ public class ProdRecuperoMaterialeFragment extends BaseFragment implements ITitl private void initBarcodeReader() { - barcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessful) .setOnScanFailed(this::onError)); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } public String getCodJfas() { @@ -248,7 +248,12 @@ public class ProdRecuperoMaterialeFragment extends BaseFragment implements ITitl if (!mDialogInputQuantityV2View.isVisible()) mDialogInputQuantityV2View .setDialogInputQuantityV2DTO(dialogInputQuantityV2DTO) - .setOnComplete((resultDTO, shouldCloseLU) -> { + .setOnComplete(resultDTO -> { + if(resultDTO == null || resultDTO.isAborted()) { + this.onLoadingEnded(); + return; + } + PickedQuantityDTO pickedQuantityDTO = new PickedQuantityDTO() .setNumCnf(resultDTO.getNumCnf()) .setQtaCnf(resultDTO.getQtaCnf()) diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/prod_rientro_merce/ProdRientroMerceFragment.java b/app/src/main/java/it/integry/integrywmsnative/gest/prod_rientro_merce/ProdRientroMerceFragment.java index 372fff5a..9bebfab1 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/prod_rientro_merce/ProdRientroMerceFragment.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/prod_rientro_merce/ProdRientroMerceFragment.java @@ -212,13 +212,13 @@ public class ProdRientroMerceFragment extends BaseFragment implements @Override public void onOrderLoadingStarted() { - BarcodeManager.disable(); + BarcodeManager.disableLastCallback(); this.mProdRientroMerceOrderListFragment.onOrderLoadingStarted(); } @Override public void onOrderLoadingEnded() { - BarcodeManager.enable(); + BarcodeManager.enableLastCallback(); this.mProdRientroMerceOrderListFragment.onOrderLoadingEnded(); } diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/prod_rientro_merce/order_list/ProdRientroMerceOrderListFragment.java b/app/src/main/java/it/integry/integrywmsnative/gest/prod_rientro_merce/order_list/ProdRientroMerceOrderListFragment.java index 3a956920..c64dec63 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/prod_rientro_merce/order_list/ProdRientroMerceOrderListFragment.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/prod_rientro_merce/order_list/ProdRientroMerceOrderListFragment.java @@ -278,7 +278,7 @@ public class ProdRientroMerceOrderListFragment extends Fragment { requireActivity().runOnUiThread(() -> { onOrderLoadingEnded(); UtilityExceptions.defaultException(getActivity(), ex); - BarcodeManager.enable(); + BarcodeManager.enableLastCallback(); }); } diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/prod_riposizionamento_da_prod/ProdRiposizionamentoDaProdFragment.java b/app/src/main/java/it/integry/integrywmsnative/gest/prod_riposizionamento_da_prod/ProdRiposizionamentoDaProdFragment.java index 6c6c50ef..8f7e2ebb 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/prod_riposizionamento_da_prod/ProdRiposizionamentoDaProdFragment.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/prod_riposizionamento_da_prod/ProdRiposizionamentoDaProdFragment.java @@ -55,7 +55,7 @@ public class ProdRiposizionamentoDaProdFragment extends BaseFragment implements private ProdRiposizionamentoDaProdFilterViewModel mFilterViewModel = new ProdRiposizionamentoDaProdFilterViewModel(); private final Handler mHandler = new Handler(); private final int mInterval = 120 * 1000; //2 minuti - private int barcodeScannerIstanceID = -1; + private int mBarcodeScannerInstanceID = -1; private AppCompatTextView mAppBarTitle; private String mTextFilter; @@ -220,7 +220,7 @@ public class ProdRiposizionamentoDaProdFragment extends BaseFragment implements public void onInfoClick(ArtsInGiacenzaDTO item) { try { - BarcodeManager.disable(); + BarcodeManager.disable(mBarcodeScannerInstanceID); DialogInfoGiacenzaView.newInstance(item).show(getChildFragmentManager(), DialogInfoGiacenzaView.class.getName()); } catch (Exception e) { UtilityExceptions.defaultException(this.getContext(), e); @@ -237,11 +237,11 @@ public class ProdRiposizionamentoDaProdFragment extends BaseFragment implements }; private void initBarcodeReader() { - barcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessful) .setOnScanFailed(ex -> UtilityExceptions.defaultException(getActivity(), ex, false))); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } private final RunnableArgs onScanSuccessful = data -> { @@ -310,7 +310,7 @@ public class ProdRiposizionamentoDaProdFragment extends BaseFragment implements @Override public void onDestroy() { - BarcodeManager.removeCallback(barcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); mHandler.removeCallbacks(mRunnable); mViewModel.setListener(null); diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/prod_versamento_materiale/ProdVersamentoMaterialeFragment.java b/app/src/main/java/it/integry/integrywmsnative/gest/prod_versamento_materiale/ProdVersamentoMaterialeFragment.java index fda72b03..a73843a7 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/prod_versamento_materiale/ProdVersamentoMaterialeFragment.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/prod_versamento_materiale/ProdVersamentoMaterialeFragment.java @@ -75,7 +75,7 @@ public class ProdVersamentoMaterialeFragment extends BaseFragment implements Pro public final ObservableField fabVisible = new ObservableField<>(false); - private int barcodeScannerIstanceID = -1; + private int mBarcodeScannerInstanceID = -1; public ProdVersamentoMaterialeFragment() { // Required empty public constructor @@ -193,11 +193,11 @@ public class ProdVersamentoMaterialeFragment extends BaseFragment implements Pro private void initBarcodeReader() { - barcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(mViewModel::processBarcodeDTO) .setOnScanFailed(this::onError)); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } // private void openLU() { @@ -383,7 +383,12 @@ public class ProdVersamentoMaterialeFragment extends BaseFragment implements Pro if (!mDialogInputQuantityV2View.isVisible()) mDialogInputQuantityV2View.setDialogInputQuantityV2DTO(dialogInputQuantityV2DTO) - .setOnComplete((resultDTO, shouldCloseLU) -> { + .setOnComplete(resultDTO -> { + if(resultDTO == null || resultDTO.isAborted()) { + this.onLoadingEnded(); + return; + } + PickedQuantityDTO pickedQuantityDTO = new PickedQuantityDTO() .setNumCnf(resultDTO.getNumCnf()) .setQtaCnf(resultDTO.getQtaCnf()) @@ -392,7 +397,7 @@ public class ProdVersamentoMaterialeFragment extends BaseFragment implements Pro .setDataScad(resultDTO.getDataScad()); this.onLoadingStarted(); - onComplete.run(pickedQuantityDTO, shouldCloseLU); + onComplete.run(pickedQuantityDTO, resultDTO.isShouldCloseLu()); }) .setOnAbort(this::onLoadingEnded) .show(requireActivity().getSupportFragmentManager(), "tag"); diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/pv_ordine_acquisto_edit/PVOrdineAcquistoEditActivity.java b/app/src/main/java/it/integry/integrywmsnative/gest/pv_ordine_acquisto_edit/PVOrdineAcquistoEditActivity.java index e4997378..9c4a655f 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/pv_ordine_acquisto_edit/PVOrdineAcquistoEditActivity.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/pv_ordine_acquisto_edit/PVOrdineAcquistoEditActivity.java @@ -52,7 +52,7 @@ public class PVOrdineAcquistoEditActivity extends BaseActivity implements PVOrdi private static String DATA_KEY_ORDER = "keyOrdine"; private static String DATA_LIST_ARTS = "listArts"; private ActivityPvOrdineAcquistoEditBinding mBinding; - private int barcodeScannerIstanceID; + private int mBarcodeScannerInstanceID; @Inject PVOrdineAcquistoEditViewModel mViewModel; @@ -130,11 +130,11 @@ public class PVOrdineAcquistoEditActivity extends BaseActivity implements PVOrdi } private void initBarcodeReader() { - barcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessful) .setOnScanFailed(this::onError)); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } private void initRecyclerView() { @@ -159,7 +159,7 @@ public class PVOrdineAcquistoEditActivity extends BaseActivity implements PVOrdi private void selectAction(ArticoloOrdine articoloOrdine) { mBinding.closeActivityFab.close(false); - BarcodeManager.disable(); + BarcodeManager.disable(mBarcodeScannerInstanceID); DialogAskActionView.newInstance(articoloOrdine.getDescrizione(), articoloOrdine.getQtaOrd() + " " + articoloOrdine.getUntMis(), @@ -168,8 +168,8 @@ public class PVOrdineAcquistoEditActivity extends BaseActivity implements PVOrdi }), () -> { this.deleteArticolo(articoloOrdine); - BarcodeManager.enable(); - }, BarcodeManager::enable).show(getSupportFragmentManager(), "tag"); + BarcodeManager.enable(mBarcodeScannerInstanceID); + }, () -> BarcodeManager.enable(mBarcodeScannerInstanceID)).show(getSupportFragmentManager(), "tag"); } @@ -234,16 +234,16 @@ public class PVOrdineAcquistoEditActivity extends BaseActivity implements PVOrdi @Override public void onBackPressed() { - BarcodeManager.removeCallback(barcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); super.onBackPressed(); } public void manualSearch() { - BarcodeManager.disable(); + BarcodeManager.disable(mBarcodeScannerInstanceID); DialogSimpleInputHelper.makeInputDialog(this, "Inserisci il codice a barre/codice articolo da cercare", barcode -> { this.onLoadingStarted(); this.mViewModel.processBarcode(barcode); - }, BarcodeManager::enable).show(); + }, () -> BarcodeManager.enable(mBarcodeScannerInstanceID)).show(); } private boolean isOrderNewProdsForced() { diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/pv_ordine_acquisto_edit/PVOrdineAcquistoEditViewModel.java b/app/src/main/java/it/integry/integrywmsnative/gest/pv_ordine_acquisto_edit/PVOrdineAcquistoEditViewModel.java index 351ac62c..1914cf8e 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/pv_ordine_acquisto_edit/PVOrdineAcquistoEditViewModel.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/pv_ordine_acquisto_edit/PVOrdineAcquistoEditViewModel.java @@ -157,8 +157,8 @@ public class PVOrdineAcquistoEditViewModel { } public void processBarcode(String barcode) { - Runnable onComplete = BarcodeManager::enable; - BarcodeManager.disable(); + Runnable onComplete = BarcodeManager::enableLastCallback; + BarcodeManager.disableLastCallback(); try { List listArticoli = findArticoliByBarcode(barcode); diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/pv_ordine_acquisto_edit/dialog/edit_articolo/DialogEditArticoloView.java b/app/src/main/java/it/integry/integrywmsnative/gest/pv_ordine_acquisto_edit/dialog/edit_articolo/DialogEditArticoloView.java index 57b17796..cf501fe4 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/pv_ordine_acquisto_edit/dialog/edit_articolo/DialogEditArticoloView.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/pv_ordine_acquisto_edit/dialog/edit_articolo/DialogEditArticoloView.java @@ -50,7 +50,7 @@ public class DialogEditArticoloView extends BaseDialogFragment implements Dialog private DialogPvEditArticoloBinding mBindings; private boolean mEnableDataCallback = true; - private int barcodeScannerIstanceID; + private int mBarcodeScannerInstanceID; public static DialogEditArticoloView newInstance(ArticoloOrdine articolo, RunnableArgs onComplete, Runnable onAbort) { return new DialogEditArticoloView(articolo, onComplete, onAbort); @@ -117,17 +117,17 @@ public class DialogEditArticoloView extends BaseDialogFragment implements Dialog if (this.mOnAbort != null) { this.mOnAbort.run(); } - BarcodeManager.removeCallback(barcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); super.onDismiss(dialog); } private void initBarcodeReader() { - barcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful((barcodeScanDTO) -> { }) .setOnScanFailed(this::onError)); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } private void initBindings() { diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/pv_ordini_acquisto/PVOrdiniAcquistoGrigliaFragment.java b/app/src/main/java/it/integry/integrywmsnative/gest/pv_ordini_acquisto/PVOrdiniAcquistoGrigliaFragment.java index ff4633f4..92411937 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/pv_ordini_acquisto/PVOrdiniAcquistoGrigliaFragment.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/pv_ordini_acquisto/PVOrdiniAcquistoGrigliaFragment.java @@ -105,7 +105,7 @@ public class PVOrdiniAcquistoGrigliaFragment extends BaseFragment implements ITi } private void init() { - BarcodeManager.enable(); + BarcodeManager.enableLastCallback(); DialogScanGrigliaAcquistoView.newInstance((griglia, listArticoli) -> { if (griglia == null) { ((IPoppableActivity) requireActivity()).pop(); diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/pv_ordini_acquisto/dialogs/DialogScanGrigliaAcquistoView.java b/app/src/main/java/it/integry/integrywmsnative/gest/pv_ordini_acquisto/dialogs/DialogScanGrigliaAcquistoView.java index 048baa31..c312b106 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/pv_ordini_acquisto/dialogs/DialogScanGrigliaAcquistoView.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/pv_ordini_acquisto/dialogs/DialogScanGrigliaAcquistoView.java @@ -36,7 +36,7 @@ import it.integry.integrywmsnative.databinding.DialogScanCodiceGrigliaBinding; public class DialogScanGrigliaAcquistoView extends BaseDialogFragment { private DialogScanCodiceGrigliaBinding mBinding; - private int mBarcodeScannerIstanceID; + private int mBarcodeScannerInstanceID; public boolean canIgnoreGrid; private final RunnableArgss> mOnDialogDismiss; @@ -89,18 +89,18 @@ public class DialogScanGrigliaAcquistoView extends BaseDialogFragment { return; } - BarcodeManager.disable(); + BarcodeManager.disable(mBarcodeScannerInstanceID); RunnableArgs mOnError = exception -> { this.onError(exception); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); }; retrieveArticoli(null, mOnError); } private void initBarcode() { - mBarcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessfull) .setOnScanFailed(this::onError)); @@ -109,18 +109,18 @@ public class DialogScanGrigliaAcquistoView extends BaseDialogFragment { @Override public void onDismiss(@NonNull DialogInterface dialog) { - BarcodeManager.removeCallback(mBarcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); mOnDialogDismiss.run(mGriglia, mListArticoli); super.onDismiss(dialog); } private final RunnableArgs onScanSuccessfull = data -> { - BarcodeManager.disable(); + BarcodeManager.disable(mBarcodeScannerInstanceID); RunnableArgs mOnError = exception -> { this.onError(exception); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); }; retrieveArticoli(data.getStringValue(), mOnError); diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/rettifica_giacenze/RettificaGiacenzeFragment.java b/app/src/main/java/it/integry/integrywmsnative/gest/rettifica_giacenze/RettificaGiacenzeFragment.java index 4c467954..f71df24c 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/rettifica_giacenze/RettificaGiacenzeFragment.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/rettifica_giacenze/RettificaGiacenzeFragment.java @@ -84,7 +84,7 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr private RettificaGiacenzeMainListAdapter mAdapter; - private int barcodeScannerIstanceID = -1; + private int mBarcodeScannerInstanceID = -1; private GestioneEnum mCurrentGestione; public RettificaGiacenzeFragment() { @@ -165,7 +165,7 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr } private void initBarcodeReader() { - barcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessful) .setOnScanFailed(ex -> UtilityExceptions.defaultException(getActivity(), ex, false))); } @@ -370,7 +370,7 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr @Override public void onError(Exception ex) { this.onLoadingEnded(); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); if (ex instanceof InvalidPesoKGException) { UtilityToast.showToast(ex.getMessage()); @@ -425,7 +425,9 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr if (!mDialogInputQuantityV2View.isVisible()) mDialogInputQuantityV2View .setDialogInputQuantityV2DTO(dialogInputQuantityV2DTO) - .setOnComplete((resultDTO, shouldCloseLU) -> { + .setOnComplete(resultDTO -> { + if(resultDTO == null || resultDTO.isAborted()) return; + PickedQuantityDTO pickedQuantityDTO = new PickedQuantityDTO() .setNumCnf(resultDTO.getNumCnf()) .setQtaCnf(resultDTO.getQtaCnf()) @@ -433,7 +435,7 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr .setPartitaMag(resultDTO.getPartitaMag()) .setDataScad(resultDTO.getDataScad()); - onComplete.run(pickedQuantityDTO, shouldCloseLU); + onComplete.run(pickedQuantityDTO, resultDTO.isShouldCloseLu()); }) .show(requireActivity().getSupportFragmentManager(), "tag"); }, () -> { @@ -555,7 +557,7 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr if (mViewModel.getCurrentMtbColt() != null) mViewModel.closeLU(false); else { - BarcodeManager.removeCallback(barcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); onComplete.run(); } } diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/SpedizioneActivity.java b/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/SpedizioneActivity.java index 534b0086..5e9067fe 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/SpedizioneActivity.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/SpedizioneActivity.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; import android.os.Bundle; +import android.os.Handler; import android.text.Html; import android.text.SpannableString; import android.view.Gravity; @@ -13,6 +14,7 @@ import android.widget.Toast; import androidx.appcompat.widget.PopupMenu; import androidx.databinding.DataBindingUtil; import androidx.databinding.ObservableArrayList; +import androidx.lifecycle.MutableLiveData; import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.LinearLayoutManager; @@ -96,21 +98,23 @@ public class SpedizioneActivity extends BaseActivity implements SpedizioneViewMo @Inject DialogInputQuantityV2View mDialogInputQuantityV2View; + @Inject + Handler handler; + private BottomSheetFragmentLUContentViewModel mBottomSheetFragmentLUContentViewModel; private final ObservableArrayList mSpedizioneMutableData = new ObservableArrayList<>(); - public BindableBoolean addExtraItemsEnabled = new BindableBoolean(false); public BindableBoolean noItemsToPick = new BindableBoolean(false); - public BindableBoolean noLUPresent = new BindableBoolean(true); + public MutableLiveData noLUPresent = new MutableLiveData<>(true); public BindableBoolean bottomSheetEnabled = new BindableBoolean(false); private boolean mEnableFakeGiacenza; private boolean mFlagShowCodForn; private boolean mDivideByGrpMerc; private boolean mEnableQuantityReset; - private int barcodeScannerIstanceID = -1; + private int mBarcodeScannerInstanceID = -1; private ArrayList mSitArtOrd; private ArrayList mTestateOrdini; @@ -239,31 +243,36 @@ public class SpedizioneActivity extends BaseActivity implements SpedizioneViewMo @Override public void onBackPressed() { - if (this.mBindings.bottomSheetLuContent.isExpanded()) { this.mBindings.bottomSheetLuContent.collapse(); - } else if (!noLUPresent.get()) { + } else if (!noLUPresent.getValue()) { this.mShouldCloseActivity = true; - BarcodeManager.removeCallback(barcodeScannerIstanceID); - this.mViewmodel.requestCloseLU(true); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); + executorService.execute(() -> { + try { + this.mViewmodel.requestCloseLU(true); + } catch (Exception e) { + onError(e); + } + }); } else { - BarcodeManager.removeCallback(barcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); super.onBackPressed(); } } private void initVars() { - this.noLUPresent.addOnPropertyChangedCallback(() -> { - this.bottomSheetEnabled.set(!this.noLUPresent.get()); + this.noLUPresent.observeForever(newValue -> { + this.bottomSheetEnabled.set(!newValue); }); } private void initBarcodeReader() { - barcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessful) .setOnScanFailed(this::onError)); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } @@ -320,13 +329,19 @@ public class SpedizioneActivity extends BaseActivity implements SpedizioneViewMo this.mBindings.spedizionePickingList.setLayoutManager(new LinearLayoutManager(this)); RunnableArgssss onItemClicked = (clickedItem, refMtbColt, refMtbColr, executeImmediately) -> { - if (!noLUPresent.get() && - ((SettingsManager.iDB().isFlagSpedizioneEnableManualPick() && - clickedItem.getSitArtOrdDTO().isFlagEnablePickManuale()) || - clickedItem.getTempPickData() != null)) { - this.mViewmodel.dispatchOrdineRow(clickedItem, refMtbColt, refMtbColr, - SettingsManager.iDB().isFlagSpedizioneEnableManualPick() && clickedItem.getSitArtOrdDTO().isFlagEnablePickManuale(), executeImmediately); - } + executorService.execute(() -> { + if (!noLUPresent.getValue() && + ((SettingsManager.iDB().isFlagSpedizioneEnableManualPick() && + clickedItem.getSitArtOrdDTO().isFlagEnablePickManuale()) || + clickedItem.getTempPickData() != null)) { + try { + this.mViewmodel.dispatchOrdineRow(clickedItem, refMtbColt, refMtbColr, + SettingsManager.iDB().isFlagSpedizioneEnableManualPick() && clickedItem.getSitArtOrdDTO().isFlagEnablePickManuale(), executeImmediately); + } catch (Exception e) { + onError(e); + } + } + }); }; spedizioneListAdapter.setOnItemClicked(onItemClicked); @@ -709,36 +724,64 @@ public class SpedizioneActivity extends BaseActivity implements SpedizioneViewMo private final RunnableArgs onScanSuccessful = data -> { this.onLoadingStarted(); - this.mViewmodel.processBarcodeDTO(data, () -> { - this.onLoadingEnded(); + executorService.execute(() -> { + try { + this.mViewmodel.processBarcodeDTO(data); + } catch (Exception e) { + onError(e); + } }); + + this.onLoadingEnded(); }; public void addExtraItem() { - DialogScanArtView - .newInstance(!mEnableFakeGiacenza, (status, mtbAart, ean128Model, mtbColr) -> { - if (status == DialogConsts.Results.YES) { - this.mViewmodel.dispatchExtraItem(mtbAart, ean128Model, mtbColr); - } - }, pickMagazzinoAutomaticoPosizione -> { - this.onLoadingStarted(); - this.mViewmodel.executeEmptyMagazzinoAutomaticoRequest(pickMagazzinoAutomaticoPosizione, this::onLoadingEnded); - }) - .show(getSupportFragmentManager(), "tag"); + handler.post(() -> { + DialogScanArtView + .newInstance(!mEnableFakeGiacenza, (status, mtbAart, ean128Model, mtbColr) -> { + if (status == DialogConsts.Results.YES) { + + executorService.execute(() -> { + try { + this.mViewmodel.dispatchExtraItem(mtbAart, ean128Model, mtbColr); + } catch (Exception e) { + onError(e); + } + }); + + } + }, pickMagazzinoAutomaticoPosizione -> { + this.onLoadingStarted(); + + executorService.execute(() -> { + try { + this.mViewmodel.executeEmptyMagazzinoAutomaticoRequest(pickMagazzinoAutomaticoPosizione); + } catch (Exception e) { + onError(e); + } + this.onLoadingEnded(); + }); + }) + .show(getSupportFragmentManager(), "tag"); + }); } public void startManualSearch() { - BarcodeManager.disable(); - DialogSimpleInputHelper.makeInputDialog(this, "Inserisci il codice a barre", codice -> { + handler.post(() -> { + BarcodeManager.disable(mBarcodeScannerInstanceID); + DialogSimpleInputHelper.makeInputDialog(this, "Inserisci il codice a barre", codice -> { - this.onScanSuccessful.run(new BarcodeScanDTO().setStringValue(codice).setType(BarcodeType.CODE128)); - BarcodeManager.enable(); + this.onScanSuccessful.run(new BarcodeScanDTO().setStringValue(codice).setType(BarcodeType.CODE128)); + BarcodeManager.enable(mBarcodeScannerInstanceID); - }, BarcodeManager::enable).show(); + }, () -> BarcodeManager.enable(mBarcodeScannerInstanceID)).show(); + }); } public void removeListFilter() { - this.mViewmodel.resetMatchedRows(); + handler.post(() -> { + this.mViewmodel.resetMatchedRows(); + }); } @@ -747,88 +790,109 @@ public class SpedizioneActivity extends BaseActivity implements SpedizioneViewMo this.onLoadingStarted(); - this.mViewmodel.createNewLU(null, null, () -> { - this.onLoadingEnded(); + executorService.execute(() -> { + try { + this.mViewmodel.createNewLU(null, null); + this.onLoadingEnded(); + } catch (Exception e) { + onError(e); + } }); } public void trackPackaging() { - this.fabPopupMenu.dismiss(); + handler.post(() -> { + this.fabPopupMenu.dismiss(); - DialogTracciamentoImballiView.newInstance(imballiData -> { + DialogTracciamentoImballiView.newInstance(imballiData -> { - if (imballiData != null && !imballiData.isEmpty()) { - DialogAskVettoreView.newInstance(mViewmodel.getDefaultVettore(), vettoreData -> { - mViewmodel.registraImballi(vettoreData, imballiData); - }) - .show(getSupportFragmentManager(), DialogAskVettoreView.class.getName()); - } - }).show(getSupportFragmentManager(), DialogTracciamentoImballiView.class.getName()); + if (imballiData != null && !imballiData.isEmpty()) { + DialogAskVettoreView.newInstance(mViewmodel.getDefaultVettore(), vettoreData -> { + mViewmodel.registraImballi(vettoreData, imballiData); + }) + .show(getSupportFragmentManager(), DialogAskVettoreView.class.getName()); + } + }).show(getSupportFragmentManager(), DialogTracciamentoImballiView.class.getName()); + }); } public void showCreatedUL() { - this.fabPopupMenu.dismiss(); + handler.post(() -> { + this.fabPopupMenu.dismiss(); - ArrayList createdMtbColts = this.mViewmodel.getCreatedMtbColts(); + ArrayList createdMtbColts = this.mViewmodel.getCreatedMtbColts(); - Intent myIntent = ListaBancaliActivity.createIntent(this, createdMtbColts, true, false); - this.startActivityForResult(myIntent, PICK_UL_REQUEST); + Intent myIntent = ListaBancaliActivity.createIntent(this, createdMtbColts, true, false); + this.startActivityForResult(myIntent, PICK_UL_REQUEST); + }); } public void closeOrder() { - this.fabPopupMenu.dismiss(); + handler.post(() -> { + this.fabPopupMenu.dismiss(); - this.mViewmodel.closeOrder(); + this.mViewmodel.closeOrder(); + }); } @Override public void onLUOpened(MtbColt mtbColt) { - this.addExtraItemsEnabled.set(SettingsManager.iDB().isFlagCanAddExtraItemSpedizione()); - noLUPresent.set(false); + handler.post(() -> { + this.addExtraItemsEnabled.set(SettingsManager.iDB().isFlagCanAddExtraItemSpedizione()); + noLUPresent.postValue(false); - Snackbar.make(mBindings.getRoot(), R.string.data_saved, Snackbar.LENGTH_SHORT) - .setBackgroundTint(getResources().getColor(R. color. green_500)) - .show(); + Snackbar.make(mBindings.getRoot(), R.string.data_saved, Snackbar.LENGTH_SHORT) + .setBackgroundTint(getResources().getColor(R.color.green_500)) + .show(); - this.mBottomSheetFragmentLUContentViewModel.setMtbColt(mtbColt); + this.mBottomSheetFragmentLUContentViewModel.setMtbColt(mtbColt); + }); } @Override public void onLUClosed() { - this.addExtraItemsEnabled.set(false); - noLUPresent.set(true); - this.mBottomSheetFragmentLUContentViewModel.setMtbColt(null); + handler.post(() -> { + this.addExtraItemsEnabled.set(false); + noLUPresent.postValue(true); + this.mBottomSheetFragmentLUContentViewModel.setMtbColt(null); - if (this.mShouldCloseActivity) super.onBackPressed(); + if (this.mShouldCloseActivity) super.onBackPressed(); + }); } @Override public void onLUPesoRequired(String codTcol, BigDecimal netWeightKG, BigDecimal grossWeightKG, RunnableArgsss onComplete) { - DialogInputPesoLUView.newInstance(null, new BigDecimal(50), new BigDecimal(55), (newCodTcol, newNetWeight, newGrossWeight) -> { - onComplete.run(newCodTcol, netWeightKG, grossWeightKG); - }) - .show(getSupportFragmentManager(), "tag"); + handler.post(() -> { + DialogInputPesoLUView.newInstance(null, new BigDecimal(50), new BigDecimal(55), (newCodTcol, newNetWeight, newGrossWeight) -> { + onComplete.run(newCodTcol, netWeightKG, grossWeightKG); + }) + .show(getSupportFragmentManager(), "tag"); + }); } @Override public void onLUSuccessullyPrinted() { - Resources res = getResources(); - String errorMessage = res.getText(R.string.alert_print_completed_message).toString(); - DialogSimpleMessageView - .makeSuccessDialog(res.getText(R.string.completed).toString(), new SpannableString(errorMessage), null, null) - .show(getSupportFragmentManager(), "tag"); + handler.post(() -> { + Resources res = getResources(); + String errorMessage = res.getText(R.string.alert_print_completed_message).toString(); + DialogSimpleMessageView + .makeSuccessDialog(res.getText(R.string.completed).toString(), new SpannableString(errorMessage), null, null) + .show(getSupportFragmentManager(), "tag"); + }); } @Override public void onLUPrintRequest(RunnableArgs onComplete) { - DialogYesNoView.newInstance(getString(R.string.action_print), - String.format(getString(R.string.message_print_packing_list), "Packing List"), - result -> { - onComplete.run(result == DialogConsts.Results.YES); - }) - .show(getSupportFragmentManager(), "dialog-print"); + handler.post(() -> { + DialogYesNoView.newInstance(getString(R.string.action_print), + String.format(getString(R.string.message_print_packing_list), "Packing List"), + result -> { + onComplete.run(result == DialogConsts.Results.YES); + }) + .show(getSupportFragmentManager(), "dialog-print"); + }); } @Override @@ -845,41 +909,52 @@ public class SpedizioneActivity extends BaseActivity implements SpedizioneViewMo @Override public void onFilterApplied(String newValue) { - this.mBindings.filteredArtsInListExpandableLayout.expand(true); - this.mBindings.descriptionFilterText.setText(!UtilityString.isNullOrEmpty(newValue) ? newValue : ""); + handler.post(() -> { + this.mBindings.filteredArtsInListExpandableLayout.expand(true); + this.mBindings.descriptionFilterText.setText(!UtilityString.isNullOrEmpty(newValue) ? newValue : ""); + }); } @Override public void onFilterRemoved() { - this.mBindings.filteredArtsInListExpandableLayout.collapse(true); - this.mBindings.descriptionFilterText.setText(""); + handler.post(() -> { + this.mBindings.filteredArtsInListExpandableLayout.collapse(true); + this.mBindings.descriptionFilterText.setText(""); + }); } @Override public void onMtbColrDeleteRequest(RunnableArgs onComplete) { - String text = getResources().getString(R.string.alert_delete_mtb_colr); - DialogSimpleMessageView.makeWarningDialog(new SpannableString(text), - null, - () -> onComplete.run(true), - () -> onComplete.run(false) - ) - .show(getSupportFragmentManager(), "tag"); + handler.post(() -> { + String text = getResources().getString(R.string.alert_delete_mtb_colr); + DialogSimpleMessageView.makeWarningDialog(new SpannableString(text), + null, + () -> onComplete.run(true), + () -> onComplete.run(false) + ) + .show(getSupportFragmentManager(), "tag"); + }); } @Override public void onError(Exception ex, boolean useSnackbar) { - this.onLoadingEnded(); - if (ex instanceof InvalidPesoKGException) { - UtilityToast.showToast(ex.getMessage()); - } else { - if(useSnackbar) - Snackbar.make(mBindings.getRoot(), Objects.requireNonNull(ex.getMessage()), Snackbar.LENGTH_LONG).show(); - else - UtilityExceptions.defaultException(this, ex); - } + handler.post(() -> { - BarcodeManager.enable(); + this.onLoadingEnded(); + + if (ex instanceof InvalidPesoKGException) { + UtilityToast.showToast(ex.getMessage()); + } else { + if (useSnackbar) + Snackbar.make(mBindings.getRoot(), Objects.requireNonNull(ex.getMessage()), Snackbar.LENGTH_LONG).show(); + else + UtilityExceptions.defaultException(this, ex); + } + + BarcodeManager.enable(mBarcodeScannerInstanceID); + + }); } @Override @@ -901,7 +976,8 @@ public class SpedizioneActivity extends BaseActivity implements SpedizioneViewMo LocalDate dataScad, boolean canOverflowOrderQuantity, boolean canPartitaMagBeChanged, - RunnableArgss onComplete) { + RunnableArgs onComplete, + Runnable onAbort) { if (dataScad == null && pickingObjectDTO.getMtbAart().getGgScadPartita() != null && pickingObjectDTO.getMtbAart().getGgScadPartita() > 0) { dataScad = UtilityDate.getNow(); @@ -935,20 +1011,23 @@ public class SpedizioneActivity extends BaseActivity implements SpedizioneViewMo if (!mDialogInputQuantityV2View.isVisible()) mDialogInputQuantityV2View .setDialogInputQuantityV2DTO(dialogInputQuantityV2DTO) - .setOnComplete((resultDTO, shouldCloseLU) -> { + .setOnComplete(resultDTO -> { + if (resultDTO == null || resultDTO.isAborted()) { + onAbort.run(); + return; + } + PickedQuantityDTO pickedQuantityDTO = new PickedQuantityDTO() .setNumCnf(resultDTO.getNumCnf()) .setQtaCnf(resultDTO.getQtaCnf()) .setQtaTot(resultDTO.getQtaTot()) .setPartitaMag(resultDTO.getPartitaMag()) - .setDataScad(resultDTO.getDataScad()); - - this.onLoadingStarted(); - onComplete.run(pickedQuantityDTO, shouldCloseLU); - }) - .setOnAbort(() -> { - this.mViewmodel.resetMatchedRows(); + .setDataScad(resultDTO.getDataScad()) + .setShouldCloseLu(resultDTO.isShouldCloseLu()) + .setNextUlBarcode(resultDTO.getNextUlBarcode()); + onComplete.run(pickedQuantityDTO); }) + .setOnAbort(onAbort) .show(getSupportFragmentManager(), "tag"); else Toast.makeText(this, "Dialog già a video", Toast.LENGTH_LONG).show(); } @@ -1043,8 +1122,8 @@ public class SpedizioneActivity extends BaseActivity implements SpedizioneViewMo } @Override - public void onChooseArtsRequest(List artsList, RunnableArgs> onComplete) { - DialogChooseArtsFromMtbAartListView.newInstance(artsList, onComplete, this::onLoadingEnded) + public void onChooseArtsRequest(List artsList, RunnableArgs> onComplete, Runnable onAbort) { + DialogChooseArtsFromMtbAartListView.newInstance(artsList, onComplete, onAbort) .show(getSupportFragmentManager(), "tag"); } @@ -1057,7 +1136,7 @@ public class SpedizioneActivity extends BaseActivity implements SpedizioneViewMo @Override public void onRowSaved() { Snackbar.make(mBindings.getRoot(), R.string.data_saved, Snackbar.LENGTH_SHORT) - .setBackgroundTint(getResources().getColor(R. color. green_500)) + .setBackgroundTint(getResources().getColor(R.color.green_500)) .show(); } @@ -1073,17 +1152,37 @@ public class SpedizioneActivity extends BaseActivity implements SpedizioneViewMo @Override public void onBottomSheetLUClose() { - this.mViewmodel.requestCloseLU(true); + executorService.execute(() -> { + try { + this.mViewmodel.requestCloseLU(true); + } catch (Exception e) { + onError(e); + } + }); } @Override public void onMtbColrEdit(MtbColr mtbColr) { - this.mViewmodel.dispatchRowEdit(mtbColr); + executorService.execute(() -> { + this.onLoadingStarted(); + try { + this.mViewmodel.dispatchRowEdit(mtbColr); + } catch (Exception e) { + onError(e); + } + this.onLoadingEnded(); + }); } @Override public void onMtbColrDelete(MtbColr mtbColr) { - this.mViewmodel.requestDeleteRow(mtbColr); + executorService.execute(() -> { + try { + this.mViewmodel.requestDeleteRow(mtbColr); + } catch (Exception e) { + onError(e); + } + }); } diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/SpedizioneModule.java b/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/SpedizioneModule.java index e2f150e2..2c0b9f60 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/SpedizioneModule.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/SpedizioneModule.java @@ -1,5 +1,7 @@ package it.integry.integrywmsnative.gest.spedizione; +import java.util.concurrent.ExecutorService; + import dagger.Module; import dagger.Provides; import it.integry.integrywmsnative.core.data_recover.ColliDataRecoverService; @@ -38,7 +40,8 @@ public class SpedizioneModule { ColliLavorazioneRESTConsumer colliLavorazioneRESTConsumer, MagazzinoAutomaticoRESTConsumer magazzinoAutomaticoRESTConsumer, ImballiRESTConsumer imballiRESTConsumer, - MagazzinoRESTConsumer magazzinoRESTConsumer) { + MagazzinoRESTConsumer magazzinoRESTConsumer, + ExecutorService executorService) { return new SpedizioneViewModel(articoloRESTConsumer, barcodeRESTConsumer, colliDataRecoverService, @@ -51,7 +54,8 @@ public class SpedizioneModule { colliLavorazioneRESTConsumer, magazzinoAutomaticoRESTConsumer, imballiRESTConsumer, - magazzinoRESTConsumer); + magazzinoRESTConsumer, + executorService); } } diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/SpedizioneViewModel.java b/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/SpedizioneViewModel.java index e1bc5ec4..1a82be96 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/SpedizioneViewModel.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/SpedizioneViewModel.java @@ -1,5 +1,9 @@ package it.integry.integrywmsnative.gest.spedizione; +import android.os.Handler; +import android.os.Looper; +import android.util.Pair; + import androidx.databinding.ObservableArrayList; import androidx.lifecycle.MutableLiveData; @@ -14,6 +18,9 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; import javax.inject.Inject; @@ -140,9 +147,13 @@ public class SpedizioneViewModel { private final MagazzinoAutomaticoRESTConsumer mMagazzinoAutomaticoRESTConsumer; private final ImballiRESTConsumer mImballiRESTConsumer; + private final ExecutorService executorService; + private ColliScaricoRESTConsumerInterface mColliScaricoRESTConsumer; private MagazzinoRESTConsumer magazzinoRESTConsumer; + private Handler handler = new Handler(Looper.getMainLooper()); + @Inject public SpedizioneViewModel(ArticoloRESTConsumer articoloRESTConsumer, BarcodeRESTConsumer barcodeRESTConsumer, @@ -156,7 +167,8 @@ public class SpedizioneViewModel { ColliLavorazioneRESTConsumer colliLavorazioneRESTConsumer, MagazzinoAutomaticoRESTConsumer mMagazzinoAutomaticoRESTConsumer, ImballiRESTConsumer imballiRESTConsumer, - MagazzinoRESTConsumer magazzinoRESTConsumer) { + MagazzinoRESTConsumer magazzinoRESTConsumer, + ExecutorService executorService) { this.mArticoloRESTConsumer = articoloRESTConsumer; this.mBarcodeRESTConsumer = barcodeRESTConsumer; this.mColliDataRecoverService = colliDataRecoverService; @@ -170,6 +182,7 @@ public class SpedizioneViewModel { this.mMagazzinoAutomaticoRESTConsumer = mMagazzinoAutomaticoRESTConsumer; this.mImballiRESTConsumer = imballiRESTConsumer; this.magazzinoRESTConsumer = magazzinoRESTConsumer; + this.executorService = executorService; } @@ -353,8 +366,23 @@ public class SpedizioneViewModel { if (this.mListener != null) mListener.onChooseArtRequest(mtbAarts, onComplete); } - private void sendChooseArtsRequest(List mtbAarts, RunnableArgs> onComplete) { - if (this.mListener != null) mListener.onChooseArtsRequest(mtbAarts, onComplete); + private List sendChooseArtsRequest(List mtbAarts) { + final CountDownLatch latch = new CountDownLatch(1); + AtomicReference> result = new AtomicReference<>(); + + mListener.onChooseArtsRequest(mtbAarts, data -> { + result.set(data); + latch.countDown(); + }, latch::countDown); + + try { + latch.await(); // Attende che il dialog venga chiuso + return result.get(); + } catch (InterruptedException e) { + this.sendError(e); + } + + return null; } private void sendOnOrderClosed() { @@ -402,39 +430,87 @@ public class SpedizioneViewModel { if (this.mListener != null) mListener.onFilterRemoved(); } - private void sendMtbColrDeleteRequest(RunnableArgs onComplete) { - if (this.mListener != null) mListener.onMtbColrDeleteRequest(onComplete); + private boolean sendMtbColrDeleteRequest() { + final CountDownLatch latch = new CountDownLatch(1); + AtomicReference result = new AtomicReference<>(); + + mListener.onMtbColrDeleteRequest(data -> { + result.set(data); + latch.countDown(); + }); + + try { + latch.await(); // Attende che il dialog venga chiuso + return result.get(); + } catch (InterruptedException e) { + this.sendError(e); + } + + return false; } - private void sendOnFullItemDispatched(PickingObjectDTO pickingObjectDTO, MtbAart mtbAart, BigDecimal initialNumCnf, BigDecimal initialQtaCnf, BigDecimal initialQtaTot, BigDecimal totalQtaOrd, BigDecimal totalNumCnfOrd, BigDecimal qtaCnfOrd, BigDecimal totalQtaToBeTaken, BigDecimal totalNumCnfToBeTaken, BigDecimal qtaCnfToBeTaken, BigDecimal totalQtaAvailable, BigDecimal totalNumCnfAvailable, BigDecimal qtaCnfAvailable, String partitaMag, LocalDate dataScad, boolean canOverflowOrderQuantity, boolean canBatchLotBeChanged, RunnableArgss onComplete) { - if (this.mListener != null) - mListener.onFullItemDispatched(pickingObjectDTO, - mtbAart, - initialNumCnf, - initialQtaCnf, - initialQtaTot, - totalQtaOrd, - totalNumCnfOrd, - qtaCnfOrd, - totalQtaToBeTaken, - totalNumCnfToBeTaken, - qtaCnfToBeTaken, - totalQtaAvailable, - totalNumCnfAvailable, - qtaCnfAvailable, - partitaMag, - dataScad, - canOverflowOrderQuantity, - canBatchLotBeChanged, - onComplete); + private PickedQuantityDTO sendOnFullItemDispatched(PickingObjectDTO pickingObjectDTO, MtbAart mtbAart, BigDecimal initialNumCnf, BigDecimal initialQtaCnf, BigDecimal initialQtaTot, BigDecimal totalQtaOrd, BigDecimal totalNumCnfOrd, BigDecimal qtaCnfOrd, BigDecimal totalQtaToBeTaken, BigDecimal totalNumCnfToBeTaken, BigDecimal qtaCnfToBeTaken, BigDecimal totalQtaAvailable, BigDecimal totalNumCnfAvailable, BigDecimal qtaCnfAvailable, String partitaMag, LocalDate dataScad, boolean canOverflowOrderQuantity, boolean canBatchLotBeChanged) { + + final CountDownLatch latch = new CountDownLatch(1); + AtomicReference result = new AtomicReference<>(); + + mListener.onFullItemDispatched(pickingObjectDTO, + mtbAart, + initialNumCnf, + initialQtaCnf, + initialQtaTot, + totalQtaOrd, + totalNumCnfOrd, + qtaCnfOrd, + totalQtaToBeTaken, + totalNumCnfToBeTaken, + qtaCnfToBeTaken, + totalQtaAvailable, + totalNumCnfAvailable, + qtaCnfAvailable, + partitaMag, + dataScad, + canOverflowOrderQuantity, + canBatchLotBeChanged, + (data) -> { + result.set(data); + latch.countDown(); + }, () -> { + resetMatchedRows(); + latch.countDown(); + }); + + try { + latch.await(); // Attende che il dialog venga chiuso + return result.get(); + } catch (InterruptedException e) { + this.sendError(e); + } + + return null; } private void sendOnRowSaved() { if (this.mListener != null) mListener.onRowSaved(); } - private void sendLUPositionChangeRequest(RunnableArgss onComplete) { - if (this.mListener != null) mListener.onLUPositionChangeRequest(onComplete); + private Pair sendLUPositionChangeRequest() { + + final CountDownLatch latch = new CountDownLatch(1); + AtomicReference> result = new AtomicReference<>(); + + mListener.onLUPositionChangeRequest((status, data) -> { + result.set(new Pair<>(status, data)); + latch.countDown(); + }); + + try { + latch.await(); // Attende che il dialog venga chiuso + return result.get(); + } catch (InterruptedException e) { + this.sendError(e); + } + return null; } private void sendBatchLotSelectionRequest(List availableBatchLots, RunnableArgs onComplete) { @@ -442,282 +518,252 @@ public class SpedizioneViewModel { mListener.onBatchLotSelectionRequest(availableBatchLots, onComplete); } - public void processBarcodeDTO(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) { + public void processBarcodeDTO(BarcodeScanDTO barcodeScanDTO) throws Exception { + //Se non c'è una UL aperta + if (mCurrentMtbColt == null) { - //Se non c'è una UL aperta - if (mCurrentMtbColt == null) { + //Se è un'etichetta anonima + if (UtilityBarcode.isEtichettaAnonima(barcodeScanDTO)) { + //Se il collo non esiste allora lo creo associandolo a questa etichetta anonima + //invece se esiste apro un collo nuovo e cerco gli articoli presenti nell'ul + //dell'etichetta anonima + this.executeEtichettaAnonimaNotOpenedLU(barcodeScanDTO); - //Se è un'etichetta anonima - if (UtilityBarcode.isEtichettaAnonima(barcodeScanDTO)) { - //Se il collo non esiste allora lo creo associandolo a questa etichetta anonima - //invece se esiste apro un collo nuovo e cerco gli articoli presenti nell'ul - //dell'etichetta anonima - this.executeEtichettaAnonimaNotOpenedLU(barcodeScanDTO, onComplete); + } else if (UtilityBarcode.isEtichettaPosizione(barcodeScanDTO)/* && mDefaultSegnoCol == 1*/) { + this.processBarcodePosizioneNotOpenedLU(barcodeScanDTO); - } else if (UtilityBarcode.isEtichettaPosizione(barcodeScanDTO)/* && mDefaultSegnoCol == 1*/) { - this.processBarcodePosizioneNotOpenedLU(barcodeScanDTO, onComplete); + } else { + this.processBarcodeNotOpenedLU(barcodeScanDTO); + } } else { - this.processBarcodeNotOpenedLU(barcodeScanDTO, onComplete); + if (UtilityBarcode.isEtichettaAnonima(barcodeScanDTO)) { + //Cerco gli articoli presenti nell'ul dell'etichetta anonima + this.executeEtichettaLU(barcodeScanDTO.getStringValue()); + + } else { + this.processBarcodeAlreadyOpenedLU(barcodeScanDTO); + } } - } else { - if (UtilityBarcode.isEtichettaAnonima(barcodeScanDTO)) { - //Cerco gli articoli presenti nell'ul dell'etichetta anonima - this.executeEtichettaLU(barcodeScanDTO.getStringValue(), onComplete); - - } else { - this.processBarcodeAlreadyOpenedLU(barcodeScanDTO, onComplete); - } - } } - private void processBarcodePosizioneNotOpenedLU(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) { + private void processBarcodePosizioneNotOpenedLU(BarcodeScanDTO barcodeScanDTO) throws Exception { MtbDepoPosizione foundPosizione = UtilityPosizione.getFromCache(barcodeScanDTO.getStringValue()); if (foundPosizione == null) { //Nessuna posizione trovata con questo barcode - this.sendError(new ScannedPositionNotExistException()); - return; + throw new ScannedPositionNotExistException(); } if (!foundPosizione.isFlagMonoCollo()) { //La posizione non è Mono-UL - this.sendError(new CurrentMonoLUPositionIsNotCorrectException()); - return; + throw new CurrentMonoLUPositionIsNotCorrectException(); } if (foundPosizione.isMagazzinoAutomatico()) { //La posizione è di un magazzino automatico - this.sendError(new InvalidMagazzinoAutomaticoMovementException(foundPosizione)); - return; + throw new InvalidMagazzinoAutomaticoMovementException(foundPosizione); } - this.mPosizioneRESTConsumer.getBancaliInPosizione(foundPosizione, mtbColtList -> { - if (mtbColtList == null || mtbColtList.size() != 1) { - //Nessuna UL trovata oppure più UL nella stessa posizione - this.sendError(new NoLUFoundException()); - return; - } + var mtbColtList = this.mPosizioneRESTConsumer.getBancaliInPosizioneSynchronized(foundPosizione); - mColliMagazzinoRESTConsumer.getByTestata(mtbColtList.get(0), true, false, mtbColt -> { + if (mtbColtList == null || mtbColtList.size() != 1) { + //Nessuna UL trovata oppure più UL nella stessa posizione + throw new NoLUFoundException(); + } - if (mtbColt.getSegno() != mDefaultSegnoCol) { - this.sendError(new InvalidLUException()); - onComplete.run(); - return; - } + var mtbColt = mColliMagazzinoRESTConsumer.getByTestataSynchronized(mtbColtList.get(0), true, false); - //Reset of existant mtbColrs - mtbColt.setMtbColr(new ObservableArrayList<>()); + if (mtbColt.getSegno() != mDefaultSegnoCol) { + throw new InvalidLUException(); + } - this.mCurrentMtbColt = mtbColt; - this.mMtbColtSessionID = this.mColliDataRecoverService.startNewSession(mtbColt, mTestateOrdini); - this.mIsNewLU = false; + //Reset of existant mtbColrs + mtbColt.setMtbColr(new ObservableArrayList<>()); - this.sendLUOpened(mtbColt); - - onComplete.run(); - - }, this::sendError); - }, this::sendError); + this.mCurrentMtbColt = mtbColt; + this.mMtbColtSessionID = this.mColliDataRecoverService.startNewSession(mtbColt, mTestateOrdini); + this.mIsNewLU = false; + this.sendLUOpened(mtbColt); } - private void processBarcodeNotOpenedLU(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) { - this.createNewLU(null, null, () -> processBarcodeAlreadyOpenedLU(barcodeScanDTO, onComplete)); + private void processBarcodeNotOpenedLU(BarcodeScanDTO barcodeScanDTO) throws Exception { + this.createNewLU(null, null); + processBarcodeAlreadyOpenedLU(barcodeScanDTO); } - private void processBarcodeAlreadyOpenedLU(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) { + private void processBarcodeAlreadyOpenedLU(BarcodeScanDTO barcodeScanDTO) throws Exception { if (UtilityBarcode.isEanPeso(barcodeScanDTO)) { //Cerco tramite etichetta ean 128 (che può indicarmi un articolo o una UL) - this.executeEtichettaEanPeso(barcodeScanDTO, onComplete); + this.executeEtichettaEanPeso(barcodeScanDTO); } else if (UtilityBarcode.isEtichettaPosizione(barcodeScanDTO)) { //Cerco l'UL presente all'interno della posizione - this.executeEtichettaPosizione(barcodeScanDTO.getStringValue(), onComplete); + this.executeEtichettaPosizione(barcodeScanDTO.getStringValue()); } else if (UtilityBarcode.isEtichetta128(barcodeScanDTO)) { //Cerco tramite etichetta ean 128 (che può indicarmi un articolo o una UL) - this.executeEtichettaEan128(barcodeScanDTO, onComplete); + this.executeEtichettaEan128(barcodeScanDTO); } else { - this.loadArticolo(barcodeScanDTO.getStringValue(), null, onComplete); + this.loadArticolo(barcodeScanDTO.getStringValue(), null); } } - private void executeEtichettaAnonimaNotOpenedLU(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) { - mColliMagazzinoRESTConsumer.getBySSCC(barcodeScanDTO.getStringValue(), true, false, mtbColt -> { + private void executeEtichettaAnonimaNotOpenedLU(BarcodeScanDTO barcodeScanDTO) throws Exception { + var mtbColt = mColliMagazzinoRESTConsumer.getBySsccSynchronized(barcodeScanDTO.getStringValue(), true, false); - if (mtbColt == null) { - - if (!UtilityBarcode.isEtichettaAnonimaOfCurrentYear(barcodeScanDTO.getStringValue())) { - this.sendError(new NotCurrentYearLUException()); - } else { - int numCollo = -1; - - try { - numCollo = UtilityBarcode.getNumColloFromULAnonima(barcodeScanDTO.getStringValue()); - this.createNewLU(numCollo, CommonConst.Config.DEFAULT_ANONYMOUS_UL_SERIE, onComplete); - } catch (Exception ex) { - this.sendError(ex); - } - } + if (mtbColt == null) { + if (!UtilityBarcode.isEtichettaAnonimaOfCurrentYear(barcodeScanDTO.getStringValue())) { + throw new NotCurrentYearLUException(); } else { - - boolean codMdepIsValid = SettingsManager.iDB().getAvailableCodMdep() - .stream() - .anyMatch(x -> x.getCodMdep().equalsIgnoreCase(mtbColt.getCodMdep())); - - if (codMdepIsValid) { - this.createNewLU(null, null, () -> searchArtFromUL(mtbColt, onComplete)); - } else this.sendError(new InvalidCodMdepException()); - + int numCollo = UtilityBarcode.getNumColloFromULAnonima(barcodeScanDTO.getStringValue()); + this.createNewLU(numCollo, CommonConst.Config.DEFAULT_ANONYMOUS_UL_SERIE); } + } else { - }, this::sendError); + boolean codMdepIsValid = SettingsManager.iDB().getAvailableCodMdep() + .stream() + .anyMatch(x -> x.getCodMdep().equalsIgnoreCase(mtbColt.getCodMdep())); + + if (codMdepIsValid) { + this.createNewLU(null, null); + searchArtFromUL(mtbColt); + } else throw new InvalidCodMdepException(); + + } } - private void executeEtichettaPosizione(String posizione, Runnable onComplete) { + private void executeEtichettaPosizione(String posizione) throws Exception { MtbDepoPosizione foundPosizione = UtilityPosizione.getFromCache(posizione); if (foundPosizione == null) { //Nessuna posizione trovata con questo barcode - this.sendError(new ScannedPositionNotExistException()); - return; + throw new ScannedPositionNotExistException(); } if (!foundPosizione.isFlagMonoCollo()) { //La posizione non è Mono-UL - this.sendError(new CurrentMonoLUPositionIsNotCorrectException()); - return; + throw new CurrentMonoLUPositionIsNotCorrectException(); } if (foundPosizione.isMagazzinoAutomatico()) { //Eseguo picking da magazzino automatico - executeMagazzinoAutomatico(foundPosizione, onComplete); + executeMagazzinoAutomatico(foundPosizione); return; } - this.mPosizioneRESTConsumer.getBancaliInPosizione(foundPosizione, mtbColtList -> { + var mtbColtList = this.mPosizioneRESTConsumer.getBancaliInPosizioneSynchronized(foundPosizione); - if (mtbColtList == null || mtbColtList.size() != 1) { - //Nessuna UL trovata oppure più UL nella stessa posizione - this.sendError(new NoLUFoundException()); - return; - } + if (mtbColtList == null || mtbColtList.size() != 1) { + //Nessuna UL trovata oppure più UL nella stessa posizione + throw new NoLUFoundException(); + } - mColliMagazzinoRESTConsumer.getByTestata(mtbColtList.get(0), true, false, mtbColt -> { - if (mtbColt != null && mtbColt.getMtbColr() != null && !mtbColt.getMtbColr().isEmpty()) { + var mtbColt = mColliMagazzinoRESTConsumer.getByTestataSynchronized(mtbColtList.get(0), true, false); - boolean codMdepIsValid = SettingsManager.iDB().getAvailableCodMdep().stream() - .anyMatch(x -> x.getCodMdep().equalsIgnoreCase(mtbColt.getCodMdep())); + if (mtbColt != null && mtbColt.getMtbColr() != null && !mtbColt.getMtbColr().isEmpty()) { - if (codMdepIsValid) { - this.searchArtFromUL(mtbColt, onComplete); - } else this.sendError(new InvalidCodMdepException()); + boolean codMdepIsValid = SettingsManager.iDB().getAvailableCodMdep().stream() + .anyMatch(x -> x.getCodMdep().equalsIgnoreCase(mtbColt.getCodMdep())); - } else { - this.sendError(new EmptyLUException()); - } + if (codMdepIsValid) { + this.searchArtFromUL(mtbColt); + } else throw new InvalidCodMdepException(); - }, this::sendError); - - }, this::sendError); - - } - - private void executeEtichettaLU(String SSCC, Runnable onComplete) { - mColliMagazzinoRESTConsumer.getBySSCC(SSCC, true, false, mtbColt -> { - - if (mtbColt != null && mtbColt.getMtbColr() != null && !mtbColt.getMtbColr().isEmpty()) { - if (mtbColt.getSegno() != -1) { - - boolean codMdepIsValid = SettingsManager.iDB().getAvailableCodMdep().stream() - .anyMatch(x -> x.getCodMdep().equalsIgnoreCase(mtbColt.getCodMdep())); - - if (codMdepIsValid) { - searchArtFromUL(mtbColt, onComplete); - } else this.sendError(new InvalidCodMdepException()); - - } else { - this.sendError(new InvalidLUException()); - } - } else { - this.sendError(new EmptyLUException()); - } - - }, this::sendError); - } - - - private void executeEtichettaEan128(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) { - mBarcodeRESTConsumer.decodeEan128(barcodeScanDTO, ean128Model -> { - - String barcodeProd = null; - - if (!UtilityString.isNullOrEmpty(ean128Model.Sscc)) barcodeProd = ean128Model.Sscc; - if (!UtilityString.isNullOrEmpty(ean128Model.Gtin)) barcodeProd = ean128Model.Gtin; - if (!UtilityString.isNullOrEmpty(ean128Model.Content)) - barcodeProd = ean128Model.Content; - - - if (!UtilityString.isNullOrEmpty(barcodeProd)) { - - if (!UtilityString.isNullOrEmpty(ean128Model.Sscc)) { - this.executeEtichettaLU(ean128Model.Sscc, onComplete); - - } else { - if(SettingsManager.iDB().isFlagSpedizioneEnableManualPick()) { - PickDataDTO pickDataDTO = PickDataDTO.fromEan128(ean128Model); - this.loadArticolo(barcodeProd, pickDataDTO, onComplete); - - } else { - this.sendError(new NoResultFromBarcodeException(), true); - onComplete.run(); - } - } - } else { - //EAN 128 non completo o comunque mancano i riferimenti al prodotto - onComplete.run(); - } - }, this::sendError); - } - - private void executeEtichettaEanPeso(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) { - - try { - Ean13PesoModel ean13PesoModel = Ean13PesoModel.fromBarcode(barcodeScanDTO.getStringValue()); - - this.loadArticolo(ean13PesoModel.getPrecode(), PickDataDTO.fromEan128(ean13PesoModel.toEan128()), onComplete); - } catch (Exception ex) { - this.sendError(ex); + } else { + throw new EmptyLUException(); } } - private void loadArticolo(String barcodeProd, PickDataDTO pickData, Runnable onComplete) { - this.mArticoloRESTConsumer.searchByBarcode(barcodeProd, mtbAartList -> { + private void executeEtichettaLU(String SSCC) throws Exception { + var mtbColt = mColliMagazzinoRESTConsumer.getBySsccSynchronized(SSCC, true, false); + + if (mtbColt != null && mtbColt.getMtbColr() != null && !mtbColt.getMtbColr().isEmpty()) { + if (mtbColt.getSegno() != -1) { + + boolean codMdepIsValid = SettingsManager.iDB().getAvailableCodMdep().stream() + .anyMatch(x -> x.getCodMdep().equalsIgnoreCase(mtbColt.getCodMdep())); + + if (codMdepIsValid) { + searchArtFromUL(mtbColt); + } else throw new InvalidCodMdepException(); - if (mtbAartList != null && !mtbAartList.isEmpty()) { - if (mtbAartList.size() == 1) { - this.searchArtFromAnag(mtbAartList.get(0), pickData, onComplete); - } else { - this.sendChooseArtRequest(mtbAartList, art -> this.searchArtFromAnag(art, pickData, onComplete)); - } } else { - this.sendError(new NoResultFromBarcodeException(barcodeProd)); + throw new InvalidLUException(); } + } else { + throw new EmptyLUException(); + } - }, this::sendError); } - private void executeMagazzinoAutomatico(MtbDepoPosizione mtbDepoPosizione, Runnable onComplete) { + + private void executeEtichettaEan128(BarcodeScanDTO barcodeScanDTO) throws Exception { + var ean128Model = mBarcodeRESTConsumer.decodeEan128Synchronized(barcodeScanDTO); + + String barcodeProd = null; + + if (!UtilityString.isNullOrEmpty(ean128Model.Sscc)) barcodeProd = ean128Model.Sscc; + if (!UtilityString.isNullOrEmpty(ean128Model.Gtin)) barcodeProd = ean128Model.Gtin; + if (!UtilityString.isNullOrEmpty(ean128Model.Content)) + barcodeProd = ean128Model.Content; + + + if (!UtilityString.isNullOrEmpty(barcodeProd)) { + + if (!UtilityString.isNullOrEmpty(ean128Model.Sscc)) { + this.executeEtichettaLU(ean128Model.Sscc); + + } else { + if (SettingsManager.iDB().isFlagSpedizioneEnableManualPick()) { + PickDataDTO pickDataDTO = PickDataDTO.fromEan128(ean128Model); + this.loadArticolo(barcodeProd, pickDataDTO); + + } else { + throw new NoResultFromBarcodeException(); + } + } + } + } + + private void executeEtichettaEanPeso(BarcodeScanDTO barcodeScanDTO) throws Exception { + Ean13PesoModel ean13PesoModel = Ean13PesoModel.fromBarcode(barcodeScanDTO.getStringValue()); + + this.loadArticolo(ean13PesoModel.getPrecode(), PickDataDTO.fromEan128(ean13PesoModel.toEan128())); + + } + + private void loadArticolo(String barcodeProd, PickDataDTO pickData) throws Exception { + var mtbAartList = this.mArticoloRESTConsumer.searchByBarcodeSynchronized(barcodeProd); + + if (mtbAartList != null && !mtbAartList.isEmpty()) { + if (mtbAartList.size() == 1) { + this.searchArtFromAnag(mtbAartList.get(0), pickData); + } else { + this.sendChooseArtRequest(mtbAartList, art -> { + try { + this.searchArtFromAnag(art, pickData); + } catch (Exception e) { + this.sendError(e); + } + }); + } + } else { + throw new NoResultFromBarcodeException(barcodeProd); + } + + } + + private void executeMagazzinoAutomatico(MtbDepoPosizione mtbDepoPosizione) throws Exception { var magazzinoAutomaticoPickableArts = Objects.requireNonNull(this.mPickingList.getValue()) .stream() .filter(x -> x.getMtbColts().stream() @@ -730,45 +776,45 @@ public class SpedizioneViewModel { .map(PickingObjectDTO::getMtbAart) .collect(Collectors.toList()); - this.sendChooseArtsRequest(mtbAarts, selectedArts -> { - final List orders = this.mTestateOrdini.stream() - .map(x -> new MagazzinoAutomaticoPickOrderRequestDTO(UtilityDate.toLocalDate(x.getDataOrdD()), x.getGestione(), x.getNumOrd()) - .setDataCons(x.getDataConsD() != null ? UtilityDate.toLocalDate(x.getDataConsD()) : null)) - .collect(Collectors.toList()); + var selectedArts = this.sendChooseArtsRequest(mtbAarts); + if (selectedArts == null) return; - final List magazzinoAutomaticoPickItemRequestDTOList = new ArrayList<>(); - for (MtbAart selectedArt : selectedArts) { - final PickingObjectDTO pickingObjectDTO = magazzinoAutomaticoPickableArts.stream() - .filter(x -> x.getMtbAart().getCodMart().equalsIgnoreCase(selectedArt.getCodMart())) - .findFirst() - .orElse(null); + final List orders = this.mTestateOrdini.stream() + .map(x -> new MagazzinoAutomaticoPickOrderRequestDTO(UtilityDate.toLocalDate(x.getDataOrdD()), x.getGestione(), x.getNumOrd()) + .setDataCons(x.getDataConsD() != null ? UtilityDate.toLocalDate(x.getDataConsD()) : null)) + .collect(Collectors.toList()); - if (pickingObjectDTO == null) { - continue; - } + final List magazzinoAutomaticoPickItemRequestDTOList = new ArrayList<>(); + for (MtbAart selectedArt : selectedArts) { + final PickingObjectDTO pickingObjectDTO = magazzinoAutomaticoPickableArts.stream() + .filter(x -> x.getMtbAart().getCodMart().equalsIgnoreCase(selectedArt.getCodMart())) + .findFirst() + .orElse(null); - MagazzinoAutomaticoPickItemRequestDTO itemDto = new MagazzinoAutomaticoPickItemRequestDTO(selectedArt.getCodMart()) - .setQtaTot(pickingObjectDTO.getSitArtOrdDTO().getQtaOrd()) - .setNumCnf(pickingObjectDTO.getSitArtOrdDTO().getNumCnfOrd()) - .setUntMis(selectedArt.getUntMis()); - - magazzinoAutomaticoPickItemRequestDTOList.add(itemDto); + if (pickingObjectDTO == null) { + continue; } + MagazzinoAutomaticoPickItemRequestDTO itemDto = new MagazzinoAutomaticoPickItemRequestDTO(selectedArt.getCodMart()) + .setQtaTot(pickingObjectDTO.getSitArtOrdDTO().getQtaOrd()) + .setNumCnf(pickingObjectDTO.getSitArtOrdDTO().getNumCnfOrd()) + .setUntMis(selectedArt.getUntMis()); - var magazzinoAutomaticoPickRequest = new MagazzinoAutomaticoPickItemsRequestDTO() - .setShouldCreateUDS(true) - .setDefaultGestioneOfNewUDS(mDefaultGestioneOfUL.getText()) - .setOrdersOfNewUDS(orders) - .setItemsToPick(magazzinoAutomaticoPickItemRequestDTOList); + magazzinoAutomaticoPickItemRequestDTOList.add(itemDto); + } - mMagazzinoAutomaticoRESTConsumer.pickItems(mtbDepoPosizione, - magazzinoAutomaticoPickRequest, onComplete, this::sendError); - }); + + var magazzinoAutomaticoPickRequest = new MagazzinoAutomaticoPickItemsRequestDTO() + .setShouldCreateUDS(true) + .setDefaultGestioneOfNewUDS(mDefaultGestioneOfUL.getText()) + .setOrdersOfNewUDS(orders) + .setItemsToPick(magazzinoAutomaticoPickItemRequestDTOList); + + mMagazzinoAutomaticoRESTConsumer.pickItemsSynchronous(mtbDepoPosizione, magazzinoAutomaticoPickRequest); } - public void executeEmptyMagazzinoAutomaticoRequest(MtbDepoPosizione mtbDepoPosizione, Runnable onComplete) { + public void executeEmptyMagazzinoAutomaticoRequest(MtbDepoPosizione mtbDepoPosizione) throws Exception { final List orders = this.mTestateOrdini.stream() .map(x -> new MagazzinoAutomaticoPickOrderRequestDTO(UtilityDate.toLocalDate(x.getDataOrdD()), x.getGestione(), x.getNumOrd()) .setDataCons(UtilityDate.toLocalDate(x.getDataConsD()))) @@ -779,11 +825,10 @@ public class SpedizioneViewModel { .setDefaultGestioneOfNewUDS(mDefaultGestioneOfUL.getText()) .setOrdersOfNewUDS(orders); - mMagazzinoAutomaticoRESTConsumer.pickItems(mtbDepoPosizione, - magazzinoAutomaticoPickRequest, onComplete, this::sendError); + mMagazzinoAutomaticoRESTConsumer.pickItemsSynchronous(mtbDepoPosizione, magazzinoAutomaticoPickRequest); } - private void searchArtFromUL(MtbColt scannedUL, Runnable onComplete) { + private void searchArtFromUL(MtbColt scannedUL) throws Exception { final List pickingList = mPickingList.getValue(); final List matchPickingObject = new ArrayList<>(); @@ -821,7 +866,7 @@ public class SpedizioneViewModel { for (PickingObjectDTO matchedObject : matchPickingObject) { MtbColt cloneMtbColt = (MtbColt) scannedUL.clone(); - ObservableArrayList cloneMtbColrs = (ObservableArrayList) cloneMtbColt.getMtbColr().clone(); + ObservableArrayList cloneMtbColrs = cloneMtbColt.getMtbColr(); cloneMtbColt.getMtbColr().stream() @@ -841,11 +886,10 @@ public class SpedizioneViewModel { this.loadMatchedRows(matchPickingObject); - onComplete.run(); } - private void searchArtFromAnag(MtbAart mtbAart, PickDataDTO pickData, Runnable onComplete) { + private void searchArtFromAnag(MtbAart mtbAart, PickDataDTO pickData) throws Exception { final List pickingList = mPickingList.getValue(); List matchPickingObject = pickingList.stream() @@ -861,13 +905,12 @@ public class SpedizioneViewModel { } this.loadMatchedRows(matchPickingObject); - onComplete.run(); } - private void loadMatchedRows(List matchedRows) { + private void loadMatchedRows(List matchedRows) throws Exception { if (matchedRows == null || matchedRows.isEmpty()) { - this.sendError(new NoArtsFoundException()); + throw new NoArtsFoundException(); } else if (matchedRows.size() == 1) { PickingObjectDTO matchedItem = matchedRows.get(0); @@ -881,6 +924,7 @@ public class SpedizioneViewModel { this.sendFilterApplied(null); this.getPickingList().postValue(pickingList); } else { + MtbColt refMtbColt = matchedItem.getRefMtbColt(); if (matchedItem.getMtbColts() != null && matchedItem.getMtbColts().size() == 1) { refMtbColt = matchedItem.getMtbColts().get(0); @@ -907,7 +951,7 @@ public class SpedizioneViewModel { } - public void dispatchOrdineRow(final PickingObjectDTO pickingObjectDTO, MtbColt refMtbColt, MtbColr refMtbColr, boolean canPartitaMagBeChanged, boolean executeImmediately) { + public void dispatchOrdineRow(final PickingObjectDTO pickingObjectDTO, MtbColt refMtbColt, MtbColr refMtbColr, boolean canPartitaMagBeChanged, boolean executeImmediately) throws Exception { if (pickingObjectDTO.getTempPickData() != null && pickingObjectDTO.getTempPickData().getSourceMtbColt() != null && pickingObjectDTO.getTempPickData().getSourceMtbColt().getMtbColr() != null) { @@ -965,7 +1009,11 @@ public class SpedizioneViewModel { .findFirst() .orElse(null); - dispatchOrdineRowOnPostBatchLotSelection(pickingObjectDTO, refMtbColt, refMtbColr, scannedMtbColr, canPartitaMagBeChanged, executeImmediately); + try { + dispatchOrdineRowOnPostBatchLotSelection(pickingObjectDTO, refMtbColt, refMtbColr, scannedMtbColr, canPartitaMagBeChanged, executeImmediately); + } catch (Exception e) { + this.sendError(e); + } } }); @@ -978,7 +1026,7 @@ public class SpedizioneViewModel { } } - private void dispatchOrdineRowOnPostBatchLotSelection(final PickingObjectDTO pickingObjectDTO, MtbColt refMtbColt, MtbColr refMtbColr, MtbColr scannedMtbColr, boolean canPartitaMagBeChanged, boolean executeImmediately) { + private void dispatchOrdineRowOnPostBatchLotSelection(final PickingObjectDTO pickingObjectDTO, MtbColt refMtbColt, MtbColr refMtbColr, MtbColr scannedMtbColr, boolean canPartitaMagBeChanged, boolean executeImmediately) throws Exception { BigDecimal totalQtaOrd = pickingObjectDTO.getSitArtOrdDTO().getQtaOrd(); BigDecimal totalNumCnfOrd = pickingObjectDTO.getSitArtOrdDTO().getNumCnfOrd(); BigDecimal qtaCnfOrd = pickingObjectDTO.getSitArtOrdDTO().getQtaCnfOrd(); @@ -1108,38 +1156,55 @@ public class SpedizioneViewModel { BigDecimal initialQtaTot = mUseColliPedana ? initialNumCnf.multiply(initialQtaCnf) : mUseQtaOrd ? qtaColDaPrelevare : null; if (executeImmediately) { - this.saveNewRow(pickingObjectDTO, refMtbColt, numCnfDaPrelevare, qtaCnfDaPrelevare, qtaColDaPrelevare, partitaMag, dataScad, false, false); + this.saveNewRow(pickingObjectDTO, + refMtbColt, + numCnfDaPrelevare, + qtaCnfDaPrelevare, + qtaColDaPrelevare, + partitaMag, + dataScad, + false, + false, + null); } else { MtbColt finalRefMtbColt = refMtbColt; - this.onItemDispatched(pickingObjectDTO, pickingObjectDTO.getMtbAart(), initialNumCnf, initialQtaCnf, initialQtaTot, qtaDaEvadere, numCnfDaEvadere, qtaCnfDaEvadere, qtaColDaPrelevare, numCnfDaPrelevare, qtaCnfDaPrelevare, totalQtaAvailable, totalNumCnfAvailable, qtaCnfAvailable, partitaMag, dataScad, mCanOverflowOrderQuantity, canPartitaMagBeChanged, (pickedQuantityDTO, shouldCloseLU) -> { - this.saveNewRow(pickingObjectDTO, finalRefMtbColt, pickedQuantityDTO.getNumCnf(), pickedQuantityDTO.getQtaCnf(), pickedQuantityDTO.getQtaTot(), pickedQuantityDTO.getPartitaMag(), pickedQuantityDTO.getDataScad(), shouldCloseLU, true); - }); - + var pickedQuantityDTO = this.onItemDispatched(pickingObjectDTO, pickingObjectDTO.getMtbAart(), initialNumCnf, initialQtaCnf, initialQtaTot, qtaDaEvadere, numCnfDaEvadere, qtaCnfDaEvadere, qtaColDaPrelevare, numCnfDaPrelevare, qtaCnfDaPrelevare, totalQtaAvailable, totalNumCnfAvailable, qtaCnfAvailable, partitaMag, dataScad, mCanOverflowOrderQuantity, canPartitaMagBeChanged); + if (pickedQuantityDTO == null) return; + this.saveNewRow(pickingObjectDTO, finalRefMtbColt, + pickedQuantityDTO.getNumCnf(), + pickedQuantityDTO.getQtaCnf(), + pickedQuantityDTO.getQtaTot(), + pickedQuantityDTO.getPartitaMag(), + pickedQuantityDTO.getDataScad(), + pickedQuantityDTO.isShouldCloseLu(), true, + pickedQuantityDTO.getNextUlBarcode()); } } - public void onItemDispatched(PickingObjectDTO pickingObjectDTO, MtbAart mtbAart, BigDecimal initialNumCnf, BigDecimal initialQtaCnf, BigDecimal initialQtaTot, BigDecimal totalQtaOrd, BigDecimal totalNumCnfOrd, BigDecimal qtaCnfOrd, BigDecimal totalQtaToBeTaken, BigDecimal totalNumCnfToBeTaken, BigDecimal qtaCnfToBeTaken, BigDecimal totalQtaAvailable, BigDecimal totalNumCnfAvailable, BigDecimal qtaCnfAvailable, String partitaMag, LocalDate dataScad, boolean canOverflowOrderQuantity, boolean canPartitaMagBeChanged, RunnableArgss onComplete) { + public PickedQuantityDTO onItemDispatched(PickingObjectDTO pickingObjectDTO, MtbAart mtbAart, BigDecimal initialNumCnf, BigDecimal initialQtaCnf, BigDecimal initialQtaTot, BigDecimal totalQtaOrd, BigDecimal totalNumCnfOrd, BigDecimal qtaCnfOrd, BigDecimal totalQtaToBeTaken, BigDecimal totalNumCnfToBeTaken, BigDecimal qtaCnfToBeTaken, BigDecimal totalQtaAvailable, BigDecimal totalNumCnfAvailable, BigDecimal qtaCnfAvailable, String partitaMag, LocalDate dataScad, boolean canOverflowOrderQuantity, boolean canPartitaMagBeChanged) throws Exception { + PickedQuantityDTO pickedQuantities = null; + if (SettingsManager.iDB().isNotifyLotStatus() && !UtilityString.isNullOrEmpty(partitaMag)) { - this.loadProductLotStatus(mtbAart.getCodMart(), partitaMag, (status) -> { - pickingObjectDTO.setStatoArticoloDTO(status); - this.sendOnFullItemDispatched(pickingObjectDTO, mtbAart, initialNumCnf, initialQtaCnf, initialQtaTot, totalQtaOrd, totalNumCnfOrd, qtaCnfOrd, totalQtaToBeTaken, totalNumCnfToBeTaken, qtaCnfToBeTaken, totalQtaAvailable, totalNumCnfAvailable, qtaCnfAvailable, partitaMag, dataScad, canOverflowOrderQuantity, canPartitaMagBeChanged, onComplete); - }); + var status = this.loadProductLotStatus(mtbAart.getCodMart(), partitaMag); + pickingObjectDTO.setStatoArticoloDTO(status); + pickedQuantities = this.sendOnFullItemDispatched(pickingObjectDTO, mtbAart, initialNumCnf, initialQtaCnf, initialQtaTot, totalQtaOrd, totalNumCnfOrd, qtaCnfOrd, totalQtaToBeTaken, totalNumCnfToBeTaken, qtaCnfToBeTaken, totalQtaAvailable, totalNumCnfAvailable, qtaCnfAvailable, partitaMag, dataScad, canOverflowOrderQuantity, canPartitaMagBeChanged); + } else { - this.sendOnFullItemDispatched(pickingObjectDTO, mtbAart, initialNumCnf, initialQtaCnf, initialQtaTot, totalQtaOrd, totalNumCnfOrd, qtaCnfOrd, totalQtaToBeTaken, totalNumCnfToBeTaken, qtaCnfToBeTaken, totalQtaAvailable, totalNumCnfAvailable, qtaCnfAvailable, partitaMag, dataScad, canOverflowOrderQuantity, canPartitaMagBeChanged, onComplete); + pickedQuantities = this.sendOnFullItemDispatched(pickingObjectDTO, mtbAart, initialNumCnf, initialQtaCnf, initialQtaTot, totalQtaOrd, totalNumCnfOrd, qtaCnfOrd, totalQtaToBeTaken, totalNumCnfToBeTaken, qtaCnfToBeTaken, totalQtaAvailable, totalNumCnfAvailable, qtaCnfAvailable, partitaMag, dataScad, canOverflowOrderQuantity, canPartitaMagBeChanged); + } - + return pickedQuantities; } - private void loadProductLotStatus(String codMart, String partitaMag, RunnableArgs onComplete) { + private StatoArticoloDTO loadProductLotStatus(String codMart, String partitaMag) throws Exception { this.sendOnLoadingStarted(); - this.mArticoloRESTConsumer.getStatoPartita(codMart, partitaMag, stati -> { - onComplete.run(!stati.isEmpty() ? stati.get(0) : null); - }, this::sendError); + var stati = this.mArticoloRESTConsumer.getStatoPartitaSynchronized(codMart, partitaMag); + return !stati.isEmpty() ? stati.get(0) : null; } - public void dispatchExtraItem(MtbAart mtbAart, Ean128Model ean128Model, MtbColr mtbColrToUse) { + public void dispatchExtraItem(MtbAart mtbAart, Ean128Model ean128Model, MtbColr mtbColrToUse) throws Exception { PickingObjectDTO pickingObjectDTO = new PickingObjectDTO().setMtbAart(mtbAart).setTempPickData(PickDataDTO.fromEan128(ean128Model)); @@ -1238,15 +1303,23 @@ public class SpedizioneViewModel { MtbColt finalRefMtbColt = refMtbColt; - this.onItemDispatched(pickingObjectDTO, pickingObjectDTO.getMtbAart(), initialNumCnf, initialQtaCnf, initialQtaTot, null, null, null, qtaColDaPrelevare, numCnfDaPrelevare, qtaCnfDaPrelevare, totalQtaAvailable, totalNumCnfAvailable, qtaCnfAvailable, partitaMag, dataScad, mCanOverflowOrderQuantity, true, (pickedQuantityDTO, shouldCloseLU) -> { - this.saveNewRow(pickingObjectDTO, finalRefMtbColt, pickedQuantityDTO.getNumCnf(), pickedQuantityDTO.getQtaCnf(), pickedQuantityDTO.getQtaTot(), pickedQuantityDTO.getPartitaMag(), pickedQuantityDTO.getDataScad(), shouldCloseLU, true); - }); + var pickedQuantityDTO = this.onItemDispatched(pickingObjectDTO, pickingObjectDTO.getMtbAart(), initialNumCnf, initialQtaCnf, initialQtaTot, null, null, null, qtaColDaPrelevare, numCnfDaPrelevare, qtaCnfDaPrelevare, totalQtaAvailable, totalNumCnfAvailable, qtaCnfAvailable, partitaMag, dataScad, mCanOverflowOrderQuantity, true); + if (pickedQuantityDTO == null) return; + + this.saveNewRow(pickingObjectDTO, finalRefMtbColt, + pickedQuantityDTO.getNumCnf(), + pickedQuantityDTO.getQtaCnf(), + pickedQuantityDTO.getQtaTot(), + pickedQuantityDTO.getPartitaMag(), + pickedQuantityDTO.getDataScad(), + pickedQuantityDTO.isShouldCloseLu(), + true, + pickedQuantityDTO.getNextUlBarcode()); + } - public void dispatchRowEdit(final MtbColr mtbColrToEdit) { - this.sendOnLoadingStarted(); - + public void dispatchRowEdit(final MtbColr mtbColrToEdit) throws Exception { Optional optionalPickingObjectDTO = this.mPickingList.getValue().stream() .filter(x -> x.getWithdrawMtbColrs().stream().anyMatch(y -> y == mtbColrToEdit)) @@ -1260,114 +1333,115 @@ public class SpedizioneViewModel { PickingObjectDTO finalPickingObjectDTO = pickingObjectDTO; - loadRifULFromMtbColr(mtbColrToEdit, mtbColtRif -> { + var mtbColtRif = loadRifULFromMtbColr(mtbColrToEdit); - BigDecimal totalQtaOrd = null; - BigDecimal totalNumCnfOrd = null; - BigDecimal qtaCnfOrd = null; + BigDecimal totalQtaOrd = null; + BigDecimal totalNumCnfOrd = null; + BigDecimal qtaCnfOrd = null; - BigDecimal numCnfDaEvadere = null; - BigDecimal qtaDaEvadere = null; - BigDecimal qtaCnfDaEvadere = null; + BigDecimal numCnfDaEvadere = null; + BigDecimal qtaDaEvadere = null; + BigDecimal qtaCnfDaEvadere = null; - if (finalPickingObjectDTO != null) { - totalQtaOrd = finalPickingObjectDTO.getSitArtOrdDTO().getQtaOrd(); - totalNumCnfOrd = finalPickingObjectDTO.getSitArtOrdDTO().getNumCnfOrd(); - qtaCnfOrd = finalPickingObjectDTO.getSitArtOrdDTO().getQtaCnfOrd(); + if (finalPickingObjectDTO != null) { + totalQtaOrd = finalPickingObjectDTO.getSitArtOrdDTO().getQtaOrd(); + totalNumCnfOrd = finalPickingObjectDTO.getSitArtOrdDTO().getNumCnfOrd(); + qtaCnfOrd = finalPickingObjectDTO.getSitArtOrdDTO().getQtaCnfOrd(); - AtomicBigDecimal numCnfWithdrawRows = new AtomicBigDecimal(0); - AtomicBigDecimal qtaColWithdrawRows = new AtomicBigDecimal(0); + AtomicBigDecimal numCnfWithdrawRows = new AtomicBigDecimal(0); + AtomicBigDecimal qtaColWithdrawRows = new AtomicBigDecimal(0); - finalPickingObjectDTO.getWithdrawMtbColrs() - .forEach(row -> { - numCnfWithdrawRows.addAndGet(row.getNumCnf()); - qtaColWithdrawRows.addAndGet(row.getQtaCol()); - }); + finalPickingObjectDTO.getWithdrawMtbColrs() + .forEach(row -> { + numCnfWithdrawRows.addAndGet(row.getNumCnf()); + qtaColWithdrawRows.addAndGet(row.getQtaCol()); + }); - numCnfDaEvadere = totalNumCnfOrd.subtract(numCnfWithdrawRows.getBigDecimalValue()).add(mtbColrToEdit.getNumCnf()); - qtaDaEvadere = totalQtaOrd.subtract(qtaColWithdrawRows.getBigDecimalValue()).add(mtbColrToEdit.getQtaCol()); - qtaCnfDaEvadere = mtbColrToEdit.getQtaCnf(); - } + numCnfDaEvadere = totalNumCnfOrd.subtract(numCnfWithdrawRows.getBigDecimalValue()).add(mtbColrToEdit.getNumCnf()); + qtaDaEvadere = totalQtaOrd.subtract(qtaColWithdrawRows.getBigDecimalValue()).add(mtbColrToEdit.getQtaCol()); + qtaCnfDaEvadere = mtbColrToEdit.getQtaCnf(); + } - BigDecimal numCnfDaPrelevare = null; - BigDecimal qtaColDaPrelevare = null; - BigDecimal qtaCnfDaPrelevare = null; + BigDecimal numCnfDaPrelevare = null; + BigDecimal qtaColDaPrelevare = null; + BigDecimal qtaCnfDaPrelevare = null; - BigDecimal totalQtaAvailable = null; - BigDecimal totalNumCnfAvailable = null; - BigDecimal qtaCnfAvailable = null; + BigDecimal totalQtaAvailable = null; + BigDecimal totalNumCnfAvailable = null; + BigDecimal qtaCnfAvailable = null; - String partitaMag = null; - LocalDate dataScad = null; + String partitaMag = null; + LocalDate dataScad = null; - List mtbColrRifs = mtbColtRif != null && mtbColtRif.getMtbColr() != null ? mtbColtRif.getMtbColr() : null; + List mtbColrRifs = mtbColtRif != null && mtbColtRif.getMtbColr() != null ? mtbColtRif.getMtbColr() : null; - MtbColr mtbColrRif = null; + MtbColr mtbColrRif = null; - if (mtbColrRifs != null && !mtbColrRifs.isEmpty()) { - //TODO: Da capire se è necessario controllare anche il cod_jcom - Optional optionalMtbColr = - mtbColrRifs.stream() - .filter(x -> UtilityString.equalsIgnoreCase(x.getCodMart(), mtbColrToEdit.getCodMart()) && - UtilityString.equalsIgnoreCase(x.getCodCol(), mtbColrToEdit.getCodCol()) && - UtilityString.equalsIgnoreCase(x.getCodTagl(), mtbColrToEdit.getCodTagl()) && - UtilityString.equalsIgnoreCase(x.getPartitaMag(), mtbColrToEdit.getPartitaMag())) - .findFirst(); + if (mtbColrRifs != null && !mtbColrRifs.isEmpty()) { + //TODO: Da capire se è necessario controllare anche il cod_jcom + Optional optionalMtbColr = + mtbColrRifs.stream() + .filter(x -> UtilityString.equalsIgnoreCase(x.getCodMart(), mtbColrToEdit.getCodMart()) && + UtilityString.equalsIgnoreCase(x.getCodCol(), mtbColrToEdit.getCodCol()) && + UtilityString.equalsIgnoreCase(x.getCodTagl(), mtbColrToEdit.getCodTagl()) && + UtilityString.equalsIgnoreCase(x.getPartitaMag(), mtbColrToEdit.getPartitaMag())) + .findFirst(); - mtbColrRif = optionalMtbColr.isPresent() ? optionalMtbColr.get() : null; - } + mtbColrRif = optionalMtbColr.isPresent() ? optionalMtbColr.get() : null; + } - if (mtbColrRif != null) { + if (mtbColrRif != null) { - totalQtaAvailable = mtbColrRif.getQtaCol(); - totalNumCnfAvailable = mtbColrRif.getNumCnf(); - qtaCnfAvailable = mtbColrRif.getQtaCnf(); + totalQtaAvailable = mtbColrRif.getQtaCol(); + totalNumCnfAvailable = mtbColrRif.getNumCnf(); + qtaCnfAvailable = mtbColrRif.getQtaCnf(); - totalNumCnfAvailable = totalNumCnfAvailable.add(mtbColrToEdit.getNumCnf()); - totalQtaAvailable = totalQtaAvailable.add(mtbColrToEdit.getQtaCol()); - - } else { - - totalQtaAvailable = mtbColrToEdit.getQtaCol(); - totalNumCnfAvailable = mtbColrToEdit.getNumCnf(); - qtaCnfAvailable = mtbColrToEdit.getQtaCnf(); - - } - - - if (UtilityBigDecimal.lowerThan(numCnfDaPrelevare, BigDecimal.ZERO)) - numCnfDaPrelevare = BigDecimal.ZERO; - - if (UtilityBigDecimal.lowerThan(qtaColDaPrelevare, BigDecimal.ZERO)) - qtaColDaPrelevare = BigDecimal.ZERO; - - - partitaMag = mtbColrToEdit.getPartitaMag(); - dataScad = mtbColrToEdit.getDataScadPartita(); - - this.sendOnLoadingEnded(); - - this.onItemDispatched(finalPickingObjectDTO, mtbColrToEdit.getMtbAart(), mtbColrToEdit.getNumCnf(), mtbColrToEdit.getQtaCnf(), mtbColrToEdit.getQtaCol(), qtaDaEvadere, numCnfDaEvadere, qtaCnfDaEvadere, qtaColDaPrelevare, numCnfDaPrelevare, qtaCnfDaPrelevare, totalQtaAvailable, totalNumCnfAvailable, qtaCnfAvailable, partitaMag, dataScad, mCanOverflowOrderQuantity, false, (pickedQuantityDTO, shouldCloseLU) -> { - this.saveEditedRow(mtbColrToEdit, pickedQuantityDTO.getNumCnf(), pickedQuantityDTO.getQtaCnf(), pickedQuantityDTO.getQtaTot(), pickedQuantityDTO.getPartitaMag(), pickedQuantityDTO.getDataScad(), shouldCloseLU); - }); - }); - } - - private void loadRifULFromMtbColr(MtbColr mtbColr, RunnableArgs onComplete) { - //Se ho dei riferimenti ad una UL devo leggere la QTA ancora disponibile sulla Ul - if (mtbColr != null && !UtilityString.isNullOrEmpty(mtbColr.getGestioneRif()) && !UtilityString.isNullOrEmpty(mtbColr.getSerColloRif()) && !UtilityString.isNullOrEmpty(mtbColr.getDataColloRifS()) && mtbColr.getNumColloRif() != null) { - - mColliMagazzinoRESTConsumer.getByChiaveCollo(mtbColr.getGestioneRifEnum(), mtbColr.getNumColloRif(), mtbColr.getDataColloRifS(), mtbColr.getSerColloRif(), true, false, onComplete, this::sendError); + totalNumCnfAvailable = totalNumCnfAvailable.add(mtbColrToEdit.getNumCnf()); + totalQtaAvailable = totalQtaAvailable.add(mtbColrToEdit.getQtaCol()); } else { - onComplete.run(null); + + totalQtaAvailable = mtbColrToEdit.getQtaCol(); + totalNumCnfAvailable = mtbColrToEdit.getNumCnf(); + qtaCnfAvailable = mtbColrToEdit.getQtaCnf(); + } + + + if (UtilityBigDecimal.lowerThan(numCnfDaPrelevare, BigDecimal.ZERO)) + numCnfDaPrelevare = BigDecimal.ZERO; + + if (UtilityBigDecimal.lowerThan(qtaColDaPrelevare, BigDecimal.ZERO)) + qtaColDaPrelevare = BigDecimal.ZERO; + + + partitaMag = mtbColrToEdit.getPartitaMag(); + dataScad = mtbColrToEdit.getDataScadPartita(); + + var pickedQuantityDTO = this.onItemDispatched(finalPickingObjectDTO, mtbColrToEdit.getMtbAart(), mtbColrToEdit.getNumCnf(), mtbColrToEdit.getQtaCnf(), mtbColrToEdit.getQtaCol(), qtaDaEvadere, numCnfDaEvadere, qtaCnfDaEvadere, qtaColDaPrelevare, numCnfDaPrelevare, qtaCnfDaPrelevare, totalQtaAvailable, totalNumCnfAvailable, qtaCnfAvailable, partitaMag, dataScad, mCanOverflowOrderQuantity, false); + if (pickedQuantityDTO == null) return; + + this.saveEditedRow(mtbColrToEdit, + pickedQuantityDTO.getNumCnf(), + pickedQuantityDTO.getQtaCnf(), + pickedQuantityDTO.getQtaTot(), + pickedQuantityDTO.getPartitaMag(), + pickedQuantityDTO.getDataScad(), + pickedQuantityDTO.isShouldCloseLu()); } - public void createNewLU(Integer customNumCollo, String customSerCollo, Runnable onComplete) { + private MtbColt loadRifULFromMtbColr(MtbColr mtbColr) throws Exception { + //Se ho dei riferimenti ad una UL devo leggere la QTA ancora disponibile sulla Ul + if (mtbColr != null && !UtilityString.isNullOrEmpty(mtbColr.getGestioneRif()) && !UtilityString.isNullOrEmpty(mtbColr.getSerColloRif()) && !UtilityString.isNullOrEmpty(mtbColr.getDataColloRifS()) && mtbColr.getNumColloRif() != null) { + return mColliMagazzinoRESTConsumer.getByChiaveColloSynchronized(mtbColr.getGestioneRifEnum(), mtbColr.getNumColloRif(), mtbColr.getDataColloRifS(), mtbColr.getSerColloRif(), true, false); + } + return null; + } + + public void createNewLU(Integer customNumCollo, String customSerCollo) throws Exception { int causaleCollo = 0; if (mDefaultGestioneOfUL == GestioneEnum.LAVORAZIONE && mDefaultSegnoCol == +1) causaleCollo = 1; @@ -1388,19 +1462,18 @@ public class SpedizioneViewModel { .setCausaleCollo(causaleCollo) .setOrders(orders); - this.mColliScaricoRESTConsumer.createUDS(createUDSRequestDTO, createdUDS -> { - mMtbColtSessionID = this.mColliDataRecoverService.startNewSession(createdUDS, mTestateOrdini); + var createdUDS = this.mColliScaricoRESTConsumer.createUDSSynchronized(createUDSRequestDTO); - this.mCurrentMtbColt = createdUDS; - this.mCurrentMtbColt.setRagSocCliente(mDefaultRagSocOfUL); - this.mIsNewLU = true; + mMtbColtSessionID = this.mColliDataRecoverService.startNewSession(createdUDS, mTestateOrdini); - if (onComplete != null) onComplete.run(); - this.sendLUOpened(createdUDS); - }, this::sendError); + this.mCurrentMtbColt = createdUDS; + this.mCurrentMtbColt.setRagSocCliente(mDefaultRagSocOfUL); + this.mIsNewLU = true; + + this.sendLUOpened(createdUDS); } - public void saveNewRow(PickingObjectDTO pickingObjectDTO, MtbColt refMtbColt, BigDecimal numCnf, BigDecimal qtaCnf, BigDecimal qtaTot, String partitaMag, LocalDate dataScad, boolean shouldCloseLU, boolean removeFilters) { + public void saveNewRow(PickingObjectDTO pickingObjectDTO, MtbColt refMtbColt, BigDecimal numCnf, BigDecimal qtaCnf, BigDecimal qtaTot, String partitaMag, LocalDate dataScad, boolean shouldCloseLU, boolean removeFilters, BarcodeScanDTO nextUlBarcode) throws Exception { this.sendOnLoadingStarted(); //TODO: Al posto di prelevare la prima riga bisognerebbe controllare se c'è ne una che corrisponde con la partita richiesta @@ -1444,89 +1517,97 @@ public class SpedizioneViewModel { insertUDSRowRequestDto .setDataScad(dataScad); - executeDepositChangeIfNeeded(refMtbColt, - () -> executeTipoUlChangeIfNeeded(refMtbColt, - () -> this.mColliScaricoRESTConsumer.insertUDSRow(insertUDSRowRequestDto, createdMtbColr -> { - pickingObjectDTO.getWithdrawMtbColrs().add(createdMtbColr); - this.mCurrentMtbColt.getMtbColr().add(createdMtbColr); + MtbColr createdMtbColr = null; + try { + executeDepositChangeIfNeeded(refMtbColt); + executeTipoUlChangeIfNeeded(refMtbColt); - createdMtbColr - .setUntMis(pickingObjectDTO.getMtbAart().getUntMis()) - .setMtbAart(pickingObjectDTO.getMtbAart()); + createdMtbColr = this.mColliScaricoRESTConsumer.insertUDSRowSynchronized(insertUDSRowRequestDto); + } catch (Exception ex) { + this.sendError(ex); + } + + pickingObjectDTO.getWithdrawMtbColrs().add(createdMtbColr); + this.mCurrentMtbColt.getMtbColr().add(createdMtbColr); + + createdMtbColr + .setUntMis(pickingObjectDTO.getMtbAart().getUntMis()) + .setMtbAart(pickingObjectDTO.getMtbAart()); - if (mEnableGiacenza) { - MtbColr refMtbColr = new MtbColr() - .setCodMart(createdMtbColr.getCodMart()) - .setPartitaMag(createdMtbColr.getPartitaMag()) - .setCodTagl(createdMtbColr.getCodTagl()) - .setCodCol(createdMtbColr.getCodCol()); + if (mEnableGiacenza) { + MtbColr refMtbColr = new MtbColr() + .setCodMart(createdMtbColr.getCodMart()) + .setPartitaMag(createdMtbColr.getPartitaMag()) + .setCodTagl(createdMtbColr.getCodTagl()) + .setCodCol(createdMtbColr.getCodCol()); - if (refMtbColt != null) { + if (refMtbColt != null) { - MtbColr originalRefMtbColr = refMtbColt.getMtbColr() != null && !refMtbColt.getMtbColr().isEmpty() ? refMtbColt.getMtbColr().get(0) : null; + MtbColr originalRefMtbColr = refMtbColt.getMtbColr() != null && !refMtbColt.getMtbColr().isEmpty() ? refMtbColt.getMtbColr().get(0) : null; - if (originalRefMtbColr != null) { - refMtbColr.setId(originalRefMtbColr.getId()); - } + if (originalRefMtbColr != null) { + refMtbColr.setId(originalRefMtbColr.getId()); + } - refMtbColr.setNumCollo(refMtbColt.getNumCollo()) - .setDataCollo(refMtbColt.getDataColloS()) - .setSerCollo(refMtbColt.getSerCollo()) - .setGestione(refMtbColt.getGestione()); - } - createdMtbColr.setRefMtbColr(refMtbColr); - } + refMtbColr.setNumCollo(refMtbColt.getNumCollo()) + .setDataCollo(refMtbColt.getDataColloS()) + .setSerCollo(refMtbColt.getSerCollo()) + .setGestione(refMtbColt.getGestione()); + } + createdMtbColr.setRefMtbColr(refMtbColr); + } - //Chiamato removeListFilter perché cosi mi cancella tutti i dati di pick temporanei - if (removeFilters) - resetMatchedRows(); - else - //Refresh della lista forzato - this.mPickingList.postValue(this.mPickingList.getValue()); + //Chiamato removeListFilter perché cosi mi cancella tutti i dati di pick temporanei + if (removeFilters) + resetMatchedRows(); + else + //Refresh della lista forzato + this.mPickingList.postValue(this.mPickingList.getValue()); - this.sendOnRowSaved(); - this.sendOnLoadingEnded(); + this.sendOnRowSaved(); + this.sendOnLoadingEnded(); - if (shouldCloseLU) requestCloseLU(shouldPrint); - - }, this::sendError))); + if (shouldCloseLU) { + requestCloseLU(shouldPrint); + if (nextUlBarcode != null) { + processBarcodeDTO(nextUlBarcode); + } + } } - private void executeDepositChangeIfNeeded(MtbColt refMtbColt, Runnable onComplete) { + private void executeDepositChangeIfNeeded(MtbColt refMtbColt) throws Exception { //Considero solo la prima UDC scansionata boolean shouldChangeCodMdep = refMtbColt != null && !refMtbColt.getCodMdep().equalsIgnoreCase(mCurrentMtbColt.getCodMdep()) && mCurrentMtbColt.getMtbColr().isEmpty(); String newCodMdep = shouldChangeCodMdep ? refMtbColt.getCodMdep() : null; if (shouldChangeCodMdep) { - mColliMagazzinoRESTConsumer.spostaUL(mCurrentMtbColt, newCodMdep, null, false, () -> { - mCurrentMtbColt.setCodMdep(newCodMdep); - onComplete.run(); - }, this::sendError); - } else onComplete.run(); + mColliMagazzinoRESTConsumer.spostaUlSynchronized(mCurrentMtbColt, newCodMdep, null, false); + mCurrentMtbColt.setCodMdep(newCodMdep); + } } - private void executeTipoUlChangeIfNeeded(MtbColt refMtbColt, Runnable onComplete) { + private void executeTipoUlChangeIfNeeded(MtbColt refMtbColt) throws Exception { boolean shouldChangeCodTcol = refMtbColt != null && refMtbColt.getCodTcol() != null && !refMtbColt.getCodTcol().equalsIgnoreCase(mCurrentMtbColt.getCodTcol()) && mCurrentMtbColt.getMtbColr().isEmpty(); String newTipoUL = shouldChangeCodTcol ? refMtbColt.getCodTcol() : null; - ObservableMtbTcol newMtbTcol = SettingsManager.iDB().getInternalImballi().stream().filter(x -> x.getCodTcol().equalsIgnoreCase(newTipoUL)) + ObservableMtbTcol newMtbTcol = SettingsManager.iDB().getInternalImballi().stream() + .filter(x -> x.getCodTcol().equalsIgnoreCase(newTipoUL)) .findFirst() .orElse(null); - if(!UtilityString.isNullOrEmpty(newTipoUL) && newMtbTcol == null) { - this.sendError(new Exception("Impossibile riconoscere il tipo UL " + newTipoUL)); - onComplete.run(); - return; + if (!UtilityString.isNullOrEmpty(newTipoUL) && newMtbTcol == null) { + throw new Exception("Impossibile riconoscere il tipo UL " + newTipoUL); } if (shouldChangeCodTcol && newMtbTcol != null) { - updateTipoUl(newMtbTcol, onComplete); - } else onComplete.run(); + mColliMagazzinoRESTConsumer.updateTipoULSynchronized(mCurrentMtbColt, newMtbTcol.getCodTcol()); + mCurrentMtbColt.setCodTcol(newMtbTcol.getCodTcol()); + } } public void updateTipoUl(ObservableMtbTcol newTipoUL, Runnable onComplete) { @@ -1536,8 +1617,7 @@ public class SpedizioneViewModel { }, this::sendError); } - private void saveEditedRow(MtbColr mtbColrToUpdate, BigDecimal numCnf, BigDecimal qtaCnf, BigDecimal qtaTot, String partitaMag, LocalDate dataScad, boolean shouldCloseLU) { - + private void saveEditedRow(MtbColr mtbColrToUpdate, BigDecimal numCnf, BigDecimal qtaCnf, BigDecimal qtaTot, String partitaMag, LocalDate dataScad, boolean shouldCloseLU) throws Exception { this.sendOnLoadingStarted(); MtbColr mtbColrClone = (MtbColr) mtbColrToUpdate.clone(); @@ -1550,121 +1630,195 @@ public class SpedizioneViewModel { .setNewQtaCnf(qtaCnf) .setNewQtaTot(qtaTot); - this.mColliScaricoRESTConsumer.editUDSRow(editUDSRowRequest, savedMtbColr -> { - mtbColrToUpdate.setNumCnf(savedMtbColr.getNumCnf()) - .setQtaCnf(savedMtbColr.getQtaCnf()) - .setQtaCol(savedMtbColr.getQtaCol()); + var savedMtbColr = this.mColliScaricoRESTConsumer.editUDSRowSynchronized(editUDSRowRequest); - Optional pickingObjectDTO = this.mPickingList.getValue().stream() - .filter(x -> x.getWithdrawMtbColrs().stream() - .anyMatch(y -> y == mtbColrToUpdate)) - .findFirst(); + mtbColrToUpdate.setNumCnf(savedMtbColr.getNumCnf()) + .setQtaCnf(savedMtbColr.getQtaCnf()) + .setQtaCol(savedMtbColr.getQtaCol()); - if (pickingObjectDTO.isPresent()) { - pickingObjectDTO.get().getWithdrawMtbColrs().remove(mtbColrToUpdate); - pickingObjectDTO.get().getWithdrawMtbColrs().add(mtbColrToUpdate); - } + Optional pickingObjectDTO = this.mPickingList.getValue().stream() + .filter(x -> x.getWithdrawMtbColrs().stream() + .anyMatch(y -> y == mtbColrToUpdate)) + .findFirst(); - this.mCurrentMtbColt.getMtbColr().remove(mtbColrToUpdate); - this.mCurrentMtbColt.getMtbColr().add(mtbColrToUpdate); + if (pickingObjectDTO.isPresent()) { + pickingObjectDTO.get().getWithdrawMtbColrs().remove(mtbColrToUpdate); + pickingObjectDTO.get().getWithdrawMtbColrs().add(mtbColrToUpdate); + } - this.resetMatchedRows(); - this.sendOnRowSaved(); - this.sendOnLoadingEnded(); - }, this::sendError); + this.mCurrentMtbColt.getMtbColr().remove(mtbColrToUpdate); + this.mCurrentMtbColt.getMtbColr().add(mtbColrToUpdate); + + this.resetMatchedRows(); + this.sendOnRowSaved(); + this.sendOnLoadingEnded(); } - public void requestDeleteRow(MtbColr mtbColrToDelete) { - this.sendMtbColrDeleteRequest(canDelete -> { - if (!canDelete) - return; + public void requestDeleteRow(MtbColr mtbColrToDelete) throws Exception { + var canDelete = this.sendMtbColrDeleteRequest(); + if (!canDelete) + return; - this.sendOnLoadingStarted(); + this.sendOnLoadingStarted(); - var deleteUDSRowRequestoDTO = new DeleteUDSRowRequestDTO() - .setMtbColrToDelete(mtbColrToDelete); + var deleteUDSRowRequestoDTO = new DeleteUDSRowRequestDTO() + .setMtbColrToDelete(mtbColrToDelete); - this.mColliScaricoRESTConsumer.deleteUDSRow(deleteUDSRowRequestoDTO, () -> { - Optional pickingObjectDTO = this.mPickingList.getValue().stream() - .filter(x -> x.getWithdrawMtbColrs().stream().anyMatch(y -> y == mtbColrToDelete)) - .findFirst(); + this.mColliScaricoRESTConsumer.deleteUDSRowSynchronized(deleteUDSRowRequestoDTO); - if (pickingObjectDTO.isPresent()) { - pickingObjectDTO.get().getWithdrawMtbColrs().remove(mtbColrToDelete); - } + Optional pickingObjectDTO = this.mPickingList.getValue().stream() + .filter(x -> x.getWithdrawMtbColrs().stream().anyMatch(y -> y == mtbColrToDelete)) + .findFirst(); - this.mCurrentMtbColt.getMtbColr().remove(mtbColrToDelete); + if (pickingObjectDTO.isPresent()) { + pickingObjectDTO.get().getWithdrawMtbColrs().remove(mtbColrToDelete); + } - this.resetMatchedRows(); - this.sendOnRowSaved(); - this.sendOnLoadingEnded(); - }, this::sendError); + this.mCurrentMtbColt.getMtbColr().remove(mtbColrToDelete); - }); + this.resetMatchedRows(); + this.sendOnRowSaved(); + this.sendOnLoadingEnded(); } - public void requestCloseLU(boolean shouldPrint) { +// public void requestCloseLU(boolean shouldPrint) throws Exception { +// if (mCurrentMtbColt == null) return; +// this.sendOnLoadingStarted(); +// +// var shouldBeDeleted = this.shouldUlBeDeleted(); +// if (shouldBeDeleted) { +// deleteLU(); +// +// this.mCurrentMtbColt = null; +// +// if (mMtbColtSessionID != null) +// this.mColliDataRecoverService.closeSession(mMtbColtSessionID); +// +// this.mIsNewLU = false; +// this.sendLUClosed(); +// this.sendOnLoadingEnded(); +// +// } else { +// var askInfoAggiuntiveFuture = Futures.transformAsync( +// askPeso(), +// voidResult -> askInfoAggiuntive(), +// executorService +// ); +// +// var closeLuFuture = Futures.transformAsync( +// askInfoAggiuntiveFuture, +// voidResult -> closeLU(), +// executorService +// ); +// +// var duplicateUlFuture = Futures.transformAsync( +// closeLuFuture, +// generatedMtbColts -> validateTheUdsToBeDuplicated(generatedMtbColts), +// executorService +// ); +// +// var filledMtbColtFuture = Futures.transformAsync( +// duplicateUlFuture, +// duplicatedMtbColts -> { +// SettableFuture> future = SettableFuture.create(); +// this.mColliMagazzinoRESTConsumer.fillMtbAartsOfMtbColts(duplicatedMtbColts, +// future::set, +// future::setException); +// +// return future; +// }, +// executorService +// ); +// +// var askPosizioneFuture = Futures.transformAsync(filledMtbColtFuture, +// this::askPositionChange, +// executorService); +// +// var askPrintFuture = Futures.transformAsync(askPosizioneFuture, +// mtbColts -> askPrint(shouldPrint && SettingsManager.iDB().isFlagPrintEtichetteOnLUClose(), mtbColts), +// executorService); +// +// +// Futures.addCallback(askPrintFuture, new FutureCallback<>() { +// +// @Override +// public void onSuccess(List result) { +// handler.post(() -> { +// result.stream() +// .filter(x -> !mColliRegistrati.contains(x)) +// .forEach(x -> mColliRegistrati.add(x)); +// +// postCloseOperations(result); +// +// mIsNewLU = false; +// +// resetMatchedRows(); +// sendLUClosed(); +// sendOnLoadingEnded(); +// }); +// } +// +// @Override +// public void onFailure(Throwable throwable) { +// sendError(new Exception(throwable)); +// } +// }, executorService); +// +// } +// } + + public void requestCloseLU(boolean shouldPrint) throws Exception { if (mCurrentMtbColt == null) return; this.sendOnLoadingStarted(); - this.checkIfShouldBeDeleted(() -> { - deleteLU(() -> { - this.mCurrentMtbColt = null; + var shouldBeDeleted = this.shouldUlBeDeleted(); + if (shouldBeDeleted) { + deleteLU(); - if (mMtbColtSessionID != null) - this.mColliDataRecoverService.closeSession(mMtbColtSessionID); + this.mCurrentMtbColt = null; - this.mIsNewLU = false; - this.sendLUClosed(); - this.sendOnLoadingEnded(); - }); + if (mMtbColtSessionID != null) + this.mColliDataRecoverService.closeSession(mMtbColtSessionID); - }, () -> { - this.askPeso(() -> { + this.mIsNewLU = false; + this.sendLUClosed(); + this.sendOnLoadingEnded(); - this.askInfoAggiuntive(() -> { + } else { - this.closeLU(generatedMtbColts -> { + this.askPeso(); + this.askInfoAggiuntive(); + var generatedMtbColts = this.closeLU(); - this.validateTheUdsToBeDuplicated(generatedMtbColts, duplicatedMtbColts -> { + var duplicatedMtbColts = this.validateTheUdsToBeDuplicated(generatedMtbColts); - if (duplicatedMtbColts != null) { - generatedMtbColts.addAll(duplicatedMtbColts); - } + if (duplicatedMtbColts != null) { + generatedMtbColts.addAll(duplicatedMtbColts); + } - this.mColliMagazzinoRESTConsumer.fillMtbAartsOfMtbColts(generatedMtbColts, filledMtbColts -> { + var filledMtbColts = this.mColliMagazzinoRESTConsumer.fillMtbAartsOfMtbColtsSynchronized(generatedMtbColts); - this.askPositionChange( - filledMtbColts, - positionedMtbColts -> { + var positionedMtbColts = this.askPositionChange(filledMtbColts); - this.askPrint((shouldPrint && SettingsManager.iDB().isFlagPrintEtichetteOnLUClose()), positionedMtbColts, () -> { - positionedMtbColts.stream() - .filter(x -> !this.mColliRegistrati.contains(x)) - .forEach(x -> this.mColliRegistrati.add(x)); - postCloseOperations(positionedMtbColts); + this.askPrint((shouldPrint && SettingsManager.iDB().isFlagPrintEtichetteOnLUClose()), positionedMtbColts); - this.mIsNewLU = false; + positionedMtbColts.stream() + .filter(x -> !this.mColliRegistrati.contains(x)) + .forEach(x -> this.mColliRegistrati.add(x)); - this.resetMatchedRows(); - this.sendLUClosed(); - this.sendOnLoadingEnded(); - }); + postCloseOperations(positionedMtbColts); - }); + this.mIsNewLU = false; - }, this::sendError); - }); - }); - }); - }); - }); + this.resetMatchedRows(); + this.sendLUClosed(); + this.sendOnLoadingEnded(); + } } - - private void closeLU(RunnableArgs> onComplete) { + private List closeLU() throws Exception { var clonedLuToClose = (MtbColt) this.mCurrentMtbColt.clone(); clonedLuToClose.setMtbColr(null); @@ -1694,12 +1848,11 @@ public class SpedizioneViewModel { } - this.mColliScaricoRESTConsumer.closeUDS(closeUDSRequestDto, closeResponse -> { - onComplete.run(closeResponse.getGeneratedMtbColts()); - }, this::sendError); + var closeResponse = this.mColliScaricoRESTConsumer.closeUDSSynchronized(closeUDSRequestDto); + return closeResponse.getGeneratedMtbColts(); } - private void validateTheUdsToBeDuplicated(List mtbColtList, RunnableArgs> onComplete) { + private List validateTheUdsToBeDuplicated(List mtbColtList) throws Exception { var clonedLu = (MtbColt) this.mCurrentMtbColt.clone(); boolean noReference = clonedLu.getMtbColr().stream() @@ -1711,8 +1864,7 @@ public class SpedizioneViewModel { ); if (mtbColtList.size() > 1 || !noReference || !SettingsManager.iDB().isFlagAskDuplicateUDSSpedizione()) { - onComplete.run(new ArrayList<>()); - return; + return new ArrayList<>(); } var savedMtbColt = mtbColtList.get(0); @@ -1734,88 +1886,90 @@ public class SpedizioneViewModel { BigDecimal qtaEvasa = Objects.requireNonNull(groupedByCodMart.get(codMart)).stream().map(MtbColr::getNumCnf).reduce(BigDecimal.ZERO, BigDecimal::add); - sendInputDuplicate(qtaTot, qtaEvasa, inputNumber -> { - duplicateUDS(savedMtbColt, inputNumber, onComplete); - }, () -> onComplete.run(null)); + var inputNumber = sendInputDuplicate(qtaTot, qtaEvasa); + return duplicateUDS(savedMtbColt, inputNumber); } } } } else { - sendInputDuplicate(inputNumber -> { - duplicateUDS(savedMtbColt, inputNumber, onComplete); - }, () -> onComplete.run(null)); + var inputNumber = sendInputDuplicate(); + return duplicateUDS(savedMtbColt, inputNumber); } + + return null; } - private void duplicateUDS(MtbColt savedMtbColt, Integer inputNumber, RunnableArgs> onComplete) { + private List duplicateUDS(MtbColt savedMtbColt, Integer inputNumber) throws Exception { var duplicateUDSRequestDTO = new DuplicateUDSRequestDTO() .setMtbColt(savedMtbColt) .setNumOfDuplicates(inputNumber); - this.mColliSpedizioneRESTConsumer.duplicateUDS(duplicateUDSRequestDTO, data -> { - Map> groupedByCodMart = data.getMtbColtList() - .stream() - .flatMap(x -> x.getMtbColr().stream()) - .filter(x -> x.getCodMart() != null) - .collect(Collectors.groupingBy(MtbColr::getCodMart)); + var data = this.mColliSpedizioneRESTConsumer.duplicateUDSSynchronized(duplicateUDSRequestDTO); - for (PickingObjectDTO pickingObjectDTO : Objects.requireNonNull(this.mPickingList.getValue())) { - if (pickingObjectDTO.getMtbAart() != null) { - String codMart = pickingObjectDTO.getMtbAart().getCodMart(); - if (groupedByCodMart.containsKey(codMart)) { - pickingObjectDTO.getWithdrawMtbColrs() - .addAll(Objects.requireNonNull(groupedByCodMart.get(codMart))); - } + Map> groupedByCodMart = data.getMtbColtList() + .stream() + .flatMap(x -> x.getMtbColr().stream()) + .filter(x -> x.getCodMart() != null) + .collect(Collectors.groupingBy(MtbColr::getCodMart)); + + for (PickingObjectDTO pickingObjectDTO : Objects.requireNonNull(this.mPickingList.getValue())) { + if (pickingObjectDTO.getMtbAart() != null) { + String codMart = pickingObjectDTO.getMtbAart().getCodMart(); + if (groupedByCodMart.containsKey(codMart)) { + pickingObjectDTO.getWithdrawMtbColrs() + .addAll(Objects.requireNonNull(groupedByCodMart.get(codMart))); } } - onComplete.run(data.getMtbColtList()); - }, this::sendError); + } + + return data.getMtbColtList(); } - private void checkIfShouldBeDeleted(Runnable onDeleted, Runnable onContinue) { + private boolean shouldUlBeDeleted() throws Exception { + var shouldBeDeleted = this.mColliMagazzinoRESTConsumer.canULBeDeletedSynchronized(this.mCurrentMtbColt); - this.mColliMagazzinoRESTConsumer.canULBeDeleted(this.mCurrentMtbColt, - canBeDeleted -> { - if (canBeDeleted == null || !canBeDeleted) - onContinue.run(); - - else onDeleted.run(); - - }, this::sendError); + return shouldBeDeleted != null && shouldBeDeleted; } - private void deleteLU(Runnable onComplete) { - this.mColliMagazzinoRESTConsumer.deleteUL( + private void deleteLU() throws Exception { + this.mColliMagazzinoRESTConsumer.deleteULSynchronized( new DeleteULRequestDTO() - .setMtbColt(this.mCurrentMtbColt), - onComplete, this::sendError); + .setMtbColt(this.mCurrentMtbColt)); } - private void askPeso(Runnable onComplete) { - + private void askPeso() { if (mDefaultSegnoCol != -1 || !mShouldAskPesoLU) { - onComplete.run(); return; } - this.sendLUPesoRequired(mCurrentMtbColt.getCodTcol(), mCurrentMtbColt.getPesoNettoKg(), mCurrentMtbColt.getPesoKg(), (newCodTcol, newNetWeight, newGrossWeight) -> { + final CountDownLatch latch = new CountDownLatch(1); - mCurrentMtbColt.setCodTcol(newCodTcol); - mCurrentMtbColt.setPesoNettoKg(newNetWeight); - mCurrentMtbColt.setPesoKg(newGrossWeight); + this.sendLUPesoRequired(mCurrentMtbColt.getCodTcol(), mCurrentMtbColt.getPesoNettoKg(), mCurrentMtbColt.getPesoKg(), + (newCodTcol, newNetWeight, newGrossWeight) -> { - onComplete.run(); - }); + mCurrentMtbColt.setCodTcol(newCodTcol); + mCurrentMtbColt.setPesoNettoKg(newNetWeight); + mCurrentMtbColt.setPesoKg(newGrossWeight); + + latch.countDown(); + }); + + try { + latch.await(); // Attende che il dialog venga chiuso + } catch (InterruptedException e) { + this.sendError(e); + } } - private void askInfoAggiuntive(Runnable onComplete) { + private void askInfoAggiuntive() { if (mDefaultSegnoCol != -1 || !SettingsManager.iDB().isFlagAskInfoAggiuntiveSpedizione()) { - onComplete.run(); return; } + final CountDownLatch latch = new CountDownLatch(1); + this.mListener.onInfoAggiuntiveRequired(mCurrentMtbColt, (note, mtbTcol) -> { mCurrentMtbColt.setAnnotazioni(note); @@ -1827,67 +1981,57 @@ public class SpedizioneViewModel { mCurrentMtbColt.setCodTcol(null); } - onComplete.run(); + latch.countDown(); }); + + try { + latch.await(); // Attende che il dialog venga chiuso + } catch (InterruptedException e) { + this.sendError(e); + } } - private void askPositionChange(List mtbColtsToMove, RunnableArgs> onComplete) { + private List askPositionChange(List mtbColtsToMove) throws Exception { if (mDefaultGestioneOfUL != GestioneEnum.LAVORAZIONE || mDefaultSegnoCol != 1 || !this.mIsNewLU) { - onComplete.run(mtbColtsToMove); - return; + return mtbColtsToMove; } - this.sendLUPositionChangeRequest((shouldChangePosition, mtbDepoPosizione) -> { + var response = this.sendLUPositionChangeRequest(); - if (!shouldChangePosition) { - onComplete.run(mtbColtsToMove); - return; - } + if (response == null || !response.first) { + return mtbColtsToMove; + } - if (mtbDepoPosizione == null) { - //Nessuna posizione trovata con questo barcode - this.sendError(new ScannedPositionNotExistException()); - return; - } + var mtbDepoPosizione = response.second; + if (mtbDepoPosizione == null) { + //Nessuna posizione trovata con questo barcode + throw new ScannedPositionNotExistException(); + } - if (!mtbDepoPosizione.isFlagMonoCollo()) { - //La posizione non è Mono-UL - this.sendError(new CurrentMonoLUPositionIsNotCorrectException()); - return; - } + if (!mtbDepoPosizione.isFlagMonoCollo()) { + //La posizione non è Mono-UL + throw new CurrentMonoLUPositionIsNotCorrectException(); + } - this.mPosizioneRESTConsumer.getBancaliInPosizione(mtbDepoPosizione, destMtbColtList -> { + var destMtbColtList = this.mPosizioneRESTConsumer.getBancaliInPosizioneSynchronized(mtbDepoPosizione); - if (destMtbColtList == null || destMtbColtList.size() != 1) { - //Nessuna UL trovata oppure più UL nella stessa posizione - this.sendError(new NoLUFoundException()); - return; + if (destMtbColtList == null || destMtbColtList.size() != 1) { + //Nessuna UL trovata oppure più UL nella stessa posizione + throw new NoLUFoundException(); + } - } + if (destMtbColtList.get(0).getSegno() != mDefaultSegnoCol) { + throw new InvalidLUException(); - if (destMtbColtList.get(0).getSegno() != mDefaultSegnoCol) { - this.sendError(new InvalidLUException()); - return; - - } - - moveLUtoLU(mtbColtsToMove, destMtbColtList.get(0), savedMtbColt -> { - ArrayList savedMtbColtList = new ArrayList<>(); - savedMtbColtList.add(savedMtbColt); - onComplete.run(savedMtbColtList); - }); - - - }, this::sendError); - - - }); + } + var savedMtbColt = moveLUtoLU(mtbColtsToMove, destMtbColtList.get(0)); + return savedMtbColt; } - private void askPrint(boolean canPrint, List mtbColtsToPrint, Runnable onComplete) { + private void askPrint(boolean canPrint, List mtbColtsToPrint) { if (mDefaultGestioneOfUL != GestioneEnum.VENDITA || mDefaultSegnoCol != -1 || @@ -1895,36 +2039,50 @@ public class SpedizioneViewModel { mtbColtsToPrint.isEmpty() || !canPrint) { - onComplete.run(); return; } + final CountDownLatch latch = new CountDownLatch(1); + this.sendLUPrintRequest(shouldPrint -> { if (!shouldPrint) { - onComplete.run(); return; } var printUDSRequestDto = new PrintULRequestDTO() .setMtbColts(mtbColtsToPrint); - this.mColliMagazzinoRESTConsumer.printUL(printUDSRequestDto, onComplete, - ex -> this.sendLUPrintError(ex, onComplete)); + this.mColliMagazzinoRESTConsumer + .printUL(printUDSRequestDto, + latch::countDown, + ex -> this.sendLUPrintError(ex, latch::countDown)); }); + try { + latch.await(); // Attende che il dialog venga chiuso + } catch (InterruptedException e) { + this.sendError(e); + } + + } - private void moveLUtoLU(List sourceMtbColts, MtbColt destMtbColt, RunnableArgs onComplete) { + private List moveLUtoLU(List sourceMtbColts, MtbColt destMtbColt) throws Exception { destMtbColt.setMtbColr(new ObservableArrayList<>()); for (MtbColt sourceMtbColt : sourceMtbColts) { for (MtbColr sourceMtbColr : sourceMtbColt.getMtbColr()) { MtbColr cloneMtbColr = (MtbColr) sourceMtbColr.clone(); - cloneMtbColr.setRiga(null).setNumCollo(null).setGestione((String) null).setDataCollo((String) null).setSerCollo(null).setCausale(MtbColr.Causale.VERSAMENTO); + cloneMtbColr.setRiga(null) + .setNumCollo(null) + .setGestione((String) null) + .setDataCollo((String) null) + .setSerCollo(null) + .setCausale(MtbColr.Causale.VERSAMENTO); cloneMtbColr.setOperation(CommonModelConsts.OPERATION.INSERT); destMtbColt.getMtbColr().add(cloneMtbColr); @@ -1937,9 +2095,8 @@ public class SpedizioneViewModel { destMtbColt.setOperation(CommonModelConsts.OPERATION.INSERT_OR_UPDATE); sourceMtbColts.add(destMtbColt); - this.mColliMagazzinoRESTConsumer.saveColli(sourceMtbColts, data -> { - onComplete.run(destMtbColt); - }, this::sendError); + var data = this.mColliMagazzinoRESTConsumer.saveColliSynchronized(sourceMtbColts); + return data; } @@ -2115,14 +2272,28 @@ public class SpedizioneViewModel { this.mDocumentRESTConsumer.createDocFromColli(loadCollidto, doc -> this.sendOnOrderClosed(), this::sendError); } - private void sendInputDuplicate(BigDecimal qtaTot, BigDecimal qtaEvasa, RunnableArgs onComplete, Runnable onNegativeClick) { - if (this.mListener != null) - mListener.onInputDuplicate(qtaTot, qtaEvasa, onComplete, onNegativeClick); + private Integer sendInputDuplicate() { + return sendInputDuplicate(null, null); } - private void sendInputDuplicate(RunnableArgs onComplete, Runnable onNegativeClick) { - if (this.mListener != null) - mListener.onInputDuplicate(null, null, onComplete, onNegativeClick); + private Integer sendInputDuplicate(BigDecimal qtaTot, BigDecimal qtaEvasa) { + + final CountDownLatch latch = new CountDownLatch(1); + AtomicReference result = new AtomicReference<>(); + + mListener.onInputDuplicate(qtaTot, qtaEvasa, data -> { + result.set(data); + latch.countDown(); + }, latch::countDown); + + try { + latch.await(); // Attende che il dialog venga chiuso + return result.get(); + } catch (InterruptedException e) { + this.sendError(e); + } + + return null; } public SpedizioneViewModel setListeners(Listener listener) { @@ -2140,7 +2311,7 @@ public class SpedizioneViewModel { void onError(Exception ex, boolean useSnackbar); - void onFullItemDispatched(PickingObjectDTO pickingObjectDTO, MtbAart mtbAart, BigDecimal initialNumCnf, BigDecimal initialQtaCnf, BigDecimal initialQtaTot, BigDecimal totalQtaOrd, BigDecimal totalNumCnfOrd, BigDecimal qtaCnfOrd, BigDecimal totalQtaToBeTaken, BigDecimal totalNumCnfToBeTaken, BigDecimal qtaCnfToBeTaken, BigDecimal totalQtaAvailable, BigDecimal totalNumCnfAvailable, BigDecimal qtaCnfAvailable, String partitaMag, LocalDate dataScad, boolean canOverflowOrderQuantity, boolean canBatchLotBeChanged, RunnableArgss onComplete); + void onFullItemDispatched(PickingObjectDTO pickingObjectDTO, MtbAart mtbAart, BigDecimal initialNumCnf, BigDecimal initialQtaCnf, BigDecimal initialQtaTot, BigDecimal totalQtaOrd, BigDecimal totalNumCnfOrd, BigDecimal qtaCnfOrd, BigDecimal totalQtaToBeTaken, BigDecimal totalNumCnfToBeTaken, BigDecimal qtaCnfToBeTaken, BigDecimal totalQtaAvailable, BigDecimal totalNumCnfAvailable, BigDecimal qtaCnfAvailable, String partitaMag, LocalDate dataScad, boolean canOverflowOrderQuantity, boolean canBatchLotBeChanged, RunnableArgs onComplete, Runnable onAbort); void onInfoAggiuntiveRequired(MtbColt currentMtbColt, RunnableArgss onComplete); @@ -2154,7 +2325,7 @@ public class SpedizioneViewModel { void onChooseArtRequest(List artsList, RunnableArgs onComplete); - void onChooseArtsRequest(List artsList, RunnableArgs> onComplete); + void onChooseArtsRequest(List artsList, RunnableArgs> onComplete, Runnable onAbort); void onOrderClosed(); diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/model/PickedQuantityDTO.java b/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/model/PickedQuantityDTO.java index d41e3ed6..6e6c6b98 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/model/PickedQuantityDTO.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/model/PickedQuantityDTO.java @@ -3,6 +3,8 @@ package it.integry.integrywmsnative.gest.spedizione.model; import java.math.BigDecimal; import java.time.LocalDate; +import it.integry.barcode_base_android_library.model.BarcodeScanDTO; + public class PickedQuantityDTO { private String partitaMag; @@ -12,6 +14,9 @@ public class PickedQuantityDTO { private BigDecimal qtaCnf; private BigDecimal qtaTot; + private BarcodeScanDTO nextUlBarcode; + private boolean shouldCloseLu; + public String getPartitaMag() { return partitaMag; } @@ -56,4 +61,22 @@ public class PickedQuantityDTO { this.qtaTot = qtaTot; return this; } + + public BarcodeScanDTO getNextUlBarcode() { + return nextUlBarcode; + } + + public PickedQuantityDTO setNextUlBarcode(BarcodeScanDTO nextUlBarcode) { + this.nextUlBarcode = nextUlBarcode; + return this; + } + + public boolean isShouldCloseLu() { + return shouldCloseLu; + } + + public PickedQuantityDTO setShouldCloseLu(boolean shouldCloseLu) { + this.shouldCloseLu = shouldCloseLu; + return this; + } } diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/ultime_consegne_cliente/UltimeConsegneClienteFragment.java b/app/src/main/java/it/integry/integrywmsnative/gest/ultime_consegne_cliente/UltimeConsegneClienteFragment.java index 8b6fde24..a5124ead 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/ultime_consegne_cliente/UltimeConsegneClienteFragment.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/ultime_consegne_cliente/UltimeConsegneClienteFragment.java @@ -47,7 +47,7 @@ public class UltimeConsegneClienteFragment extends BaseFragment implements Ultim private final List mOnPreDestroyList = new ArrayList<>(); private ElevatedToolbar mToolbar; - private int barcodeScannerIstanceID = -1; + private int mBarcodeScannerInstanceID = -1; private final ObservableArrayList mDocumentiMutableData = new ObservableArrayList<>(); @@ -138,18 +138,18 @@ public class UltimeConsegneClienteFragment extends BaseFragment implements Ultim } private void initBarcodeReader() { - barcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessful) .setOnScanFailed(ex -> UtilityExceptions.defaultException(getActivity(), ex, false))); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } private final RunnableArgs onScanSuccessful = data -> { - BarcodeManager.disable(); + BarcodeManager.disable(mBarcodeScannerInstanceID); this.mViewModel.processBarcodeDTO(data, () -> { - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); }); }; diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/ultimi_arrivi_fornitore/UltimiArriviFornitoreFragment.java b/app/src/main/java/it/integry/integrywmsnative/gest/ultimi_arrivi_fornitore/UltimiArriviFornitoreFragment.java index 239deef7..718f3b3c 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/ultimi_arrivi_fornitore/UltimiArriviFornitoreFragment.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/ultimi_arrivi_fornitore/UltimiArriviFornitoreFragment.java @@ -54,7 +54,7 @@ public class UltimiArriviFornitoreFragment extends BaseFragment implements ITitl private final List mOnPreDestroyList = new ArrayList<>(); private ElevatedToolbar mToolbar; - private int barcodeScannerIstanceID = -1; + private int mBarcodeScannerInstanceID = -1; private final ObservableArrayList mDocumentiMutableData = new ObservableArrayList<>(); @@ -142,18 +142,18 @@ public class UltimiArriviFornitoreFragment extends BaseFragment implements ITitl } private void initBarcodeReader() { - barcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessful) .setOnScanFailed(ex -> UtilityExceptions.defaultException(getActivity(), ex, false))); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } private final RunnableArgs onScanSuccessful = data -> { - BarcodeManager.disable(); + BarcodeManager.disable(mBarcodeScannerInstanceID); this.mViewModel.processBarcodeDTO(data, () -> { - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); }); }; @@ -222,7 +222,7 @@ public class UltimiArriviFornitoreFragment extends BaseFragment implements ITitl @Override public void onDestroy() { - BarcodeManager.removeCallback(barcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); for (Runnable onPreDestroy : mOnPreDestroyList) { onPreDestroy.run(); diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/versamento_merce/VersamentoMerceFragment.java b/app/src/main/java/it/integry/integrywmsnative/gest/versamento_merce/VersamentoMerceFragment.java index f1f335a4..06fea57a 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/versamento_merce/VersamentoMerceFragment.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/versamento_merce/VersamentoMerceFragment.java @@ -55,7 +55,7 @@ public class VersamentoMerceFragment extends BaseFragment implements ITitledFrag private final List mOnPreDestroyList = new ArrayList<>(); - private int barcodeScannerIstanceID = -1; + private int mBarcodeScannerInstanceID = -1; public static VersamentoMerceFragment newInstance() { @@ -94,7 +94,7 @@ public class VersamentoMerceFragment extends BaseFragment implements ITitledFrag @Override public void onDestroy() { - BarcodeManager.removeCallback(barcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); for (Runnable onPreDestroy : mOnPreDestroyList) { onPreDestroy.run(); @@ -122,11 +122,11 @@ public class VersamentoMerceFragment extends BaseFragment implements ITitledFrag private void initBarcodeReader() { - barcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessful) .setOnScanFailed(ex -> UtilityExceptions.defaultException(getActivity(), ex, false))); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } private final RunnableArgs onScanSuccessful = data -> { @@ -211,7 +211,12 @@ public class VersamentoMerceFragment extends BaseFragment implements ITitledFrag this.requireActivity().runOnUiThread(() -> { mDialogInputQuantityV2View .setDialogInputQuantityV2DTO(dialogInputQuantityV2DTO) - .setOnComplete((resultDTO, shouldCloseLU) -> { + .setOnComplete(resultDTO -> { + + if(resultDTO == null || resultDTO.isAborted()) { + this.onLoadingEnded(); + return; + } PickedQuantityDTO pickedQuantityDTO = new PickedQuantityDTO() .setNumCnf(resultDTO.getNumCnf()) diff --git a/app/src/main/java/it/integry/integrywmsnative/view/bottom_sheet__lu_content/BottomSheetFragmentLUContentListAdapter.java b/app/src/main/java/it/integry/integrywmsnative/view/bottom_sheet__lu_content/BottomSheetFragmentLUContentListAdapter.java index 201e6f69..30fb1104 100644 --- a/app/src/main/java/it/integry/integrywmsnative/view/bottom_sheet__lu_content/BottomSheetFragmentLUContentListAdapter.java +++ b/app/src/main/java/it/integry/integrywmsnative/view/bottom_sheet__lu_content/BottomSheetFragmentLUContentListAdapter.java @@ -1,6 +1,8 @@ package it.integry.integrywmsnative.view.bottom_sheet__lu_content; import android.content.Context; +import android.os.Handler; +import android.os.Looper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -48,10 +50,12 @@ public class BottomSheetFragmentLUContentListAdapter extends RecyclerView.Adapte this.mContext = context; this.mDataset = mtbColrs != null ? mtbColrs : new ArrayList<>(); + Handler handler = new Handler(Looper.getMainLooper()); + mtbColrs.addOnListChangedCallback(new OnListGeneralChangedCallback() { @Override public void onChanged(ObservableList sender) { - notifyDataSetChanged(); + handler.post(() -> notifyDataSetChanged()); } }); } diff --git a/app/src/main/java/it/integry/integrywmsnative/view/bottom_sheet__lu_content/BottomSheetFragmentLUContentView.java b/app/src/main/java/it/integry/integrywmsnative/view/bottom_sheet__lu_content/BottomSheetFragmentLUContentView.java index ab0b3697..7c4aa05d 100644 --- a/app/src/main/java/it/integry/integrywmsnative/view/bottom_sheet__lu_content/BottomSheetFragmentLUContentView.java +++ b/app/src/main/java/it/integry/integrywmsnative/view/bottom_sheet__lu_content/BottomSheetFragmentLUContentView.java @@ -1,6 +1,8 @@ package it.integry.integrywmsnative.view.bottom_sheet__lu_content; import android.content.Context; +import android.os.Handler; +import android.os.Looper; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; @@ -76,25 +78,31 @@ public class BottomSheetFragmentLUContentView extends BottomSheetFragmentBaseVie } private void initCallbacks() { + Handler handler = new Handler(Looper.getMainLooper()); this.mViewModel.getObservableMtbColt().addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() { @Override public void onPropertyChanged(Observable sender, int propertyId) { - var mtbColt = mViewModel.getObservableMtbColt().get(); + handler.post(() -> { - if (mtbColt != null) { - initAdapter(); + var mtbColt = mViewModel.getObservableMtbColt().get(); - onMtbColrItemChanged(); + if (mtbColt != null) { + initAdapter(); - mtbColt.getMtbColr().addOnListChangedCallback(new OnListGeneralChangedCallback() { - @Override - public void onChanged(ObservableList sender) { - onMtbColrItemChanged(); - } - }); - } else { - mBinding.mtbColrRecyclerView.setAdapter(null); - } + onMtbColrItemChanged(); + + mtbColt.getMtbColr().addOnListChangedCallback(new OnListGeneralChangedCallback() { + @Override + public void onChanged(ObservableList sender) { + handler.post(() -> { + onMtbColrItemChanged(); + }); + } + }); + } else { + mBinding.mtbColrRecyclerView.setAdapter(null); + } + }); } }); } diff --git a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/ask_cliente/viewmodel/DialogAskCliente_Page1ViewModel.java b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/ask_cliente/viewmodel/DialogAskCliente_Page1ViewModel.java index 943e5464..c97a3ef7 100644 --- a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/ask_cliente/viewmodel/DialogAskCliente_Page1ViewModel.java +++ b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/ask_cliente/viewmodel/DialogAskCliente_Page1ViewModel.java @@ -61,7 +61,7 @@ public class DialogAskCliente_Page1ViewModel implements IDialogAskClienteViewMod mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessful) .setOnScanFailed(ex -> UtilityExceptions.defaultException(mContext, ex, false))); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); this.mBinding.buttonYes.setOnClickListener(v -> { if (validateCliente()) { @@ -91,7 +91,7 @@ public class DialogAskCliente_Page1ViewModel implements IDialogAskClienteViewMod private final RunnableArgs onScanSuccessful = data -> { - BarcodeManager.disable(); + BarcodeManager.disable(mBarcodeScannerInstanceID); String barcode = data.getStringValue(); @@ -118,7 +118,7 @@ public class DialogAskCliente_Page1ViewModel implements IDialogAskClienteViewMod } } - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); }; diff --git a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/ask_commessa/DialogAskCommessaView.java b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/ask_commessa/DialogAskCommessaView.java index 6224038c..432d57a9 100644 --- a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/ask_commessa/DialogAskCommessaView.java +++ b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/ask_commessa/DialogAskCommessaView.java @@ -44,7 +44,7 @@ public class DialogAskCommessaView extends BaseDialogFragment implements DialogA private DialogAskCommessaBinding mBindings; private Context mContext; - private int mBarcodeScannerIstanceID; + private int mBarcodeScannerInstanceID; private JtbComt selectedJtbComt; @@ -113,7 +113,7 @@ public class DialogAskCommessaView extends BaseDialogFragment implements DialogA public void onDismiss(@NonNull DialogInterface dialog) { super.onDismiss(dialog); - BarcodeManager.removeCallback(mBarcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); } @Override @@ -125,15 +125,15 @@ public class DialogAskCommessaView extends BaseDialogFragment implements DialogA } private void initBarcode() { - mBarcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessful) .setOnScanFailed(this::onError)); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } private final RunnableArgs onScanSuccessful = data -> { - BarcodeManager.disable(); + BarcodeManager.disable(mBarcodeScannerInstanceID); // this.mViewModel.processBarcodeDTO(data, BarcodeManager::enable); }; diff --git a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/ask_linea_prod/DialogAskLineaProdView.java b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/ask_linea_prod/DialogAskLineaProdView.java index 2b0709b0..268d7632 100644 --- a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/ask_linea_prod/DialogAskLineaProdView.java +++ b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/ask_linea_prod/DialogAskLineaProdView.java @@ -35,7 +35,7 @@ public class DialogAskLineaProdView extends BaseDialogFragment implements Dialog private Context mContext; - private int mBarcodeScannerIstanceID; + private int mBarcodeScannerInstanceID; //Pass here all external parameters public static DialogAskLineaProdView newInstance(RunnableArgs onComplete, Runnable onAbort) { @@ -89,16 +89,16 @@ public class DialogAskLineaProdView extends BaseDialogFragment implements Dialog } private void initBarcode() { - mBarcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessful) .setOnScanFailed(this::onError)); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } private final RunnableArgs onScanSuccessful = data -> { - BarcodeManager.disable(); - this.mViewModel.processBarcodeDTO(data, BarcodeManager::enable); + BarcodeManager.disable(mBarcodeScannerInstanceID); + this.mViewModel.processBarcodeDTO(data, () -> BarcodeManager.enable(mBarcodeScannerInstanceID)); }; @Override @@ -110,7 +110,7 @@ public class DialogAskLineaProdView extends BaseDialogFragment implements Dialog @Override public void onDismiss(@NonNull DialogInterface dialog) { - BarcodeManager.removeCallback(mBarcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); super.onDismiss(dialog); } } \ No newline at end of file diff --git a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/ask_position_of_lu/DialogAskPositionOfLUView.java b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/ask_position_of_lu/DialogAskPositionOfLUView.java index d6d538d5..c5493af8 100644 --- a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/ask_position_of_lu/DialogAskPositionOfLUView.java +++ b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/ask_position_of_lu/DialogAskPositionOfLUView.java @@ -37,7 +37,7 @@ public class DialogAskPositionOfLUView extends BaseDialogFragment implements Dia private DialogAskPositionOfLuBinding mBindings; private DialogAskPositionOfLUAdapter viewpagerAdapter; - private int mBarcodeScannerIstanceID; + private int mBarcodeScannerInstanceID; private boolean mCheckForLineaProd; @@ -142,23 +142,23 @@ public class DialogAskPositionOfLUView extends BaseDialogFragment implements Dia } private void initBarcode() { - mBarcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessfull) .setOnScanFailed(this::onError)); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } @Override public void onDismiss(@NonNull DialogInterface dialog) { - BarcodeManager.removeCallback(mBarcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); if (!completedFlow) onComplete.run(DialogConsts.Results.ABORT, null); super.onDismiss(dialog); } private final RunnableArgs onScanSuccessfull = data -> { - BarcodeManager.disable(); + BarcodeManager.disable(mBarcodeScannerInstanceID); if (!isOnLivelloPage()) { @@ -169,11 +169,11 @@ public class DialogAskPositionOfLUView extends BaseDialogFragment implements Dia if (!mCheckForLineaProd && !currentMtbDepoPosizione.isFlagLineaProduzione() && UtilityPosizione.isPosizioneWithLivello(foundPosizione)) { askLivello(); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } else { completedFlow = true; - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); if (onComplete != null) onComplete.run(DialogConsts.Results.YES, foundPosizione); @@ -181,14 +181,14 @@ public class DialogAskPositionOfLUView extends BaseDialogFragment implements Dia } } else { - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); Toast.makeText(requireContext(), "Barcode non riconosciuto", Toast.LENGTH_SHORT) .show(); } } else { Toast.makeText(requireContext(), "Barcode non riconosciuto", Toast.LENGTH_SHORT) .show(); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } }; diff --git a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/ask_unknown_barcode_notes/DialogAskUnknownBarcodeNotesView.java b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/ask_unknown_barcode_notes/DialogAskUnknownBarcodeNotesView.java index ce6b0ece..f0296cc9 100644 --- a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/ask_unknown_barcode_notes/DialogAskUnknownBarcodeNotesView.java +++ b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/ask_unknown_barcode_notes/DialogAskUnknownBarcodeNotesView.java @@ -37,7 +37,7 @@ public class DialogAskUnknownBarcodeNotesView extends BaseDialogFragment { private final Runnable onAbort; - private int mBarcodeScannerIstanceID; + private int mBarcodeScannerInstanceID; //Pass here all external parameters public static DialogAskUnknownBarcodeNotesView newInstance(String unknownBarcode, RunnableArgs onComplete, Runnable onAbort) { @@ -108,17 +108,17 @@ public class DialogAskUnknownBarcodeNotesView extends BaseDialogFragment { @Override public void onDismiss(@NonNull DialogInterface dialog) { - BarcodeManager.removeCallback(mBarcodeScannerIstanceID); - BarcodeManager.enable(); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); + BarcodeManager.enable(mBarcodeScannerInstanceID); super.onDismiss(dialog); } private void initBarcode() { - mBarcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessfull) .setOnScanFailed(this::onError)); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); setBarcodeListener(true); } @@ -137,6 +137,6 @@ public class DialogAskUnknownBarcodeNotesView extends BaseDialogFragment { @Override public void onError(Exception ex) { super.onError(ex); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } } \ No newline at end of file diff --git a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/bind_product_barcode_with_package/DialogBindProductBarcodeWithPackageView.java b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/bind_product_barcode_with_package/DialogBindProductBarcodeWithPackageView.java index 129eb719..ff0c457f 100644 --- a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/bind_product_barcode_with_package/DialogBindProductBarcodeWithPackageView.java +++ b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/bind_product_barcode_with_package/DialogBindProductBarcodeWithPackageView.java @@ -35,7 +35,7 @@ public class DialogBindProductBarcodeWithPackageView extends BaseDialogFragment private final Runnable onAbort; - private int mBarcodeScannerIstanceID; + private int mBarcodeScannerInstanceID; //Pass here all external parameters public static DialogBindProductBarcodeWithPackageView newInstance(String unknownBarcode,Runnable onAbort) { @@ -85,8 +85,8 @@ public class DialogBindProductBarcodeWithPackageView extends BaseDialogFragment @Override public void onDismiss(@NonNull DialogInterface dialog) { - BarcodeManager.removeCallback(mBarcodeScannerIstanceID); - BarcodeManager.enable(); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); + BarcodeManager.enable(mBarcodeScannerInstanceID); super.onDismiss(dialog); } @@ -94,10 +94,10 @@ public class DialogBindProductBarcodeWithPackageView extends BaseDialogFragment private void initBarcode() { - mBarcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessfull) .setOnScanFailed(this::onError)); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); setBarcodeListener(true); } @@ -116,6 +116,6 @@ public class DialogBindProductBarcodeWithPackageView extends BaseDialogFragment @Override public void onError(Exception ex) { super.onError(ex); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } } \ No newline at end of file diff --git a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/choose_arts_from_mtbcolr_list/DialogChooseArtsFromMtbColrList.java b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/choose_arts_from_mtbcolr_list/DialogChooseArtsFromMtbColrList.java index 1f241c6f..1d6a124f 100644 --- a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/choose_arts_from_mtbcolr_list/DialogChooseArtsFromMtbColrList.java +++ b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/choose_arts_from_mtbcolr_list/DialogChooseArtsFromMtbColrList.java @@ -50,7 +50,7 @@ public class DialogChooseArtsFromMtbColrList extends BaseDialogFragment implemen ArticoloRESTConsumer articoloRESTConsumer; - private int mBarcodeScannerIstanceID; + private int mBarcodeScannerInstanceID; private final List inputMtbColrList; private MtbAart selectedArt; private final RunnableArgs> onConfirmed; @@ -231,9 +231,9 @@ public class DialogChooseArtsFromMtbColrList extends BaseDialogFragment implemen } private void setupBarcode() { - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); - mBarcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessfull) .setOnScanFailed(ex -> UtilityExceptions.defaultException(mContext, ex, false))); } @@ -241,7 +241,7 @@ public class DialogChooseArtsFromMtbColrList extends BaseDialogFragment implemen @Override public void onDismiss(@NonNull DialogInterface dialog) { - BarcodeManager.removeCallback(mBarcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); this.onAbort.run(); super.onDismiss(dialog); } diff --git a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/create_new_art/DialogCreateNewArtView.java b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/create_new_art/DialogCreateNewArtView.java index 24e5b708..9ddc7412 100644 --- a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/create_new_art/DialogCreateNewArtView.java +++ b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/create_new_art/DialogCreateNewArtView.java @@ -53,7 +53,7 @@ public class DialogCreateNewArtView extends BaseDialogFragment implements Dialog private Context mContext; public final BarcodeScanDTO mScannedBarcode; - private int mBarcodeScannerIstanceID; + private int mBarcodeScannerInstanceID; private final String initialPosizione; private final RunnableArgs onArticleCreated; @@ -187,7 +187,7 @@ public class DialogCreateNewArtView extends BaseDialogFragment implements Dialog } private void initBarcodeReader() { - mBarcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(data -> { requireActivity().runOnUiThread(() -> { @@ -205,7 +205,7 @@ public class DialogCreateNewArtView extends BaseDialogFragment implements Dialog @Override public void onDismiss(@NonNull DialogInterface dialog) { super.onDismiss(dialog); - BarcodeManager.removeCallback(mBarcodeScannerIstanceID); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); } private void initObservable() { diff --git a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_quantity_v2/DialogInputQuantityV2ResponseViewModel.java b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_quantity_v2/DialogInputQuantityV2ResponseViewModel.java new file mode 100644 index 00000000..7ea9e7c6 --- /dev/null +++ b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_quantity_v2/DialogInputQuantityV2ResponseViewModel.java @@ -0,0 +1,25 @@ +package it.integry.integrywmsnative.view.dialogs.input_quantity_v2; + +import androidx.lifecycle.LiveData; +import androidx.lifecycle.MutableLiveData; +import androidx.lifecycle.ViewModel; + +public class DialogInputQuantityV2ResponseViewModel extends ViewModel { + + + private MutableLiveData result = new MutableLiveData<>(); + + public LiveData getResult() { + return result; + } + + public DialogInputQuantityV2ResponseViewModel setResult(MutableLiveData result) { + this.result = result; + return this; + } + + public DialogInputQuantityV2ResponseViewModel setResultValue(DialogInputQuantityV2ResultDTO result) { + this.result.postValue(result); + return this; + } +} diff --git a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_quantity_v2/DialogInputQuantityV2ResultDTO.java b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_quantity_v2/DialogInputQuantityV2ResultDTO.java index 53a7ed8f..63c407bf 100644 --- a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_quantity_v2/DialogInputQuantityV2ResultDTO.java +++ b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_quantity_v2/DialogInputQuantityV2ResultDTO.java @@ -3,6 +3,8 @@ package it.integry.integrywmsnative.view.dialogs.input_quantity_v2; import java.math.BigDecimal; import java.time.LocalDate; +import it.integry.barcode_base_android_library.model.BarcodeScanDTO; + public class DialogInputQuantityV2ResultDTO { private String partitaMag; @@ -13,6 +15,12 @@ public class DialogInputQuantityV2ResultDTO { private BigDecimal qtaCnf; private BigDecimal qtaTot; + private BarcodeScanDTO nextUlBarcode; + + private boolean shouldCloseLu = false; + private boolean aborted = true; + + public String getPartitaMag() { return partitaMag; } @@ -66,4 +74,31 @@ public class DialogInputQuantityV2ResultDTO { this.qtaTot = qtaTot; return this; } + + public BarcodeScanDTO getNextUlBarcode() { + return nextUlBarcode; + } + + public DialogInputQuantityV2ResultDTO setNextUlBarcode(BarcodeScanDTO nextUlBarcode) { + this.nextUlBarcode = nextUlBarcode; + return this; + } + + public boolean isShouldCloseLu() { + return shouldCloseLu; + } + + public DialogInputQuantityV2ResultDTO setShouldCloseLu(boolean shouldCloseLu) { + this.shouldCloseLu = shouldCloseLu; + return this; + } + + public boolean isAborted() { + return aborted; + } + + public DialogInputQuantityV2ResultDTO setAborted(boolean aborted) { + this.aborted = aborted; + return this; + } } diff --git a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_quantity_v2/DialogInputQuantityV2View.java b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_quantity_v2/DialogInputQuantityV2View.java index fe40362f..daa9b4df 100644 --- a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_quantity_v2/DialogInputQuantityV2View.java +++ b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_quantity_v2/DialogInputQuantityV2View.java @@ -4,7 +4,6 @@ import android.app.Dialog; import android.content.Context; import android.content.res.ColorStateList; import android.os.Bundle; -import android.os.Handler; import android.text.Html; import android.text.InputType; import android.text.SpannableString; @@ -39,7 +38,6 @@ import it.integry.integrywmsnative.core.barcode_reader.BarcodeCallbackDTO; import it.integry.integrywmsnative.core.barcode_reader.BarcodeManager; import it.integry.integrywmsnative.core.expansion.BaseDialogFragment; import it.integry.integrywmsnative.core.expansion.RunnableArgs; -import it.integry.integrywmsnative.core.expansion.RunnableArgss; import it.integry.integrywmsnative.core.model.MtbAart; import it.integry.integrywmsnative.core.model.MtbUntMis; import it.integry.integrywmsnative.core.settings.SettingsManager; @@ -59,7 +57,8 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia DialogInputQuantityV2ViewModel mViewModel; private DialogInputQuantityV2DTO mDialogInputQuantityV2DTO; - private RunnableArgss mOnComplete; + //1: Result / 2: ShouldCloseLu / 3: Aborted + private RunnableArgs mOnComplete; private Runnable mOnAbort; public ObservableField currentTextNumCnfToTake = new ObservableField<>(0); @@ -88,15 +87,13 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia public ObservableField enabledLUCloseButton = new ObservableField<>(true); public ObservableField showProductLotStatus = new ObservableField<>(false); - private final Handler mHandler = new Handler(); - private Context context; private DialogInputQuantityV2Binding mBindings; private boolean mEnableDataCallback = true; private boolean mObservablesInitated = false; - private int mBarcodeScannerIstanceID; + private int mBarcodeScannerInstanceID; private boolean mAbort = true; @@ -105,7 +102,7 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia return this; } - public DialogInputQuantityV2View setOnComplete(RunnableArgss mOnComplete) { + public DialogInputQuantityV2View setOnComplete(RunnableArgs mOnComplete) { this.mOnComplete = mOnComplete; return this; } @@ -130,7 +127,6 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia super.onCreate(savedInstanceState); setStyle(DialogFragment.STYLE_NORMAL, R.style.AppTheme_NewMaterial_Dialog_FullscreenDialog); this.initBarcode(); - } @NonNull @@ -241,12 +237,14 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia public void onDestroyView() { super.onDestroyView(); - BarcodeManager.removeCallback(mBarcodeScannerIstanceID); + mViewModel.destroy(); + + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); if (mAbort && this.mOnAbort != null) this.mOnAbort.run(); } private void initBarcode() { - mBarcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessful) .setOnScanFailed(ex -> UtilityExceptions.defaultException(this.context, ex, false))); } @@ -254,7 +252,14 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia private final RunnableArgs onScanSuccessful = data -> { this.onLoadingStarted(); - this.mViewModel.processBarcodeDTO(data, this::onLoadingEnded); + executorService.execute(() -> { + try { + this.mViewModel.processBarcodeDTO(data); + this.onLoadingEnded(); + } catch (Exception ex) { + onError(ex); + } + }); }; public void save() { @@ -266,9 +271,10 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia this.onLoadingEnded(); if (validated) { - this.mAbort = false; - dismiss(); - this.mOnComplete.run(this.mViewModel.getResult(), false); + var result = this.mViewModel.getResult() + .setAborted(false) + .setShouldCloseLu(false); + dismiss(result); } }); }); @@ -277,15 +283,32 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia public void saveAndCloseLU() { this.mViewModel.validate(validated -> { if (validated) { - this.mAbort = false; - dismiss(); - this.mOnComplete.run(this.mViewModel.getResult(), true); - } else { - this.onLoadingEnded(); + var result = this.mViewModel.getResult() + .setAborted(false) + .setShouldCloseLu(true); + + dismiss(result); } }); } + @Override + public void dismiss() { + dismiss(null); + } + + private void dismiss(DialogInputQuantityV2ResultDTO result) { + if (this.mOnComplete != null) { + if(result == null) { + result = new DialogInputQuantityV2ResultDTO() + .setAborted(true); + } + + this.mOnComplete.run(result); + } + super.dismiss(); + } + @Override public void onStart() { super.onStart(); @@ -544,4 +567,9 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia () -> result.run(false) ).show(requireActivity().getSupportFragmentManager(), "tag"); } + + @Override + public void onULCloseRequested() { + saveAndCloseLU(); + } } diff --git a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_quantity_v2/DialogInputQuantityV2ViewModel.java b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_quantity_v2/DialogInputQuantityV2ViewModel.java index a348c09f..02c8edd3 100644 --- a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_quantity_v2/DialogInputQuantityV2ViewModel.java +++ b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_quantity_v2/DialogInputQuantityV2ViewModel.java @@ -1,7 +1,5 @@ package it.integry.integrywmsnative.view.dialogs.input_quantity_v2; -import android.text.SpannableString; - import androidx.databinding.ObservableField; import java.math.BigDecimal; @@ -18,12 +16,12 @@ import it.integry.integrywmsnative.R; import it.integry.integrywmsnative.core.di.BindableString; import it.integry.integrywmsnative.core.expansion.RunnableArgs; import it.integry.integrywmsnative.core.expansion.RunnableArgsWithReturn; +import it.integry.integrywmsnative.core.interfaces.viewmodel_listeners.ILoadingListener; import it.integry.integrywmsnative.core.model.MtbAart; import it.integry.integrywmsnative.core.model.MtbPartitaMag; import it.integry.integrywmsnative.core.model.secondary.StatoPartitaMag; import it.integry.integrywmsnative.core.rest.consumers.BarcodeRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers.MagazzinoRESTConsumer; -import it.integry.integrywmsnative.core.interfaces.viewmodel_listeners.ILoadingListener; import it.integry.integrywmsnative.core.rest.model.Ean13PesoModel; import it.integry.integrywmsnative.core.settings.SettingsManager; import it.integry.integrywmsnative.core.utility.UtilityBarcode; @@ -31,8 +29,6 @@ import it.integry.integrywmsnative.core.utility.UtilityBigDecimal; import it.integry.integrywmsnative.core.utility.UtilityDate; import it.integry.integrywmsnative.core.utility.UtilityResources; import it.integry.integrywmsnative.core.utility.UtilityString; -import it.integry.integrywmsnative.view.dialogs.base.DialogSimpleMessageView; -import it.integry.integrywmsnative.view.dialogs.exception.InactiveBatchLotException; import it.integry.integrywmsnative.view.dialogs.exception.InvalidBatchLotException; import it.integry.integrywmsnative.view.dialogs.exception.InvalidExpireDateException; import it.integry.integrywmsnative.view.dialogs.exception.InvalidNotesException; @@ -88,6 +84,8 @@ public class DialogInputQuantityV2ViewModel { private String internalNote; private LocalDate internalDataScad; + private BarcodeScanDTO internalNextUlBarcode; + private RunnableArgsWithReturn suggestPartitaMagRunnable; private boolean canInputZeroQuantity; @@ -150,17 +148,16 @@ public class DialogInputQuantityV2ViewModel { this.mListener.onDataChanged(); } - public void processBarcodeDTO(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) { - if (UtilityBarcode.isEanPeso(barcodeScanDTO)) { - Ean13PesoModel ean13PesoModel; + public void destroy() { + this.internalPartitaMag = null; + this.internalNote = null; + this.internalDataScad = null; + this.internalNextUlBarcode = null; + } - try { - ean13PesoModel = Ean13PesoModel.fromBarcode(barcodeScanDTO.getStringValue()); - } catch (Exception ex) { - this.mListener.onError(ex); - onComplete.run(); - return; - } + public void processBarcodeDTO(BarcodeScanDTO barcodeScanDTO) throws Exception { + if (UtilityBarcode.isEanPeso(barcodeScanDTO)) { + Ean13PesoModel ean13PesoModel = Ean13PesoModel.fromBarcode(barcodeScanDTO.getStringValue()); if (this.mtbAart.get() != null && this.mtbAart.get().getBarCode() != null && @@ -178,57 +175,48 @@ public class DialogInputQuantityV2ViewModel { this.unlockQtaCnf(); } - onComplete.run(); } else if (UtilityBarcode.isEtichetta128(barcodeScanDTO)) { - this.mBarcodeRESTConsumer.decodeEan128(barcodeScanDTO, ean128Model -> { + var ean128Model = this.mBarcodeRESTConsumer.decodeEan128Synchronized(barcodeScanDTO); - if (ean128Model == null) { - onComplete.run(); - return; + if (ean128Model == null) { + return; + } + + if (canPartitaMagBeChanged) { + if (!UtilityString.isNullOrEmpty(ean128Model.BatchLot)) { + this.setPartitaMag(ean128Model.BatchLot); } - if (canPartitaMagBeChanged) { + if (!UtilityString.isNullOrEmpty(ean128Model.BestBefore)) { + this.setDataScad(UtilityDate.recognizeLocalDate(ean128Model.BestBefore)); + } else if (!UtilityString.isNullOrEmpty(ean128Model.Expiry)) { + this.setDataScad(UtilityDate.recognizeLocalDate(ean128Model.Expiry)); + } + } - if (!UtilityString.isNullOrEmpty(ean128Model.BatchLot)) { - this.setPartitaMag(ean128Model.BatchLot); - } + if (ean128Model.Count != null && ean128Model.Count > 0) { + this.setNumCnf(BigDecimal.valueOf(ean128Model.Count)); + } else if (ean128Model.NetWeightKg != null && ean128Model.NetWeightKg > 0) { + this.setQtaTot(BigDecimal.valueOf(ean128Model.NetWeightKg)); + this.setNumCnf(UtilityBigDecimal.divideAndRoundToInteger(this.getQtaTot(), this.mtbAart.get().getQtaCnf())); - try { - if (!UtilityString.isNullOrEmpty(ean128Model.BestBefore)) { - this.setDataScad(UtilityDate.recognizeLocalDate(ean128Model.BestBefore)); - } else if (!UtilityString.isNullOrEmpty(ean128Model.Expiry)) { - this.setDataScad(UtilityDate.recognizeLocalDate(ean128Model.Expiry)); - } - } catch (Exception ex) { - this.mListener.onError(ex); - } + if (!this.mtbAart.get().isFlagQtaCnfFissaBoolean()) { + if (UtilityBigDecimal.equalsTo(this.getNumCnf(), BigDecimal.ZERO)) + this.setNumCnf(BigDecimal.ONE); + this.setQtaCnf(UtilityBigDecimal.divide(this.getQtaTot(), this.getNumCnf())); } - if (ean128Model.Count != null && ean128Model.Count > 0) { - this.setNumCnf(BigDecimal.valueOf(ean128Model.Count)); - } else if (ean128Model.NetWeightKg != null && ean128Model.NetWeightKg > 0) { - this.setQtaTot(BigDecimal.valueOf(ean128Model.NetWeightKg)); - this.setNumCnf(UtilityBigDecimal.divideAndRoundToInteger(this.getQtaTot(), this.mtbAart.get().getQtaCnf())); + this.unlockNumCnf(); + this.unlockQtaCnf(); + } else if (ean128Model.Sscc != null) { + //Close current UDS and open another one with new SSCC + this.internalNextUlBarcode = barcodeScanDTO; + this.sendOnULCloseRequested(); + return; + } - if (!this.mtbAart.get().isFlagQtaCnfFissaBoolean()) { - if (UtilityBigDecimal.equalsTo(this.getNumCnf(), BigDecimal.ZERO)) - this.setNumCnf(BigDecimal.ONE); - this.setQtaCnf(UtilityBigDecimal.divide(this.getQtaTot(), this.getNumCnf())); - } + this.mListener.onDataChanged(); - this.unlockNumCnf(); - this.unlockQtaCnf(); - } - - this.mListener.onDataChanged(); - onComplete.run(); - - }, ex -> { - this.mListener.onError(ex); - onComplete.run(); - }); - } else { - onComplete.run(); } } @@ -527,144 +515,142 @@ public class DialogInputQuantityV2ViewModel { } public void validate(RunnableArgs onValidated) { - new Thread(() -> { - if (this.internalQtaCnf == null || UtilityBigDecimal.equalsTo(this.internalQtaCnf, BigDecimal.ZERO)) { + if (this.internalQtaCnf == null || UtilityBigDecimal.equalsTo(this.internalQtaCnf, BigDecimal.ZERO)) { - this.sendError(new InvalidQtaCnfQuantityException()); - onValidated.run(false); - return; - } + this.sendError(new InvalidQtaCnfQuantityException()); + onValidated.run(false); + return; + } - if (!disableTracciabilitaCheck && mtbAart.get().isFlagTracciabilitaBoolean()) { - if (UtilityString.isNullOrEmpty(internalPartitaMag)) { - if (suggestPartitaMagRunnable != null) { - internalPartitaMag = suggestPartitaMagRunnable.run(this); - if (internalPartitaMag == null) { - this.sendError(new InvalidBatchLotException()); - onValidated.run(false); - return; - } - } else { + if (!disableTracciabilitaCheck && mtbAart.get().isFlagTracciabilitaBoolean()) { + if (UtilityString.isNullOrEmpty(internalPartitaMag)) { + if (suggestPartitaMagRunnable != null) { + internalPartitaMag = suggestPartitaMagRunnable.run(this); + if (internalPartitaMag == null) { this.sendError(new InvalidBatchLotException()); onValidated.run(false); return; } } else { - if (SettingsManager.iDB().isFlagWarningNewPartitaMag()) { - MtbPartitaMag mtbPartitaMag = null; - try { - mtbPartitaMag = retrievePartitaMag(internalPartitaMag, this.getMtbAart().getCodMart()); - } catch (Exception e) { - this.sendError(e); + this.sendError(new InvalidBatchLotException()); + onValidated.run(false); + return; + } + } else { + if (SettingsManager.iDB().isFlagWarningNewPartitaMag()) { + MtbPartitaMag mtbPartitaMag = null; + try { + mtbPartitaMag = retrievePartitaMag(internalPartitaMag, this.getMtbAart().getCodMart()); + } catch (Exception e) { + this.sendError(e); + onValidated.run(false); + return; + } + + if (mtbPartitaMag == null) { + boolean result = runWarningDialogSyncronized(UtilityResources.getString(R.string.batch_lot_inexistent_error_message)); + if (!result) { onValidated.run(false); return; } - - if (mtbPartitaMag == null) { - boolean result = runWarningDialogSyncronized(UtilityResources.getString(R.string.batch_lot_inexistent_error_message)); - if (!result) { - onValidated.run(false); - return; - } - } } } } + } - if (this.statoArt == StatoPartitaMag.DISATTIVO) { - boolean result = runWarningDialogSyncronized(String.format(UtilityResources.getString(R.string.batch_lot_not_enabled), internalPartitaMag)); - if (!result) { - onValidated.run(false); - return; - } - } - - if (this.shouldAskDataScad && UtilityString.isNullOrEmpty(internalPartitaMag)) { - - this.sendError(new InvalidBatchLotException()); + if (this.statoArt == StatoPartitaMag.DISATTIVO) { + boolean result = runWarningDialogSyncronized(String.format(UtilityResources.getString(R.string.batch_lot_not_enabled), internalPartitaMag)); + if (!result) { onValidated.run(false); return; } + } - if (this.shouldAskDataScad && this.internalDataScad == null) { + if (this.shouldAskDataScad && UtilityString.isNullOrEmpty(internalPartitaMag)) { - this.sendError(new InvalidExpireDateException()); + this.sendError(new InvalidBatchLotException()); + onValidated.run(false); + return; + } + + if (this.shouldAskDataScad && this.internalDataScad == null) { + + this.sendError(new InvalidExpireDateException()); + onValidated.run(false); + return; + } + + if (!this.canOverflowOrderQuantity && UtilityBigDecimal.greaterThan(this.internalQtaTot, this.totalQtaOrd) && + this.mtbAart.get().isFlagQtaCnfFissaBoolean()) { + + this.sendError(new OverflowQtaTotOrderedQuantityException()); + onValidated.run(false); + return; + } + + if (!this.canOverflowOrderQuantity && UtilityBigDecimal.greaterThan(this.internalNumCnf, this.totalNumCnfOrd) && + !this.mtbAart.get().isFlagQtaCnfFissaBoolean()) { + + this.sendError(new OverflowNumCnfOrderedQuantityException()); + onValidated.run(false); + return; + } + + if (UtilityBigDecimal.greaterThan(this.internalQtaTot, this.totalQtaAvailable)) { + + this.sendError(new OverflowQtaTotAvailableQuantityException()); + onValidated.run(false); + return; + } + + if (UtilityBigDecimal.greaterThan(this.internalNumCnf, this.totalNumCnfAvailable) && + !this.mtbAart.get().isFlagQtaCnfFissaBoolean()) { + + this.sendError(new OverflowNumCnfAvailableQuantityException()); + onValidated.run(false); + return; + } + + if (!this.canInputZeroQuantity && (this.internalNumCnf == null || this.internalQtaCnf == null || this.internalQtaTot == null || + UtilityBigDecimal.equalsOrLowerThan(this.internalNumCnf, BigDecimal.ZERO) || + UtilityBigDecimal.equalsOrLowerThan(this.internalQtaCnf, BigDecimal.ZERO) || + UtilityBigDecimal.equalsOrLowerThan(this.internalQtaTot, BigDecimal.ZERO))) { + + this.sendError(new InvalidQuantityException()); + onValidated.run(false); + return; + } + + if (this.isNoteMandatory() && (this.internalNote == null || this.internalNote.length() <= 0)) { + this.sendError(new InvalidNotesException()); + onValidated.run(false); + return; + } + + if (!UtilityString.isNullOrEmpty(this.internalPartitaMag)) + this.internalPartitaMag = this.internalPartitaMag.toUpperCase(); + + if (this.warnOnQuantityOverflow && UtilityBigDecimal.greaterThan(this.internalQtaTot, this.totalQtaOrd) && + this.mtbAart.get().isFlagQtaCnfFissaBoolean()) { + + boolean result = runWarningDialogSyncronized(UtilityResources.getString(R.string.confirm_ordered_quantity_overflow_error_message)); + if (!result) { onValidated.run(false); return; } + } - if (!this.canOverflowOrderQuantity && UtilityBigDecimal.greaterThan(this.internalQtaTot, this.totalQtaOrd) && - this.mtbAart.get().isFlagQtaCnfFissaBoolean()) { + if (this.warnOnQuantityOverflow && UtilityBigDecimal.greaterThan(this.internalNumCnf, this.totalNumCnfOrd) && + !this.mtbAart.get().isFlagQtaCnfFissaBoolean()) { - this.sendError(new OverflowQtaTotOrderedQuantityException()); + boolean result = runWarningDialogSyncronized(UtilityResources.getString(R.string.confirm_ordered_num_cnf_overflow_error_message)); + if (!result) { onValidated.run(false); return; } + } - if (!this.canOverflowOrderQuantity && UtilityBigDecimal.greaterThan(this.internalNumCnf, this.totalNumCnfOrd) && - !this.mtbAart.get().isFlagQtaCnfFissaBoolean()) { - - this.sendError(new OverflowNumCnfOrderedQuantityException()); - onValidated.run(false); - return; - } - - if (UtilityBigDecimal.greaterThan(this.internalQtaTot, this.totalQtaAvailable)) { - - this.sendError(new OverflowQtaTotAvailableQuantityException()); - onValidated.run(false); - return; - } - - if (UtilityBigDecimal.greaterThan(this.internalNumCnf, this.totalNumCnfAvailable) && - !this.mtbAart.get().isFlagQtaCnfFissaBoolean()) { - - this.sendError(new OverflowNumCnfAvailableQuantityException()); - onValidated.run(false); - return; - } - - if (!this.canInputZeroQuantity && (this.internalNumCnf == null || this.internalQtaCnf == null || this.internalQtaTot == null || - UtilityBigDecimal.equalsOrLowerThan(this.internalNumCnf, BigDecimal.ZERO) || - UtilityBigDecimal.equalsOrLowerThan(this.internalQtaCnf, BigDecimal.ZERO) || - UtilityBigDecimal.equalsOrLowerThan(this.internalQtaTot, BigDecimal.ZERO))) { - - this.sendError(new InvalidQuantityException()); - onValidated.run(false); - return; - } - - if (this.isNoteMandatory() && (this.internalNote == null || this.internalNote.length() <= 0)) { - this.sendError(new InvalidNotesException()); - onValidated.run(false); - return; - } - - if (!UtilityString.isNullOrEmpty(this.internalPartitaMag)) - this.internalPartitaMag = this.internalPartitaMag.toUpperCase(); - - if (this.warnOnQuantityOverflow && UtilityBigDecimal.greaterThan(this.internalQtaTot, this.totalQtaOrd) && - this.mtbAart.get().isFlagQtaCnfFissaBoolean()) { - - boolean result = runWarningDialogSyncronized(UtilityResources.getString(R.string.confirm_ordered_quantity_overflow_error_message)); - if (!result) { - onValidated.run(false); - return; - } - } - - if (this.warnOnQuantityOverflow && UtilityBigDecimal.greaterThan(this.internalNumCnf, this.totalNumCnfOrd) && - !this.mtbAart.get().isFlagQtaCnfFissaBoolean()) { - - boolean result = runWarningDialogSyncronized(UtilityResources.getString(R.string.confirm_ordered_num_cnf_overflow_error_message)); - if (!result) { - onValidated.run(false); - return; - } - } - - onValidated.run(true); - }).start(); + onValidated.run(true); } private boolean runWarningDialogSyncronized(String text) { @@ -696,7 +682,8 @@ public class DialogInputQuantityV2ViewModel { .setNumCnf(this.internalNumCnf) .setQtaCnf(this.internalQtaCnf) .setNote(this.internalNote) - .setQtaTot(this.internalQtaTot); + .setQtaTot(this.internalQtaTot) + .setNextUlBarcode(this.internalNextUlBarcode); } public void setListener(Listener listener) { @@ -738,11 +725,17 @@ public class DialogInputQuantityV2ViewModel { if (this.mListener != null) mListener.onLoadingEnded(); } + private void sendOnULCloseRequested() { + if (this.mListener != null) mListener.onULCloseRequested(); + } + public interface Listener extends ILoadingListener { void onDataChanged(); void onError(Exception ex); void onWarning(String text, RunnableArgs result); + + void onULCloseRequested(); } } diff --git a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/scan_art/DialogScanArtView.java b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/scan_art/DialogScanArtView.java index 6938c66d..a5f09312 100644 --- a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/scan_art/DialogScanArtView.java +++ b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/scan_art/DialogScanArtView.java @@ -41,7 +41,7 @@ public class DialogScanArtView extends BaseDialogFragment implements DialogScanA private DialogScanArtBinding mBindings; - private int mBarcodeScannerIstanceID; + private int mBarcodeScannerInstanceID; private RunnableArgssss onPickingCompleted = null; private RunnableArgs onMagazzinoAutomaticoPickingRequest = null; @@ -89,17 +89,17 @@ public class DialogScanArtView extends BaseDialogFragment implements DialogScanA @Override public void onDismiss(@NonNull DialogInterface dialog) { - BarcodeManager.removeCallback(mBarcodeScannerIstanceID); - BarcodeManager.enable(); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); + BarcodeManager.enable(mBarcodeScannerInstanceID); super.onDismiss(dialog); } private void initBarcode() { - mBarcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessfull) .setOnScanFailed(this::onError)); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); setBarcodeListener(true); } @@ -145,6 +145,6 @@ public class DialogScanArtView extends BaseDialogFragment implements DialogScanA @Override public void onError(Exception ex) { super.onError(ex); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); } } diff --git a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/scan_or_create_lu/DialogScanOrCreateLUView.java b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/scan_or_create_lu/DialogScanOrCreateLUView.java index ffd5aae7..5a47ae4a 100644 --- a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/scan_or_create_lu/DialogScanOrCreateLUView.java +++ b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/scan_or_create_lu/DialogScanOrCreateLUView.java @@ -35,7 +35,7 @@ public class DialogScanOrCreateLUView extends BaseDialogFragment implements Dial DialogScanOrCreateLUViewModel mViewModel; private DialogScanOrCreateLuBinding mBindings; - private int mBarcodeScannerIstanceID; + private int mBarcodeScannerInstanceID; private final RunnableArgss mOnComplete; private MtbColt openedMtbColt; @@ -116,8 +116,8 @@ public class DialogScanOrCreateLUView extends BaseDialogFragment implements Dial @Override public void onDismiss(@NonNull DialogInterface dialog) { - BarcodeManager.removeCallback(mBarcodeScannerIstanceID); - BarcodeManager.enable(); + BarcodeManager.removeCallback(mBarcodeScannerInstanceID); + BarcodeManager.enable(mBarcodeScannerInstanceID); if (openedMtbColt == null) { mOnComplete.run(null, false); } @@ -126,10 +126,10 @@ public class DialogScanOrCreateLUView extends BaseDialogFragment implements Dial private void initBarcode() { - mBarcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() + mBarcodeScannerInstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO() .setOnScanSuccessful(onScanSuccessfull) .setOnScanFailed(this::onError)); - BarcodeManager.enable(); + BarcodeManager.enable(mBarcodeScannerInstanceID); setBarcodeListener(true); } diff --git a/app/src/main/res/layout/fragment_main_ordini_uscita__list_group_model.xml b/app/src/main/res/layout/fragment_main_ordini_uscita__list_group_model.xml index 2d522cb1..38792a6d 100644 --- a/app/src/main/res/layout/fragment_main_ordini_uscita__list_group_model.xml +++ b/app/src/main/res/layout/fragment_main_ordini_uscita__list_group_model.xml @@ -11,7 +11,7 @@ - - - + - + \ No newline at end of file