Fix vari su Synchronized e MainThread

This commit is contained in:
Giuseppe Scorrano 2025-03-12 19:26:45 +01:00
parent fb6a74aef8
commit 18937a3315
4 changed files with 73 additions and 53 deletions

View File

@ -99,8 +99,8 @@ public class MainApplicationModule {
@Provides @Provides
@Singleton @Singleton
MainContext providesMainContextNew(MenuService menuService, AppDatabase appDatabase, SystemRESTConsumer systemRESTConsumer, AuthenticationRESTConsumer authenticationRESTConsumer) { MainContext providesMainContextNew(MenuService menuService, AppDatabase appDatabase, SystemRESTConsumer systemRESTConsumer, AuthenticationRESTConsumer authenticationRESTConsumer, ExecutorService executorService, Handler handler) {
return new MainContext(mApplication.getApplicationContext(), menuService, appDatabase, systemRESTConsumer, authenticationRESTConsumer); return new MainContext(mApplication.getApplicationContext(), menuService, appDatabase, systemRESTConsumer, authenticationRESTConsumer, executorService, handler);
} }
@Provides @Provides

View File

@ -1,6 +1,7 @@
package it.integry.integrywmsnative.core.context; package it.integry.integrywmsnative.core.context;
import android.content.Context; import android.content.Context;
import android.os.Handler;
import android.text.Html; import android.text.Html;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
@ -9,6 +10,7 @@ import android.text.SpannedString;
import com.google.firebase.installations.FirebaseInstallations; import com.google.firebase.installations.FirebaseInstallations;
import java.net.ConnectException; import java.net.ConnectException;
import java.util.concurrent.ExecutorService;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -18,7 +20,6 @@ import it.integry.integrywmsnative.core.menu.MenuService;
import it.integry.integrywmsnative.core.rest.consumers.SystemRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers.SystemRESTConsumer;
import it.integry.integrywmsnative.core.rest.watcher.ServerStatusChecker; import it.integry.integrywmsnative.core.rest.watcher.ServerStatusChecker;
import it.integry.integrywmsnative.core.settings.SettingsManager; import it.integry.integrywmsnative.core.settings.SettingsManager;
import it.integry.integrywmsnative.core.utility.UtilityThread;
import it.integry.integrywmsnative.gest.login.rest.AuthenticationRESTConsumer; import it.integry.integrywmsnative.gest.login.rest.AuthenticationRESTConsumer;
@Singleton @Singleton
@ -29,15 +30,19 @@ public class MainContext {
private final AppDatabase appDatabase; private final AppDatabase appDatabase;
private final SystemRESTConsumer systemRESTConsumer; private final SystemRESTConsumer systemRESTConsumer;
private final AuthenticationRESTConsumer authenticationRESTConsumer; private final AuthenticationRESTConsumer authenticationRESTConsumer;
private final ExecutorService executorService;
private final Handler handler;
private Listener mListener; private Listener mListener;
public MainContext(Context applicationContext, MenuService menuService, AppDatabase appDatabase, SystemRESTConsumer systemRESTConsumer, AuthenticationRESTConsumer authenticationRESTConsumer) { public MainContext(Context applicationContext, MenuService menuService, AppDatabase appDatabase, SystemRESTConsumer systemRESTConsumer, AuthenticationRESTConsumer authenticationRESTConsumer, ExecutorService executorService, Handler handler) {
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
this.menuService = menuService; this.menuService = menuService;
this.appDatabase = appDatabase; this.appDatabase = appDatabase;
this.systemRESTConsumer = systemRESTConsumer; this.systemRESTConsumer = systemRESTConsumer;
this.authenticationRESTConsumer = authenticationRESTConsumer; this.authenticationRESTConsumer = authenticationRESTConsumer;
this.executorService = executorService;
this.handler = handler;
} }
public void init() { public void init() {
@ -105,14 +110,16 @@ public class MainContext {
public void logout(Runnable onLoggedOut) { public void logout(Runnable onLoggedOut) {
menuService.invalidateCache(); menuService.invalidateCache();
UtilityThread.executeParallel(() -> { executorService.execute(() -> {
SettingsManager.i().setUser(null); SettingsManager.i().setUser(null);
SettingsManager.i().setUserSession(null); SettingsManager.i().setUserSession(null);
SettingsManager.update(); SettingsManager.update();
appDatabase.clearAllTables(); appDatabase.clearAllTables();
handler.post(() -> {
onLoggedOut.run(); onLoggedOut.run();
}, true); });
});
} }
private void initServerStatusChecker() { private void initServerStatusChecker() {

View File

@ -5,6 +5,7 @@ import android.content.pm.ActivityInfo;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.text.Html; import android.text.Html;
import android.text.SpannableString; import android.text.SpannableString;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -77,6 +78,9 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr
@Inject @Inject
DialogInputQuantityV2View mDialogInputQuantityV2View; DialogInputQuantityV2View mDialogInputQuantityV2View;
@Inject
Handler handler;
public BindableBoolean thereIsAnOpenedUL = new BindableBoolean(false); public BindableBoolean thereIsAnOpenedUL = new BindableBoolean(false);
public BindableBoolean thereIsntAnOpenedUL = new BindableBoolean(false); public BindableBoolean thereIsntAnOpenedUL = new BindableBoolean(false);
@ -268,6 +272,8 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr
@Override @Override
public void onFornitoriLoaded(ArrayList<FornitoreDTO> fornitoriList) { public void onFornitoriLoaded(ArrayList<FornitoreDTO> fornitoriList) {
handler.post(() -> {
AutoCompleteFornitoreAdapter autoCompleteFornitoreAdapter = new AutoCompleteFornitoreAdapter(getActivity(), fornitoriList); AutoCompleteFornitoreAdapter autoCompleteFornitoreAdapter = new AutoCompleteFornitoreAdapter(getActivity(), fornitoriList);
mBinding.autoCompleteFornitori.setAdapter(autoCompleteFornitoreAdapter); mBinding.autoCompleteFornitori.setAdapter(autoCompleteFornitoreAdapter);
mBinding.autoCompleteFornitori.setDropDownWidth(getActivity().getResources().getDisplayMetrics().widthPixels); mBinding.autoCompleteFornitori.setDropDownWidth(getActivity().getResources().getDisplayMetrics().widthPixels);
@ -309,6 +315,7 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr
} }
return false; return false;
}); });
});
} }
@Override @Override
@ -339,14 +346,17 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr
@Override @Override
public void onLUOpened(MtbColt mtbColt) { public void onLUOpened(MtbColt mtbColt) {
handler.post(() -> {
initAdapter(); initAdapter();
this.currentMtbColtObs.set(mtbColt); this.currentMtbColtObs.set(mtbColt);
thereIsAnOpenedUL.set(true); thereIsAnOpenedUL.set(true);
});
} }
@Override @Override
public void onLUClosed() { public void onLUClosed() {
handler.post(() -> {
destroyAdapter(); destroyAdapter();
this.currentMtbColtObs.set(null); this.currentMtbColtObs.set(null);
@ -354,6 +364,7 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr
this.mViewModel.requestLU(); this.mViewModel.requestLU();
/*if (getActivity() != null) ((IPoppableActivity) getActivity()).pop();*/ /*if (getActivity() != null) ((IPoppableActivity) getActivity()).pop();*/
});
} }
@Override @Override
@ -426,7 +437,7 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr
mDialogInputQuantityV2View mDialogInputQuantityV2View
.setDialogInputQuantityV2DTO(dialogInputQuantityV2DTO) .setDialogInputQuantityV2DTO(dialogInputQuantityV2DTO)
.setOnComplete(resultDTO -> { .setOnComplete(resultDTO -> {
if(resultDTO == null || resultDTO.isAborted()) return; if (resultDTO == null || resultDTO.isAborted()) return;
PickedQuantityDTO pickedQuantityDTO = new PickedQuantityDTO() PickedQuantityDTO pickedQuantityDTO = new PickedQuantityDTO()
.setNumCnf(resultDTO.getNumCnf()) .setNumCnf(resultDTO.getNumCnf())
@ -458,7 +469,7 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr
@Override @Override
public void onRowSaved() { public void onRowSaved() {
Snackbar.make(getView(), R.string.data_saved, Snackbar.LENGTH_SHORT) Snackbar.make(getView(), R.string.data_saved, Snackbar.LENGTH_SHORT)
.setBackgroundTint(getResources().getColor(R. color. green_500)) .setBackgroundTint(getResources().getColor(R.color.green_500))
.show(); .show();
} }

View File

@ -1524,8 +1524,9 @@ public class SpedizioneViewModel {
MtbColr createdMtbColr = null; MtbColr createdMtbColr = null;
try { try {
executeDepositChangeIfNeeded(refMtbColt); MtbColt sourceMtbColt = pickingObjectDTO.getTempPickData() != null ? pickingObjectDTO.getTempPickData().getSourceMtbColt() : null;
executeTipoUlChangeIfNeeded(refMtbColt); executeDepositChangeIfNeeded(sourceMtbColt);
executeTipoUlChangeIfNeeded(sourceMtbColt);
createdMtbColr = this.mColliScaricoRESTConsumer.insertUDSRowSynchronized(insertUDSRowRequestDto); createdMtbColr = this.mColliScaricoRESTConsumer.insertUDSRowSynchronized(insertUDSRowRequestDto);
} catch (Exception ex) { } catch (Exception ex) {
@ -2130,7 +2131,8 @@ public class SpedizioneViewModel {
try { try {
printClosedOrders(dto); printClosedOrders(dto);
} catch (Exception e) { } catch (Exception e) {
this.sendLUPrintError(e, () -> {}); this.sendLUPrintError(e, () -> {
});
} }
} }