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
@Singleton
MainContext providesMainContextNew(MenuService menuService, AppDatabase appDatabase, SystemRESTConsumer systemRESTConsumer, AuthenticationRESTConsumer authenticationRESTConsumer) {
return new MainContext(mApplication.getApplicationContext(), menuService, appDatabase, systemRESTConsumer, authenticationRESTConsumer);
MainContext providesMainContextNew(MenuService menuService, AppDatabase appDatabase, SystemRESTConsumer systemRESTConsumer, AuthenticationRESTConsumer authenticationRESTConsumer, ExecutorService executorService, Handler handler) {
return new MainContext(mApplication.getApplicationContext(), menuService, appDatabase, systemRESTConsumer, authenticationRESTConsumer, executorService, handler);
}
@Provides

View File

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

View File

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

View File

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