Commit c1841aa98d61a008f23cda6e5e1e6314a0016204
1 parent
517f580e
Can create Personne
Showing
2 changed files
with
27 additions
and
3 deletions
Show diff stats
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/CreatePersonne.java
@@ -18,6 +18,7 @@ import android.widget.ProgressBar; | @@ -18,6 +18,7 @@ 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; |
@@ -26,6 +27,7 @@ import com.android.volley.toolbox.JsonObjectRequest; | @@ -26,6 +27,7 @@ import com.android.volley.toolbox.JsonObjectRequest; | ||
26 | import com.google.gson.Gson; | 27 | import com.google.gson.Gson; |
27 | 28 | ||
28 | import net.plil.clubinfo.etunicorn.R; | 29 | import net.plil.clubinfo.etunicorn.R; |
30 | +import net.plil.clubinfo.etunicorn.app.MainActivity; | ||
29 | import net.plil.clubinfo.etunicorn.data.Role; | 31 | import net.plil.clubinfo.etunicorn.data.Role; |
30 | import net.plil.clubinfo.etunicorn.utils.ConvertBytesToString; | 32 | import net.plil.clubinfo.etunicorn.utils.ConvertBytesToString; |
31 | import net.plil.clubinfo.etunicorn.utils.JsonConverter; | 33 | import net.plil.clubinfo.etunicorn.utils.JsonConverter; |
@@ -38,8 +40,10 @@ import org.json.JSONObject; | @@ -38,8 +40,10 @@ import org.json.JSONObject; | ||
38 | import java.text.SimpleDateFormat; | 40 | import java.text.SimpleDateFormat; |
39 | import java.util.ArrayList; | 41 | import java.util.ArrayList; |
40 | import java.util.Calendar; | 42 | import java.util.Calendar; |
43 | +import java.util.HashMap; | ||
41 | import java.util.List; | 44 | import java.util.List; |
42 | import java.util.Locale; | 45 | import java.util.Locale; |
46 | +import java.util.Map; | ||
43 | 47 | ||
44 | 48 | ||
45 | public class CreatePersonne extends DialogFragment { | 49 | public class CreatePersonne extends DialogFragment { |
@@ -122,7 +126,7 @@ public class CreatePersonne extends DialogFragment { | @@ -122,7 +126,7 @@ public class CreatePersonne extends DialogFragment { | ||
122 | try { | 126 | try { |
123 | jsonObject.put("login", mLogin.getText().toString()); | 127 | jsonObject.put("login", mLogin.getText().toString()); |
124 | jsonObject.put("carte", mCarte.getText().toString()); | 128 | jsonObject.put("carte", mCarte.getText().toString()); |
125 | - jsonObject.put("role", mRole.getSelectedItem()); | 129 | + jsonObject.put("role", JsonConverter.convertToJSONObject(mRole.getSelectedItem())); |
126 | if (!mNaissance.getSelectedItem().equals(getString(R.string.create_personne_naissance))) | 130 | if (!mNaissance.getSelectedItem().equals(getString(R.string.create_personne_naissance))) |
127 | jsonObject.put("naissance", mNaissance.getSelectedItem()); | 131 | jsonObject.put("naissance", mNaissance.getSelectedItem()); |
128 | } catch (JSONException e) { | 132 | } catch (JSONException e) { |
@@ -143,9 +147,18 @@ public class CreatePersonne extends DialogFragment { | @@ -143,9 +147,18 @@ public class CreatePersonne extends DialogFragment { | ||
143 | mCarteInput.setVisibility(View.VISIBLE); | 147 | mCarteInput.setVisibility(View.VISIBLE); |
144 | mNaissance.setVisibility(View.VISIBLE); | 148 | mNaissance.setVisibility(View.VISIBLE); |
145 | mRole.setVisibility(View.VISIBLE); | 149 | mRole.setVisibility(View.VISIBLE); |
150 | + if (error.networkResponse != null) | ||
151 | + Toast.makeText(getContext(), ConvertBytesToString.bytesToStringVolLey(error.networkResponse.data), Toast.LENGTH_LONG).show(); | ||
146 | } | 152 | } |
147 | } | 153 | } |
148 | - ); | 154 | + ) |
155 | + { | ||
156 | + @Override | ||
157 | + public Map<String, String> getHeaders() throws AuthFailureError { | ||
158 | + Map<String, String> headers = new HashMap<String, String>(); | ||
159 | + headers.put("Authorization", MainActivity.session.getToken()); | ||
160 | + return headers; | ||
161 | + }}; | ||
149 | jsonObjectRequest.setTag(CreatePersonne.class); | 162 | jsonObjectRequest.setTag(CreatePersonne.class); |
150 | VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); | 163 | VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); |
151 | } | 164 | } |
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/DeletePersonne.java
@@ -11,18 +11,23 @@ import android.widget.Button; | @@ -11,18 +11,23 @@ import android.widget.Button; | ||
11 | import android.widget.ProgressBar; | 11 | import android.widget.ProgressBar; |
12 | import android.widget.Toast; | 12 | import android.widget.Toast; |
13 | 13 | ||
14 | +import com.android.volley.AuthFailureError; | ||
14 | import com.android.volley.Request; | 15 | import com.android.volley.Request; |
15 | import com.android.volley.Response; | 16 | import com.android.volley.Response; |
16 | import com.android.volley.VolleyError; | 17 | import com.android.volley.VolleyError; |
17 | import com.android.volley.toolbox.JsonObjectRequest; | 18 | import com.android.volley.toolbox.JsonObjectRequest; |
18 | 19 | ||
19 | import net.plil.clubinfo.etunicorn.R; | 20 | import net.plil.clubinfo.etunicorn.R; |
21 | +import net.plil.clubinfo.etunicorn.app.MainActivity; | ||
20 | import net.plil.clubinfo.etunicorn.data.Event; | 22 | import net.plil.clubinfo.etunicorn.data.Event; |
21 | import net.plil.clubinfo.etunicorn.data.Personne; | 23 | import net.plil.clubinfo.etunicorn.data.Personne; |
22 | import net.plil.clubinfo.etunicorn.utils.VolleyUtils; | 24 | import net.plil.clubinfo.etunicorn.utils.VolleyUtils; |
23 | 25 | ||
24 | import org.json.JSONObject; | 26 | import org.json.JSONObject; |
25 | 27 | ||
28 | +import java.util.HashMap; | ||
29 | +import java.util.Map; | ||
30 | + | ||
26 | 31 | ||
27 | public class DeletePersonne extends DialogFragment { | 32 | public class DeletePersonne extends DialogFragment { |
28 | 33 | ||
@@ -89,7 +94,13 @@ public class DeletePersonne extends DialogFragment { | @@ -89,7 +94,13 @@ public class DeletePersonne extends DialogFragment { | ||
89 | Toast.makeText(getContext(), R.string.delete_refused, Toast.LENGTH_LONG).show(); | 94 | Toast.makeText(getContext(), R.string.delete_refused, Toast.LENGTH_LONG).show(); |
90 | } | 95 | } |
91 | } | 96 | } |
92 | - ); | 97 | + ){ |
98 | + @Override | ||
99 | + public Map<String, String> getHeaders() throws AuthFailureError { | ||
100 | + Map<String, String> headers = new HashMap<String, String>(); | ||
101 | + headers.put("Authorization", MainActivity.session.getToken()); | ||
102 | + return headers; | ||
103 | + }}; | ||
93 | jsonObjectRequest.setTag(DeletePersonne.class); | 104 | jsonObjectRequest.setTag(DeletePersonne.class); |
94 | VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); | 105 | VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); |
95 | } | 106 | } |