diff --git a/Android-CleanArchitecture.iml b/REPARTO.iml old mode 100755 new mode 100644 similarity index 70% rename from Android-CleanArchitecture.iml rename to REPARTO.iml index 93b5911..afeb48b --- a/Android-CleanArchitecture.iml +++ b/REPARTO.iml @@ -1,5 +1,5 @@ - + @@ -13,7 +13,7 @@ - + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/app.iml b/app/app.iml new file mode 100644 index 0000000..9efad8e --- /dev/null +++ b/app/app.iml @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..07ab39a --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,33 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 28 + defaultConfig { + applicationId "verdnatura.es.repartoverdnatura" + minSdkVersion 19 + targetSdkVersion 28 + versionCode 2 + versionName "1.2" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'com.android.support.constraint:constraint-layout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + implementation 'com.android.support:recyclerview-v7:28.0.0' + implementation 'com.squareup.retrofit2:retrofit:2.0.2' + implementation 'com.squareup.retrofit2:converter-gson:2.0.2' + implementation 'com.squareup.retrofit2:converter-scalars:2.3.0' + implementation 'com.simplify:ink:1.0.2' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/release/output.json b/app/release/output.json new file mode 100644 index 0000000..02280a3 --- /dev/null +++ b/app/release/output.json @@ -0,0 +1 @@ +[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":2,"versionName":"1.2","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] \ No newline at end of file diff --git a/app/release/vndelivery.apk b/app/release/vndelivery.apk new file mode 100644 index 0000000..d009180 Binary files /dev/null and b/app/release/vndelivery.apk differ diff --git a/app/src/androidTest/java/verdnatura/es/repartoverdnatura/ExampleInstrumentedTest.java b/app/src/androidTest/java/verdnatura/es/repartoverdnatura/ExampleInstrumentedTest.java new file mode 100644 index 0000000..9374394 --- /dev/null +++ b/app/src/androidTest/java/verdnatura/es/repartoverdnatura/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package verdnatura.es.repartoverdnatura; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("verdnatura.es.repartoverdnatura", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..874589f --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/ADAPTERS/ClientAdapter.java b/app/src/main/java/verdnatura/es/repartoverdnatura/ADAPTERS/ClientAdapter.java new file mode 100644 index 0000000..b8d966c --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/ADAPTERS/ClientAdapter.java @@ -0,0 +1,148 @@ +package verdnatura.es.repartoverdnatura.ADAPTERS; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import java.util.List; + +import verdnatura.es.repartoverdnatura.MODELS.ClientTickets; +import verdnatura.es.repartoverdnatura.MODELS.Cliente; +import verdnatura.es.repartoverdnatura.MODELS.Ticket; +import verdnatura.es.repartoverdnatura.R; +import verdnatura.es.repartoverdnatura.Tickets; + +public class ClientAdapter extends ArrayAdapter { + public ClientAdapter(Context context, List clientes) { + super(context,0,clientes); + } + + @Override + public View getView(final int position, View convertView, ViewGroup parent) { + ClientTickets clientes = getItem(position); + + if (convertView == null){ + convertView = LayoutInflater.from(getContext()).inflate(R.layout.row_ticket,parent,false); + } + + TextView txtCliente = convertView.findViewById(R.id.textView21); + TextView txtConsignatorio = convertView.findViewById(R.id.textView17); + TextView txtTienda = convertView.findViewById(R.id.textView25); + TextView txtCalle = convertView.findViewById(R.id.textView24); + TextView txtPC = convertView.findViewById(R.id.textView27); + TextView txtCiudad = convertView.findViewById(R.id.textView26); + TextView txtNote = convertView.findViewById(R.id.txtNote); + + txtCliente.setText(clientes.getClient()); + txtConsignatorio.setText(clientes.getAddress()); + txtTienda.setText(clientes.getClientName()); + txtCalle.setText(clientes.getAddressName()); + txtPC.setText(clientes.getPostalCode()); + txtCiudad.setText(clientes.getCity()); + /*if(clientes.getNote()!= null ){ + txtNote.setText(clientes.getNote()); + txtNote.setVisibility(View.VISIBLE); + }else{ + txtNote.setVisibility(View.GONE); + }*/ + + LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); + LinearLayout viewTickets = convertView.findViewById(R.id.layoutTickets); + viewTickets.removeAllViews(); + View v; + for (int i =0; i < clientes.getTickets().size();i++){ + v = vi.inflate(R.layout.row_sub_ticket,null); + TextView txtTicket = v.findViewById(R.id.textView29); + TextView txtPackage = v.findViewById(R.id.textView31); + TextView txtWarehouse = v.findViewById(R.id.textView33); + ImageView btnPolizon = v.findViewById(R.id.btnPolizon); + txtTicket.setText(clientes.getTickets().get(i).get("Id")); + txtPackage.setText(clientes.getTickets().get(i).get("Packages")); + txtWarehouse.setText(clientes.getTickets().get(i).get("Warehouse")); + if(clientes.getTickets().get(i).get("Polizon") != null){ + final int posTicket = i; + btnPolizon.setVisibility(View.VISIBLE); + btnPolizon.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if(getContext() instanceof Tickets){ + ((Tickets) getContext()).showPolizon(position,posTicket); + } + } + }); + }else{ + btnPolizon.setVisibility(View.GONE); + } + //rellenamos datos + viewTickets.addView(v); + } + + + ImageView btnPhone = convertView.findViewById(R.id.imageView4); + ImageView btnMap = convertView.findViewById(R.id.imageView5); + ImageView btnSign = convertView.findViewById(R.id.imageView6); + ImageView btnNote = convertView.findViewById(R.id.imageView7); + LinearLayout lyNote = convertView.findViewById(R.id.btnNote); + ImageView btnAddNote = convertView.findViewById(R.id.imageView9); + + if (clientes.getNote() != null && clientes.getNote().length()>0){ + lyNote.setVisibility(View.VISIBLE); + }else{ + lyNote.setVisibility(View.GONE); + } + + + btnPhone.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if(getContext() instanceof Tickets){ + ((Tickets) getContext()).showPhones(position); + } + } + }); + + btnMap.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if(getContext() instanceof Tickets){ + ((Tickets) getContext()).goMaps(position); + } + } + }); + + btnSign.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if(getContext() instanceof Tickets){ + ((Tickets) getContext()).goSign(position); + } + } + }); + + btnNote.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if(getContext() instanceof Tickets){ + ((Tickets) getContext()).showNote(position); + } + } + }); + + btnAddNote.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if(getContext() instanceof Tickets){ + ((Tickets) getContext()).goToNotes(position); + } + } + }); + + return convertView; + } +} \ No newline at end of file diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/ADAPTERS/PendingTickets.java b/app/src/main/java/verdnatura/es/repartoverdnatura/ADAPTERS/PendingTickets.java new file mode 100644 index 0000000..15bf5b8 --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/ADAPTERS/PendingTickets.java @@ -0,0 +1,50 @@ +package verdnatura.es.repartoverdnatura.ADAPTERS; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TextView; + +import org.w3c.dom.Text; + +import java.util.List; + +import verdnatura.es.repartoverdnatura.MODELS.SignDataUpload; +import verdnatura.es.repartoverdnatura.MODELS.Ticket; +import verdnatura.es.repartoverdnatura.MainActivity; +import verdnatura.es.repartoverdnatura.R; + +public class PendingTickets extends ArrayAdapter { +public PendingTickets(Context context, List signs) { + super(context,0,signs); + } + +@Override +public View getView(final int position, View convertView, ViewGroup parent) { + SignDataUpload sign = getItem(position); + + if (convertView == null){ + convertView = LayoutInflater.from(getContext()).inflate(R.layout.ticket_pending_row,parent,false); + } + + TextView txtIdCliente = convertView.findViewById(R.id.txtIdCliente); + TextView txtNameCliente = convertView.findViewById(R.id.txtNameCliente); + + txtIdCliente.setText(sign.getIdClient()); + txtNameCliente.setText(sign.getClientName()); + + convertView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (getContext() instanceof MainActivity) { + ((MainActivity) getContext()).savePending(position); + } + } + }); + + + return convertView; + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/ADAPTERS/PhonesAdapter.java b/app/src/main/java/verdnatura/es/repartoverdnatura/ADAPTERS/PhonesAdapter.java new file mode 100644 index 0000000..46b253a --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/ADAPTERS/PhonesAdapter.java @@ -0,0 +1,60 @@ +package verdnatura.es.repartoverdnatura.ADAPTERS; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TextView; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.List; +import verdnatura.es.repartoverdnatura.R; +import verdnatura.es.repartoverdnatura.Tickets; + +public class PhonesAdapter extends ArrayAdapter { + private DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); + public List phones; + + + + public PhonesAdapter(Context context, List phones) { + super(context,0,phones); + this.phones = phones; + } + + @Override + public View getView(final int position, View convertView, ViewGroup parent) { + final String phone = getItem(position); + + if (convertView == null){ + convertView = LayoutInflater.from(getContext()).inflate(R.layout.phone_row,parent,false); + } + TextView txtTitulo = convertView.findViewById(R.id.txtTitulo); + TextView txtPhone = convertView.findViewById(R.id.txtPhone); + + if(position < (phones.size() - 1)){ + + txtTitulo.setText(getContext().getResources().getString(R.string.telefono)+" "+(position+1)); + + + }else{ + txtTitulo.setText(getContext().getResources().getString(R.string.comercial)); + } + txtPhone.setText(phone); + + convertView.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + if(getContext() instanceof Tickets){ + ((Tickets) getContext()).llamarTelefono(phone); + } + + return false; + } + }); + + return convertView; + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/ADAPTERS/RutaAdapter.java b/app/src/main/java/verdnatura/es/repartoverdnatura/ADAPTERS/RutaAdapter.java new file mode 100644 index 0000000..a91cc12 --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/ADAPTERS/RutaAdapter.java @@ -0,0 +1,93 @@ +package verdnatura.es.repartoverdnatura.ADAPTERS; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.List; + +import verdnatura.es.repartoverdnatura.MODELS.Ruta; +import verdnatura.es.repartoverdnatura.MainActivity; +import verdnatura.es.repartoverdnatura.R; +import verdnatura.es.repartoverdnatura.UTILS.LocalStorage; + +public class RutaAdapter extends ArrayAdapter { + private DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); + public RutaAdapter(Context context, List rutas) { + super(context,0,rutas); + } + + @Override + public View getView(final int position, View convertView, ViewGroup parent) { + Ruta ruta = getItem(position); + + if (ruta.getHeader()){ + convertView = LayoutInflater.from(getContext()).inflate(R.layout.header_route,parent,false); + TextView txtHour = convertView.findViewById(R.id.textView16); + try { + txtHour.setText(new SimpleDateFormat("dd/MM/yyyy").format(format.parse(ruta.getDate()))); + }catch (Exception e){ + + } + + }else{ + convertView = LayoutInflater.from(getContext()).inflate(R.layout.row_route,parent,false); + TextView txtIdRuta = convertView.findViewById(R.id.textView11); + TextView txtZona = convertView.findViewById(R.id.textView8); + TextView txtPalete = convertView.findViewById(R.id.textView12); + TextView txtM3 = convertView.findViewById(R.id.txtM3); + TextView txtHour = convertView.findViewById(R.id.textView15); + LinearLayout btnShow = convertView.findViewById(R.id.linearLayout); + TextView btnCargador = convertView.findViewById(R.id.btnCargadores); + TextView txtOnline = convertView.findViewById(R.id.txtOnline); + ImageView imgNoWeb = convertView.findViewById(R.id.imageView10); + + txtIdRuta.setText(ruta.getId()); + txtZona.setText(ruta.getAgency()); + txtPalete.setText(ruta.getPlate()); + txtM3.setText(ruta.getM3()); + txtHour.setText(ruta.getHour()); + + btnShow.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (getContext() instanceof MainActivity) { + ((MainActivity) getContext()).onRouteSelected(position); + } + } + }); + + btnCargador.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (getContext() instanceof MainActivity) { + ((MainActivity) getContext()).goToLoaders(position); + } + } + }); + + if (LocalStorage.isOfflineAviable(getContext(),ruta.getId())){ + txtOnline.setText(getContext().getResources().getString(R.string.disponible_offline)); + txtOnline.setTextColor(getContext().getResources().getColor(R.color.colorGreen)); + imgNoWeb.setVisibility(View.GONE); + }else{ + txtOnline.setText(getContext().getResources().getString(R.string.no_disponible)); + txtOnline.setTextColor(getContext().getResources().getColor(R.color.colorGray)); + imgNoWeb.setVisibility(View.VISIBLE); + } + + } + + + + return convertView; + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/ADAPTERS/WorkerAdapter.java b/app/src/main/java/verdnatura/es/repartoverdnatura/ADAPTERS/WorkerAdapter.java new file mode 100644 index 0000000..68118cd --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/ADAPTERS/WorkerAdapter.java @@ -0,0 +1,122 @@ +package verdnatura.es.repartoverdnatura.ADAPTERS; + +import android.content.Context; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.Filter; +import android.widget.Filterable; +import android.widget.LinearLayout; +import android.widget.TextView; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; + +import verdnatura.es.repartoverdnatura.LoadersActivity; +import verdnatura.es.repartoverdnatura.MODELS.Worker; +import verdnatura.es.repartoverdnatura.R; + +public class WorkerAdapter extends ArrayAdapter implements Filterable { + private DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); + List workers; + List allWorkers; + public WorkerAdapter(Context context, List workers) { + super(context,0,workers); + this.workers = workers; + this.allWorkers = workers; + } + + @Override + public View getView(final int position, View convertView, ViewGroup parent) { + final Worker worker = getItem(position); + + convertView = LayoutInflater.from(getContext()).inflate(R.layout.row_worker,parent,false); + TextView txtId = convertView.findViewById(R.id.textView11); + TextView txtFullName = convertView.findViewById(R.id.textView8); + TextView txtWorkerCode = convertView.findViewById(R.id.textView13); + TextView txtName = convertView.findViewById(R.id.txtCity); + LinearLayout layerSelected = convertView.findViewById(R.id.layerSelected); + if (worker.getSelected()){ + layerSelected.setBackgroundColor(getContext().getResources().getColor(R.color.colorPrimary)); + }else{ + layerSelected.setBackgroundColor(getContext().getResources().getColor(R.color.colorMainBg)); + } + + txtId.setText(worker.getId()); + txtFullName.setText(worker.getFullName()); + txtWorkerCode.setText(worker.getWorkerCode()); + txtName.setText(worker.getName()); + + convertView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (getContext() instanceof LoadersActivity){ + ((LoadersActivity) getContext()).setSelectedWorker(worker); + } + + } + }); + + return convertView; + } + + @Override + public int getCount() { + return workers.size(); + } + + @Override + public Worker getItem(int position) { + return workers.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + public List getAllWorkers(){ + return allWorkers; + } + + @Override + public Filter getFilter() { + Filter filter = new Filter() { + + @SuppressWarnings("unchecked") + @Override + protected void publishResults(CharSequence constraint, FilterResults results) { + workers = (List) results.values; + notifyDataSetChanged(); + } + + @Override + protected FilterResults performFiltering(CharSequence constraint) { + + FilterResults results = new FilterResults(); + ArrayList FilteredArrayNames = new ArrayList<>(); + + constraint = constraint.toString().toLowerCase(); + for (int i = 0; i < allWorkers.size(); i++) { + String dataNames = allWorkers.get(i).getFullName(); + String dataCode = allWorkers.get(i).getWorkerCode(); + if (dataNames.toLowerCase().contains(constraint.toString()) || dataCode.toLowerCase().contains(constraint.toString())) { + FilteredArrayNames.add(allWorkers.get(i)); + } + } + + results.count = FilteredArrayNames.size(); + results.values = FilteredArrayNames; + Log.e("VALUES", results.values.toString()); + + return results; + } + }; + + return filter; + } + +} \ No newline at end of file diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/ConfigureActivity.java b/app/src/main/java/verdnatura/es/repartoverdnatura/ConfigureActivity.java new file mode 100644 index 0000000..e229781 --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/ConfigureActivity.java @@ -0,0 +1,156 @@ +package verdnatura.es.repartoverdnatura; + +import android.app.Activity; +import android.app.TimePickerDialog; +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.TimePicker; + +import java.text.DecimalFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import verdnatura.es.repartoverdnatura.INTERFACES.RestClient; +import verdnatura.es.repartoverdnatura.MODELS.Ruta; +import verdnatura.es.repartoverdnatura.UTILS.ApiUtils; +import verdnatura.es.repartoverdnatura.UTILS.Utils; + +public class ConfigureActivity extends AppCompatActivity { + + private TextView txtTitle; + private EditText txtKmStart,txtKmFinish,txtHourStart,txtHourFinish; + public Ruta route; + private RestClient restClient; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + restClient = ApiUtils.getAPIService(); + Intent intent = this.getIntent(); + Bundle bundle = intent.getExtras(); + route = (Ruta) bundle.getSerializable("route"); + setContentView(R.layout.activity_configure); + setViews(); + setEvents(); + } + + private void setViews(){ + txtTitle = findViewById(R.id.textView19); + txtTitle.setText(route.getAgency()); + + txtKmStart = findViewById(R.id.editText); + txtKmStart.setText(route.getKmStart()); + txtKmFinish = findViewById(R.id.editText1); + txtKmFinish.setText(route.getKmEnd()); + txtHourStart = findViewById(R.id.editText12); + txtHourStart.setText(getHour(route.getdStart())); + txtHourFinish = findViewById(R.id.editText123); + txtHourFinish.setText(getHour(route.getdEnd())); + } + + private void setEvents(){ + txtHourStart.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + + TimePickerDialog mTimePicker; + Calendar mcurrentTime = Calendar.getInstance(); + int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY); + int minute = mcurrentTime.get(Calendar.MINUTE); + + mTimePicker = new TimePickerDialog(ConfigureActivity.this, new TimePickerDialog.OnTimeSetListener() { + @Override + public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) { + txtHourStart.setText( selectedHour + ":" + selectedMinute); + } + }, hour, minute, true);//Yes 24 hour time + mTimePicker.setTitle("Select Time"); + mTimePicker.show(); + } + }); + + txtHourFinish.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + + TimePickerDialog mTimePicker; + Calendar mcurrentTime = Calendar.getInstance(); + int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY); + int minute = mcurrentTime.get(Calendar.MINUTE); + + mTimePicker = new TimePickerDialog(ConfigureActivity.this, new TimePickerDialog.OnTimeSetListener() { + @Override + public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) { + txtHourFinish.setText( selectedHour + ":" + selectedMinute); + } + }, hour, minute, true);//Yes 24 hour time + mTimePicker.setTitle("Select Time"); + mTimePicker.show(); + } + }); + } + + private String getHour(String date) { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Calendar cal = Calendar.getInstance(); + try { + cal.setTime(format.parse(date)); + DecimalFormat f = new DecimalFormat("00"); + return ""+f.format(cal.get(Calendar.HOUR_OF_DAY))+":"+f.format(cal.get(Calendar.MINUTE)); + + } catch (ParseException e) { + e.printStackTrace(); + return "00:00"; + } + } + + public void sendConfig(View v){ + Utils.progressBar.show(this,getResources().getString(R.string.please_wait)); + final ConfigureActivity that = this; + Object[] args = new Object[5]; + args[0] = route.getId(); + args[1] = txtKmStart.getText().toString().trim(); + args[2] = txtKmFinish.getText().toString().trim(); + args[3] = txtHourStart.getText().toString().trim(); + args[4] = txtHourFinish.getText().toString().trim(); + restClient.saveConfig(Utils.getMapWhitUser(this),args).enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + Utils.progressBar.getDialog().dismiss(); + if(response.isSuccessful()){ + if (response.body().equals("Finish")){ + Log.i("INFO","guardado"); + Intent returnIntent = new Intent(); + route.setKmStart(txtKmStart.getText().toString().trim()); + route.setKmEnd(txtKmFinish.getText().toString().trim()); + route.setdStart("2019-03-09 "+txtHourStart.getText().toString().trim()+":00"); + route.setdEnd("2019-03-09 "+txtHourFinish.getText().toString().trim()+":00"); + returnIntent.putExtra("route",route); + setResult(Activity.RESULT_OK,returnIntent); + finish(); + }else{ + Utils.showErrorDialog(that,that.getResources().getString(R.string.error_conexion)); + } + + }else{ + Log.i("ERROR","error al guardar"); + Utils.showErrorDialog(that,that.getResources().getString(R.string.error_conexion)); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + Utils.progressBar.getDialog().dismiss(); + Utils.showErrorDialog(that,that.getResources().getString(R.string.error_conexion)); + } + }); + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/INTERFACES/RestClient.java b/app/src/main/java/verdnatura/es/repartoverdnatura/INTERFACES/RestClient.java new file mode 100644 index 0000000..30cd3e9 --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/INTERFACES/RestClient.java @@ -0,0 +1,44 @@ +package verdnatura.es.repartoverdnatura.INTERFACES; + +import java.util.List; +import java.util.Map; +import retrofit2.Call; +import retrofit2.http.Body; +import retrofit2.http.HeaderMap; +import retrofit2.http.POST; +import verdnatura.es.repartoverdnatura.MODELS.Cliente; +import verdnatura.es.repartoverdnatura.MODELS.Ruta; +import verdnatura.es.repartoverdnatura.MODELS.Version; +import verdnatura.es.repartoverdnatura.MODELS.Worker; + + +public interface RestClient { + @POST("/security/login") + Call login(@HeaderMap Map headers, @Body String[] userData); + + @POST("/security/getVersion") + Call getVersion(@HeaderMap Map headers, @Body String[] userData); + + @POST("/delivery/get_routes") + Call> getRoutes(@HeaderMap Map headers); + + @POST("/delivery/get_tickets") + Call> getClients(@HeaderMap Map headers, @Body String[] route); + + @POST("/delivery/save_sign") + Call saveSign(@HeaderMap Map headers,@Body Object[] args); + + @POST("/delivery/update_routes") + Call saveConfig(@HeaderMap Map headers,@Body Object[] args); + + @POST("/delivery/getWorkers") + Call> getWorkers(@HeaderMap Map headers); + + @POST("/delivery/saveLoadersWorkers") + Call saveLoadersWorkers(@HeaderMap Map headers,@Body Object[] args); + + @POST("/delivery/addNote") + Call addNote(@HeaderMap Map headers,@Body Object[] args); + + +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/InfoActivity.java b/app/src/main/java/verdnatura/es/repartoverdnatura/InfoActivity.java new file mode 100644 index 0000000..2bb42f4 --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/InfoActivity.java @@ -0,0 +1,13 @@ +package verdnatura.es.repartoverdnatura; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; + +public class InfoActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_info); + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/LoadersActivity.java b/app/src/main/java/verdnatura/es/repartoverdnatura/LoadersActivity.java new file mode 100644 index 0000000..80e58a8 --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/LoadersActivity.java @@ -0,0 +1,196 @@ +package verdnatura.es.repartoverdnatura; + +import android.app.Activity; +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.util.Log; +import android.view.KeyEvent; +import android.view.View; +import android.view.ViewGroup; +import android.widget.EditText; +import android.widget.ListView; +import android.widget.TextView; + +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Stream; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import verdnatura.es.repartoverdnatura.ADAPTERS.RutaAdapter; +import verdnatura.es.repartoverdnatura.ADAPTERS.WorkerAdapter; +import verdnatura.es.repartoverdnatura.INTERFACES.RestClient; +import verdnatura.es.repartoverdnatura.MODELS.Ruta; +import verdnatura.es.repartoverdnatura.MODELS.Worker; +import verdnatura.es.repartoverdnatura.MODELS.WorkerSave; +import verdnatura.es.repartoverdnatura.UTILS.ApiUtils; +import verdnatura.es.repartoverdnatura.UTILS.Utils; + +public class LoadersActivity extends AppCompatActivity { + + private ListView workersListView; + private ArrayList listWorkers = new ArrayList<>(); + private ArrayList listWorkersSelected = new ArrayList<>(); + private ArrayList listWorkersNoSelected = new ArrayList<>(); + private WorkerAdapter adapter; + private TextView txtTotal; + private EditText txtWorker; + private RestClient restClient; + public String idRoute = "0"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_loaders); + restClient = ApiUtils.getAPIService(); + Intent intent = this.getIntent(); + Bundle bundle = intent.getExtras(); + idRoute = bundle.getString("idRoute"); + setViews(); + getWorkers(); + setEvents(); + } + + private void setViews(){ + workersListView = findViewById(R.id.listWorkers); + txtTotal = findViewById(R.id.textView38); + txtWorker = findViewById(R.id.editText2); + } + + private void setEvents(){ + + txtWorker.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + + } + + @Override + public void afterTextChanged(Editable editable) { + Log.i("Worker",txtWorker.getText().toString()); + filterList(); + } + }); + + + } + + public void filterList(){ + this.adapter.getFilter().filter(txtWorker.getText()); + } + + private void getWorkers(){ + listWorkers = new ArrayList<>(); + final LoadersActivity that = this; + Utils.progressBar.show(this,getResources().getString(R.string.please_wait)); + restClient.getWorkers(Utils.getMapWhitUser(this)).enqueue(new Callback>() { + @Override + public void onResponse(Call> call, Response> response) { + Utils.progressBar.getDialog().dismiss(); + if (response.isSuccessful()){ + for (Worker w : response.body()){ + if(w.getRouteLoader() != null && w.getRouteLoader().equals(idRoute)){ + w.setSelected(true); + listWorkersSelected.add(w); + }else{ + if(w.getRouteLoader() == null){ + w.setSelected(false); + listWorkersNoSelected.add(w); + } + + } + + } + listWorkers.addAll(listWorkersSelected); + listWorkers.addAll(listWorkersNoSelected); + adapter = new WorkerAdapter(that,listWorkers); + workersListView.setAdapter(adapter); + txtTotal.setText(""+getSelecteds()+" "+getResources().getString(R.string.seleccionados)); + }else{ + Utils.showErrorDialog(that,that.getResources().getString(R.string.error_conexion)); + } + } + + @Override + public void onFailure(Call> call, Throwable t) { + Utils.progressBar.getDialog().dismiss(); + Utils.showErrorDialog(that,that.getResources().getString(R.string.error_conexion)); + } + }); + + + } + + public void setSelectedWorker(Worker worker){ + int pos = 0; + for (Worker w : listWorkers){ + if (worker == w){ + break; + } + pos+=1; + } + listWorkers.get(pos).setSelected(!listWorkers.get(pos).getSelected()); + adapter.notifyDataSetChanged(); + txtTotal.setText(""+getSelecteds()+" "+getResources().getString(R.string.seleccionados)); + } + + private int getSelecteds(){ + int count = 0; + for(Worker w : listWorkers){ + if (w.getSelected()) count += 1; + } + return count; + } + + public void saveWorkers(View v){ + Utils.progressBar.show(this,getResources().getString(R.string.please_wait)); + final LoadersActivity that = this; + ArrayList workersId = new ArrayList<>(); + for (Worker w:listWorkers){ + if (w.getSelected()){ + workersId.add(w.getId()); + } + } + WorkerSave ws = new WorkerSave(idRoute,workersId); + Object[] args = new Object[1]; + args[0] = ws; + restClient.saveLoadersWorkers(Utils.getMapWhitUser(this),args).enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + Utils.progressBar.getDialog().dismiss(); + if(response.isSuccessful()){ + if (response.body().equals("Finish")){ + finish(); + }else{ + Utils.showErrorDialog(that,that.getResources().getString(R.string.error_conexion)); + } + }else{ + Utils.showErrorDialog(that,that.getResources().getString(R.string.error_conexion)); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + Utils.progressBar.getDialog().dismiss(); + Utils.showErrorDialog(that,that.getResources().getString(R.string.error_conexion)); + } + }); + } + + public void orderWorkers(){ + + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/LoginActivity.java b/app/src/main/java/verdnatura/es/repartoverdnatura/LoginActivity.java new file mode 100644 index 0000000..0ea71ff --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/LoginActivity.java @@ -0,0 +1,110 @@ +package verdnatura.es.repartoverdnatura; + +import android.app.AlertDialog; +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.text.InputType; +import android.text.method.HideReturnsTransformationMethod; +import android.text.method.PasswordTransformationMethod; +import android.util.Log; +import android.view.View; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.EditText; + +import java.util.HashMap; +import java.util.Map; + +import okhttp3.ResponseBody; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import verdnatura.es.repartoverdnatura.INTERFACES.RestClient; +import verdnatura.es.repartoverdnatura.UTILS.ApiUtils; +import verdnatura.es.repartoverdnatura.UTILS.CustomProgressBar; +import verdnatura.es.repartoverdnatura.UTILS.Utils; + +public class LoginActivity extends AppCompatActivity { + + private RestClient restClient; + private EditText txtUser,txtPassword; + private CheckBox checkVerPass; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_login); + restClient = ApiUtils.getAPIService(); + setViews(); + setEvents(); + + checkUser(); + } + + private void checkUser(){ + if (!Utils.getIdUser(this).equals("nouser")){ + startActivity(new Intent(this,MainActivity.class)); + } + } + + private void setViews(){ + txtUser = findViewById(R.id.txtUsuario); + txtPassword = findViewById(R.id.txtPassword); + checkVerPass = findViewById(R.id.checkVerPass); + } + + private void setEvents(){ + checkVerPass.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { + if(!isChecked){ + txtPassword.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); + + }else{ + txtPassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); + } + } + }); + } + + public void logIn(View v){ + Utils.progressBar.show(this,"Check user"); + final String user = txtUser.getText().toString(); + final String password = txtPassword.getText().toString(); + String[] userData = new String[2]; + + final LoginActivity that = this; + + restClient.login(Utils.getMap(user,password),userData).enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + Utils.progressBar.getDialog().dismiss(); + if(response.isSuccessful()){ + Log.i("API","Respuesta: "+response.body()); + Utils.saveIdUser(that,response.body()); + Utils.saveUserPass(that,user,password); + startActivity(new Intent(that,MainActivity.class)); + txtUser.setText(""); + txtPassword.setText(""); + }else{ + Utils.showErrorDialog(that,that.getResources().getString(R.string.usuario_incorrecto)); + Log.e("API", "Response is not successful "+response.message()); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + Utils.progressBar.getDialog().dismiss(); + Utils.showErrorDialog(that,that.getResources().getString(R.string.error_conexion)); + } + }); + + + } + + public void showPassword(View v){ + txtPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/ClientTickets.java b/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/ClientTickets.java new file mode 100644 index 0000000..2a99b92 --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/ClientTickets.java @@ -0,0 +1,149 @@ +package verdnatura.es.repartoverdnatura.MODELS; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Map; + +public class ClientTickets implements Serializable { + + private String Client,ClientName,Address,AddressName,PostalCode,City,SalePersonPhone,Note,Latitude,Longitude,Polizon; + private Boolean Signed; + private ArrayList Phones; + private ArrayList> tickets; + + public ClientTickets(String client, String clientName, String address, String addressName, String postalCode, String city, String salePersonPhone, String note, String latitude, String longitude, Boolean signed, ArrayList phones, ArrayList> tickets,String polizon) { + Client = client; + ClientName = clientName; + Address = address; + AddressName = addressName; + PostalCode = postalCode; + City = city; + SalePersonPhone = salePersonPhone; + Note = note; + Latitude = latitude; + Longitude = longitude; + Signed = signed; + Phones = phones; + this.tickets = tickets; + Polizon = polizon; + + } + + public String getPolizon() { + return Polizon; + } + + public void setPolizon(String polizon) { + Polizon = polizon; + } + + public ArrayList> getTickets() { + return tickets; + } + + public void setTickets(ArrayList> tickets) { + this.tickets = tickets; + } + + public void addTicket(Map values){ + tickets.add(values); + } + + public String getClient() { + return Client; + } + + public void setClient(String client) { + Client = client; + } + + public String getClientName() { + return ClientName; + } + + public void setClientName(String clientName) { + ClientName = clientName; + } + + public String getAddress() { + return Address; + } + + public void setAddress(String address) { + Address = address; + } + + public String getAddressName() { + return AddressName; + } + + public void setAddressName(String addressName) { + AddressName = addressName; + } + + public String getPostalCode() { + return PostalCode; + } + + public void setPostalCode(String postalCode) { + PostalCode = postalCode; + } + + public String getCity() { + return City; + } + + public void setCity(String city) { + City = city; + } + + public String getSalePersonPhone() { + return SalePersonPhone; + } + + public void setSalePersonPhone(String salePersonPhone) { + SalePersonPhone = salePersonPhone; + } + + public String getNote() { + return Note; + } + + public void setNote(String note) { + Note = note; + } + + public String getLatitude() { + return Latitude; + } + + public void setLatitude(String latitude) { + Latitude = latitude; + } + + public String getLongitude() { + return Longitude; + } + + public void setLongitude(String longitude) { + Longitude = longitude; + } + + public Boolean getSigned() { + return Signed; + } + + public void setSigned(Boolean signed) { + Signed = signed; + } + + public ArrayList getPhones() { + return Phones; + } + + public void setPhones(ArrayList phones) { + Phones = phones; + } + + +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/Cliente.java b/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/Cliente.java new file mode 100644 index 0000000..e9ef088 --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/Cliente.java @@ -0,0 +1,187 @@ +package verdnatura.es.repartoverdnatura.MODELS; + +import com.google.gson.annotations.SerializedName; + +import java.util.ArrayList; + +public class Cliente { + @SerializedName("Id") + private String Id; + @SerializedName("Client") + private String Client; + @SerializedName("ClientName") + private String ClientName; + @SerializedName("Address") + private String Address; + @SerializedName("Packages") + private String Packages; + @SerializedName("AddressName") + private String AddressName; + @SerializedName("PostalCode") + private String PostalCode; + @SerializedName("City") + private String City; + @SerializedName("Warehouse") + private String Warehouse; + @SerializedName("SalePersonPhone") + private String SalePersonPhone; + @SerializedName("Note") + private String Note; + @SerializedName("Phones") + private ArrayList Phones; + @SerializedName("Signed") + private String Signed; + @SerializedName("Latitude") + private String Latitude; + @SerializedName("Longitude") + private String Longitude; + @SerializedName("Polizon") + private String Polizon; + + public Cliente(String id, String client, String clientName, String address, String packages, String addressName, String postalCode, String city, String warehouse, String salePersonPhone, String note, ArrayList phones, String signed, String latitude, String longitude, String polizon) { + Id = id; + Client = client; + ClientName = clientName; + Address = address; + Packages = packages; + AddressName = addressName; + PostalCode = postalCode; + City = city; + Warehouse = warehouse; + SalePersonPhone = salePersonPhone; + Note = note; + Phones = phones; + Signed = signed; + Latitude = latitude; + Longitude = longitude; + Polizon = polizon; + } + + public String getId() { + return Id; + } + + public void setId(String id) { + Id = id; + } + + public String getClient() { + return Client; + } + + public void setClient(String client) { + Client = client; + } + + public String getClientName() { + return ClientName; + } + + public void setClientName(String clientName) { + ClientName = clientName; + } + + public String getAddress() { + return Address; + } + + public void setAddress(String address) { + Address = address; + } + + public String getPackages() { + return Packages; + } + + public void setPackages(String packages) { + Packages = packages; + } + + public String getAddressName() { + return AddressName; + } + + public void setAddressName(String addressName) { + AddressName = addressName; + } + + public String getPostalCode() { + return PostalCode; + } + + public void setPostalCode(String postalCode) { + PostalCode = postalCode; + } + + public String getCity() { + return City; + } + + public void setCity(String city) { + City = city; + } + + public String getWarehouse() { + return Warehouse; + } + + public void setWarehouse(String warehouse) { + Warehouse = warehouse; + } + + public String getSalePersonPhone() { + return SalePersonPhone; + } + + public void setSalePersonPhone(String salePersonPhone) { + SalePersonPhone = salePersonPhone; + } + + public String getNote() { + return Note; + } + + public void setNote(String note) { + Note = note; + } + + public ArrayList getPhones() { + return Phones; + } + + public void setPhones(ArrayList phones) { + Phones = phones; + } + + public String getSigned() { + return Signed; + } + + public void setSigned(String signed) { + Signed = signed; + } + + public String getLatitude() { + return Latitude; + } + + public void setLatitude(String latitude) { + Latitude = latitude; + } + + public String getLongitude() { + return Longitude; + } + + public void setLongitude(String longitude) { + Longitude = longitude; + } + + public String getPolizon() { + return Polizon; + } + + public void setPolizon(String polizon) { + Polizon = polizon; + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/Location.java b/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/Location.java new file mode 100644 index 0000000..1169bed --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/Location.java @@ -0,0 +1,12 @@ +package verdnatura.es.repartoverdnatura.MODELS; + + + +public class Location { + public String Longitude,Latitude; + + public Location(String longitude, String latitude) { + Longitude = longitude; + Latitude = latitude; + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/NoteSave.java b/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/NoteSave.java new file mode 100644 index 0000000..ef556cb --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/NoteSave.java @@ -0,0 +1,14 @@ +package verdnatura.es.repartoverdnatura.MODELS; + +import java.util.List; + +public class NoteSave { + private String note; + private List Tickets; + + + public NoteSave(String note, List tickets) { + this.note = note; + Tickets = tickets; + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/Ruta.java b/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/Ruta.java new file mode 100644 index 0000000..02540b8 --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/Ruta.java @@ -0,0 +1,156 @@ +package verdnatura.es.repartoverdnatura.MODELS; + +import com.google.gson.annotations.SerializedName; + +import java.io.Serializable; + +public class Ruta implements Serializable { + + @SerializedName("Id") + private String Id; + @SerializedName("Hour") + private String Hour; + @SerializedName("Date") + private String Date; + @SerializedName("M3") + private String M3; + @SerializedName("Plate") + private String Plate; + @SerializedName("Agency") + private String Agency; + @SerializedName("Driver") + private String Driver; + @SerializedName("kmStart") + private String kmStart; + @SerializedName("kmEnd") + private String kmEnd; + @SerializedName("dStart") + private String dStart; + @SerializedName("dEnd") + private String dEnd; + @SerializedName("Chofer") + private String Chofer; + + private Boolean isHeader = false; + + public Ruta(String id, String hour, String date, String m3, String plate, String agency, String driver, String kmStart, String kmEnd, String dStart, String dEnd, String chofer) { + Id = id; + Hour = hour; + Date = date; + M3 = m3; + Plate = plate; + Agency = agency; + Driver = driver; + this.kmStart = kmStart; + this.kmEnd = kmEnd; + this.dStart = dStart; + this.dEnd = dEnd; + Chofer = chofer; + } + + public Ruta(){} + + public Boolean getHeader() { + return isHeader; + } + + public void setHeader(Boolean header) { + isHeader = header; + } + + public String getId() { + return Id; + } + + public void setId(String id) { + Id = id; + } + + public String getHour() { + return Hour; + } + + public void setHour(String hour) { + Hour = hour; + } + + public String getDate() { + return Date; + } + + public void setDate(String date) { + Date = date; + } + + public String getM3() { + return M3; + } + + public void setM3(String m3) { + M3 = m3; + } + + public String getPlate() { + return Plate; + } + + public void setPlate(String plate) { + Plate = plate; + } + + public String getAgency() { + return Agency; + } + + public void setAgency(String agency) { + Agency = agency; + } + + public String getDriver() { + return Driver; + } + + public void setDriver(String driver) { + Driver = driver; + } + + public String getKmStart() { + return kmStart; + } + + public void setKmStart(String kmStart) { + this.kmStart = kmStart; + } + + public String getKmEnd() { + return kmEnd; + } + + public void setKmEnd(String kmEnd) { + this.kmEnd = kmEnd; + } + + public String getdStart() { + return dStart; + } + + public void setdStart(String dStart) { + this.dStart = dStart; + } + + public String getdEnd() { + return dEnd; + } + + public void setdEnd(String dEnd) { + this.dEnd = dEnd; + } + + public String getChofer() { + return Chofer; + } + + public void setChofer(String chofer) { + Chofer = chofer; + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/SignDataUpload.java b/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/SignDataUpload.java new file mode 100644 index 0000000..5becb7a --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/SignDataUpload.java @@ -0,0 +1,59 @@ +package verdnatura.es.repartoverdnatura.MODELS; + +import android.location.Location; + +import java.util.List; + +public class SignDataUpload { + private String Sign; + private List Tickets; + private verdnatura.es.repartoverdnatura.MODELS.Location Location; + private String clientName = ""; + private String idClient = ""; + + public SignDataUpload(String sign, List tickets, verdnatura.es.repartoverdnatura.MODELS.Location location) { + Sign = sign; + Tickets = tickets; + Location = location; + } + + public String getSign() { + return Sign; + } + + public void setSign(String sign) { + Sign = sign; + } + + public List getTickets() { + return Tickets; + } + + public void setTickets(List tickets) { + Tickets = tickets; + } + + public verdnatura.es.repartoverdnatura.MODELS.Location getLocation() { + return Location; + } + + public void setLocation(verdnatura.es.repartoverdnatura.MODELS.Location location) { + Location = location; + } + + public String getClientName() { + return clientName; + } + + public void setClientName(String clientName) { + this.clientName = clientName; + } + + public String getIdClient() { + return idClient; + } + + public void setIdClient(String idClient) { + this.idClient = idClient; + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/Ticket.java b/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/Ticket.java new file mode 100644 index 0000000..911b33a --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/Ticket.java @@ -0,0 +1,41 @@ +package verdnatura.es.repartoverdnatura.MODELS; + +public class Ticket { + private String idTicket,txtTitulo,txtDireccion; + + public Ticket() { + this.idTicket = ""; + this.txtTitulo = ""; + this.txtDireccion = ""; + } + + public Ticket(String idTicket, String txtTitulo, String txtDireccion) { + this.idTicket = idTicket; + this.txtTitulo = txtTitulo; + this.txtDireccion = txtDireccion; + } + + public String getIdTicket() { + return idTicket; + } + + public void setIdTicket(String idTicket) { + this.idTicket = idTicket; + } + + public String getTxtTitulo() { + return txtTitulo; + } + + public void setTxtTitulo(String txtTitulo) { + this.txtTitulo = txtTitulo; + } + + public String getTxtDireccion() { + return txtDireccion; + } + + public void setTxtDireccion(String txtDireccion) { + this.txtDireccion = txtDireccion; + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/User.java b/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/User.java new file mode 100644 index 0000000..bbd94e9 --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/User.java @@ -0,0 +1,26 @@ +package verdnatura.es.repartoverdnatura.MODELS; + +public class User { + private String name,idUser; + + public User(String name, String idUser) { + this.name = name; + this.idUser = idUser; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getIdUser() { + return idUser; + } + + public void setIdUser(String idUser) { + this.idUser = idUser; + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/Version.java b/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/Version.java new file mode 100644 index 0000000..66f09f1 --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/Version.java @@ -0,0 +1,43 @@ +package verdnatura.es.repartoverdnatura.MODELS; + +import com.google.gson.annotations.SerializedName; + +public class Version { + + @SerializedName("id") + private String id; + @SerializedName("appName") + private String appName; + @SerializedName("version") + private String version; + + public Version(String id, String appName, String version) { + this.id = id; + this.appName = appName; + this.version = version; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getAppName() { + return appName; + } + + public void setAppName(String appName) { + this.appName = appName; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/Worker.java b/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/Worker.java new file mode 100644 index 0000000..954060e --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/Worker.java @@ -0,0 +1,74 @@ +package verdnatura.es.repartoverdnatura.MODELS; + +import com.google.gson.annotations.SerializedName; + +public class Worker { + @SerializedName("id") + private String id; + @SerializedName("fullName") + private String fullName; + @SerializedName("workerCode") + private String workerCode; + @SerializedName("name") + private String name; + @SerializedName("routeLoader") + private String routeLoader; + + private Boolean isSelected = false; + + public Worker(String id, String fullName, String workerCode, String name, String routeLoader) { + this.id = id; + this.fullName = fullName; + this.workerCode = workerCode; + this.name = name; + this.routeLoader = routeLoader; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getFullName() { + return fullName; + } + + public void setFullName(String fullName) { + this.fullName = fullName; + } + + public String getWorkerCode() { + return workerCode; + } + + public void setWorkerCode(String workerCode) { + this.workerCode = workerCode; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Boolean getSelected() { + return isSelected; + } + + public void setSelected(Boolean selected) { + isSelected = selected; + } + + public String getRouteLoader() { + return routeLoader; + } + + public void setRouteLoader(String routeLoader) { + this.routeLoader = routeLoader; + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/WorkerSave.java b/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/WorkerSave.java new file mode 100644 index 0000000..3cdd421 --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/MODELS/WorkerSave.java @@ -0,0 +1,14 @@ +package verdnatura.es.repartoverdnatura.MODELS; + +import java.util.ArrayList; +import java.util.List; + +public class WorkerSave { + private String idRoute; + private List Workers; + + public WorkerSave(String idRoute, List workers) { + this.idRoute = idRoute; + Workers = workers; + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/MainActivity.java b/app/src/main/java/verdnatura/es/repartoverdnatura/MainActivity.java new file mode 100644 index 0000000..02f0c55 --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/MainActivity.java @@ -0,0 +1,428 @@ +package verdnatura.es.repartoverdnatura; + +import android.Manifest; +import android.app.Activity; +import android.app.AlertDialog; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.net.Uri; +import android.support.v4.app.ActivityCompat; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.ListView; +import android.widget.TextView; + +import com.google.gson.Gson; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Locale; +import java.util.Set; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import verdnatura.es.repartoverdnatura.ADAPTERS.PendingTickets; +import verdnatura.es.repartoverdnatura.ADAPTERS.RutaAdapter; +import verdnatura.es.repartoverdnatura.INTERFACES.RestClient; +import verdnatura.es.repartoverdnatura.MODELS.Ruta; +import verdnatura.es.repartoverdnatura.MODELS.SignDataUpload; +import verdnatura.es.repartoverdnatura.MODELS.Ticket; +import verdnatura.es.repartoverdnatura.MODELS.Version; +import verdnatura.es.repartoverdnatura.UTILS.ApiUtils; +import verdnatura.es.repartoverdnatura.UTILS.LocalStorage; +import verdnatura.es.repartoverdnatura.UTILS.Utils; + +public class MainActivity extends AppCompatActivity { + + private ListView listViewRutas, listViewPendingTickets; + private ArrayList listaRutas = new ArrayList<>(); + private ArrayList listaPendientes = new ArrayList<>(); + private RutaAdapter rutaAdapter; + private PendingTickets pendingAdapter; + private int heightCellRoute; + private int heightCellHeader; + private RestClient restClient; + private DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); + private Date date = new Date(); + private TextView txtDriver; + private final int MY_PERMISSIONS_REQUEST_FINE_LOCATION = 1; + private ImageView btnUpload; + + @Override + protected void onCreate(Bundle savedInstanceState) { + + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + restClient = ApiUtils.getAPIService(); + setViews(); + getRoutes(null); + getPending(); + registerReceiver(broadcastReceiver, new IntentFilter("UPDATEPENDING")); + + if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(this, + new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, + MY_PERMISSIONS_REQUEST_FINE_LOCATION); + } + + + } + + BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + getPending(); + } + }; + + @Override + protected void onRestart() { + getRoutes(null); + getPending(); + super.onRestart(); + } + + private void setViews(){ + listViewRutas = findViewById(R.id.listRutas); + listViewPendingTickets = findViewById(R.id.listPendingTickets); + heightCellRoute = Utils.convertDipToPixels(120f,this); + heightCellHeader = Utils.convertDipToPixels(45f,this); + txtDriver = findViewById(R.id.textView3); + btnUpload = findViewById(R.id.btnUpload); + } + + public void getRoutes(View v){ + + date = new Date(); + final MainActivity that = this; + listaRutas = new ArrayList<>(); + listViewRutas.setVisibility(View.VISIBLE); + Utils.progressBar.show(this,getResources().getString(R.string.please_wait)); + restClient.getRoutes(Utils.getMapWhitUser(this)).enqueue(new Callback>() { + @Override + public void onResponse(Call> call, Response> response) { + Utils.progressBar.getDialog().dismiss(); + if(response.isSuccessful()){ + for (Ruta ruta : response.body()){ + LocalStorage.saveRutas(that,response.body()); + txtDriver.setText(ruta.getDriver()); + try { + + if (date.compareTo(format.parse(ruta.getDate())) == 0){ + listaRutas.add(ruta); + }else{ + date = format.parse(ruta.getDate()); + Ruta rutaHeader = new Ruta(); + rutaHeader.setHeader(true); + rutaHeader.setDate(ruta.getDate()); + listaRutas.add(rutaHeader); + listaRutas.add(ruta); + } + } catch (ParseException e) { + e.printStackTrace(); + } + + } + that.rutaAdapter = new RutaAdapter(that,listaRutas); + that.listViewRutas.setAdapter(that.rutaAdapter); + ViewGroup.LayoutParams params = listViewRutas.getLayoutParams(); + params.height = (heightCellRoute * (listaRutas.size())); + listViewRutas.setLayoutParams(params); + checkVersion(); + }else{ + getLocalData(); + } + + } + + @Override + public void onFailure(Call> call, Throwable t) { + Utils.progressBar.getDialog().dismiss(); + getLocalData(); + } + }); + + } + + public void getLocalData(){ + List list = LocalStorage.getRutas(this); + if (list.size() > 0){ + for (Ruta ruta : list){ + txtDriver.setText(ruta.getDriver()); + try { + + if (date.compareTo(format.parse(ruta.getDate())) == 0){ + listaRutas.add(ruta); + }else{ + date = format.parse(ruta.getDate()); + Ruta rutaHeader = new Ruta(); + rutaHeader.setHeader(true); + rutaHeader.setDate(ruta.getDate()); + listaRutas.add(rutaHeader); + listaRutas.add(ruta); + } + } catch (ParseException e) { + e.printStackTrace(); + } + + } + this.rutaAdapter = new RutaAdapter(this,listaRutas); + this.listViewRutas.setAdapter(this.rutaAdapter); + ViewGroup.LayoutParams params = listViewRutas.getLayoutParams(); + params.height = (heightCellRoute * (listaRutas.size())); + listViewRutas.setLayoutParams(params); + }else{ + txtDriver.setText(this.getResources().getString(R.string.reparto)); + listViewRutas.setVisibility(View.GONE); + } + + } + + private void getPending(){ + listaPendientes = new ArrayList<>(); + Set listPendientes = LocalStorage.getPendingSigns(this); + Gson gson = new Gson(); + for(String s : listPendientes){ + listaPendientes.add(gson.fromJson(s,SignDataUpload.class)); + } + + ViewGroup.LayoutParams params = listViewPendingTickets.getLayoutParams(); + params.height = (heightCellRoute * (listaPendientes.size())); + listViewPendingTickets.setLayoutParams(params); + pendingAdapter = new PendingTickets(this,listaPendientes); + listViewPendingTickets.setAdapter(pendingAdapter); + if (listPendientes.size() > 0 ){ + btnUpload.setVisibility(View.VISIBLE); + }else{ + btnUpload.setVisibility(View.GONE); + } + } + + public void onRouteSelected(int pos){ + Intent i = new Intent(this,Tickets.class); + i.putExtra("route",listaRutas.get(pos)); + startActivity(i); + } + + public void logOut(View v){ + final MainActivity that = this; + + if (listaPendientes.size() > 0){ + new AlertDialog.Builder(this) + .setIcon(android.R.drawable.ic_dialog_alert) + .setTitle("ATENCIÓN") + .setMessage("Tienes tickets pendientes de actualizar,¿Estás seguro de cerrar sesión?") + .setPositiveButton("Si", new DialogInterface.OnClickListener() + { + @Override + public void onClick(DialogInterface dialog, int which) { + Utils.logOut(that); + finish(); + } + + }) + .setNegativeButton("No", null) + .show(); + }else{ + new AlertDialog.Builder(this) + .setIcon(android.R.drawable.ic_dialog_alert) + .setTitle("Cerrar sesión") + .setMessage("¿Estás seguro de cerrar sesión?") + .setPositiveButton("Si", new DialogInterface.OnClickListener() + { + @Override + public void onClick(DialogInterface dialog, int which) { + Utils.logOut(that); + finish(); + } + + }) + .setNegativeButton("No", null) + .show(); + } + + + + } + + public void goToInfo(View v){ + startActivity(new Intent(this,InfoActivity.class)); + } + + public void goToLoaders(int pos){ + Intent i = new Intent(this,LoadersActivity.class); + i.putExtra("idRoute",listaRutas.get(pos).getId()); + startActivity(i); + } + + public void savePending(int pos){ + SignDataUpload data = listaPendientes.get(pos); + confirmSave(data); + } + + public void confirmSave(final SignDataUpload data){ + Utils.progressBar.show(this,getResources().getString(R.string.please_wait)); + final MainActivity that = this; + Object[] args = new Object[1]; + args[0] = data; + restClient.saveSign(Utils.getMapWhitUser(this),args).enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + Utils.progressBar.getDialog().dismiss(); + if(response.isSuccessful()){ + + if (response.body().equals("OK")){ + ArrayList listAux = new ArrayList<>(); + + listaPendientes.remove(data); + LocalStorage.udpatePendingSigns(that,listaPendientes); + getPending(); + + + }else{ + Utils.showErrorDialog(that,that.getResources().getString(R.string.error_conexion)); + } + + }else{ + Log.i("ERROR","error al guardar"); + Utils.showErrorDialog(that,that.getResources().getString(R.string.error_conexion)); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + Utils.progressBar.getDialog().dismiss(); + Utils.showErrorDialog(that,that.getResources().getString(R.string.error_conexion)); + } + }); + } + + public void confirmSavePos(View v){ + if (listaPendientes.size() > 0) { + Utils.progressBar.show(this, getResources().getString(R.string.please_wait)); + final SignDataUpload data = listaPendientes.get(0); + final MainActivity that = this; + Object[] args = new Object[1]; + args[0] = data; + restClient.saveSign(Utils.getMapWhitUser(this), args).enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + + if (response.isSuccessful()) { + + if (response.body().equals("OK")) { + ArrayList listAux = new ArrayList<>(); + + listaPendientes.remove(data); + LocalStorage.udpatePendingSigns(that, listaPendientes); + confirmSavePos(null); + + + } else { + Utils.showErrorDialog(that, that.getResources().getString(R.string.error_conexion)); + } + + } else { + Log.i("ERROR", "error al guardar"); + Utils.showErrorDialog(that, that.getResources().getString(R.string.error_conexion)); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + Utils.progressBar.getDialog().dismiss(); + Utils.showErrorDialog(that, that.getResources().getString(R.string.error_conexion)); + } + }); + }else{ + Utils.progressBar.getDialog().dismiss(); + getPending(); + } + } + + public void checkVersion(){ + + + String[] userData = new String[1]; + userData[0] = "delivery"; + + final MainActivity that = this; + + restClient.getVersion(Utils.getMapWhitUser(this),userData).enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()){ + Version v = response.body(); + PackageManager manager = that.getPackageManager(); + try{ + PackageInfo info = manager.getPackageInfo(that.getPackageName(), 0); + int versionCode = info.versionCode; + if (versionCode != Integer.parseInt(v.getVersion())){ + AlertDialog.Builder builder1 = new AlertDialog.Builder(that); + builder1.setMessage("Existe una nueva versión. Se recomienda actualizar."); + builder1.setCancelable(true); + + builder1.setPositiveButton( + "Actualizar", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object + try { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName))); + } catch (android.content.ActivityNotFoundException anfe) { + //startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName))); + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://app.verdnatura.es/bin/vndelivery.apk"))); + } + + } + }); + + builder1.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + + } + }); + AlertDialog alert11 = builder1.create(); + alert11.show(); + } + }catch (Exception e){ + + } + + + } + } + + @Override + public void onFailure(Call call, Throwable t) { + + } + }); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + unregisterReceiver(broadcastReceiver); + } + + @Override + public void onBackPressed() { + + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/NetworkStateReveiver.java b/app/src/main/java/verdnatura/es/repartoverdnatura/NetworkStateReveiver.java new file mode 100644 index 0000000..0552eac --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/NetworkStateReveiver.java @@ -0,0 +1,103 @@ +package verdnatura.es.repartoverdnatura; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.util.Log; + +import com.google.gson.Gson; + +import java.util.ArrayList; +import java.util.Set; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import verdnatura.es.repartoverdnatura.INTERFACES.RestClient; +import verdnatura.es.repartoverdnatura.MODELS.SignDataUpload; +import verdnatura.es.repartoverdnatura.UTILS.ApiUtils; +import verdnatura.es.repartoverdnatura.UTILS.LocalStorage; +import verdnatura.es.repartoverdnatura.UTILS.Utils; + +public class NetworkStateReveiver extends BroadcastReceiver { + public ArrayList listData = new ArrayList<>(); + private RestClient restClient; + public Context context; + + public void onReceive(Context context, Intent intent) { + this.context = context; + Log.d("app", "Network connectivity change"); + if (intent.getExtras() != null) { + NetworkInfo ni = (NetworkInfo) intent.getExtras().get(ConnectivityManager.EXTRA_NETWORK_INFO); + if (ni != null && ni.getState() == NetworkInfo.State.CONNECTED) { + Log.i("app", "Network " + ni.getTypeName() + " connected"); + //TENEMOS INTERNET + Set listPendientes = LocalStorage.getPendingSigns(context); + if (listPendientes.size() != 0){ + restClient = ApiUtils.getAPIService(); + Gson gson = new Gson(); + listData = new ArrayList<>(); + for (String s : listPendientes){ + listData.add(gson.fromJson(s,SignDataUpload.class)); + } + + confirmSave(0); + } + confirmSave(0); + + } else if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, Boolean.FALSE)) { + Log.d("app", "There's no network connectivity"); + } + } + } + + public void confirmSave(final int pos){ + if (pos < listData.size()) { + //Utils.progressBar.show(this, getResources().getString(R.string.please_wait)); + Object[] args = new Object[1]; + args[0] = listData.get(pos); + restClient.saveSign(Utils.getMapWhitUser(context), args).enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + + if (response.isSuccessful()) { + + if (response.body().equals("OK")) { + confirmSave(pos+1); + }else{ + updateLocal(pos); + } + + } else { + Log.i("ERROR", "error al guardar"); + updateLocal(pos); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + updateLocal(pos); + } + }); + }else{ + updateLocal(pos); + } + } + + public void updateLocal(int pos){ + ArrayList listAux = new ArrayList<>(); + if(pos < listData.size() && pos != -1){ + + for(int i = pos; i < listData.size(); i++){ + listAux.add(listData.get(i)); + } + LocalStorage.udpatePendingSigns(context,listAux,"0"); + }else{ + LocalStorage.udpatePendingSigns(context,listAux,"0"); + } + + context.sendBroadcast(new Intent("UPDATEPENDING")); + } +} \ No newline at end of file diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/NoteActivity.java b/app/src/main/java/verdnatura/es/repartoverdnatura/NoteActivity.java new file mode 100644 index 0000000..379a4fc --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/NoteActivity.java @@ -0,0 +1,147 @@ +package verdnatura.es.repartoverdnatura; + +import android.app.Activity; +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.util.Log; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.ListAdapter; +import android.widget.ListView; +import android.widget.SimpleAdapter; +import android.widget.TextView; + +import java.util.ArrayList; +import java.util.Map; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import verdnatura.es.repartoverdnatura.INTERFACES.RestClient; +import verdnatura.es.repartoverdnatura.MODELS.ClientTickets; +import verdnatura.es.repartoverdnatura.MODELS.NoteSave; +import verdnatura.es.repartoverdnatura.MODELS.Worker; +import verdnatura.es.repartoverdnatura.MODELS.WorkerSave; +import verdnatura.es.repartoverdnatura.UTILS.ApiUtils; +import verdnatura.es.repartoverdnatura.UTILS.Utils; + +public class NoteActivity extends AppCompatActivity { + private RestClient restClient; + private EditText txtNota; + private TextView txtNumCharacters; + private final int MAX_CHARACTERS = 90; + public int total = 90; + private ClientTickets clientTicket; + private boolean isSignedShowed; + private ListView listViewMnesaje; + private ArrayList listMensajes = new ArrayList<>(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_note); + restClient = ApiUtils.getAPIService(); + Intent intent = this.getIntent(); + Bundle bundle = intent.getExtras(); + clientTicket = (ClientTickets) bundle.getSerializable("clientTicket"); + isSignedShowed = bundle.getBoolean("isSignedShowed"); + setViews(); + setEvents(); + setMensajes(); + } + + private void setViews(){ + txtNota = findViewById(R.id.editText2); + txtNumCharacters = findViewById(R.id.txtNumCharacters); + total = MAX_CHARACTERS - txtNota.getText().toString().length(); + txtNumCharacters.setText(""+total+" "+getResources().getString(R.string.caract_restantes)); + listViewMnesaje = findViewById(R.id.listMensajes); + } + + private void setMensajes(){ + listMensajes.add("CLIENTE AUSENTE"); + listMensajes.add("CLIENTE AUTORIZA DESCARGA A REPARTIDOR"); + listMensajes.add("CLIENTE RECHAZA PEDIDO"); + listMensajes.add("FALTAN BULTOS: "); + listMensajes.add("RECOGER DEVOLUCIÓN, NÚMERO DE RECLAMACIÓN: "); + + ArrayAdapter adapter = new ArrayAdapter<>(this,R.layout.row_mensaje,listMensajes); + listViewMnesaje.setAdapter(adapter); + + } + + private void setEvents(){ + txtNota.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + + } + + @Override + public void afterTextChanged(Editable editable) { + total = MAX_CHARACTERS - txtNota.getText().toString().length(); + txtNumCharacters.setText(""+total+" "+getResources().getString(R.string.caract_restantes)); + + + } + }); + + listViewMnesaje.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView adapterView, View view, int pos, long l) { + txtNota.setText(listMensajes.get(pos) + " "); + } + }); + } + + public void addNote(View v){ + Utils.progressBar.show(this,getResources().getString(R.string.please_wait)); + final NoteActivity that = this; + + ArrayList listTickets = new ArrayList<>(); + + for (Map ticket : clientTicket.getTickets()){ + listTickets.add(ticket.get("Id")); + } + + NoteSave na = new NoteSave("-"+txtNota.getText().toString(),listTickets); + Object[] args = new Object[1]; + args[0] = na; + restClient.addNote(Utils.getMapWhitUser(this),args).enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + Utils.progressBar.getDialog().dismiss(); + if (response.isSuccessful()){ + if(response.body().equals("Finish")){ + finish(); + }else{ + clientTicket.setNote(response.body()); + Intent returnIntent = new Intent(); + returnIntent.putExtra("clientTicket",clientTicket); + returnIntent.putExtra("isSignedShowed",isSignedShowed); + setResult(Activity.RESULT_OK,returnIntent); + finish(); + + } + }else{ + Utils.showErrorDialog(that,that.getResources().getString(R.string.error_conexion)); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + Utils.progressBar.getDialog().dismiss(); + Utils.showErrorDialog(that,that.getResources().getString(R.string.error_conexion)); + } + }); + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/SignActivity.java b/app/src/main/java/verdnatura/es/repartoverdnatura/SignActivity.java new file mode 100644 index 0000000..3e8888d --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/SignActivity.java @@ -0,0 +1,281 @@ +package verdnatura.es.repartoverdnatura; + +import android.Manifest; +import android.app.Activity; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.graphics.Bitmap; +import android.location.Criteria; +import android.location.Location; +import android.location.LocationListener; +import android.location.LocationManager; +import android.support.v4.app.ActivityCompat; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Base64; +import android.util.Log; +import android.view.View; +import android.widget.TextView; + +import com.simplify.ink.InkView; + +import java.io.ByteArrayOutputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import verdnatura.es.repartoverdnatura.INTERFACES.RestClient; +import verdnatura.es.repartoverdnatura.MODELS.ClientTickets; +import verdnatura.es.repartoverdnatura.MODELS.SignDataUpload; +import verdnatura.es.repartoverdnatura.UTILS.ApiUtils; +import verdnatura.es.repartoverdnatura.UTILS.LocalStorage; +import verdnatura.es.repartoverdnatura.UTILS.Utils; + +public class SignActivity extends AppCompatActivity implements LocationListener{ + + private InkView ink; + public ClientTickets clientTickets; + private TextView txtTickets, txtPackages, txtCliente; + private RestClient restClient; + public LocationManager locationManager; + public Location location; + public List tickets = new ArrayList<>(); + public String idRuta = ""; + private final int MY_PERMISSIONS_REQUEST_FINE_LOCATION = 1; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_sign); + restClient = ApiUtils.getAPIService(); + locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); + Criteria criteria = new Criteria(); + String provider = locationManager.getBestProvider(criteria, true); + if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(this, + new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, + MY_PERMISSIONS_REQUEST_FINE_LOCATION); + }else{ + location = locationManager.getLastKnownLocation(provider); + } + + locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0, 0,this); + locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0, 0,this); + + + Intent intent = this.getIntent(); + Bundle bundle = intent.getExtras(); + clientTickets = (ClientTickets) bundle.getSerializable("clientTicket"); + idRuta = bundle.getString("idRuta"); + setViews(); + setScreen(); + } + + + private void setViews(){ + ink = findViewById(R.id.ink); + ink.setColor(getResources().getColor(R.color.colorWhite)); + ink.setMinStrokeWidth(1.5f); + ink.setMaxStrokeWidth(6f); + + txtTickets = findViewById(R.id.textView5); + txtPackages = findViewById(R.id.textView8); + txtCliente = findViewById(R.id.txtCliente); + } + + private void setScreen(){ + StringBuffer auxText = new StringBuffer(); + int sumPackages = 0; + boolean isFirst = true; + for(Map ticket : clientTickets.getTickets()){ + if (isFirst){ + auxText.append(ticket.get("Id")); + isFirst = false; + }else{ + auxText.append(" , "+ticket.get("Id")); + } + + sumPackages += Integer.parseInt(ticket.get("Packages")); + tickets.add(Integer.parseInt(ticket.get("Id"))); + } + txtTickets.setText(auxText.toString()); + txtPackages.setText(""+sumPackages); + txtCliente.setText(clientTickets.getClientName()); + } + + + public void saveSign(View v){ + + final SignActivity that = this; + new AlertDialog.Builder(this) + .setIcon(android.R.drawable.ic_dialog_alert) + .setTitle(getResources().getString(R.string.firma)) + .setMessage(getResources().getString(R.string.estas_seguro_firma)) + .setPositiveButton(getResources().getString(R.string.si), new DialogInterface.OnClickListener() + { + @Override + public void onClick(DialogInterface dialog, int which) { + + final Bitmap drawing = ink.getBitmap(); + if(clientTickets.getLongitude()!=null && !clientTickets.getLongitude().equals("")){ + Location l2 = new Location(""); + l2.setLatitude(Double.parseDouble(clientTickets.getLatitude())); + l2.setLongitude(Double.parseDouble(clientTickets.getLongitude())); + if(location != null && distanceTwoPoints(location,l2)>30.0){ + AlertDialog alertDialog = new AlertDialog.Builder(that).create(); + alertDialog.setTitle("Alert"); + alertDialog.setMessage(that.getResources().getString(R.string.diferente_loc)); + alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, that.getResources().getString(R.string.mantener), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + + SignDataUpload data = new SignDataUpload(that.BitMapToString(drawing),tickets,new verdnatura.es.repartoverdnatura.MODELS.Location(clientTickets.getLongitude(),clientTickets.getLatitude())); + confirmSave(data); + + } + }); + alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, that.getResources().getString(R.string.actualizar), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + + SignDataUpload data = new SignDataUpload(that.BitMapToString(drawing),tickets,new verdnatura.es.repartoverdnatura.MODELS.Location(String.valueOf(location.getLongitude()),String.valueOf(location.getLatitude()))); + confirmSave(data); + + } + }); + alertDialog.show(); + }else{ + SignDataUpload data = new SignDataUpload(that.BitMapToString(drawing),tickets,new verdnatura.es.repartoverdnatura.MODELS.Location(String.valueOf(location.getLongitude()),String.valueOf(location.getLatitude()))); + confirmSave(data); + } + }else{ + + if (location != null){ + SignDataUpload data = new SignDataUpload(that.BitMapToString(drawing),tickets,new verdnatura.es.repartoverdnatura.MODELS.Location(String.valueOf(location.getLongitude()),String.valueOf(location.getLatitude()))); + confirmSave(data); + }else{ + SignDataUpload data = new SignDataUpload(that.BitMapToString(drawing),tickets,new verdnatura.es.repartoverdnatura.MODELS.Location("0.0","0.0")); + confirmSave(data); + } + + } + + } + + }) + .setNegativeButton(getResources().getString(R.string.no), null) + .show(); + + + } + + public void confirmSave(final SignDataUpload data){ + Utils.progressBar.show(this,getResources().getString(R.string.please_wait)); + final SignActivity that = this; + Object[] args = new Object[1]; + args[0] = data; + restClient.saveSign(Utils.getMapWhitUser(this),args).enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + Utils.progressBar.getDialog().dismiss(); + if(response.isSuccessful()){ + + if (response.body().equals("OK")){ + Log.i("INFO","guardado"); + Intent returnIntent = new Intent(); + returnIntent.putExtra("idCliente",clientTickets.getClient()); + setResult(Activity.RESULT_OK,returnIntent); + finish(); + }else{ + saveLocal(data); + } + + }else{ + Log.i("ERROR","error al guardar"); + saveLocal(data); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + Utils.progressBar.getDialog().dismiss(); + saveLocal(data); + } + }); + } + + public void saveLocal(SignDataUpload data){ + data.setIdClient(clientTickets.getClient()); + LocalStorage.saveSign(this,data,clientTickets.getClientName(),idRuta); + Intent returnIntent = new Intent(); + returnIntent.putExtra("idCliente",clientTickets.getClient()); + setResult(Activity.RESULT_OK,returnIntent); + finish(); + } + + public String BitMapToString(Bitmap bitmap){ + ByteArrayOutputStream baos=new ByteArrayOutputStream(); + bitmap.compress(Bitmap.CompressFormat.PNG,100, baos); + byte [] b=baos.toByteArray(); + String temp=Base64.encodeToString(b, Base64.DEFAULT); + return temp; + } + + public void clearSign(View v){ + ink.clear(); + } + + public float distanceTwoPoints(Location l1 , Location l2){ + + return l1.distanceTo(l2); + } + + @Override + public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { + switch (requestCode) { + case MY_PERMISSIONS_REQUEST_FINE_LOCATION: { + // If request is cancelled, the result arrays are empty. + if (grantResults.length > 0 + && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + + // permission was granted + } else { + // permission denied, boo! Disable the + // functionality that depends on this permission. + + } + } + + // other 'case' lines to check for other + // permissions this app might request + } + } + + @Override + public void onLocationChanged(Location location) { + Log.v("COORDENADAS", "IN ON LOCATION CHANGE, lat=" + location.getLatitude() + ", lon=" + location.getLongitude()); + this.location = location; + } + + @Override + public void onStatusChanged(String s, int i, Bundle bundle) { + + } + + @Override + public void onProviderEnabled(String s) { + + } + + @Override + public void onProviderDisabled(String s) { + + } + +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/Tickets.java b/app/src/main/java/verdnatura/es/repartoverdnatura/Tickets.java new file mode 100644 index 0000000..67d4371 --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/Tickets.java @@ -0,0 +1,625 @@ +package verdnatura.es.repartoverdnatura; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.net.Uri; +import android.os.Build; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v4.app.ActivityCompat; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.ListView; +import android.widget.TextView; +import android.widget.Toast; + +import com.google.gson.Gson; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import okhttp3.Route; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import verdnatura.es.repartoverdnatura.ADAPTERS.ClientAdapter; +import verdnatura.es.repartoverdnatura.ADAPTERS.PhonesAdapter; +import verdnatura.es.repartoverdnatura.INTERFACES.RestClient; +import verdnatura.es.repartoverdnatura.MODELS.ClientTickets; +import verdnatura.es.repartoverdnatura.MODELS.Cliente; +import verdnatura.es.repartoverdnatura.MODELS.Ruta; +import verdnatura.es.repartoverdnatura.MODELS.SignDataUpload; +import verdnatura.es.repartoverdnatura.UTILS.ApiUtils; +import verdnatura.es.repartoverdnatura.UTILS.LocalStorage; +import verdnatura.es.repartoverdnatura.UTILS.Utils; + +public class Tickets extends AppCompatActivity { + + public String tlf; + private ListView listViewClients; + private ArrayList listClientesTickets = new ArrayList<>(); + private ArrayList listClientesTicketsFirmados = new ArrayList<>(); + private ClientAdapter adapter; + public Ruta route; + private RestClient restClient; + private TextView txtZona, txtLines,btnVolver,txtClientsToSign,btnShowSigned; + private boolean isSignedShowed = false; + private ListView dialogListView; + public String uri = ""; + private int posForNote = 0; + public ArrayList listData = new ArrayList<>(); + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_tickets); + Intent intent = this.getIntent(); + Bundle bundle = intent.getExtras(); + route = (Ruta) bundle.getSerializable("route"); + restClient = ApiUtils.getAPIService(); + setViews(); + checkPendingSigns(); + } + + public void checkPendingSigns(){ + Set pendingSigns = LocalStorage.getPendingSigns(this); + if (pendingSigns.size() == 0){ + getData(-1); + }else{ + Gson gson = new Gson(); + listData = new ArrayList<>(); + for (String s : pendingSigns){ + listData.add(gson.fromJson(s,SignDataUpload.class)); + } + + confirmSave(0); + + } + } + + public void confirmSave(final int pos){ + if (pos < listData.size()) { + Utils.progressBar.show(this, getResources().getString(R.string.please_wait)); + final Tickets that = this; + Object[] args = new Object[1]; + args[0] = listData.get(pos); + restClient.saveSign(Utils.getMapWhitUser(this), args).enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + Utils.progressBar.getDialog().dismiss(); + if (response.isSuccessful()) { + + if (response.body().equals("OK")) { + confirmSave(pos+1); + }else{ + getData(pos); + } + + } else { + Log.i("ERROR", "error al guardar"); + Utils.showErrorDialog(that, that.getResources().getString(R.string.error_conexion)); + getData(pos); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + Utils.progressBar.getDialog().dismiss(); + getData(pos); + } + }); + }else{ + Utils.progressBar.getDialog().dismiss(); + getData(pos); + } + } + + private void setViews(){ + + listViewClients = this.findViewById(R.id.listClientes); + txtZona = this.findViewById(R.id.textView19); + txtLines = this.findViewById(R.id.textView35); + btnVolver = this.findViewById(R.id.textView3); + txtClientsToSign = this.findViewById(R.id.textView20); + btnShowSigned = this.findViewById(R.id.textView22); + + txtZona.setText(route.getAgency()); + + } + + private void getData(int pos){ + //han quedado firmas por subir + ArrayList listAux = new ArrayList<>(); + if(pos < listData.size() && pos != -1){ + + for(int i = pos; i < listData.size(); i++){ + listAux.add(listData.get(i)); + } + LocalStorage.udpatePendingSigns(this,listAux,route.getId()); + }else{ + LocalStorage.udpatePendingSigns(this,listAux,route.getId()); + } + + txtLines.setText(""); + final Tickets that = this; + listClientesTickets = new ArrayList<>(); + listClientesTicketsFirmados = new ArrayList<>(); + listViewClients.setVisibility(View.VISIBLE); + Utils.progressBar.show(this,getResources().getString(R.string.please_wait)); + String idR = route.getId(); + String[] routeData = new String[1]; + routeData[0] = idR; + restClient.getClients(Utils.getMapWhitUser(this),routeData).enqueue(new Callback>() { + @Override + public void onResponse(Call> call, Response> response) { + Utils.progressBar.getDialog().dismiss(); + Boolean exists = false; + if(response.isSuccessful()){ + for(Cliente cliente : response.body()){ + + exists = false; + + for (ClientTickets c : listClientesTicketsFirmados){ + if(c.getClient().equals(cliente.getClient())){ + Map values = new HashMap<>(); + values.put("Packages",cliente.getPackages()); + values.put("Warehouse",cliente.getWarehouse()); + values.put("Id",cliente.getId()); + values.put("Polizon",cliente.getPolizon()); + c.addTicket(values); + exists = true; + break; + } + } + + for (ClientTickets c : listClientesTickets){ + if(c.getClient().equals(cliente.getClient())){ + Map values = new HashMap<>(); + values.put("Packages",cliente.getPackages()); + values.put("Warehouse",cliente.getWarehouse()); + values.put("Id",cliente.getId()); + values.put("Polizon",cliente.getPolizon()); + c.addTicket(values); + exists = true; + break; + } + } + + + + if(!exists){ + Map values = new HashMap<>(); + values.put("Packages",cliente.getPackages()); + values.put("Warehouse",cliente.getWarehouse()); + values.put("Id",cliente.getId()); + values.put("Polizon",cliente.getPolizon()); + ArrayList> arrayValues = new ArrayList<>(); + arrayValues.add(values); + if(cliente.getSigned().equals("0")){ + listClientesTickets.add(new ClientTickets(cliente.getClient(), + cliente.getClientName(), + cliente.getAddress(), + cliente.getAddressName(), + cliente.getPostalCode(), + cliente.getCity(), + cliente.getSalePersonPhone(), + cliente.getNote(), + cliente.getLatitude(), + cliente.getLongitude(), + Boolean.parseBoolean(cliente.getSigned()), + cliente.getPhones(), + arrayValues, + cliente.getPolizon())); + }else{ + listClientesTicketsFirmados.add(new ClientTickets(cliente.getClient(), + cliente.getClientName(), + cliente.getAddress(), + cliente.getAddressName(), + cliente.getPostalCode(), + cliente.getCity(), + cliente.getSalePersonPhone(), + cliente.getNote(), + cliente.getLatitude(), + cliente.getLongitude(), + Boolean.parseBoolean(cliente.getSigned()), + cliente.getPhones(), + arrayValues, + cliente.getPolizon())); + } + + } + } + + //ACTUALIZAR RESPECTO LOCAL + Set localSigns = LocalStorage.getPendingSigns(that); + Gson gson = new Gson(); + ArrayList listAux = new ArrayList<>(); + for (String s : localSigns){ + SignDataUpload sdu = gson.fromJson(s,SignDataUpload.class); + int count = 0; + for(ClientTickets c : listClientesTickets){ + if (sdu.getIdClient().equals(c.getClient())){ + listAux.add(listClientesTickets.get(count)); + break; + } + count += 1; + } + } + + for (ClientTickets c : listAux) { + listClientesTickets.remove(c); + } + + + + if (isSignedShowed){ + adapter = new ClientAdapter(that,listClientesTicketsFirmados); + }else{ + adapter = new ClientAdapter(that,listClientesTickets); + } + listViewClients.setAdapter(adapter); + txtLines.setText(""+listClientesTicketsFirmados.size()+"/"+(listClientesTicketsFirmados.size()+listClientesTickets.size())+" "+that.getResources().getString(R.string.clientes_firmados)); + + //GUARDAR EN LOCAL + LocalStorage.saveListClientesTickets(that,listClientesTickets,route.getId()); + LocalStorage.saveListClientesTicketsFirmados(that,listClientesTicketsFirmados,route.getId()); + + + }else{ + getLocalData(); + } + } + + @Override + public void onFailure(Call> call, Throwable t) { + Utils.progressBar.getDialog().dismiss(); + /* Utils.showErrorDialog(that,that.getResources().getString(R.string.error_conexion)); + listViewClients.setVisibility(View.GONE);*/ + getLocalData(); + } + }); + + + + } + + public void getLocalData(){ + listClientesTicketsFirmados = LocalStorage.getClientesTicketsFirmados(this,route.getId()); + listClientesTickets = LocalStorage.getClientesTickets(this,route.getId()); + + if (listClientesTicketsFirmados.size()== 0 && listClientesTickets.size() == 0){ + Utils.showErrorDialogAndFinish(this,this.getResources().getString(R.string.error_conexion)); + listViewClients.setVisibility(View.GONE); + + } + if (isSignedShowed){ + adapter = new ClientAdapter(this,listClientesTicketsFirmados); + }else{ + adapter = new ClientAdapter(this,listClientesTickets); + } + listViewClients.setAdapter(adapter); + txtLines.setText(""+listClientesTicketsFirmados.size()+"/"+(listClientesTicketsFirmados.size()+listClientesTickets.size())+" "+this.getResources().getString(R.string.clientes_firmados)); + + } + + public void showPhones(int pos){ + ArrayList phones = new ArrayList<>(); + if (isSignedShowed){ + for (String phone : listClientesTicketsFirmados.get(pos).getPhones()){ + if (phone!=""){ + phones.add(phone); + } + } + phones.add(listClientesTicketsFirmados.get(pos).getSalePersonPhone()); + }else{ + for (String phone : listClientesTickets.get(pos).getPhones()){ + if (phone!=""){ + phones.add(phone); + } + } + phones.add(listClientesTickets.get(pos).getSalePersonPhone()); + } + + AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); + LayoutInflater inflater = getLayoutInflater(); + View convertView = inflater.inflate(R.layout.phone_dialog, null); + alertDialog.setView(convertView); + alertDialog.setTitle(getResources().getString(R.string.telefono)); + ListView lv = convertView.findViewById(R.id.dialoglist); + PhonesAdapter adapter = new PhonesAdapter(this,phones){}; + lv.setAdapter(adapter); + alertDialog.show(); + } + + public void llamarTelefono(String phone){ + + tlf = phone; + if (Build.VERSION.SDK_INT >= 23) { + String[] PERMISSIONS = {android.Manifest.permission.CALL_PHONE}; + if (!hasPermissions(this, PERMISSIONS)) { + ActivityCompat.requestPermissions((Activity) this, PERMISSIONS, 112 ); + } else { + makeCall(); + } + } else { + makeCall(); + } + + + } + + private static boolean hasPermissions(Context context, String... permissions) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null && permissions != null) { + for (String permission : permissions) { + if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) { + return false; + } + } + } + return true; + } + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + switch (requestCode) { + case 112: { + if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + makeCall(); + } else { + Toast.makeText(this, "No tienes permisos para llamar.", Toast.LENGTH_LONG).show(); + } + } + } + } + + public void makeCall(){ + String uri = "tel:" + tlf.trim() ; + Intent intent = new Intent(Intent.ACTION_CALL); + intent.setData(Uri.parse(uri)); + startActivity(intent); + } + + public void goMaps(int pos){ + final Tickets that = this; + final int posicion = pos; + if(isGoogleMapsInstalled()){ + + if (isSignedShowed){ + if (listClientesTicketsFirmados.get(pos).getLatitude() == null || listClientesTicketsFirmados.get(pos).getLatitude().equals("0.0")){ + uri = "geo:0,0?q="+listClientesTicketsFirmados.get(pos).getClientName() + + " " + listClientesTicketsFirmados.get(pos).getAddressName() + + " " + listClientesTicketsFirmados.get(pos).getCity()+ + " " + listClientesTicketsFirmados.get(pos).getPostalCode(); + startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(uri))); + }else{ + AlertDialog.Builder builder1 = new AlertDialog.Builder(this); + builder1.setMessage(that.getResources().getString(R.string.ver_loc)); + builder1.setCancelable(true); + + builder1.setPositiveButton( + that.getResources().getString(R.string.nombre), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + uri = "geo:0,0?q="+listClientesTicketsFirmados.get(posicion).getClientName() + + " " + listClientesTicketsFirmados.get(posicion).getAddressName() + + " " + listClientesTicketsFirmados.get(posicion).getCity()+ + " " + listClientesTicketsFirmados.get(posicion).getPostalCode(); + startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(uri))); + } + }); + + builder1.setNegativeButton( + that.getResources().getString(R.string.coordenadas), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + + uri = "geo:0,0?q="+listClientesTicketsFirmados.get(posicion).getLatitude() + + " " + listClientesTicketsFirmados.get(posicion).getLongitude(); + startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(uri))); + + } + }); + + AlertDialog alert11 = builder1.create(); + alert11.show(); + + } + + }else{ + if (listClientesTickets.get(pos).getLatitude() == null || listClientesTickets.get(pos).getLatitude().equals("0.0")){ + uri = "geo:0,0?q="+listClientesTickets.get(pos).getClientName() + + " " + listClientesTickets.get(pos).getAddressName() + + " " + listClientesTickets.get(pos).getCity()+ + " " + listClientesTickets.get(pos).getPostalCode(); + startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(uri))); + }else { + AlertDialog.Builder builder1 = new AlertDialog.Builder(this); + builder1.setMessage(that.getResources().getString(R.string.ver_loc)); + builder1.setCancelable(true); + + builder1.setPositiveButton( + that.getResources().getString(R.string.nombre), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + uri = "geo:0,0?q="+listClientesTickets.get(posicion).getClientName() + + " " + listClientesTickets.get(posicion).getAddressName() + + " " + listClientesTickets.get(posicion).getCity()+ + " " + listClientesTickets.get(posicion).getPostalCode(); + startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(uri))); + } + }); + + builder1.setNegativeButton( + that.getResources().getString(R.string.coordenadas), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + + uri = "geo:0,0?q="+listClientesTickets.get(posicion).getLatitude() + + " " + listClientesTickets.get(posicion).getLongitude(); + startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(uri))); + + } + }); + + AlertDialog alert11 = builder1.create(); + alert11.show(); + } + } + + + + }else{ + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setMessage("Please install Google Maps"); + builder.setCancelable(false); + builder.setPositiveButton("Install", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.apps.maps")); + startActivity(intent); + finish(); + } + }); + AlertDialog dialog = builder.create(); + dialog.show(); + } + + } + + public void goSign(int pos){ + Intent i = new Intent(this,SignActivity.class); + if (isSignedShowed){ + i.putExtra("clientTicket",listClientesTicketsFirmados.get(pos)); + + }else{ + i.putExtra("clientTicket",listClientesTickets.get(pos)); + } + + i.putExtra("idRuta",route.getId()); + startActivityForResult(i,1); + + + } + + public boolean isGoogleMapsInstalled() { + try + { + ApplicationInfo info = getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0 ); + return true; + } + catch(PackageManager.NameNotFoundException e) + { + return false; + } + } + + public void showSigned(View v){ + if(isSignedShowed){ + adapter = new ClientAdapter(this,listClientesTickets); + isSignedShowed = false; + txtClientsToSign.setText(getResources().getString(R.string.tickets_por_firmar)); + btnShowSigned.setText(getResources().getString(R.string.ver_firmados)); + }else{ + adapter = new ClientAdapter(this,listClientesTicketsFirmados); + isSignedShowed = true; + txtClientsToSign.setText(getResources().getString(R.string.clientes_firmados)); + btnShowSigned.setText(getResources().getString(R.string.ver_por_firmar)); + } + listViewClients.setAdapter(adapter); + } + + public void showNote(int pos){ + String mensaje = ""; + if(isSignedShowed){ + mensaje = listClientesTicketsFirmados.get(pos).getNote(); + }else{ + mensaje = listClientesTickets.get(pos).getNote(); + } + AlertDialog alertDialog = new AlertDialog.Builder(this).create(); + alertDialog.setTitle("Alert"); + alertDialog.setMessage(mensaje); + alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }); + alertDialog.show(); + } + + public void showPolizon(int pos,int posTicket){ + String polizon = ""; + if (isSignedShowed){ + polizon = listClientesTicketsFirmados.get(pos).getTickets().get(posTicket).get("Polizon"); + }else{ + polizon = listClientesTickets.get(pos).getTickets().get(posTicket).get("Polizon"); + } + AlertDialog alertDialog = new AlertDialog.Builder(this).create(); + alertDialog.setTitle(this.getResources().getString(R.string.polizon)); + alertDialog.setMessage(polizon); + alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }); + alertDialog.show(); + } + + public void goToConfig(View v){ + Intent i = new Intent(this,ConfigureActivity.class); + i.putExtra("route",route); + startActivityForResult(i,2); + } + + public void goToNotes(int position){ + posForNote = position; + Intent i = new Intent(this,NoteActivity.class); + if (isSignedShowed){ + i.putExtra("clientTicket",listClientesTicketsFirmados.get(position)); + }else{ + i.putExtra("clientTicket",listClientesTickets.get(position)); + } + + i.putExtra("isSignedShowed",isSignedShowed); + + startActivityForResult(i,3); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + + if (requestCode == 1){ + if (resultCode == Activity.RESULT_OK){ + checkPendingSigns(); + } + }else if (requestCode == 2){ + if (resultCode == Activity.RESULT_OK) { + route = (Ruta) data.getSerializableExtra("route"); + } + }else if (requestCode == 3){ + if (resultCode == Activity.RESULT_OK) { + ClientTickets ct = (ClientTickets) data.getSerializableExtra("clientTicket"); + if (data.getBooleanExtra("isSignedShowed",false)){ + listClientesTicketsFirmados.get(posForNote).setNote(ct.getNote()); + }else{ + listClientesTickets.get(posForNote).setNote(ct.getNote()); + } + + adapter.notifyDataSetChanged(); + } + } + + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/UTILS/ApiUtils.java b/app/src/main/java/verdnatura/es/repartoverdnatura/UTILS/ApiUtils.java new file mode 100644 index 0000000..13e4abb --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/UTILS/ApiUtils.java @@ -0,0 +1,14 @@ +package verdnatura.es.repartoverdnatura.UTILS; + +import verdnatura.es.repartoverdnatura.INTERFACES.RestClient; + +public class ApiUtils { + private ApiUtils() {} + + //public static final String BASE_URL = "http://172.16.198.34:8080/"; + public static final String BASE_URL = "https://app.verdnatura.es/"; + + public static RestClient getAPIService() { + return RetrofitClient.getClient(BASE_URL).create(RestClient.class); + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/UTILS/CustomProgressBar.java b/app/src/main/java/verdnatura/es/repartoverdnatura/UTILS/CustomProgressBar.java new file mode 100644 index 0000000..fc006cd --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/UTILS/CustomProgressBar.java @@ -0,0 +1,50 @@ +package verdnatura.es.repartoverdnatura.UTILS; + +import android.app.Dialog; +import android.app.SearchManager; +import android.content.Context; +import android.content.DialogInterface; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.TextView; + +import verdnatura.es.repartoverdnatura.R; + +public class CustomProgressBar { + private Dialog dialog; + + public Dialog show(Context context) { + return show(context, null); + } + + public Dialog show(Context context, CharSequence title) { + return show(context, title, false); + } + + public Dialog show(Context context, CharSequence title, boolean cancelable) { + return show(context, title, cancelable, null); + } + + public Dialog show(Context context, CharSequence title, boolean cancelable, + SearchManager.OnCancelListener cancelListener) { + LayoutInflater inflator = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + final View view = inflator.inflate(R.layout.progress_bar, null); + if(title != null) { + final TextView tv = (TextView) view.findViewById(R.id.id_title); + tv.setText(title); + } + + dialog = new Dialog(context, R.style.NewDialog); + dialog.setContentView(view); + dialog.setCancelable(cancelable); + dialog.setOnCancelListener((DialogInterface.OnCancelListener) cancelListener); + dialog.show(); + + return dialog; + } + + public Dialog getDialog() { + return dialog; + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/UTILS/LocalStorage.java b/app/src/main/java/verdnatura/es/repartoverdnatura/UTILS/LocalStorage.java new file mode 100644 index 0000000..7992005 --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/UTILS/LocalStorage.java @@ -0,0 +1,309 @@ +package verdnatura.es.repartoverdnatura.UTILS; + +import android.app.Activity; +import android.content.Context; +import android.content.SharedPreferences; +import com.google.gson.Gson; +import com.google.gson.internal.LinkedTreeMap; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import verdnatura.es.repartoverdnatura.MODELS.ClientTickets; +import verdnatura.es.repartoverdnatura.MODELS.Ruta; +import verdnatura.es.repartoverdnatura.MODELS.SignDataUpload; + +public class LocalStorage { + static SharedPreferences sp; + + public static void saveRutas(Context context, List rutas){ + clearClients(context,rutas); + sp = context.getSharedPreferences("delivery",Activity.MODE_PRIVATE); + SharedPreferences.Editor editor = sp.edit(); + + Gson gson = new Gson(); + String json = gson.toJson(rutas); + + editor.putString("rutas",json); + editor.commit(); + } + public static void saveListClientesTickets(Context context, List listClientesTickets,String idRuta){ + sp = context.getSharedPreferences("delivery",Activity.MODE_PRIVATE); + SharedPreferences.Editor editor = sp.edit(); + + Gson gson = new Gson(); + String json = gson.toJson(listClientesTickets); + + editor.putString("clientTickets_"+idRuta,json); + editor.commit(); + } + public static void saveListClientesTicketsFirmados(Context context, List listClientesTicketsFirmados,String idRuta){ + sp = context.getSharedPreferences("delivery",Activity.MODE_PRIVATE); + SharedPreferences.Editor editor = sp.edit(); + + Gson gson = new Gson(); + String json = gson.toJson(listClientesTicketsFirmados); + + editor.putString("clientTicketsFirmados_"+idRuta,json); + editor.commit(); + } + public static ArrayList getRutas(Context context){ + Gson gson = new Gson(); + sp = context.getSharedPreferences("delivery",Activity.MODE_PRIVATE); + String json = sp.getString("rutas",""); + if (json.length() > 0 ){ + ArrayList listRutas = new ArrayList<>(); + List list = gson.fromJson(json,List.class); + for (int i = 0; i(); + } + } + public static ArrayList getClientesTickets(Context context,String idRuta){ + Gson gson = new Gson(); + sp = context.getSharedPreferences("delivery",Activity.MODE_PRIVATE); + String json = sp.getString("clientTickets_"+idRuta,""); + if (json.length() > 0 ){ + ArrayList listRutas = new ArrayList<>(); + List list = gson.fromJson(json,List.class); + String nota = ""; + String polizon = ""; + for (int i = 0; i) list.get(i).get("Phones"), + (ArrayList>) list.get(i).get("tickets"), + ((list.get(i) == null) || (list.get(i).get("Polizon") == null) ? "" : list.get(i).get("Polizon")).toString())); + } + + + return listRutas; + }else{ + return new ArrayList<>(); + } + } + public static ArrayList getClientesTicketsFirmados(Context context,String idRuta){ + Gson gson = new Gson(); + sp = context.getSharedPreferences("delivery",Activity.MODE_PRIVATE); + String json = sp.getString("clientTicketsFirmados_"+idRuta,""); + if (json.length() > 0 ){ + ArrayList listRutas = new ArrayList<>(); + List list = gson.fromJson(json,List.class); + String nota = ""; + String polizon = ""; + for (int i = 0; i) list.get(i).get("Phones"), + (ArrayList>) list.get(i).get("tickets"), + ((list.get(i) == null) || (list.get(i).get("Polizon") == null) ? "" : list.get(i).get("Polizon")).toString())); + } + + + return listRutas; + }else{ + return new ArrayList<>(); + } + } + public static boolean isOfflineAviable(Context context,String idRuta){ + sp = context.getSharedPreferences("delivery",Activity.MODE_PRIVATE); + String clientTickets = sp.getString("clientTickets_"+idRuta,""); + String clientTicketsFirmados = sp.getString("clientTicketsFirmados_"+idRuta,""); + + if (clientTickets.equals("") && clientTicketsFirmados.equals("")){ + return false; + }else{ + return true; + } + } + private static void clearClients(Context context,List rutas){ + sp = context.getSharedPreferences("delivery",Activity.MODE_PRIVATE); + + //1 Obtenemos todos los clientes que si queremos + ArrayList> listClientesFirmados = new ArrayList<>(); + ArrayList> listClientes = new ArrayList<>(); + String aux = ""; + Map mapClientes = new HashMap<>(); + for(Ruta r : rutas){ + mapClientes = new HashMap<>(); + aux = sp.getString("clientTicketsFirmados_"+r.getId(),""); + if(!aux.equals("")){ + mapClientes.put("localid","clientTicketsFirmados_"+r.getId()); + mapClientes.put("json",aux); + listClientesFirmados.add(mapClientes); + } + mapClientes = new HashMap<>(); + aux = sp.getString("clientTickets_"+r.getId(),""); + if(!aux.equals("")){ + mapClientes.put("localid","clientTickets_"+r.getId()); + mapClientes.put("json",aux); + listClientes.add(mapClientes); + } + } + //2 Obtenemos la info del usuario + Map userInfo = Utils.getMapWhitUser(context); + + //3 Obtenemos los clientes pendientes de firmar + Set pendingSigns = getPendingSigns(context); + + //4 Limpiamos todos los datos locales + SharedPreferences.Editor editor = sp.edit(); + editor.clear(); + editor.commit(); + + //5 Guardamos los datos que queremos + Utils.saveIdUser(context,userInfo.get("user")); + Utils.saveUserPass(context,userInfo.get("user"),userInfo.get("pass")); + + for (Map map : listClientes){ + editor.putString(map.get("localid"),map.get("json")); + } + + for (Map map : listClientesFirmados){ + editor.putString(map.get("localid"),map.get("json")); + } + + saveSignSet(context,pendingSigns); + + editor.commit(); + + + } + public static void saveSign(Context context,SignDataUpload data, String clientName,String idRuta){ + sp = context.getSharedPreferences("delivery",Activity.MODE_PRIVATE); + SharedPreferences.Editor editor = sp.edit(); + + data.setClientName(clientName); + Gson gson = new Gson(); + String dataJson = gson.toJson(data); + + Set listSigns = sp.getStringSet("listSigns",new HashSet()); + listSigns.add(dataJson); + editor.putStringSet("listSigns",listSigns); + + editor.commit(); + + updateListClients(context,idRuta,clientName); + } + public static void saveSignSet(Context context,Set data){ + sp = context.getSharedPreferences("delivery",Activity.MODE_PRIVATE); + SharedPreferences.Editor editor = sp.edit(); + editor.putStringSet("listSigns",data); + editor.commit(); + } + private static void updateListClients(Context context, String idRuta, String clientName){ + ArrayList clientesTickets = getClientesTickets(context,idRuta); + ArrayList clientesTicketsFirmados = getClientesTicketsFirmados(context,idRuta); + int cont = 0; + ClientTickets aux = null; + for (ClientTickets c : clientesTickets){ + if (c.getClientName().equals(clientName)){ + clientesTickets.get(cont).setSigned(true); + clientesTicketsFirmados.add(clientesTickets.get(cont)); + aux = c; + break; + } + cont += 1; + } + cont = 0; + + clientesTickets.remove(aux); + saveListClientesTickets(context,clientesTickets,idRuta); + saveListClientesTicketsFirmados(context,clientesTicketsFirmados,idRuta); + } + public static Set getPendingSigns(Context context){ + sp = context.getSharedPreferences("delivery",Activity.MODE_PRIVATE); + return sp.getStringSet("listSigns",new HashSet()); + } + public static void udpatePendingSigns(Context context,ArrayList list,String idRuta){ + for(SignDataUpload s : list){ + saveSign(context,s,s.getClientName(),idRuta); + } + if (list.size() == 0) { + clearPendingSigns(context); + } + } + public static void udpatePendingSigns(Context context,ArrayList list){ + sp = context.getSharedPreferences("delivery",Activity.MODE_PRIVATE); + SharedPreferences.Editor editor = sp.edit(); + Set listString = new HashSet<>(); + Gson gson = new Gson(); + for(SignDataUpload s : list){ + listString.add(gson.toJson(s)); + } + + editor.putStringSet("listSigns",listString); + editor.commit(); + } + private static void clearPendingSigns(Context context){ + sp = context.getSharedPreferences("delivery",Activity.MODE_PRIVATE); + SharedPreferences.Editor editor = sp.edit(); + editor.remove("listSigns"); + editor.commit(); + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/UTILS/RetrofitClient.java b/app/src/main/java/verdnatura/es/repartoverdnatura/UTILS/RetrofitClient.java new file mode 100644 index 0000000..d7a6c41 --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/UTILS/RetrofitClient.java @@ -0,0 +1,19 @@ +package verdnatura.es.repartoverdnatura.UTILS; + +import retrofit2.Retrofit; +import retrofit2.converter.gson.GsonConverterFactory; +import retrofit2.converter.scalars.ScalarsConverterFactory; + +public class RetrofitClient { + private static Retrofit retrofit = null; + + public static Retrofit getClient(String baseUrl){ + if (retrofit==null) { + retrofit = new Retrofit.Builder() + .baseUrl(baseUrl) + .addConverterFactory(GsonConverterFactory.create()) + .build(); + } + return retrofit; + } +} diff --git a/app/src/main/java/verdnatura/es/repartoverdnatura/UTILS/Utils.java b/app/src/main/java/verdnatura/es/repartoverdnatura/UTILS/Utils.java new file mode 100644 index 0000000..618a0d5 --- /dev/null +++ b/app/src/main/java/verdnatura/es/repartoverdnatura/UTILS/Utils.java @@ -0,0 +1,108 @@ +package verdnatura.es.repartoverdnatura.UTILS; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.SharedPreferences; + +import java.util.HashMap; +import java.util.Map; + +public class Utils { + + static SharedPreferences sp; + + static Map map = new HashMap<>(); + + public static CustomProgressBar progressBar = new CustomProgressBar(); + + public static int convertDipToPixels(float dips, Context context) { + return (int) (dips * context.getResources().getDisplayMetrics().density + 0.5f); + } + + public static Map getMap(String user,String password){ + map.put("version", "1"); + map.put("aplicacion", "json"); + map.put("user", user); + map.put("pass", password); + map.put("Content-Type", "application/x-www-form-urlencoded"); + return map; + } + + public static Map getMapWhitUser(Context context){ + sp = context.getSharedPreferences("delivery",Activity.MODE_PRIVATE); + String user = sp.getString("user",""); + String password = sp.getString("pass",""); + map.put("version", "1"); + map.put("aplicacion", "json"); + map.put("user", user); + map.put("pass", password); + map.put("Content-Type", "application/x-www-form-urlencoded"); + return map; + } + + public static void showErrorDialog(Context context,String mensaje){ + AlertDialog.Builder builder1 = new AlertDialog.Builder(context); + builder1.setMessage(mensaje); + builder1.setCancelable(true); + + builder1.setPositiveButton( + "Ok", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + } + }); + + + AlertDialog alert11 = builder1.create(); + alert11.show(); + } + public static void showErrorDialogAndFinish(final Context context, String mensaje){ + AlertDialog.Builder builder1 = new AlertDialog.Builder(context); + builder1.setMessage(mensaje); + builder1.setCancelable(true); + + builder1.setPositiveButton( + "Ok", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + ((Activity) context).finish(); + dialog.cancel(); + } + }); + + + AlertDialog alert11 = builder1.create(); + alert11.show(); + } + + public static void saveIdUser(Context context,String idUser){ + sp = context.getSharedPreferences("delivery",Activity.MODE_PRIVATE); + SharedPreferences.Editor editor = sp.edit(); + editor.putString("idUser",idUser); + editor.commit(); + } + + public static void saveUserPass(Context context,String user,String pass){ + sp = context.getSharedPreferences("delivery",Activity.MODE_PRIVATE); + SharedPreferences.Editor editor = sp.edit(); + editor.putString("user",user); + editor.putString("pass",pass); + editor.commit(); + } + + public static String getIdUser(Context context){ + sp = context.getSharedPreferences("delivery",Activity.MODE_PRIVATE); + return sp.getString("idUser","nouser"); + } + + public static void logOut(Context context){ + sp = context.getSharedPreferences("delivery",Activity.MODE_PRIVATE); + SharedPreferences.Editor editor = sp.edit(); + editor.clear(); + editor.commit(); + } + +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/back.png b/app/src/main/res/drawable/back.png new file mode 100644 index 0000000..e226a72 Binary files /dev/null and b/app/src/main/res/drawable/back.png differ diff --git a/app/src/main/res/drawable/button_background.xml b/app/src/main/res/drawable/button_background.xml new file mode 100644 index 0000000..456b165 --- /dev/null +++ b/app/src/main/res/drawable/button_background.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/exit.png b/app/src/main/res/drawable/exit.png new file mode 100644 index 0000000..a1c1876 Binary files /dev/null and b/app/src/main/res/drawable/exit.png differ diff --git a/app/src/main/res/drawable/ficha.png b/app/src/main/res/drawable/ficha.png new file mode 100644 index 0000000..5fa97ac Binary files /dev/null and b/app/src/main/res/drawable/ficha.png differ diff --git a/app/src/main/res/drawable/firmar.png b/app/src/main/res/drawable/firmar.png new file mode 100644 index 0000000..d488f6b Binary files /dev/null and b/app/src/main/res/drawable/firmar.png differ diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/icon.png b/app/src/main/res/drawable/icon.png new file mode 100644 index 0000000..8a7b8ca Binary files /dev/null and b/app/src/main/res/drawable/icon.png differ diff --git a/app/src/main/res/drawable/input_background.xml b/app/src/main/res/drawable/input_background.xml new file mode 100644 index 0000000..574d456 --- /dev/null +++ b/app/src/main/res/drawable/input_background.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/logo.png b/app/src/main/res/drawable/logo.png new file mode 100644 index 0000000..ced977f Binary files /dev/null and b/app/src/main/res/drawable/logo.png differ diff --git a/app/src/main/res/drawable/note.png b/app/src/main/res/drawable/note.png new file mode 100644 index 0000000..944ca7f Binary files /dev/null and b/app/src/main/res/drawable/note.png differ diff --git a/app/src/main/res/drawable/notes.png b/app/src/main/res/drawable/notes.png new file mode 100644 index 0000000..eb4dfe8 Binary files /dev/null and b/app/src/main/res/drawable/notes.png differ diff --git a/app/src/main/res/drawable/noweb.png b/app/src/main/res/drawable/noweb.png new file mode 100644 index 0000000..7a89bd4 Binary files /dev/null and b/app/src/main/res/drawable/noweb.png differ diff --git a/app/src/main/res/drawable/placeholder.png b/app/src/main/res/drawable/placeholder.png new file mode 100644 index 0000000..81cc7a3 Binary files /dev/null and b/app/src/main/res/drawable/placeholder.png differ diff --git a/app/src/main/res/drawable/polizon.png b/app/src/main/res/drawable/polizon.png new file mode 100644 index 0000000..8850401 Binary files /dev/null and b/app/src/main/res/drawable/polizon.png differ diff --git a/app/src/main/res/drawable/settinhgs.png b/app/src/main/res/drawable/settinhgs.png new file mode 100644 index 0000000..bd399a1 Binary files /dev/null and b/app/src/main/res/drawable/settinhgs.png differ diff --git a/app/src/main/res/drawable/telephone.png b/app/src/main/res/drawable/telephone.png new file mode 100644 index 0000000..35b8e8e Binary files /dev/null and b/app/src/main/res/drawable/telephone.png differ diff --git a/app/src/main/res/drawable/ticket.png b/app/src/main/res/drawable/ticket.png new file mode 100644 index 0000000..f980bc7 Binary files /dev/null and b/app/src/main/res/drawable/ticket.png differ diff --git a/app/src/main/res/drawable/update.png b/app/src/main/res/drawable/update.png new file mode 100644 index 0000000..0fdba43 Binary files /dev/null and b/app/src/main/res/drawable/update.png differ diff --git a/app/src/main/res/drawable/upload.png b/app/src/main/res/drawable/upload.png new file mode 100644 index 0000000..e397f4f Binary files /dev/null and b/app/src/main/res/drawable/upload.png differ diff --git a/app/src/main/res/font/roboto.xml b/app/src/main/res/font/roboto.xml new file mode 100644 index 0000000..2641caf --- /dev/null +++ b/app/src/main/res/font/roboto.xml @@ -0,0 +1,7 @@ + + + diff --git a/app/src/main/res/font/roboto_bold.xml b/app/src/main/res/font/roboto_bold.xml new file mode 100644 index 0000000..1e8c20a --- /dev/null +++ b/app/src/main/res/font/roboto_bold.xml @@ -0,0 +1,7 @@ + + + diff --git a/app/src/main/res/font/roboto_light.xml b/app/src/main/res/font/roboto_light.xml new file mode 100644 index 0000000..28fbc0d --- /dev/null +++ b/app/src/main/res/font/roboto_light.xml @@ -0,0 +1,7 @@ + + + diff --git a/app/src/main/res/font/roboto_thin.xml b/app/src/main/res/font/roboto_thin.xml new file mode 100644 index 0000000..7acfbd3 --- /dev/null +++ b/app/src/main/res/font/roboto_thin.xml @@ -0,0 +1,7 @@ + + + diff --git a/app/src/main/res/layout/activity_configure.xml b/app/src/main/res/layout/activity_configure.xml new file mode 100644 index 0000000..6ae0c4f --- /dev/null +++ b/app/src/main/res/layout/activity_configure.xml @@ -0,0 +1,264 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_info.xml b/app/src/main/res/layout/activity_info.xml new file mode 100644 index 0000000..376f823 --- /dev/null +++ b/app/src/main/res/layout/activity_info.xml @@ -0,0 +1,144 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_loaders.xml b/app/src/main/res/layout/activity_loaders.xml new file mode 100644 index 0000000..b27743c --- /dev/null +++ b/app/src/main/res/layout/activity_loaders.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml new file mode 100644 index 0000000..6b8581b --- /dev/null +++ b/app/src/main/res/layout/activity_login.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + +