Implementata lettura deposito durante il Login.
This commit is contained in:
parent
8476fa4508
commit
08c99aaac0
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
@ -53,6 +53,8 @@ dependencies {
|
||||
implementation 'org.parceler:parceler-api:1.1.10'
|
||||
annotationProcessor 'org.parceler:parceler:1.1.10'
|
||||
|
||||
implementation 'com.annimon:stream:1.2.1'
|
||||
|
||||
//MVVM
|
||||
implementation "android.arch.lifecycle:extensions:1.1.1"
|
||||
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
|
||||
|
||||
@ -34,8 +34,8 @@ public class HttpInterceptor implements Interceptor {
|
||||
.addHeader("Authorization", string)
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.addHeader("Accept", "*/*")
|
||||
.addHeader("username", USERNAME)
|
||||
.addHeader("password", PASSWORD)
|
||||
.addHeader("username", USERNAME != null ? USERNAME : "")
|
||||
.addHeader("password", PASSWORD != null ? PASSWORD : "")
|
||||
.url(url).build();
|
||||
|
||||
return chain.proceed(newRequest);
|
||||
|
||||
@ -12,4 +12,12 @@ public class AvailableCodMdepsDTO {
|
||||
public String getDescrizione() {
|
||||
return descrizione;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if((obj) != null) {
|
||||
return ((AvailableCodMdepsDTO) obj).codMdep.equalsIgnoreCase(codMdep);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,10 +98,10 @@ public class SettingsManager {
|
||||
|
||||
boolean codMdepExistsAnymore = false;
|
||||
|
||||
if(settingsModelIstance.userSession.codMdep != null && !settingsModelIstance.userSession.codMdep.isEmpty()){
|
||||
if(settingsModelIstance.userSession.depo != null){
|
||||
for(AvailableCodMdepsDTO availableCodMdepDTO : availableCodMdeps){
|
||||
//Controllo se il codMdep salvato esiste ancora
|
||||
if(availableCodMdepDTO.getCodMdep().equalsIgnoreCase(settingsModelIstance.userSession.codMdep)) {
|
||||
if(availableCodMdepDTO.getCodMdep().equalsIgnoreCase(settingsModelIstance.userSession.depo.getCodMdep())) {
|
||||
codMdepExistsAnymore = true;
|
||||
break;
|
||||
}
|
||||
@ -109,7 +109,7 @@ public class SettingsManager {
|
||||
}
|
||||
|
||||
if(!codMdepExistsAnymore){
|
||||
settingsModelIstance.userSession.codMdep = availableCodMdeps.get(0).getCodMdep();
|
||||
settingsModelIstance.userSession.depo = availableCodMdeps.get(0);
|
||||
}
|
||||
|
||||
if(callback != null) callback.onSuccess(null);
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package it.integry.integrywmsnative.core.settings;
|
||||
|
||||
import it.integry.integrywmsnative.core.REST.model.AvailableCodMdepsDTO;
|
||||
|
||||
public class SettingsModel {
|
||||
|
||||
public Server server;
|
||||
@ -20,7 +22,8 @@ public class SettingsModel {
|
||||
|
||||
public static class UserSession {
|
||||
public String profileDB;
|
||||
public String codMdep;
|
||||
public AvailableCodMdepsDTO depo;
|
||||
// public String codMdep;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -3,14 +3,11 @@ package it.integry.integrywmsnative.gest.accettazione;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.databinding.DataBindingUtil;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
@ -19,11 +16,12 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import it.integry.integrywmsnative.R;
|
||||
@ -249,9 +247,12 @@ public class MainAccettazioneFragment extends Fragment implements ICheckBoxCallb
|
||||
public void onLoadSuccess(final List<OrdineAccettazioneDTO> ordini) {
|
||||
progress.dismiss();
|
||||
|
||||
AtomicInteger artsCounter = new AtomicInteger();
|
||||
|
||||
Stream.of(ordini).forEach(x -> {
|
||||
artsCounter.addAndGet((int) Stream.of(x.ordini).filter(y -> y.qtaDaEvadere > 0).count());
|
||||
});
|
||||
|
||||
Arrays.stream(ordini).
|
||||
int artsCounter = Coollection.from(ordini).where("qtaDaEvadere", Coollection.greaterThan(0)).all().size();
|
||||
List<String> ordersKeys = new ArrayList<>();
|
||||
|
||||
for(OrdineAccettazioneDTO ordine : ordini){
|
||||
@ -264,7 +265,7 @@ public class MainAccettazioneFragment extends Fragment implements ICheckBoxCallb
|
||||
getText(R.string.orders).toString(),
|
||||
Html.fromHtml(String.format(getActivity().getResources().getQuantityString(R.plurals.loaded_orders_message, ordersKeys.size()), ordersKeys.size())
|
||||
+ "<br /><br />" +
|
||||
"<b>" + artsCounter + "</b> " + getActivity().getResources().getQuantityString(R.plurals.available_articles, artsCounter)),
|
||||
"<b>" + artsCounter + "</b> " + getActivity().getResources().getQuantityString(R.plurals.available_articles, artsCounter.get())),
|
||||
null,
|
||||
(dialogInterface, i) -> {
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ public class AccettazioneHelper {
|
||||
}
|
||||
|
||||
public void loadOrdini(final ILoadOrdiniCallback callback){
|
||||
String codMdep = SettingsManager.i().userSession.codMdep;
|
||||
String codMdep = SettingsManager.i().userSession.depo.getCodMdep();
|
||||
|
||||
OrdiniAccettazioneRESTConsumerService service = RESTBuilder.getService(OrdiniAccettazioneRESTConsumerService.class);
|
||||
service.listOrdiniInevasi(codMdep).enqueue(new Callback<ServiceRESTResponse<List<OrdineAccettazioneInevasoDTO>>>() {
|
||||
|
||||
@ -174,7 +174,7 @@ public class AccettazioneOnOrdineInevasoViewModel implements IOnColloClosedCallb
|
||||
MtbColt mtbColt = new MtbColt();
|
||||
mtbColt .setDataCollo(new Date())
|
||||
.setGestione(GestioneEnum.ACQUISTO)
|
||||
.setCodMdep(SettingsManager.i().userSession.codMdep)
|
||||
.setCodMdep(SettingsManager.i().userSession.depo.getCodMdep())
|
||||
.setPreparatoDa(SettingsManager.i().user.username)
|
||||
.setOraInizPrep(new Date())
|
||||
.setAnnotazioni(noteString)
|
||||
|
||||
@ -16,6 +16,8 @@ import it.integry.integrywmsnative.MainActivity;
|
||||
import it.integry.integrywmsnative.R;
|
||||
import it.integry.integrywmsnative.core.REST.consumers.ISimpleOperationCallback;
|
||||
import it.integry.integrywmsnative.core.REST.consumers.ISingleValueOperationCallback;
|
||||
import it.integry.integrywmsnative.core.REST.consumers.SystemRESTConsumer;
|
||||
import it.integry.integrywmsnative.core.REST.model.AvailableCodMdepsDTO;
|
||||
import it.integry.integrywmsnative.core.di.BindableBoolean;
|
||||
import it.integry.integrywmsnative.core.di.BindableString;
|
||||
import it.integry.integrywmsnative.core.settings.SettingsManager;
|
||||
@ -111,20 +113,22 @@ public class LoginViewModel {
|
||||
if(value1){ //Is online
|
||||
loginHelper.doLogin(host, port, new ISimpleOperationCallback<LoginDTO>() {
|
||||
@Override
|
||||
public void onSuccess(final LoginDTO value1) {
|
||||
public void onSuccess(final LoginDTO loginDTO) {
|
||||
|
||||
SettingsManager.iDB().setAvailableProfiles(loginDTO.availableProfiles);
|
||||
|
||||
SettingsManager.iDB().setAvailableProfiles(value1.availableProfiles);
|
||||
|
||||
mActivity.runOnUiThread(() -> onLoginSuccess(
|
||||
"Benvenuto",
|
||||
Html.fromHtml("Ciao <b>" + value1.full_name + "</b>, la Integry le augura di svolgere al meglio il suo lavoro"),
|
||||
host, port, value1.availableProfiles));
|
||||
Html.fromHtml("Ciao <b>" + loginDTO.full_name + "</b>, la Integry le augura di svolgere al meglio il suo lavoro"),
|
||||
host, port, loginDTO.availableProfiles));
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(final Exception ex) {
|
||||
onLoginFailed(new SpannableString(ex.getMessage().toString()));
|
||||
onLoginFailed(new SpannableString(ex.getMessage()));
|
||||
}
|
||||
});
|
||||
|
||||
@ -146,40 +150,55 @@ public class LoginViewModel {
|
||||
}
|
||||
|
||||
|
||||
private void onLoginFailed(final Spanned message){
|
||||
mProgress.dismiss();
|
||||
loginButtonEnabled.set(true);
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
private void loadDepo(Runnable onComplete) {
|
||||
|
||||
SettingsManager.i().user.username = username.get();
|
||||
SettingsManager.i().user.password = password.get();
|
||||
|
||||
SystemRESTConsumer.getAvailableCodMdeps(new ISimpleOperationCallback<List<AvailableCodMdepsDTO>>() {
|
||||
@Override
|
||||
public void run() {
|
||||
DialogSimpleMessageHelper.makeErrorDialog(
|
||||
mActivity,
|
||||
message,
|
||||
null,
|
||||
null).show();
|
||||
public void onSuccess(List<AvailableCodMdepsDTO> availableCodMdeps) {
|
||||
SettingsManager.iDB().setAvailableCodMdep(availableCodMdeps);
|
||||
|
||||
if(availableCodMdeps == null || availableCodMdeps.size() == 0) {
|
||||
onLoginFailed(Html.fromHtml(String.format(mActivity.getText(R.string.no_codmdep_available).toString())));
|
||||
return;
|
||||
}
|
||||
|
||||
SettingsManager.i().userSession.depo = availableCodMdeps.get(0);
|
||||
|
||||
|
||||
if(onComplete != null) onComplete.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(Exception ex) {
|
||||
//BOH
|
||||
onLoginFailed(new SpannableString(ex.getMessage()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void onLoginFailed(final Spanned message){
|
||||
mProgress.dismiss();
|
||||
loginButtonEnabled.set(true);
|
||||
mActivity.runOnUiThread(() -> DialogSimpleMessageHelper.makeErrorDialog(
|
||||
mActivity,
|
||||
message,
|
||||
null,
|
||||
null).show());
|
||||
}
|
||||
|
||||
|
||||
private void onLoginSuccess(final String title, final Spanned message, final String host, final int port, final List<String> availableProfiles){
|
||||
mProgress.dismiss();
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DialogSimpleMessageHelper.makeSuccessDialog(
|
||||
mActivity,
|
||||
title,
|
||||
message,
|
||||
null,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
showProfileDBSelectionDialog(host, port, availableProfiles);
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
});
|
||||
mActivity.runOnUiThread(() -> DialogSimpleMessageHelper.makeSuccessDialog(
|
||||
mActivity,
|
||||
title,
|
||||
message,
|
||||
null,
|
||||
(dialogInterface, i) -> showProfileDBSelectionDialog(host, port, availableProfiles)).show());
|
||||
}
|
||||
|
||||
private void showProfileDBSelectionDialog(final String host, final int port, final List<String> availableProfiles){
|
||||
@ -190,13 +209,12 @@ public class LoginViewModel {
|
||||
// add a list
|
||||
String[] profiles = new String[availableProfiles.size()];
|
||||
profiles = availableProfiles.toArray(profiles);
|
||||
builder.setItems(profiles, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
SettingsManager.i().userSession.profileDB = availableProfiles.get(which);
|
||||
builder.setItems(profiles, (dialog, which) -> {
|
||||
SettingsManager.i().userSession.profileDB = availableProfiles.get(which);
|
||||
|
||||
loadDepo(() -> {
|
||||
onLoginCompleted(host, port);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// create and show the alert dialog
|
||||
@ -207,11 +225,10 @@ public class LoginViewModel {
|
||||
public void onLoginCompleted(String host, int port) {
|
||||
loginButtonEnabled.set(true);
|
||||
|
||||
|
||||
SettingsManager.i().server.codAzienda = codAzienda.get();
|
||||
SettingsManager.i().server.host = host;
|
||||
SettingsManager.i().server.port = port;
|
||||
SettingsManager.i().user.username = username.get();
|
||||
SettingsManager.i().user.password = password.get();
|
||||
|
||||
SettingsManager.update();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user