Commit 517f580efdbcaf0bf4077afb269bdd7635601110

Authored by badetitou
1 parent bda0317b

Can modify User

app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/MyEventRecyclerViewAdapter.java
@@ -40,7 +40,7 @@ public class MyEventRecyclerViewAdapter extends RecyclerView.Adapter<MyEventRecy @@ -40,7 +40,7 @@ public class MyEventRecyclerViewAdapter extends RecyclerView.Adapter<MyEventRecy
40 public void onBindViewHolder(final ViewHolder holder, int position) { 40 public void onBindViewHolder(final ViewHolder holder, int position) {
41 holder.mItem = mEvents.get(position); 41 holder.mItem = mEvents.get(position);
42 holder.mContentView.setText(mEvents.get(position).getNomEvent()); 42 holder.mContentView.setText(mEvents.get(position).getNomEvent());
43 - holder.mPriceView.setText(String.format(Locale.FRANCE, "%.2f", mEvents.get(position).getPrice())); 43 + holder.mPriceView.setText(String.format(Locale.US, "%.2f", mEvents.get(position).getPrice()));
44 holder.mId = mEvents.get(position).getIdEvent(); 44 holder.mId = mEvents.get(position).getIdEvent();
45 45
46 holder.mView.setOnClickListener(new View.OnClickListener() { 46 holder.mView.setOnClickListener(new View.OnClickListener() {
app/src/main/java/net/plil/clubinfo/etunicorn/app/LoginActivity.java
@@ -3,65 +3,35 @@ package net.plil.clubinfo.etunicorn.app; @@ -3,65 +3,35 @@ package net.plil.clubinfo.etunicorn.app;
3 import android.animation.Animator; 3 import android.animation.Animator;
4 import android.animation.AnimatorListenerAdapter; 4 import android.animation.AnimatorListenerAdapter;
5 import android.annotation.TargetApi; 5 import android.annotation.TargetApi;
6 -import android.app.DownloadManager;  
7 import android.content.Intent; 6 import android.content.Intent;
8 -import android.content.pm.PackageManager;  
9 -import android.support.annotation.NonNull;  
10 -import android.support.design.widget.Snackbar;  
11 import android.support.v7.app.AppCompatActivity; 7 import android.support.v7.app.AppCompatActivity;
12 -import android.app.LoaderManager.LoaderCallbacks;  
13 -  
14 -import android.content.CursorLoader;  
15 -import android.content.Loader;  
16 -import android.database.Cursor;  
17 -import android.net.Uri;  
18 -import android.os.AsyncTask;  
19 8
20 import android.os.Build; 9 import android.os.Build;
21 import android.os.Bundle; 10 import android.os.Bundle;
22 -import android.provider.ContactsContract;  
23 -import android.text.TextUtils;  
24 import android.view.KeyEvent; 11 import android.view.KeyEvent;
25 import android.view.View; 12 import android.view.View;
26 import android.view.View.OnClickListener; 13 import android.view.View.OnClickListener;
27 import android.view.inputmethod.EditorInfo; 14 import android.view.inputmethod.EditorInfo;
28 -import android.widget.ArrayAdapter;  
29 import android.widget.Button; 15 import android.widget.Button;
30 import android.widget.EditText; 16 import android.widget.EditText;
31 import android.widget.TextView; 17 import android.widget.TextView;
32 import android.widget.Toast; 18 import android.widget.Toast;
33 19
34 import com.android.volley.Request; 20 import com.android.volley.Request;
35 -import com.android.volley.RequestQueue;  
36 import com.android.volley.Response; 21 import com.android.volley.Response;
37 import com.android.volley.VolleyError; 22 import com.android.volley.VolleyError;
38 import com.android.volley.toolbox.JsonObjectRequest; 23 import com.android.volley.toolbox.JsonObjectRequest;
39 -import com.google.gson.Gson;  
40 -import com.google.gson.GsonBuilder;  
41 -import com.google.gson.JsonDeserializationContext;  
42 -import com.google.gson.JsonDeserializer;  
43 -import com.google.gson.JsonElement;  
44 -import com.google.gson.JsonParseException;  
45 24
46 import net.plil.clubinfo.etunicorn.R; 25 import net.plil.clubinfo.etunicorn.R;
47 -import net.plil.clubinfo.etunicorn.data.Permission;  
48 -import net.plil.clubinfo.etunicorn.data.Personne;  
49 import net.plil.clubinfo.etunicorn.data.Session; 26 import net.plil.clubinfo.etunicorn.data.Session;
50 import net.plil.clubinfo.etunicorn.data.User; 27 import net.plil.clubinfo.etunicorn.data.User;
51 import net.plil.clubinfo.etunicorn.utils.ConvertBytesToString; 28 import net.plil.clubinfo.etunicorn.utils.ConvertBytesToString;
52 -import net.plil.clubinfo.etunicorn.utils.JsonCoverter; 29 +import net.plil.clubinfo.etunicorn.utils.JsonConverter;
53 import net.plil.clubinfo.etunicorn.utils.VolleyUtils; 30 import net.plil.clubinfo.etunicorn.utils.VolleyUtils;
54 31
55 import org.json.JSONException; 32 import org.json.JSONException;
56 import org.json.JSONObject; 33 import org.json.JSONObject;
57 34
58 -import java.lang.reflect.Type;  
59 -import java.util.ArrayList;  
60 -import java.util.Date;  
61 -import java.util.List;  
62 -  
63 -import static android.Manifest.permission.READ_CONTACTS;  
64 -  
65 /** 35 /**
66 * A login screen that offers login via email/password. 36 * A login screen that offers login via email/password.
67 */ 37 */
@@ -183,12 +153,12 @@ public class LoginActivity extends AppCompatActivity { @@ -183,12 +153,12 @@ public class LoginActivity extends AppCompatActivity {
183 JsonObjectRequest jsonObjectRequest = null; 153 JsonObjectRequest jsonObjectRequest = null;
184 try { 154 try {
185 155
186 - jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/login" , new JSONObject(JsonCoverter.getConverter().toJson(user)), new Response.Listener<JSONObject>() { 156 + jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/login" , new JSONObject(JsonConverter.getConverter().toJson(user)), new Response.Listener<JSONObject>() {
187 @Override 157 @Override
188 public void onResponse(JSONObject response) { 158 public void onResponse(JSONObject response) {
189 showProgress(false); 159 showProgress(false);
190 Intent intent = new Intent(getApplicationContext(), MainActivity.class); 160 Intent intent = new Intent(getApplicationContext(), MainActivity.class);
191 - Session s = JsonCoverter.getConverter().fromJson(String.valueOf(response), Session.class); 161 + Session s = JsonConverter.getConverter().fromJson(String.valueOf(response), Session.class);
192 intent.putExtra("session", s); 162 intent.putExtra("session", s);
193 startActivity(intent); 163 startActivity(intent);
194 } 164 }
@@ -196,7 +166,10 @@ public class LoginActivity extends AppCompatActivity { @@ -196,7 +166,10 @@ public class LoginActivity extends AppCompatActivity {
196 @Override 166 @Override
197 public void onErrorResponse(VolleyError error) { 167 public void onErrorResponse(VolleyError error) {
198 showProgress(false); 168 showProgress(false);
199 - Toast.makeText(getApplicationContext(), "error : " + ConvertBytesToString.bytesToStringVolLey(error.networkResponse.data), Toast.LENGTH_SHORT).show(); 169 + if (error.networkResponse != null)
  170 + Toast.makeText(getApplicationContext(), "error : " + ConvertBytesToString.bytesToStringVolLey(error.networkResponse.data), Toast.LENGTH_SHORT).show();
  171 + else
  172 + Toast.makeText(getApplicationContext(), "Unknow Error " + error.getMessage(), Toast.LENGTH_SHORT).show();
200 } 173 }
201 } 174 }
202 ); 175 );
app/src/main/java/net/plil/clubinfo/etunicorn/app/MainActivity.java
@@ -59,7 +59,7 @@ public class MainActivity extends AppCompatActivity @@ -59,7 +59,7 @@ public class MainActivity extends AppCompatActivity
59 private Toolbar toolbar; 59 private Toolbar toolbar;
60 private AppBarLayout appBarLayout; 60 private AppBarLayout appBarLayout;
61 61
62 - private Session s; 62 + public static Session session;
63 63
64 NfcAdapter mAdapter; 64 NfcAdapter mAdapter;
65 PendingIntent mPendingIntent; 65 PendingIntent mPendingIntent;
@@ -69,18 +69,18 @@ public class MainActivity extends AppCompatActivity @@ -69,18 +69,18 @@ public class MainActivity extends AppCompatActivity
69 super.onCreate(savedInstanceState); 69 super.onCreate(savedInstanceState);
70 70
71 Intent intent = this.getIntent(); 71 Intent intent = this.getIntent();
72 - s = (Session) intent.getSerializableExtra("session");  
73 - if (s.getPersonne().getRole().getNom().equals("admin")){ 72 + session = (Session) intent.getSerializableExtra("session");
  73 + if (session.getPersonne().getRole().getNom().equals("admin")){
74 nbPages = 5; 74 nbPages = 5;
75 Action.CONSOMATION.setValue(2); 75 Action.CONSOMATION.setValue(2);
76 Action.EVENT.setValue(3); 76 Action.EVENT.setValue(3);
77 Action.PERSONNE.setValue(4); 77 Action.PERSONNE.setValue(4);
78 - } else if (s.getPersonne().getRole().getNom().equals("bde")){ 78 + } else if (session.getPersonne().getRole().getNom().equals("bde")){
79 nbPages = 4; 79 nbPages = 4;
80 Action.CONSOMATION.setValue(-1); 80 Action.CONSOMATION.setValue(-1);
81 Action.EVENT.setValue(2); 81 Action.EVENT.setValue(2);
82 Action.PERSONNE.setValue(3); 82 Action.PERSONNE.setValue(3);
83 - } else if (s.getPersonne().getRole().getNom().equals("bar")){ 83 + } else if (session.getPersonne().getRole().getNom().equals("bar")){
84 nbPages = 3; 84 nbPages = 3;
85 Action.CONSOMATION.setValue(2); 85 Action.CONSOMATION.setValue(2);
86 Action.EVENT.setValue(-1); 86 Action.EVENT.setValue(-1);
app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/ConsommationRecyclerViewAdapter.java
@@ -42,9 +42,9 @@ public class ConsommationRecyclerViewAdapter extends RecyclerView.Adapter&lt;Consom @@ -42,9 +42,9 @@ public class ConsommationRecyclerViewAdapter extends RecyclerView.Adapter&lt;Consom
42 @Override 42 @Override
43 public void onBindViewHolder(final ViewHolder holder, int position) { 43 public void onBindViewHolder(final ViewHolder holder, int position) {
44 holder.mItem = mValues.get(position); 44 holder.mItem = mValues.get(position);
45 - holder.mIdView.setText(String.format(Locale.FRANCE, "%d", mValues.get(position).getIdConsomation())); 45 + holder.mIdView.setText(String.format(Locale.US, "%d", mValues.get(position).getIdConsomation()));
46 holder.mContentView.setText(mValues.get(position).getNomConsomation()); 46 holder.mContentView.setText(mValues.get(position).getNomConsomation());
47 - holder.mPriceView.setText(String.format(Locale.FRANCE, "%.2f",mValues.get(position).getPrix())); 47 + holder.mPriceView.setText(String.format(Locale.US, "%.2f",mValues.get(position).getPrix()));
48 48
49 holder.mView.setOnClickListener(new View.OnClickListener() { 49 holder.mView.setOnClickListener(new View.OnClickListener() {
50 @Override 50 @Override
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/CreatePersonne.java
@@ -21,11 +21,14 @@ import android.widget.Toast; @@ -21,11 +21,14 @@ import android.widget.Toast;
21 import com.android.volley.Request; 21 import com.android.volley.Request;
22 import com.android.volley.Response; 22 import com.android.volley.Response;
23 import com.android.volley.VolleyError; 23 import com.android.volley.VolleyError;
  24 +import com.android.volley.toolbox.JsonArrayRequest;
24 import com.android.volley.toolbox.JsonObjectRequest; 25 import com.android.volley.toolbox.JsonObjectRequest;
25 import com.google.gson.Gson; 26 import com.google.gson.Gson;
26 27
27 import net.plil.clubinfo.etunicorn.R; 28 import net.plil.clubinfo.etunicorn.R;
28 import net.plil.clubinfo.etunicorn.data.Role; 29 import net.plil.clubinfo.etunicorn.data.Role;
  30 +import net.plil.clubinfo.etunicorn.utils.ConvertBytesToString;
  31 +import net.plil.clubinfo.etunicorn.utils.JsonConverter;
29 import net.plil.clubinfo.etunicorn.utils.VolleyUtils; 32 import net.plil.clubinfo.etunicorn.utils.VolleyUtils;
30 33
31 import org.json.JSONArray; 34 import org.json.JSONArray;
@@ -129,6 +132,7 @@ public class CreatePersonne extends DialogFragment { @@ -129,6 +132,7 @@ public class CreatePersonne extends DialogFragment {
129 @Override 132 @Override
130 public void onResponse(JSONObject response) { 133 public void onResponse(JSONObject response) {
131 mProgressBar.setVisibility(View.GONE); 134 mProgressBar.setVisibility(View.GONE);
  135 + Toast.makeText(getContext(), response.toString(), Toast.LENGTH_LONG).show();
132 dismiss(); 136 dismiss();
133 } 137 }
134 }, new Response.ErrorListener() { 138 }, new Response.ErrorListener() {
@@ -166,16 +170,13 @@ public class CreatePersonne extends DialogFragment { @@ -166,16 +170,13 @@ public class CreatePersonne extends DialogFragment {
166 } 170 }
167 171
168 private void changeRolePossibility(){ 172 private void changeRolePossibility(){
169 - JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, VolleyUtils.baseUri + "/role/" ,null , new Response.Listener<JSONObject>() { 173 + JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, VolleyUtils.baseUri + "/role" ,null , new Response.Listener<JSONArray>() {
170 @Override 174 @Override
171 - public void onResponse(JSONObject response) {  
172 - JSONArray jsonArray = null; 175 + public void onResponse(JSONArray response) {
173 try { 176 try {
174 - //TODO change this by the real name of the array  
175 - jsonArray = response.getJSONArray("roles");  
176 arraySpinnerRole.clear(); 177 arraySpinnerRole.clear();
177 - for (int i =0; i<jsonArray.length();++i){  
178 - arraySpinnerRole.add(new Gson().fromJson(String.valueOf(jsonArray.getJSONObject(i)), Role.class)); 178 + for (int i =0; i<response.length();++i){
  179 + arraySpinnerRole.add(JsonConverter.getConverter().fromJson(String.valueOf(response.getJSONObject(i)), Role.class));
179 } 180 }
180 adapterRole.notifyDataSetChanged(); 181 adapterRole.notifyDataSetChanged();
181 } catch (JSONException e) { 182 } catch (JSONException e) {
@@ -186,12 +187,15 @@ public class CreatePersonne extends DialogFragment { @@ -186,12 +187,15 @@ public class CreatePersonne extends DialogFragment {
186 }, new Response.ErrorListener() { 187 }, new Response.ErrorListener() {
187 @Override 188 @Override
188 public void onErrorResponse(VolleyError error) { 189 public void onErrorResponse(VolleyError error) {
189 - Toast.makeText(getContext(), "Can't update role", Toast.LENGTH_LONG).show(); 190 + if(error.networkResponse == null)
  191 + Toast.makeText(getContext(), "Verifier votre connection Internet", Toast.LENGTH_LONG).show();
  192 + else
  193 + Toast.makeText(getContext(), ConvertBytesToString.bytesToStringVolLey(error.networkResponse.data), Toast.LENGTH_LONG).show();
190 } 194 }
191 } 195 }
192 ); 196 );
193 - jsonObjectRequest.setTag(CreatePersonne.class);  
194 - VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); 197 + jsonArrayRequest.setTag(CreatePersonne.class);
  198 + VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonArrayRequest);
195 } 199 }
196 200
197 DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() { 201 DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/ModifyPersonne.java
@@ -18,15 +18,23 @@ import android.widget.ProgressBar; @@ -18,15 +18,23 @@ import android.widget.ProgressBar;
18 import android.widget.Spinner; 18 import android.widget.Spinner;
19 import android.widget.Toast; 19 import android.widget.Toast;
20 20
  21 +import com.android.volley.AuthFailureError;
21 import com.android.volley.Request; 22 import com.android.volley.Request;
22 import com.android.volley.Response; 23 import com.android.volley.Response;
23 import com.android.volley.VolleyError; 24 import com.android.volley.VolleyError;
  25 +import com.android.volley.toolbox.JsonArrayRequest;
24 import com.android.volley.toolbox.JsonObjectRequest; 26 import com.android.volley.toolbox.JsonObjectRequest;
25 import com.google.gson.Gson; 27 import com.google.gson.Gson;
  28 +import com.google.gson.JsonArray;
  29 +import com.google.gson.JsonObject;
  30 +import com.google.gson.JsonParser;
26 31
27 import net.plil.clubinfo.etunicorn.R; 32 import net.plil.clubinfo.etunicorn.R;
  33 +import net.plil.clubinfo.etunicorn.app.MainActivity;
28 import net.plil.clubinfo.etunicorn.data.Personne; 34 import net.plil.clubinfo.etunicorn.data.Personne;
29 import net.plil.clubinfo.etunicorn.data.Role; 35 import net.plil.clubinfo.etunicorn.data.Role;
  36 +import net.plil.clubinfo.etunicorn.utils.ConvertBytesToString;
  37 +import net.plil.clubinfo.etunicorn.utils.JsonConverter;
30 import net.plil.clubinfo.etunicorn.utils.VolleyUtils; 38 import net.plil.clubinfo.etunicorn.utils.VolleyUtils;
31 39
32 import org.json.JSONArray; 40 import org.json.JSONArray;
@@ -36,8 +44,10 @@ import org.json.JSONObject; @@ -36,8 +44,10 @@ import org.json.JSONObject;
36 import java.text.SimpleDateFormat; 44 import java.text.SimpleDateFormat;
37 import java.util.ArrayList; 45 import java.util.ArrayList;
38 import java.util.Calendar; 46 import java.util.Calendar;
  47 +import java.util.HashMap;
39 import java.util.List; 48 import java.util.List;
40 import java.util.Locale; 49 import java.util.Locale;
  50 +import java.util.Map;
41 51
42 52
43 public class ModifyPersonne extends DialogFragment { 53 public class ModifyPersonne extends DialogFragment {
@@ -81,10 +91,10 @@ public class ModifyPersonne extends DialogFragment { @@ -81,10 +91,10 @@ public class ModifyPersonne extends DialogFragment {
81 mCarte = (EditText) view.findViewById(R.id.modify_personne_carte); 91 mCarte = (EditText) view.findViewById(R.id.modify_personne_carte);
82 mNaissance = (Spinner) view.findViewById(R.id.modify_personne_naissance); 92 mNaissance = (Spinner) view.findViewById(R.id.modify_personne_naissance);
83 mRole = (Spinner) view.findViewById(R.id.modify_personne_role); 93 mRole = (Spinner) view.findViewById(R.id.modify_personne_role);
84 - mProgressBar = (ProgressBar) view.findViewById(R.id.modify_event_progress_bar); 94 + mProgressBar = (ProgressBar) view.findViewById(R.id.modify_personne_progress_bar);
85 95
86 - mLoginInput = (TextInputLayout) view.findViewById(R.id.create_personne_login_input);  
87 - mCarteInput = (TextInputLayout) view.findViewById(R.id.create_personne_carte_input); 96 + mLoginInput = (TextInputLayout) view.findViewById(R.id.modify_personne_login_input);
  97 + mCarteInput = (TextInputLayout) view.findViewById(R.id.modify_personne_carte_input);
88 98
89 final Personne personne = (Personne) getArguments().getSerializable("personne"); 99 final Personne personne = (Personne) getArguments().getSerializable("personne");
90 100
@@ -98,7 +108,7 @@ public class ModifyPersonne extends DialogFragment { @@ -98,7 +108,7 @@ public class ModifyPersonne extends DialogFragment {
98 mRole.setAdapter(adapterRole); 108 mRole.setAdapter(adapterRole);
99 changeRolePossibility(); 109 changeRolePossibility();
100 mNaissance = (Spinner) view.findViewById(R.id.modify_personne_naissance); 110 mNaissance = (Spinner) view.findViewById(R.id.modify_personne_naissance);
101 - String myFormat = "yyyy-MM-dd"; //In which you need put here 111 + final String myFormat = "yyyy-MM-dd"; //In which you need put here
102 SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.FRANCE); 112 SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.FRANCE);
103 if (personne.getNaissance() == null){ 113 if (personne.getNaissance() == null){
104 arraySpinnerNaissance = new String[]{ 114 arraySpinnerNaissance = new String[]{
@@ -140,7 +150,7 @@ public class ModifyPersonne extends DialogFragment { @@ -140,7 +150,7 @@ public class ModifyPersonne extends DialogFragment {
140 try { 150 try {
141 jsonObject.put("carte", mCarte.getText().toString()); 151 jsonObject.put("carte", mCarte.getText().toString());
142 jsonObject.put("login", mLogin.getText().toString()); 152 jsonObject.put("login", mLogin.getText().toString());
143 - jsonObject.put("role", mRole.getSelectedItem()); 153 + jsonObject.put("role", JsonConverter.convertToJSONObject(mRole.getSelectedItem()));
144 if (!mNaissance.getSelectedItem().equals(getString(R.string.modify_personne_hint_date))) 154 if (!mNaissance.getSelectedItem().equals(getString(R.string.modify_personne_hint_date)))
145 jsonObject.put("naissance", mNaissance.getSelectedItem().toString()); 155 jsonObject.put("naissance", mNaissance.getSelectedItem().toString());
146 } catch (JSONException e){ 156 } catch (JSONException e){
@@ -150,19 +160,42 @@ public class ModifyPersonne extends DialogFragment { @@ -150,19 +160,42 @@ public class ModifyPersonne extends DialogFragment {
150 @Override 160 @Override
151 public void onResponse(JSONObject response) { 161 public void onResponse(JSONObject response) {
152 mProgressBar.setVisibility(View.GONE); 162 mProgressBar.setVisibility(View.GONE);
153 - Toast.makeText(getContext(), R.string.modify_done, Toast.LENGTH_LONG).show(); 163 + //Toast.makeText(getContext(), R.string.modify_done, Toast.LENGTH_LONG).show();
  164 + Toast.makeText(getContext(), "good response", Toast.LENGTH_SHORT).show();
154 dismiss(); 165 dismiss();
155 } 166 }
156 }, new Response.ErrorListener() { 167 }, new Response.ErrorListener() {
157 @Override 168 @Override
158 public void onErrorResponse(VolleyError error) { 169 public void onErrorResponse(VolleyError error) {
159 mProgressBar.setVisibility(View.GONE); 170 mProgressBar.setVisibility(View.GONE);
160 - Toast.makeText(getContext(), R.string.modify_refused, Toast.LENGTH_LONG).show();  
161 - 171 + if (error.networkResponse != null)
  172 + Toast.makeText(getContext(), R.string.modify_refused + " : " + ConvertBytesToString.bytesToStringVolLey(error.networkResponse.data), Toast.LENGTH_LONG).show();
  173 + else
  174 + Toast.makeText(getContext(), "!!" + error.getStackTrace().toString(), Toast.LENGTH_SHORT).show();
  175 + mRole.setVisibility(View.VISIBLE);
  176 + mCarteInput.setVisibility(View.VISIBLE);
  177 + mLoginInput.setVisibility(View.VISIBLE);
  178 + mNaissance.setVisibility(View.VISIBLE);
162 } 179 }
163 } 180 }
164 - ); 181 + ){
  182 + @Override
  183 + public Map<String, String> getHeaders() throws AuthFailureError {
  184 + Map<String, String> headers = new HashMap<String, String>();
  185 + headers.put("Authorization", MainActivity.session.getToken());
  186 + return headers;
  187 + }};
165 jsonObjectRequest.setTag(ModifyPersonne.class); 188 jsonObjectRequest.setTag(ModifyPersonne.class);
  189 +
  190 + try {
  191 + for (String s : jsonObjectRequest.getHeaders().keySet()){
  192 + System.out.println(s + " " + jsonObjectRequest.getHeaders().get(s));
  193 + }
  194 + } catch (AuthFailureError authFailureError) {
  195 + authFailureError.printStackTrace();
  196 + }
  197 + System.out.println(ConvertBytesToString.bytesToStringVolLey(jsonObjectRequest.getBody()));
  198 +
166 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); 199 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
167 } 200 }
168 }); 201 });
@@ -211,16 +244,13 @@ public class ModifyPersonne extends DialogFragment { @@ -211,16 +244,13 @@ public class ModifyPersonne extends DialogFragment {
211 } 244 }
212 245
213 private void changeRolePossibility(){ 246 private void changeRolePossibility(){
214 - JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, VolleyUtils.baseUri + "/role/" ,null , new Response.Listener<JSONObject>() { 247 + JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, VolleyUtils.baseUri + "/role" ,null , new Response.Listener<JSONArray>() {
215 @Override 248 @Override
216 - public void onResponse(JSONObject response) {  
217 - JSONArray jsonArray = null; 249 + public void onResponse(JSONArray response) {
218 try { 250 try {
219 - //TODO change this by the real name of the array  
220 - jsonArray = response.getJSONArray("roles");  
221 arraySpinnerRole.clear(); 251 arraySpinnerRole.clear();
222 - for (int i =0; i<jsonArray.length();++i){  
223 - arraySpinnerRole.add(new Gson().fromJson(String.valueOf(jsonArray.getJSONObject(i)), Role.class)); 252 + for (int i =0; i<response.length();++i){
  253 + arraySpinnerRole.add(JsonConverter.getConverter().fromJson(String.valueOf(response.getJSONObject(i)), Role.class));
224 } 254 }
225 adapterRole.notifyDataSetChanged(); 255 adapterRole.notifyDataSetChanged();
226 } catch (JSONException e) { 256 } catch (JSONException e) {
@@ -231,11 +261,14 @@ public class ModifyPersonne extends DialogFragment { @@ -231,11 +261,14 @@ public class ModifyPersonne extends DialogFragment {
231 }, new Response.ErrorListener() { 261 }, new Response.ErrorListener() {
232 @Override 262 @Override
233 public void onErrorResponse(VolleyError error) { 263 public void onErrorResponse(VolleyError error) {
234 - Toast.makeText(getContext(), "Can't update role", Toast.LENGTH_LONG).show(); 264 + if(error.networkResponse == null)
  265 + Toast.makeText(getContext(), "Verifier votre connection Internet", Toast.LENGTH_LONG).show();
  266 + else
  267 + Toast.makeText(getContext(), ConvertBytesToString.bytesToStringVolLey(error.networkResponse.data), Toast.LENGTH_LONG).show();
235 } 268 }
236 } 269 }
237 ); 270 );
238 - jsonObjectRequest.setTag(ModifyPersonne.class);  
239 - VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); 271 + jsonArrayRequest.setTag(ModifyPersonne.class);
  272 + VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonArrayRequest);
240 } 273 }
241 } 274 }
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/PersonOverviewFragment.java
@@ -15,6 +15,7 @@ import android.widget.TextView; @@ -15,6 +15,7 @@ import android.widget.TextView;
15 import net.plil.clubinfo.etunicorn.R; 15 import net.plil.clubinfo.etunicorn.R;
16 import net.plil.clubinfo.etunicorn.data.Personne; 16 import net.plil.clubinfo.etunicorn.data.Personne;
17 17
  18 +import java.text.SimpleDateFormat;
18 import java.util.Locale; 19 import java.util.Locale;
19 20
20 /** 21 /**
@@ -61,8 +62,9 @@ public class PersonOverviewFragment extends DialogFragment{ @@ -61,8 +62,9 @@ public class PersonOverviewFragment extends DialogFragment{
61 assert personne != null; 62 assert personne != null;
62 mCarte.setText(personne.getCarte()); 63 mCarte.setText(personne.getCarte());
63 mRole.setText(personne.getRole().getNom()); 64 mRole.setText(personne.getRole().getNom());
64 - mSolde.setText(String.format(Locale.FRANCE, "%.2f",personne.getSolde()));  
65 - mNaissance.setText(personne.getNaissance().toString()); 65 + mSolde.setText(String.format(Locale.US, "%.2f",personne.getSolde()));
  66 + if (personne.getNaissance() != null)
  67 + mNaissance.setText(personne.getNaissance().toString());
66 mLogin.setText(personne.getLogin()); 68 mLogin.setText(personne.getLogin());
67 69
68 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 70 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/PersonneFragment.java
@@ -8,16 +8,28 @@ import android.support.v7.widget.RecyclerView; @@ -8,16 +8,28 @@ import android.support.v7.widget.RecyclerView;
8 import android.view.LayoutInflater; 8 import android.view.LayoutInflater;
9 import android.view.View; 9 import android.view.View;
10 import android.view.ViewGroup; 10 import android.view.ViewGroup;
  11 +import android.widget.Toast;
  12 +
  13 +import com.android.volley.AuthFailureError;
  14 +import com.android.volley.Request;
  15 +import com.android.volley.Response;
  16 +import com.android.volley.VolleyError;
  17 +import com.android.volley.toolbox.JsonArrayRequest;
11 18
12 import net.plil.clubinfo.etunicorn.R; 19 import net.plil.clubinfo.etunicorn.R;
13 import net.plil.clubinfo.etunicorn.app.FragmentNFC; 20 import net.plil.clubinfo.etunicorn.app.FragmentNFC;
14 -import net.plil.clubinfo.etunicorn.data.Permission; 21 +import net.plil.clubinfo.etunicorn.app.MainActivity;
15 import net.plil.clubinfo.etunicorn.data.Personne; 22 import net.plil.clubinfo.etunicorn.data.Personne;
16 -import net.plil.clubinfo.etunicorn.data.Role; 23 +import net.plil.clubinfo.etunicorn.utils.ConvertBytesToString;
  24 +import net.plil.clubinfo.etunicorn.utils.JsonConverter;
  25 +import net.plil.clubinfo.etunicorn.utils.VolleyUtils;
  26 +
  27 +import org.json.JSONArray;
  28 +import org.json.JSONException;
17 29
18 -import java.sql.Date;  
19 import java.util.ArrayList; 30 import java.util.ArrayList;
20 -import java.util.List; 31 +import java.util.HashMap;
  32 +import java.util.Map;
21 33
22 /** 34 /**
23 * A fragment representing a list of Items. 35 * A fragment representing a list of Items.
@@ -28,6 +40,8 @@ import java.util.List; @@ -28,6 +40,8 @@ import java.util.List;
28 public class PersonneFragment extends FragmentNFC { 40 public class PersonneFragment extends FragmentNFC {
29 41
30 private OnListFragmentInteractionListener mListener; 42 private OnListFragmentInteractionListener mListener;
  43 + private ArrayList<Personne> personnes = new ArrayList<>();
  44 + private RecyclerView.Adapter mAdapter;
31 45
32 /** 46 /**
33 * Mandatory empty constructor for the fragment manager to instantiate the 47 * Mandatory empty constructor for the fragment manager to instantiate the
@@ -54,27 +68,9 @@ public class PersonneFragment extends FragmentNFC { @@ -54,27 +68,9 @@ public class PersonneFragment extends FragmentNFC {
54 Context context = view.getContext(); 68 Context context = view.getContext();
55 RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.personne_list); 69 RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.personne_list);
56 recyclerView.setLayoutManager(new LinearLayoutManager(context)); 70 recyclerView.setLayoutManager(new LinearLayoutManager(context));
57 -  
58 - List<Personne> personneList = new ArrayList<>();  
59 - Role r = new Role();  
60 - r.setNom("ADMIN_TEST");  
61 - Permission p = new Permission();  
62 - p.setNom("Lire");  
63 - r.getPermissions().add(p);  
64 - p = new Permission();  
65 - p.setNom("Ecrire");  
66 - r.getPermissions().add(p);  
67 - for (int i = 0;i<150;++i){  
68 - Personne personne = new Personne();  
69 - personne.setCarte("15245698547856");  
70 - personne.setLogin("bverhaeg");  
71 - personne.setNaissance(new Date(System.currentTimeMillis()));  
72 - personne.setSolde(45);  
73 - personne.setRole(r);  
74 - personneList.add(personne);  
75 - }  
76 - recyclerView.setAdapter(new MyPersonneRecyclerViewAdapter(personneList, mListener, getActivity()));  
77 - 71 + mAdapter = new MyPersonneRecyclerViewAdapter(personnes, mListener, getActivity());
  72 + recyclerView.setAdapter(mAdapter);
  73 + setPersonnes();
78 FloatingActionButton fAB = (FloatingActionButton) view.findViewById(R.id.personne_add); 74 FloatingActionButton fAB = (FloatingActionButton) view.findViewById(R.id.personne_add);
79 fAB.setOnClickListener(new View.OnClickListener() { 75 fAB.setOnClickListener(new View.OnClickListener() {
80 @Override 76 @Override
@@ -105,6 +101,39 @@ public class PersonneFragment extends FragmentNFC { @@ -105,6 +101,39 @@ public class PersonneFragment extends FragmentNFC {
105 mListener = null; 101 mListener = null;
106 } 102 }
107 103
  104 + private void setPersonnes(){
  105 + JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, VolleyUtils.baseUri + "/personne" ,null , new Response.Listener<JSONArray>() {
  106 + @Override
  107 + public void onResponse(JSONArray response) {
  108 + try {
  109 + personnes.clear();
  110 + for (int i =0; i<response.length();++i){
  111 + personnes.add(JsonConverter.getConverter().fromJson(String.valueOf(response.getJSONObject(i)), Personne.class));
  112 + }
  113 + mAdapter.notifyDataSetChanged();
  114 + } catch (JSONException e) {
  115 + e.printStackTrace();
  116 + }
  117 +
  118 + }
  119 + }, new Response.ErrorListener() {
  120 + @Override
  121 + public void onErrorResponse(VolleyError error) {
  122 + Toast.makeText(getContext(), ConvertBytesToString.bytesToStringVolLey(error.networkResponse.data), Toast.LENGTH_LONG).show();
  123 + }
  124 + }
  125 + ) {
  126 + @Override
  127 + public Map<String, String> getHeaders() throws AuthFailureError {
  128 + Map<String, String> headers = new HashMap<>();
  129 + headers.put("Authorization", MainActivity.session.getToken());
  130 + return headers;
  131 + }
  132 + };
  133 + jsonArrayRequest.setTag(ModifyPersonne.class);
  134 + VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonArrayRequest);
  135 + }
  136 +
108 @Override 137 @Override
109 public void processNFC(String idCardUser) { 138 public void processNFC(String idCardUser) {
110 139
app/src/main/java/net/plil/clubinfo/etunicorn/utils/JsonCoverter.java renamed to app/src/main/java/net/plil/clubinfo/etunicorn/utils/JsonConverter.java
@@ -2,12 +2,16 @@ package net.plil.clubinfo.etunicorn.utils; @@ -2,12 +2,16 @@ package net.plil.clubinfo.etunicorn.utils;
2 2
3 import com.google.gson.Gson; 3 import com.google.gson.Gson;
4 import com.google.gson.GsonBuilder; 4 import com.google.gson.GsonBuilder;
  5 +import com.google.gson.JsonParser;
  6 +
  7 +import org.json.JSONException;
  8 +import org.json.JSONObject;
5 9
6 /** 10 /**
7 * Created by badetitou on 05/02/2017. 11 * Created by badetitou on 05/02/2017.
8 */ 12 */
9 13
10 -public class JsonCoverter { 14 +public class JsonConverter {
11 15
12 private static Gson gson; 16 private static Gson gson;
13 17
@@ -18,4 +22,14 @@ public class JsonCoverter { @@ -18,4 +22,14 @@ public class JsonCoverter {
18 gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create(); 22 gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
19 return gson; 23 return gson;
20 } 24 }
  25 +
  26 + public static JSONObject convertToJSONObject(Object selectedItem) {
  27 + JSONObject jsonObject = null;
  28 + try {
  29 + jsonObject = new JSONObject(getConverter().toJson(selectedItem));
  30 + } catch (JSONException e) {
  31 + e.printStackTrace();
  32 + }
  33 + return jsonObject;
  34 + }
21 } 35 }
app/src/main/res/layout/activity_login.xml
@@ -38,9 +38,9 @@ @@ -38,9 +38,9 @@
38 android:layout_width="match_parent" 38 android:layout_width="match_parent"
39 android:layout_height="wrap_content" 39 android:layout_height="wrap_content"
40 android:hint="@string/prompt_username" 40 android:hint="@string/prompt_username"
41 - android:inputType="none"  
42 android:maxLines="1" 41 android:maxLines="1"
43 - android:singleLine="true" /> 42 + android:singleLine="true"
  43 + android:inputType="textNoSuggestions" />
44 44
45 </android.support.design.widget.TextInputLayout> 45 </android.support.design.widget.TextInputLayout>
46 46
app/src/main/res/layout/fragment_modify_personne.xml
@@ -41,7 +41,7 @@ @@ -41,7 +41,7 @@
41 style="?android:attr/progressBarStyle" 41 style="?android:attr/progressBarStyle"
42 android:layout_width="match_parent" 42 android:layout_width="match_parent"
43 android:layout_height="wrap_content" 43 android:layout_height="wrap_content"
44 - android:id="@+id/modify_consommation_progress_bar" 44 + android:id="@+id/modify_personne_progress_bar"
45 android:layout_gravity="center" 45 android:layout_gravity="center"
46 android:visibility="gone"/> 46 android:visibility="gone"/>
47 47