Rimossi mutable live data sulle variabili interne della gestione Documenti Interni

This commit is contained in:
Giuseppe Scorrano 2023-03-29 10:19:56 +02:00
parent fa413aba25
commit 6f2be2b459

View File

@ -37,12 +37,12 @@ public class DocInterniViewModel {
private List<DocumentoArtDTO> availableArts; private List<DocumentoArtDTO> availableArts;
private MutableLiveData<List<DocInternoWrapper>> mDocsList = new MutableLiveData<>(); private MutableLiveData<List<DocInternoWrapper>> mDocsList = new MutableLiveData<>();
public final MutableLiveData<TipoDocDTO> dtbTipi = new MutableLiveData<>(); public TipoDocDTO dtbTipi;
public final MutableLiveData<GruppoArticoloDTO> mtbGrup = new MutableLiveData<>(); public GruppoArticoloDTO mtbGrup;
public final MutableLiveData<FornitoreDTO> fornitore = new MutableLiveData<>(); public FornitoreDTO fornitore;
public final MutableLiveData<Date> dataDoc = new MutableLiveData<>(); public Date dataDoc;
public final MutableLiveData<String> numDoc = new MutableLiveData<>(); public String numDoc;
public final MutableLiveData<String> note = new MutableLiveData<>(); public String note;
public final BindableInteger artsSize = new BindableInteger(0); public final BindableInteger artsSize = new BindableInteger(0);
@Inject @Inject
@ -86,13 +86,13 @@ public class DocInterniViewModel {
} }
public void setSelectedDocDetails(DialogSelectDocInfoResponseDTO selection) { public void setSelectedDocDetails(DialogSelectDocInfoResponseDTO selection) {
this.fornitore.postValue(selection.getFornitore()); this.fornitore = selection.getFornitore();
this.dtbTipi.postValue(selection.getTipoDoc()); this.dtbTipi = selection.getTipoDoc();
this.mtbGrup.postValue(selection.getGruppoArt()); this.mtbGrup = selection.getGruppoArt();
this.dataDoc.postValue(selection.getDataDoc()); this.dataDoc = selection.getDataDoc();
this.numDoc.postValue(selection.getNumDoc() != null ? selection.getNumDoc().toString() : null); this.numDoc = selection.getNumDoc() != null ? selection.getNumDoc().toString() : null;
this.note.postValue(selection.getNote()); this.note = selection.getNote();
this.sendOnLoadingStarted(); this.sendOnLoadingStarted();
fetchProducts(() -> { fetchProducts(() -> {
@ -118,7 +118,7 @@ public class DocInterniViewModel {
String codAnag = null; String codAnag = null;
String codVdes = null; String codVdes = null;
FornitoreDTO fornitore = this.fornitore.getValue(); FornitoreDTO fornitore = this.fornitore;
if (fornitore != null) { if (fornitore != null) {
codAnag = fornitore.getCodAnag(); codAnag = fornitore.getCodAnag();
codVdes = fornitore.getCodVdes(); codVdes = fornitore.getCodVdes();
@ -126,7 +126,7 @@ public class DocInterniViewModel {
var docsList = documentRepository.getDocuments(this.getCodDtip(), var docsList = documentRepository.getDocuments(this.getCodDtip(),
codAnag, codVdes, dataDoc.getValue(), numDoc.getValue()); codAnag, codVdes, dataDoc, numDoc);
docsList.observeForever(data -> { docsList.observeForever(data -> {
this.mDocsList.postValue(data); this.mDocsList.postValue(data);
@ -145,31 +145,28 @@ public class DocInterniViewModel {
} }
private String getCodDtip() { private String getCodDtip() {
if (this.dtbTipi.getValue() == null) { if (this.dtbTipi == null) {
return null; return null;
} }
return this.dtbTipi.getValue().getCodDtip(); return this.dtbTipi.getCodDtip();
} }
public TipoDocDTO getTipoDoc() { public TipoDocDTO getTipoDoc() {
if (this.dtbTipi.getValue() == null) { return this.dtbTipi;
return null;
}
return this.dtbTipi.getValue();
} }
private String getCodMgrp() { private String getCodMgrp() {
if (this.mtbGrup.getValue() == null) { if (this.mtbGrup == null) {
return null; return null;
} }
return this.mtbGrup.getValue().getCodMgrp(); return this.mtbGrup.getCodMgrp();
} }
private String getCodAnagForn() { private String getCodAnagForn() {
if (this.fornitore.getValue() == null) { if (this.fornitore == null) {
return null; return null;
} }
return this.fornitore.getValue().getCodAnag(); return this.fornitore.getCodAnag();
} }
public void editDocument(SqlMtbColt document) { public void editDocument(SqlMtbColt document) {
@ -178,7 +175,7 @@ public class DocInterniViewModel {
public void newDocument() { public void newDocument() {
SqlMtbColt document = new SqlMtbColt(); SqlMtbColt document = new SqlMtbColt();
if (this.dtbTipi.getValue() == null) { if (this.dtbTipi == null) {
this.sendError(new NoDocTypeSelectedException()); this.sendError(new NoDocTypeSelectedException());
return; return;
} }
@ -186,18 +183,18 @@ public class DocInterniViewModel {
document.setCodMgrp(this.getCodMgrp()); document.setCodMgrp(this.getCodMgrp());
document.setDataCollo(new Date()); document.setDataCollo(new Date());
document.setCodMdep(SettingsManager.i().getUserSession().getDepo().getCodMdep()); document.setCodMdep(SettingsManager.i().getUserSession().getDepo().getCodMdep());
document.setAnnotazioni(this.note.getValue()); document.setAnnotazioni(this.note);
document.setSegno(-1); document.setSegno(-1);
document.setSerCollo("/"); document.setSerCollo("/");
document.setNumCollo(this.nextNumCollo); document.setNumCollo(this.nextNumCollo);
document.setGestione("L"); document.setGestione("L");
document.setDataDoc(this.dataDoc.getValue()); document.setDataDoc(this.dataDoc);
if (this.numDoc.getValue() != null) { if (this.numDoc != null) {
document.setNumDoc(Integer.parseInt(this.numDoc.getValue())); document.setNumDoc(Integer.parseInt(this.numDoc));
} }
if (this.fornitore.getValue() != null) { if (this.fornitore != null) {
document.setCodAnag(this.fornitore.getValue().getCodAnag()); document.setCodAnag(this.fornitore.getCodAnag());
document.setCodVdes(this.fornitore.getValue().getCodVdes()); document.setCodVdes(this.fornitore.getCodVdes());
} }
documentRepository.insert(document, id -> { documentRepository.insert(document, id -> {
document.setId(id); document.setId(id);
@ -206,7 +203,7 @@ public class DocInterniViewModel {
} }
public boolean hasDocDetails() { public boolean hasDocDetails() {
return this.dtbTipi.getValue() != null; return this.dtbTipi != null;
} }
public interface Listener extends ILoadingListener { public interface Listener extends ILoadingListener {