Implementata prima Activity (Login) con binding dinamici
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package it.integry.integrywmsnative;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
@@ -18,13 +19,26 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import net.cachapa.expandablelayout.ExpandableLayout;
|
||||
|
||||
import org.xml.sax.ErrorHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import it.integry.integrywmsnative.core.REST.consumers.ISimpleOperationCallback;
|
||||
import it.integry.integrywmsnative.core.REST.consumers.ISingleValueOperationCallback;
|
||||
import it.integry.integrywmsnative.core.REST.watcher.ServerStatusChecker;
|
||||
import it.integry.integrywmsnative.core.exception.ExceptionsHandler;
|
||||
import it.integry.integrywmsnative.core.settings.SettingsManager;
|
||||
import it.integry.integrywmsnative.core.utility.UtilitySettings;
|
||||
import it.integry.integrywmsnative.core.wifi.WiFiCheckerViewHolder;
|
||||
import it.integry.integrywmsnative.gest.accettazione.MainAccettazioneFragment;
|
||||
import it.integry.integrywmsnative.gest.accettazione.core.interfaces.ITitledFragment;
|
||||
import it.integry.integrywmsnative.gest.accettazione.dto.OrdineAccettazioneDTO;
|
||||
import it.integry.integrywmsnative.gest.accettazione_ordine_inevaso.AccettazioneOrdineInevasoActivity;
|
||||
import it.integry.integrywmsnative.gest.login.LoginActivity;
|
||||
|
||||
public class MainActivity extends AppCompatActivity
|
||||
implements NavigationView.OnNavigationItemSelectedListener {
|
||||
@@ -33,34 +47,103 @@ public class MainActivity extends AppCompatActivity
|
||||
|
||||
@BindView(R.id.nav_view) NavigationView mNavigationView;
|
||||
|
||||
@BindView(R.id.no_connection_top_layout)
|
||||
ExpandableLayout mNoConnectionLayout;
|
||||
|
||||
private ServerStatusChecker serverStatusChecker;
|
||||
private boolean firstCheckExecution = true;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// ExceptionsHandler.toCatch(this);
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
if(SettingsManager.i().user.username == null && SettingsManager.i().user.password == null){
|
||||
startLoginActivity();
|
||||
} else {
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
ButterKnife.bind(this);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
||||
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
||||
drawer.setDrawerListener(toggle);
|
||||
toggle.syncState();
|
||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
||||
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
||||
drawer.setDrawerListener(toggle);
|
||||
toggle.syncState();
|
||||
|
||||
mNavigationView = (NavigationView) findViewById(R.id.nav_view);
|
||||
mNavigationView.setNavigationItemSelectedListener(this);
|
||||
mNavigationView = findViewById(R.id.nav_view);
|
||||
mNavigationView.setNavigationItemSelectedListener(this);
|
||||
|
||||
mSearchView.setVisibility(View.GONE);
|
||||
mSearchView.setVisibility(View.GONE);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void startLoginActivity(){
|
||||
Intent myIntent = new Intent(this, LoginActivity.class);
|
||||
startActivity(myIntent);
|
||||
this.finish();
|
||||
}
|
||||
|
||||
private void init(){
|
||||
serverStatusChecker = new ServerStatusChecker();
|
||||
serverStatusChecker.startMonitoring(new ISingleValueOperationCallback<Boolean>() {
|
||||
@Override
|
||||
public void onResult(Boolean value) {
|
||||
if(value && (mNoConnectionLayout.isExpanded() || firstCheckExecution)){
|
||||
|
||||
SettingsManager.reloadDBVariables(new ISimpleOperationCallback() {
|
||||
@Override
|
||||
public void onSuccess(Object value) {
|
||||
collapseNoConnectionLayout();
|
||||
firstCheckExecution = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(Exception ex) {
|
||||
//mNoConnectionLayout.expand(true);
|
||||
if(!mNoConnectionLayout.isExpanded()) expandNoConnectionLayout();
|
||||
}
|
||||
});
|
||||
|
||||
} else if(!value && !mNoConnectionLayout.isExpanded()){
|
||||
expandNoConnectionLayout();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
WiFiCheckerViewHolder wiFiCheckerViewHolder = new WiFiCheckerViewHolder(this, R.id.wifi_power);
|
||||
wiFiCheckerViewHolder.startMonitoring();
|
||||
}
|
||||
|
||||
private void collapseNoConnectionLayout(){
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mNoConnectionLayout.collapse(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void expandNoConnectionLayout(){
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mNoConnectionLayout.expand(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||
if (drawer.isDrawerOpen(GravityCompat.START)) {
|
||||
drawer.closeDrawer(GravityCompat.START);
|
||||
} else {
|
||||
@@ -94,17 +177,10 @@ public class MainActivity extends AppCompatActivity
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(MenuItem item) {
|
||||
// Handle navigation view item clicks here.
|
||||
// resetAllMenuItemsTextColor(mNavigationView);
|
||||
|
||||
// int[] menuColorArray = this.getResources().getIntArray(R.array.menuColors);
|
||||
|
||||
|
||||
Fragment fragment = null;
|
||||
int id = item.getItemId();
|
||||
|
||||
if (id == R.id.nav_accettazione) {
|
||||
// setTextColorForMenuItem(item, menuColorArray[0]);
|
||||
|
||||
fragment = MainAccettazioneFragment.newInstance();
|
||||
this.adaptViewToFragment(fragment);
|
||||
} else if (id == R.id.nav_gallery) {
|
||||
@@ -119,6 +195,12 @@ public class MainActivity extends AppCompatActivity
|
||||
|
||||
}
|
||||
|
||||
|
||||
else if(id == R.id.nav_logout){
|
||||
UtilitySettings.logout();
|
||||
startLoginActivity();
|
||||
}
|
||||
|
||||
if (fragment != null) {
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
fragmentManager.beginTransaction()
|
||||
@@ -126,29 +208,11 @@ public class MainActivity extends AppCompatActivity
|
||||
|
||||
}
|
||||
|
||||
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||
drawer.closeDrawer(GravityCompat.START);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void resetAllMenuItemsTextColor(NavigationView navigationView) {
|
||||
for (int i = 0; i < navigationView.getMenu().size(); i++)
|
||||
setTextColorForMenuItem(navigationView.getMenu().getItem(i), R.color.colorPrimary);
|
||||
}
|
||||
|
||||
private void setTextColorForMenuItem(MenuItem menuItem, int color) {
|
||||
SpannableString spanString = new SpannableString(menuItem.getTitle().toString());
|
||||
spanString.setSpan(new ForegroundColorSpan(color), 0, spanString.length(), 0);
|
||||
menuItem.setTitle(spanString);
|
||||
|
||||
if(menuItem.getIcon() != null){
|
||||
Drawable icon = menuItem.getIcon();
|
||||
icon.mutate();
|
||||
icon.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void adaptViewToFragment(Fragment fragment){
|
||||
if(fragment instanceof SearchView.OnQueryTextListener) {
|
||||
mSearchView.setOnQueryTextListener((SearchView.OnQueryTextListener) fragment);
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package it.integry.integrywmsnative;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.res.Configuration;
|
||||
import android.text.SpannableString;
|
||||
|
||||
import it.integry.integrywmsnative.core.settings.SettingsManager;
|
||||
import it.integry.integrywmsnative.core.settings.Stash;
|
||||
import it.integry.integrywmsnative.view.dialogs.DialogSimpleMessageHelper;
|
||||
|
||||
public class MainApplication extends Application {
|
||||
|
||||
// Called when the application is starting, before any other application objects have been created.
|
||||
// Overriding this method is totally optional!
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
Stash.init(this);
|
||||
|
||||
SettingsManager.init();
|
||||
|
||||
}
|
||||
|
||||
// Called by the system when the device configuration changes while your component is running.
|
||||
// Overriding this method is totally optional!
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
// This is called when the overall system is running low on memory,
|
||||
// and would like actively running processes to tighten their belts.
|
||||
// Overriding this method is totally optional!
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package it.integry.integrywmsnative.core;
|
||||
|
||||
public class CommonConst {
|
||||
|
||||
public static class Login {
|
||||
|
||||
public static class Azienda {
|
||||
public static String host = "192.168.2.13";
|
||||
public static int port = 8080;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import android.util.Base64;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import it.integry.integrywmsnative.core.settings.SettingsManager;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.Request;
|
||||
@@ -15,12 +16,13 @@ import okhttp3.Response;
|
||||
|
||||
public class HttpInterceptor implements Interceptor {
|
||||
|
||||
private final String USERNAME = "magazzino";
|
||||
private final String PASSWORD = "m";
|
||||
private final String PROFILE_DB = "IME_TE";
|
||||
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
|
||||
final String PROFILE_DB = SettingsManager.i().userSession.profileDB;
|
||||
final String USERNAME = SettingsManager.i().user.username;
|
||||
final String PASSWORD = SettingsManager.i().user.password;
|
||||
|
||||
final Request request = chain.request();
|
||||
final HttpUrl url = request.url().newBuilder()
|
||||
.addQueryParameter("profileDb", PROFILE_DB)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package it.integry.integrywmsnative.core.REST;
|
||||
|
||||
import it.integry.integrywmsnative.core.settings.SettingsManager;
|
||||
import okhttp3.OkHttpClient;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
@@ -11,11 +12,22 @@ import retrofit2.converter.gson.GsonConverterFactory;
|
||||
public class RESTBuilder {
|
||||
|
||||
public static <T> T getService(final Class<T> service) {
|
||||
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(new HttpInterceptor()).build();
|
||||
// return getService(service, "192.168.2.13", 8080);
|
||||
return getService(service, SettingsManager.i().server.host, SettingsManager.i().server.port, true);
|
||||
|
||||
}
|
||||
|
||||
public static <T> T getService(final Class<T> service, String host, int port, boolean addInterceptors){
|
||||
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
|
||||
|
||||
if(addInterceptors) clientBuilder.addInterceptor(new HttpInterceptor());
|
||||
|
||||
OkHttpClient client = clientBuilder.build();
|
||||
|
||||
String endpoint = "http://" + host + ":" + port + "/ems-api/";
|
||||
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
// .baseUrl("http://192.168.2.13:8080/ems-api/")
|
||||
.baseUrl("http://www2.studioml.it/ems-api/")
|
||||
.baseUrl(endpoint)
|
||||
.client(client)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build();
|
||||
|
||||
@@ -35,7 +35,7 @@ public class EntityRESTConsumer {
|
||||
callback.onSuccess((T) gson.fromJson(json, clazzType));
|
||||
} else {
|
||||
Log.e("EntityRESTConsumer", response.body().getErrorMessage());
|
||||
callback.onFailed(new Exception(response.message()));
|
||||
callback.onFailed(new Exception(response.body().getErrorMessage()));
|
||||
}
|
||||
} else {
|
||||
Log.e("EntityRESTConsumer", response.message());
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package it.integry.integrywmsnative.core.REST.consumers;
|
||||
|
||||
public interface ISingleOperationDoubleCallback<T, U> {
|
||||
|
||||
void onSuccess(T firstValue, U secondValue);
|
||||
|
||||
void onFailed(Exception ex );
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package it.integry.integrywmsnative.core.REST.consumers;
|
||||
|
||||
public interface ISingleValueOperationCallback<T> {
|
||||
|
||||
void onResult(T value);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package it.integry.integrywmsnative.core.REST.consumers;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import it.integry.integrywmsnative.core.REST.RESTBuilder;
|
||||
import it.integry.integrywmsnative.core.REST.model.EsitoType;
|
||||
import it.integry.integrywmsnative.core.REST.model.ServiceRESTResponse;
|
||||
import it.integry.integrywmsnative.core.settings.SettingsManager;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class SystemRESTConsumer {
|
||||
|
||||
public static void getAvailableProfiles(final ISimpleOperationCallback<List<String>> callback){
|
||||
|
||||
SystemRESTConsumerService service = RESTBuilder.getService(SystemRESTConsumerService.class);
|
||||
service.getAvailableProfiles(SettingsManager.i().user.username, SettingsManager.i().user.password).enqueue(new Callback<ServiceRESTResponse<List<String>>>() {
|
||||
@Override
|
||||
public void onResponse(Call<ServiceRESTResponse<List<String>>> call, Response<ServiceRESTResponse<List<String>>> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
if(response.body() != null) {
|
||||
if(response.body().getEsito() == EsitoType.OK) {
|
||||
callback.onSuccess(response.body().getDto());
|
||||
} else {
|
||||
Log.e("ProfilesAvailable", response.body().getErrorMessage());
|
||||
callback.onFailed(new Exception(response.body().getErrorMessage()));
|
||||
}
|
||||
} else {
|
||||
Log.e("ProfilesAvailable", response.message());
|
||||
callback.onFailed(new Exception(response.message()));
|
||||
}
|
||||
} else {
|
||||
Log.e("ProfilesAvailable", "Status " + response.code() + ": " + response.message());
|
||||
callback.onFailed(new Exception("Status " + response.code() + ": " + response.message()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<ServiceRESTResponse<List<String>>> call, final Throwable t) {
|
||||
|
||||
Log.e("ProfilesAvailable", t.toString());
|
||||
callback.onFailed(new Exception(t));
|
||||
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package it.integry.integrywmsnative.core.REST.consumers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import it.integry.integrywmsnative.core.REST.model.ServiceRESTResponse;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface SystemRESTConsumerService {
|
||||
|
||||
@GET("getAvailableProfiles")
|
||||
Call<ServiceRESTResponse<List<String>>> getAvailableProfiles(@Query("username") String username, @Query("password") String password);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package it.integry.integrywmsnative.core.REST.watcher;
|
||||
|
||||
import android.os.Handler;
|
||||
|
||||
import it.integry.integrywmsnative.core.REST.consumers.ISingleValueOperationCallback;
|
||||
import it.integry.integrywmsnative.core.settings.SettingsManager;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityServer;
|
||||
|
||||
public class ServerStatusChecker {
|
||||
|
||||
private ISingleValueOperationCallback<Boolean> mCallback;
|
||||
|
||||
private boolean shouldExecute = true;
|
||||
private final long MILLIS_DELAY = 5 * 1000;
|
||||
|
||||
|
||||
private Handler handler = new Handler();
|
||||
private Runnable runnableCode = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(shouldExecute) {
|
||||
UtilityServer.isHostReachable(SettingsManager.i().server.host, SettingsManager.i().server.port, mCallback);
|
||||
handler.postDelayed(this, MILLIS_DELAY);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public void startMonitoring(ISingleValueOperationCallback<Boolean> callback){
|
||||
this.mCallback = callback;
|
||||
shouldExecute = true;
|
||||
|
||||
handler.post(runnableCode);
|
||||
}
|
||||
|
||||
public void stopMonitoring(){
|
||||
shouldExecute = false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package it.integry.integrywmsnative.core.di;
|
||||
|
||||
import android.databinding.BaseObservable;
|
||||
|
||||
import org.parceler.Parcel;
|
||||
|
||||
@Parcel
|
||||
public class BindableBoolean extends BaseObservable {
|
||||
boolean mValue;
|
||||
|
||||
public boolean get() {
|
||||
return mValue;
|
||||
}
|
||||
|
||||
public void set(boolean value) {
|
||||
if (mValue != value) {
|
||||
this.mValue = value;
|
||||
notifyChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package it.integry.integrywmsnative.core.di;
|
||||
|
||||
import android.databinding.BaseObservable;
|
||||
|
||||
import org.parceler.Parcel;
|
||||
|
||||
@Parcel
|
||||
public class BindableString extends BaseObservable {
|
||||
String value;
|
||||
|
||||
public String get() {
|
||||
return value != null ? value : "";
|
||||
}
|
||||
|
||||
public void set(String value) {
|
||||
if (!Objects.equals(this.value, value)) {
|
||||
this.value = value;
|
||||
notifyChange();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return value == null || value.isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package it.integry.integrywmsnative.core.di;
|
||||
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.databinding.BindingConversion;
|
||||
import android.support.design.widget.TextInputEditText;
|
||||
import android.support.v4.util.Pair;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
|
||||
import it.integry.integrywmsnative.R;
|
||||
|
||||
public class Converters {
|
||||
|
||||
@BindingConversion
|
||||
public static String convertBindableToString(BindableString bindableString) {
|
||||
return bindableString.get();
|
||||
}
|
||||
|
||||
@BindingConversion
|
||||
public static boolean convertBindableToBoolean(BindableBoolean bindableBoolean) {
|
||||
return bindableBoolean.get();
|
||||
}
|
||||
|
||||
@BindingAdapter("app:binding")
|
||||
public static void bindEditText(EditText view, final BindableString bindableString) {
|
||||
Pair<BindableString, TextWatcherAdapter> pair = (Pair) view.getTag(R.id.bound_observable);
|
||||
if (pair == null || pair.first != bindableString) {
|
||||
if (pair != null) {
|
||||
view.removeTextChangedListener(pair.second);
|
||||
}
|
||||
TextWatcherAdapter watcher = new TextWatcherAdapter() {
|
||||
@Override public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
bindableString.set(s.toString());
|
||||
}
|
||||
};
|
||||
view.setTag(R.id.bound_observable, new Pair<>(bindableString, watcher));
|
||||
view.addTextChangedListener(watcher);
|
||||
}
|
||||
String newValue = bindableString.get();
|
||||
if (!view.getText().toString().equals(newValue)) {
|
||||
view.setText(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter("app:binding")
|
||||
public static void bindTextInputEditText(TextInputEditText view, final BindableString bindableString) {
|
||||
Pair<BindableString, TextWatcherAdapter> pair = (Pair) view.getTag(R.id.bound_observable);
|
||||
if (pair == null || pair.first != bindableString) {
|
||||
if (pair != null) {
|
||||
view.removeTextChangedListener(pair.second);
|
||||
}
|
||||
TextWatcherAdapter watcher = new TextWatcherAdapter() {
|
||||
@Override public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
bindableString.set(s.toString());
|
||||
}
|
||||
};
|
||||
view.setTag(R.id.bound_observable, new Pair<>(bindableString, watcher));
|
||||
view.addTextChangedListener(watcher);
|
||||
}
|
||||
String newValue = bindableString.get();
|
||||
if (!view.getText().toString().equals(newValue)) {
|
||||
view.setText(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter("app:binding")
|
||||
public static void bindRadioGroup(RadioGroup view, final BindableBoolean bindableBoolean) {
|
||||
if (view.getTag(R.id.bound_observable) != bindableBoolean) {
|
||||
view.setTag(R.id.bound_observable, bindableBoolean);
|
||||
view.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
|
||||
@Override public void onCheckedChanged(RadioGroup group, int checkedId) {
|
||||
bindableBoolean.set(checkedId == group.getChildAt(1).getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
Boolean newValue = bindableBoolean.get();
|
||||
((RadioButton) view.getChildAt(newValue ? 1 : 0)).setChecked(true);
|
||||
}
|
||||
|
||||
@BindingAdapter("app:checked")
|
||||
public static void bindCheckbox(CheckBox view, final BindableBoolean bindableBoolean) {
|
||||
if (view.getTag(R.id.bound_observable) != bindableBoolean) {
|
||||
view.setTag(R.id.bound_observable, bindableBoolean);
|
||||
view.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
bindableBoolean.set(b);
|
||||
}
|
||||
});
|
||||
}
|
||||
Boolean newValue = bindableBoolean.get();
|
||||
view.setChecked(newValue);
|
||||
}
|
||||
|
||||
@BindingAdapter({"app:onClick"})
|
||||
public static void bindOnClick(View view, final Runnable runnable) {
|
||||
view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override public void onClick(View v) {
|
||||
runnable.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package it.integry.integrywmsnative.core.di;
|
||||
|
||||
public class Objects {
|
||||
public static boolean equals(Object a, Object b) {
|
||||
return (a == b) || (a != null && a.equals(b));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package it.integry.integrywmsnative.core.di;
|
||||
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
|
||||
public class TextWatcherAdapter implements TextWatcher
|
||||
{
|
||||
public void afterTextChanged(Editable editable)
|
||||
{
|
||||
}
|
||||
|
||||
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
|
||||
{
|
||||
}
|
||||
|
||||
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package it.integry.integrywmsnative.core.di.binders;
|
||||
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.support.design.widget.TextInputEditText;
|
||||
import android.support.v4.util.Pair;
|
||||
|
||||
import net.cachapa.expandablelayout.ExpandableLayout;
|
||||
|
||||
import it.integry.integrywmsnative.R;
|
||||
import it.integry.integrywmsnative.core.di.BindableBoolean;
|
||||
|
||||
public class ExpandableLayoutBinders {
|
||||
|
||||
@BindingAdapter("app:el_expanded_bind")
|
||||
public static void bindExpandableLayout(final ExpandableLayout view, final BindableBoolean bindableBoolean) {
|
||||
|
||||
Pair<BindableBoolean, ExpandableLayout.OnExpansionUpdateListener> pair = (Pair) view.getTag(R.id.bound_observable);
|
||||
if (pair == null || pair.first != bindableBoolean) {
|
||||
if (pair != null) {
|
||||
view.setOnExpansionUpdateListener(null);
|
||||
}
|
||||
|
||||
ExpandableLayout.OnExpansionUpdateListener watcher = new ExpandableLayout.OnExpansionUpdateListener() {
|
||||
@Override
|
||||
public void onExpansionUpdate(float expansionFraction, int state) {
|
||||
if(view.isExpanded() == bindableBoolean.get()) return;
|
||||
bindableBoolean.set(state == 1);
|
||||
}
|
||||
};
|
||||
|
||||
view.setTag(R.id.bound_observable, new Pair<>(bindableBoolean, watcher));
|
||||
view.setOnExpansionUpdateListener(watcher);
|
||||
}
|
||||
boolean newValue = bindableBoolean.get();
|
||||
if (!view.isExpanded() == newValue) {
|
||||
if(newValue) view.expand(true);
|
||||
else view.collapse(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package it.integry.integrywmsnative.core.di.binders;
|
||||
|
||||
import android.databinding.BindingAdapter;
|
||||
import android.support.design.widget.TextInputLayout;
|
||||
|
||||
public class TextInputLayoutBinders {
|
||||
|
||||
@BindingAdapter("app:errorText")
|
||||
public static void setErrorMessage(TextInputLayout view, String errorMessage) {
|
||||
view.setError(errorMessage);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package it.integry.integrywmsnative.core.settings;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DBSettingsModel {
|
||||
|
||||
private List<String> availableProfiles = null;
|
||||
private List<String> availableCodMdep = null;
|
||||
|
||||
public List<String> getAvailableProfiles() {
|
||||
return availableProfiles;
|
||||
}
|
||||
|
||||
public void setAvailableProfiles(List<String> availableProfiles) {
|
||||
this.availableProfiles = availableProfiles;
|
||||
}
|
||||
|
||||
public List<String> getAvailableCodMdep() {
|
||||
return availableCodMdep;
|
||||
}
|
||||
|
||||
public void setAvailableCodMdep(List<String> availableCodMdep) {
|
||||
this.availableCodMdep = availableCodMdep;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package it.integry.integrywmsnative.core.settings;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import it.integry.integrywmsnative.core.REST.consumers.ISimpleOperationCallback;
|
||||
import it.integry.integrywmsnative.core.REST.consumers.SystemRESTConsumer;
|
||||
|
||||
public class SettingsManager {
|
||||
|
||||
private static String TAG = "SETTINGS";
|
||||
|
||||
private static SettingsModel settingsModelIstance;
|
||||
private static DBSettingsModel dbSettingsModelIstance;
|
||||
|
||||
private static boolean firstStart = false;
|
||||
|
||||
public static void init(){
|
||||
settingsModelIstance = (SettingsModel) Stash.getObject(TAG, SettingsModel.class);
|
||||
|
||||
if(settingsModelIstance == null) {
|
||||
settingsModelIstance = new SettingsModel();
|
||||
|
||||
settingsModelIstance.server = new SettingsModel.Server();
|
||||
settingsModelIstance.user = new SettingsModel.User();
|
||||
settingsModelIstance.userSession = new SettingsModel.UserSession();
|
||||
|
||||
dbSettingsModelIstance = new DBSettingsModel();
|
||||
|
||||
firstStart = true;
|
||||
}
|
||||
|
||||
dbSettingsModelIstance = new DBSettingsModel();
|
||||
|
||||
}
|
||||
|
||||
public static SettingsModel i(){
|
||||
return settingsModelIstance;
|
||||
}
|
||||
public static DBSettingsModel iDB(){
|
||||
return dbSettingsModelIstance;
|
||||
}
|
||||
|
||||
public static boolean isFirstStart(){
|
||||
return firstStart;
|
||||
}
|
||||
|
||||
public static void update(){
|
||||
Stash.put(TAG, settingsModelIstance);
|
||||
}
|
||||
|
||||
public static void reloadDBVariables(final ISimpleOperationCallback callback){
|
||||
dbSettingsModelIstance = new DBSettingsModel();
|
||||
|
||||
SystemRESTConsumer.getAvailableProfiles(new ISimpleOperationCallback<List<String>>() {
|
||||
@Override
|
||||
public void onSuccess(List<String> availableProfiles) {
|
||||
dbSettingsModelIstance.setAvailableProfiles(availableProfiles);
|
||||
if(callback != null) callback.onSuccess(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(Exception ex) {
|
||||
//BOH
|
||||
if(callback != null) callback.onFailed(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,26 @@ package it.integry.integrywmsnative.core.settings;
|
||||
|
||||
public class SettingsModel {
|
||||
|
||||
public static String currentUserCodMdep = "01";
|
||||
public static String currentUsername = "Magazzino";
|
||||
public Server server;
|
||||
public User user;
|
||||
public UserSession userSession;
|
||||
|
||||
|
||||
public static class Server {
|
||||
public String codAzienda;
|
||||
public String host;
|
||||
public int port;
|
||||
}
|
||||
|
||||
public static class User {
|
||||
public String username;
|
||||
public String password;
|
||||
}
|
||||
|
||||
public static class UserSession {
|
||||
public String profileDB;
|
||||
public String codMdep;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,241 @@
|
||||
package it.integry.integrywmsnative.core.settings;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
public class Stash {
|
||||
|
||||
private static Stash stash;
|
||||
private SharedPreferences sp;
|
||||
|
||||
public static void init(Context context) {
|
||||
stash = new Stash();
|
||||
if (stash.sp == null) {
|
||||
stash.sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkfornull() {
|
||||
if (stash == null)
|
||||
throw new NullPointerException("Call init() method in application class");
|
||||
}
|
||||
|
||||
//putString
|
||||
public static void put(String key, String value) {
|
||||
checkfornull();
|
||||
try {
|
||||
stash.sp.edit().putString(key, value).apply();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//putStringSet
|
||||
public static void put(String key, Set<String> value) {
|
||||
checkfornull();
|
||||
try {
|
||||
stash.sp.edit().putStringSet(key, value).apply();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//putInt
|
||||
public static void put(String key, int value) {
|
||||
checkfornull();
|
||||
try {
|
||||
stash.sp.edit().putInt(key, value).apply();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//putLong
|
||||
public static void put(String key, long value) {
|
||||
checkfornull();
|
||||
try {
|
||||
stash.sp.edit().putLong(key, value).apply();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//putFloat
|
||||
public static void put(String key, float value) {
|
||||
checkfornull();
|
||||
try {
|
||||
stash.sp.edit().putFloat(key, value).apply();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//putBoolean
|
||||
public static void put(String key, boolean value) {
|
||||
checkfornull();
|
||||
try {
|
||||
stash.sp.edit().putBoolean(key, value).apply();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//putObject or arrayList
|
||||
public static void put(String key, Object value) {
|
||||
checkfornull();
|
||||
try {
|
||||
Gson gson = new GsonBuilder().create();
|
||||
stash.sp.edit().putString(key, gson.toJson(value).toString()).apply();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//getString
|
||||
public static String getString(String key, String defaultvalue) {
|
||||
checkfornull();
|
||||
try {
|
||||
return stash.sp.getString(key, defaultvalue);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return defaultvalue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//getStringSet
|
||||
public static Set<String> getStringSet(String key, Set<String> defaultvalue) {
|
||||
checkfornull();
|
||||
try {
|
||||
return getStringSet(key, defaultvalue);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return defaultvalue;
|
||||
}
|
||||
}
|
||||
|
||||
//getInt
|
||||
public static int getInt(String key, int defaultvalue) {
|
||||
checkfornull();
|
||||
try {
|
||||
return stash.sp.getInt(key, defaultvalue);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return defaultvalue;
|
||||
}
|
||||
}
|
||||
|
||||
//getLong
|
||||
public static long getLong(String key, long defaultvalue) {
|
||||
checkfornull();
|
||||
try {
|
||||
return stash.sp.getLong(key, defaultvalue);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return defaultvalue;
|
||||
}
|
||||
}
|
||||
|
||||
//getFloat
|
||||
public static float getFloat(String key, float defaultvalue) {
|
||||
checkfornull();
|
||||
try {
|
||||
return stash.sp.getFloat(key, defaultvalue);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return defaultvalue;
|
||||
}
|
||||
}
|
||||
|
||||
//getBoolean
|
||||
public static boolean getBoolean(String key, boolean defaultvalue) {
|
||||
checkfornull();
|
||||
try {
|
||||
return stash.sp.getBoolean(key, defaultvalue);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return defaultvalue;
|
||||
}
|
||||
}
|
||||
|
||||
//getObject
|
||||
public static <T> Object getObject(String key, Class<?> tClass) {
|
||||
checkfornull();
|
||||
try {
|
||||
Gson gson = new GsonBuilder().create();
|
||||
return gson.fromJson(stash.sp.getString(key, ""), tClass);
|
||||
} catch (Exception e) {
|
||||
Log.e("gson", e.getMessage());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
//getArrayList
|
||||
public static <T> ArrayList<T> getArrayList(String key, Class<?> tClass) {
|
||||
Log.e("_+_++__+_+", "" + tClass.getName());
|
||||
Gson gson = new Gson();
|
||||
String data = stash.sp.getString(key, "");
|
||||
if (!data.trim().isEmpty()) {
|
||||
Type type = new GenericType(tClass);
|
||||
return (ArrayList<T>) gson.fromJson(data, type);
|
||||
}
|
||||
return new ArrayList<T>();
|
||||
}
|
||||
|
||||
//clear single value
|
||||
public static void clear(String key) {
|
||||
checkfornull();
|
||||
try {
|
||||
stash.sp.edit().remove(key).apply();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//clear all preference
|
||||
public static void clearAll() {
|
||||
checkfornull();
|
||||
try {
|
||||
stash.sp.edit().clear().apply();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static class GenericType implements ParameterizedType {
|
||||
|
||||
private Type type;
|
||||
|
||||
GenericType(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type[] getActualTypeArguments() {
|
||||
return new Type[]{type};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getRawType() {
|
||||
return ArrayList.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getOwnerType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// implement equals method too! (as per javadoc)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package it.integry.integrywmsnative.core.utility;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
|
||||
import it.integry.integrywmsnative.core.REST.consumers.ISingleValueOperationCallback;
|
||||
|
||||
public class UtilityServer {
|
||||
|
||||
public static void isHostReachable(final String serverAddress, final int serverTCPport, final ISingleValueOperationCallback<Boolean> callback){
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
boolean connected = false;
|
||||
Socket socket;
|
||||
try {
|
||||
socket = new Socket();
|
||||
SocketAddress socketAddress = new InetSocketAddress(serverAddress, serverTCPport);
|
||||
socket.connect(socketAddress, 10000);
|
||||
if (socket.isConnected()) {
|
||||
connected = true;
|
||||
socket.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
socket = null;
|
||||
}
|
||||
|
||||
callback.onResult(connected);
|
||||
|
||||
}
|
||||
}).start();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package it.integry.integrywmsnative.core.utility;
|
||||
|
||||
import it.integry.integrywmsnative.core.settings.SettingsManager;
|
||||
import it.integry.integrywmsnative.core.settings.SettingsModel;
|
||||
|
||||
public class UtilitySettings {
|
||||
|
||||
|
||||
public static void logout(){
|
||||
SettingsManager.i().user = new SettingsModel.User();
|
||||
SettingsManager.i().userSession = new SettingsModel.UserSession();
|
||||
|
||||
SettingsManager.update();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package it.integry.integrywmsnative.core.utility;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
public class UtilityWindow {
|
||||
|
||||
public static void maximizeToFullScreen(Activity activity){
|
||||
activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package it.integry.integrywmsnative.core.wifi;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.widget.TextView;
|
||||
|
||||
import it.integry.integrywmsnative.core.REST.consumers.ISingleValueOperationCallback;
|
||||
|
||||
public class WiFiCheckerViewHolder implements ISingleValueOperationCallback<WiFiStatusChecker.SIGNAL>{
|
||||
|
||||
private TextView mWifiSignalTextView;
|
||||
|
||||
private WiFiStatusChecker mWiFiStatusChecker;
|
||||
|
||||
public WiFiCheckerViewHolder(Activity activity, int rsid){
|
||||
mWifiSignalTextView = activity.findViewById(rsid);
|
||||
|
||||
mWiFiStatusChecker = new WiFiStatusChecker(activity);
|
||||
}
|
||||
|
||||
|
||||
public void startMonitoring(){
|
||||
mWiFiStatusChecker.startMonitoring(this);
|
||||
}
|
||||
|
||||
public void stopMonitoring(){
|
||||
mWiFiStatusChecker.stopMonitoring();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResult(WiFiStatusChecker.SIGNAL value) {
|
||||
switch (value){
|
||||
case EXCELLENT:
|
||||
mWifiSignalTextView.setText("EXCELLENT");
|
||||
break;
|
||||
case GOOD:
|
||||
mWifiSignalTextView.setText("GOOD");
|
||||
break;
|
||||
case FAIR:
|
||||
mWifiSignalTextView.setText("FAIR");
|
||||
break;
|
||||
case WEAK:
|
||||
mWifiSignalTextView.setText("WEAK");
|
||||
break;
|
||||
case NONE:
|
||||
mWifiSignalTextView.setText("NONE");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package it.integry.integrywmsnative.core.wifi;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Handler;
|
||||
|
||||
import it.integry.integrywmsnative.core.REST.consumers.ISingleValueOperationCallback;
|
||||
|
||||
public class WiFiStatusChecker {
|
||||
|
||||
|
||||
public enum SIGNAL {
|
||||
EXCELLENT,
|
||||
GOOD,
|
||||
FAIR,
|
||||
WEAK,
|
||||
NONE
|
||||
}
|
||||
|
||||
private ISingleValueOperationCallback<SIGNAL> mCallback;
|
||||
|
||||
private WifiManager mWifiManager;
|
||||
private int mNumberOfLevels = 4;
|
||||
|
||||
private boolean shouldExecute = true;
|
||||
private final long MILLIS_DELAY = 5 * 1000;
|
||||
|
||||
|
||||
private Handler handler = new Handler();
|
||||
private Runnable runnableCode = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(shouldExecute) {
|
||||
WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
|
||||
int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), mNumberOfLevels);
|
||||
|
||||
SIGNAL signal;
|
||||
|
||||
switch (level){
|
||||
case 0: signal = SIGNAL.WEAK; break;
|
||||
case 1: signal = SIGNAL.FAIR; break;
|
||||
case 2: signal = SIGNAL.GOOD; break;
|
||||
case 3: signal = SIGNAL.EXCELLENT; break;
|
||||
default: signal = SIGNAL.NONE; break;
|
||||
}
|
||||
|
||||
mCallback.onResult(signal);
|
||||
|
||||
handler.postDelayed(this, MILLIS_DELAY);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public WiFiStatusChecker(Context context){
|
||||
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
}
|
||||
|
||||
public void startMonitoring(ISingleValueOperationCallback<SIGNAL> callback){
|
||||
this.mCallback = callback;
|
||||
shouldExecute = true;
|
||||
|
||||
handler.post(runnableCode);
|
||||
}
|
||||
|
||||
public void stopMonitoring(){
|
||||
shouldExecute = false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -248,9 +248,20 @@ public class MainAccettazioneFragment extends Fragment implements ICheckBoxCallb
|
||||
public void onLoadSuccess(final List<OrdineAccettazioneDTO> ordini) {
|
||||
progress.dismiss();
|
||||
|
||||
int artsCounter = ordini.size();
|
||||
List<String> ordersKeys = new ArrayList<>();
|
||||
|
||||
for(OrdineAccettazioneDTO ordine : ordini){
|
||||
if(!ordersKeys.contains(ordine.data + " " + ordine.numero + " " + ordine.gestione)){
|
||||
ordersKeys.add(ordine.data + " " + ordine.numero + " " + ordine.gestione);
|
||||
}
|
||||
}
|
||||
|
||||
DialogSimpleMessageHelper.makeInfoDialog(getActivity(),
|
||||
getText(R.string.orders).toString(),
|
||||
Html.fromHtml(String.format(getText(R.string.loaded_orders_message).toString(), ordini.size())),
|
||||
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)),
|
||||
null,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
|
||||
@@ -35,6 +35,7 @@ import it.integry.integrywmsnative.core.REST.consumers.ISimpleOperationCallback;
|
||||
import it.integry.integrywmsnative.core.model.CommonModelConsts;
|
||||
import it.integry.integrywmsnative.core.model.MtbColt;
|
||||
import it.integry.integrywmsnative.core.model.secondary.GestioneEnum;
|
||||
import it.integry.integrywmsnative.core.settings.SettingsManager;
|
||||
import it.integry.integrywmsnative.core.settings.SettingsModel;
|
||||
import it.integry.integrywmsnative.gest.accettazione.dto.OrdineAccettazioneDTO;
|
||||
import it.integry.integrywmsnative.gest.accettazione_ordine_inevaso.core.AccettazioneOrdineInevasoHelper;
|
||||
@@ -218,8 +219,8 @@ public class AccettazioneOrdineInevasoActivity extends AppCompatActivity {
|
||||
MtbColt mtbColt = new MtbColt();
|
||||
mtbColt .setDataCollo(new Date())
|
||||
.setGestione(GestioneEnum.ACQUISTO)
|
||||
.setCodMdep(SettingsModel.currentUserCodMdep)
|
||||
.setPreparatoDa(SettingsModel.currentUsername)
|
||||
.setCodMdep(SettingsManager.i().userSession.codMdep)
|
||||
.setPreparatoDa(SettingsManager.i().user.username)
|
||||
.setOraInizPrep(new Date())
|
||||
.setAnnotazioni(noteString)
|
||||
.setOperation(CommonModelConsts.OPERATION.INSERT_OR_UPDATE);
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package it.integry.integrywmsnative.gest.login;
|
||||
|
||||
import android.databinding.DataBindingUtil;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
|
||||
import it.integry.integrywmsnative.BR;
|
||||
import it.integry.integrywmsnative.R;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityWindow;
|
||||
import it.integry.integrywmsnative.databinding.ActivityLoginBinding;
|
||||
import it.integry.integrywmsnative.gest.login.viewmodel.LoginViewModel;
|
||||
|
||||
public class LoginActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
UtilityWindow.maximizeToFullScreen(this);
|
||||
|
||||
ActivityLoginBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_login);
|
||||
LoginViewModel loginViewModel = new LoginViewModel(this);
|
||||
binding.setVariable(BR.loginViewModel, loginViewModel);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
// disable going back to the MainActivity
|
||||
moveTaskToBack(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package it.integry.integrywmsnative.gest.login.core;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import it.integry.integrywmsnative.core.CommonConst;
|
||||
import it.integry.integrywmsnative.core.REST.RESTBuilder;
|
||||
import it.integry.integrywmsnative.core.REST.consumers.ISimpleOperationCallback;
|
||||
import it.integry.integrywmsnative.core.REST.consumers.ISingleOperationDoubleCallback;
|
||||
import it.integry.integrywmsnative.core.REST.model.EsitoType;
|
||||
import it.integry.integrywmsnative.core.REST.model.ServiceRESTResponse;
|
||||
import it.integry.integrywmsnative.gest.login.dto.LoginAziendaDTO;
|
||||
import it.integry.integrywmsnative.gest.login.dto.LoginDTO;
|
||||
import it.integry.integrywmsnative.gest.login.rest.LoginRESTConsumerService;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class LoginHelper {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private String mCodAzienda;
|
||||
private String mUsername;
|
||||
private String mPassword;
|
||||
|
||||
public LoginHelper(Context context, String codAzienda, String username, String password){
|
||||
this.mContext = context;
|
||||
|
||||
this.mCodAzienda = codAzienda;
|
||||
this.mUsername = username;
|
||||
this.mPassword = password;
|
||||
}
|
||||
|
||||
|
||||
public void retrieveServerData(final ISimpleOperationCallback<LoginAziendaDTO> callback){
|
||||
|
||||
String host = CommonConst.Login.Azienda.host;
|
||||
int port = CommonConst.Login.Azienda.port;
|
||||
|
||||
LoginRESTConsumerService service = RESTBuilder.getService(LoginRESTConsumerService.class, host, port, false);
|
||||
service.loginAzienda(mCodAzienda).enqueue(new Callback<ServiceRESTResponse<LoginAziendaDTO>>() {
|
||||
@Override
|
||||
public void onResponse(Call<ServiceRESTResponse<LoginAziendaDTO>> call, Response<ServiceRESTResponse<LoginAziendaDTO>> response) {
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
if(response.body() != null) {
|
||||
if(response.body().getEsito() == EsitoType.OK) {
|
||||
callback.onSuccess(response.body().getDto());
|
||||
} else {
|
||||
Log.e("LoginAzienda", response.body().getErrorMessage());
|
||||
callback.onFailed(new Exception(response.body().getErrorMessage()));
|
||||
}
|
||||
} else {
|
||||
Log.e("LoginAzienda", response.message());
|
||||
callback.onFailed(new Exception(response.message()));
|
||||
}
|
||||
} else {
|
||||
Log.e("LoginAzienda", "Status " + response.code() + ": " + response.message());
|
||||
callback.onFailed(new Exception("Status " + response.code() + ": " + response.message()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<ServiceRESTResponse<LoginAziendaDTO>> call, Throwable t) {
|
||||
Log.e("LoginAzienda", t.toString());
|
||||
callback.onFailed(new Exception(t));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void doLogin(String host, int port, final ISimpleOperationCallback<LoginDTO> callback){
|
||||
LoginRESTConsumerService service = RESTBuilder.getService(LoginRESTConsumerService.class, host, port, false);
|
||||
service.login(mUsername, mPassword).enqueue(new Callback<ServiceRESTResponse<LoginDTO>>() {
|
||||
@Override
|
||||
public void onResponse(Call<ServiceRESTResponse<LoginDTO>> call, Response<ServiceRESTResponse<LoginDTO>> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
if(response.body() != null) {
|
||||
if(response.body().getEsito() == EsitoType.OK) {
|
||||
callback.onSuccess(response.body().getDto());
|
||||
} else {
|
||||
Log.e("Login", response.body().getErrorMessage());
|
||||
callback.onFailed(new Exception(response.body().getErrorMessage()));
|
||||
}
|
||||
} else {
|
||||
Log.e("Login", response.message());
|
||||
callback.onFailed(new Exception(response.message()));
|
||||
}
|
||||
} else {
|
||||
Log.e("Login", "Status " + response.code() + ": " + response.message());
|
||||
callback.onFailed(new Exception("Status " + response.code() + ": " + response.message()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<ServiceRESTResponse<LoginDTO>> call, final Throwable t) {
|
||||
|
||||
Log.e("Login", t.toString());
|
||||
callback.onFailed(new Exception(t));
|
||||
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package it.integry.integrywmsnative.gest.login.dto;
|
||||
|
||||
public class LoginAziendaDTO {
|
||||
|
||||
public String profileDb;
|
||||
public String endpointRestApi;
|
||||
public String phpApi;
|
||||
public String repoPhoto;
|
||||
public String endpointPvm;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package it.integry.integrywmsnative.gest.login.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LoginDTO {
|
||||
|
||||
public String full_name;
|
||||
public List<String> availableProfiles;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package it.integry.integrywmsnative.gest.login.rest;
|
||||
|
||||
|
||||
import it.integry.integrywmsnative.core.REST.model.ServiceRESTResponse;
|
||||
import it.integry.integrywmsnative.gest.login.dto.LoginAziendaDTO;
|
||||
import it.integry.integrywmsnative.gest.login.dto.LoginDTO;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface LoginRESTConsumerService {
|
||||
|
||||
|
||||
@GET("loginAziendaWms")
|
||||
Call<ServiceRESTResponse<LoginAziendaDTO>> loginAzienda(@Query("codHash") String codHash);
|
||||
|
||||
@POST("loginWeb")
|
||||
Call<ServiceRESTResponse<LoginDTO>> login(@Query("username") String username, @Query("password") String password);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
package it.integry.integrywmsnative.gest.login.viewmodel;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
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.di.BindableBoolean;
|
||||
import it.integry.integrywmsnative.core.di.BindableString;
|
||||
import it.integry.integrywmsnative.core.settings.SettingsManager;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityServer;
|
||||
import it.integry.integrywmsnative.gest.login.LoginActivity;
|
||||
import it.integry.integrywmsnative.gest.login.core.LoginHelper;
|
||||
import it.integry.integrywmsnative.gest.login.dto.LoginAziendaDTO;
|
||||
import it.integry.integrywmsnative.gest.login.dto.LoginDTO;
|
||||
import it.integry.integrywmsnative.view.dialogs.DialogSimpleMessageHelper;
|
||||
|
||||
public class LoginViewModel {
|
||||
private static final String TAG = LoginViewModel.class.getSimpleName();
|
||||
|
||||
public BindableString username = new BindableString();
|
||||
public BindableString password = new BindableString();
|
||||
public BindableString codAzienda = new BindableString();
|
||||
|
||||
public BindableBoolean customSettingsCheckboxEnabled = new BindableBoolean();
|
||||
public BindableBoolean customSettingsCheckboxChecked = new BindableBoolean();
|
||||
|
||||
public BindableBoolean loginButtonEnabled = new BindableBoolean();
|
||||
|
||||
|
||||
public BindableString usernameError = new BindableString();
|
||||
public BindableString passwordError = new BindableString();
|
||||
public BindableString codAziendaError = new BindableString();
|
||||
|
||||
|
||||
|
||||
private LoginActivity mActivity;
|
||||
|
||||
private ProgressDialog mProgress;
|
||||
|
||||
public LoginViewModel(LoginActivity activity) {
|
||||
this.mActivity = activity;
|
||||
|
||||
loginButtonEnabled.set(true);
|
||||
|
||||
codAzienda.set(SettingsManager.i().server.codAzienda);
|
||||
|
||||
customSettingsCheckboxChecked.set(SettingsManager.i().server.host == null);
|
||||
customSettingsCheckboxEnabled.set(SettingsManager.i().server.host != null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean validate() {
|
||||
if (username.isEmpty() || username.get().length() < 3) {
|
||||
usernameError.set(mActivity.getText(R.string.username_error_not_valid).toString());
|
||||
return false;
|
||||
} else usernameError.set(null);
|
||||
|
||||
if (codAzienda.isEmpty() || codAzienda.get().length() < 3) {
|
||||
codAziendaError.set(mActivity.getText(R.string.server_cod_azienda_not_valid).toString());
|
||||
return false;
|
||||
} else codAziendaError.set(null);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void login(boolean areValidData){
|
||||
if(areValidData){
|
||||
loginButtonEnabled.set(false);
|
||||
|
||||
mProgress = ProgressDialog.show(mActivity, mActivity.getText(R.string.waiting),
|
||||
mActivity.getText(R.string.loading) + " ...", true);
|
||||
|
||||
final LoginHelper loginHelper = new LoginHelper(mActivity, codAzienda.get(), username.get(), password.get());
|
||||
|
||||
loginHelper.retrieveServerData(new ISimpleOperationCallback<LoginAziendaDTO>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(LoginAziendaDTO value) {
|
||||
|
||||
final String serverEndpoint = value.endpointRestApi;
|
||||
|
||||
URL u;
|
||||
try {
|
||||
u = new URL(serverEndpoint);
|
||||
} catch (final MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
onLoginFailed(new SpannableString(e.toString()));
|
||||
return;
|
||||
}
|
||||
|
||||
final String host = u.getHost();
|
||||
final int port = u.getPort();
|
||||
|
||||
UtilityServer.isHostReachable(host, port, new ISingleValueOperationCallback<Boolean>() {
|
||||
@Override
|
||||
public void onResult(Boolean value) {
|
||||
|
||||
if(value){ //Is online
|
||||
loginHelper.doLogin(host, port, new ISimpleOperationCallback<LoginDTO>() {
|
||||
@Override
|
||||
public void onSuccess(final LoginDTO value) {
|
||||
|
||||
SettingsManager.iDB().setAvailableProfiles(value.availableProfiles);
|
||||
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
onLoginSuccess(
|
||||
"Benvenuto",
|
||||
Html.fromHtml("Ciao <b>" + value.full_name + "</b>, la Integry le augura di svolgere al meglio il suo lavoro"),
|
||||
host, port, value.availableProfiles);
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(final Exception ex) {
|
||||
onLoginFailed(new SpannableString(ex.getMessage().toString()));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
} else { //Is not online
|
||||
onLoginFailed(Html.fromHtml(String.format(mActivity.getText(R.string.server_not_reachable).toString(), host, port)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(Exception ex) {
|
||||
onLoginFailed(Html.fromHtml(String.format(mActivity.getText(R.string.server_cod_azienda_not_valid).toString(), codAzienda)));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void onLoginFailed(final Spanned message){
|
||||
mProgress.dismiss();
|
||||
loginButtonEnabled.set(false);
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showProfileDBSelectionDialog(final String host, final int port, final List<String> availableProfiles){
|
||||
// setup the alert builder
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
|
||||
builder.setTitle(R.string.action_choose_profile_db);
|
||||
|
||||
// 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);
|
||||
|
||||
onLoginCompleted(host, port);
|
||||
}
|
||||
});
|
||||
|
||||
// create and show the alert dialog
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
Intent myIntent = new Intent(mActivity, MainActivity.class);
|
||||
mActivity.startActivity(myIntent);
|
||||
|
||||
mActivity.finish();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -76,7 +76,7 @@ public class DialogSimpleMessageHelper {
|
||||
|
||||
case ERROR:
|
||||
colorBackgroundTitle = ContextCompat.getColor(mContext, R.color.red_600);
|
||||
titleIconRes = mContext.getResources().getDrawable(R.drawable.ic_error_white_24dp);
|
||||
titleIconRes = mContext.getResources().getDrawable(R.drawable.ic_mood_bad_24dp);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user