Migliorie interceptor http

This commit is contained in:
2025-06-06 10:29:24 +02:00
parent 3a8debdbc4
commit 1f1011e628
3 changed files with 90 additions and 48 deletions

View File

@@ -21,9 +21,12 @@ public class HttpInterceptor implements Interceptor {
final String APP_TOKEN = "fa3a21af-606b-4129-a22b-aedc2a52c7b6";
final Request request = chain.request();
final HttpUrl url = request.url().newBuilder()
.addQueryParameter("profileDb", PROFILE_DB)
.build();
final HttpUrl.Builder httpUrlBuilder = request.url().newBuilder();
if(PROFILE_DB != null)
httpUrlBuilder.addQueryParameter("profileDb", PROFILE_DB);
HttpUrl url = httpUrlBuilder.build();
Request.Builder builder = chain.request().newBuilder()
.addHeader("Content-Type", "application/json")

View File

@@ -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) {
AuthenticationRESTConsumerService service = restBuilder.getService(AuthenticationRESTConsumerService.class, protocol, host, port, false);
AuthenticationRESTConsumerService service = restBuilder.getService(AuthenticationRESTConsumerService.class, protocol, host, port);
LoginRequestDTO loginRequestDTO = new LoginRequestDTO()
.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) {
AuthenticationRESTConsumerService service = restBuilder.getService(AuthenticationRESTConsumerService.class, protocol, host, port, false);
AuthenticationRESTConsumerService service = restBuilder.getService(AuthenticationRESTConsumerService.class, protocol, host, port);
service.retreiveAvailableProfiles(username, password)
.enqueue(new ManagedErrorCallback<>() {

View File

@@ -237,18 +237,27 @@ public class OrdiniUscitaElencoFragment extends BaseFragment implements ITitledF
var orderElementItemType = new Type<OrdiniUscitaElencoDTO, FragmentMainOrdiniUscitaListGroupModelBinding>(
R.layout.fragment_main_ordini_uscita__list_group_model,
it.integry.integrywmsnative.BR.item)
.areItemSame((item1, item2) -> item1.hashCodeKey() == item2.hashCodeKey() && item1.equalsKey(item2))
.areContentsTheSame((item1, item2) -> item1.hashCode() == item2.hashCode() && item1.equals(item2));
orderElementItemType.onClick(holder -> {
holder.getBinding().getItem().getSelectedProperty().toggle();
if (!canSelectMultipleClienti && holder.getBinding().getItem().isSelected()) {
this.mAppliedFilterViewModel.getMutableFilteredOrderList().getValue().stream()
.filter(y -> !y.getRagSocOrd().equalsIgnoreCase(holder.getBinding().getItem().getRagSocOrd()) && y.isSelected())
.forEach(y -> y.setSelected(false));
// Ottimizzato: eseguiamo questa operazione su un thread in background
executorService.execute(() -> {
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();
@@ -260,56 +269,88 @@ public class OrdiniUscitaElencoFragment extends BaseFragment implements ITitledF
it.integry.integrywmsnative.BR.item);
orderElementSeparatorType.onClick(holder -> {
if (!canSelectMultipleClienti) {
this.mAppliedFilterViewModel.getMutableFilteredOrderList().getValue().stream()
.filter(y -> !y.getRagSocOrd().equalsIgnoreCase(holder.getBinding().getItem()) &&
y.isSelected())
.forEach(y -> y.setSelected(false));
}
final String currentRagSoc = holder.getBinding().getItem();
boolean allSelected = this.mAppliedFilterViewModel.getMutableFilteredOrderList().getValue().stream()
.filter(y -> y.getRagSocOrd().equalsIgnoreCase(holder.getBinding().getItem()))
.allMatch(OrdiniUscitaElencoDTO::isSelected);
// Ottimizzato: eseguiamo questa operazione su un thread in background
executorService.execute(() -> {
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()
.filter(y -> y.getRagSocOrd().equalsIgnoreCase(holder.getBinding().getItem()))
.forEach(y -> y.setSelected(!allSelected));
if (!toUnselect.isEmpty()) {
handler.post(() -> toUnselect.forEach(y -> y.setSelected(false)));
}
}
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;
});
var mutableFilteredOrderListWithSeparators = new MutableLiveData<List<Object>>();
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<>();
String lastRagSoc = null;
// Prealloca la lista per evitare ridimensionamenti costosi
int estimatedSize = orderList.size() + (orderList.isEmpty() ? 0 : orderList.size() / 3);
listWithSeparators = new ArrayList<>(estimatedSize);
for (OrdiniUscitaElencoDTO order : orderList) {
order.initEtichettaStatoColor(requireContext());
for (OrdiniUscitaElencoDTO order : orderList) {
order.initEtichettaStatoColor(requireContext());
String currentRagSoc = order.getRagSocOrd();
if (lastRagSoc == null || !lastRagSoc.equals(currentRagSoc)) {
// Aggiungi un separatore quando cambia la ragione sociale
listWithSeparators.add(currentRagSoc);
lastRagSoc = currentRagSoc;
String currentRagSoc = order.getRagSocOrd();
if (lastRagSoc == null || !lastRagSoc.equals(currentRagSoc)) {
// Aggiungi un separatore quando cambia la ragione sociale
listWithSeparators.add(currentRagSoc);
lastRagSoc = currentRagSoc;
}
listWithSeparators.add(order);
}
listWithSeparators.add(order);
}
mutableFilteredOrderListWithSeparators.setValue(listWithSeparators);
refreshFabStatus();
List<Object> finalList = listWithSeparators;
handler.post(() -> {
mutableFilteredOrderListWithSeparators.setValue(finalList);
refreshFabStatus();
});
});
});
new LiveAdapter(mutableFilteredOrderListWithSeparators, this) // Observe filteredList
LiveAdapter liveAdapter = new LiveAdapter(mutableFilteredOrderListWithSeparators, this)
.map(String.class, orderElementSeparatorType)
.map(OrdiniUscitaElencoDTO.class, orderElementItemType)
.onNoData(x -> {
this.mBindings.ordiniVenditaEmptyView.setVisibility(x ? View.VISIBLE : View.GONE);
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() {
@@ -685,8 +726,12 @@ public class OrdiniUscitaElencoFragment extends BaseFragment implements ITitledF
private void refreshFabStatus() {
fabVisible.set(this.mAppliedFilterViewModel.getMutableFilteredOrderList().getValue().stream()
.anyMatch(OrdiniUscitaElencoDTO::isSelected));
boolean isEnabled = this.mAppliedFilterViewModel.getMutableFilteredOrderList().getValue().stream()
.anyMatch(OrdiniUscitaElencoDTO::isSelected);
handler.post(() -> {
fabVisible.set(isEnabled);
});
}
private void refreshList(List<OrdiniUscitaElencoDTO> originalData, List<OrdiniUscitaElencoDTO> filteredList) {
@@ -752,12 +797,6 @@ public class OrdiniUscitaElencoFragment extends BaseFragment implements ITitledF
// return notHiddenElements;
// }
@Override
public void onResume() {
super.onResume();
// this.mAppliedFilterViewModel.getMutableFilteredOrderList().getValue().stream()
// .forEach(x -> x.setSelected(false));
}
@Override
public void onCreateActionBar(AppCompatTextView titleText, Context context) {