Resa synchronized l'init iniziale dell'app

This commit is contained in:
Giuseppe Scorrano 2025-03-17 18:31:45 +01:00
parent 3ac021d7ef
commit ce5ab1cfc2
18 changed files with 366 additions and 422 deletions

View File

@ -49,6 +49,7 @@ import it.integry.integrywmsnative.core.rest.consumers.ProductionLinesRESTConsum
import it.integry.integrywmsnative.core.rest.consumers.ProduzioneRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers.ProduzioneRESTConsumer;
import it.integry.integrywmsnative.core.rest.consumers.SystemRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers.SystemRESTConsumer;
import it.integry.integrywmsnative.core.rest.consumers.VettoriRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers.VettoriRESTConsumer;
import it.integry.integrywmsnative.core.rest.watcher.ServerStatusChecker;
import it.integry.integrywmsnative.core.services.inventario.InventarioService; import it.integry.integrywmsnative.core.services.inventario.InventarioService;
import it.integry.integrywmsnative.core.settings.SettingsManager; import it.integry.integrywmsnative.core.settings.SettingsManager;
import it.integry.integrywmsnative.core.sound.SoundAlertService; import it.integry.integrywmsnative.core.sound.SoundAlertService;
@ -100,8 +101,14 @@ public class MainApplicationModule {
@Provides @Provides
@Singleton @Singleton
MainContext providesMainContextNew(MenuService menuService, AppDatabase appDatabase, SystemRESTConsumer systemRESTConsumer, AuthenticationRESTConsumer authenticationRESTConsumer, ExecutorService executorService, Handler handler) { ServerStatusChecker providesServerStatusChecker(Handler handler) {
return new MainContext(mApplication.getApplicationContext(), menuService, appDatabase, systemRESTConsumer, authenticationRESTConsumer, executorService, handler); return new ServerStatusChecker(handler);
}
@Provides
@Singleton
MainContext providesMainContextNew(MenuService menuService, AppDatabase appDatabase, AuthenticationRESTConsumer authenticationRESTConsumer, ExecutorService executorService, Handler handler, ServerStatusChecker serverStatusChecker) {
return new MainContext(mApplication.getApplicationContext(), menuService, appDatabase, authenticationRESTConsumer, executorService, handler, serverStatusChecker);
} }
@Provides @Provides

View File

@ -5,6 +5,7 @@ import android.content.Intent;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -37,6 +38,9 @@ public class SplashActivity extends BaseActivity implements MainContext.Listener
@Inject @Inject
MainContext mainContext; MainContext mainContext;
@Inject
Handler handler;
private RunnableArgsss<Integer, String[], List<Integer>> onRequestPermissionResult; private RunnableArgsss<Integer, String[], List<Integer>> onRequestPermissionResult;
public static void startActivity(Context context) { public static void startActivity(Context context) {
@ -103,12 +107,12 @@ public class SplashActivity extends BaseActivity implements MainContext.Listener
@Override @Override
public void onDBDataLoading(String item) { public void onDBDataLoading(String item) {
runOnUiThread(() -> mBinding.loadingInfoTextview.setText("Caricamento " + item)); handler.post(() -> mBinding.loadingInfoTextview.setText("Caricamento " + item));
} }
@Override @Override
public void onMenuLoading() { public void onMenuLoading() {
runOnUiThread(() -> mBinding.loadingInfoTextview.setText("Caricamento menù")); handler.post(() -> mBinding.loadingInfoTextview.setText("Caricamento menù"));
} }
@Override @Override
@ -151,11 +155,13 @@ public class SplashActivity extends BaseActivity implements MainContext.Listener
@Override @Override
public void onError(Spanned message) { public void onError(Spanned message) {
handler.post(() -> {
DialogSimpleMessageView.makeErrorDialog( DialogSimpleMessageView.makeErrorDialog(
message, null, this::finish, R.string.logout, () -> { message, null, this::finish, R.string.logout, () -> {
this.mainContext.logout(MainApplication::exit); this.mainContext.logout(MainApplication::exit);
}) })
.show(this.getSupportFragmentManager(), "tag"); .show(this.getSupportFragmentManager(), "tag");
});
} }
} }

View File

@ -17,7 +17,6 @@ import javax.inject.Singleton;
import it.integry.integrywmsnative.core.barcode_reader.BarcodeManager; import it.integry.integrywmsnative.core.barcode_reader.BarcodeManager;
import it.integry.integrywmsnative.core.data_store.db.AppDatabase; import it.integry.integrywmsnative.core.data_store.db.AppDatabase;
import it.integry.integrywmsnative.core.menu.MenuService; 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.rest.watcher.ServerStatusChecker;
import it.integry.integrywmsnative.core.settings.SettingsManager; import it.integry.integrywmsnative.core.settings.SettingsManager;
import it.integry.integrywmsnative.gest.login.rest.AuthenticationRESTConsumer; import it.integry.integrywmsnative.gest.login.rest.AuthenticationRESTConsumer;
@ -28,21 +27,21 @@ public class MainContext {
private final Context applicationContext; private final Context applicationContext;
private final MenuService menuService; private final MenuService menuService;
private final AppDatabase appDatabase; private final AppDatabase appDatabase;
private final SystemRESTConsumer systemRESTConsumer;
private final AuthenticationRESTConsumer authenticationRESTConsumer; private final AuthenticationRESTConsumer authenticationRESTConsumer;
private final ExecutorService executorService; private final ExecutorService executorService;
private final Handler handler; private final Handler handler;
private final ServerStatusChecker serverStatusChecker;
private Listener mListener; private Listener mListener;
public MainContext(Context applicationContext, MenuService menuService, AppDatabase appDatabase, SystemRESTConsumer systemRESTConsumer, AuthenticationRESTConsumer authenticationRESTConsumer, ExecutorService executorService, Handler handler) { public MainContext(Context applicationContext, MenuService menuService, AppDatabase appDatabase, AuthenticationRESTConsumer authenticationRESTConsumer, ExecutorService executorService, Handler handler, ServerStatusChecker serverStatusChecker) {
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
this.menuService = menuService; this.menuService = menuService;
this.appDatabase = appDatabase; this.appDatabase = appDatabase;
this.systemRESTConsumer = systemRESTConsumer;
this.authenticationRESTConsumer = authenticationRESTConsumer; this.authenticationRESTConsumer = authenticationRESTConsumer;
this.executorService = executorService; this.executorService = executorService;
this.handler = handler; this.handler = handler;
this.serverStatusChecker = serverStatusChecker;
} }
public void init() { public void init() {
@ -53,33 +52,30 @@ public class MainContext {
} }
//this.initAuthSession(() -> { executorService.execute(() -> {
// this.initDeviceId(() -> {
this.initDBData(() -> { try {
this.initMenu(() -> { this.initDBData();
this.initMenu();
serverStatusChecker.init();
if (mListener != null) mListener.onContextInitialized(); if (mListener != null) mListener.onContextInitialized();
});
});
// });
//});
} catch (Exception ex) {
Spanned message = null;
this.initServerStatusChecker(); if (ex.getCause() != null && ex.getCause() instanceof ConnectException) {
message = Html.fromHtml("Impossibile collegarsi all'host <b>" + SettingsManager.i().getServer().getHost() + ":" + SettingsManager.i().getServer().getPort() + "</b>. Riprovare più tardi.");
// EventBus.getDefault().register(this); } else if (ex.getMessage().startsWith("Status 404:")) {
message = Html.fromHtml("Errore 404. Non è stato possibile soddisfare la richiesta sull'host <b>" + SettingsManager.i().getServer().getHost() + ":" + SettingsManager.i().getServer().getPort() + "</b>. Riprovare più tardi.");
} else {
message = new SpannableString(ex.getMessage());
} }
// @Subscribe(threadMode = ThreadMode.MAIN) if (mListener != null) mListener.onError(message);
// public void onSessionExpired(SessionExpiredEvent event) { }
// DialogSimpleMessageView.makeErrorDialog( });
// new SpannedString("La sessione è scaduta. Effettua nuovamente la login"), }
// null,
// () -> {
// logout(MainApplication::exit);
// })
// .show(activity.getSupportFragmentManager(), "expired-session-error");
// }
private void initAuthSession(Runnable onComplete) { private void initAuthSession(Runnable onComplete) {
@ -122,42 +118,18 @@ public class MainContext {
}); });
} }
private void initServerStatusChecker() { private void initDBData() throws Exception {
ServerStatusChecker.init();
}
private void initDBData(Runnable onComplete) {
SettingsManager.loadDBVariables(item -> { SettingsManager.loadDBVariables(item -> {
if (mListener != null) mListener.onDBDataLoading(item); if (mListener != null) mListener.onDBDataLoading(item);
},
onComplete,
ex -> {
Spanned message = null;
if (ex.getCause() != null && ex.getCause() instanceof ConnectException) {
message = Html.fromHtml("Impossibile collegarsi all'host <b>" + SettingsManager.i().getServer().getHost() + ":" + SettingsManager.i().getServer().getPort() + "</b>. Riprovare più tardi.");
} else if (ex.getMessage().startsWith("Status 404:")) {
message = Html.fromHtml("Errore 404. Non è stato possibile soddisfare la richiesta sull'host <b>" + SettingsManager.i().getServer().getHost() + ":" + SettingsManager.i().getServer().getPort() + "</b>. Riprovare più tardi.");
} else {
message = new SpannableString(ex.getMessage());
}
if (mListener != null) mListener.onError(message);
}
);
}
private void initMenu(Runnable onComplete) {
if (mListener != null) mListener.onMenuLoading();
this.menuService.init(onComplete, ex -> {
if (mListener != null) mListener.onError(new SpannedString(ex.getMessage()));
}); });
} }
private void initMenu() throws Exception {
if (mListener != null) mListener.onMenuLoading();
this.menuService.init();
}
public MainContext setListener(Listener listener) { public MainContext setListener(Listener listener) {
this.mListener = listener; this.mListener = listener;

View File

@ -1,17 +1,10 @@
package it.integry.integrywmsnative.core.menu; package it.integry.integrywmsnative.core.menu;
import androidx.annotation.NonNull;
import javax.inject.Singleton; import javax.inject.Singleton;
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
import it.integry.integrywmsnative.core.model.StbMenu; import it.integry.integrywmsnative.core.model.StbMenu;
import it.integry.integrywmsnative.core.rest.RESTBuilder; import it.integry.integrywmsnative.core.rest.RESTBuilder;
import it.integry.integrywmsnative.core.rest.consumers._BaseRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers._BaseRESTConsumer;
import it.integry.integrywmsnative.core.rest.handler.ManagedErrorCallback;
import it.integry.integrywmsnative.core.rest.model.ServiceRESTResponse;
import retrofit2.Call;
import retrofit2.Response;
@Singleton @Singleton
public class MenuRESTConsumer extends _BaseRESTConsumer { public class MenuRESTConsumer extends _BaseRESTConsumer {
@ -22,19 +15,12 @@ public class MenuRESTConsumer extends _BaseRESTConsumer {
this.restBuilder = restBuilder; this.restBuilder = restBuilder;
} }
public void retrieveMenu(String rootCodOpz, RunnableArgs<StbMenu> onComplete, RunnableArgs<Exception> onFailed) { public StbMenu retrieveMenuSynchronized(String rootCodOpz) throws Exception {
MenuRESTConsumerService menuRESTConsumerService = restBuilder.getService(MenuRESTConsumerService.class); MenuRESTConsumerService menuRESTConsumerService = restBuilder.getService(MenuRESTConsumerService.class);
menuRESTConsumerService.retrieveMenuConfig(rootCodOpz).enqueue(new ManagedErrorCallback<>() { var response = menuRESTConsumerService.retrieveMenuConfig(rootCodOpz)
@Override .execute();
public void onResponse(Call<ServiceRESTResponse<StbMenu>> call, Response<ServiceRESTResponse<StbMenu>> response) {
analyzeAnswer(response, "retrieveMenu", onComplete, onFailed);
}
@Override return analyzeAnswer(response, "retrieveMenu");
public void onFailure(Call<ServiceRESTResponse<StbMenu>> call, @NonNull final Exception e) {
onFailed.run(e);
}
});
} }
} }

View File

@ -10,7 +10,6 @@ import javax.inject.Singleton;
import it.integry.integrywmsnative.core.class_router.configs.BaseMenuConfiguration; import it.integry.integrywmsnative.core.class_router.configs.BaseMenuConfiguration;
import it.integry.integrywmsnative.core.class_router.configs.MenuConfiguration; import it.integry.integrywmsnative.core.class_router.configs.MenuConfiguration;
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
import it.integry.integrywmsnative.core.menu.exception.MenuNotFoundException; import it.integry.integrywmsnative.core.menu.exception.MenuNotFoundException;
import it.integry.integrywmsnative.core.model.StbMenu; import it.integry.integrywmsnative.core.model.StbMenu;
@ -29,16 +28,14 @@ public class MenuService {
this.menuRESTConsumer = menuRESTConsumer; this.menuRESTConsumer = menuRESTConsumer;
} }
public void init(Runnable onMenuInitialized, RunnableArgs<Exception> onFailed) { public void init() throws Exception {
menuRESTConsumer.retrieveMenu(MENU_COD_OPZ, menu -> { var menu = menuRESTConsumer.retrieveMenuSynchronized(MENU_COD_OPZ);
if (menu != null) { if (menu != null) {
this.mInternalCachedMenu = menu.getStbMenuChildren(); this.mInternalCachedMenu = menu.getStbMenuChildren();
this.mInternalCachedFlatMenu = new ArrayList<>(); this.mInternalCachedFlatMenu = new ArrayList<>();
flattenMenu(this.mInternalCachedMenu); flattenMenu(this.mInternalCachedMenu);
} }
onMenuInitialized.run();
}, onFailed);
} }
public List<StbMenu> getMenu() throws Exception { public List<StbMenu> getMenu() throws Exception {

View File

@ -1,16 +1,9 @@
package it.integry.integrywmsnative.core.rest.consumers; package it.integry.integrywmsnative.core.rest.consumers;
import androidx.annotation.NonNull;
import javax.inject.Singleton; import javax.inject.Singleton;
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
import it.integry.integrywmsnative.core.model.Azienda; import it.integry.integrywmsnative.core.model.Azienda;
import it.integry.integrywmsnative.core.rest.RESTBuilder; import it.integry.integrywmsnative.core.rest.RESTBuilder;
import it.integry.integrywmsnative.core.rest.handler.ManagedErrorCallback;
import it.integry.integrywmsnative.core.rest.model.ServiceRESTResponse;
import retrofit2.Call;
import retrofit2.Response;
@Singleton @Singleton
public class AziendaRESTConsumer extends _BaseRESTConsumer { public class AziendaRESTConsumer extends _BaseRESTConsumer {
@ -21,19 +14,12 @@ public class AziendaRESTConsumer extends _BaseRESTConsumer {
this.restBuilder = restBuilder; this.restBuilder = restBuilder;
} }
public void retrieveAzienda(RunnableArgs<Azienda> onComplete, RunnableArgs<Exception> onFailed) { public Azienda retrieveAziendaSynchronized() throws Exception {
AziendaRESTConsumerService aziendaRESTConsumerService = restBuilder.getService(AziendaRESTConsumerService.class); AziendaRESTConsumerService aziendaRESTConsumerService = restBuilder.getService(AziendaRESTConsumerService.class);
aziendaRESTConsumerService.retrieveDefaultAzienda().enqueue(new ManagedErrorCallback<>() { var response = aziendaRESTConsumerService.retrieveDefaultAzienda()
@Override .execute();
public void onResponse(Call<ServiceRESTResponse<Azienda>> call, Response<ServiceRESTResponse<Azienda>> response) {
analyzeAnswer(response, "Retrieve default azienda", onComplete, onFailed);
}
@Override return analyzeAnswer(response, "Retrieve default azienda");
public void onFailure(Call<ServiceRESTResponse<Azienda>> call, @NonNull final Exception e) {
onFailed.run(e);
}
});
} }
} }

View File

@ -79,15 +79,13 @@ public class GestSetupRESTConsumer extends _BaseRESTConsumer {
} }
public void getValues(String codMdep, List<StbGestSetupReader> stbGestSetupList, RunnableArgs<List<StbGestSetupReader>> onComplete, RunnableArgs<Exception> onFailed) { public List<StbGestSetupReader> getValuesSynchronized(String codMdep, List<StbGestSetupReader> stbGestSetupList) throws Exception {
var stbGestSetups = stbGestSetupList.stream().map(x -> (StbGestSetup) x).collect(Collectors.toList()); var stbGestSetups = stbGestSetupList.stream().map(x -> (StbGestSetup) x).collect(Collectors.toList());
GestSetupRESTConsumerService service = restBuilder.getService(GestSetupRESTConsumerService.class); GestSetupRESTConsumerService service = restBuilder.getService(GestSetupRESTConsumerService.class);
service.getGestSetupValues(codMdep, stbGestSetups).enqueue(new ManagedErrorCallback<>() { var response = service.getGestSetupValues(codMdep, stbGestSetups)
@Override .execute();
public void onResponse(Call<ServiceRESTResponse<List<StbGestSetup>>> call, Response<ServiceRESTResponse<List<StbGestSetup>>> response) { var data = analyzeAnswer(response, "GestSetup");
analyzeAnswer(response, "GestSetup", data -> {
for (StbGestSetup stbGestSetup : data) { for (StbGestSetup stbGestSetup : data) {
stbGestSetupList.stream().filter(x -> stbGestSetup.getGestName().equalsIgnoreCase(x.getGestName()) && stbGestSetupList.stream().filter(x -> stbGestSetup.getGestName().equalsIgnoreCase(x.getGestName()) &&
stbGestSetup.getSection().equalsIgnoreCase(x.getSection()) && stbGestSetup.getSection().equalsIgnoreCase(x.getSection()) &&
@ -96,15 +94,7 @@ public class GestSetupRESTConsumer extends _BaseRESTConsumer {
.ifPresent(x -> x.setValue(stbGestSetup.getValue())); .ifPresent(x -> x.setValue(stbGestSetup.getValue()));
} }
onComplete.run(stbGestSetupList); return stbGestSetupList;
}, onFailed);
}
@Override
public void onFailure(Call<ServiceRESTResponse<List<StbGestSetup>>> call, @NonNull final Exception e) {
if (onFailed != null) onFailed.run(e);
}
});
} }

View File

@ -1,7 +1,5 @@
package it.integry.integrywmsnative.core.rest.consumers; package it.integry.integrywmsnative.core.rest.consumers;
import androidx.annotation.NonNull;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@ -15,11 +13,7 @@ import it.integry.integrywmsnative.core.expansion.RunnableArgs;
import it.integry.integrywmsnative.core.model.MtbColt; import it.integry.integrywmsnative.core.model.MtbColt;
import it.integry.integrywmsnative.core.model.MtbDepoPosizione; import it.integry.integrywmsnative.core.model.MtbDepoPosizione;
import it.integry.integrywmsnative.core.rest.RESTBuilder; import it.integry.integrywmsnative.core.rest.RESTBuilder;
import it.integry.integrywmsnative.core.rest.handler.ManagedErrorCallback;
import it.integry.integrywmsnative.core.rest.model.ServiceRESTResponse;
import it.integry.integrywmsnative.core.utility.UtilityDB; import it.integry.integrywmsnative.core.utility.UtilityDB;
import retrofit2.Call;
import retrofit2.Response;
@Singleton @Singleton
public class PosizioniRESTConsumer extends _BaseRESTConsumer { public class PosizioniRESTConsumer extends _BaseRESTConsumer {
@ -34,23 +28,15 @@ public class PosizioniRESTConsumer extends _BaseRESTConsumer {
this.executorService = executorService; this.executorService = executorService;
} }
public void getAvailablePosizioni(RunnableArgs<List<MtbDepoPosizione>> onComplete, RunnableArgs<Exception> onFailed) { public List<MtbDepoPosizione> getAvailablePosizioniSynchronized() throws Exception {
String codMdep = null; String codMdep = null;
PosizioniRESTConsumerService posizioniRESTConsumerService = restBuilder.getService(PosizioniRESTConsumerService.class); PosizioniRESTConsumerService posizioniRESTConsumerService = restBuilder.getService(PosizioniRESTConsumerService.class);
posizioniRESTConsumerService.getAvailablePosizioni(codMdep).enqueue(new ManagedErrorCallback<>() { var response = posizioniRESTConsumerService.getAvailablePosizioni(codMdep)
@Override .execute();
public void onResponse(Call<ServiceRESTResponse<List<MtbDepoPosizione>>> call, Response<ServiceRESTResponse<List<MtbDepoPosizione>>> response) {
analyzeAnswer(response, "getAvailablePosizioni", (m) -> {
onComplete.run(response.body().getDto());
}, onFailed);
}
@Override var data = analyzeAnswer(response, "getAvailablePosizioni");
public void onFailure(Call<ServiceRESTResponse<List<MtbDepoPosizione>>> call, @NonNull final Exception e) { return response.body().getDto();
onFailed.run(e);
}
});
} }
public ArrayList<MtbColt> getBancaliInPosizioneSynchronized(MtbDepoPosizione mtbDepoPosizione) throws Exception { public ArrayList<MtbColt> getBancaliInPosizioneSynchronized(MtbDepoPosizione mtbDepoPosizione) throws Exception {

View File

@ -89,6 +89,11 @@ public class SystemRESTConsumer extends _BaseRESTConsumer {
}); });
} }
public List<AvailableCodMdepsDTO> getAvailableCodMdepsSynchronized() throws Exception {
SystemRESTConsumerService service = restBuilder.getService(SystemRESTConsumerService.class);
var response = service.getAvailableCodMdeps().execute();
return analyzeAnswer(response, "CodMdepsAvailable");
}
public void getAvailableCodMdeps(final RunnableArgs<List<AvailableCodMdepsDTO>> onSuccess, RunnableArgs<Exception> onFailed) { public void getAvailableCodMdeps(final RunnableArgs<List<AvailableCodMdepsDTO>> onSuccess, RunnableArgs<Exception> onFailed) {
SystemRESTConsumerService service = restBuilder.getService(SystemRESTConsumerService.class); SystemRESTConsumerService service = restBuilder.getService(SystemRESTConsumerService.class);

View File

@ -12,7 +12,11 @@ import it.integry.integrywmsnative.core.utility.UtilityString;
public class ServerStatusChecker { public class ServerStatusChecker {
private static final ServerStatusChecker instance = new ServerStatusChecker();
private final Handler handler;
private final List<RunnableArgs<Boolean>> mCallback = new ArrayList<>(); private final List<RunnableArgs<Boolean>> mCallback = new ArrayList<>();
@ -26,7 +30,29 @@ public class ServerStatusChecker {
private final long MILLIS_DELAY = 5 * 1000; private final long MILLIS_DELAY = 5 * 1000;
private final Handler handler = new Handler(); public ServerStatusChecker(Handler handler) {
this.handler = handler;
}
public void addCallback(RunnableArgs<Boolean> callback) {
this.mCallback.add(callback);
}
public void removeCallback(RunnableArgs<Boolean> callback) {
this.mCallback.remove(callback);
}
public void init() {
this.shouldExecute = true;
this.handler.post(this.runnableCode);
}
public void dispose() {
this.shouldExecute = false;
}
private final Runnable runnableCode = new Runnable() { private final Runnable runnableCode = new Runnable() {
@Override @Override
public void run() { public void run() {
@ -42,27 +68,4 @@ public class ServerStatusChecker {
} }
}; };
public void addCallback(RunnableArgs<Boolean> callback) {
this.mCallback.add(callback);
}
public void removeCallback(RunnableArgs<Boolean> callback) {
this.mCallback.remove(callback);
}
public static void init() {
instance.shouldExecute = true;
instance.handler.post(instance.runnableCode);
}
public static void dispose() {
instance.shouldExecute = false;
}
public static ServerStatusChecker getInstance() {
return instance;
}
} }

View File

@ -102,68 +102,60 @@ public class SettingsManager {
} }
public static void loadDBVariables(RunnableArgs<String> onProgress, Runnable onComplete, RunnableArgs<Exception> onFailed) { public static void loadDBVariables(RunnableArgs<String> onProgress) throws Exception {
dbSettingsModelIstance = new DBSettingsModel(); dbSettingsModelIstance = new DBSettingsModel();
Trace perfTrace = UtilityFirebase.getNewPerformanceTrace("db_load_vars"); Trace perfTrace = UtilityFirebase.getNewPerformanceTrace("db_load_vars");
perfTrace.start(); perfTrace.start();
Runnable tmpOnComplete = () -> { try {
perfTrace.stop();
onComplete.run();
};
RunnableArgs<Exception> tmpOnFailed = ex -> {
UtilityLogger.error(ex);
perfTrace.putAttribute("failed", "true");
if (!(ex instanceof SocketTimeoutException)) onFailed.run(ex);
else
onFailed.run(new Exception("Errore durante il caricamento dei dati. Riavviare l'applicazione!"));
};
onProgress.run("depositi"); onProgress.run("depositi");
loadAvailableCodMdeps(() -> { loadAvailableCodMdeps();
onProgress.run("posizioni"); onProgress.run("posizioni");
loadAvailablePosizioni(() -> { loadAvailablePosizioni();
onProgress.run("impostazioni"); onProgress.run("impostazioni");
loadGestSetupValues(() -> { loadGestSetupValues();
onProgress.run("dati azienda"); onProgress.run("dati azienda");
loadDatiAzienda(() -> { loadDatiAzienda();
loadTipiCollo();
loadTipiCollo(tmpOnComplete, tmpOnFailed); perfTrace.stop();
}, tmpOnFailed); } catch (Exception ex) {
}, tmpOnFailed); UtilityLogger.error(ex);
}, tmpOnFailed); perfTrace.putAttribute("failed", "true");
}, tmpOnFailed);
if (!(ex instanceof SocketTimeoutException))
throw ex;
else
throw new Exception("Errore durante il caricamento dei dati. Riavviare l'applicazione!");
}
} }
private static void loadTipiCollo(Runnable onComplete, RunnableArgs<Exception> onFailed) { private static void loadTipiCollo() throws Exception {
mImballiRESTConsumer.retrieveImballi(MtbTCol.FlagUiUlEnum.UL, tipiColloUl -> { var tipiColloUl = mImballiRESTConsumer.retrieveImballiSyncronized(MtbTCol.FlagUiUlEnum.UL);
mImballiRESTConsumer.retrieveImballi(MtbTCol.FlagUiUlEnum.UI, tipiColloUi -> { var tipiColloUi = mImballiRESTConsumer.retrieveImballiSyncronized(MtbTCol.FlagUiUlEnum.UI);
var imballiList = new ObservableArrayList<ObservableMtbTcol>(); var imballiList = new ObservableArrayList<ObservableMtbTcol>();
imballiList.addAll(tipiColloUi); imballiList.addAll(tipiColloUi);
imballiList.addAll(tipiColloUl); imballiList.addAll(tipiColloUl);
SettingsManager.iDB().setInternalImballi(imballiList); SettingsManager.iDB().setInternalImballi(imballiList);
onComplete.run();
}, onFailed);
}, onFailed);
} }
private static void loadDatiAzienda(Runnable onComplete, RunnableArgs<Exception> onFailed) { private static void loadDatiAzienda() throws Exception {
var datiAzienda = mAziendaRESTConsumer.retrieveAziendaSynchronized();
mAziendaRESTConsumer.retrieveAzienda(datiAzienda -> {
SettingsManager.iDB().setDatiAzienda(datiAzienda); SettingsManager.iDB().setDatiAzienda(datiAzienda);
if (!SettingsManager.iDB().isFlagUseCodAnagAziendale()) { if (!SettingsManager.iDB().isFlagUseCodAnagAziendale()) {
onComplete.run();
return; return;
} }
@ -177,22 +169,17 @@ public class SettingsManager {
Type type = new TypeToken<List<InternalCodAnagsDTO>>() { Type type = new TypeToken<List<InternalCodAnagsDTO>>() {
}.getType(); }.getType();
mSystemRESTConsumer.<List<InternalCodAnagsDTO>>processSql(internalCodAnagsQuery, type, internalCodAnagsList -> { var internalCodAnagsList = mSystemRESTConsumer.<List<InternalCodAnagsDTO>>processSqlSynchronized(internalCodAnagsQuery, type);
SettingsManager.iDB().setInternalCodAnags(internalCodAnagsList); SettingsManager.iDB().setInternalCodAnags(internalCodAnagsList);
if (onComplete != null) onComplete.run();
}, onFailed);
}, onFailed);
} }
private static void loadAvailableCodMdeps(Runnable onComplete, RunnableArgs<Exception> onFailed) { private static void loadAvailableCodMdeps() throws Exception {
mSystemRESTConsumer.getAvailableCodMdeps(availableCodMdeps -> { var availableCodMdeps = mSystemRESTConsumer.getAvailableCodMdepsSynchronized();
dbSettingsModelIstance.setAvailableCodMdep(availableCodMdeps); dbSettingsModelIstance.setAvailableCodMdep(availableCodMdeps);
if (availableCodMdeps == null || availableCodMdeps.isEmpty()) { if (availableCodMdeps == null || availableCodMdeps.isEmpty()) {
onFailed.run(new Exception(mContext.getText(R.string.no_codmdep_available).toString())); throw new Exception(mContext.getText(R.string.no_codmdep_available).toString());
return;
} }
boolean codMdepExistsAnymore = false; boolean codMdepExistsAnymore = false;
@ -210,28 +197,16 @@ public class SettingsManager {
if (!codMdepExistsAnymore) { if (!codMdepExistsAnymore) {
settingsModelIstance.getUserSession().setDepo(availableCodMdeps.get(0)); settingsModelIstance.getUserSession().setDepo(availableCodMdeps.get(0));
} }
if (onComplete != null) onComplete.run();
}, ex -> {
//BOH
if (onFailed != null) onFailed.run(ex);
});
} }
private static void loadAvailablePosizioni(Runnable onComplete, RunnableArgs<Exception> onFailed) { private static void loadAvailablePosizioni() throws Exception {
mPosizioniRESTConsumer.getAvailablePosizioni(availablePosizioni -> { var availablePosizioni = mPosizioniRESTConsumer.getAvailablePosizioniSynchronized();
dbSettingsModelIstance.setAvailablePosizioni(availablePosizioni); dbSettingsModelIstance.setAvailablePosizioni(availablePosizioni);
if (onComplete != null) onComplete.run();
}, ex -> {
if (onFailed != null) onFailed.run(ex);
}
);
} }
private static void loadGestSetupValues(Runnable onComplete, RunnableArgs<Exception> onFailed) { private static void loadGestSetupValues() throws Exception {
List<StbGestSetupReader> stbGestSetupReaderList = new ArrayList<>(); List<StbGestSetupReader> stbGestSetupReaderList = new ArrayList<>();
@ -648,7 +623,8 @@ public class SettingsManager {
String codMdep = SettingsManager.i().getUserSession().getDepo().getCodMdep(); String codMdep = SettingsManager.i().getUserSession().getDepo().getCodMdep();
mGestSetupRESTConsumer.getValues(codMdep, stbGestSetupReaderList, list -> { var list = mGestSetupRESTConsumer.getValuesSynchronized(codMdep, stbGestSetupReaderList);
for (var stbGestSetupReader : list) { for (var stbGestSetupReader : list) {
var value = stbGestSetupReader.getValue(); var value = stbGestSetupReader.getValue();
@ -674,8 +650,6 @@ public class SettingsManager {
stbGestSetupReader.getSetter().run(finalValue); stbGestSetupReader.getSetter().run(finalValue);
} }
if (onComplete != null) onComplete.run();
}, onFailed);
} }

View File

@ -10,6 +10,7 @@ import com.google.firebase.crashlytics.FirebaseCrashlytics;
import com.orhanobut.logger.Logger; import com.orhanobut.logger.Logger;
import it.integry.integrywmsnative.BuildConfig; import it.integry.integrywmsnative.BuildConfig;
import it.integry.integrywmsnative.core.barcode_reader.BarcodeManager;
import it.integry.integrywmsnative.core.exception.InvalidConnectionException; import it.integry.integrywmsnative.core.exception.InvalidConnectionException;
import it.integry.integrywmsnative.core.exception.InvalidLUException; import it.integry.integrywmsnative.core.exception.InvalidLUException;
import it.integry.integrywmsnative.core.exception.InvalidLUGestioneException; import it.integry.integrywmsnative.core.exception.InvalidLUGestioneException;
@ -24,6 +25,7 @@ public class UtilityExceptions {
InvalidLUGestioneException.class, InvalidLUGestioneException.class,
InvalidLUException.class InvalidLUException.class
}; };
public static void defaultException(Context context, Exception ex) { public static void defaultException(Context context, Exception ex) {
defaultException(context, ex, false); defaultException(context, ex, false);
} }
@ -47,7 +49,11 @@ public class UtilityExceptions {
FragmentManager fm = ContextHelper.getFragmentManagerFromContext(context); FragmentManager fm = ContextHelper.getFragmentManagerFromContext(context);
if (fm != null) { if (fm != null) {
DialogSimpleMessageView.makeErrorDialog(Html.fromHtml(errorMessage), null, null) boolean isBarcodeEnabled = BarcodeManager.isLastCallbackEnabled();
if (isBarcodeEnabled) BarcodeManager.disableLastCallback();
DialogSimpleMessageView.makeErrorDialog(Html.fromHtml(errorMessage), null, () -> {
if (isBarcodeEnabled) BarcodeManager.enableLastCallback();
})
.show(fm, "tag"); .show(fm, "tag");
} }

View File

@ -77,6 +77,9 @@ public class MainActivity extends BaseActivity
@Inject @Inject
DialogProgressView mDialogProgressView; DialogProgressView mDialogProgressView;
@Inject
ServerStatusChecker serverStatusChecker;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -194,7 +197,7 @@ public class MainActivity extends BaseActivity
fragment = new MainSettingsFragment(); fragment = new MainSettingsFragment();
this.adaptViewToFragment(fragment); this.adaptViewToFragment(fragment);
} else if (id == R.id.nav_logout) { } else if (id == R.id.nav_logout) {
ServerStatusChecker.dispose(); serverStatusChecker.dispose();
this.mainContext.logout(() -> { this.mainContext.logout(() -> {
startLoginActivity(); startLoginActivity();
}); });

View File

@ -80,6 +80,9 @@ public class MainFragment extends Fragment implements ITitledFragment, IScrollab
@Inject @Inject
ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer; ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer;
@Inject
ServerStatusChecker serverStatusChecker;
private FragmentMainBinding mBindings; private FragmentMainBinding mBindings;
private final List<Runnable> mOnPreDestroyList = new ArrayList<>(); private final List<Runnable> mOnPreDestroyList = new ArrayList<>();
@ -144,7 +147,7 @@ public class MainFragment extends Fragment implements ITitledFragment, IScrollab
private void init() { private void init() {
ServerStatusChecker.getInstance().addCallback(value -> { serverStatusChecker.addCallback(value -> {
if (value && mBindings.noConnectionTopLayout.isExpanded()) { if (value && mBindings.noConnectionTopLayout.isExpanded()) {
collapseNoConnectionLayout(); collapseNoConnectionLayout();
} else if (!value && !mBindings.noConnectionTopLayout.isExpanded()) { } else if (!value && !mBindings.noConnectionTopLayout.isExpanded()) {

View File

@ -107,12 +107,13 @@ public class DialogSimpleMessageView extends BaseDialogFragment {
mBindings.setView(this); mBindings.setView(this);
mBindings.setLifecycleOwner(this); mBindings.setLifecycleOwner(this);
setCancelable(false);
this.initContent(); this.initContent();
var alertDialogBuilder = new MaterialAlertDialogBuilder(requireContext()) var alertDialogBuilder = new MaterialAlertDialogBuilder(requireContext())
.setView(mBindings.getRoot()) .setView(mBindings.getRoot())
.setCancelable(false); .setCancelable(isCancelable());
if (isPositiveVisible()) if (isPositiveVisible())
alertDialogBuilder.setPositiveButton(getPositiveButtonText(), (dialog, which) -> { alertDialogBuilder.setPositiveButton(getPositiveButtonText(), (dialog, which) -> {
@ -130,7 +131,7 @@ public class DialogSimpleMessageView extends BaseDialogFragment {
}); });
var alertDialog = alertDialogBuilder.create(); var alertDialog = alertDialogBuilder.create();
alertDialog.setCanceledOnTouchOutside(false); alertDialog.setCanceledOnTouchOutside(isCancelable());
return alertDialog; return alertDialog;
} }
@ -188,6 +189,8 @@ public class DialogSimpleMessageView extends BaseDialogFragment {
} }
public boolean isPositiveVisible() { public boolean isPositiveVisible() {
return mOnPositiveClick != null || (!isNeutralVisible() && !isNegativeVisible()); return mOnPositiveClick != null || (!isNeutralVisible() && !isNegativeVisible());
} }

View File

@ -1,5 +1,7 @@
package it.integry.integrywmsnative.view.dialogs.input_quantity_v2; package it.integry.integrywmsnative.view.dialogs.input_quantity_v2;
import java.util.concurrent.ExecutorService;
import dagger.Module; import dagger.Module;
import dagger.Provides; import dagger.Provides;
import it.integry.integrywmsnative.core.rest.consumers.BarcodeRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers.BarcodeRESTConsumer;
@ -9,8 +11,8 @@ import it.integry.integrywmsnative.core.rest.consumers.MagazzinoRESTConsumer;
public class DialogInputQuantityV2Module { public class DialogInputQuantityV2Module {
@Provides @Provides
DialogInputQuantityV2ViewModel providesDialogInputQuantityV2ViewModel(BarcodeRESTConsumer barcodeRESTConsumer, MagazzinoRESTConsumer magazzinoRESTConsumer) { DialogInputQuantityV2ViewModel providesDialogInputQuantityV2ViewModel(ExecutorService executorService, BarcodeRESTConsumer barcodeRESTConsumer, MagazzinoRESTConsumer magazzinoRESTConsumer) {
return new DialogInputQuantityV2ViewModel(barcodeRESTConsumer, magazzinoRESTConsumer); return new DialogInputQuantityV2ViewModel(executorService, barcodeRESTConsumer, magazzinoRESTConsumer);
} }
} }

View File

@ -4,6 +4,7 @@ import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.text.Html; import android.text.Html;
import android.text.InputType; import android.text.InputType;
import android.text.SpannableString; import android.text.SpannableString;
@ -56,6 +57,9 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia
@Inject @Inject
DialogInputQuantityV2ViewModel mViewModel; DialogInputQuantityV2ViewModel mViewModel;
@Inject
Handler handler;
private DialogInputQuantityV2DTO mDialogInputQuantityV2DTO; private DialogInputQuantityV2DTO mDialogInputQuantityV2DTO;
//1: Result / 2: ShouldCloseLu / 3: Aborted //1: Result / 2: ShouldCloseLu / 3: Aborted
private RunnableArgs<DialogInputQuantityV2ResultDTO> mOnComplete; private RunnableArgs<DialogInputQuantityV2ResultDTO> mOnComplete;
@ -267,7 +271,7 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia
this.mViewModel.validate(validated -> { this.mViewModel.validate(validated -> {
requireActivity().runOnUiThread(() -> { handler.post(() -> {
this.onLoadingEnded(); this.onLoadingEnded();
if (validated) { if (validated) {
@ -562,11 +566,14 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia
@Override @Override
public void onWarning(String text, RunnableArgs<Boolean> result) { public void onWarning(String text, RunnableArgs<Boolean> result) {
handler.post(() -> {
DialogSimpleMessageView.makeWarningDialog(new SpannableString(Html.fromHtml(text)), DialogSimpleMessageView.makeWarningDialog(new SpannableString(Html.fromHtml(text)),
null, null,
() -> result.run(true), () -> result.run(true),
() -> result.run(false) () -> result.run(false)
).show(requireActivity().getSupportFragmentManager(), "tag"); ).show(requireActivity().getSupportFragmentManager(), "tag");
});
} }
@Override @Override

View File

@ -6,6 +6,7 @@ import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.FutureTask; import java.util.concurrent.FutureTask;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@ -98,6 +99,7 @@ public class DialogInputQuantityV2ViewModel {
private Listener mListener; private Listener mListener;
private final ExecutorService executorService;
private final BarcodeRESTConsumer mBarcodeRESTConsumer; private final BarcodeRESTConsumer mBarcodeRESTConsumer;
private final MagazzinoRESTConsumer mMagazzinoRESTConsumer; private final MagazzinoRESTConsumer mMagazzinoRESTConsumer;
@ -106,7 +108,8 @@ public class DialogInputQuantityV2ViewModel {
private List<MtbPartitaMag> mPartitaMagList; private List<MtbPartitaMag> mPartitaMagList;
@Inject @Inject
public DialogInputQuantityV2ViewModel(BarcodeRESTConsumer barcodeRESTConsumer, MagazzinoRESTConsumer magazzinoRESTConsumer) { public DialogInputQuantityV2ViewModel(ExecutorService executorService, BarcodeRESTConsumer barcodeRESTConsumer, MagazzinoRESTConsumer magazzinoRESTConsumer) {
this.executorService = executorService;
this.mBarcodeRESTConsumer = barcodeRESTConsumer; this.mBarcodeRESTConsumer = barcodeRESTConsumer;
this.mMagazzinoRESTConsumer = magazzinoRESTConsumer; this.mMagazzinoRESTConsumer = magazzinoRESTConsumer;
} }
@ -515,6 +518,9 @@ public class DialogInputQuantityV2ViewModel {
} }
public void validate(RunnableArgs<Boolean> onValidated) { public void validate(RunnableArgs<Boolean> onValidated) {
executorService.execute(() -> {
if (this.internalQtaCnf == null || UtilityBigDecimal.equalsTo(this.internalQtaCnf, BigDecimal.ZERO)) { if (this.internalQtaCnf == null || UtilityBigDecimal.equalsTo(this.internalQtaCnf, BigDecimal.ZERO)) {
this.sendError(new InvalidQtaCnfQuantityException()); this.sendError(new InvalidQtaCnfQuantityException());
@ -651,6 +657,8 @@ public class DialogInputQuantityV2ViewModel {
} }
onValidated.run(true); onValidated.run(true);
});
} }
private boolean runWarningDialogSyncronized(String text) { private boolean runWarningDialogSyncronized(String text) {