Commit 3dc52ca94ce78bfcc520d867b5d995fe97144f6b

Authored by badetitou
1 parent b7f2b9a4

Cleaning code 2.0

Showing 24 changed files with 317 additions and 306 deletions   Show diff stats
.idea/inspectionProfiles/Project_Default.xml 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +<component name="InspectionProjectProfileManager">
  2 + <profile version="1.0">
  3 + <option name="myName" value="Project Default" />
  4 + <inspection_tool class="AndroidLintInflateParams" enabled="false" level="WARNING" enabled_by_default="false" />
  5 + <inspection_tool class="LoggerInitializedWithForeignClass" enabled="false" level="WARNING" enabled_by_default="false">
  6 + <option name="loggerClassName" value="org.apache.log4j.Logger,org.slf4j.LoggerFactory,org.apache.commons.logging.LogFactory,java.util.logging.Logger" />
  7 + <option name="loggerFactoryMethodName" value="getLogger,getLogger,getLog,getLogger" />
  8 + </inspection_tool>
  9 + </profile>
  10 +</component>
0 11 \ No newline at end of file
... ...
.idea/inspectionProfiles/profiles_settings.xml 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +<component name="InspectionProjectProfileManager">
  2 + <settings>
  3 + <option name="PROJECT_PROFILE" value="Project Default" />
  4 + <option name="USE_PROJECT_PROFILE" value="true" />
  5 + <version value="1.0" />
  6 + </settings>
  7 +</component>
0 8 \ No newline at end of file
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/CreateEvent.java
... ... @@ -4,6 +4,7 @@ import android.app.DatePickerDialog;
4 4 import android.app.Dialog;
5 5 import android.content.DialogInterface;
6 6 import android.os.Bundle;
  7 +import android.support.annotation.NonNull;
7 8 import android.support.design.widget.TextInputLayout;
8 9 import android.support.v4.app.DialogFragment;
9 10 import android.support.v7.app.AlertDialog;
... ... @@ -49,14 +50,23 @@ public class CreateEvent extends DialogFragment {
49 50  
50 51 TextInputLayout mPriceInput;
51 52 TextInputLayout mNameInput;
52   -
  53 + ProgressBar mProgressBar;
53 54 private String[] arraySpinnerDate;
54 55 private ArrayAdapter<String> adapterDate;
  56 + DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
55 57  
56   - ProgressBar mProgressBar;
57   -
  58 + @Override
  59 + public void onDateSet(DatePicker view, int year, int monthOfYear,
  60 + int dayOfMonth) {
  61 + myCalendar.set(Calendar.YEAR, year);
  62 + myCalendar.set(Calendar.MONTH, monthOfYear);
  63 + myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
  64 + updateLabel();
  65 + }
  66 + };
58 67  
59 68 @Override
  69 + @NonNull
60 70 public Dialog onCreateDialog(Bundle savedInstanceState) {
61 71 // Use the Builder class for convenient dialog construction
62 72 LayoutInflater inflater = getActivity().getLayoutInflater();
... ... @@ -66,7 +76,7 @@ public class CreateEvent extends DialogFragment {
66 76 mDate = (Spinner) view.findViewById(R.id.create_event_date);
67 77 mPriceInput = (TextInputLayout) view.findViewById(R.id.create_event_price_input);
68 78 mNameInput = (TextInputLayout) view.findViewById(R.id.create_event_name_input);
69   - arraySpinnerDate = new String[] {
  79 + arraySpinnerDate = new String[]{
70 80 getString(R.string.create_event_date_input)
71 81 };
72 82 adapterDate = new ArrayAdapter<>(getActivity(),
... ... @@ -87,7 +97,7 @@ public class CreateEvent extends DialogFragment {
87 97 mDate.setOnTouchListener(new View.OnTouchListener() {
88 98 @Override
89 99 public boolean onTouch(View v, MotionEvent event) {
90   - if(event.getAction() == MotionEvent.ACTION_UP) {
  100 + if (event.getAction() == MotionEvent.ACTION_UP) {
91 101 new DatePickerDialog(getContext(), date, myCalendar
92 102 .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
93 103 myCalendar.get(Calendar.DAY_OF_MONTH)).show();
... ... @@ -110,7 +120,7 @@ public class CreateEvent extends DialogFragment {
110 120 } else {
111 121 mPriceInput.setError(null);
112 122 }
113   - if (mName.getText().toString().isEmpty()){
  123 + if (mName.getText().toString().isEmpty()) {
114 124 mNameInput.setError(getString(R.string.error_create_event_input_nom));
115 125 testDateInputOk = false;
116 126 } else {
... ... @@ -130,10 +140,10 @@ public class CreateEvent extends DialogFragment {
130 140 jsonObject.put("nom", mName.getText().toString());
131 141 jsonObject.put("prix", Double.parseDouble(mPrice.getText().toString()));
132 142 jsonObject.put("date", mDate.getAdapter().getItem(0));
133   - } catch (JSONException e){
  143 + } catch (JSONException e) {
134 144 e.printStackTrace();
135 145 }
136   - JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/evenement" ,jsonObject , new Response.Listener<JSONObject>() {
  146 + JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/evenement", jsonObject, new Response.Listener<JSONObject>() {
137 147 @Override
138 148 public void onResponse(JSONObject response) {
139 149 mProgressBar.setVisibility(View.GONE);
... ... @@ -149,13 +159,14 @@ public class CreateEvent extends DialogFragment {
149 159 Toast.makeText(getContext(), error.getMessage(), Toast.LENGTH_LONG).show();
150 160 }
151 161 }
152   - ){
  162 + ) {
153 163 @Override
154 164 public Map<String, String> getHeaders() throws AuthFailureError {
155   - Map<String, String> headers = new HashMap<String, String>();
  165 + Map<String, String> headers = new HashMap<>();
156 166 headers.put("Authorization", MainActivity.session.getToken());
157 167 return headers;
158   - }};
  168 + }
  169 + };
159 170 jsonObjectRequest.setTag(CreateEvent.class);
160 171 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
161 172 }
... ... @@ -174,18 +185,6 @@ public class CreateEvent extends DialogFragment {
174 185 super.onStop();
175 186 }
176 187  
177   - DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
178   -
179   - @Override
180   - public void onDateSet(DatePicker view, int year, int monthOfYear,
181   - int dayOfMonth) {
182   - myCalendar.set(Calendar.YEAR, year);
183   - myCalendar.set(Calendar.MONTH, monthOfYear);
184   - myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
185   - updateLabel();
186   - }
187   - };
188   -
189 188 private void updateLabel() {
190 189 String myFormat = "yyyy-MM-dd"; //In which you need put here
191 190 SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.FRANCE);
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/DeleteEvent.java
... ... @@ -3,6 +3,7 @@ package net.plil.clubinfo.etunicorn.app.event;
3 3 import android.app.Dialog;
4 4 import android.content.DialogInterface;
5 5 import android.os.Bundle;
  6 +import android.support.annotation.NonNull;
6 7 import android.support.v4.app.DialogFragment;
7 8 import android.support.v7.app.AlertDialog;
8 9 import android.view.LayoutInflater;
... ... @@ -19,7 +20,6 @@ import com.android.volley.toolbox.JsonObjectRequest;
19 20  
20 21 import net.plil.clubinfo.etunicorn.R;
21 22 import net.plil.clubinfo.etunicorn.app.MainActivity;
22   -import net.plil.clubinfo.etunicorn.data.Consommation;
23 23 import net.plil.clubinfo.etunicorn.data.Event;
24 24 import net.plil.clubinfo.etunicorn.utils.VolleyUtils;
25 25  
... ... @@ -33,7 +33,8 @@ public class DeleteEvent extends DialogFragment {
33 33  
34 34 ProgressBar mProgressBar;
35 35  
36   - public DeleteEvent(){}
  36 + public DeleteEvent() {
  37 + }
37 38  
38 39 /**
39 40 * Create a new instance of MyDialogFragment, providing "num"
... ... @@ -52,13 +53,16 @@ public class DeleteEvent extends DialogFragment {
52 53  
53 54  
54 55 @Override
  56 + @NonNull
55 57 public Dialog onCreateDialog(Bundle savedInstanceState) {
56 58 // Use the Builder class for convenient dialog construction
57 59 LayoutInflater inflater = getActivity().getLayoutInflater();
58 60 View view = inflater.inflate(R.layout.fragment_delete_event, null);
59 61  
60 62 mProgressBar = (ProgressBar) view.findViewById(R.id.delete_event_progress_bar);
  63 +
61 64 final Event event = (Event) getArguments().getSerializable("evenement");
  65 + assert event != null;
62 66  
63 67  
64 68 AlertDialog dialog = new AlertDialog.Builder(getActivity())
... ... @@ -94,18 +98,20 @@ public class DeleteEvent extends DialogFragment {
94 98 Toast.makeText(getContext(), R.string.delete_refused, Toast.LENGTH_LONG).show();
95 99 }
96 100 }
97   - ){
  101 + ) {
98 102 @Override
99 103 public Map<String, String> getHeaders() throws AuthFailureError {
100   - Map<String, String> headers = new HashMap<String, String>();
  104 + Map<String, String> headers = new HashMap<>();
101 105 headers.put("Authorization", MainActivity.session.getToken());
102 106 return headers;
103   - }};
  107 + }
  108 + };
104 109 jsonObjectRequest.setTag(DeleteEvent.class);
105 110 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
106 111 }
107 112 });
108   - }});
  113 + }
  114 + });
109 115 return dialog;
110 116 }
111 117  
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/EventFragment.java
... ... @@ -54,7 +54,7 @@ public class EventFragment extends Fragment implements NFCSupport {
54 54 recyclerView.setLayoutManager(new LinearLayoutManager(context));
55 55  
56 56 List<Event> events = new ArrayList<>();
57   - for (int i = 0; i< 150; ++i) {
  57 + for (int i = 0; i < 150; ++i) {
58 58 Event ev = new Event();
59 59 ev.setNomEvent("Hello " + i);
60 60 ev.setPrice(15.52);
... ... @@ -96,10 +96,9 @@ public class EventFragment extends Fragment implements NFCSupport {
96 96 @Override
97 97 public void processNFC(String idCardUser) {
98 98 PaiementEvent paiementEvent = (PaiementEvent) getFragmentManager().findFragmentByTag("paiementEvent");
99   - if (paiementEvent == null){
  99 + if (paiementEvent == null) {
100 100 Toast.makeText(getContext(), R.string.payment_consumable_alert_no_selection, Toast.LENGTH_LONG).show();
101   - }
102   - else {
  101 + } else {
103 102 paiementEvent.processNFC(idCardUser);
104 103 }
105 104 }
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/ModifyEvent.java
... ... @@ -4,6 +4,7 @@ import android.app.DatePickerDialog;
4 4 import android.app.Dialog;
5 5 import android.content.DialogInterface;
6 6 import android.os.Bundle;
  7 +import android.support.annotation.NonNull;
7 8 import android.support.design.widget.TextInputLayout;
8 9 import android.support.v4.app.DialogFragment;
9 10 import android.support.v7.app.AlertDialog;
... ... @@ -42,16 +43,25 @@ import java.util.Map;
42 43 public class ModifyEvent extends DialogFragment {
43 44  
44 45 Calendar myCalendar = Calendar.getInstance();
45   - private String[] arraySpinnerDate;
46   - private ArrayAdapter<String> adapterDate;
47   -
48 46 EditText mNom;
49 47 EditText mPrice;
50 48 Spinner mDate;
51 49 ProgressBar mProgressBar;
52   -
53 50 TextInputLayout mNomInput;
54 51 TextInputLayout mPriceInput;
  52 + private String[] arraySpinnerDate;
  53 + private ArrayAdapter<String> adapterDate;
  54 + DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
  55 +
  56 + @Override
  57 + public void onDateSet(DatePicker view, int year, int monthOfYear,
  58 + int dayOfMonth) {
  59 + myCalendar.set(Calendar.YEAR, year);
  60 + myCalendar.set(Calendar.MONTH, monthOfYear);
  61 + myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
  62 + updateLabel();
  63 + }
  64 + };
55 65  
56 66 public static ModifyEvent newInstance(Event event) {
57 67 ModifyEvent f = new ModifyEvent();
... ... @@ -64,8 +74,8 @@ public class ModifyEvent extends DialogFragment {
64 74 return f;
65 75 }
66 76  
67   -
68 77 @Override
  78 + @NonNull
69 79 public Dialog onCreateDialog(Bundle savedInstanceState) {
70 80 // Use the Builder class for convenient dialog construction
71 81 LayoutInflater inflater = getActivity().getLayoutInflater();
... ... @@ -79,10 +89,11 @@ public class ModifyEvent extends DialogFragment {
79 89  
80 90  
81 91 final Event event = (Event) getArguments().getSerializable("event");
  92 + assert event != null;
82 93  
83 94 String myFormat = "yyyy-MM-dd"; //In which you need put here
84 95 SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.FRANCE);
85   - arraySpinnerDate = new String[] {
  96 + arraySpinnerDate = new String[]{
86 97 sdf.format(event.getDate().getTime())
87 98 };
88 99 adapterDate = new ArrayAdapter<>(getActivity(),
... ... @@ -90,7 +101,7 @@ public class ModifyEvent extends DialogFragment {
90 101 mDate.setAdapter(adapterDate);
91 102  
92 103 mNom.setText(event.getNomEvent());
93   - mPrice.setText(String.format(Locale.US, "%.2f", event.getPrice()));
  104 + mPrice.setText(String.format(Locale.US, "%.2f", event.getPrice()));
94 105  
95 106 AlertDialog dialog = new AlertDialog.Builder(getActivity())
96 107 .setTitle(R.string.modify)
... ... @@ -105,7 +116,7 @@ public class ModifyEvent extends DialogFragment {
105 116 mDate.setOnTouchListener(new View.OnTouchListener() {
106 117 @Override
107 118 public boolean onTouch(View v, MotionEvent event) {
108   - if(event.getAction() == MotionEvent.ACTION_UP) {
  119 + if (event.getAction() == MotionEvent.ACTION_UP) {
109 120 new DatePickerDialog(getContext(), date, myCalendar
110 121 .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
111 122 myCalendar.get(Calendar.DAY_OF_MONTH)).show();
... ... @@ -131,10 +142,10 @@ public class ModifyEvent extends DialogFragment {
131 142 if (!mPrice.getText().toString().isEmpty())
132 143 jsonObject.put("prix", Double.parseDouble(mPrice.getText().toString()));
133 144 jsonObject.put("date", mDate.getSelectedItem());
134   - } catch (JSONException e){
  145 + } catch (JSONException e) {
135 146 e.printStackTrace();
136 147 }
137   - JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/evenement/" + event.getIdEvent() ,jsonObject , new Response.Listener<JSONObject>() {
  148 + JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/evenement/" + event.getIdEvent(), jsonObject, new Response.Listener<JSONObject>() {
138 149 @Override
139 150 public void onResponse(JSONObject response) {
140 151 mProgressBar.setVisibility(View.GONE);
... ... @@ -153,13 +164,14 @@ public class ModifyEvent extends DialogFragment {
153 164  
154 165 }
155 166 }
156   - ){
  167 + ) {
157 168 @Override
158 169 public Map<String, String> getHeaders() throws AuthFailureError {
159   - Map<String, String> headers = new HashMap<String, String>();
  170 + Map<String, String> headers = new HashMap<>();
160 171 headers.put("Authorization", MainActivity.session.getToken());
161 172 return headers;
162   - }};
  173 + }
  174 + };
163 175 jsonObjectRequest.setTag(ModifyEvent.class);
164 176 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
165 177 }
... ... @@ -177,18 +189,6 @@ public class ModifyEvent extends DialogFragment {
177 189 super.onStop();
178 190 }
179 191  
180   - DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
181   -
182   - @Override
183   - public void onDateSet(DatePicker view, int year, int monthOfYear,
184   - int dayOfMonth) {
185   - myCalendar.set(Calendar.YEAR, year);
186   - myCalendar.set(Calendar.MONTH, monthOfYear);
187   - myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
188   - updateLabel();
189   - }
190   - };
191   -
192 192 private void updateLabel() {
193 193 String myFormat = "yyyy-MM-dd"; //In which you need put here
194 194 SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.FRANCE);
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/MyEventRecyclerViewAdapter.java
... ... @@ -17,13 +17,13 @@ import java.util.List;
17 17 import java.util.Locale;
18 18  
19 19  
20   -public class MyEventRecyclerViewAdapter extends RecyclerView.Adapter<MyEventRecyclerViewAdapter.ViewHolder> {
  20 +class MyEventRecyclerViewAdapter extends RecyclerView.Adapter<MyEventRecyclerViewAdapter.ViewHolder> {
21 21  
22 22 private final List<Event> mEvents;
23 23 private final EventFragment.OnListFragmentInteractionListener mListener;
24 24 private final Context context;
25 25  
26   - public MyEventRecyclerViewAdapter(List<Event> items, EventFragment.OnListFragmentInteractionListener listener, Context context) {
  26 + MyEventRecyclerViewAdapter(List<Event> items, EventFragment.OnListFragmentInteractionListener listener, Context context) {
27 27 mEvents = items;
28 28 mListener = listener;
29 29 this.context = context;
... ... @@ -89,13 +89,13 @@ public class MyEventRecyclerViewAdapter extends RecyclerView.Adapter&lt;MyEventRecy
89 89  
90 90 class ViewHolder extends RecyclerView.ViewHolder {
91 91 final View mView;
92   - int mId;
93 92 final TextView mContentView;
94 93 final TextView mPriceView;
95 94 final TextView mButtonView;
  95 + int mId;
96 96 Event mItem;
97 97  
98   - public ViewHolder(View view) {
  98 + ViewHolder(View view) {
99 99 super(view);
100 100 mView = view;
101 101 mContentView = (TextView) view.findViewById(R.id.event_name);
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/PaiementEvent.java
... ... @@ -3,6 +3,7 @@ package net.plil.clubinfo.etunicorn.app.event;
3 3 import android.app.Dialog;
4 4 import android.content.DialogInterface;
5 5 import android.os.Bundle;
  6 +import android.support.annotation.NonNull;
6 7 import android.support.v4.app.DialogFragment;
7 8 import android.support.v7.app.AlertDialog;
8 9 import android.view.LayoutInflater;
... ... @@ -38,7 +39,8 @@ public class PaiementEvent extends DialogFragment implements NFCSupport {
38 39 TextView mPaiementEventPrice;
39 40 int eventId;
40 41  
41   - public PaiementEvent(){}
  42 + public PaiementEvent() {
  43 + }
42 44  
43 45 public static PaiementEvent newInstance(Event event) {
44 46 PaiementEvent f = new PaiementEvent();
... ... @@ -50,6 +52,7 @@ public class PaiementEvent extends DialogFragment implements NFCSupport {
50 52  
51 53  
52 54 @Override
  55 + @NonNull
53 56 public Dialog onCreateDialog(Bundle savedInstanceState) {
54 57 // Use the Builder class for convenient dialog construction
55 58 LayoutInflater inflater = getActivity().getLayoutInflater();
... ... @@ -60,6 +63,8 @@ public class PaiementEvent extends DialogFragment implements NFCSupport {
60 63  
61 64  
62 65 Event event = (Event) getArguments().getSerializable("event");
  66 + assert event != null;
  67 +
63 68 mPaiementEventName.setText(event.getNomEvent());
64 69 mPaiementEventPrice.setText(String.format(Locale.US, "%.2f €", event.getPrice()));
65 70  
... ... @@ -74,7 +79,7 @@ public class PaiementEvent extends DialogFragment implements NFCSupport {
74 79 VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(PaiementEvent.class);
75 80 }
76 81 });
77   - Dialog dialog = builder.create();
  82 + Dialog dialog = builder.create();
78 83 dialog.setCanceledOnTouchOutside(false);
79 84 return dialog;
80 85 }
... ... @@ -103,20 +108,20 @@ public class PaiementEvent extends DialogFragment implements NFCSupport {
103 108 Toast.makeText(getContext(), R.string.payment_refused, Toast.LENGTH_LONG).show();
104 109 }
105 110 }
106   - ){
  111 + ) {
107 112 @Override
108 113 public Map<String, String> getHeaders() throws AuthFailureError {
109   - Map<String, String> headers = new HashMap<String, String>();
  114 + Map<String, String> headers = new HashMap<>();
110 115 headers.put("Authorization", MainActivity.session.getToken());
111 116 return headers;
112   - }};
  117 + }
  118 + };
113 119  
114 120 jsonObjectRequest.setTag(PaiementEvent.class);
115 121 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
116 122 }
117 123  
118 124  
119   -
120 125 @Override
121 126 public void onStop() {
122 127 VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll(PaiementEvent.class);
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/LoginActivity.java
... ... @@ -4,10 +4,9 @@ import android.animation.Animator;
4 4 import android.animation.AnimatorListenerAdapter;
5 5 import android.annotation.TargetApi;
6 6 import android.content.Intent;
7   -import android.support.v7.app.AppCompatActivity;
8   -
9 7 import android.os.Build;
10 8 import android.os.Bundle;
  9 +import android.support.v7.app.AppCompatActivity;
11 10 import android.view.KeyEvent;
12 11 import android.view.View;
13 12 import android.view.View.OnClickListener;
... ... @@ -37,16 +36,6 @@ import org.json.JSONObject;
37 36 */
38 37 public class LoginActivity extends AppCompatActivity {
39 38  
40   - /**
41   - * Id to identity READ_CONTACTS permission request.
42   - */
43   - private static final int REQUEST_READ_CONTACTS = 0;
44   -
45   - /**
46   - * Keep track of the login task to ensure we can cancel it if requested.
47   - */
48   -
49   - // UI references.
50 39 private EditText mUsernameView;
51 40 private EditText mPasswordView;
52 41 private View mProgressView;
... ... @@ -146,14 +135,14 @@ public class LoginActivity extends AppCompatActivity {
146 135 * @param username The username of the person
147 136 * @param password The password of the person
148 137 */
149   - private void tryLogin (String username, String password){
  138 + private void tryLogin(String username, String password) {
150 139 User user = new User();
151 140 user.setPassword(password);
152 141 user.setLogin(username);
153 142 JsonObjectRequest jsonObjectRequest = null;
154 143 try {
155 144  
156   - jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/login" , new JSONObject(JsonConverter.getConverter().toJson(user)), new Response.Listener<JSONObject>() {
  145 + jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/login", new JSONObject(JsonConverter.getConverter().toJson(user)), new Response.Listener<JSONObject>() {
157 146 @Override
158 147 public void onResponse(JSONObject response) {
159 148 showProgress(false);
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/MainActivity.java
... ... @@ -2,11 +2,9 @@ package net.plil.clubinfo.etunicorn.app;
2 2  
3 3 import android.app.PendingIntent;
4 4 import android.content.Intent;
5   -import android.net.Uri;
6 5 import android.nfc.NfcAdapter;
7 6 import android.nfc.Tag;
8 7 import android.os.Bundle;
9   -import android.support.design.widget.AppBarLayout;
10 8 import android.support.design.widget.TabLayout;
11 9 import android.support.v4.app.Fragment;
12 10 import android.support.v4.app.FragmentManager;
... ... @@ -18,12 +16,12 @@ import android.view.Menu;
18 16 import android.view.MenuItem;
19 17  
20 18 import net.plil.clubinfo.etunicorn.R;
  19 +import net.plil.clubinfo.etunicorn.app.consommation.FragmentConsommation;
  20 +import net.plil.clubinfo.etunicorn.app.consommation.PaiementConsommation;
21 21 import net.plil.clubinfo.etunicorn.app.credit.Crediter;
22 22 import net.plil.clubinfo.etunicorn.app.debit.Debiter;
23 23 import net.plil.clubinfo.etunicorn.app.event.EventFragment;
24 24 import net.plil.clubinfo.etunicorn.app.event.PaiementEvent;
25   -import net.plil.clubinfo.etunicorn.app.consommation.FragmentConsommation;
26   -import net.plil.clubinfo.etunicorn.app.consommation.PaiementConsommation;
27 25 import net.plil.clubinfo.etunicorn.app.personne.PersonOverviewFragment;
28 26 import net.plil.clubinfo.etunicorn.app.personne.PersonneFragment;
29 27 import net.plil.clubinfo.etunicorn.data.Consommation;
... ... @@ -36,9 +34,11 @@ import net.plil.clubinfo.etunicorn.utils.ConvertBytesToString;
36 34 public class MainActivity extends AppCompatActivity
37 35 implements FragmentConsommation.OnListFragmentInteractionListener,
38 36 EventFragment.OnListFragmentInteractionListener,
39   - PersonneFragment.OnListFragmentInteractionListener
40   -{
  37 + PersonneFragment.OnListFragmentInteractionListener {
41 38  
  39 + public static Session session;
  40 + NfcAdapter mAdapter;
  41 + PendingIntent mPendingIntent;
42 42 /**
43 43 * The {@link android.support.v4.view.PagerAdapter} that will provide
44 44 * fragments for each of the sections. We use a
... ... @@ -47,21 +47,11 @@ public class MainActivity extends AppCompatActivity
47 47 * may be best to switch to a
48 48 * {@link android.support.v4.app.FragmentStatePagerAdapter}.
49 49 */
50   - private SectionsPagerAdapter mSectionsPagerAdapter;
51   -
52 50 private int nbPages = 0;
53   -
54 51 /**
55 52 * The {@link ViewPager} that will host the section contents.
56 53 */
57 54 private ViewPager mViewPager;
58   - private Toolbar toolbar;
59   - private AppBarLayout appBarLayout;
60   -
61   - public static Session session;
62   -
63   - NfcAdapter mAdapter;
64   - PendingIntent mPendingIntent;
65 55  
66 56 @Override
67 57 protected void onCreate(Bundle savedInstanceState) {
... ... @@ -69,35 +59,37 @@ public class MainActivity extends AppCompatActivity
69 59  
70 60 Intent intent = this.getIntent();
71 61 session = (Session) intent.getSerializableExtra("session");
72   - if (session.getPersonne().getRole().getNom().equals("admin")){
73   - nbPages = 5;
74   - Action.CONSOMATION.setValue(2);
75   - Action.EVENT.setValue(3);
76   - Action.PERSONNE.setValue(4);
77   - } else if (session.getPersonne().getRole().getNom().equals("bde")){
78   - nbPages = 4;
79   - Action.CONSOMATION.setValue(-1);
80   - Action.EVENT.setValue(2);
81   - Action.PERSONNE.setValue(3);
82   - } else if (session.getPersonne().getRole().getNom().equals("bar")){
83   - nbPages = 3;
84   - Action.CONSOMATION.setValue(2);
85   - Action.EVENT.setValue(-1);
86   - Action.PERSONNE.setValue(-1);
87   - } else {
88   - nbPages = 2;
  62 + switch (session.getPersonne().getRole().getNom()) {
  63 + case "admin":
  64 + nbPages = 5;
  65 + Action.CONSOMATION.setValue(2);
  66 + Action.EVENT.setValue(3);
  67 + Action.PERSONNE.setValue(4);
  68 + break;
  69 + case "bde":
  70 + nbPages = 4;
  71 + Action.CONSOMATION.setValue(-1);
  72 + Action.EVENT.setValue(2);
  73 + Action.PERSONNE.setValue(3);
  74 + break;
  75 + case "bar":
  76 + nbPages = 3;
  77 + Action.CONSOMATION.setValue(2);
  78 + Action.EVENT.setValue(-1);
  79 + Action.PERSONNE.setValue(-1);
  80 + break;
  81 + default:
  82 + nbPages = 2;
89 83 }
90   -
91 84 // config other stuff
92 85 setContentView(R.layout.activity_main);
93 86  
94   - appBarLayout = (AppBarLayout) findViewById(R.id.appbar);
95   - toolbar = (Toolbar) findViewById(R.id.toolbar);
  87 + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
96 88 setSupportActionBar(toolbar);
97 89  
98 90 // Create the adapter that will return a fragment for each of the three
99 91 // primary sections of the activity.
100   - mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
  92 + SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
101 93  
102 94 // Set up the ViewPager with the sections adapter.
103 95 mViewPager = (ViewPager) findViewById(R.id.container);
... ... @@ -150,13 +142,13 @@ public class MainActivity extends AppCompatActivity
150 142 }
151 143  
152 144 @Override
153   - public void onResume(){
  145 + public void onResume() {
154 146 super.onResume();
155 147 mAdapter.enableForegroundDispatch(this, mPendingIntent, null, null);
156 148 }
157 149  
158 150 @Override
159   - public void onPause(){
  151 + public void onPause() {
160 152 super.onPause();
161 153 if (mAdapter != null) {
162 154 mAdapter.disableForegroundDispatch(this);
... ... @@ -183,13 +175,31 @@ public class MainActivity extends AppCompatActivity
183 175  
184 176 }
185 177  
  178 + private enum Action {
  179 + DEBITER(0), CREDITER(1), CONSOMATION(2), EVENT(3), PERSONNE(4);
  180 +
  181 + private int value;
  182 +
  183 + Action(int value) {
  184 + this.value = value;
  185 + }
  186 +
  187 + public int getValue() {
  188 + return value;
  189 + }
  190 +
  191 + public void setValue(int value) {
  192 + this.value = value;
  193 + }
  194 + }
  195 +
186 196 /**
187 197 * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
188 198 * one of the sections/tabs/pages.
189 199 */
190 200 public class SectionsPagerAdapter extends FragmentPagerAdapter {
191 201  
192   - public SectionsPagerAdapter(FragmentManager fm) {
  202 + SectionsPagerAdapter(FragmentManager fm) {
193 203 super(fm);
194 204 }
195 205  
... ... @@ -216,34 +226,17 @@ public class MainActivity extends AppCompatActivity
216 226  
217 227 @Override
218 228 public CharSequence getPageTitle(int position) {
219   - if(position == Action.DEBITER.getValue())
  229 + if (position == Action.DEBITER.getValue())
220 230 return "Debiter";
221 231 else if (position == Action.CREDITER.getValue())
222 232 return "Crediter";
223 233 else if (position == Action.CONSOMATION.getValue())
224 234 return "Consommation";
225   - else if(position == Action.EVENT.getValue())
  235 + else if (position == Action.EVENT.getValue())
226 236 return getString(R.string.event);
227   - else if(position == Action.PERSONNE.getValue())
  237 + else if (position == Action.PERSONNE.getValue())
228 238 return getString(R.string.personne);
229 239 return null;
230 240 }
231 241 }
232   -
233   - private enum Action {
234   - DEBITER(0), CREDITER(1), CONSOMATION(2), EVENT(3), PERSONNE(4);
235   -
236   - private int value;
237   - Action(int value) {
238   - this.value = value;
239   - }
240   -
241   - public int getValue() {
242   - return value;
243   - }
244   -
245   - public void setValue(int value) {
246   - this.value = value;
247   - }
248   - }
249 242 }
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/ConsommationRecyclerViewAdapter.java
1 1 package net.plil.clubinfo.etunicorn.app.consommation;
2 2  
3   -import android.app.Activity;
4 3 import android.content.Context;
5 4 import android.support.v7.app.AppCompatActivity;
6 5 import android.support.v7.widget.PopupMenu;
7 6 import android.support.v7.widget.RecyclerView;
8   -import android.view.ContextMenu;
9 7 import android.view.LayoutInflater;
10 8 import android.view.MenuItem;
11 9 import android.view.View;
... ... @@ -19,13 +17,13 @@ import java.util.List;
19 17 import java.util.Locale;
20 18  
21 19  
22   -public class ConsommationRecyclerViewAdapter extends RecyclerView.Adapter<ConsommationRecyclerViewAdapter.ViewHolder> {
  20 +class ConsommationRecyclerViewAdapter extends RecyclerView.Adapter<ConsommationRecyclerViewAdapter.ViewHolder> {
23 21  
24 22 private final List<Consommation> mValues;
25 23 private final FragmentConsommation.OnListFragmentInteractionListener mListener;
26 24 private final Context context;
27 25  
28   - public ConsommationRecyclerViewAdapter(List<Consommation> items, FragmentConsommation.OnListFragmentInteractionListener listener, Context context) {
  26 + ConsommationRecyclerViewAdapter(List<Consommation> items, FragmentConsommation.OnListFragmentInteractionListener listener, Context context) {
29 27 mValues = items;
30 28 mListener = listener;
31 29 this.context = context;
... ... @@ -44,7 +42,7 @@ public class ConsommationRecyclerViewAdapter extends RecyclerView.Adapter&lt;Consom
44 42 holder.mItem = mValues.get(position);
45 43 holder.mIdView.setText(String.format(Locale.US, "%d", mValues.get(position).getIdConsomation()));
46 44 holder.mContentView.setText(mValues.get(position).getNomConsomation());
47   - holder.mPriceView.setText(String.format(Locale.US, "%.2f",mValues.get(position).getPrix()));
  45 + holder.mPriceView.setText(String.format(Locale.US, "%.2f", mValues.get(position).getPrix()));
48 46  
49 47 holder.mView.setOnClickListener(new View.OnClickListener() {
50 48 @Override
... ... @@ -89,15 +87,15 @@ public class ConsommationRecyclerViewAdapter extends RecyclerView.Adapter&lt;Consom
89 87 return mValues.size();
90 88 }
91 89  
92   - public class ViewHolder extends RecyclerView.ViewHolder {
93   - public final View mView;
94   - public final TextView mIdView;
95   - public final TextView mContentView;
96   - public final TextView mPriceView;
97   - public final TextView mButtonMenu;
98   - public Consommation mItem;
  90 + class ViewHolder extends RecyclerView.ViewHolder {
  91 + final View mView;
  92 + final TextView mIdView;
  93 + final TextView mContentView;
  94 + final TextView mPriceView;
  95 + final TextView mButtonMenu;
  96 + Consommation mItem;
99 97  
100   - public ViewHolder(View view) {
  98 + ViewHolder(View view) {
101 99 super(view);
102 100 mView = view;
103 101 mIdView = (TextView) view.findViewById(R.id.consomation_id);
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/CreateConsommation.java
... ... @@ -3,11 +3,10 @@ package net.plil.clubinfo.etunicorn.app.consommation;
3 3 import android.app.Dialog;
4 4 import android.content.DialogInterface;
5 5 import android.os.Bundle;
  6 +import android.support.annotation.NonNull;
6 7 import android.support.design.widget.TextInputLayout;
7 8 import android.support.v4.app.DialogFragment;
8 9 import android.support.v7.app.AlertDialog;
9   -import android.text.Editable;
10   -import android.text.TextWatcher;
11 10 import android.view.LayoutInflater;
12 11 import android.view.View;
13 12 import android.widget.Button;
... ... @@ -41,6 +40,7 @@ public class CreateConsommation extends DialogFragment {
41 40  
42 41  
43 42 @Override
  43 + @NonNull
44 44 public Dialog onCreateDialog(Bundle savedInstanceState) {
45 45 // Use the Builder class for convenient dialog construction
46 46 LayoutInflater inflater = getActivity().getLayoutInflater();
... ... @@ -75,7 +75,7 @@ public class CreateConsommation extends DialogFragment {
75 75 } else {
76 76 mPriceInput.setError(null);
77 77 }
78   - if (mNomConsomation.getText().toString().isEmpty()){
  78 + if (mNomConsomation.getText().toString().isEmpty()) {
79 79 mNomInput.setError(getString(R.string.error_create_consomation_input_nom));
80 80 testDateInputOk = false;
81 81 } else {
... ... @@ -107,13 +107,14 @@ public class CreateConsommation extends DialogFragment {
107 107 dismiss();
108 108 }
109 109 }
110   - ){
  110 + ) {
111 111 @Override
112 112 public Map<String, String> getHeaders() throws AuthFailureError {
113   - Map<String, String> headers = new HashMap<String, String>();
  113 + Map<String, String> headers = new HashMap<>();
114 114 headers.put("Authorization", MainActivity.session.getToken());
115 115 return headers;
116   - }};
  116 + }
  117 + };
117 118 jsonObjectRequest.setTag(CreateConsommation.class);
118 119 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
119 120 }
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/DeleteConsommation.java
... ... @@ -3,13 +3,13 @@ package net.plil.clubinfo.etunicorn.app.consommation;
3 3 import android.app.Dialog;
4 4 import android.content.DialogInterface;
5 5 import android.os.Bundle;
  6 +import android.support.annotation.NonNull;
6 7 import android.support.v4.app.DialogFragment;
7 8 import android.support.v7.app.AlertDialog;
8 9 import android.view.LayoutInflater;
9 10 import android.view.View;
10 11 import android.widget.Button;
11 12 import android.widget.ProgressBar;
12   -import android.widget.TextView;
13 13 import android.widget.Toast;
14 14  
15 15 import com.android.volley.AuthFailureError;
... ... @@ -23,11 +23,9 @@ import net.plil.clubinfo.etunicorn.app.MainActivity;
23 23 import net.plil.clubinfo.etunicorn.data.Consommation;
24 24 import net.plil.clubinfo.etunicorn.utils.VolleyUtils;
25 25  
26   -import org.json.JSONException;
27 26 import org.json.JSONObject;
28 27  
29 28 import java.util.HashMap;
30   -import java.util.Locale;
31 29 import java.util.Map;
32 30  
33 31  
... ... @@ -35,7 +33,8 @@ public class DeleteConsommation extends DialogFragment {
35 33  
36 34 ProgressBar mProgressBar;
37 35  
38   - public DeleteConsommation(){}
  36 + public DeleteConsommation() {
  37 + }
39 38  
40 39 /**
41 40 * Create a new instance of MyDialogFragment, providing "num"
... ... @@ -54,13 +53,16 @@ public class DeleteConsommation extends DialogFragment {
54 53  
55 54  
56 55 @Override
  56 + @NonNull
57 57 public Dialog onCreateDialog(Bundle savedInstanceState) {
58 58 // Use the Builder class for convenient dialog construction
59 59 LayoutInflater inflater = getActivity().getLayoutInflater();
60 60 View view = inflater.inflate(R.layout.fragment_delete_consomation, null);
61 61  
62 62 mProgressBar = (ProgressBar) view.findViewById(R.id.delete_consommation_progress_bar);
  63 +
63 64 final Consommation consommation = (Consommation) getArguments().getSerializable("consommation");
  65 + assert consommation != null;
64 66  
65 67  
66 68 AlertDialog dialog = new AlertDialog.Builder(getActivity())
... ... @@ -94,13 +96,14 @@ public class DeleteConsommation extends DialogFragment {
94 96 Toast.makeText(getContext(), R.string.delete_refused, Toast.LENGTH_LONG).show();
95 97 }
96 98 }
97   - ){
  99 + ) {
98 100 @Override
99 101 public Map<String, String> getHeaders() throws AuthFailureError {
100   - Map<String, String> headers = new HashMap<String, String>();
  102 + Map<String, String> headers = new HashMap<>();
101 103 headers.put("Authorization", MainActivity.session.getToken());
102 104 return headers;
103   - }};
  105 + }
  106 + };
104 107 jsonObjectRequest.setTag(DeleteConsommation.class);
105 108 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
106 109 }
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/FragmentConsommation.java
... ... @@ -60,14 +60,14 @@ public class FragmentConsommation extends Fragment implements NFCSupport {
60 60 c1.setNomConsomation("Hello");
61 61 c1.setPrix(12.5);
62 62 consommationList.add(c1);
63   - for (int i = 0; i< 100; ++i){
  63 + for (int i = 0; i < 100; ++i) {
64 64 c1 = new Consommation();
65 65 c1.setIdConsomation(i);
66 66 c1.setNomConsomation("World");
67 67 c1.setPrix(42.407);
68 68 consommationList.add(c1);
69 69 }
70   - recyclerView.setAdapter(new ConsommationRecyclerViewAdapter(consommationList, mListener, this.getActivity()));
  70 + recyclerView.setAdapter(new ConsommationRecyclerViewAdapter(consommationList, mListener, this.getActivity()));
71 71  
72 72 FloatingActionButton fAB = (FloatingActionButton) view.findViewById(R.id.consomation_add);
73 73 fAB.setOnClickListener(new View.OnClickListener() {
... ... @@ -102,10 +102,9 @@ public class FragmentConsommation extends Fragment implements NFCSupport {
102 102 @Override
103 103 public void processNFC(String idCardUser) {
104 104 PaiementConsommation paiementConsommation = (PaiementConsommation) getFragmentManager().findFragmentByTag("paiementConsommation");
105   - if (paiementConsommation == null){
  105 + if (paiementConsommation == null) {
106 106 Toast.makeText(getContext(), R.string.payment_consumable_alert_no_selection, Toast.LENGTH_LONG).show();
107   - }
108   - else {
  107 + } else {
109 108 paiementConsommation.processNFC(idCardUser);
110 109 }
111 110 }
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/ModifyConsommation.java
... ... @@ -3,6 +3,7 @@ package net.plil.clubinfo.etunicorn.app.consommation;
3 3 import android.app.Dialog;
4 4 import android.content.DialogInterface;
5 5 import android.os.Bundle;
  6 +import android.support.annotation.NonNull;
6 7 import android.support.design.widget.TextInputLayout;
7 8 import android.support.v4.app.DialogFragment;
8 9 import android.support.v7.app.AlertDialog;
... ... @@ -53,6 +54,7 @@ public class ModifyConsommation extends DialogFragment {
53 54  
54 55  
55 56 @Override
  57 + @NonNull
56 58 public Dialog onCreateDialog(Bundle savedInstanceState) {
57 59 // Use the Builder class for convenient dialog construction
58 60 final LayoutInflater inflater = getActivity().getLayoutInflater();
... ... @@ -64,9 +66,10 @@ public class ModifyConsommation extends DialogFragment {
64 66 mPriceInput = (TextInputLayout) view.findViewById(R.id.modify_consommation_input_price);
65 67  
66 68 final Consommation consommation = (Consommation) getArguments().getSerializable("consommation");
  69 + assert consommation != null;
67 70  
68 71 mNomConsomation.setText(consommation.getNomConsomation());
69   - mPrice.setText(String.format(Locale.US,"%.2f", consommation.getPrix()));
  72 + mPrice.setText(String.format(Locale.US, "%.2f", consommation.getPrix()));
70 73  
71 74 AlertDialog dialog = new AlertDialog.Builder(getActivity())
72 75 .setTitle(R.string.modify)
... ... @@ -87,13 +90,13 @@ public class ModifyConsommation extends DialogFragment {
87 90 @Override
88 91 public void onClick(View v) {
89 92 boolean inputOk = true;
90   - if (mPrice.getText().toString().isEmpty()){
  93 + if (mPrice.getText().toString().isEmpty()) {
91 94 inputOk = false;
92 95 mPriceInput.setError(getString(R.string.error_modify_consommation_input_price));
93 96 } else {
94 97 mPriceInput.setError(null);
95 98 }
96   - if (mNomConsomation.getText().toString().isEmpty()){
  99 + if (mNomConsomation.getText().toString().isEmpty()) {
97 100 inputOk = false;
98 101 mNomInput.setError(getString(R.string.error_modify_consommation_input_nom));
99 102 } else {
... ... @@ -125,19 +128,21 @@ public class ModifyConsommation extends DialogFragment {
125 128 Toast.makeText(getContext(), R.string.modify_refused, Toast.LENGTH_LONG).show();
126 129 }
127 130 }
128   - ){
  131 + ) {
129 132 @Override
130 133 public Map<String, String> getHeaders() throws AuthFailureError {
131   - Map<String, String> headers = new HashMap<String, String>();
  134 + Map<String, String> headers = new HashMap<>();
132 135 headers.put("Authorization", MainActivity.session.getToken());
133 136 return headers;
134   - }};
  137 + }
  138 + };
135 139 jsonObjectRequest.setTag(ModifyConsommation.class);
136 140 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
137 141 }
138 142 }
139 143 });
140   - }});
  144 + }
  145 + });
141 146 dialog.setCanceledOnTouchOutside(false);
142 147 return dialog;
143 148 }
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/PaiementConsommation.java
... ... @@ -3,9 +3,9 @@ package net.plil.clubinfo.etunicorn.app.consommation;
3 3 import android.app.Dialog;
4 4 import android.content.DialogInterface;
5 5 import android.os.Bundle;
  6 +import android.support.annotation.NonNull;
6 7 import android.support.v4.app.DialogFragment;
7 8 import android.support.v7.app.AlertDialog;
8   -import android.view.KeyEvent;
9 9 import android.view.LayoutInflater;
10 10 import android.view.View;
11 11 import android.widget.ProgressBar;
... ... @@ -21,7 +21,6 @@ import com.android.volley.toolbox.JsonObjectRequest;
21 21 import net.plil.clubinfo.etunicorn.R;
22 22 import net.plil.clubinfo.etunicorn.app.MainActivity;
23 23 import net.plil.clubinfo.etunicorn.app.NFCSupport;
24   -import net.plil.clubinfo.etunicorn.app.event.PaiementEvent;
25 24 import net.plil.clubinfo.etunicorn.data.Consommation;
26 25 import net.plil.clubinfo.etunicorn.utils.VolleyUtils;
27 26  
... ... @@ -40,7 +39,8 @@ public class PaiementConsommation extends DialogFragment implements NFCSupport {
40 39 TextView mPaiementConsommationPrice;
41 40 int consommationId;
42 41  
43   - public PaiementConsommation(){}
  42 + public PaiementConsommation() {
  43 + }
44 44  
45 45 /**
46 46 * Create a new instance of MyDialogFragment, providing "num"
... ... @@ -57,6 +57,7 @@ public class PaiementConsommation extends DialogFragment implements NFCSupport {
57 57  
58 58  
59 59 @Override
  60 + @NonNull
60 61 public Dialog onCreateDialog(Bundle savedInstanceState) {
61 62 // Use the Builder class for convenient dialog construction
62 63 LayoutInflater inflater = getActivity().getLayoutInflater();
... ... @@ -67,6 +68,8 @@ public class PaiementConsommation extends DialogFragment implements NFCSupport {
67 68  
68 69  
69 70 Consommation consommation = (Consommation) getArguments().getSerializable("consommation");
  71 + assert consommation != null;
  72 +
70 73 mPaiementConsommationName.setText(consommation.getNomConsomation());
71 74 mPaiementConsommationPrice.setText(String.format(Locale.FRANCE, "%.2f €", consommation.getPrix()));
72 75  
... ... @@ -82,7 +85,7 @@ public class PaiementConsommation extends DialogFragment implements NFCSupport {
82 85 }
83 86 });
84 87  
85   - Dialog dialog = builder.create();
  88 + Dialog dialog = builder.create();
86 89 dialog.setCanceledOnTouchOutside(false);
87 90 return dialog;
88 91 }
... ... @@ -112,13 +115,14 @@ public class PaiementConsommation extends DialogFragment implements NFCSupport {
112 115 Toast.makeText(getContext(), R.string.payment_refused, Toast.LENGTH_LONG).show();
113 116 }
114 117 }
115   - ){
  118 + ) {
116 119 @Override
117 120 public Map<String, String> getHeaders() throws AuthFailureError {
118   - Map<String, String> headers = new HashMap<String, String>();
  121 + Map<String, String> headers = new HashMap<>();
119 122 headers.put("Authorization", MainActivity.session.getToken());
120 123 return headers;
121   - }};
  124 + }
  125 + };
122 126 jsonObjectRequest.setTag(PaiementConsommation.class);
123 127 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
124 128 }
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/credit/Crediter.java
... ... @@ -29,7 +29,7 @@ import org.json.JSONObject;
29 29 import java.util.HashMap;
30 30 import java.util.Map;
31 31  
32   -public class Crediter extends Fragment implements NFCSupport{
  32 +public class Crediter extends Fragment implements NFCSupport {
33 33  
34 34 private EditText mMoneyEditText;
35 35 private ProgressBar mProgressBar;
... ... @@ -70,7 +70,7 @@ public class Crediter extends Fragment implements NFCSupport{
70 70  
71 71 @Override
72 72 public void processNFC(String idCardUser) {
73   - if(mMoneyEditText.getText().toString().isEmpty()){
  73 + if (mMoneyEditText.getText().toString().isEmpty()) {
74 74 mMoneyEditText.setError(getString(R.string.error_enter_debit));
75 75 return;
76 76 }
... ... @@ -82,10 +82,10 @@ public class Crediter extends Fragment implements NFCSupport{
82 82 p.setCarte(idCardUser);
83 83 jsonObject.put("participant", p);
84 84 jsonObject.put("prix", Double.parseDouble(mMoneyEditText.getText().toString()));
85   - } catch (JSONException e){
  85 + } catch (JSONException e) {
86 86 e.printStackTrace();
87 87 }
88   - JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/transaction/debit" ,jsonObject , new Response.Listener<JSONObject>() {
  88 + JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/transaction/debit", jsonObject, new Response.Listener<JSONObject>() {
89 89 @Override
90 90 public void onResponse(JSONObject response) {
91 91 mProgressBar.setVisibility(View.GONE);
... ... @@ -101,13 +101,14 @@ public class Crediter extends Fragment implements NFCSupport{
101 101 Snackbar.make(coordinatorLayout, error.getMessage(), Snackbar.LENGTH_LONG).show();
102 102 }
103 103 }
104   - ){
  104 + ) {
105 105 @Override
106 106 public Map<String, String> getHeaders() throws AuthFailureError {
107   - Map<String, String> headers = new HashMap<String, String>();
  107 + Map<String, String> headers = new HashMap<>();
108 108 headers.put("Authorization", MainActivity.session.getToken());
109 109 return headers;
110   - }};
  110 + }
  111 + };
111 112 jsonObjectRequest.setTag(Crediter.class);
112 113 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
113 114 }
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/debit/Debiter.java
... ... @@ -74,7 +74,7 @@ public class Debiter extends Fragment implements NFCSupport {
74 74  
75 75 @Override
76 76 public void processNFC(String iDCardUser) {
77   - if(mMoneyEditText.getText().toString().isEmpty()){
  77 + if (mMoneyEditText.getText().toString().isEmpty()) {
78 78 mMoneyEditText.setError(getString(R.string.error_enter_debit));
79 79 return;
80 80 }
... ... @@ -88,10 +88,10 @@ public class Debiter extends Fragment implements NFCSupport {
88 88 jsonObject.put("participant", p);
89 89 jsonObject.put("prix", -Double.parseDouble(mMoneyEditText.getText().toString()));
90 90 mMoneyEditText.setError(null);
91   - } catch (JSONException e){
  91 + } catch (JSONException e) {
92 92 e.printStackTrace();
93 93 }
94   - JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/transaction/credit" ,jsonObject , new Response.Listener<JSONObject>() {
  94 + JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/transaction/credit", jsonObject, new Response.Listener<JSONObject>() {
95 95 @Override
96 96 public void onResponse(JSONObject response) {
97 97 mProgressBar.setVisibility(View.GONE);
... ... @@ -108,14 +108,14 @@ public class Debiter extends Fragment implements NFCSupport {
108 108 Snackbar.make(coordinatorLayout, error.getMessage(), Snackbar.LENGTH_LONG).show();
109 109  
110 110 }
111   - })
112   - {
  111 + }) {
113 112 @Override
114 113 public Map<String, String> getHeaders() throws AuthFailureError {
115   - Map<String, String> headers = new HashMap<String, String>();
  114 + Map<String, String> headers = new HashMap<>();
116 115 headers.put("Authorization", MainActivity.session.getToken());
117 116 return headers;
118   - }};
  117 + }
  118 + };
119 119 jsonObjectRequest.setTag(Debiter.class);
120 120 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
121 121 }
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/CreatePersonne.java
... ... @@ -4,6 +4,7 @@ import android.app.DatePickerDialog;
4 4 import android.app.Dialog;
5 5 import android.content.DialogInterface;
6 6 import android.os.Bundle;
  7 +import android.support.annotation.NonNull;
7 8 import android.support.design.widget.TextInputLayout;
8 9 import android.support.v4.app.DialogFragment;
9 10 import android.support.v7.app.AlertDialog;
... ... @@ -26,8 +27,8 @@ import com.android.volley.toolbox.JsonArrayRequest;
26 27 import com.android.volley.toolbox.JsonObjectRequest;
27 28  
28 29 import net.plil.clubinfo.etunicorn.R;
29   -import net.plil.clubinfo.etunicorn.app.NFCSupport;
30 30 import net.plil.clubinfo.etunicorn.app.MainActivity;
  31 +import net.plil.clubinfo.etunicorn.app.NFCSupport;
31 32 import net.plil.clubinfo.etunicorn.data.Role;
32 33 import net.plil.clubinfo.etunicorn.utils.ConvertBytesToString;
33 34 import net.plil.clubinfo.etunicorn.utils.JsonConverter;
... ... @@ -48,30 +49,35 @@ import java.util.Map;
48 49  
49 50 public class CreatePersonne extends DialogFragment implements NFCSupport {
50 51  
51   - private DialogInterface.OnDismissListener onDismissListener;
52   -
53 52 Calendar myCalendar = Calendar.getInstance();
54   -
55   -
  53 + TextInputLayout mLoginInput;
  54 + TextInputLayout mCarteInput;
  55 + private DialogInterface.OnDismissListener onDismissListener;
56 56 private EditText mLogin;
57 57 private EditText mCarte;
58 58 private Spinner mNaissance;
59 59 private Spinner mRole;
60 60 private ProgressBar mProgressBar;
61   -
62   - TextInputLayout mLoginInput;
63   - TextInputLayout mCarteInput;
64   -
65 61 private String[] arraySpinnerNaissance;
66 62 private ArrayAdapter<String> adapterNaissance;
  63 + DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
67 64  
  65 + @Override
  66 + public void onDateSet(DatePicker view, int year, int monthOfYear,
  67 + int dayOfMonth) {
  68 + myCalendar.set(Calendar.YEAR, year);
  69 + myCalendar.set(Calendar.MONTH, monthOfYear);
  70 + myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
  71 + updateLabel();
  72 + }
  73 + };
68 74 private List<Role> arraySpinnerRole;
69 75 private ArrayAdapter<Role> adapterRole;
70 76  
71   -
72 77 @Override
  78 + @NonNull
73 79 public Dialog onCreateDialog(Bundle savedInstanceState) {
74   - myCalendar.set(Calendar.YEAR, myCalendar.get(Calendar.YEAR)-18);
  80 + myCalendar.set(Calendar.YEAR, myCalendar.get(Calendar.YEAR) - 18);
75 81 // Use the Builder class for convenient dialog construction
76 82 LayoutInflater inflater = getActivity().getLayoutInflater();
77 83 View view = inflater.inflate(R.layout.fragment_create_personne, null);
... ... @@ -89,10 +95,10 @@ public class CreatePersonne extends DialogFragment implements NFCSupport {
89 95 mRole.setAdapter(adapterRole);
90 96 changeRolePossibility();
91 97 mNaissance = (Spinner) view.findViewById(R.id.create_personne_naissance);
92   - arraySpinnerNaissance = new String[] {
  98 + arraySpinnerNaissance = new String[]{
93 99 getString(R.string.create_personne_naissance)
94 100 };
95   - adapterNaissance = new ArrayAdapter<String>(getActivity(),
  101 + adapterNaissance = new ArrayAdapter<>(getActivity(),
96 102 R.layout.simple_item_layout, arraySpinnerNaissance);
97 103 mNaissance.setAdapter(adapterNaissance);
98 104 mProgressBar = (ProgressBar) view.findViewById(R.id.create_personne_progress_bar);
... ... @@ -113,11 +119,10 @@ public class CreatePersonne extends DialogFragment implements NFCSupport {
113 119 button.setOnClickListener(new View.OnClickListener() {
114 120 @Override
115 121 public void onClick(View v) {
116   - if (mLogin.getText().toString().isEmpty() && mCarte.getText().toString().isEmpty()){
  122 + if (mLogin.getText().toString().isEmpty() && mCarte.getText().toString().isEmpty()) {
117 123 mLogin.setError(getString(R.string.error_create_personne_login_carte));
118 124 mCarte.setError(getString(R.string.error_create_personne_login_carte));
119   - }
120   - else {
  125 + } else {
121 126 mProgressBar.setVisibility(View.VISIBLE);
122 127 mLoginInput.setVisibility(View.GONE);
123 128 mCarteInput.setVisibility(View.GONE);
... ... @@ -127,7 +132,7 @@ public class CreatePersonne extends DialogFragment implements NFCSupport {
127 132 try {
128 133 if (!mLogin.getText().toString().isEmpty())
129 134 jsonObject.put("login", mLogin.getText().toString());
130   - if(!mCarte.getText().toString().isEmpty())
  135 + if (!mCarte.getText().toString().isEmpty())
131 136 jsonObject.put("carte", mCarte.getText().toString());
132 137 jsonObject.put("role", JsonConverter.convertToJSONObject(mRole.getSelectedItem()));
133 138 if (!mNaissance.getSelectedItem().equals(getString(R.string.create_personne_naissance)))
... ... @@ -153,14 +158,14 @@ public class CreatePersonne extends DialogFragment implements NFCSupport {
153 158 Toast.makeText(getContext(), ConvertBytesToString.bytesToStringVolLey(error.networkResponse.data), Toast.LENGTH_LONG).show();
154 159 }
155 160 }
156   - )
157   - {
  161 + ) {
158 162 @Override
159 163 public Map<String, String> getHeaders() throws AuthFailureError {
160   - Map<String, String> headers = new HashMap<String, String>();
  164 + Map<String, String> headers = new HashMap<>();
161 165 headers.put("Authorization", MainActivity.session.getToken());
162 166 return headers;
163   - }};
  167 + }
  168 + };
164 169 jsonObjectRequest.setTag(CreatePersonne.class);
165 170 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
166 171 }
... ... @@ -172,7 +177,7 @@ public class CreatePersonne extends DialogFragment implements NFCSupport {
172 177 mNaissance.setOnTouchListener(new View.OnTouchListener() {
173 178 @Override
174 179 public boolean onTouch(View v, MotionEvent event) {
175   - if(event.getAction() == MotionEvent.ACTION_UP) {
  180 + if (event.getAction() == MotionEvent.ACTION_UP) {
176 181 new DatePickerDialog(getContext(), date, myCalendar
177 182 .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
178 183 myCalendar.get(Calendar.DAY_OF_MONTH)).show();
... ... @@ -184,13 +189,13 @@ public class CreatePersonne extends DialogFragment implements NFCSupport {
184 189 return dialog;
185 190 }
186 191  
187   - private void changeRolePossibility(){
188   - JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, VolleyUtils.baseUri + "/role" ,null , new Response.Listener<JSONArray>() {
  192 + private void changeRolePossibility() {
  193 + JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, VolleyUtils.baseUri + "/role", null, new Response.Listener<JSONArray>() {
189 194 @Override
190 195 public void onResponse(JSONArray response) {
191 196 try {
192 197 arraySpinnerRole.clear();
193   - for (int i =0; i<response.length();++i){
  198 + for (int i = 0; i < response.length(); ++i) {
194 199 arraySpinnerRole.add(JsonConverter.getConverter().fromJson(String.valueOf(response.getJSONObject(i)), Role.class));
195 200 }
196 201 adapterRole.notifyDataSetChanged();
... ... @@ -202,7 +207,7 @@ public class CreatePersonne extends DialogFragment implements NFCSupport {
202 207 }, new Response.ErrorListener() {
203 208 @Override
204 209 public void onErrorResponse(VolleyError error) {
205   - if(error.networkResponse == null)
  210 + if (error.networkResponse == null)
206 211 Toast.makeText(getContext(), "Verifier votre connection Internet", Toast.LENGTH_LONG).show();
207 212 else
208 213 Toast.makeText(getContext(), ConvertBytesToString.bytesToStringVolLey(error.networkResponse.data), Toast.LENGTH_LONG).show();
... ... @@ -213,18 +218,6 @@ public class CreatePersonne extends DialogFragment implements NFCSupport {
213 218 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonArrayRequest);
214 219 }
215 220  
216   - DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
217   -
218   - @Override
219   - public void onDateSet(DatePicker view, int year, int monthOfYear,
220   - int dayOfMonth) {
221   - myCalendar.set(Calendar.YEAR, year);
222   - myCalendar.set(Calendar.MONTH, monthOfYear);
223   - myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
224   - updateLabel();
225   - }
226   - };
227   -
228 221 private void updateLabel() {
229 222 String myFormat = "yyyy-MM-dd"; //In which you need put here
230 223 SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.FRANCE);
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/DeletePersonne.java
... ... @@ -3,6 +3,7 @@ package net.plil.clubinfo.etunicorn.app.personne;
3 3 import android.app.Dialog;
4 4 import android.content.DialogInterface;
5 5 import android.os.Bundle;
  6 +import android.support.annotation.NonNull;
6 7 import android.support.v4.app.DialogFragment;
7 8 import android.support.v7.app.AlertDialog;
8 9 import android.view.LayoutInflater;
... ... @@ -19,7 +20,6 @@ import com.android.volley.toolbox.JsonObjectRequest;
19 20  
20 21 import net.plil.clubinfo.etunicorn.R;
21 22 import net.plil.clubinfo.etunicorn.app.MainActivity;
22   -import net.plil.clubinfo.etunicorn.data.Event;
23 23 import net.plil.clubinfo.etunicorn.data.Personne;
24 24 import net.plil.clubinfo.etunicorn.utils.VolleyUtils;
25 25  
... ... @@ -33,7 +33,8 @@ public class DeletePersonne extends DialogFragment {
33 33  
34 34 ProgressBar mProgressBar;
35 35  
36   - public DeletePersonne(){}
  36 + public DeletePersonne() {
  37 + }
37 38  
38 39 /**
39 40 * Create a new instance of MyDialogFragment, providing "num"
... ... @@ -46,20 +47,21 @@ public class DeletePersonne extends DialogFragment {
46 47 Bundle args = new Bundle();
47 48 args.putSerializable("personne", personne);
48 49 f.setArguments(args);
49   -
50 50 return f;
51 51 }
52 52  
53 53  
54 54 @Override
  55 + @NonNull
55 56 public Dialog onCreateDialog(Bundle savedInstanceState) {
56 57 // Use the Builder class for convenient dialog construction
57 58 LayoutInflater inflater = getActivity().getLayoutInflater();
58 59 View view = inflater.inflate(R.layout.fragment_delete_personne, null);
59 60  
60 61 mProgressBar = (ProgressBar) view.findViewById(R.id.delete_personne_progress_bar);
61   - final Personne personne = (Personne) getArguments().getSerializable("personne");
62 62  
  63 + final Personne personne = (Personne) getArguments().getSerializable("personne");
  64 + assert personne != null;
63 65  
64 66 AlertDialog dialog = new AlertDialog.Builder(getActivity())
65 67 .setTitle(R.string.verif_delete_personne)
... ... @@ -94,13 +96,14 @@ public class DeletePersonne extends DialogFragment {
94 96 Toast.makeText(getContext(), R.string.delete_refused, Toast.LENGTH_LONG).show();
95 97 }
96 98 }
97   - ){
  99 + ) {
98 100 @Override
99 101 public Map<String, String> getHeaders() throws AuthFailureError {
100   - Map<String, String> headers = new HashMap<String, String>();
  102 + Map<String, String> headers = new HashMap<>();
101 103 headers.put("Authorization", MainActivity.session.getToken());
102 104 return headers;
103   - }};
  105 + }
  106 + };
104 107 jsonObjectRequest.setTag(DeletePersonne.class);
105 108 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
106 109 }
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/ModifyPersonne.java
... ... @@ -4,6 +4,7 @@ import android.app.DatePickerDialog;
4 4 import android.app.Dialog;
5 5 import android.content.DialogInterface;
6 6 import android.os.Bundle;
  7 +import android.support.annotation.NonNull;
7 8 import android.support.design.widget.TextInputLayout;
8 9 import android.support.v4.app.DialogFragment;
9 10 import android.support.v7.app.AlertDialog;
... ... @@ -26,8 +27,8 @@ import com.android.volley.toolbox.JsonArrayRequest;
26 27 import com.android.volley.toolbox.JsonObjectRequest;
27 28  
28 29 import net.plil.clubinfo.etunicorn.R;
29   -import net.plil.clubinfo.etunicorn.app.NFCSupport;
30 30 import net.plil.clubinfo.etunicorn.app.MainActivity;
  31 +import net.plil.clubinfo.etunicorn.app.NFCSupport;
31 32 import net.plil.clubinfo.etunicorn.data.Personne;
32 33 import net.plil.clubinfo.etunicorn.data.Role;
33 34 import net.plil.clubinfo.etunicorn.utils.ConvertBytesToString;
... ... @@ -62,7 +63,17 @@ public class ModifyPersonne extends DialogFragment implements NFCSupport {
62 63  
63 64 private String[] arraySpinnerNaissance;
64 65 private ArrayAdapter<String> adapterNaissance;
  66 + DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
65 67  
  68 + @Override
  69 + public void onDateSet(DatePicker view, int year, int monthOfYear,
  70 + int dayOfMonth) {
  71 + myCalendar.set(Calendar.YEAR, year);
  72 + myCalendar.set(Calendar.MONTH, monthOfYear);
  73 + myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
  74 + updateLabel();
  75 + }
  76 + };
66 77 private List<Role> arraySpinnerRole;
67 78 private ArrayAdapter<Role> adapterRole;
68 79  
... ... @@ -77,10 +88,10 @@ public class ModifyPersonne extends DialogFragment implements NFCSupport {
77 88 return f;
78 89 }
79 90  
80   -
81 91 @Override
  92 + @NonNull
82 93 public Dialog onCreateDialog(Bundle savedInstanceState) {
83   - myCalendar.set(Calendar.YEAR, myCalendar.get(Calendar.YEAR)-18);
  94 + myCalendar.set(Calendar.YEAR, myCalendar.get(Calendar.YEAR) - 18);
84 95 // Use the Builder class for convenient dialog construction
85 96 LayoutInflater inflater = getActivity().getLayoutInflater();
86 97 View view = inflater.inflate(R.layout.fragment_modify_personne, null);
... ... @@ -94,6 +105,7 @@ public class ModifyPersonne extends DialogFragment implements NFCSupport {
94 105 mCarteInput = (TextInputLayout) view.findViewById(R.id.modify_personne_carte_input);
95 106  
96 107 final Personne personne = (Personne) getArguments().getSerializable("personne");
  108 + assert personne != null;
97 109  
98 110 mCarte.setText(personne.getCarte());
99 111 mLogin.setText(personne.getLogin());
... ... @@ -107,7 +119,7 @@ public class ModifyPersonne extends DialogFragment implements NFCSupport {
107 119 mNaissance = (Spinner) view.findViewById(R.id.modify_personne_naissance);
108 120 final String myFormat = "yyyy-MM-dd"; //In which you need put here
109 121 SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.FRANCE);
110   - if (personne.getNaissance() == null){
  122 + if (personne.getNaissance() == null) {
111 123 arraySpinnerNaissance = new String[]{
112 124 getString(R.string.modify_personne_hint_date)
113 125 };
... ... @@ -116,7 +128,7 @@ public class ModifyPersonne extends DialogFragment implements NFCSupport {
116 128 sdf.format(personne.getNaissance())
117 129 };
118 130 }
119   - adapterNaissance = new ArrayAdapter<String>(getActivity(),
  131 + adapterNaissance = new ArrayAdapter<>(getActivity(),
120 132 R.layout.simple_item_layout, arraySpinnerNaissance);
121 133 mNaissance.setAdapter(adapterNaissance);
122 134  
... ... @@ -150,10 +162,10 @@ public class ModifyPersonne extends DialogFragment implements NFCSupport {
150 162 jsonObject.put("role", JsonConverter.convertToJSONObject(mRole.getSelectedItem()));
151 163 if (!mNaissance.getSelectedItem().equals(getString(R.string.modify_personne_hint_date)))
152 164 jsonObject.put("naissance", mNaissance.getSelectedItem().toString());
153   - } catch (JSONException e){
  165 + } catch (JSONException e) {
154 166 e.printStackTrace();
155 167 }
156   - JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.PUT, VolleyUtils.baseUri + "/personne/" + personne.getId() ,jsonObject , new Response.Listener<JSONObject>() {
  168 + JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.PUT, VolleyUtils.baseUri + "/personne/" + personne.getId(), jsonObject, new Response.Listener<JSONObject>() {
157 169 @Override
158 170 public void onResponse(JSONObject response) {
159 171 mProgressBar.setVisibility(View.GONE);
... ... @@ -168,24 +180,25 @@ public class ModifyPersonne extends DialogFragment implements NFCSupport {
168 180 if (error.networkResponse != null)
169 181 Toast.makeText(getContext(), R.string.modify_refused + " : " + ConvertBytesToString.bytesToStringVolLey(error.networkResponse.data), Toast.LENGTH_LONG).show();
170 182 else
171   - Toast.makeText(getContext(), "!!" + error.getStackTrace().toString(), Toast.LENGTH_SHORT).show();
  183 + Toast.makeText(getContext(), "!!" + error.getMessage(), Toast.LENGTH_SHORT).show();
172 184 mRole.setVisibility(View.VISIBLE);
173 185 mCarteInput.setVisibility(View.VISIBLE);
174 186 mLoginInput.setVisibility(View.VISIBLE);
175 187 mNaissance.setVisibility(View.VISIBLE);
176 188 }
177 189 }
178   - ){
  190 + ) {
179 191 @Override
180 192 public Map<String, String> getHeaders() throws AuthFailureError {
181   - Map<String, String> headers = new HashMap<String, String>();
  193 + Map<String, String> headers = new HashMap<>();
182 194 headers.put("Authorization", MainActivity.session.getToken());
183 195 return headers;
184   - }};
  196 + }
  197 + };
185 198 jsonObjectRequest.setTag(ModifyPersonne.class);
186 199  
187 200 try {
188   - for (String s : jsonObjectRequest.getHeaders().keySet()){
  201 + for (String s : jsonObjectRequest.getHeaders().keySet()) {
189 202 System.out.println(s + " " + jsonObjectRequest.getHeaders().get(s));
190 203 }
191 204 } catch (AuthFailureError authFailureError) {
... ... @@ -201,7 +214,7 @@ public class ModifyPersonne extends DialogFragment implements NFCSupport {
201 214 mNaissance.setOnTouchListener(new View.OnTouchListener() {
202 215 @Override
203 216 public boolean onTouch(View v, MotionEvent event) {
204   - if(event.getAction() == MotionEvent.ACTION_UP) {
  217 + if (event.getAction() == MotionEvent.ACTION_UP) {
205 218 new DatePickerDialog(getContext(), date, myCalendar
206 219 .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
207 220 myCalendar.get(Calendar.DAY_OF_MONTH)).show();
... ... @@ -213,18 +226,6 @@ public class ModifyPersonne extends DialogFragment implements NFCSupport {
213 226 return dialog;
214 227 }
215 228  
216   - DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
217   -
218   - @Override
219   - public void onDateSet(DatePicker view, int year, int monthOfYear,
220   - int dayOfMonth) {
221   - myCalendar.set(Calendar.YEAR, year);
222   - myCalendar.set(Calendar.MONTH, monthOfYear);
223   - myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
224   - updateLabel();
225   - }
226   - };
227   -
228 229 private void updateLabel() {
229 230 String myFormat = "yyyy-MM-dd"; //In which you need put here
230 231 SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.FRANCE);
... ... @@ -240,13 +241,13 @@ public class ModifyPersonne extends DialogFragment implements NFCSupport {
240 241 super.onStop();
241 242 }
242 243  
243   - private void changeRolePossibility(){
244   - JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, VolleyUtils.baseUri + "/role" ,null , new Response.Listener<JSONArray>() {
  244 + private void changeRolePossibility() {
  245 + JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, VolleyUtils.baseUri + "/role", null, new Response.Listener<JSONArray>() {
245 246 @Override
246 247 public void onResponse(JSONArray response) {
247 248 try {
248 249 arraySpinnerRole.clear();
249   - for (int i =0; i<response.length();++i){
  250 + for (int i = 0; i < response.length(); ++i) {
250 251 arraySpinnerRole.add(JsonConverter.getConverter().fromJson(String.valueOf(response.getJSONObject(i)), Role.class));
251 252 }
252 253 adapterRole.notifyDataSetChanged();
... ... @@ -258,7 +259,7 @@ public class ModifyPersonne extends DialogFragment implements NFCSupport {
258 259 }, new Response.ErrorListener() {
259 260 @Override
260 261 public void onErrorResponse(VolleyError error) {
261   - if(error.networkResponse == null)
  262 + if (error.networkResponse == null)
262 263 Toast.makeText(getContext(), "Verifier votre connection Internet", Toast.LENGTH_LONG).show();
263 264 else
264 265 Toast.makeText(getContext(), ConvertBytesToString.bytesToStringVolLey(error.networkResponse.data), Toast.LENGTH_LONG).show();
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/MyPersonneRecyclerViewAdapter.java
... ... @@ -16,14 +16,14 @@ import net.plil.clubinfo.etunicorn.data.Personne;
16 16 import java.util.List;
17 17 import java.util.Locale;
18 18  
19   -public class MyPersonneRecyclerViewAdapter extends RecyclerView.Adapter<MyPersonneRecyclerViewAdapter.ViewHolder> {
  19 +class MyPersonneRecyclerViewAdapter extends RecyclerView.Adapter<MyPersonneRecyclerViewAdapter.ViewHolder> {
20 20  
21 21 private final List<Personne> mValues;
22 22 private final PersonneFragment.OnListFragmentInteractionListener mListener;
23 23 private final Context context;
24 24  
25 25  
26   - public MyPersonneRecyclerViewAdapter(List<Personne> items, PersonneFragment.OnListFragmentInteractionListener listener, Context context) {
  26 + MyPersonneRecyclerViewAdapter(List<Personne> items, PersonneFragment.OnListFragmentInteractionListener listener, Context context) {
27 27 mValues = items;
28 28 mListener = listener;
29 29 this.context = context;
... ... @@ -88,16 +88,16 @@ public class MyPersonneRecyclerViewAdapter extends RecyclerView.Adapter&lt;MyPerson
88 88 return mValues.size();
89 89 }
90 90  
91   - public class ViewHolder extends RecyclerView.ViewHolder {
92   - public final View mView;
93   - public final TextView mLogin;
94   - public final TextView mCarte;
95   - public final TextView mRole;
96   - public final TextView mSolde;
97   - public final TextView mButton;
98   - public Personne mItem;
  91 + class ViewHolder extends RecyclerView.ViewHolder {
  92 + final View mView;
  93 + final TextView mLogin;
  94 + final TextView mCarte;
  95 + final TextView mRole;
  96 + final TextView mSolde;
  97 + final TextView mButton;
  98 + Personne mItem;
99 99  
100   - public ViewHolder(View view) {
  100 + ViewHolder(View view) {
101 101 super(view);
102 102 mView = view;
103 103 mLogin = (TextView) view.findViewById(R.id.personne_login);
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/PersonOverviewFragment.java
1 1 package net.plil.clubinfo.etunicorn.app.personne;
2 2  
3 3 import android.app.Dialog;
4   -import android.content.Context;
5   -import android.net.Uri;
6 4 import android.os.Bundle;
  5 +import android.support.annotation.NonNull;
7 6 import android.support.v4.app.DialogFragment;
8   -import android.support.v4.app.Fragment;
9 7 import android.support.v7.app.AlertDialog;
10 8 import android.view.LayoutInflater;
11 9 import android.view.View;
... ... @@ -15,16 +13,10 @@ import android.widget.TextView;
15 13 import net.plil.clubinfo.etunicorn.R;
16 14 import net.plil.clubinfo.etunicorn.data.Personne;
17 15  
18   -import java.text.SimpleDateFormat;
19 16 import java.util.Locale;
20 17  
21   -/**
22   - * A simple {@link Fragment} subclass.
23   - * Activities that contain this fragment must implement the
24   - * {@link PersonOverviewFragment.OnFragmentInteractionListener} interface
25   - * to handle interaction events.
26   - */
27   -public class PersonOverviewFragment extends DialogFragment{
  18 +
  19 +public class PersonOverviewFragment extends DialogFragment {
28 20  
29 21 TextView mCarte;
30 22 TextView mNaissance;
... ... @@ -45,7 +37,8 @@ public class PersonOverviewFragment extends DialogFragment{
45 37 }
46 38  
47 39 @Override
48   - public Dialog onCreateDialog(Bundle savedInstanceState){
  40 + @NonNull
  41 + public Dialog onCreateDialog(Bundle savedInstanceState) {
49 42 LayoutInflater inflater = getActivity().getLayoutInflater();
50 43 View view = inflater.inflate(R.layout.fragment_person_overview, null);
51 44  
... ... @@ -60,7 +53,7 @@ public class PersonOverviewFragment extends DialogFragment{
60 53 assert personne != null;
61 54 mCarte.setText(personne.getCarte());
62 55 mRole.setText(personne.getRole().getNom());
63   - mSolde.setText(String.format(Locale.US, "%.2f",personne.getSolde()));
  56 + mSolde.setText(String.format(Locale.US, "%.2f", personne.getSolde()));
64 57 if (personne.getNaissance() != null)
65 58 mNaissance.setText(personne.getNaissance().toString());
66 59 mLogin.setText(personne.getLogin());
... ...
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/PersonneFragment.java
... ... @@ -20,8 +20,8 @@ import com.android.volley.VolleyError;
20 20 import com.android.volley.toolbox.JsonArrayRequest;
21 21  
22 22 import net.plil.clubinfo.etunicorn.R;
23   -import net.plil.clubinfo.etunicorn.app.NFCSupport;
24 23 import net.plil.clubinfo.etunicorn.app.MainActivity;
  24 +import net.plil.clubinfo.etunicorn.app.NFCSupport;
25 25 import net.plil.clubinfo.etunicorn.data.Personne;
26 26 import net.plil.clubinfo.etunicorn.utils.ConvertBytesToString;
27 27 import net.plil.clubinfo.etunicorn.utils.JsonConverter;
... ... @@ -119,13 +119,13 @@ public class PersonneFragment extends Fragment implements NFCSupport {
119 119 mListener = null;
120 120 }
121 121  
122   - private void setPersonnes(){
123   - JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, VolleyUtils.baseUri + "/personne" ,null , new Response.Listener<JSONArray>() {
  122 + private void setPersonnes() {
  123 + JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, VolleyUtils.baseUri + "/personne", null, new Response.Listener<JSONArray>() {
124 124 @Override
125 125 public void onResponse(JSONArray response) {
126 126 try {
127 127 personnes.clear();
128   - for (int i =0; i<response.length();++i){
  128 + for (int i = 0; i < response.length(); ++i) {
129 129 personnes.add(JsonConverter.getConverter().fromJson(String.valueOf(response.getJSONObject(i)), Personne.class));
130 130 }
131 131 mAdapter.notifyDataSetChanged();
... ... @@ -159,11 +159,13 @@ public class PersonneFragment extends Fragment implements NFCSupport {
159 159 @Override
160 160 public void processNFC(String idCardUser) {
161 161 CreatePersonne createPersonne = (CreatePersonne) getFragmentManager().findFragmentByTag(getString(R.string.tag_create_personne));
162   - if (createPersonne != null){
  162 + if (createPersonne != null) {
163 163 createPersonne.processNFC(idCardUser);
164   - }
165   - else {
  164 + } else {
166 165 ModifyPersonne modifyPersonne = (ModifyPersonne) getFragmentManager().findFragmentByTag(getString(R.string.tag_modify_personne));
  166 + if (modifyPersonne != null){
  167 + modifyPersonne.processNFC(idCardUser);
  168 + }
167 169 }
168 170  
169 171 }
... ...