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