Resa synchronized l'init iniziale dell'app
This commit is contained in:
parent
3ac021d7ef
commit
ce5ab1cfc2
@ -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.SystemRESTConsumer;
|
||||
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.settings.SettingsManager;
|
||||
import it.integry.integrywmsnative.core.sound.SoundAlertService;
|
||||
@ -100,8 +101,14 @@ public class MainApplicationModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
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);
|
||||
ServerStatusChecker providesServerStatusChecker(Handler 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
|
||||
|
||||
@ -5,6 +5,7 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.view.LayoutInflater;
|
||||
@ -37,6 +38,9 @@ public class SplashActivity extends BaseActivity implements MainContext.Listener
|
||||
@Inject
|
||||
MainContext mainContext;
|
||||
|
||||
@Inject
|
||||
Handler handler;
|
||||
|
||||
private RunnableArgsss<Integer, String[], List<Integer>> onRequestPermissionResult;
|
||||
|
||||
public static void startActivity(Context context) {
|
||||
@ -103,12 +107,12 @@ public class SplashActivity extends BaseActivity implements MainContext.Listener
|
||||
|
||||
@Override
|
||||
public void onDBDataLoading(String item) {
|
||||
runOnUiThread(() -> mBinding.loadingInfoTextview.setText("Caricamento " + item));
|
||||
handler.post(() -> mBinding.loadingInfoTextview.setText("Caricamento " + item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMenuLoading() {
|
||||
runOnUiThread(() -> mBinding.loadingInfoTextview.setText("Caricamento menù"));
|
||||
handler.post(() -> mBinding.loadingInfoTextview.setText("Caricamento menù"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -151,11 +155,13 @@ public class SplashActivity extends BaseActivity implements MainContext.Listener
|
||||
|
||||
@Override
|
||||
public void onError(Spanned message) {
|
||||
handler.post(() -> {
|
||||
DialogSimpleMessageView.makeErrorDialog(
|
||||
message, null, this::finish, R.string.logout, () -> {
|
||||
this.mainContext.logout(MainApplication::exit);
|
||||
})
|
||||
.show(this.getSupportFragmentManager(), "tag");
|
||||
|
||||
DialogSimpleMessageView.makeErrorDialog(
|
||||
message, null, this::finish, R.string.logout, () -> {
|
||||
this.mainContext.logout(MainApplication::exit);
|
||||
})
|
||||
.show(this.getSupportFragmentManager(), "tag");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,6 @@ import javax.inject.Singleton;
|
||||
import it.integry.integrywmsnative.core.barcode_reader.BarcodeManager;
|
||||
import it.integry.integrywmsnative.core.data_store.db.AppDatabase;
|
||||
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.gest.login.rest.AuthenticationRESTConsumer;
|
||||
@ -28,21 +27,21 @@ public class MainContext {
|
||||
private final Context applicationContext;
|
||||
private final MenuService menuService;
|
||||
private final AppDatabase appDatabase;
|
||||
private final SystemRESTConsumer systemRESTConsumer;
|
||||
private final AuthenticationRESTConsumer authenticationRESTConsumer;
|
||||
private final ExecutorService executorService;
|
||||
private final Handler handler;
|
||||
private final ServerStatusChecker serverStatusChecker;
|
||||
|
||||
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.menuService = menuService;
|
||||
this.appDatabase = appDatabase;
|
||||
this.systemRESTConsumer = systemRESTConsumer;
|
||||
this.authenticationRESTConsumer = authenticationRESTConsumer;
|
||||
this.executorService = executorService;
|
||||
this.handler = handler;
|
||||
this.serverStatusChecker = serverStatusChecker;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
@ -53,34 +52,31 @@ public class MainContext {
|
||||
}
|
||||
|
||||
|
||||
//this.initAuthSession(() -> {
|
||||
// this.initDeviceId(() -> {
|
||||
this.initDBData(() -> {
|
||||
this.initMenu(() -> {
|
||||
executorService.execute(() -> {
|
||||
|
||||
if (mListener != null) mListener.onContextInitialized();
|
||||
});
|
||||
});
|
||||
// });
|
||||
//});
|
||||
try {
|
||||
this.initDBData();
|
||||
this.initMenu();
|
||||
serverStatusChecker.init();
|
||||
|
||||
if (mListener != null) mListener.onContextInitialized();
|
||||
|
||||
this.initServerStatusChecker();
|
||||
} catch (Exception ex) {
|
||||
Spanned message = null;
|
||||
|
||||
// EventBus.getDefault().register(this);
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// @Subscribe(threadMode = ThreadMode.MAIN)
|
||||
// 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) {
|
||||
this.authenticationRESTConsumer.me(obj -> {
|
||||
@ -122,40 +118,16 @@ public class MainContext {
|
||||
});
|
||||
}
|
||||
|
||||
private void initServerStatusChecker() {
|
||||
ServerStatusChecker.init();
|
||||
}
|
||||
|
||||
private void initDBData(Runnable onComplete) {
|
||||
|
||||
private void initDBData() throws Exception {
|
||||
|
||||
SettingsManager.loadDBVariables(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);
|
||||
|
||||
}
|
||||
);
|
||||
if (mListener != null) mListener.onDBDataLoading(item);
|
||||
});
|
||||
}
|
||||
|
||||
private void initMenu(Runnable onComplete) {
|
||||
private void initMenu() throws Exception {
|
||||
if (mListener != null) mListener.onMenuLoading();
|
||||
this.menuService.init(onComplete, ex -> {
|
||||
if (mListener != null) mListener.onError(new SpannedString(ex.getMessage()));
|
||||
});
|
||||
this.menuService.init();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,17 +1,10 @@
|
||||
package it.integry.integrywmsnative.core.menu;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
|
||||
import it.integry.integrywmsnative.core.model.StbMenu;
|
||||
import it.integry.integrywmsnative.core.rest.RESTBuilder;
|
||||
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
|
||||
public class MenuRESTConsumer extends _BaseRESTConsumer {
|
||||
@ -22,19 +15,12 @@ public class MenuRESTConsumer extends _BaseRESTConsumer {
|
||||
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.retrieveMenuConfig(rootCodOpz).enqueue(new ManagedErrorCallback<>() {
|
||||
@Override
|
||||
public void onResponse(Call<ServiceRESTResponse<StbMenu>> call, Response<ServiceRESTResponse<StbMenu>> response) {
|
||||
analyzeAnswer(response, "retrieveMenu", onComplete, onFailed);
|
||||
}
|
||||
var response = menuRESTConsumerService.retrieveMenuConfig(rootCodOpz)
|
||||
.execute();
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<ServiceRESTResponse<StbMenu>> call, @NonNull final Exception e) {
|
||||
onFailed.run(e);
|
||||
}
|
||||
});
|
||||
return analyzeAnswer(response, "retrieveMenu");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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.MenuConfiguration;
|
||||
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
|
||||
import it.integry.integrywmsnative.core.menu.exception.MenuNotFoundException;
|
||||
import it.integry.integrywmsnative.core.model.StbMenu;
|
||||
|
||||
@ -29,20 +28,18 @@ public class MenuService {
|
||||
this.menuRESTConsumer = menuRESTConsumer;
|
||||
}
|
||||
|
||||
public void init(Runnable onMenuInitialized, RunnableArgs<Exception> onFailed) {
|
||||
menuRESTConsumer.retrieveMenu(MENU_COD_OPZ, menu -> {
|
||||
if(menu != null) {
|
||||
this.mInternalCachedMenu = menu.getStbMenuChildren();
|
||||
this.mInternalCachedFlatMenu = new ArrayList<>();
|
||||
flattenMenu(this.mInternalCachedMenu);
|
||||
}
|
||||
public void init() throws Exception {
|
||||
var menu = menuRESTConsumer.retrieveMenuSynchronized(MENU_COD_OPZ);
|
||||
|
||||
onMenuInitialized.run();
|
||||
}, onFailed);
|
||||
if (menu != null) {
|
||||
this.mInternalCachedMenu = menu.getStbMenuChildren();
|
||||
this.mInternalCachedFlatMenu = new ArrayList<>();
|
||||
flattenMenu(this.mInternalCachedMenu);
|
||||
}
|
||||
}
|
||||
|
||||
public List<StbMenu> getMenu() throws Exception {
|
||||
if(mInternalCachedMenu == null) throw new MenuNotFoundException();
|
||||
if (mInternalCachedMenu == null) throw new MenuNotFoundException();
|
||||
|
||||
return mInternalCachedMenu;
|
||||
}
|
||||
@ -64,10 +61,10 @@ public class MenuService {
|
||||
}
|
||||
|
||||
private void flattenMenu(List<StbMenu> menu) {
|
||||
for(StbMenu stbMenu : menu) {
|
||||
for (StbMenu stbMenu : menu) {
|
||||
this.mInternalCachedFlatMenu.add(stbMenu);
|
||||
|
||||
if(stbMenu.getStbMenuChildren() != null && !stbMenu.getStbMenuChildren().isEmpty()) {
|
||||
if (stbMenu.getStbMenuChildren() != null && !stbMenu.getStbMenuChildren().isEmpty()) {
|
||||
flattenMenu(stbMenu.getStbMenuChildren());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,16 +1,9 @@
|
||||
package it.integry.integrywmsnative.core.rest.consumers;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
|
||||
import it.integry.integrywmsnative.core.model.Azienda;
|
||||
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
|
||||
public class AziendaRESTConsumer extends _BaseRESTConsumer {
|
||||
@ -21,19 +14,12 @@ public class AziendaRESTConsumer extends _BaseRESTConsumer {
|
||||
this.restBuilder = restBuilder;
|
||||
}
|
||||
|
||||
public void retrieveAzienda(RunnableArgs<Azienda> onComplete, RunnableArgs<Exception> onFailed) {
|
||||
public Azienda retrieveAziendaSynchronized() throws Exception {
|
||||
AziendaRESTConsumerService aziendaRESTConsumerService = restBuilder.getService(AziendaRESTConsumerService.class);
|
||||
aziendaRESTConsumerService.retrieveDefaultAzienda().enqueue(new ManagedErrorCallback<>() {
|
||||
@Override
|
||||
public void onResponse(Call<ServiceRESTResponse<Azienda>> call, Response<ServiceRESTResponse<Azienda>> response) {
|
||||
analyzeAnswer(response, "Retrieve default azienda", onComplete, onFailed);
|
||||
}
|
||||
var response = aziendaRESTConsumerService.retrieveDefaultAzienda()
|
||||
.execute();
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<ServiceRESTResponse<Azienda>> call, @NonNull final Exception e) {
|
||||
onFailed.run(e);
|
||||
}
|
||||
});
|
||||
return analyzeAnswer(response, "Retrieve default azienda");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -79,32 +79,22 @@ 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());
|
||||
|
||||
GestSetupRESTConsumerService service = restBuilder.getService(GestSetupRESTConsumerService.class);
|
||||
service.getGestSetupValues(codMdep, stbGestSetups).enqueue(new ManagedErrorCallback<>() {
|
||||
@Override
|
||||
public void onResponse(Call<ServiceRESTResponse<List<StbGestSetup>>> call, Response<ServiceRESTResponse<List<StbGestSetup>>> response) {
|
||||
analyzeAnswer(response, "GestSetup", data -> {
|
||||
var response = service.getGestSetupValues(codMdep, stbGestSetups)
|
||||
.execute();
|
||||
var data = analyzeAnswer(response, "GestSetup");
|
||||
for (StbGestSetup stbGestSetup : data) {
|
||||
stbGestSetupList.stream().filter(x -> stbGestSetup.getGestName().equalsIgnoreCase(x.getGestName()) &&
|
||||
stbGestSetup.getSection().equalsIgnoreCase(x.getSection()) &&
|
||||
stbGestSetup.getKeySection().equalsIgnoreCase(x.getKeySection()))
|
||||
.findFirst()
|
||||
.ifPresent(x -> x.setValue(stbGestSetup.getValue()));
|
||||
}
|
||||
|
||||
for (StbGestSetup stbGestSetup : data) {
|
||||
stbGestSetupList.stream().filter(x -> stbGestSetup.getGestName().equalsIgnoreCase(x.getGestName()) &&
|
||||
stbGestSetup.getSection().equalsIgnoreCase(x.getSection()) &&
|
||||
stbGestSetup.getKeySection().equalsIgnoreCase(x.getKeySection()))
|
||||
.findFirst()
|
||||
.ifPresent(x -> x.setValue(stbGestSetup.getValue()));
|
||||
}
|
||||
|
||||
onComplete.run(stbGestSetupList);
|
||||
}, onFailed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<ServiceRESTResponse<List<StbGestSetup>>> call, @NonNull final Exception e) {
|
||||
if (onFailed != null) onFailed.run(e);
|
||||
}
|
||||
});
|
||||
return stbGestSetupList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
package it.integry.integrywmsnative.core.rest.consumers;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
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.MtbDepoPosizione;
|
||||
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 retrofit2.Call;
|
||||
import retrofit2.Response;
|
||||
|
||||
@Singleton
|
||||
public class PosizioniRESTConsumer extends _BaseRESTConsumer {
|
||||
@ -34,23 +28,15 @@ public class PosizioniRESTConsumer extends _BaseRESTConsumer {
|
||||
this.executorService = executorService;
|
||||
}
|
||||
|
||||
public void getAvailablePosizioni(RunnableArgs<List<MtbDepoPosizione>> onComplete, RunnableArgs<Exception> onFailed) {
|
||||
public List<MtbDepoPosizione> getAvailablePosizioniSynchronized() throws Exception {
|
||||
String codMdep = null;
|
||||
|
||||
PosizioniRESTConsumerService posizioniRESTConsumerService = restBuilder.getService(PosizioniRESTConsumerService.class);
|
||||
posizioniRESTConsumerService.getAvailablePosizioni(codMdep).enqueue(new ManagedErrorCallback<>() {
|
||||
@Override
|
||||
public void onResponse(Call<ServiceRESTResponse<List<MtbDepoPosizione>>> call, Response<ServiceRESTResponse<List<MtbDepoPosizione>>> response) {
|
||||
analyzeAnswer(response, "getAvailablePosizioni", (m) -> {
|
||||
onComplete.run(response.body().getDto());
|
||||
}, onFailed);
|
||||
}
|
||||
var response = posizioniRESTConsumerService.getAvailablePosizioni(codMdep)
|
||||
.execute();
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<ServiceRESTResponse<List<MtbDepoPosizione>>> call, @NonNull final Exception e) {
|
||||
onFailed.run(e);
|
||||
}
|
||||
});
|
||||
var data = analyzeAnswer(response, "getAvailablePosizioni");
|
||||
return response.body().getDto();
|
||||
}
|
||||
|
||||
public ArrayList<MtbColt> getBancaliInPosizioneSynchronized(MtbDepoPosizione mtbDepoPosizione) throws Exception {
|
||||
|
||||
@ -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) {
|
||||
SystemRESTConsumerService service = restBuilder.getService(SystemRESTConsumerService.class);
|
||||
|
||||
@ -12,7 +12,11 @@ import it.integry.integrywmsnative.core.utility.UtilityString;
|
||||
|
||||
public class ServerStatusChecker {
|
||||
|
||||
private static final ServerStatusChecker instance = new ServerStatusChecker();
|
||||
|
||||
private final Handler handler;
|
||||
|
||||
|
||||
|
||||
|
||||
private final List<RunnableArgs<Boolean>> mCallback = new ArrayList<>();
|
||||
|
||||
@ -26,7 +30,29 @@ public class ServerStatusChecker {
|
||||
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() {
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -102,136 +102,111 @@ 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();
|
||||
|
||||
Trace perfTrace = UtilityFirebase.getNewPerformanceTrace("db_load_vars");
|
||||
perfTrace.start();
|
||||
|
||||
Runnable tmpOnComplete = () -> {
|
||||
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");
|
||||
loadAvailableCodMdeps(() -> {
|
||||
try {
|
||||
onProgress.run("depositi");
|
||||
loadAvailableCodMdeps();
|
||||
|
||||
onProgress.run("posizioni");
|
||||
loadAvailablePosizioni(() -> {
|
||||
loadAvailablePosizioni();
|
||||
|
||||
onProgress.run("impostazioni");
|
||||
loadGestSetupValues(() -> {
|
||||
|
||||
onProgress.run("dati azienda");
|
||||
loadDatiAzienda(() -> {
|
||||
onProgress.run("impostazioni");
|
||||
loadGestSetupValues();
|
||||
|
||||
loadTipiCollo(tmpOnComplete, tmpOnFailed);
|
||||
|
||||
}, tmpOnFailed);
|
||||
}, tmpOnFailed);
|
||||
}, tmpOnFailed);
|
||||
}, tmpOnFailed);
|
||||
onProgress.run("dati azienda");
|
||||
loadDatiAzienda();
|
||||
loadTipiCollo();
|
||||
|
||||
perfTrace.stop();
|
||||
|
||||
} catch (Exception ex) {
|
||||
UtilityLogger.error(ex);
|
||||
perfTrace.putAttribute("failed", "true");
|
||||
|
||||
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) {
|
||||
mImballiRESTConsumer.retrieveImballi(MtbTCol.FlagUiUlEnum.UL, tipiColloUl -> {
|
||||
mImballiRESTConsumer.retrieveImballi(MtbTCol.FlagUiUlEnum.UI, tipiColloUi -> {
|
||||
private static void loadTipiCollo() throws Exception {
|
||||
var tipiColloUl = mImballiRESTConsumer.retrieveImballiSyncronized(MtbTCol.FlagUiUlEnum.UL);
|
||||
var tipiColloUi = mImballiRESTConsumer.retrieveImballiSyncronized(MtbTCol.FlagUiUlEnum.UI);
|
||||
|
||||
var imballiList = new ObservableArrayList<ObservableMtbTcol>();
|
||||
imballiList.addAll(tipiColloUi);
|
||||
imballiList.addAll(tipiColloUl);
|
||||
var imballiList = new ObservableArrayList<ObservableMtbTcol>();
|
||||
|
||||
SettingsManager.iDB().setInternalImballi(imballiList);
|
||||
onComplete.run();
|
||||
}, onFailed);
|
||||
}, onFailed);
|
||||
imballiList.addAll(tipiColloUi);
|
||||
imballiList.addAll(tipiColloUl);
|
||||
|
||||
SettingsManager.iDB().setInternalImballi(imballiList);
|
||||
}
|
||||
|
||||
private static void loadDatiAzienda(Runnable onComplete, RunnableArgs<Exception> onFailed) {
|
||||
private static void loadDatiAzienda() throws Exception {
|
||||
|
||||
mAziendaRESTConsumer.retrieveAzienda(datiAzienda -> {
|
||||
SettingsManager.iDB().setDatiAzienda(datiAzienda);
|
||||
var datiAzienda = mAziendaRESTConsumer.retrieveAziendaSynchronized();
|
||||
|
||||
if (!SettingsManager.iDB().isFlagUseCodAnagAziendale()) {
|
||||
onComplete.run();
|
||||
return;
|
||||
}
|
||||
SettingsManager.iDB().setDatiAzienda(datiAzienda);
|
||||
|
||||
String internalCodAnagsQuery = "SELECT ga.cod_anag,\n" +
|
||||
" CAST(CASE WHEN vc.cod_anag IS NOT NULL THEN 1 ELSE 0 END AS BIT) AS is_cliente,\n" +
|
||||
" CAST(CASE WHEN af.cod_anag IS NOT NULL THEN 1 ELSE 0 END AS BIT) AS is_fornitore\n" +
|
||||
"FROM azienda\n" +
|
||||
"INNER JOIN gtb_anag ga on azienda.part_iva = ga.part_iva\n" +
|
||||
"LEFT OUTER JOIN vtb_clie vc on ga.cod_anag = vc.cod_anag AND vc.flag_stato = 'A'\n" +
|
||||
"LEFT OUTER JOIN atb_forn af on ga.cod_anag = af.cod_anag AND af.flag_stato = 'A'";
|
||||
if (!SettingsManager.iDB().isFlagUseCodAnagAziendale()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Type type = new TypeToken<List<InternalCodAnagsDTO>>() {
|
||||
}.getType();
|
||||
mSystemRESTConsumer.<List<InternalCodAnagsDTO>>processSql(internalCodAnagsQuery, type, internalCodAnagsList -> {
|
||||
SettingsManager.iDB().setInternalCodAnags(internalCodAnagsList);
|
||||
String internalCodAnagsQuery = "SELECT ga.cod_anag,\n" +
|
||||
" CAST(CASE WHEN vc.cod_anag IS NOT NULL THEN 1 ELSE 0 END AS BIT) AS is_cliente,\n" +
|
||||
" CAST(CASE WHEN af.cod_anag IS NOT NULL THEN 1 ELSE 0 END AS BIT) AS is_fornitore\n" +
|
||||
"FROM azienda\n" +
|
||||
"INNER JOIN gtb_anag ga on azienda.part_iva = ga.part_iva\n" +
|
||||
"LEFT OUTER JOIN vtb_clie vc on ga.cod_anag = vc.cod_anag AND vc.flag_stato = 'A'\n" +
|
||||
"LEFT OUTER JOIN atb_forn af on ga.cod_anag = af.cod_anag AND af.flag_stato = 'A'";
|
||||
|
||||
if (onComplete != null) onComplete.run();
|
||||
}, onFailed);
|
||||
|
||||
}, onFailed);
|
||||
Type type = new TypeToken<List<InternalCodAnagsDTO>>() {
|
||||
}.getType();
|
||||
var internalCodAnagsList = mSystemRESTConsumer.<List<InternalCodAnagsDTO>>processSqlSynchronized(internalCodAnagsQuery, type);
|
||||
SettingsManager.iDB().setInternalCodAnags(internalCodAnagsList);
|
||||
}
|
||||
|
||||
private static void loadAvailableCodMdeps(Runnable onComplete, RunnableArgs<Exception> onFailed) {
|
||||
mSystemRESTConsumer.getAvailableCodMdeps(availableCodMdeps -> {
|
||||
dbSettingsModelIstance.setAvailableCodMdep(availableCodMdeps);
|
||||
private static void loadAvailableCodMdeps() throws Exception {
|
||||
var availableCodMdeps = mSystemRESTConsumer.getAvailableCodMdepsSynchronized();
|
||||
|
||||
if (availableCodMdeps == null || availableCodMdeps.isEmpty()) {
|
||||
onFailed.run(new Exception(mContext.getText(R.string.no_codmdep_available).toString()));
|
||||
return;
|
||||
}
|
||||
dbSettingsModelIstance.setAvailableCodMdep(availableCodMdeps);
|
||||
|
||||
boolean codMdepExistsAnymore = false;
|
||||
if (availableCodMdeps == null || availableCodMdeps.isEmpty()) {
|
||||
throw new Exception(mContext.getText(R.string.no_codmdep_available).toString());
|
||||
}
|
||||
|
||||
if (settingsModelIstance.getUserSession().getDepo() != null) {
|
||||
for (AvailableCodMdepsDTO availableCodMdepDTO : availableCodMdeps) {
|
||||
//Controllo se il codMdep salvato esiste ancora
|
||||
if (availableCodMdepDTO.getCodMdep().equalsIgnoreCase(settingsModelIstance.getUserSession().getDepo().getCodMdep())) {
|
||||
codMdepExistsAnymore = true;
|
||||
break;
|
||||
}
|
||||
boolean codMdepExistsAnymore = false;
|
||||
|
||||
if (settingsModelIstance.getUserSession().getDepo() != null) {
|
||||
for (AvailableCodMdepsDTO availableCodMdepDTO : availableCodMdeps) {
|
||||
//Controllo se il codMdep salvato esiste ancora
|
||||
if (availableCodMdepDTO.getCodMdep().equalsIgnoreCase(settingsModelIstance.getUserSession().getDepo().getCodMdep())) {
|
||||
codMdepExistsAnymore = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!codMdepExistsAnymore) {
|
||||
settingsModelIstance.getUserSession().setDepo(availableCodMdeps.get(0));
|
||||
}
|
||||
|
||||
if (onComplete != null) onComplete.run();
|
||||
}, ex -> {
|
||||
//BOH
|
||||
if (onFailed != null) onFailed.run(ex);
|
||||
});
|
||||
if (!codMdepExistsAnymore) {
|
||||
settingsModelIstance.getUserSession().setDepo(availableCodMdeps.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void loadAvailablePosizioni(Runnable onComplete, RunnableArgs<Exception> onFailed) {
|
||||
mPosizioniRESTConsumer.getAvailablePosizioni(availablePosizioni -> {
|
||||
dbSettingsModelIstance.setAvailablePosizioni(availablePosizioni);
|
||||
|
||||
if (onComplete != null) onComplete.run();
|
||||
}, ex -> {
|
||||
if (onFailed != null) onFailed.run(ex);
|
||||
}
|
||||
);
|
||||
private static void loadAvailablePosizioni() throws Exception {
|
||||
var availablePosizioni = mPosizioniRESTConsumer.getAvailablePosizioniSynchronized();
|
||||
dbSettingsModelIstance.setAvailablePosizioni(availablePosizioni);
|
||||
}
|
||||
|
||||
|
||||
private static void loadGestSetupValues(Runnable onComplete, RunnableArgs<Exception> onFailed) {
|
||||
private static void loadGestSetupValues() throws Exception {
|
||||
|
||||
List<StbGestSetupReader> stbGestSetupReaderList = new ArrayList<>();
|
||||
|
||||
@ -648,34 +623,33 @@ public class SettingsManager {
|
||||
String codMdep = SettingsManager.i().getUserSession().getDepo().getCodMdep();
|
||||
|
||||
|
||||
mGestSetupRESTConsumer.getValues(codMdep, stbGestSetupReaderList, list -> {
|
||||
var list = mGestSetupRESTConsumer.getValuesSynchronized(codMdep, stbGestSetupReaderList);
|
||||
|
||||
for (var stbGestSetupReader : list) {
|
||||
var value = stbGestSetupReader.getValue();
|
||||
var clazz = stbGestSetupReader.getClazz();
|
||||
|
||||
Object finalValue = null;
|
||||
if (value != null) {
|
||||
if (clazz == String.class) {
|
||||
finalValue = clazz.cast(value);
|
||||
} else if (clazz == Boolean.class) {
|
||||
finalValue = clazz.cast("S".equalsIgnoreCase(value));
|
||||
} else if (clazz == Integer.class && value != null) {
|
||||
finalValue = clazz.cast(Integer.parseInt(value));
|
||||
}
|
||||
} else if (stbGestSetupReader.getDefaultValue() == null) {
|
||||
if (clazz == Boolean.class) {
|
||||
finalValue = clazz.cast(Boolean.FALSE);
|
||||
} else if (clazz == Integer.class) {
|
||||
finalValue = clazz.cast(0);
|
||||
}
|
||||
} else finalValue = stbGestSetupReader.getDefaultValue();
|
||||
for (var stbGestSetupReader : list) {
|
||||
var value = stbGestSetupReader.getValue();
|
||||
var clazz = stbGestSetupReader.getClazz();
|
||||
|
||||
stbGestSetupReader.getSetter().run(finalValue);
|
||||
}
|
||||
Object finalValue = null;
|
||||
if (value != null) {
|
||||
if (clazz == String.class) {
|
||||
finalValue = clazz.cast(value);
|
||||
} else if (clazz == Boolean.class) {
|
||||
finalValue = clazz.cast("S".equalsIgnoreCase(value));
|
||||
} else if (clazz == Integer.class && value != null) {
|
||||
finalValue = clazz.cast(Integer.parseInt(value));
|
||||
}
|
||||
} else if (stbGestSetupReader.getDefaultValue() == null) {
|
||||
if (clazz == Boolean.class) {
|
||||
finalValue = clazz.cast(Boolean.FALSE);
|
||||
} else if (clazz == Integer.class) {
|
||||
finalValue = clazz.cast(0);
|
||||
}
|
||||
} else finalValue = stbGestSetupReader.getDefaultValue();
|
||||
|
||||
stbGestSetupReader.getSetter().run(finalValue);
|
||||
}
|
||||
|
||||
if (onComplete != null) onComplete.run();
|
||||
}, onFailed);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@ import com.google.firebase.crashlytics.FirebaseCrashlytics;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
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.InvalidLUException;
|
||||
import it.integry.integrywmsnative.core.exception.InvalidLUGestioneException;
|
||||
@ -19,11 +20,12 @@ import it.integry.integrywmsnative.view.dialogs.base.DialogSimpleMessageView;
|
||||
|
||||
public class UtilityExceptions {
|
||||
|
||||
private static final Class<?>[] FIREBASE_IGNORED_EXCEPTIONS = new Class[] {
|
||||
private static final Class<?>[] FIREBASE_IGNORED_EXCEPTIONS = new Class[]{
|
||||
InvalidConnectionException.class,
|
||||
InvalidLUGestioneException.class,
|
||||
InvalidLUException.class
|
||||
};
|
||||
|
||||
public static void defaultException(Context context, Exception ex) {
|
||||
defaultException(context, ex, false);
|
||||
}
|
||||
@ -47,7 +49,11 @@ public class UtilityExceptions {
|
||||
FragmentManager fm = ContextHelper.getFragmentManagerFromContext(context);
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
@ -77,6 +77,9 @@ public class MainActivity extends BaseActivity
|
||||
@Inject
|
||||
DialogProgressView mDialogProgressView;
|
||||
|
||||
@Inject
|
||||
ServerStatusChecker serverStatusChecker;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -194,7 +197,7 @@ public class MainActivity extends BaseActivity
|
||||
fragment = new MainSettingsFragment();
|
||||
this.adaptViewToFragment(fragment);
|
||||
} else if (id == R.id.nav_logout) {
|
||||
ServerStatusChecker.dispose();
|
||||
serverStatusChecker.dispose();
|
||||
this.mainContext.logout(() -> {
|
||||
startLoginActivity();
|
||||
});
|
||||
|
||||
@ -80,6 +80,9 @@ public class MainFragment extends Fragment implements ITitledFragment, IScrollab
|
||||
@Inject
|
||||
ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer;
|
||||
|
||||
@Inject
|
||||
ServerStatusChecker serverStatusChecker;
|
||||
|
||||
private FragmentMainBinding mBindings;
|
||||
|
||||
private final List<Runnable> mOnPreDestroyList = new ArrayList<>();
|
||||
@ -144,7 +147,7 @@ public class MainFragment extends Fragment implements ITitledFragment, IScrollab
|
||||
|
||||
|
||||
private void init() {
|
||||
ServerStatusChecker.getInstance().addCallback(value -> {
|
||||
serverStatusChecker.addCallback(value -> {
|
||||
if (value && mBindings.noConnectionTopLayout.isExpanded()) {
|
||||
collapseNoConnectionLayout();
|
||||
} else if (!value && !mBindings.noConnectionTopLayout.isExpanded()) {
|
||||
|
||||
@ -107,12 +107,13 @@ public class DialogSimpleMessageView extends BaseDialogFragment {
|
||||
|
||||
mBindings.setView(this);
|
||||
mBindings.setLifecycleOwner(this);
|
||||
setCancelable(false);
|
||||
|
||||
this.initContent();
|
||||
|
||||
var alertDialogBuilder = new MaterialAlertDialogBuilder(requireContext())
|
||||
.setView(mBindings.getRoot())
|
||||
.setCancelable(false);
|
||||
.setCancelable(isCancelable());
|
||||
|
||||
if (isPositiveVisible())
|
||||
alertDialogBuilder.setPositiveButton(getPositiveButtonText(), (dialog, which) -> {
|
||||
@ -130,7 +131,7 @@ public class DialogSimpleMessageView extends BaseDialogFragment {
|
||||
});
|
||||
|
||||
var alertDialog = alertDialogBuilder.create();
|
||||
alertDialog.setCanceledOnTouchOutside(false);
|
||||
alertDialog.setCanceledOnTouchOutside(isCancelable());
|
||||
return alertDialog;
|
||||
}
|
||||
|
||||
@ -188,6 +189,8 @@ public class DialogSimpleMessageView extends BaseDialogFragment {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public boolean isPositiveVisible() {
|
||||
return mOnPositiveClick != null || (!isNeutralVisible() && !isNegativeVisible());
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package it.integry.integrywmsnative.view.dialogs.input_quantity_v2;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import it.integry.integrywmsnative.core.rest.consumers.BarcodeRESTConsumer;
|
||||
@ -9,8 +11,8 @@ import it.integry.integrywmsnative.core.rest.consumers.MagazzinoRESTConsumer;
|
||||
public class DialogInputQuantityV2Module {
|
||||
|
||||
@Provides
|
||||
DialogInputQuantityV2ViewModel providesDialogInputQuantityV2ViewModel(BarcodeRESTConsumer barcodeRESTConsumer, MagazzinoRESTConsumer magazzinoRESTConsumer) {
|
||||
return new DialogInputQuantityV2ViewModel(barcodeRESTConsumer, magazzinoRESTConsumer);
|
||||
DialogInputQuantityV2ViewModel providesDialogInputQuantityV2ViewModel(ExecutorService executorService, BarcodeRESTConsumer barcodeRESTConsumer, MagazzinoRESTConsumer magazzinoRESTConsumer) {
|
||||
return new DialogInputQuantityV2ViewModel(executorService, barcodeRESTConsumer, magazzinoRESTConsumer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.Html;
|
||||
import android.text.InputType;
|
||||
import android.text.SpannableString;
|
||||
@ -56,6 +57,9 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia
|
||||
@Inject
|
||||
DialogInputQuantityV2ViewModel mViewModel;
|
||||
|
||||
@Inject
|
||||
Handler handler;
|
||||
|
||||
private DialogInputQuantityV2DTO mDialogInputQuantityV2DTO;
|
||||
//1: Result / 2: ShouldCloseLu / 3: Aborted
|
||||
private RunnableArgs<DialogInputQuantityV2ResultDTO> mOnComplete;
|
||||
@ -267,13 +271,13 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia
|
||||
|
||||
this.mViewModel.validate(validated -> {
|
||||
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
handler.post(() -> {
|
||||
this.onLoadingEnded();
|
||||
|
||||
if (validated) {
|
||||
var result = this.mViewModel.getResult()
|
||||
.setAborted(false)
|
||||
.setShouldCloseLu(false);
|
||||
.setAborted(false)
|
||||
.setShouldCloseLu(false);
|
||||
dismiss(result);
|
||||
}
|
||||
});
|
||||
@ -301,7 +305,7 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia
|
||||
super.dismiss();
|
||||
|
||||
if (this.mOnComplete != null) {
|
||||
if(result == null) {
|
||||
if (result == null) {
|
||||
result = new DialogInputQuantityV2ResultDTO()
|
||||
.setAborted(true);
|
||||
}
|
||||
@ -562,11 +566,14 @@ public class DialogInputQuantityV2View extends BaseDialogFragment implements Dia
|
||||
|
||||
@Override
|
||||
public void onWarning(String text, RunnableArgs<Boolean> result) {
|
||||
DialogSimpleMessageView.makeWarningDialog(new SpannableString(Html.fromHtml(text)),
|
||||
null,
|
||||
() -> result.run(true),
|
||||
() -> result.run(false)
|
||||
).show(requireActivity().getSupportFragmentManager(), "tag");
|
||||
handler.post(() -> {
|
||||
|
||||
DialogSimpleMessageView.makeWarningDialog(new SpannableString(Html.fromHtml(text)),
|
||||
null,
|
||||
() -> result.run(true),
|
||||
() -> result.run(false)
|
||||
).show(requireActivity().getSupportFragmentManager(), "tag");
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -6,6 +6,7 @@ import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@ -98,6 +99,7 @@ public class DialogInputQuantityV2ViewModel {
|
||||
|
||||
private Listener mListener;
|
||||
|
||||
private final ExecutorService executorService;
|
||||
private final BarcodeRESTConsumer mBarcodeRESTConsumer;
|
||||
private final MagazzinoRESTConsumer mMagazzinoRESTConsumer;
|
||||
|
||||
@ -106,7 +108,8 @@ public class DialogInputQuantityV2ViewModel {
|
||||
private List<MtbPartitaMag> mPartitaMagList;
|
||||
|
||||
@Inject
|
||||
public DialogInputQuantityV2ViewModel(BarcodeRESTConsumer barcodeRESTConsumer, MagazzinoRESTConsumer magazzinoRESTConsumer) {
|
||||
public DialogInputQuantityV2ViewModel(ExecutorService executorService, BarcodeRESTConsumer barcodeRESTConsumer, MagazzinoRESTConsumer magazzinoRESTConsumer) {
|
||||
this.executorService = executorService;
|
||||
this.mBarcodeRESTConsumer = barcodeRESTConsumer;
|
||||
this.mMagazzinoRESTConsumer = magazzinoRESTConsumer;
|
||||
}
|
||||
@ -515,142 +518,147 @@ public class DialogInputQuantityV2ViewModel {
|
||||
}
|
||||
|
||||
public void validate(RunnableArgs<Boolean> onValidated) {
|
||||
if (this.internalQtaCnf == null || UtilityBigDecimal.equalsTo(this.internalQtaCnf, BigDecimal.ZERO)) {
|
||||
executorService.execute(() -> {
|
||||
|
||||
this.sendError(new InvalidQtaCnfQuantityException());
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!disableTracciabilitaCheck && mtbAart.get().isFlagTracciabilitaBoolean()) {
|
||||
if (UtilityString.isNullOrEmpty(internalPartitaMag)) {
|
||||
if (suggestPartitaMagRunnable != null) {
|
||||
internalPartitaMag = suggestPartitaMagRunnable.run(this);
|
||||
if (internalPartitaMag == null) {
|
||||
if (this.internalQtaCnf == null || UtilityBigDecimal.equalsTo(this.internalQtaCnf, BigDecimal.ZERO)) {
|
||||
|
||||
this.sendError(new InvalidQtaCnfQuantityException());
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!disableTracciabilitaCheck && mtbAart.get().isFlagTracciabilitaBoolean()) {
|
||||
if (UtilityString.isNullOrEmpty(internalPartitaMag)) {
|
||||
if (suggestPartitaMagRunnable != null) {
|
||||
internalPartitaMag = suggestPartitaMagRunnable.run(this);
|
||||
if (internalPartitaMag == null) {
|
||||
this.sendError(new InvalidBatchLotException());
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
this.sendError(new InvalidBatchLotException());
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
this.sendError(new InvalidBatchLotException());
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (SettingsManager.iDB().isFlagWarningNewPartitaMag()) {
|
||||
MtbPartitaMag mtbPartitaMag = null;
|
||||
try {
|
||||
mtbPartitaMag = retrievePartitaMag(internalPartitaMag, this.getMtbAart().getCodMart());
|
||||
} catch (Exception e) {
|
||||
this.sendError(e);
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mtbPartitaMag == null) {
|
||||
boolean result = runWarningDialogSyncronized(UtilityResources.getString(R.string.batch_lot_inexistent_error_message));
|
||||
if (!result) {
|
||||
if (SettingsManager.iDB().isFlagWarningNewPartitaMag()) {
|
||||
MtbPartitaMag mtbPartitaMag = null;
|
||||
try {
|
||||
mtbPartitaMag = retrievePartitaMag(internalPartitaMag, this.getMtbAart().getCodMart());
|
||||
} catch (Exception e) {
|
||||
this.sendError(e);
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mtbPartitaMag == null) {
|
||||
boolean result = runWarningDialogSyncronized(UtilityResources.getString(R.string.batch_lot_inexistent_error_message));
|
||||
if (!result) {
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.statoArt == StatoPartitaMag.DISATTIVO) {
|
||||
boolean result = runWarningDialogSyncronized(String.format(UtilityResources.getString(R.string.batch_lot_not_enabled), internalPartitaMag));
|
||||
if (!result) {
|
||||
if (this.statoArt == StatoPartitaMag.DISATTIVO) {
|
||||
boolean result = runWarningDialogSyncronized(String.format(UtilityResources.getString(R.string.batch_lot_not_enabled), internalPartitaMag));
|
||||
if (!result) {
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.shouldAskDataScad && UtilityString.isNullOrEmpty(internalPartitaMag)) {
|
||||
|
||||
this.sendError(new InvalidBatchLotException());
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.shouldAskDataScad && UtilityString.isNullOrEmpty(internalPartitaMag)) {
|
||||
if (this.shouldAskDataScad && this.internalDataScad == null) {
|
||||
|
||||
this.sendError(new InvalidBatchLotException());
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.shouldAskDataScad && this.internalDataScad == null) {
|
||||
|
||||
this.sendError(new InvalidExpireDateException());
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.canOverflowOrderQuantity && UtilityBigDecimal.greaterThan(this.internalQtaTot, this.totalQtaOrd) &&
|
||||
this.mtbAart.get().isFlagQtaCnfFissaBoolean()) {
|
||||
|
||||
this.sendError(new OverflowQtaTotOrderedQuantityException());
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.canOverflowOrderQuantity && UtilityBigDecimal.greaterThan(this.internalNumCnf, this.totalNumCnfOrd) &&
|
||||
!this.mtbAart.get().isFlagQtaCnfFissaBoolean()) {
|
||||
|
||||
this.sendError(new OverflowNumCnfOrderedQuantityException());
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (UtilityBigDecimal.greaterThan(this.internalQtaTot, this.totalQtaAvailable)) {
|
||||
|
||||
this.sendError(new OverflowQtaTotAvailableQuantityException());
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (UtilityBigDecimal.greaterThan(this.internalNumCnf, this.totalNumCnfAvailable) &&
|
||||
!this.mtbAart.get().isFlagQtaCnfFissaBoolean()) {
|
||||
|
||||
this.sendError(new OverflowNumCnfAvailableQuantityException());
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.canInputZeroQuantity && (this.internalNumCnf == null || this.internalQtaCnf == null || this.internalQtaTot == null ||
|
||||
UtilityBigDecimal.equalsOrLowerThan(this.internalNumCnf, BigDecimal.ZERO) ||
|
||||
UtilityBigDecimal.equalsOrLowerThan(this.internalQtaCnf, BigDecimal.ZERO) ||
|
||||
UtilityBigDecimal.equalsOrLowerThan(this.internalQtaTot, BigDecimal.ZERO))) {
|
||||
|
||||
this.sendError(new InvalidQuantityException());
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isNoteMandatory() && (this.internalNote == null || this.internalNote.length() <= 0)) {
|
||||
this.sendError(new InvalidNotesException());
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!UtilityString.isNullOrEmpty(this.internalPartitaMag))
|
||||
this.internalPartitaMag = this.internalPartitaMag.toUpperCase();
|
||||
|
||||
if (this.warnOnQuantityOverflow && UtilityBigDecimal.greaterThan(this.internalQtaTot, this.totalQtaOrd) &&
|
||||
this.mtbAart.get().isFlagQtaCnfFissaBoolean()) {
|
||||
|
||||
boolean result = runWarningDialogSyncronized(UtilityResources.getString(R.string.confirm_ordered_quantity_overflow_error_message));
|
||||
if (!result) {
|
||||
this.sendError(new InvalidExpireDateException());
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.warnOnQuantityOverflow && UtilityBigDecimal.greaterThan(this.internalNumCnf, this.totalNumCnfOrd) &&
|
||||
!this.mtbAart.get().isFlagQtaCnfFissaBoolean()) {
|
||||
if (!this.canOverflowOrderQuantity && UtilityBigDecimal.greaterThan(this.internalQtaTot, this.totalQtaOrd) &&
|
||||
this.mtbAart.get().isFlagQtaCnfFissaBoolean()) {
|
||||
|
||||
boolean result = runWarningDialogSyncronized(UtilityResources.getString(R.string.confirm_ordered_num_cnf_overflow_error_message));
|
||||
if (!result) {
|
||||
this.sendError(new OverflowQtaTotOrderedQuantityException());
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
onValidated.run(true);
|
||||
if (!this.canOverflowOrderQuantity && UtilityBigDecimal.greaterThan(this.internalNumCnf, this.totalNumCnfOrd) &&
|
||||
!this.mtbAart.get().isFlagQtaCnfFissaBoolean()) {
|
||||
|
||||
this.sendError(new OverflowNumCnfOrderedQuantityException());
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (UtilityBigDecimal.greaterThan(this.internalQtaTot, this.totalQtaAvailable)) {
|
||||
|
||||
this.sendError(new OverflowQtaTotAvailableQuantityException());
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (UtilityBigDecimal.greaterThan(this.internalNumCnf, this.totalNumCnfAvailable) &&
|
||||
!this.mtbAart.get().isFlagQtaCnfFissaBoolean()) {
|
||||
|
||||
this.sendError(new OverflowNumCnfAvailableQuantityException());
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.canInputZeroQuantity && (this.internalNumCnf == null || this.internalQtaCnf == null || this.internalQtaTot == null ||
|
||||
UtilityBigDecimal.equalsOrLowerThan(this.internalNumCnf, BigDecimal.ZERO) ||
|
||||
UtilityBigDecimal.equalsOrLowerThan(this.internalQtaCnf, BigDecimal.ZERO) ||
|
||||
UtilityBigDecimal.equalsOrLowerThan(this.internalQtaTot, BigDecimal.ZERO))) {
|
||||
|
||||
this.sendError(new InvalidQuantityException());
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isNoteMandatory() && (this.internalNote == null || this.internalNote.length() <= 0)) {
|
||||
this.sendError(new InvalidNotesException());
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!UtilityString.isNullOrEmpty(this.internalPartitaMag))
|
||||
this.internalPartitaMag = this.internalPartitaMag.toUpperCase();
|
||||
|
||||
if (this.warnOnQuantityOverflow && UtilityBigDecimal.greaterThan(this.internalQtaTot, this.totalQtaOrd) &&
|
||||
this.mtbAart.get().isFlagQtaCnfFissaBoolean()) {
|
||||
|
||||
boolean result = runWarningDialogSyncronized(UtilityResources.getString(R.string.confirm_ordered_quantity_overflow_error_message));
|
||||
if (!result) {
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.warnOnQuantityOverflow && UtilityBigDecimal.greaterThan(this.internalNumCnf, this.totalNumCnfOrd) &&
|
||||
!this.mtbAart.get().isFlagQtaCnfFissaBoolean()) {
|
||||
|
||||
boolean result = runWarningDialogSyncronized(UtilityResources.getString(R.string.confirm_ordered_num_cnf_overflow_error_message));
|
||||
if (!result) {
|
||||
onValidated.run(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
onValidated.run(true);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private boolean runWarningDialogSyncronized(String text) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user