Commit 7f1ea45677c7e92e9fad506969a1c90de7449fa3

Authored by badetitou
1 parent db223567

Stabilité app + deco Personne

app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/CreateEvent.java
@@ -112,7 +112,7 @@ public class CreateEvent extends DialogFragment { @@ -112,7 +112,7 @@ public class CreateEvent extends DialogFragment {
112 } else { 112 } else {
113 mNameInput.setError(null); 113 mNameInput.setError(null);
114 } 114 }
115 - if (((String)mDate.getSelectedItem()).equals(getString(R.string.create_event_date))) { 115 + if ((mDate.getSelectedItem()).equals(getString(R.string.create_event_date))) {
116 testDateInputOk = false; 116 testDateInputOk = false;
117 Toast.makeText(getContext(), getString(R.string.error_create_event_date), Toast.LENGTH_LONG).show(); 117 Toast.makeText(getContext(), getString(R.string.error_create_event_date), Toast.LENGTH_LONG).show();
118 } 118 }
@@ -133,6 +133,7 @@ public class CreateEvent extends DialogFragment { @@ -133,6 +133,7 @@ public class CreateEvent extends DialogFragment {
133 @Override 133 @Override
134 public void onResponse(JSONObject response) { 134 public void onResponse(JSONObject response) {
135 mProgressBar.setVisibility(View.GONE); 135 mProgressBar.setVisibility(View.GONE);
  136 + dismiss();
136 } 137 }
137 }, new Response.ErrorListener() { 138 }, new Response.ErrorListener() {
138 @Override 139 @Override
app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/ModifyEvent.java
@@ -134,6 +134,7 @@ public class ModifyEvent extends DialogFragment { @@ -134,6 +134,7 @@ public class ModifyEvent extends DialogFragment {
134 public void onResponse(JSONObject response) { 134 public void onResponse(JSONObject response) {
135 mProgressBar.setVisibility(View.GONE); 135 mProgressBar.setVisibility(View.GONE);
136 Toast.makeText(getContext(), R.string.modify_done, Toast.LENGTH_LONG).show(); 136 Toast.makeText(getContext(), R.string.modify_done, Toast.LENGTH_LONG).show();
  137 + dismiss();
137 138
138 } 139 }
139 }, new Response.ErrorListener() { 140 }, new Response.ErrorListener() {
app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/PaiementEvent.java
@@ -56,7 +56,7 @@ public class PaiementEvent extends DialogFragment { @@ -56,7 +56,7 @@ public class PaiementEvent extends DialogFragment {
56 56
57 Event event = (Event) getArguments().getSerializable("event"); 57 Event event = (Event) getArguments().getSerializable("event");
58 mPaiementEventName.setText(event.getNomEvent()); 58 mPaiementEventName.setText(event.getNomEvent());
59 - mPaiementEventPrice.setText(String.format(Locale.FRANCE, "%.2f €", event.getPrice())); 59 + mPaiementEventPrice.setText(String.format(Locale.US, "%.2f €", event.getPrice()));
60 60
61 eventId = event.getIdEvent(); 61 eventId = event.getIdEvent();
62 62
@@ -96,7 +96,6 @@ public class PaiementEvent extends DialogFragment { @@ -96,7 +96,6 @@ public class PaiementEvent extends DialogFragment {
96 public void onErrorResponse(VolleyError error) { 96 public void onErrorResponse(VolleyError error) {
97 mProgressBar.setVisibility(View.GONE); 97 mProgressBar.setVisibility(View.GONE);
98 Toast.makeText(getContext(), R.string.payment_refused, Toast.LENGTH_LONG).show(); 98 Toast.makeText(getContext(), R.string.payment_refused, Toast.LENGTH_LONG).show();
99 - dismiss();  
100 } 99 }
101 } 100 }
102 ); 101 );
app/src/main/java/net/plil/clubinfo/etunicorn/app/credit/Crediter.java
@@ -96,7 +96,13 @@ public class Crediter extends FragmentNFC { @@ -96,7 +96,13 @@ public class Crediter extends FragmentNFC {
96 } 96 }
97 } 97 }
98 ); 98 );
99 - 99 + jsonObjectRequest.setTag(Crediter.class);
100 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); 100 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
101 } 101 }
  102 +
  103 + @Override
  104 + public void onStop() {
  105 + VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(Crediter.class);
  106 + super.onStop();
  107 + }
102 } 108 }
app/src/main/java/net/plil/clubinfo/etunicorn/app/debit/Debiter.java
@@ -104,7 +104,13 @@ public class Debiter extends FragmentNFC { @@ -104,7 +104,13 @@ public class Debiter extends FragmentNFC {
104 } 104 }
105 } 105 }
106 ); 106 );
107 - 107 + jsonObjectRequest.setTag(Debiter.class);
108 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); 108 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
109 } 109 }
  110 +
  111 + @Override
  112 + public void onStop() {
  113 + VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(Debiter.class);
  114 + super.onStop();
  115 + }
110 } 116 }
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/CreatePersonne.java
@@ -4,16 +4,19 @@ import android.app.DatePickerDialog; @@ -4,16 +4,19 @@ import android.app.DatePickerDialog;
4 import android.app.Dialog; 4 import android.app.Dialog;
5 import android.content.DialogInterface; 5 import android.content.DialogInterface;
6 import android.os.Bundle; 6 import android.os.Bundle;
  7 +import android.support.design.widget.TextInputLayout;
7 import android.support.v4.app.DialogFragment; 8 import android.support.v4.app.DialogFragment;
8 import android.support.v7.app.AlertDialog; 9 import android.support.v7.app.AlertDialog;
9 import android.view.LayoutInflater; 10 import android.view.LayoutInflater;
10 import android.view.MotionEvent; 11 import android.view.MotionEvent;
11 import android.view.View; 12 import android.view.View;
12 import android.widget.ArrayAdapter; 13 import android.widget.ArrayAdapter;
  14 +import android.widget.Button;
13 import android.widget.DatePicker; 15 import android.widget.DatePicker;
14 import android.widget.EditText; 16 import android.widget.EditText;
15 import android.widget.ProgressBar; 17 import android.widget.ProgressBar;
16 import android.widget.Spinner; 18 import android.widget.Spinner;
  19 +import android.widget.Toast;
17 20
18 import com.android.volley.Request; 21 import com.android.volley.Request;
19 import com.android.volley.Response; 22 import com.android.volley.Response;
@@ -29,6 +32,7 @@ import net.plil.clubinfo.etunicorn.utils.VolleyUtils; @@ -29,6 +32,7 @@ import net.plil.clubinfo.etunicorn.utils.VolleyUtils;
29 import org.json.JSONArray; 32 import org.json.JSONArray;
30 import org.json.JSONException; 33 import org.json.JSONException;
31 import org.json.JSONObject; 34 import org.json.JSONObject;
  35 +import org.w3c.dom.Text;
32 36
33 import java.text.SimpleDateFormat; 37 import java.text.SimpleDateFormat;
34 import java.util.ArrayList; 38 import java.util.ArrayList;
@@ -49,6 +53,9 @@ public class CreatePersonne extends DialogFragment { @@ -49,6 +53,9 @@ public class CreatePersonne extends DialogFragment {
49 private Spinner mRole; 53 private Spinner mRole;
50 private ProgressBar mProgressBar; 54 private ProgressBar mProgressBar;
51 55
  56 + TextInputLayout mLoginInput;
  57 + TextInputLayout mCarteInput;
  58 +
52 private String[] arraySpinnerNaissance; 59 private String[] arraySpinnerNaissance;
53 private ArrayAdapter<String> adapterNaissance; 60 private ArrayAdapter<String> adapterNaissance;
54 61
@@ -64,6 +71,8 @@ public class CreatePersonne extends DialogFragment { @@ -64,6 +71,8 @@ public class CreatePersonne extends DialogFragment {
64 View view = inflater.inflate(R.layout.fragment_create_personne, null); 71 View view = inflater.inflate(R.layout.fragment_create_personne, null);
65 mLogin = (EditText) view.findViewById(R.id.create_personne_login); 72 mLogin = (EditText) view.findViewById(R.id.create_personne_login);
66 mCarte = (EditText) view.findViewById(R.id.create_personne_carte); 73 mCarte = (EditText) view.findViewById(R.id.create_personne_carte);
  74 + mLoginInput = (TextInputLayout) view.findViewById(R.id.create_personne_login_input);
  75 + mCarteInput = (TextInputLayout) view.findViewById(R.id.create_personne_carte_input);
67 mRole = (Spinner) view.findViewById(R.id.create_personne_role); 76 mRole = (Spinner) view.findViewById(R.id.create_personne_role);
68 arraySpinnerRole = new ArrayList<>(); 77 arraySpinnerRole = new ArrayList<>();
69 Role r = new Role(); 78 Role r = new Role();
@@ -75,53 +84,73 @@ public class CreatePersonne extends DialogFragment { @@ -75,53 +84,73 @@ public class CreatePersonne extends DialogFragment {
75 changeRolePossibility(); 84 changeRolePossibility();
76 mNaissance = (Spinner) view.findViewById(R.id.create_personne_naissance); 85 mNaissance = (Spinner) view.findViewById(R.id.create_personne_naissance);
77 arraySpinnerNaissance = new String[] { 86 arraySpinnerNaissance = new String[] {
78 - "Date d'anniversaire" 87 + getString(R.string.create_personne_naissance)
79 }; 88 };
80 adapterNaissance = new ArrayAdapter<String>(getActivity(), 89 adapterNaissance = new ArrayAdapter<String>(getActivity(),
81 R.layout.simple_item_layout, arraySpinnerNaissance); 90 R.layout.simple_item_layout, arraySpinnerNaissance);
82 mNaissance.setAdapter(adapterNaissance); 91 mNaissance.setAdapter(adapterNaissance);
83 mProgressBar = (ProgressBar) view.findViewById(R.id.create_personne_progress_bar); 92 mProgressBar = (ProgressBar) view.findViewById(R.id.create_personne_progress_bar);
84 - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());  
85 - builder 93 + AlertDialog dialog = new AlertDialog.Builder(getActivity())
86 .setTitle(R.string.create_personne) 94 .setTitle(R.string.create_personne)
87 .setView(view) 95 .setView(view)
88 - .setPositiveButton(R.string.valid, new DialogInterface.OnClickListener() { 96 + .setPositiveButton(R.string.valid, null)
  97 + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
89 public void onClick(DialogInterface dialog, int id) { 98 public void onClick(DialogInterface dialog, int id) {
  99 + VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(CreatePersonne.class);
  100 + }
  101 + }).create();
90 102
91 - mProgressBar.setVisibility(View.VISIBLE);  
92 - mLogin.setVisibility(View.GONE);  
93 - mCarte.setVisibility(View.GONE);  
94 - mNaissance.setVisibility(View.GONE);  
95 - JSONObject jsonObject = new JSONObject();  
96 - try {  
97 - jsonObject.put("login", mLogin.getText().toString());  
98 - jsonObject.put("carte", mCarte.getText().toString());  
99 - jsonObject.put("role", mRole.getSelectedItem());  
100 - jsonObject.put("naissance", mNaissance.getSelectedItem());  
101 - } catch (JSONException e){  
102 - e.printStackTrace(); 103 + dialog.setOnShowListener(new DialogInterface.OnShowListener() {
  104 + @Override
  105 + public void onShow(final DialogInterface dialog) {
  106 + Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
  107 + button.setOnClickListener(new View.OnClickListener() {
  108 + @Override
  109 + public void onClick(View v) {
  110 + if (mLogin.getText().toString().isEmpty() && mCarte.getText().toString().isEmpty()){
  111 + mLogin.setError(getString(R.string.error_create_personne_login_carte));
  112 + mCarte.setError(getString(R.string.error_create_personne_login_carte));
103 } 113 }
104 - JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/personne" ,jsonObject , new Response.Listener<JSONObject>() {  
105 - @Override  
106 - public void onResponse(JSONObject response) {  
107 - mProgressBar.setVisibility(View.GONE); 114 + else {
  115 + mProgressBar.setVisibility(View.VISIBLE);
  116 + mLoginInput.setVisibility(View.GONE);
  117 + mCarteInput.setVisibility(View.GONE);
  118 + mNaissance.setVisibility(View.GONE);
  119 + mRole.setVisibility(View.GONE);
  120 + JSONObject jsonObject = new JSONObject();
  121 + try {
  122 + jsonObject.put("login", mLogin.getText().toString());
  123 + jsonObject.put("carte", mCarte.getText().toString());
  124 + jsonObject.put("role", mRole.getSelectedItem());
  125 + if (!mNaissance.getSelectedItem().equals(getString(R.string.create_personne_naissance)))
  126 + jsonObject.put("naissance", mNaissance.getSelectedItem());
  127 + } catch (JSONException e) {
  128 + e.printStackTrace();
108 } 129 }
109 - }, new Response.ErrorListener() {  
110 - @Override  
111 - public void onErrorResponse(VolleyError error) {  
112 - mProgressBar.setVisibility(View.GONE); 130 + JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/personne", jsonObject, new Response.Listener<JSONObject>() {
  131 + @Override
  132 + public void onResponse(JSONObject response) {
  133 + mProgressBar.setVisibility(View.GONE);
  134 + dismiss();
  135 + }
  136 + }, new Response.ErrorListener() {
  137 + @Override
  138 + public void onErrorResponse(VolleyError error) {
  139 + mProgressBar.setVisibility(View.GONE);
  140 + mLoginInput.setVisibility(View.VISIBLE);
  141 + mCarteInput.setVisibility(View.VISIBLE);
  142 + mNaissance.setVisibility(View.VISIBLE);
  143 + mRole.setVisibility(View.VISIBLE);
  144 + }
113 } 145 }
  146 + );
  147 + jsonObjectRequest.setTag(CreatePersonne.class);
  148 + VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
114 } 149 }
115 - );  
116 -  
117 - VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);  
118 - }  
119 - })  
120 - .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {  
121 - public void onClick(DialogInterface dialog, int id) {  
122 - // User cancelled the dialog  
123 } 150 }
124 }); 151 });
  152 + }
  153 + });
125 154
126 mNaissance.setOnTouchListener(new View.OnTouchListener() { 155 mNaissance.setOnTouchListener(new View.OnTouchListener() {
127 @Override 156 @Override
@@ -134,8 +163,8 @@ public class CreatePersonne extends DialogFragment { @@ -134,8 +163,8 @@ public class CreatePersonne extends DialogFragment {
134 return true; 163 return true;
135 } 164 }
136 }); 165 });
137 -  
138 - return builder.create(); 166 + dialog.setCanceledOnTouchOutside(false);
  167 + return dialog;
139 } 168 }
140 169
141 private void changeRolePossibility(){ 170 private void changeRolePossibility(){
@@ -155,16 +184,15 @@ public class CreatePersonne extends DialogFragment { @@ -155,16 +184,15 @@ public class CreatePersonne extends DialogFragment {
155 e.printStackTrace(); 184 e.printStackTrace();
156 } 185 }
157 186
158 -  
159 } 187 }
160 }, new Response.ErrorListener() { 188 }, new Response.ErrorListener() {
161 @Override 189 @Override
162 public void onErrorResponse(VolleyError error) { 190 public void onErrorResponse(VolleyError error) {
163 - 191 + Toast.makeText(getContext(), "Can't update role", Toast.LENGTH_LONG).show();
164 } 192 }
165 } 193 }
166 ); 194 );
167 - 195 + jsonObjectRequest.setTag(CreatePersonne.class);
168 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); 196 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
169 } 197 }
170 198
@@ -180,11 +208,17 @@ public class CreatePersonne extends DialogFragment { @@ -180,11 +208,17 @@ public class CreatePersonne extends DialogFragment {
180 } 208 }
181 }; 209 };
182 210
183 - private void updateLabel() {  
184 - String myFormat = "yyyy-MM-dd"; //In which you need put here  
185 - SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.FRANCE);  
186 - arraySpinnerNaissance[0] = sdf.format(myCalendar.getTime());  
187 - adapterNaissance.notifyDataSetChanged();  
188 - } 211 + private void updateLabel() {
  212 + String myFormat = "yyyy-MM-dd"; //In which you need put here
  213 + SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.FRANCE);
  214 + arraySpinnerNaissance[0] = sdf.format(myCalendar.getTime());
  215 + adapterNaissance.notifyDataSetChanged();
  216 + }
189 217
  218 + @Override
  219 + public void onStop() {
  220 + VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(CreatePersonne.class);
  221 + dismissAllowingStateLoss();
  222 + super.onStop();
  223 + }
190 } 224 }
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/DeletePersonne.java
@@ -7,6 +7,7 @@ import android.support.v4.app.DialogFragment; @@ -7,6 +7,7 @@ import android.support.v4.app.DialogFragment;
7 import android.support.v7.app.AlertDialog; 7 import android.support.v7.app.AlertDialog;
8 import android.view.LayoutInflater; 8 import android.view.LayoutInflater;
9 import android.view.View; 9 import android.view.View;
  10 +import android.widget.Button;
10 import android.widget.ProgressBar; 11 import android.widget.ProgressBar;
11 import android.widget.Toast; 12 import android.widget.Toast;
12 13
@@ -55,13 +56,23 @@ public class DeletePersonne extends DialogFragment { @@ -55,13 +56,23 @@ public class DeletePersonne extends DialogFragment {
55 final Personne personne = (Personne) getArguments().getSerializable("personne"); 56 final Personne personne = (Personne) getArguments().getSerializable("personne");
56 57
57 58
58 - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());  
59 - builder 59 + AlertDialog dialog = new AlertDialog.Builder(getActivity())
60 .setTitle(R.string.verif_delete_personne) 60 .setTitle(R.string.verif_delete_personne)
61 .setView(view) 61 .setView(view)
62 - .setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() { 62 + .setPositiveButton(R.string.delete, null)
  63 + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
  64 + public void onClick(DialogInterface dialog, int id) {
  65 + VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(DeletePersonne.class);
  66 + }
  67 + }).create();
  68 + dialog.setCanceledOnTouchOutside(false);
  69 + dialog.setOnShowListener(new DialogInterface.OnShowListener() {
  70 + @Override
  71 + public void onShow(DialogInterface dialog) {
  72 + Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
  73 + button.setOnClickListener(new View.OnClickListener() {
63 @Override 74 @Override
64 - public void onClick(DialogInterface dialog, int which) { 75 + public void onClick(View v) {
65 mProgressBar.setVisibility(View.VISIBLE); 76 mProgressBar.setVisibility(View.VISIBLE);
66 77
67 JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.DELETE, VolleyUtils.baseUri + "/personne/" + personne.getIdPersonne(), null, new Response.Listener<JSONObject>() { 78 JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.DELETE, VolleyUtils.baseUri + "/personne/" + personne.getIdPersonne(), null, new Response.Listener<JSONObject>() {
@@ -76,21 +87,23 @@ public class DeletePersonne extends DialogFragment { @@ -76,21 +87,23 @@ public class DeletePersonne extends DialogFragment {
76 public void onErrorResponse(VolleyError error) { 87 public void onErrorResponse(VolleyError error) {
77 mProgressBar.setVisibility(View.GONE); 88 mProgressBar.setVisibility(View.GONE);
78 Toast.makeText(getContext(), R.string.delete_refused, Toast.LENGTH_LONG).show(); 89 Toast.makeText(getContext(), R.string.delete_refused, Toast.LENGTH_LONG).show();
79 - dismiss();  
80 } 90 }
81 } 91 }
82 ); 92 );
83 - 93 + jsonObjectRequest.setTag(DeletePersonne.class);
84 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); 94 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
85 } 95 }
86 - })  
87 - .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {  
88 - public void onClick(DialogInterface dialog, int id) {  
89 -  
90 - }  
91 }); 96 });
92 - return builder.create(); 97 + }
  98 + });
  99 + return dialog;
93 } 100 }
94 101
  102 + @Override
  103 + public void onStop() {
  104 + VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(DeletePersonne.class);
  105 + dismissAllowingStateLoss();
  106 + super.onStop();
  107 + }
95 108
96 } 109 }
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/ModifyPersonne.java
1 package net.plil.clubinfo.etunicorn.app.personne; 1 package net.plil.clubinfo.etunicorn.app.personne;
2 2
  3 +import android.app.DatePickerDialog;
3 import android.app.Dialog; 4 import android.app.Dialog;
4 import android.content.DialogInterface; 5 import android.content.DialogInterface;
5 import android.os.Bundle; 6 import android.os.Bundle;
  7 +import android.support.design.widget.TextInputLayout;
6 import android.support.v4.app.DialogFragment; 8 import android.support.v4.app.DialogFragment;
7 import android.support.v7.app.AlertDialog; 9 import android.support.v7.app.AlertDialog;
8 import android.view.LayoutInflater; 10 import android.view.LayoutInflater;
  11 +import android.view.MotionEvent;
9 import android.view.View; 12 import android.view.View;
  13 +import android.widget.ArrayAdapter;
  14 +import android.widget.Button;
  15 +import android.widget.DatePicker;
10 import android.widget.EditText; 16 import android.widget.EditText;
11 import android.widget.ProgressBar; 17 import android.widget.ProgressBar;
  18 +import android.widget.Spinner;
12 import android.widget.Toast; 19 import android.widget.Toast;
13 20
14 import com.android.volley.Request; 21 import com.android.volley.Request;
15 import com.android.volley.Response; 22 import com.android.volley.Response;
16 import com.android.volley.VolleyError; 23 import com.android.volley.VolleyError;
17 import com.android.volley.toolbox.JsonObjectRequest; 24 import com.android.volley.toolbox.JsonObjectRequest;
  25 +import com.google.gson.Gson;
18 26
19 import net.plil.clubinfo.etunicorn.R; 27 import net.plil.clubinfo.etunicorn.R;
  28 +import net.plil.clubinfo.etunicorn.app.event.ModifyEvent;
20 import net.plil.clubinfo.etunicorn.data.Event; 29 import net.plil.clubinfo.etunicorn.data.Event;
21 import net.plil.clubinfo.etunicorn.data.Personne; 30 import net.plil.clubinfo.etunicorn.data.Personne;
  31 +import net.plil.clubinfo.etunicorn.data.Role;
22 import net.plil.clubinfo.etunicorn.utils.VolleyUtils; 32 import net.plil.clubinfo.etunicorn.utils.VolleyUtils;
23 33
  34 +import org.json.JSONArray;
24 import org.json.JSONException; 35 import org.json.JSONException;
25 import org.json.JSONObject; 36 import org.json.JSONObject;
26 37
  38 +import java.text.SimpleDateFormat;
  39 +import java.util.ArrayList;
  40 +import java.util.Calendar;
  41 +import java.util.List;
27 import java.util.Locale; 42 import java.util.Locale;
28 43
29 44
30 public class ModifyPersonne extends DialogFragment { 45 public class ModifyPersonne extends DialogFragment {
31 46
  47 + Calendar myCalendar = Calendar.getInstance();
  48 +
32 EditText mCarte; 49 EditText mCarte;
33 - EditText mNaissance; 50 + Spinner mNaissance;
34 EditText mLogin; 51 EditText mLogin;
35 - EditText mRole; 52 + Spinner mRole;
36 ProgressBar mProgressBar; 53 ProgressBar mProgressBar;
37 54
  55 + TextInputLayout mCarteInput;
  56 + TextInputLayout mLoginInput;
  57 +
  58 + private String[] arraySpinnerNaissance;
  59 + private ArrayAdapter<String> adapterNaissance;
  60 +
  61 + private List<Role> arraySpinnerRole;
  62 + private ArrayAdapter<Role> adapterRole;
  63 +
38 public static ModifyPersonne newInstance(Personne personne) { 64 public static ModifyPersonne newInstance(Personne personne) {
39 ModifyPersonne f = new ModifyPersonne(); 65 ModifyPersonne f = new ModifyPersonne();
40 66
@@ -49,49 +75,85 @@ public class ModifyPersonne extends DialogFragment { @@ -49,49 +75,85 @@ public class ModifyPersonne extends DialogFragment {
49 75
50 @Override 76 @Override
51 public Dialog onCreateDialog(Bundle savedInstanceState) { 77 public Dialog onCreateDialog(Bundle savedInstanceState) {
  78 + myCalendar.set(Calendar.YEAR, myCalendar.get(Calendar.YEAR)-18);
52 // Use the Builder class for convenient dialog construction 79 // Use the Builder class for convenient dialog construction
53 LayoutInflater inflater = getActivity().getLayoutInflater(); 80 LayoutInflater inflater = getActivity().getLayoutInflater();
54 View view = inflater.inflate(R.layout.fragment_modify_personne, null); 81 View view = inflater.inflate(R.layout.fragment_modify_personne, null);
55 mLogin = (EditText) view.findViewById(R.id.modify_personne_login); 82 mLogin = (EditText) view.findViewById(R.id.modify_personne_login);
56 mCarte = (EditText) view.findViewById(R.id.modify_personne_carte); 83 mCarte = (EditText) view.findViewById(R.id.modify_personne_carte);
57 - mNaissance = (EditText) view.findViewById(R.id.modify_personne_naissance);  
58 - mRole = (EditText) view.findViewById(R.id.modify_personne_role); 84 + mNaissance = (Spinner) view.findViewById(R.id.modify_personne_naissance);
  85 + mRole = (Spinner) view.findViewById(R.id.modify_personne_role);
59 mProgressBar = (ProgressBar) view.findViewById(R.id.modify_event_progress_bar); 86 mProgressBar = (ProgressBar) view.findViewById(R.id.modify_event_progress_bar);
60 87
  88 + mLoginInput = (TextInputLayout) view.findViewById(R.id.create_personne_login_input);
  89 + mCarteInput = (TextInputLayout) view.findViewById(R.id.create_personne_carte_input);
  90 +
61 final Personne personne = (Personne) getArguments().getSerializable("personne"); 91 final Personne personne = (Personne) getArguments().getSerializable("personne");
62 92
63 - mRole.setText(personne.getRole().getName());  
64 mCarte.setText(personne.getIdCarte()); 93 mCarte.setText(personne.getIdCarte());
65 mLogin.setText(personne.getLoginPoly()); 94 mLogin.setText(personne.getLoginPoly());
66 - mNaissance.setText(personne.getNaissance().toString());  
67 95
68 - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());  
69 - builder 96 + arraySpinnerRole = new ArrayList<>();
  97 + arraySpinnerRole.add(personne.getRole());
  98 + adapterRole = new ArrayAdapter<>(getActivity(),
  99 + R.layout.simple_item_layout, arraySpinnerRole);
  100 + mRole.setAdapter(adapterRole);
  101 + changeRolePossibility();
  102 + mNaissance = (Spinner) view.findViewById(R.id.modify_personne_naissance);
  103 + String myFormat = "yyyy-MM-dd"; //In which you need put here
  104 + SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.FRANCE);
  105 + if (personne.getNaissance() == null){
  106 + arraySpinnerNaissance = new String[]{
  107 + getString(R.string.modify_personne_hint_date)
  108 + };
  109 + } else {
  110 + arraySpinnerNaissance = new String[]{
  111 + sdf.format(personne.getNaissance())
  112 + };
  113 + }
  114 + adapterNaissance = new ArrayAdapter<String>(getActivity(),
  115 + R.layout.simple_item_layout, arraySpinnerNaissance);
  116 + mNaissance.setAdapter(adapterNaissance);
  117 +
  118 +
  119 + AlertDialog dialog = new AlertDialog.Builder(getActivity())
70 .setTitle(R.string.modify) 120 .setTitle(R.string.modify)
71 .setView(view) 121 .setView(view)
72 - .setPositiveButton(R.string.modify, new DialogInterface.OnClickListener() { 122 + .setPositiveButton(R.string.modify, null)
  123 + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
73 public void onClick(DialogInterface dialog, int id) { 124 public void onClick(DialogInterface dialog, int id) {
74 - 125 + VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(ModifyPersonne.class);
  126 + }
  127 + }).create();
  128 + // Create the AlertDialog object and return it
  129 + dialog.setOnShowListener(new DialogInterface.OnShowListener() {
  130 + @Override
  131 + public void onShow(DialogInterface dialog) {
  132 + Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
  133 + button.setOnClickListener(new View.OnClickListener() {
  134 + @Override
  135 + public void onClick(View v) {
75 mProgressBar.setVisibility(View.VISIBLE); 136 mProgressBar.setVisibility(View.VISIBLE);
76 mRole.setVisibility(View.GONE); 137 mRole.setVisibility(View.GONE);
77 - mLogin.setVisibility(View.GONE);  
78 - mCarte.setVisibility(View.GONE); 138 + mLoginInput.setVisibility(View.GONE);
  139 + mCarteInput.setVisibility(View.GONE);
79 mNaissance.setVisibility(View.GONE); 140 mNaissance.setVisibility(View.GONE);
80 JSONObject jsonObject = new JSONObject(); 141 JSONObject jsonObject = new JSONObject();
81 try { 142 try {
82 jsonObject.put("carte", mCarte.getText().toString()); 143 jsonObject.put("carte", mCarte.getText().toString());
83 jsonObject.put("login", mLogin.getText().toString()); 144 jsonObject.put("login", mLogin.getText().toString());
84 - jsonObject.put("role", mRole.getText().toString());  
85 - jsonObject.put("naissance", mNaissance.getText().toString()); 145 + jsonObject.put("role", mRole.getSelectedItem());
  146 + if (!mNaissance.getSelectedItem().equals(getString(R.string.modify_personne_hint_date)))
  147 + jsonObject.put("naissance", mNaissance.getSelectedItem().toString());
86 } catch (JSONException e){ 148 } catch (JSONException e){
87 e.printStackTrace(); 149 e.printStackTrace();
88 } 150 }
89 - JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/personne/" + personne.getIdPersonne() ,jsonObject , new Response.Listener<JSONObject>() { 151 + JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.PUT, VolleyUtils.baseUri + "/personne/" + personne.getIdPersonne() ,jsonObject , new Response.Listener<JSONObject>() {
90 @Override 152 @Override
91 public void onResponse(JSONObject response) { 153 public void onResponse(JSONObject response) {
92 mProgressBar.setVisibility(View.GONE); 154 mProgressBar.setVisibility(View.GONE);
93 Toast.makeText(getContext(), R.string.modify_done, Toast.LENGTH_LONG).show(); 155 Toast.makeText(getContext(), R.string.modify_done, Toast.LENGTH_LONG).show();
94 - 156 + dismiss();
95 } 157 }
96 }, new Response.ErrorListener() { 158 }, new Response.ErrorListener() {
97 @Override 159 @Override
@@ -102,18 +164,80 @@ public class ModifyPersonne extends DialogFragment { @@ -102,18 +164,80 @@ public class ModifyPersonne extends DialogFragment {
102 } 164 }
103 } 165 }
104 ); 166 );
105 - 167 + jsonObjectRequest.setTag(ModifyPersonne.class);
106 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); 168 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
107 } 169 }
108 - })  
109 - .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {  
110 - public void onClick(DialogInterface dialog, int id) {  
111 - // User cancelled the dialog  
112 - }  
113 }); 170 });
114 - // Create the AlertDialog object and return it  
115 - return builder.create(); 171 + }
  172 + });
  173 + mNaissance.setOnTouchListener(new View.OnTouchListener() {
  174 + @Override
  175 + public boolean onTouch(View v, MotionEvent event) {
  176 + if(event.getAction() == MotionEvent.ACTION_UP) {
  177 + new DatePickerDialog(getContext(), date, myCalendar
  178 + .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
  179 + myCalendar.get(Calendar.DAY_OF_MONTH)).show();
  180 + }
  181 + return true;
  182 + }
  183 + });
  184 + dialog.setCanceledOnTouchOutside(false);
  185 + return dialog;
  186 + }
  187 +
  188 + DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
  189 +
  190 + @Override
  191 + public void onDateSet(DatePicker view, int year, int monthOfYear,
  192 + int dayOfMonth) {
  193 + myCalendar.set(Calendar.YEAR, year);
  194 + myCalendar.set(Calendar.MONTH, monthOfYear);
  195 + myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
  196 + updateLabel();
  197 + }
  198 + };
  199 +
  200 + private void updateLabel() {
  201 + String myFormat = "yyyy-MM-dd"; //In which you need put here
  202 + SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.FRANCE);
  203 + arraySpinnerNaissance[0] = sdf.format(myCalendar.getTime());
  204 + adapterNaissance.notifyDataSetChanged();
116 } 205 }
117 206
118 207
  208 + @Override
  209 + public void onStop() {
  210 + VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(ModifyPersonne.class);
  211 + dismissAllowingStateLoss();
  212 + super.onStop();
  213 + }
  214 +
  215 + private void changeRolePossibility(){
  216 + JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, VolleyUtils.baseUri + "/role/" ,null , new Response.Listener<JSONObject>() {
  217 + @Override
  218 + public void onResponse(JSONObject response) {
  219 + JSONArray jsonArray = null;
  220 + try {
  221 + //TODO change this by the real name of the array
  222 + jsonArray = response.getJSONArray("roles");
  223 + arraySpinnerRole.clear();
  224 + for (int i =0; i<jsonArray.length();++i){
  225 + arraySpinnerRole.add(new Gson().fromJson(String.valueOf(jsonArray.getJSONObject(i)), Role.class));
  226 + }
  227 + adapterRole.notifyDataSetChanged();
  228 + } catch (JSONException e) {
  229 + e.printStackTrace();
  230 + }
  231 +
  232 + }
  233 + }, new Response.ErrorListener() {
  234 + @Override
  235 + public void onErrorResponse(VolleyError error) {
  236 + Toast.makeText(getContext(), "Can't update role", Toast.LENGTH_LONG).show();
  237 + }
  238 + }
  239 + );
  240 + jsonObjectRequest.setTag(ModifyPersonne.class);
  241 + VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
  242 + }
119 } 243 }
app/src/main/res/layout/fragment_create_personne.xml
@@ -7,17 +7,27 @@ @@ -7,17 +7,27 @@
7 android:layout_height="match_parent" 7 android:layout_height="match_parent"
8 > 8 >
9 9
10 - <EditText 10 + <android.support.design.widget.TextInputLayout
11 android:layout_width="match_parent" 11 android:layout_width="match_parent"
12 android:layout_height="wrap_content" 12 android:layout_height="wrap_content"
13 - android:id="@+id/create_personne_login"  
14 - android:hint="@string/create_personne_login"/>  
15 -  
16 - <EditText 13 + android:id="@+id/create_personne_login_input">
  14 + <android.support.design.widget.TextInputEditText
  15 + android:layout_width="match_parent"
  16 + android:layout_height="wrap_content"
  17 + android:id="@+id/create_personne_login"
  18 + android:hint="@string/create_personne_login"/>
  19 + </android.support.design.widget.TextInputLayout>
  20 +
  21 + <android.support.design.widget.TextInputLayout
17 android:layout_width="match_parent" 22 android:layout_width="match_parent"
18 android:layout_height="wrap_content" 23 android:layout_height="wrap_content"
19 - android:id="@+id/create_personne_carte"  
20 - android:hint="@string/create_personne_carte"/> 24 + android:id="@+id/create_personne_carte_input">
  25 + <android.support.design.widget.TextInputEditText
  26 + android:layout_width="match_parent"
  27 + android:layout_height="wrap_content"
  28 + android:id="@+id/create_personne_carte"
  29 + android:hint="@string/create_personne_carte"/>
  30 + </android.support.design.widget.TextInputLayout>
21 31
22 <Spinner 32 <Spinner
23 android:layout_width="match_parent" 33 android:layout_width="match_parent"
app/src/main/res/layout/fragment_modify_personne.xml
@@ -5,20 +5,34 @@ @@ -5,20 +5,34 @@
5 tools:context="net.plil.clubinfo.etunicorn.app.consommation.ModifyConsommation" 5 tools:context="net.plil.clubinfo.etunicorn.app.consommation.ModifyConsommation"
6 android:orientation="vertical"> 6 android:orientation="vertical">
7 7
8 - <EditText 8 + <android.support.design.widget.TextInputLayout
9 android:layout_width="match_parent" 9 android:layout_width="match_parent"
10 android:layout_height="wrap_content" 10 android:layout_height="wrap_content"
11 - android:id="@+id/modify_personne_carte" /> 11 + android:id="@+id/modify_personne_carte_input">
  12 + <android.support.design.widget.TextInputEditText
  13 + android:layout_width="match_parent"
  14 + android:layout_height="wrap_content"
  15 + android:id="@+id/modify_personne_carte"
  16 + android:hint="@string/modify_personne_hint_carte"/>
  17 + </android.support.design.widget.TextInputLayout>
12 18
13 - <EditText 19 + <android.support.design.widget.TextInputLayout
14 android:layout_width="match_parent" 20 android:layout_width="match_parent"
15 android:layout_height="wrap_content" 21 android:layout_height="wrap_content"
16 - android:id="@+id/modify_personne_login"/>  
17 - <EditText 22 + android:id="@+id/modify_personne_login_input">
  23 + <android.support.design.widget.TextInputEditText
  24 + android:layout_width="match_parent"
  25 + android:layout_height="wrap_content"
  26 + android:id="@+id/modify_personne_login"
  27 + android:hint="@string/modify_personne_hint_login"/>
  28 + </android.support.design.widget.TextInputLayout>
  29 +
  30 + <Spinner
18 android:layout_width="match_parent" 31 android:layout_width="match_parent"
19 android:layout_height="wrap_content" 32 android:layout_height="wrap_content"
20 android:id="@+id/modify_personne_role"/> 33 android:id="@+id/modify_personne_role"/>
21 - <EditText 34 +
  35 + <Spinner
22 android:layout_width="match_parent" 36 android:layout_width="match_parent"
23 android:layout_height="wrap_content" 37 android:layout_height="wrap_content"
24 android:id="@+id/modify_personne_naissance"/> 38 android:id="@+id/modify_personne_naissance"/>
app/src/main/res/values/strings.xml
@@ -54,4 +54,9 @@ @@ -54,4 +54,9 @@
54 <string name="error_create_event_date">Enter the date</string> 54 <string name="error_create_event_date">Enter the date</string>
55 <string name="modify_event_hint_name">Name</string> 55 <string name="modify_event_hint_name">Name</string>
56 <string name="modify_event_hint_price">Price</string> 56 <string name="modify_event_hint_price">Price</string>
  57 + <string name="modify_personne_hint_login">Login</string>
  58 + <string name="modify_personne_hint_carte">Card ID</string>
  59 + <string name="modify_personne_hint_date">Birthday</string>
  60 + <string name="error_create_personne_login">Need a login or a carte ID</string>
  61 + <string name="error_create_personne_login_carte">Need a login or a carte ID</string>
57 </resources> 62 </resources>