Merge branch 'feature/RefactoringGestioneColli' into master-beta
This commit is contained in:
@@ -35,7 +35,6 @@ import it.integry.integrywmsnative.core.expansion.BaseDialogFragment;
|
||||
import it.integry.integrywmsnative.core.expansion.RunnableArgss;
|
||||
import it.integry.integrywmsnative.core.model.VtbDest;
|
||||
import it.integry.integrywmsnative.core.rest.consumers.SystemRESTConsumer;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityDialog;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityHashMap;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityString;
|
||||
import it.integry.integrywmsnative.databinding.DialogAskClienteBinding;
|
||||
@@ -115,7 +114,7 @@ public class DialogAskClienteView extends BaseDialogFragment {
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
UtilityDialog.setTo90PercentWidth(this.mContext, this);
|
||||
// UtilityDialog.setTo90PercentWidth(this.mContext, this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import com.annimon.stream.Optional;
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import it.integry.barcode_base_android_library.model.BarcodeScanDTO;
|
||||
import it.integry.integrywmsnative.R;
|
||||
@@ -130,21 +129,17 @@ public class DialogAskCliente_Page1ViewModel implements IDialogAskClienteViewMod
|
||||
|
||||
|
||||
private DialogAskClienteClienteDTO searchBarcodeInCodAnag(String barcode) {
|
||||
List<DialogAskClienteClienteDTO> resultCodAnag = Stream.of(availableClienti)
|
||||
return availableClienti.stream()
|
||||
.filter(x -> barcode.equalsIgnoreCase(x.getCodAnag()))
|
||||
.toList();
|
||||
if (!resultCodAnag.isEmpty()) {
|
||||
return resultCodAnag.get(0);
|
||||
} else return null;
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private DialogAskClienteClienteDTO searchBarcodeInCodJcom(String barcode) {
|
||||
List<DialogAskClienteClienteDTO> resultCodJcom = Stream.of(availableClienti)
|
||||
return availableClienti.stream()
|
||||
.filter(x -> x.getCodJcoms().contains(barcode))
|
||||
.toList();
|
||||
if (!resultCodJcom.isEmpty()) {
|
||||
return resultCodJcom.get(0);
|
||||
} else return null;
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.WindowManager;
|
||||
|
||||
@@ -16,6 +17,7 @@ import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -38,6 +40,12 @@ public class DialogAskCommessaView extends BaseDialogFragment implements DialogA
|
||||
@Inject
|
||||
DialogAskCommessaViewModel mViewModel;
|
||||
|
||||
@Inject
|
||||
ExecutorService executorService;
|
||||
|
||||
@Inject
|
||||
Handler handler;
|
||||
|
||||
private final RunnableArgs<JtbComt> onComplete;
|
||||
private final Runnable onAbort;
|
||||
|
||||
@@ -100,12 +108,7 @@ public class DialogAskCommessaView extends BaseDialogFragment implements DialogA
|
||||
|
||||
var positiveButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
|
||||
positiveButton.setOnClickListener(view -> {
|
||||
if (selectedJtbComt != null) {
|
||||
this.onComplete.run(this.selectedJtbComt);
|
||||
alertDialog.dismiss();
|
||||
} else {
|
||||
Snackbar.make(mContext, mBindings.getRoot(), "Seleziona una commessa prima di procedere", Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
onCommessaSelected(selectedJtbComt);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -120,8 +123,16 @@ public class DialogAskCommessaView extends BaseDialogFragment implements DialogA
|
||||
public void onInit(DialogInterface dialogInterface) {
|
||||
this.initBarcode();
|
||||
|
||||
this.mViewModel.getCommesseListLiveData().observe(this, this::onCommesseLoaded);
|
||||
this.mViewModel.setListener(this);
|
||||
|
||||
executorService.execute(() -> {
|
||||
try {
|
||||
this.mViewModel.init();
|
||||
} catch (Exception e) {
|
||||
onError(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initBarcode() {
|
||||
@@ -134,13 +145,16 @@ public class DialogAskCommessaView extends BaseDialogFragment implements DialogA
|
||||
|
||||
private final RunnableArgs<BarcodeScanDTO> onScanSuccessful = data -> {
|
||||
BarcodeManager.disable(mBarcodeScannerInstanceID);
|
||||
// this.mViewModel.processBarcodeDTO(data, BarcodeManager::enable);
|
||||
|
||||
executorService.execute(() -> {
|
||||
this.mViewModel.processBarcodeDTO(data);
|
||||
BarcodeManager.enable(mBarcodeScannerInstanceID);
|
||||
});
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCommesseLoaded(List<JtbComt> dataList) {
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
|
||||
private void onCommesseLoaded(List<JtbComt> dataList) {
|
||||
handler.post(() -> {
|
||||
var listModel = dataList.stream()
|
||||
.map(x -> new SimpleAutoCompleteTwoLinesDropdownListModel<JtbComt>()
|
||||
.setTitle(x.getCodJcom())
|
||||
@@ -165,4 +179,18 @@ public class DialogAskCommessaView extends BaseDialogFragment implements DialogA
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommessaSelected(JtbComt commessa) {
|
||||
selectedJtbComt = commessa;
|
||||
|
||||
var alertDialog = ((AlertDialog) getDialog());
|
||||
|
||||
if (selectedJtbComt != null) {
|
||||
this.onComplete.run(this.selectedJtbComt);
|
||||
alertDialog.dismiss();
|
||||
} else {
|
||||
Snackbar.make(mContext, mBindings.getRoot(), "Seleziona una commessa prima di procedere", Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package it.integry.integrywmsnative.view.dialogs.ask_commessa;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
@@ -8,6 +11,7 @@ import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import it.integry.barcode_base_android_library.model.BarcodeScanDTO;
|
||||
import it.integry.integrywmsnative.core.interfaces.viewmodel_listeners.ILoadingListener;
|
||||
import it.integry.integrywmsnative.core.model.JtbComt;
|
||||
import it.integry.integrywmsnative.core.rest.consumers.SystemRESTConsumer;
|
||||
@@ -18,26 +22,46 @@ public class DialogAskCommessaViewModel {
|
||||
|
||||
private Listener mListener;
|
||||
|
||||
private final MutableLiveData<List<JtbComt>> commesseListLiveData = new MutableLiveData<>();
|
||||
|
||||
|
||||
@Inject
|
||||
public DialogAskCommessaViewModel(SystemRESTConsumer systemRESTConsumer) {
|
||||
this.systemRESTConsumer = systemRESTConsumer;
|
||||
}
|
||||
|
||||
public LiveData<List<JtbComt>> getCommesseListLiveData() {
|
||||
return commesseListLiveData;
|
||||
}
|
||||
|
||||
public void init() throws Exception {
|
||||
Type jtbComtListType = new TypeToken<ArrayList<JtbComt>>() {
|
||||
}.getType();
|
||||
|
||||
public void init() {
|
||||
Type jtbComtListType = new TypeToken<ArrayList<JtbComt>>() {}.getType();
|
||||
var data = this.systemRESTConsumer.<List<JtbComt>>processSqlSynchronized("SELECT * \n" +
|
||||
"FROM jtb_comt \n" +
|
||||
"WHERE ISNULL(stato_commessa, '') <> 'CHIUSA'", jtbComtListType);
|
||||
|
||||
this.systemRESTConsumer.<List<JtbComt>>processSql("SELECT * " +
|
||||
"FROM jtb_comt " +
|
||||
"WHERE ISNULL(stato_commessa, '') <> 'CHIUSA'", jtbComtListType, data -> {
|
||||
|
||||
this.sendOnCommesseLoaded(data);
|
||||
|
||||
}, this::sendError);
|
||||
commesseListLiveData.postValue(data);
|
||||
}
|
||||
|
||||
|
||||
public void processBarcodeDTO(BarcodeScanDTO data) {
|
||||
if (data.getStringValue() == null || data.getStringValue().isEmpty()) {
|
||||
sendError(new Exception("Codice a barre non valido"));
|
||||
return;
|
||||
}
|
||||
|
||||
var commessa = commesseListLiveData.getValue().stream()
|
||||
.filter(c -> c.getCodJcom().equals(data.getStringValue()))
|
||||
.findFirst();
|
||||
|
||||
if (commessa.isPresent()) {
|
||||
this.sendOnCommessaSelected(commessa.get());
|
||||
} else {
|
||||
sendError(new Exception("Codice a barre non trovato"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void sendOnLoadingStarted() {
|
||||
@@ -48,12 +72,12 @@ public class DialogAskCommessaViewModel {
|
||||
if (this.mListener != null) mListener.onLoadingEnded();
|
||||
}
|
||||
|
||||
private void sendError(Exception ex) {
|
||||
if (this.mListener != null) mListener.onError(ex);
|
||||
private void sendOnCommessaSelected(JtbComt commessa) {
|
||||
if (this.mListener != null) mListener.onCommessaSelected(commessa);
|
||||
}
|
||||
|
||||
private void sendOnCommesseLoaded(List<JtbComt> commesseList) {
|
||||
if (this.mListener != null) mListener.onCommesseLoaded(commesseList);
|
||||
private void sendError(Exception ex) {
|
||||
if (this.mListener != null) mListener.onError(ex);
|
||||
}
|
||||
|
||||
public DialogAskCommessaViewModel setListener(Listener listener) {
|
||||
@@ -62,7 +86,7 @@ public class DialogAskCommessaViewModel {
|
||||
}
|
||||
|
||||
interface Listener extends ILoadingListener {
|
||||
void onCommesseLoaded(List<JtbComt> dataList);
|
||||
void onCommessaSelected(JtbComt commessa);
|
||||
|
||||
void onError(Exception ex);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user