Commit a72d73c47824abc1b8a1015ee5e40984434b8f55

Authored by badetitou
1 parent 3dc52ca9

Event ?

app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/CreateEvent.java
@@ -41,6 +41,9 @@ import java.util.Map; @@ -41,6 +41,9 @@ import java.util.Map;
41 41
42 public class CreateEvent extends DialogFragment { 42 public class CreateEvent extends DialogFragment {
43 43
  44 + private DialogInterface.OnDismissListener onDismissListener;
  45 +
  46 +
44 Calendar myCalendar = Calendar.getInstance(); 47 Calendar myCalendar = Calendar.getInstance();
45 48
46 49
@@ -186,10 +189,22 @@ public class CreateEvent extends DialogFragment { @@ -186,10 +189,22 @@ public class CreateEvent extends DialogFragment {
186 } 189 }
187 190
188 private void updateLabel() { 191 private void updateLabel() {
189 - String myFormat = "yyyy-MM-dd"; //In which you need put here 192 + String myFormat = "yyyy-MM-dd";
190 SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.FRANCE); 193 SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.FRANCE);
191 arraySpinnerDate[0] = sdf.format(myCalendar.getTime()); 194 arraySpinnerDate[0] = sdf.format(myCalendar.getTime());
192 adapterDate.notifyDataSetChanged(); 195 adapterDate.notifyDataSetChanged();
193 } 196 }
194 197
  198 + public void setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) {
  199 + this.onDismissListener = onDismissListener;
  200 + }
  201 +
  202 + @Override
  203 + public void onDismiss(DialogInterface dialog) {
  204 + super.onDismiss(dialog);
  205 + if (onDismissListener != null) {
  206 + onDismissListener.onDismiss(dialog);
  207 + }
  208 + }
  209 +
195 } 210 }
app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/DeleteEvent.java
@@ -31,6 +31,9 @@ import java.util.Map; @@ -31,6 +31,9 @@ import java.util.Map;
31 31
32 public class DeleteEvent extends DialogFragment { 32 public class DeleteEvent extends DialogFragment {
33 33
  34 + private DialogInterface.OnDismissListener onDismissListener;
  35 +
  36 +
34 ProgressBar mProgressBar; 37 ProgressBar mProgressBar;
35 38
36 public DeleteEvent() { 39 public DeleteEvent() {
@@ -84,7 +87,7 @@ public class DeleteEvent extends DialogFragment { @@ -84,7 +87,7 @@ public class DeleteEvent extends DialogFragment {
84 public void onClick(View v) { 87 public void onClick(View v) {
85 mProgressBar.setVisibility(View.VISIBLE); 88 mProgressBar.setVisibility(View.VISIBLE);
86 89
87 - JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.DELETE, VolleyUtils.baseUri + "/evenement/" + event.getIdEvent(), null, new Response.Listener<JSONObject>() { 90 + JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.DELETE, VolleyUtils.baseUri + "/evenement/" + event.getId(), null, new Response.Listener<JSONObject>() {
88 @Override 91 @Override
89 public void onResponse(JSONObject response) { 92 public void onResponse(JSONObject response) {
90 mProgressBar.setVisibility(View.GONE); 93 mProgressBar.setVisibility(View.GONE);
@@ -122,4 +125,16 @@ public class DeleteEvent extends DialogFragment { @@ -122,4 +125,16 @@ public class DeleteEvent extends DialogFragment {
122 super.onStop(); 125 super.onStop();
123 } 126 }
124 127
  128 + public void setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) {
  129 + this.onDismissListener = onDismissListener;
  130 + }
  131 +
  132 + @Override
  133 + public void onDismiss(DialogInterface dialog) {
  134 + super.onDismiss(dialog);
  135 + if (onDismissListener != null) {
  136 + onDismissListener.onDismiss(dialog);
  137 + }
  138 + }
  139 +
125 } 140 }
app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/EventFragment.java
1 package net.plil.clubinfo.etunicorn.app.event; 1 package net.plil.clubinfo.etunicorn.app.event;
2 2
3 import android.content.Context; 3 import android.content.Context;
  4 +import android.content.DialogInterface;
4 import android.os.Bundle; 5 import android.os.Bundle;
5 import android.support.design.widget.FloatingActionButton; 6 import android.support.design.widget.FloatingActionButton;
6 import android.support.v4.app.Fragment; 7 import android.support.v4.app.Fragment;
  8 +import android.support.v4.widget.SwipeRefreshLayout;
7 import android.support.v7.widget.LinearLayoutManager; 9 import android.support.v7.widget.LinearLayoutManager;
8 import android.support.v7.widget.RecyclerView; 10 import android.support.v7.widget.RecyclerView;
9 import android.view.LayoutInflater; 11 import android.view.LayoutInflater;
@@ -11,14 +13,31 @@ import android.view.View; @@ -11,14 +13,31 @@ import android.view.View;
11 import android.view.ViewGroup; 13 import android.view.ViewGroup;
12 import android.widget.Toast; 14 import android.widget.Toast;
13 15
  16 +import com.android.volley.AuthFailureError;
  17 +import com.android.volley.Request;
  18 +import com.android.volley.Response;
  19 +import com.android.volley.VolleyError;
  20 +import com.android.volley.toolbox.JsonArrayRequest;
  21 +
14 import net.plil.clubinfo.etunicorn.R; 22 import net.plil.clubinfo.etunicorn.R;
  23 +import net.plil.clubinfo.etunicorn.app.MainActivity;
15 import net.plil.clubinfo.etunicorn.app.NFCSupport; 24 import net.plil.clubinfo.etunicorn.app.NFCSupport;
  25 +import net.plil.clubinfo.etunicorn.app.personne.ModifyPersonne;
16 import net.plil.clubinfo.etunicorn.data.Event; 26 import net.plil.clubinfo.etunicorn.data.Event;
  27 +import net.plil.clubinfo.etunicorn.data.Personne;
  28 +import net.plil.clubinfo.etunicorn.utils.ConvertBytesToString;
  29 +import net.plil.clubinfo.etunicorn.utils.JsonConverter;
  30 +import net.plil.clubinfo.etunicorn.utils.VolleyUtils;
  31 +
  32 +import org.json.JSONArray;
  33 +import org.json.JSONException;
17 34
18 import java.sql.Date; 35 import java.sql.Date;
19 import java.util.ArrayList; 36 import java.util.ArrayList;
20 import java.util.Calendar; 37 import java.util.Calendar;
  38 +import java.util.HashMap;
21 import java.util.List; 39 import java.util.List;
  40 +import java.util.Map;
22 41
23 /** 42 /**
24 * A fragment representing a list of Items. 43 * A fragment representing a list of Items.
@@ -26,9 +45,13 @@ import java.util.List; @@ -26,9 +45,13 @@ import java.util.List;
26 * Activities containing this fragment MUST implement the {@link OnListFragmentInteractionListener} 45 * Activities containing this fragment MUST implement the {@link OnListFragmentInteractionListener}
27 * interface. 46 * interface.
28 */ 47 */
29 -public class EventFragment extends Fragment implements NFCSupport { 48 +public class EventFragment extends Fragment implements NFCSupport, DialogInterface.OnDismissListener {
30 49
31 private OnListFragmentInteractionListener mListener; 50 private OnListFragmentInteractionListener mListener;
  51 + private SwipeRefreshLayout mSwipeRefreshLayout;
  52 +
  53 + private List<Event> events;
  54 + private RecyclerView.Adapter mAdapter;
32 55
33 public EventFragment() { 56 public EventFragment() {
34 } 57 }
@@ -48,30 +71,39 @@ public class EventFragment extends Fragment implements NFCSupport { @@ -48,30 +71,39 @@ public class EventFragment extends Fragment implements NFCSupport {
48 Bundle savedInstanceState) { 71 Bundle savedInstanceState) {
49 View view = inflater.inflate(R.layout.fragment_event_list, container, false); 72 View view = inflater.inflate(R.layout.fragment_event_list, container, false);
50 73
51 - // Set the adapter  
52 Context context = view.getContext(); 74 Context context = view.getContext();
  75 +
53 RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.event_list); 76 RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.event_list);
54 recyclerView.setLayoutManager(new LinearLayoutManager(context)); 77 recyclerView.setLayoutManager(new LinearLayoutManager(context));
55 78
56 - List<Event> events = new ArrayList<>();  
57 - for (int i = 0; i < 150; ++i) {  
58 - Event ev = new Event();  
59 - ev.setNomEvent("Hello " + i);  
60 - ev.setPrice(15.52);  
61 - ev.setDate(new Date(Calendar.getInstance().getTimeInMillis()));  
62 - events.add(ev);  
63 - } 79 + events = new ArrayList<>();
  80 + updateEvents();
  81 + mAdapter = new MyEventRecyclerViewAdapter(events, mListener, getActivity(), this);
  82 + recyclerView.setAdapter(mAdapter);
64 83
65 FloatingActionButton fAB = (FloatingActionButton) view.findViewById(R.id.event_add); 84 FloatingActionButton fAB = (FloatingActionButton) view.findViewById(R.id.event_add);
66 fAB.setOnClickListener(new View.OnClickListener() { 85 fAB.setOnClickListener(new View.OnClickListener() {
67 @Override 86 @Override
68 public void onClick(View v) { 87 public void onClick(View v) {
69 CreateEvent newFragment = new CreateEvent(); 88 CreateEvent newFragment = new CreateEvent();
  89 + newFragment.setOnDismissListener(new DialogInterface.OnDismissListener() {
  90 + @Override
  91 + public void onDismiss(DialogInterface dialog) {
  92 + updateEvents();
  93 + }
  94 + });
70 newFragment.show(getFragmentManager(), "CreateEvent"); 95 newFragment.show(getFragmentManager(), "CreateEvent");
71 } 96 }
72 }); 97 });
73 98
74 - recyclerView.setAdapter(new MyEventRecyclerViewAdapter(events, mListener, getActivity())); 99 + mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.event_swipeRefresh);
  100 + mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
  101 + @Override
  102 + public void onRefresh() {
  103 + updateEvents();
  104 + }
  105 + });
  106 +
75 return view; 107 return view;
76 } 108 }
77 109
@@ -93,6 +125,43 @@ public class EventFragment extends Fragment implements NFCSupport { @@ -93,6 +125,43 @@ public class EventFragment extends Fragment implements NFCSupport {
93 mListener = null; 125 mListener = null;
94 } 126 }
95 127
  128 + private void updateEvents(){
  129 + JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, VolleyUtils.baseUri + "/evenement", null, new Response.Listener<JSONArray>() {
  130 + @Override
  131 + public void onResponse(JSONArray response) {
  132 + try {
  133 + events.clear();
  134 + for (int i = 0; i < response.length(); ++i) {
  135 + events.add(JsonConverter.getConverter().fromJson(String.valueOf(response.getJSONObject(i)), Event.class));
  136 + }
  137 + mAdapter.notifyDataSetChanged();
  138 + mSwipeRefreshLayout.setRefreshing(false);
  139 + } catch (JSONException e) {
  140 + e.printStackTrace();
  141 + }
  142 +
  143 + }
  144 + }, new Response.ErrorListener() {
  145 + @Override
  146 + public void onErrorResponse(VolleyError error) {
  147 + if (error.networkResponse == null)
  148 + Toast.makeText(getActivity(), "Unknow error SORRY", Toast.LENGTH_LONG).show();
  149 + else
  150 + Toast.makeText(getActivity(), ConvertBytesToString.bytesToStringVolLey(error.networkResponse.data), Toast.LENGTH_LONG).show();
  151 + }
  152 + }
  153 + ) {
  154 + @Override
  155 + public Map<String, String> getHeaders() throws AuthFailureError {
  156 + Map<String, String> headers = new HashMap<>();
  157 + headers.put("Authorization", MainActivity.session.getToken());
  158 + return headers;
  159 + }
  160 + };
  161 + jsonArrayRequest.setTag(ModifyPersonne.class);
  162 + VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonArrayRequest);
  163 + }
  164 +
96 @Override 165 @Override
97 public void processNFC(String idCardUser) { 166 public void processNFC(String idCardUser) {
98 PaiementEvent paiementEvent = (PaiementEvent) getFragmentManager().findFragmentByTag("paiementEvent"); 167 PaiementEvent paiementEvent = (PaiementEvent) getFragmentManager().findFragmentByTag("paiementEvent");
@@ -103,6 +172,11 @@ public class EventFragment extends Fragment implements NFCSupport { @@ -103,6 +172,11 @@ public class EventFragment extends Fragment implements NFCSupport {
103 } 172 }
104 } 173 }
105 174
  175 + @Override
  176 + public void onDismiss(DialogInterface dialog) {
  177 + updateEvents();
  178 + }
  179 +
106 /** 180 /**
107 * This interface must be implemented by activities that contain this 181 * This interface must be implemented by activities that contain this
108 * fragment to allow an interaction in this fragment to be communicated 182 * fragment to allow an interaction in this fragment to be communicated
app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/ModifyEvent.java
@@ -42,6 +42,9 @@ import java.util.Map; @@ -42,6 +42,9 @@ import java.util.Map;
42 42
43 public class ModifyEvent extends DialogFragment { 43 public class ModifyEvent extends DialogFragment {
44 44
  45 + private DialogInterface.OnDismissListener onDismissListener;
  46 +
  47 +
45 Calendar myCalendar = Calendar.getInstance(); 48 Calendar myCalendar = Calendar.getInstance();
46 EditText mNom; 49 EditText mNom;
47 EditText mPrice; 50 EditText mPrice;
@@ -100,8 +103,8 @@ public class ModifyEvent extends DialogFragment { @@ -100,8 +103,8 @@ public class ModifyEvent extends DialogFragment {
100 R.layout.simple_item_layout, arraySpinnerDate); 103 R.layout.simple_item_layout, arraySpinnerDate);
101 mDate.setAdapter(adapterDate); 104 mDate.setAdapter(adapterDate);
102 105
103 - mNom.setText(event.getNomEvent());  
104 - mPrice.setText(String.format(Locale.US, "%.2f", event.getPrice())); 106 + mNom.setText(event.getNom());
  107 + mPrice.setText(String.format(Locale.US, "%.2f", event.getPrix()));
105 108
106 AlertDialog dialog = new AlertDialog.Builder(getActivity()) 109 AlertDialog dialog = new AlertDialog.Builder(getActivity())
107 .setTitle(R.string.modify) 110 .setTitle(R.string.modify)
@@ -138,14 +141,14 @@ public class ModifyEvent extends DialogFragment { @@ -138,14 +141,14 @@ public class ModifyEvent extends DialogFragment {
138 mDate.setVisibility(View.GONE); 141 mDate.setVisibility(View.GONE);
139 JSONObject jsonObject = new JSONObject(); 142 JSONObject jsonObject = new JSONObject();
140 try { 143 try {
141 - jsonObject.put("nomEvenement", mNom.getText().toString()); 144 + jsonObject.put("nom", mNom.getText().toString());
142 if (!mPrice.getText().toString().isEmpty()) 145 if (!mPrice.getText().toString().isEmpty())
143 jsonObject.put("prix", Double.parseDouble(mPrice.getText().toString())); 146 jsonObject.put("prix", Double.parseDouble(mPrice.getText().toString()));
144 jsonObject.put("date", mDate.getSelectedItem()); 147 jsonObject.put("date", mDate.getSelectedItem());
145 } catch (JSONException e) { 148 } catch (JSONException e) {
146 e.printStackTrace(); 149 e.printStackTrace();
147 } 150 }
148 - JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, VolleyUtils.baseUri + "/evenement/" + event.getIdEvent(), jsonObject, new Response.Listener<JSONObject>() { 151 + JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.PUT, VolleyUtils.baseUri + "/evenement/" + event.getId(), jsonObject, new Response.Listener<JSONObject>() {
149 @Override 152 @Override
150 public void onResponse(JSONObject response) { 153 public void onResponse(JSONObject response) {
151 mProgressBar.setVisibility(View.GONE); 154 mProgressBar.setVisibility(View.GONE);
@@ -161,7 +164,6 @@ public class ModifyEvent extends DialogFragment { @@ -161,7 +164,6 @@ public class ModifyEvent extends DialogFragment {
161 mNomInput.setVisibility(View.VISIBLE); 164 mNomInput.setVisibility(View.VISIBLE);
162 mDate.setVisibility(View.VISIBLE); 165 mDate.setVisibility(View.VISIBLE);
163 Toast.makeText(getContext(), R.string.modify_refused, Toast.LENGTH_LONG).show(); 166 Toast.makeText(getContext(), R.string.modify_refused, Toast.LENGTH_LONG).show();
164 -  
165 } 167 }
166 } 168 }
167 ) { 169 ) {
@@ -196,4 +198,17 @@ public class ModifyEvent extends DialogFragment { @@ -196,4 +198,17 @@ public class ModifyEvent extends DialogFragment {
196 adapterDate.notifyDataSetChanged(); 198 adapterDate.notifyDataSetChanged();
197 } 199 }
198 200
  201 + public void setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) {
  202 + this.onDismissListener = onDismissListener;
  203 + }
  204 +
  205 + @Override
  206 + public void onDismiss(DialogInterface dialog) {
  207 + super.onDismiss(dialog);
  208 + if (onDismissListener != null) {
  209 + onDismissListener.onDismiss(dialog);
  210 + }
  211 + }
  212 +
  213 +
199 } 214 }
200 \ No newline at end of file 215 \ No newline at end of file
app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/MyEventRecyclerViewAdapter.java
1 package net.plil.clubinfo.etunicorn.app.event; 1 package net.plil.clubinfo.etunicorn.app.event;
2 2
3 import android.content.Context; 3 import android.content.Context;
  4 +import android.content.DialogInterface;
4 import android.support.v7.app.AppCompatActivity; 5 import android.support.v7.app.AppCompatActivity;
5 import android.support.v7.widget.PopupMenu; 6 import android.support.v7.widget.PopupMenu;
6 import android.support.v7.widget.RecyclerView; 7 import android.support.v7.widget.RecyclerView;
@@ -22,11 +23,13 @@ class MyEventRecyclerViewAdapter extends RecyclerView.Adapter&lt;MyEventRecyclerVie @@ -22,11 +23,13 @@ class MyEventRecyclerViewAdapter extends RecyclerView.Adapter&lt;MyEventRecyclerVie
22 private final List<Event> mEvents; 23 private final List<Event> mEvents;
23 private final EventFragment.OnListFragmentInteractionListener mListener; 24 private final EventFragment.OnListFragmentInteractionListener mListener;
24 private final Context context; 25 private final Context context;
  26 + DialogInterface.OnDismissListener mOnDismissListener;
25 27
26 - MyEventRecyclerViewAdapter(List<Event> items, EventFragment.OnListFragmentInteractionListener listener, Context context) { 28 + MyEventRecyclerViewAdapter(List<Event> items, EventFragment.OnListFragmentInteractionListener listener, Context context, DialogInterface.OnDismissListener mOnDismissListener) {
27 mEvents = items; 29 mEvents = items;
28 mListener = listener; 30 mListener = listener;
29 this.context = context; 31 this.context = context;
  32 + this.mOnDismissListener = mOnDismissListener;
30 } 33 }
31 34
32 @Override 35 @Override
@@ -39,9 +42,9 @@ class MyEventRecyclerViewAdapter extends RecyclerView.Adapter&lt;MyEventRecyclerVie @@ -39,9 +42,9 @@ class MyEventRecyclerViewAdapter extends RecyclerView.Adapter&lt;MyEventRecyclerVie
39 @Override 42 @Override
40 public void onBindViewHolder(final ViewHolder holder, int position) { 43 public void onBindViewHolder(final ViewHolder holder, int position) {
41 holder.mItem = mEvents.get(position); 44 holder.mItem = mEvents.get(position);
42 - holder.mContentView.setText(mEvents.get(position).getNomEvent());  
43 - holder.mPriceView.setText(String.format(Locale.US, "%.2f", mEvents.get(position).getPrice()));  
44 - holder.mId = mEvents.get(position).getIdEvent(); 45 + holder.mContentView.setText(mEvents.get(position).getNom());
  46 + holder.mPriceView.setText(String.format(Locale.US, "%.2f", mEvents.get(position).getPrix()));
  47 + holder.mId = mEvents.get(position).getId();
45 48
46 holder.mView.setOnClickListener(new View.OnClickListener() { 49 holder.mView.setOnClickListener(new View.OnClickListener() {
47 @Override 50 @Override
@@ -65,10 +68,12 @@ class MyEventRecyclerViewAdapter extends RecyclerView.Adapter&lt;MyEventRecyclerVie @@ -65,10 +68,12 @@ class MyEventRecyclerViewAdapter extends RecyclerView.Adapter&lt;MyEventRecyclerVie
65 switch (item.getItemId()) { 68 switch (item.getItemId()) {
66 case R.id.delete: 69 case R.id.delete:
67 DeleteEvent deleteEvent = DeleteEvent.newInstance(holder.mItem); 70 DeleteEvent deleteEvent = DeleteEvent.newInstance(holder.mItem);
  71 + deleteEvent.setOnDismissListener(mOnDismissListener);
68 deleteEvent.show(((AppCompatActivity) context).getSupportFragmentManager(), "deleteConsommation"); 72 deleteEvent.show(((AppCompatActivity) context).getSupportFragmentManager(), "deleteConsommation");
69 break; 73 break;
70 case R.id.modify: 74 case R.id.modify:
71 ModifyEvent modifyEvent = ModifyEvent.newInstance(holder.mItem); 75 ModifyEvent modifyEvent = ModifyEvent.newInstance(holder.mItem);
  76 + modifyEvent.setOnDismissListener(mOnDismissListener);
72 modifyEvent.show(((AppCompatActivity) context).getSupportFragmentManager(), "modifyConsommation"); 77 modifyEvent.show(((AppCompatActivity) context).getSupportFragmentManager(), "modifyConsommation");
73 break; 78 break;
74 } 79 }
app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/PaiementEvent.java
@@ -65,10 +65,10 @@ public class PaiementEvent extends DialogFragment implements NFCSupport { @@ -65,10 +65,10 @@ public class PaiementEvent extends DialogFragment implements NFCSupport {
65 Event event = (Event) getArguments().getSerializable("event"); 65 Event event = (Event) getArguments().getSerializable("event");
66 assert event != null; 66 assert event != null;
67 67
68 - mPaiementEventName.setText(event.getNomEvent());  
69 - mPaiementEventPrice.setText(String.format(Locale.US, "%.2f โ‚ฌ", event.getPrice())); 68 + mPaiementEventName.setText(event.getNom());
  69 + mPaiementEventPrice.setText(String.format(Locale.US, "%.2f โ‚ฌ", event.getPrix()));
70 70
71 - eventId = event.getIdEvent(); 71 + eventId = event.getId();
72 72
73 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 73 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
74 builder 74 builder
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/DeletePersonne.java
@@ -31,6 +31,9 @@ import java.util.Map; @@ -31,6 +31,9 @@ import java.util.Map;
31 31
32 public class DeletePersonne extends DialogFragment { 32 public class DeletePersonne extends DialogFragment {
33 33
  34 + private DialogInterface.OnDismissListener onDismissListener;
  35 +
  36 +
34 ProgressBar mProgressBar; 37 ProgressBar mProgressBar;
35 38
36 public DeletePersonne() { 39 public DeletePersonne() {
@@ -120,4 +123,16 @@ public class DeletePersonne extends DialogFragment { @@ -120,4 +123,16 @@ public class DeletePersonne extends DialogFragment {
120 super.onStop(); 123 super.onStop();
121 } 124 }
122 125
  126 + public void setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) {
  127 + this.onDismissListener = onDismissListener;
  128 + }
  129 +
  130 + @Override
  131 + public void onDismiss(DialogInterface dialog) {
  132 + super.onDismiss(dialog);
  133 + if (onDismissListener != null) {
  134 + onDismissListener.onDismiss(dialog);
  135 + }
  136 + }
  137 +
123 } 138 }
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/ModifyPersonne.java
@@ -50,6 +50,8 @@ import java.util.Map; @@ -50,6 +50,8 @@ import java.util.Map;
50 50
51 public class ModifyPersonne extends DialogFragment implements NFCSupport { 51 public class ModifyPersonne extends DialogFragment implements NFCSupport {
52 52
  53 + private DialogInterface.OnDismissListener onDismissListener;
  54 +
53 Calendar myCalendar = Calendar.getInstance(); 55 Calendar myCalendar = Calendar.getInstance();
54 56
55 EditText mCarte; 57 EditText mCarte;
@@ -275,4 +277,17 @@ public class ModifyPersonne extends DialogFragment implements NFCSupport { @@ -275,4 +277,17 @@ public class ModifyPersonne extends DialogFragment implements NFCSupport {
275 public void processNFC(String idCard) { 277 public void processNFC(String idCard) {
276 mCarte.setText(idCard); 278 mCarte.setText(idCard);
277 } 279 }
  280 +
  281 + public void setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) {
  282 + this.onDismissListener = onDismissListener;
  283 + }
  284 +
  285 + @Override
  286 + public void onDismiss(DialogInterface dialog) {
  287 + super.onDismiss(dialog);
  288 + if (onDismissListener != null) {
  289 + onDismissListener.onDismiss(dialog);
  290 + }
  291 + }
  292 +
278 } 293 }
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/MyPersonneRecyclerViewAdapter.java
1 package net.plil.clubinfo.etunicorn.app.personne; 1 package net.plil.clubinfo.etunicorn.app.personne;
2 2
3 import android.content.Context; 3 import android.content.Context;
  4 +import android.content.DialogInterface;
4 import android.support.v7.app.AppCompatActivity; 5 import android.support.v7.app.AppCompatActivity;
5 import android.support.v7.widget.PopupMenu; 6 import android.support.v7.widget.PopupMenu;
6 import android.support.v7.widget.RecyclerView; 7 import android.support.v7.widget.RecyclerView;
@@ -18,15 +19,18 @@ import java.util.Locale; @@ -18,15 +19,18 @@ import java.util.Locale;
18 19
19 class MyPersonneRecyclerViewAdapter extends RecyclerView.Adapter<MyPersonneRecyclerViewAdapter.ViewHolder> { 20 class MyPersonneRecyclerViewAdapter extends RecyclerView.Adapter<MyPersonneRecyclerViewAdapter.ViewHolder> {
20 21
  22 + private DialogInterface.OnDismissListener mOnDismissListener;
  23 +
21 private final List<Personne> mValues; 24 private final List<Personne> mValues;
22 private final PersonneFragment.OnListFragmentInteractionListener mListener; 25 private final PersonneFragment.OnListFragmentInteractionListener mListener;
23 private final Context context; 26 private final Context context;
24 27
25 28
26 - MyPersonneRecyclerViewAdapter(List<Personne> items, PersonneFragment.OnListFragmentInteractionListener listener, Context context) { 29 + MyPersonneRecyclerViewAdapter(List<Personne> items, PersonneFragment.OnListFragmentInteractionListener listener, Context context, DialogInterface.OnDismissListener mOnDismissListener) {
27 mValues = items; 30 mValues = items;
28 mListener = listener; 31 mListener = listener;
29 this.context = context; 32 this.context = context;
  33 + this.mOnDismissListener = mOnDismissListener;
30 } 34 }
31 35
32 @Override 36 @Override
@@ -66,10 +70,12 @@ class MyPersonneRecyclerViewAdapter extends RecyclerView.Adapter&lt;MyPersonneRecyc @@ -66,10 +70,12 @@ class MyPersonneRecyclerViewAdapter extends RecyclerView.Adapter&lt;MyPersonneRecyc
66 switch (item.getItemId()) { 70 switch (item.getItemId()) {
67 case R.id.delete: 71 case R.id.delete:
68 DeletePersonne deletePersonne = DeletePersonne.newInstance(holder.mItem); 72 DeletePersonne deletePersonne = DeletePersonne.newInstance(holder.mItem);
  73 + deletePersonne.setOnDismissListener(mOnDismissListener);
69 deletePersonne.show(((AppCompatActivity) context).getSupportFragmentManager(), context.getString(R.string.tag_delete_personne)); 74 deletePersonne.show(((AppCompatActivity) context).getSupportFragmentManager(), context.getString(R.string.tag_delete_personne));
70 break; 75 break;
71 case R.id.modify: 76 case R.id.modify:
72 ModifyPersonne modifyPersonne = ModifyPersonne.newInstance(holder.mItem); 77 ModifyPersonne modifyPersonne = ModifyPersonne.newInstance(holder.mItem);
  78 + modifyPersonne.setOnDismissListener(mOnDismissListener);
73 modifyPersonne.show(((AppCompatActivity) context).getSupportFragmentManager(), context.getString(R.string.tag_modify_personne)); 79 modifyPersonne.show(((AppCompatActivity) context).getSupportFragmentManager(), context.getString(R.string.tag_modify_personne));
74 break; 80 break;
75 } 81 }
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/PersonneFragment.java
@@ -40,7 +40,7 @@ import java.util.Map; @@ -40,7 +40,7 @@ import java.util.Map;
40 * Activities containing this fragment MUST implement the {@link OnListFragmentInteractionListener} 40 * Activities containing this fragment MUST implement the {@link OnListFragmentInteractionListener}
41 * interface. 41 * interface.
42 */ 42 */
43 -public class PersonneFragment extends Fragment implements NFCSupport { 43 +public class PersonneFragment extends Fragment implements NFCSupport, DialogInterface.OnDismissListener {
44 44
45 private OnListFragmentInteractionListener mListener; 45 private OnListFragmentInteractionListener mListener;
46 private ArrayList<Personne> personnes = new ArrayList<>(); 46 private ArrayList<Personne> personnes = new ArrayList<>();
@@ -72,9 +72,9 @@ public class PersonneFragment extends Fragment implements NFCSupport { @@ -72,9 +72,9 @@ public class PersonneFragment extends Fragment implements NFCSupport {
72 Context context = view.getContext(); 72 Context context = view.getContext();
73 RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.personne_list); 73 RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.personne_list);
74 recyclerView.setLayoutManager(new LinearLayoutManager(context)); 74 recyclerView.setLayoutManager(new LinearLayoutManager(context));
75 - mAdapter = new MyPersonneRecyclerViewAdapter(personnes, mListener, getActivity()); 75 + mAdapter = new MyPersonneRecyclerViewAdapter(personnes, mListener, getActivity(), this);
76 recyclerView.setAdapter(mAdapter); 76 recyclerView.setAdapter(mAdapter);
77 - setPersonnes(); 77 + updatePersonnes();
78 FloatingActionButton fAB = (FloatingActionButton) view.findViewById(R.id.personne_add); 78 FloatingActionButton fAB = (FloatingActionButton) view.findViewById(R.id.personne_add);
79 fAB.setOnClickListener(new View.OnClickListener() { 79 fAB.setOnClickListener(new View.OnClickListener() {
80 @Override 80 @Override
@@ -83,7 +83,7 @@ public class PersonneFragment extends Fragment implements NFCSupport { @@ -83,7 +83,7 @@ public class PersonneFragment extends Fragment implements NFCSupport {
83 newFragment.setOnDismissListener(new DialogInterface.OnDismissListener() { 83 newFragment.setOnDismissListener(new DialogInterface.OnDismissListener() {
84 @Override 84 @Override
85 public void onDismiss(DialogInterface dialog) { 85 public void onDismiss(DialogInterface dialog) {
86 - setPersonnes(); 86 + updatePersonnes();
87 } 87 }
88 }); 88 });
89 newFragment.show(getFragmentManager(), getString(R.string.tag_create_personne)); 89 newFragment.show(getFragmentManager(), getString(R.string.tag_create_personne));
@@ -94,7 +94,7 @@ public class PersonneFragment extends Fragment implements NFCSupport { @@ -94,7 +94,7 @@ public class PersonneFragment extends Fragment implements NFCSupport {
94 mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 94 mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
95 @Override 95 @Override
96 public void onRefresh() { 96 public void onRefresh() {
97 - setPersonnes(); 97 + updatePersonnes();
98 } 98 }
99 }); 99 });
100 100
@@ -119,7 +119,7 @@ public class PersonneFragment extends Fragment implements NFCSupport { @@ -119,7 +119,7 @@ public class PersonneFragment extends Fragment implements NFCSupport {
119 mListener = null; 119 mListener = null;
120 } 120 }
121 121
122 - private void setPersonnes() { 122 + private void updatePersonnes() {
123 JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, VolleyUtils.baseUri + "/personne", null, new Response.Listener<JSONArray>() { 123 JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, VolleyUtils.baseUri + "/personne", null, new Response.Listener<JSONArray>() {
124 @Override 124 @Override
125 public void onResponse(JSONArray response) { 125 public void onResponse(JSONArray response) {
@@ -170,6 +170,11 @@ public class PersonneFragment extends Fragment implements NFCSupport { @@ -170,6 +170,11 @@ public class PersonneFragment extends Fragment implements NFCSupport {
170 170
171 } 171 }
172 172
  173 + @Override
  174 + public void onDismiss(DialogInterface dialog) {
  175 + updatePersonnes();
  176 + }
  177 +
173 /** 178 /**
174 * This interface must be implemented by activities that contain this 179 * This interface must be implemented by activities that contain this
175 * fragment to allow an interaction in this fragment to be communicated 180 * fragment to allow an interaction in this fragment to be communicated
app/src/main/java/net/plil/clubinfo/etunicorn/data/Event.java
@@ -9,36 +9,36 @@ import java.util.Date; @@ -9,36 +9,36 @@ import java.util.Date;
9 9
10 public class Event implements Serializable{ 10 public class Event implements Serializable{
11 11
12 - private int idEvent;  
13 - private String nomEvent;  
14 - private double price; 12 + private int id;
  13 + private String nom;
  14 + private double prix;
15 private Date date; 15 private Date date;
16 16
17 public Event() { 17 public Event() {
18 } 18 }
19 19
20 - public int getIdEvent() {  
21 - return idEvent; 20 + public int getId() {
  21 + return id;
22 } 22 }
23 23
24 - public void setIdEvent(int idEvent) {  
25 - this.idEvent = idEvent; 24 + public void setId(int id) {
  25 + this.id = id;
26 } 26 }
27 27
28 - public String getNomEvent() {  
29 - return nomEvent; 28 + public String getNom() {
  29 + return nom;
30 } 30 }
31 31
32 - public void setNomEvent(String nomEvent) {  
33 - this.nomEvent = nomEvent; 32 + public void setNom(String nom) {
  33 + this.nom = nom;
34 } 34 }
35 35
36 - public double getPrice() {  
37 - return price; 36 + public double getPrix() {
  37 + return prix;
38 } 38 }
39 39
40 - public void setPrice(double price) {  
41 - this.price = price; 40 + public void setPrix(double prix) {
  41 + this.prix = prix;
42 } 42 }
43 43
44 public Date getDate() { 44 public Date getDate() {
app/src/main/res/layout/fragment_event.xml
1 <?xml version="1.0" encoding="utf-8"?> 1 <?xml version="1.0" encoding="utf-8"?>
2 -<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
3 - android:layout_width="wrap_content" 2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="match_parent"
4 android:layout_height="wrap_content" 4 android:layout_height="wrap_content"
5 xmlns:tools="http://schemas.android.com/tools" 5 xmlns:tools="http://schemas.android.com/tools"
6 android:orientation="horizontal" 6 android:orientation="horizontal"
@@ -8,30 +8,30 @@ @@ -8,30 +8,30 @@
8 8
9 <TextView 9 <TextView
10 android:id="@+id/event_name" 10 android:id="@+id/event_name"
11 - android:layout_width="wrap_content" 11 + android:layout_width="match_parent"
12 android:layout_height="wrap_content" 12 android:layout_height="wrap_content"
  13 + android:layout_weight="17"
13 android:layout_margin="@dimen/text_margin" 14 android:layout_margin="@dimen/text_margin"
14 android:textAppearance="?attr/textAppearanceListItem" /> 15 android:textAppearance="?attr/textAppearanceListItem" />
15 16
16 <TextView 17 <TextView
17 android:id="@+id/event_price" 18 android:id="@+id/event_price"
18 - android:layout_width="wrap_content" 19 + android:layout_width="match_parent"
19 android:layout_height="wrap_content" 20 android:layout_height="wrap_content"
20 android:layout_margin="@dimen/text_margin" 21 android:layout_margin="@dimen/text_margin"
21 - android:textAppearance="?attr/textAppearanceListItem"  
22 - android:layout_toRightOf="@id/event_name"/> 22 + android:layout_weight="7"
  23 + android:textAppearance="?attr/textAppearanceListItem" />
23 24
24 <TextView 25 <TextView
25 android:id="@+id/event_options" 26 android:id="@+id/event_options"
26 - android:layout_width="wrap_content"  
27 - android:layout_height="match_parent"  
28 - android:layout_alignParentRight="true" 27 + android:layout_width="match_parent"
  28 + android:layout_height="wrap_content"
  29 + android:layout_weight="20"
  30 + android:layout_margin="@dimen/text_margin"
29 android:paddingRight="@dimen/activity_horizontal_margin" 31 android:paddingRight="@dimen/activity_horizontal_margin"
30 - android:layout_alignParentTop="true"  
31 android:paddingLeft="@dimen/activity_horizontal_margin" 32 android:paddingLeft="@dimen/activity_horizontal_margin"
32 android:text="&#8942;" 33 android:text="&#8942;"
33 android:textAppearance="?android:textAppearanceLarge" 34 android:textAppearance="?android:textAppearanceLarge"
34 tools:ignore="RtlHardcoded,RtlSymmetry" 35 tools:ignore="RtlHardcoded,RtlSymmetry"
35 - android:textStyle="normal|bold"  
36 - android:translationY="10dp" />  
37 -</RelativeLayout> 36 + android:textStyle="normal|bold" />
  37 +</LinearLayout>
app/src/main/res/layout/fragment_event_list.xml
@@ -6,17 +6,22 @@ @@ -6,17 +6,22 @@
6 android:layout_width="match_parent" 6 android:layout_width="match_parent"
7 android:layout_height="match_parent"> 7 android:layout_height="match_parent">
8 8
9 - <android.support.v7.widget.RecyclerView  
10 - android:id="@+id/event_list"  
11 - android:name="net.plil.clubinfo.etunicorn.app.event.EventFragment" 9 + <android.support.v4.widget.SwipeRefreshLayout
  10 + android:id="@+id/event_swipeRefresh"
12 android:layout_width="match_parent" 11 android:layout_width="match_parent"
13 - android:layout_height="match_parent"  
14 - android:layout_marginLeft="16dp"  
15 - android:layout_marginRight="16dp"  
16 - app:layoutManager="LinearLayoutManager"  
17 - tools:context="net.plil.clubinfo.etunicorn.app.event.EventFragment"  
18 - tools:listitem="@layout/fragment_event"  
19 - /> 12 + android:layout_height="match_parent">
  13 + <android.support.v7.widget.RecyclerView
  14 + android:id="@+id/event_list"
  15 + android:name="net.plil.clubinfo.etunicorn.app.event.EventFragment"
  16 + android:layout_width="match_parent"
  17 + android:layout_height="match_parent"
  18 + android:layout_marginLeft="16dp"
  19 + android:layout_marginRight="16dp"
  20 + app:layoutManager="LinearLayoutManager"
  21 + tools:context="net.plil.clubinfo.etunicorn.app.event.EventFragment"
  22 + tools:listitem="@layout/fragment_event"
  23 + />
  24 + </android.support.v4.widget.SwipeRefreshLayout>
20 25
21 <android.support.design.widget.FloatingActionButton 26 <android.support.design.widget.FloatingActionButton
22 android:layout_width="wrap_content" 27 android:layout_width="wrap_content"