Utilitzzati i live data nella lista dei documenti caricati da sqlite
This commit is contained in:
parent
c5eec26f8d
commit
68007ebc8e
@ -1,5 +1,6 @@
|
|||||||
package it.integry.integrywmsnative.core.data_store.db.dao;
|
package it.integry.integrywmsnative.core.data_store.db.dao;
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.room.Dao;
|
import androidx.room.Dao;
|
||||||
import androidx.room.Delete;
|
import androidx.room.Delete;
|
||||||
import androidx.room.Insert;
|
import androidx.room.Insert;
|
||||||
@ -33,7 +34,7 @@ public interface MtbColtDao {
|
|||||||
" AND ( mtb_colt.data_doc = :dataDoc OR (mtb_colt.data_doc is null and :dataDoc is null)) " +
|
" AND ( mtb_colt.data_doc = :dataDoc OR (mtb_colt.data_doc is null and :dataDoc is null)) " +
|
||||||
" AND ( mtb_colt.num_doc = :numDoc OR (mtb_colt.num_doc is null and :numDoc is null)) " +
|
" AND ( mtb_colt.num_doc = :numDoc OR (mtb_colt.num_doc is null and :numDoc is null)) " +
|
||||||
" and cod_dtip is null group by mtb_colt.id")
|
" and cod_dtip is null group by mtb_colt.id")
|
||||||
List<DocInternoWrapper> getLocalDocumentsByCodDtip(String codDtip, String codAnag, String codVdes, Date dataDoc, String numDoc);
|
LiveData<List<DocInternoWrapper>> getLocalDocumentsByCodDtip(String codDtip, String codAnag, String codVdes, Date dataDoc, String numDoc);
|
||||||
|
|
||||||
@Query("SELECT ifnull(MAX(num_collo),0) +1 as num_collo from mtb_colt")
|
@Query("SELECT ifnull(MAX(num_collo),0) +1 as num_collo from mtb_colt")
|
||||||
Integer getNextNumCollo();
|
Integer getNextNumCollo();
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
package it.integry.integrywmsnative.core.data_store.db.repository;
|
package it.integry.integrywmsnative.core.data_store.db.repository;
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -17,7 +19,7 @@ public interface MtbColtRepository {
|
|||||||
|
|
||||||
void delete(SqlMtbColt mtbColt, Runnable onSuccess, RunnableArgs<Exception> onError);
|
void delete(SqlMtbColt mtbColt, Runnable onSuccess, RunnableArgs<Exception> onError);
|
||||||
|
|
||||||
void getLocalDocumentsByCodDtip(String codDtip, String codAnag, String codVdes, Date dataDoc, String numDoc, RunnableArgs<List<DocInternoWrapper>> onSuccess, RunnableArgs<Exception> onError);
|
LiveData<List<DocInternoWrapper>> getDocuments(String codDtip, String codAnag, String codVdes, Date dataDoc, String numDoc);
|
||||||
|
|
||||||
void getNextNumCollo(RunnableArgs<Integer> onSuccess, RunnableArgs<Exception> onError);
|
void getNextNumCollo(RunnableArgs<Integer> onSuccess, RunnableArgs<Exception> onError);
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,8 @@ package it.integry.integrywmsnative.core.data_store.db.repository.datasource;
|
|||||||
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
@ -50,10 +52,8 @@ public class SqlMtbColtDataSource extends BaseDataSource implements MtbColtRepos
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getLocalDocumentsByCodDtip(String codDtip, String codAnag, String codVdes, Date dataDoc, String numDoc, RunnableArgs<List<DocInternoWrapper>> onSuccess, RunnableArgs<Exception> onError) {
|
public LiveData<List<DocInternoWrapper>> getDocuments(String codDtip, String codAnag, String codVdes, Date dataDoc, String numDoc) {
|
||||||
execute(() -> mMtbColtDao.getLocalDocumentsByCodDtip(codDtip, codAnag, codVdes, dataDoc, numDoc),
|
return mMtbColtDao.getLocalDocumentsByCodDtip(codDtip, codAnag, codVdes, dataDoc, numDoc);
|
||||||
onSuccess,
|
|
||||||
onError);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -53,7 +53,7 @@ public class DocumentRESTConsumer extends _BaseRESTConsumer {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void loadDocumentoAvailableArts(String codDtip, String codMgrp, String codAnagForn, RunnableArgs<RetrieveDocumentoArtsResponseDTO> onComplete, RunnableArgs<Exception> onFailed) {
|
public void loadDocumentAvailableArts(String codDtip, String codMgrp, String codAnagForn, RunnableArgs<RetrieveDocumentoArtsResponseDTO> onComplete, RunnableArgs<Exception> onFailed) {
|
||||||
var inventarioRESTConsumerService = RESTBuilder.getService(DocumentiRESTConsumerService.class);
|
var inventarioRESTConsumerService = RESTBuilder.getService(DocumentiRESTConsumerService.class);
|
||||||
inventarioRESTConsumerService.retrieveArts(codDtip, codMgrp, codAnagForn)
|
inventarioRESTConsumerService.retrieveArts(codDtip, codMgrp, codAnagForn)
|
||||||
.enqueue(new Callback<>() {
|
.enqueue(new Callback<>() {
|
||||||
|
|||||||
@ -85,8 +85,6 @@ public class DocInterniFragment extends BaseFragment implements ITitledFragment,
|
|||||||
mBinding.setView(this);
|
mBinding.setView(this);
|
||||||
mBinding.setViewModel(mViewModel);
|
mBinding.setViewModel(mViewModel);
|
||||||
|
|
||||||
mViewModel.mtbGrup.observe(getViewLifecycleOwner(), mtbGrup -> mViewModel.fetchProducts());
|
|
||||||
mViewModel.dtbTipi.observe(getViewLifecycleOwner(), dtbTipi -> mViewModel.fetchDocuments());
|
|
||||||
this.initRecyclerView();
|
this.initRecyclerView();
|
||||||
|
|
||||||
return mBinding.getRoot();
|
return mBinding.getRoot();
|
||||||
@ -100,7 +98,8 @@ public class DocInterniFragment extends BaseFragment implements ITitledFragment,
|
|||||||
if (!this.mViewModel.hasDocDetails()) {
|
if (!this.mViewModel.hasDocDetails()) {
|
||||||
mViewModel.init();
|
mViewModel.init();
|
||||||
} else {
|
} else {
|
||||||
this.mViewModel.fetchDocuments();
|
this.onLoadingStarted();
|
||||||
|
this.mViewModel.fetchDocuments(this::onLoadingEnded);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +145,6 @@ public class DocInterniFragment extends BaseFragment implements ITitledFragment,
|
|||||||
} else {
|
} else {
|
||||||
mBinding.docContainer.setVisibility(View.GONE);
|
mBinding.docContainer.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -167,12 +165,9 @@ public class DocInterniFragment extends BaseFragment implements ITitledFragment,
|
|||||||
.show(requireActivity().getSupportFragmentManager(), "tag");
|
.show(requireActivity().getSupportFragmentManager(), "tag");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showInfoArtDialog() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initRecyclerView() {
|
private void initRecyclerView() {
|
||||||
this.mViewModel.getDocsList().observe(getViewLifecycleOwner(), this::refreshList);
|
this.mViewModel.getDocsList().observe(getViewLifecycleOwner(), this::refreshList);
|
||||||
|
|
||||||
DocInterniListAdapter docInterniListAdapter = new DocInterniListAdapter(this.requireActivity(), this.mDocInterniMutableData);
|
DocInterniListAdapter docInterniListAdapter = new DocInterniListAdapter(this.requireActivity(), this.mDocInterniMutableData);
|
||||||
docInterniListAdapter.setEmptyView(this.mBinding.docInterniEmptyView);
|
docInterniListAdapter.setEmptyView(this.mBinding.docInterniEmptyView);
|
||||||
this.mBinding.docInterniMainList.setAdapter(docInterniListAdapter);
|
this.mBinding.docInterniMainList.setAdapter(docInterniListAdapter);
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
package it.integry.integrywmsnative.gest.contab_doc_interni;
|
package it.integry.integrywmsnative.gest.contab_doc_interni;
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ public class DocInterniViewModel {
|
|||||||
private boolean docsFetched = true;
|
private boolean docsFetched = true;
|
||||||
private int nextNumCollo = 0;
|
private int nextNumCollo = 0;
|
||||||
private List<DocumentoArtDTO> availableArts;
|
private List<DocumentoArtDTO> availableArts;
|
||||||
private final MutableLiveData<List<DocInternoWrapper>> mDocsList = new MutableLiveData<>();
|
private MutableLiveData<List<DocInternoWrapper>> mDocsList = new MutableLiveData<>();
|
||||||
|
|
||||||
public final MutableLiveData<TipoDocDTO> dtbTipi = new MutableLiveData<>();
|
public final MutableLiveData<TipoDocDTO> dtbTipi = new MutableLiveData<>();
|
||||||
public final MutableLiveData<GruppoArticoloDTO> mtbGrup = new MutableLiveData<>();
|
public final MutableLiveData<GruppoArticoloDTO> mtbGrup = new MutableLiveData<>();
|
||||||
@ -52,8 +52,6 @@ public class DocInterniViewModel {
|
|||||||
this.docInterniRESTConsumer = docInterniRESTConsumer;
|
this.docInterniRESTConsumer = docInterniRESTConsumer;
|
||||||
this.documentRepository = documentRepository;
|
this.documentRepository = documentRepository;
|
||||||
this.documentRESTConsumer = documentRESTConsumer;
|
this.documentRESTConsumer = documentRESTConsumer;
|
||||||
|
|
||||||
this.mDocsList.setValue(new ArrayList<>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -83,12 +81,11 @@ public class DocInterniViewModel {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MutableLiveData<List<DocInternoWrapper>> getDocsList() {
|
public LiveData<List<DocInternoWrapper>> getDocsList() {
|
||||||
return mDocsList;
|
return mDocsList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSelectedDocDetails(DialogSelectDocInfoResponseDTO selection) {
|
public void setSelectedDocDetails(DialogSelectDocInfoResponseDTO selection) {
|
||||||
|
|
||||||
this.fornitore.postValue(selection.getFornitore());
|
this.fornitore.postValue(selection.getFornitore());
|
||||||
this.dtbTipi.postValue(selection.getTipoDoc());
|
this.dtbTipi.postValue(selection.getTipoDoc());
|
||||||
|
|
||||||
@ -96,13 +93,15 @@ public class DocInterniViewModel {
|
|||||||
this.dataDoc.postValue(selection.getDataDoc());
|
this.dataDoc.postValue(selection.getDataDoc());
|
||||||
this.numDoc.postValue(selection.getNumDoc() != null ? selection.getNumDoc().toString() : null);
|
this.numDoc.postValue(selection.getNumDoc() != null ? selection.getNumDoc().toString() : null);
|
||||||
this.note.postValue(selection.getNote());
|
this.note.postValue(selection.getNote());
|
||||||
|
|
||||||
|
this.sendOnLoadingStarted();
|
||||||
|
fetchProducts(() -> {
|
||||||
|
fetchDocuments(this::sendOnLoadingEnded);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fetchProducts() {
|
public void fetchProducts(Runnable onComplete) {
|
||||||
this.productsFetched = false;
|
documentRESTConsumer.loadDocumentAvailableArts(
|
||||||
this.sendOnLoadingStarted();
|
|
||||||
|
|
||||||
documentRESTConsumer.loadDocumentoAvailableArts(
|
|
||||||
this.getCodDtip(),
|
this.getCodDtip(),
|
||||||
this.getCodMgrp(),
|
this.getCodMgrp(),
|
||||||
this.getCodAnagForn(),
|
this.getCodAnagForn(),
|
||||||
@ -111,30 +110,33 @@ public class DocInterniViewModel {
|
|||||||
this.availableArts = data.getArts();
|
this.availableArts = data.getArts();
|
||||||
this.artsSize.set(this.availableArts.size());
|
this.artsSize.set(this.availableArts.size());
|
||||||
|
|
||||||
if (this.docsFetched)
|
onComplete.run();
|
||||||
this.sendOnLoadingEnded();
|
|
||||||
|
|
||||||
}, this::sendError);
|
}, this::sendError);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fetchDocuments() {
|
public void fetchDocuments(Runnable onComplete) {
|
||||||
this.docsFetched = false;
|
String codAnag = null;
|
||||||
this.sendOnLoadingStarted();
|
String codVdes = null;
|
||||||
String codAnag = null, codVdes = null;
|
|
||||||
FornitoreDTO fornitore = this.fornitore.getValue();
|
FornitoreDTO fornitore = this.fornitore.getValue();
|
||||||
if (fornitore != null) {
|
if (fornitore != null) {
|
||||||
codAnag = fornitore.getCodAnag();
|
codAnag = fornitore.getCodAnag();
|
||||||
codVdes = fornitore.getCodVdes();
|
codVdes = fornitore.getCodVdes();
|
||||||
}
|
}
|
||||||
documentRepository.getLocalDocumentsByCodDtip(this.getCodDtip(), codAnag, codVdes, dataDoc.getValue(), numDoc.getValue(), list -> {
|
|
||||||
|
|
||||||
|
var docsList = documentRepository.getDocuments(this.getCodDtip(),
|
||||||
|
codAnag, codVdes, dataDoc.getValue(), numDoc.getValue());
|
||||||
|
|
||||||
|
docsList.observeForever(data -> {
|
||||||
|
this.mDocsList.postValue(data);
|
||||||
|
});
|
||||||
|
|
||||||
documentRepository.getNextNumCollo(nextNumCollo -> {
|
documentRepository.getNextNumCollo(nextNumCollo -> {
|
||||||
this.mDocsList.postValue(list);
|
|
||||||
this.setNextNumCollo(nextNumCollo);
|
this.setNextNumCollo(nextNumCollo);
|
||||||
this.docsFetched = true;
|
this.docsFetched = true;
|
||||||
if (this.productsFetched) {
|
|
||||||
this.sendOnLoadingEnded();
|
onComplete.run();
|
||||||
}
|
|
||||||
}, this::sendError);
|
|
||||||
}, this::sendError);
|
}, this::sendError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user