From 0312f972bcf04391f08004beb0ffed269123b614 Mon Sep 17 00:00:00 2001 From: GiuseppeS Date: Wed, 26 Feb 2025 19:01:04 +0100 Subject: [PATCH] Refactor: Update weight input dialog and LU closing logic - Changed `DialogInputPesoLUView` to use `BindableBigDecimal` for weight fields. - Updated `DialogInputPesoLUView` to invoke onComplete only after user confirmation - Refactored `SpedizioneViewModel` to correctly set values coming from the weight input dialog - Removed commented-out code in `SpedizioneViewModel` - Added handling for null values in weight fields. - `SpedizioneActivity` changed to pass current values to `DialogInputPesoLUView` - Fixed recovery mode UI not collapsing --- .../gest/main/MainFragment.java | 7 +- .../gest/spedizione/SpedizioneActivity.java | 4 +- .../gest/spedizione/SpedizioneViewModel.java | 94 +------------------ .../input_peso_lu/DialogInputPesoLUView.java | 16 +++- 4 files changed, 23 insertions(+), 98 deletions(-) diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/main/MainFragment.java b/app/src/main/java/it/integry/integrywmsnative/gest/main/MainFragment.java index 1873e18b..039296a5 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/main/MainFragment.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/main/MainFragment.java @@ -6,6 +6,7 @@ import android.animation.ObjectAnimator; import android.content.Context; import android.graphics.Color; import android.os.Bundle; +import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -70,6 +71,8 @@ public class MainFragment extends Fragment implements ITitledFragment, IScrollab @Inject ColliLavorazioneRESTConsumer colliLavorazioneRESTConsumer; + @Inject + Handler handler; @Inject MenuService menuService; @@ -267,7 +270,9 @@ public class MainFragment extends Fragment implements ITitledFragment, IScrollab } private void endRecoverMode() { - mBindings.recoverDataExpandableLayout.collapse(true); + handler.post(() -> { + mBindings.recoverDataExpandableLayout.collapse(true); + }); } @Override 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 5e9067fe..3f184b63 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 @@ -865,9 +865,7 @@ public class SpedizioneActivity extends BaseActivity implements SpedizioneViewMo @Override public void onLUPesoRequired(String codTcol, BigDecimal netWeightKG, BigDecimal grossWeightKG, RunnableArgsss onComplete) { handler.post(() -> { - DialogInputPesoLUView.newInstance(null, new BigDecimal(50), new BigDecimal(55), (newCodTcol, newNetWeight, newGrossWeight) -> { - onComplete.run(newCodTcol, netWeightKG, grossWeightKG); - }) + DialogInputPesoLUView.newInstance(codTcol, netWeightKG, grossWeightKG, onComplete) .show(getSupportFragmentManager(), "tag"); }); } 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 1a82be96..52b13d29 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 @@ -1682,92 +1682,6 @@ public class SpedizioneViewModel { this.sendOnLoadingEnded(); } -// 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(); @@ -1948,9 +1862,10 @@ public class SpedizioneViewModel { this.sendLUPesoRequired(mCurrentMtbColt.getCodTcol(), mCurrentMtbColt.getPesoNettoKg(), mCurrentMtbColt.getPesoKg(), (newCodTcol, newNetWeight, newGrossWeight) -> { - mCurrentMtbColt.setCodTcol(newCodTcol); - mCurrentMtbColt.setPesoNettoKg(newNetWeight); - mCurrentMtbColt.setPesoKg(newGrossWeight); + + if(newCodTcol != null) mCurrentMtbColt.setCodTcol(newCodTcol); + if(newNetWeight != null) mCurrentMtbColt.setPesoNettoKg(newNetWeight); + if(newGrossWeight != null) mCurrentMtbColt.setPesoKg(newGrossWeight); latch.countDown(); }); @@ -2047,6 +1962,7 @@ public class SpedizioneViewModel { this.sendLUPrintRequest(shouldPrint -> { if (!shouldPrint) { + latch.countDown(); return; } diff --git a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_peso_lu/DialogInputPesoLUView.java b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_peso_lu/DialogInputPesoLUView.java index 015e0263..6ee8a97d 100644 --- a/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_peso_lu/DialogInputPesoLUView.java +++ b/app/src/main/java/it/integry/integrywmsnative/view/dialogs/input_peso_lu/DialogInputPesoLUView.java @@ -20,6 +20,7 @@ import javax.inject.Inject; import it.integry.integrywmsnative.MainApplication; import it.integry.integrywmsnative.R; +import it.integry.integrywmsnative.core.di.BindableBigDecimal; import it.integry.integrywmsnative.core.di.BindableString; import it.integry.integrywmsnative.core.expansion.BaseDialogFragment; import it.integry.integrywmsnative.core.expansion.RunnableArgsss; @@ -27,7 +28,6 @@ import it.integry.integrywmsnative.core.model.MtbTCol; import it.integry.integrywmsnative.core.model.observable.ObservableMtbTcol; import it.integry.integrywmsnative.core.rest.consumers.ImballiRESTConsumer; import it.integry.integrywmsnative.core.settings.SettingsManager; -import it.integry.integrywmsnative.core.utility.UtilityNumber; import it.integry.integrywmsnative.databinding.DialogInputPesoLuBinding; public class DialogInputPesoLUView extends BaseDialogFragment { @@ -44,8 +44,8 @@ public class DialogInputPesoLUView extends BaseDialogFragment { private RunnableArgsss onDialogDismiss; public BindableString codTcol = new BindableString(); - public BindableString netWeight = new BindableString(); - public BindableString grossWeight = new BindableString(); + public BindableBigDecimal netWeight = new BindableBigDecimal(); + public BindableBigDecimal grossWeight = new BindableBigDecimal(); private List codTcolList = null; @@ -62,8 +62,8 @@ public class DialogInputPesoLUView extends BaseDialogFragment { this.onDialogDismiss = onDialogDismiss; this.codTcol.set(codTcol); - this.netWeight.set(UtilityNumber.decimalToString(netWeight)); - this.grossWeight.set(UtilityNumber.decimalToString(grossWeight)); + this.netWeight.set(netWeight); + this.grossWeight.set(grossWeight); } @@ -88,6 +88,12 @@ public class DialogInputPesoLUView extends BaseDialogFragment { var alertDialog = new MaterialAlertDialogBuilder(this.mContext) .setView(mBindings.getRoot()) .setCancelable(isCancelable()) + .setPositiveButton(R.string.confirm, (dialogInterface, i) -> { + onDialogDismiss.run(codTcol.get(), netWeight.get(), grossWeight.get()); + }) + .setNegativeButton(R.string.abort, ((dialogInterface, i) -> { + onDialogDismiss.run(null, null, null); + })) .create(); alertDialog.setCanceledOnTouchOutside(isCancelable());