Migliorie interceptor http
This commit is contained in:
@@ -21,9 +21,12 @@ public class HttpInterceptor implements Interceptor {
|
|||||||
final String APP_TOKEN = "fa3a21af-606b-4129-a22b-aedc2a52c7b6";
|
final String APP_TOKEN = "fa3a21af-606b-4129-a22b-aedc2a52c7b6";
|
||||||
|
|
||||||
final Request request = chain.request();
|
final Request request = chain.request();
|
||||||
final HttpUrl url = request.url().newBuilder()
|
final HttpUrl.Builder httpUrlBuilder = request.url().newBuilder();
|
||||||
.addQueryParameter("profileDb", PROFILE_DB)
|
|
||||||
.build();
|
if(PROFILE_DB != null)
|
||||||
|
httpUrlBuilder.addQueryParameter("profileDb", PROFILE_DB);
|
||||||
|
|
||||||
|
HttpUrl url = httpUrlBuilder.build();
|
||||||
|
|
||||||
Request.Builder builder = chain.request().newBuilder()
|
Request.Builder builder = chain.request().newBuilder()
|
||||||
.addHeader("Content-Type", "application/json")
|
.addHeader("Content-Type", "application/json")
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public class AuthenticationRESTConsumer extends _BaseRESTConsumer {
|
|||||||
|
|
||||||
|
|
||||||
public void authenticate(String protocol, String host, int port, String username, String password, String profileDb, String deviceSalt, RunnableArgs<AuthenticationJwtResponseDTO> onComplete, RunnableArgs<Exception> onFailed) {
|
public void authenticate(String protocol, String host, int port, String username, String password, String profileDb, String deviceSalt, RunnableArgs<AuthenticationJwtResponseDTO> onComplete, RunnableArgs<Exception> onFailed) {
|
||||||
AuthenticationRESTConsumerService service = restBuilder.getService(AuthenticationRESTConsumerService.class, protocol, host, port, false);
|
AuthenticationRESTConsumerService service = restBuilder.getService(AuthenticationRESTConsumerService.class, protocol, host, port);
|
||||||
|
|
||||||
LoginRequestDTO loginRequestDTO = new LoginRequestDTO()
|
LoginRequestDTO loginRequestDTO = new LoginRequestDTO()
|
||||||
.setUsername(username)
|
.setUsername(username)
|
||||||
@@ -94,7 +94,7 @@ public class AuthenticationRESTConsumer extends _BaseRESTConsumer {
|
|||||||
|
|
||||||
|
|
||||||
public void retrieveAvailableProfiles(String protocol, String host, int port, String username, String password, RunnableArgs<List<String>> onComplete, RunnableArgs<Exception> onFailed) {
|
public void retrieveAvailableProfiles(String protocol, String host, int port, String username, String password, RunnableArgs<List<String>> onComplete, RunnableArgs<Exception> onFailed) {
|
||||||
AuthenticationRESTConsumerService service = restBuilder.getService(AuthenticationRESTConsumerService.class, protocol, host, port, false);
|
AuthenticationRESTConsumerService service = restBuilder.getService(AuthenticationRESTConsumerService.class, protocol, host, port);
|
||||||
|
|
||||||
service.retreiveAvailableProfiles(username, password)
|
service.retreiveAvailableProfiles(username, password)
|
||||||
.enqueue(new ManagedErrorCallback<>() {
|
.enqueue(new ManagedErrorCallback<>() {
|
||||||
|
|||||||
@@ -237,18 +237,27 @@ public class OrdiniUscitaElencoFragment extends BaseFragment implements ITitledF
|
|||||||
var orderElementItemType = new Type<OrdiniUscitaElencoDTO, FragmentMainOrdiniUscitaListGroupModelBinding>(
|
var orderElementItemType = new Type<OrdiniUscitaElencoDTO, FragmentMainOrdiniUscitaListGroupModelBinding>(
|
||||||
R.layout.fragment_main_ordini_uscita__list_group_model,
|
R.layout.fragment_main_ordini_uscita__list_group_model,
|
||||||
it.integry.integrywmsnative.BR.item)
|
it.integry.integrywmsnative.BR.item)
|
||||||
|
|
||||||
.areItemSame((item1, item2) -> item1.hashCodeKey() == item2.hashCodeKey() && item1.equalsKey(item2))
|
.areItemSame((item1, item2) -> item1.hashCodeKey() == item2.hashCodeKey() && item1.equalsKey(item2))
|
||||||
.areContentsTheSame((item1, item2) -> item1.hashCode() == item2.hashCode() && item1.equals(item2));
|
.areContentsTheSame((item1, item2) -> item1.hashCode() == item2.hashCode() && item1.equals(item2));
|
||||||
|
|
||||||
orderElementItemType.onClick(holder -> {
|
orderElementItemType.onClick(holder -> {
|
||||||
holder.getBinding().getItem().getSelectedProperty().toggle();
|
holder.getBinding().getItem().getSelectedProperty().toggle();
|
||||||
|
|
||||||
|
|
||||||
if (!canSelectMultipleClienti && holder.getBinding().getItem().isSelected()) {
|
if (!canSelectMultipleClienti && holder.getBinding().getItem().isSelected()) {
|
||||||
this.mAppliedFilterViewModel.getMutableFilteredOrderList().getValue().stream()
|
// Ottimizzato: eseguiamo questa operazione su un thread in background
|
||||||
.filter(y -> !y.getRagSocOrd().equalsIgnoreCase(holder.getBinding().getItem().getRagSocOrd()) && y.isSelected())
|
executorService.execute(() -> {
|
||||||
.forEach(y -> y.setSelected(false));
|
List<OrdiniUscitaElencoDTO> toUnselect = this.mAppliedFilterViewModel.getMutableFilteredOrderList()
|
||||||
|
.getValue().stream()
|
||||||
|
.filter(y -> !y.getRagSocOrd().equalsIgnoreCase(holder.getBinding().getItem().getRagSocOrd()) && y.isSelected())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
if (!toUnselect.isEmpty()) {
|
||||||
|
handler.post(() -> {
|
||||||
|
toUnselect.forEach(y -> y.setSelected(false));
|
||||||
|
refreshFabStatus();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshFabStatus();
|
refreshFabStatus();
|
||||||
@@ -260,56 +269,88 @@ public class OrdiniUscitaElencoFragment extends BaseFragment implements ITitledF
|
|||||||
it.integry.integrywmsnative.BR.item);
|
it.integry.integrywmsnative.BR.item);
|
||||||
|
|
||||||
orderElementSeparatorType.onClick(holder -> {
|
orderElementSeparatorType.onClick(holder -> {
|
||||||
if (!canSelectMultipleClienti) {
|
final String currentRagSoc = holder.getBinding().getItem();
|
||||||
this.mAppliedFilterViewModel.getMutableFilteredOrderList().getValue().stream()
|
|
||||||
.filter(y -> !y.getRagSocOrd().equalsIgnoreCase(holder.getBinding().getItem()) &&
|
|
||||||
y.isSelected())
|
|
||||||
.forEach(y -> y.setSelected(false));
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean allSelected = this.mAppliedFilterViewModel.getMutableFilteredOrderList().getValue().stream()
|
// Ottimizzato: eseguiamo questa operazione su un thread in background
|
||||||
.filter(y -> y.getRagSocOrd().equalsIgnoreCase(holder.getBinding().getItem()))
|
executorService.execute(() -> {
|
||||||
.allMatch(OrdiniUscitaElencoDTO::isSelected);
|
if (!canSelectMultipleClienti) {
|
||||||
|
List<OrdiniUscitaElencoDTO> toUnselect = this.mAppliedFilterViewModel.getMutableFilteredOrderList()
|
||||||
|
.getValue().stream()
|
||||||
|
.filter(y -> !y.getRagSocOrd().equalsIgnoreCase(currentRagSoc) && y.isSelected())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
this.mAppliedFilterViewModel.getMutableFilteredOrderList().getValue().stream()
|
if (!toUnselect.isEmpty()) {
|
||||||
.filter(y -> y.getRagSocOrd().equalsIgnoreCase(holder.getBinding().getItem()))
|
handler.post(() -> toUnselect.forEach(y -> y.setSelected(false)));
|
||||||
.forEach(y -> y.setSelected(!allSelected));
|
}
|
||||||
|
}
|
||||||
|
refreshFabStatus();
|
||||||
|
|
||||||
|
boolean allSelected = this.mAppliedFilterViewModel.getMutableFilteredOrderList().getValue().stream()
|
||||||
|
.filter(y -> y.getRagSocOrd().equalsIgnoreCase(currentRagSoc))
|
||||||
|
.allMatch(OrdiniUscitaElencoDTO::isSelected);
|
||||||
|
|
||||||
|
List<OrdiniUscitaElencoDTO> toToggle = this.mAppliedFilterViewModel.getMutableFilteredOrderList()
|
||||||
|
.getValue().stream()
|
||||||
|
.filter(y -> y.getRagSocOrd().equalsIgnoreCase(currentRagSoc))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
if (!toToggle.isEmpty()) {
|
||||||
|
boolean newSelectionState = !allSelected;
|
||||||
|
handler.post(() -> {
|
||||||
|
toToggle.forEach(y -> y.setSelected(newSelectionState));
|
||||||
|
refreshFabStatus();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
refreshFabStatus();
|
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
var mutableFilteredOrderListWithSeparators = new MutableLiveData<List<Object>>();
|
var mutableFilteredOrderListWithSeparators = new MutableLiveData<List<Object>>();
|
||||||
this.mAppliedFilterViewModel.getMutableFilteredOrderList().observe(getViewLifecycleOwner(), orderList -> {
|
this.mAppliedFilterViewModel.getMutableFilteredOrderList().observe(getViewLifecycleOwner(), orderList -> {
|
||||||
|
// Ottimizzato: creiamo la lista con separatori in un thread in background
|
||||||
|
executorService.execute(() -> {
|
||||||
|
List<Object> listWithSeparators = new ArrayList<>();
|
||||||
|
String lastRagSoc = null;
|
||||||
|
|
||||||
List<Object> listWithSeparators = new ArrayList<>();
|
// Prealloca la lista per evitare ridimensionamenti costosi
|
||||||
String lastRagSoc = null;
|
int estimatedSize = orderList.size() + (orderList.isEmpty() ? 0 : orderList.size() / 3);
|
||||||
|
listWithSeparators = new ArrayList<>(estimatedSize);
|
||||||
|
|
||||||
for (OrdiniUscitaElencoDTO order : orderList) {
|
for (OrdiniUscitaElencoDTO order : orderList) {
|
||||||
order.initEtichettaStatoColor(requireContext());
|
order.initEtichettaStatoColor(requireContext());
|
||||||
|
|
||||||
String currentRagSoc = order.getRagSocOrd();
|
String currentRagSoc = order.getRagSocOrd();
|
||||||
if (lastRagSoc == null || !lastRagSoc.equals(currentRagSoc)) {
|
if (lastRagSoc == null || !lastRagSoc.equals(currentRagSoc)) {
|
||||||
// Aggiungi un separatore quando cambia la ragione sociale
|
// Aggiungi un separatore quando cambia la ragione sociale
|
||||||
listWithSeparators.add(currentRagSoc);
|
listWithSeparators.add(currentRagSoc);
|
||||||
lastRagSoc = currentRagSoc;
|
lastRagSoc = currentRagSoc;
|
||||||
|
}
|
||||||
|
listWithSeparators.add(order);
|
||||||
}
|
}
|
||||||
listWithSeparators.add(order);
|
|
||||||
}
|
|
||||||
|
|
||||||
mutableFilteredOrderListWithSeparators.setValue(listWithSeparators);
|
List<Object> finalList = listWithSeparators;
|
||||||
refreshFabStatus();
|
handler.post(() -> {
|
||||||
|
mutableFilteredOrderListWithSeparators.setValue(finalList);
|
||||||
|
refreshFabStatus();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
new LiveAdapter(mutableFilteredOrderListWithSeparators, this) // Observe filteredList
|
LiveAdapter liveAdapter = new LiveAdapter(mutableFilteredOrderListWithSeparators, this)
|
||||||
.map(String.class, orderElementSeparatorType)
|
.map(String.class, orderElementSeparatorType)
|
||||||
.map(OrdiniUscitaElencoDTO.class, orderElementItemType)
|
.map(OrdiniUscitaElencoDTO.class, orderElementItemType)
|
||||||
.onNoData(x -> {
|
.onNoData(x -> {
|
||||||
this.mBindings.ordiniVenditaEmptyView.setVisibility(x ? View.VISIBLE : View.GONE);
|
this.mBindings.ordiniVenditaEmptyView.setVisibility(x ? View.VISIBLE : View.GONE);
|
||||||
return Unit.INSTANCE;
|
return Unit.INSTANCE;
|
||||||
})
|
});
|
||||||
.into(mBindings.venditaMainList);
|
|
||||||
|
// Ottimizza il recycling delle view
|
||||||
|
mBindings.venditaMainList.setItemViewCacheSize(20);
|
||||||
|
mBindings.venditaMainList.setDrawingCacheEnabled(true);
|
||||||
|
mBindings.venditaMainList.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
|
||||||
|
|
||||||
|
liveAdapter.into(mBindings.venditaMainList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initBarcodeReader() {
|
private void initBarcodeReader() {
|
||||||
@@ -685,8 +726,12 @@ public class OrdiniUscitaElencoFragment extends BaseFragment implements ITitledF
|
|||||||
|
|
||||||
|
|
||||||
private void refreshFabStatus() {
|
private void refreshFabStatus() {
|
||||||
fabVisible.set(this.mAppliedFilterViewModel.getMutableFilteredOrderList().getValue().stream()
|
boolean isEnabled = this.mAppliedFilterViewModel.getMutableFilteredOrderList().getValue().stream()
|
||||||
.anyMatch(OrdiniUscitaElencoDTO::isSelected));
|
.anyMatch(OrdiniUscitaElencoDTO::isSelected);
|
||||||
|
|
||||||
|
handler.post(() -> {
|
||||||
|
fabVisible.set(isEnabled);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshList(List<OrdiniUscitaElencoDTO> originalData, List<OrdiniUscitaElencoDTO> filteredList) {
|
private void refreshList(List<OrdiniUscitaElencoDTO> originalData, List<OrdiniUscitaElencoDTO> filteredList) {
|
||||||
@@ -752,12 +797,6 @@ public class OrdiniUscitaElencoFragment extends BaseFragment implements ITitledF
|
|||||||
// return notHiddenElements;
|
// return notHiddenElements;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
// this.mAppliedFilterViewModel.getMutableFilteredOrderList().getValue().stream()
|
|
||||||
// .forEach(x -> x.setSelected(false));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateActionBar(AppCompatTextView titleText, Context context) {
|
public void onCreateActionBar(AppCompatTextView titleText, Context context) {
|
||||||
|
|||||||
Reference in New Issue
Block a user