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
This commit is contained in:
Giuseppe Scorrano 2025-02-26 19:01:04 +01:00
parent 645045b492
commit 0312f972bc
4 changed files with 23 additions and 98 deletions

View File

@ -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() {
handler.post(() -> {
mBindings.recoverDataExpandableLayout.collapse(true);
});
}
@Override

View File

@ -865,9 +865,7 @@ public class SpedizioneActivity extends BaseActivity implements SpedizioneViewMo
@Override
public void onLUPesoRequired(String codTcol, BigDecimal netWeightKG, BigDecimal grossWeightKG, RunnableArgsss<String, BigDecimal, BigDecimal> 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");
});
}

View File

@ -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<List<MtbColt>> 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<MtbColt> 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;
}

View File

@ -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<String, BigDecimal, BigDecimal> 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<ObservableMtbTcol> 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());