Commit 517f580efdbcaf0bf4077afb269bdd7635601110
1 parent
bda0317b
Can modify User
Showing
11 changed files
with
157 additions
and
102 deletions
Show diff stats
app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/MyEventRecyclerViewAdapter.java
... | ... | @@ -40,7 +40,7 @@ public class MyEventRecyclerViewAdapter extends RecyclerView.Adapter<MyEventRecy |
40 | 40 | public void onBindViewHolder(final ViewHolder holder, int position) { |
41 | 41 | holder.mItem = mEvents.get(position); |
42 | 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 | 44 | holder.mId = mEvents.get(position).getIdEvent(); |
45 | 45 | |
46 | 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 | 3 | import android.animation.Animator; |
4 | 4 | import android.animation.AnimatorListenerAdapter; |
5 | 5 | import android.annotation.TargetApi; |
6 | -import android.app.DownloadManager; | |
7 | 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 | 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 | 9 | import android.os.Build; |
21 | 10 | import android.os.Bundle; |
22 | -import android.provider.ContactsContract; | |
23 | -import android.text.TextUtils; | |
24 | 11 | import android.view.KeyEvent; |
25 | 12 | import android.view.View; |
26 | 13 | import android.view.View.OnClickListener; |
27 | 14 | import android.view.inputmethod.EditorInfo; |
28 | -import android.widget.ArrayAdapter; | |
29 | 15 | import android.widget.Button; |
30 | 16 | import android.widget.EditText; |
31 | 17 | import android.widget.TextView; |
32 | 18 | import android.widget.Toast; |
33 | 19 | |
34 | 20 | import com.android.volley.Request; |
35 | -import com.android.volley.RequestQueue; | |
36 | 21 | import com.android.volley.Response; |
37 | 22 | import com.android.volley.VolleyError; |
38 | 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 | 25 | import net.plil.clubinfo.etunicorn.R; |
47 | -import net.plil.clubinfo.etunicorn.data.Permission; | |
48 | -import net.plil.clubinfo.etunicorn.data.Personne; | |
49 | 26 | import net.plil.clubinfo.etunicorn.data.Session; |
50 | 27 | import net.plil.clubinfo.etunicorn.data.User; |
51 | 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 | 30 | import net.plil.clubinfo.etunicorn.utils.VolleyUtils; |
54 | 31 | |
55 | 32 | import org.json.JSONException; |
56 | 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 | 36 | * A login screen that offers login via email/password. |
67 | 37 | */ |
... | ... | @@ -183,12 +153,12 @@ public class LoginActivity extends AppCompatActivity { |
183 | 153 | JsonObjectRequest jsonObjectRequest = null; |
184 | 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 | 157 | @Override |
188 | 158 | public void onResponse(JSONObject response) { |
189 | 159 | showProgress(false); |
190 | 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 | 162 | intent.putExtra("session", s); |
193 | 163 | startActivity(intent); |
194 | 164 | } |
... | ... | @@ -196,7 +166,10 @@ public class LoginActivity extends AppCompatActivity { |
196 | 166 | @Override |
197 | 167 | public void onErrorResponse(VolleyError error) { |
198 | 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 | 59 | private Toolbar toolbar; |
60 | 60 | private AppBarLayout appBarLayout; |
61 | 61 | |
62 | - private Session s; | |
62 | + public static Session session; | |
63 | 63 | |
64 | 64 | NfcAdapter mAdapter; |
65 | 65 | PendingIntent mPendingIntent; |
... | ... | @@ -69,18 +69,18 @@ public class MainActivity extends AppCompatActivity |
69 | 69 | super.onCreate(savedInstanceState); |
70 | 70 | |
71 | 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 | 74 | nbPages = 5; |
75 | 75 | Action.CONSOMATION.setValue(2); |
76 | 76 | Action.EVENT.setValue(3); |
77 | 77 | Action.PERSONNE.setValue(4); |
78 | - } else if (s.getPersonne().getRole().getNom().equals("bde")){ | |
78 | + } else if (session.getPersonne().getRole().getNom().equals("bde")){ | |
79 | 79 | nbPages = 4; |
80 | 80 | Action.CONSOMATION.setValue(-1); |
81 | 81 | Action.EVENT.setValue(2); |
82 | 82 | Action.PERSONNE.setValue(3); |
83 | - } else if (s.getPersonne().getRole().getNom().equals("bar")){ | |
83 | + } else if (session.getPersonne().getRole().getNom().equals("bar")){ | |
84 | 84 | nbPages = 3; |
85 | 85 | Action.CONSOMATION.setValue(2); |
86 | 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<Consom |
42 | 42 | @Override |
43 | 43 | public void onBindViewHolder(final ViewHolder holder, int position) { |
44 | 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 | 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 | 49 | holder.mView.setOnClickListener(new View.OnClickListener() { |
50 | 50 | @Override | ... | ... |
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/CreatePersonne.java
... | ... | @@ -21,11 +21,14 @@ import android.widget.Toast; |
21 | 21 | import com.android.volley.Request; |
22 | 22 | import com.android.volley.Response; |
23 | 23 | import com.android.volley.VolleyError; |
24 | +import com.android.volley.toolbox.JsonArrayRequest; | |
24 | 25 | import com.android.volley.toolbox.JsonObjectRequest; |
25 | 26 | import com.google.gson.Gson; |
26 | 27 | |
27 | 28 | import net.plil.clubinfo.etunicorn.R; |
28 | 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 | 32 | import net.plil.clubinfo.etunicorn.utils.VolleyUtils; |
30 | 33 | |
31 | 34 | import org.json.JSONArray; |
... | ... | @@ -129,6 +132,7 @@ public class CreatePersonne extends DialogFragment { |
129 | 132 | @Override |
130 | 133 | public void onResponse(JSONObject response) { |
131 | 134 | mProgressBar.setVisibility(View.GONE); |
135 | + Toast.makeText(getContext(), response.toString(), Toast.LENGTH_LONG).show(); | |
132 | 136 | dismiss(); |
133 | 137 | } |
134 | 138 | }, new Response.ErrorListener() { |
... | ... | @@ -166,16 +170,13 @@ public class CreatePersonne extends DialogFragment { |
166 | 170 | } |
167 | 171 | |
168 | 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 | 174 | @Override |
171 | - public void onResponse(JSONObject response) { | |
172 | - JSONArray jsonArray = null; | |
175 | + public void onResponse(JSONArray response) { | |
173 | 176 | try { |
174 | - //TODO change this by the real name of the array | |
175 | - jsonArray = response.getJSONArray("roles"); | |
176 | 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 | 181 | adapterRole.notifyDataSetChanged(); |
181 | 182 | } catch (JSONException e) { |
... | ... | @@ -186,12 +187,15 @@ public class CreatePersonne extends DialogFragment { |
186 | 187 | }, new Response.ErrorListener() { |
187 | 188 | @Override |
188 | 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 | 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 | 18 | import android.widget.Spinner; |
19 | 19 | import android.widget.Toast; |
20 | 20 | |
21 | +import com.android.volley.AuthFailureError; | |
21 | 22 | import com.android.volley.Request; |
22 | 23 | import com.android.volley.Response; |
23 | 24 | import com.android.volley.VolleyError; |
25 | +import com.android.volley.toolbox.JsonArrayRequest; | |
24 | 26 | import com.android.volley.toolbox.JsonObjectRequest; |
25 | 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 | 32 | import net.plil.clubinfo.etunicorn.R; |
33 | +import net.plil.clubinfo.etunicorn.app.MainActivity; | |
28 | 34 | import net.plil.clubinfo.etunicorn.data.Personne; |
29 | 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 | 38 | import net.plil.clubinfo.etunicorn.utils.VolleyUtils; |
31 | 39 | |
32 | 40 | import org.json.JSONArray; |
... | ... | @@ -36,8 +44,10 @@ import org.json.JSONObject; |
36 | 44 | import java.text.SimpleDateFormat; |
37 | 45 | import java.util.ArrayList; |
38 | 46 | import java.util.Calendar; |
47 | +import java.util.HashMap; | |
39 | 48 | import java.util.List; |
40 | 49 | import java.util.Locale; |
50 | +import java.util.Map; | |
41 | 51 | |
42 | 52 | |
43 | 53 | public class ModifyPersonne extends DialogFragment { |
... | ... | @@ -81,10 +91,10 @@ public class ModifyPersonne extends DialogFragment { |
81 | 91 | mCarte = (EditText) view.findViewById(R.id.modify_personne_carte); |
82 | 92 | mNaissance = (Spinner) view.findViewById(R.id.modify_personne_naissance); |
83 | 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 | 99 | final Personne personne = (Personne) getArguments().getSerializable("personne"); |
90 | 100 | |
... | ... | @@ -98,7 +108,7 @@ public class ModifyPersonne extends DialogFragment { |
98 | 108 | mRole.setAdapter(adapterRole); |
99 | 109 | changeRolePossibility(); |
100 | 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 | 112 | SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.FRANCE); |
103 | 113 | if (personne.getNaissance() == null){ |
104 | 114 | arraySpinnerNaissance = new String[]{ |
... | ... | @@ -140,7 +150,7 @@ public class ModifyPersonne extends DialogFragment { |
140 | 150 | try { |
141 | 151 | jsonObject.put("carte", mCarte.getText().toString()); |
142 | 152 | jsonObject.put("login", mLogin.getText().toString()); |
143 | - jsonObject.put("role", mRole.getSelectedItem()); | |
153 | + jsonObject.put("role", JsonConverter.convertToJSONObject(mRole.getSelectedItem())); | |
144 | 154 | if (!mNaissance.getSelectedItem().equals(getString(R.string.modify_personne_hint_date))) |
145 | 155 | jsonObject.put("naissance", mNaissance.getSelectedItem().toString()); |
146 | 156 | } catch (JSONException e){ |
... | ... | @@ -150,19 +160,42 @@ public class ModifyPersonne extends DialogFragment { |
150 | 160 | @Override |
151 | 161 | public void onResponse(JSONObject response) { |
152 | 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 | 165 | dismiss(); |
155 | 166 | } |
156 | 167 | }, new Response.ErrorListener() { |
157 | 168 | @Override |
158 | 169 | public void onErrorResponse(VolleyError error) { |
159 | 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 | 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 | 199 | VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); |
167 | 200 | } |
168 | 201 | }); |
... | ... | @@ -211,16 +244,13 @@ public class ModifyPersonne extends DialogFragment { |
211 | 244 | } |
212 | 245 | |
213 | 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 | 248 | @Override |
216 | - public void onResponse(JSONObject response) { | |
217 | - JSONArray jsonArray = null; | |
249 | + public void onResponse(JSONArray response) { | |
218 | 250 | try { |
219 | - //TODO change this by the real name of the array | |
220 | - jsonArray = response.getJSONArray("roles"); | |
221 | 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 | 255 | adapterRole.notifyDataSetChanged(); |
226 | 256 | } catch (JSONException e) { |
... | ... | @@ -231,11 +261,14 @@ public class ModifyPersonne extends DialogFragment { |
231 | 261 | }, new Response.ErrorListener() { |
232 | 262 | @Override |
233 | 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 | 15 | import net.plil.clubinfo.etunicorn.R; |
16 | 16 | import net.plil.clubinfo.etunicorn.data.Personne; |
17 | 17 | |
18 | +import java.text.SimpleDateFormat; | |
18 | 19 | import java.util.Locale; |
19 | 20 | |
20 | 21 | /** |
... | ... | @@ -61,8 +62,9 @@ public class PersonOverviewFragment extends DialogFragment{ |
61 | 62 | assert personne != null; |
62 | 63 | mCarte.setText(personne.getCarte()); |
63 | 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 | 68 | mLogin.setText(personne.getLogin()); |
67 | 69 | |
68 | 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 | 8 | import android.view.LayoutInflater; |
9 | 9 | import android.view.View; |
10 | 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 | 19 | import net.plil.clubinfo.etunicorn.R; |
13 | 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 | 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 | 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 | 35 | * A fragment representing a list of Items. |
... | ... | @@ -28,6 +40,8 @@ import java.util.List; |
28 | 40 | public class PersonneFragment extends FragmentNFC { |
29 | 41 | |
30 | 42 | private OnListFragmentInteractionListener mListener; |
43 | + private ArrayList<Personne> personnes = new ArrayList<>(); | |
44 | + private RecyclerView.Adapter mAdapter; | |
31 | 45 | |
32 | 46 | /** |
33 | 47 | * Mandatory empty constructor for the fragment manager to instantiate the |
... | ... | @@ -54,27 +68,9 @@ public class PersonneFragment extends FragmentNFC { |
54 | 68 | Context context = view.getContext(); |
55 | 69 | RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.personne_list); |
56 | 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 | 74 | FloatingActionButton fAB = (FloatingActionButton) view.findViewById(R.id.personne_add); |
79 | 75 | fAB.setOnClickListener(new View.OnClickListener() { |
80 | 76 | @Override |
... | ... | @@ -105,6 +101,39 @@ public class PersonneFragment extends FragmentNFC { |
105 | 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 | 137 | @Override |
109 | 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 | 2 | |
3 | 3 | import com.google.gson.Gson; |
4 | 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 | 11 | * Created by badetitou on 05/02/2017. |
8 | 12 | */ |
9 | 13 | |
10 | -public class JsonCoverter { | |
14 | +public class JsonConverter { | |
11 | 15 | |
12 | 16 | private static Gson gson; |
13 | 17 | |
... | ... | @@ -18,4 +22,14 @@ public class JsonCoverter { |
18 | 22 | gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create(); |
19 | 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 | 38 | android:layout_width="match_parent" |
39 | 39 | android:layout_height="wrap_content" |
40 | 40 | android:hint="@string/prompt_username" |
41 | - android:inputType="none" | |
42 | 41 | android:maxLines="1" |
43 | - android:singleLine="true" /> | |
42 | + android:singleLine="true" | |
43 | + android:inputType="textNoSuggestions" /> | |
44 | 44 | |
45 | 45 | </android.support.design.widget.TextInputLayout> |
46 | 46 | ... | ... |
app/src/main/res/layout/fragment_modify_personne.xml
... | ... | @@ -41,7 +41,7 @@ |
41 | 41 | style="?android:attr/progressBarStyle" |
42 | 42 | android:layout_width="match_parent" |
43 | 43 | android:layout_height="wrap_content" |
44 | - android:id="@+id/modify_consommation_progress_bar" | |
44 | + android:id="@+id/modify_personne_progress_bar" | |
45 | 45 | android:layout_gravity="center" |
46 | 46 | android:visibility="gone"/> |
47 | 47 | ... | ... |