Commit d0df00ab3ee4883b96a4d37bfe6f8769cca1daf4

Authored by badetitou
1 parent 515eb393

Cleaning code

app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/EventFragment.java
@@ -116,6 +116,5 @@ public class EventFragment extends Fragment implements NFCSupport { @@ -116,6 +116,5 @@ public class EventFragment extends Fragment implements NFCSupport {
116 */ 116 */
117 public interface OnListFragmentInteractionListener { 117 public interface OnListFragmentInteractionListener {
118 void onListFragmentInteraction(Event item); 118 void onListFragmentInteraction(Event item);
119 - void onListFragmentInteractionLong(Event item);  
120 } 119 }
121 } 120 }
app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/MyEventRecyclerViewAdapter.java
@@ -52,14 +52,6 @@ public class MyEventRecyclerViewAdapter extends RecyclerView.Adapter<MyEventRecy @@ -52,14 +52,6 @@ public class MyEventRecyclerViewAdapter extends RecyclerView.Adapter<MyEventRecy
52 } 52 }
53 }); 53 });
54 54
55 - holder.mView.setOnLongClickListener(new View.OnLongClickListener() {  
56 - @Override  
57 - public boolean onLongClick(View v) {  
58 - mListener.onListFragmentInteractionLong(holder.mItem);  
59 - return true;  
60 - }  
61 - });  
62 -  
63 holder.mButtonView.setOnClickListener(new View.OnClickListener() { 55 holder.mButtonView.setOnClickListener(new View.OnClickListener() {
64 @Override 56 @Override
65 public void onClick(View v) { 57 public void onClick(View v) {
app/src/main/java/net/plil/clubinfo/etunicorn/app/MainActivity.java
@@ -36,8 +36,7 @@ import net.plil.clubinfo.etunicorn.utils.ConvertBytesToString; @@ -36,8 +36,7 @@ import net.plil.clubinfo.etunicorn.utils.ConvertBytesToString;
36 public class MainActivity extends AppCompatActivity 36 public class MainActivity extends AppCompatActivity
37 implements FragmentConsommation.OnListFragmentInteractionListener, 37 implements FragmentConsommation.OnListFragmentInteractionListener,
38 EventFragment.OnListFragmentInteractionListener, 38 EventFragment.OnListFragmentInteractionListener,
39 - PersonneFragment.OnListFragmentInteractionListener,  
40 - PersonOverviewFragment.OnFragmentInteractionListener 39 + PersonneFragment.OnListFragmentInteractionListener
41 { 40 {
42 41
43 /** 42 /**
@@ -172,38 +171,18 @@ public class MainActivity extends AppCompatActivity @@ -172,38 +171,18 @@ public class MainActivity extends AppCompatActivity
172 } 171 }
173 172
174 @Override 173 @Override
175 - public void onListFragmentInteractionLong(Consommation consommation) {  
176 -  
177 - }  
178 -  
179 - @Override  
180 public void onListFragmentInteraction(Event item) { 174 public void onListFragmentInteraction(Event item) {
181 PaiementEvent paiementEvent = PaiementEvent.newInstance(item); 175 PaiementEvent paiementEvent = PaiementEvent.newInstance(item);
182 paiementEvent.show(getSupportFragmentManager(), "paiementEvent"); 176 paiementEvent.show(getSupportFragmentManager(), "paiementEvent");
183 } 177 }
184 178
185 @Override 179 @Override
186 - public void onListFragmentInteractionLong(Event item) {  
187 -  
188 - }  
189 -  
190 - @Override  
191 public void onListFragmentInteraction(Personne personne) { 180 public void onListFragmentInteraction(Personne personne) {
192 PersonOverviewFragment personOverviewFragment = PersonOverviewFragment.newInstance(personne); 181 PersonOverviewFragment personOverviewFragment = PersonOverviewFragment.newInstance(personne);
193 personOverviewFragment.show(getSupportFragmentManager(), "overviewPersonne"); 182 personOverviewFragment.show(getSupportFragmentManager(), "overviewPersonne");
194 183
195 } 184 }
196 185
197 - @Override  
198 - public void onListFragmentInteractionLong(Personne personne) {  
199 -  
200 - }  
201 -  
202 - @Override  
203 - public void onFragmentInteraction(Uri uri) {  
204 -  
205 - }  
206 -  
207 /** 186 /**
208 * A {@link FragmentPagerAdapter} that returns a fragment corresponding to 187 * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
209 * one of the sections/tabs/pages. 188 * one of the sections/tabs/pages.
app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/ConsommationRecyclerViewAdapter.java
@@ -55,14 +55,6 @@ public class ConsommationRecyclerViewAdapter extends RecyclerView.Adapter<Consom @@ -55,14 +55,6 @@ public class ConsommationRecyclerViewAdapter extends RecyclerView.Adapter<Consom
55 } 55 }
56 }); 56 });
57 57
58 - holder.mView.setOnLongClickListener(new View.OnLongClickListener() {  
59 - @Override  
60 - public boolean onLongClick(View v) {  
61 - mListener.onListFragmentInteractionLong(holder.mItem);  
62 - return true;  
63 - }  
64 - });  
65 -  
66 holder.mButtonMenu.setOnClickListener(new View.OnClickListener() { 58 holder.mButtonMenu.setOnClickListener(new View.OnClickListener() {
67 @Override 59 @Override
68 public void onClick(View v) { 60 public void onClick(View v) {
app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/FragmentConsommation.java
@@ -122,6 +122,5 @@ public class FragmentConsommation extends Fragment implements NFCSupport { @@ -122,6 +122,5 @@ public class FragmentConsommation extends Fragment implements NFCSupport {
122 */ 122 */
123 public interface OnListFragmentInteractionListener { 123 public interface OnListFragmentInteractionListener {
124 void onListFragmentInteraction(Consommation item); 124 void onListFragmentInteraction(Consommation item);
125 - void onListFragmentInteractionLong(Consommation item);  
126 } 125 }
127 } 126 }
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/CreatePersonne.java
@@ -48,6 +48,7 @@ import java.util.Map; @@ -48,6 +48,7 @@ import java.util.Map;
48 48
49 public class CreatePersonne extends DialogFragment implements NFCSupport { 49 public class CreatePersonne extends DialogFragment implements NFCSupport {
50 50
  51 + private DialogInterface.OnDismissListener onDismissListener;
51 52
52 Calendar myCalendar = Calendar.getInstance(); 53 Calendar myCalendar = Calendar.getInstance();
53 54
@@ -124,8 +125,10 @@ public class CreatePersonne extends DialogFragment implements NFCSupport { @@ -124,8 +125,10 @@ public class CreatePersonne extends DialogFragment implements NFCSupport {
124 mRole.setVisibility(View.GONE); 125 mRole.setVisibility(View.GONE);
125 JSONObject jsonObject = new JSONObject(); 126 JSONObject jsonObject = new JSONObject();
126 try { 127 try {
127 - jsonObject.put("login", mLogin.getText().toString());  
128 - jsonObject.put("carte", mCarte.getText().toString()); 128 + if (!mLogin.getText().toString().isEmpty())
  129 + jsonObject.put("login", mLogin.getText().toString());
  130 + if(!mCarte.getText().toString().isEmpty())
  131 + jsonObject.put("carte", mCarte.getText().toString());
129 jsonObject.put("role", JsonConverter.convertToJSONObject(mRole.getSelectedItem())); 132 jsonObject.put("role", JsonConverter.convertToJSONObject(mRole.getSelectedItem()));
130 if (!mNaissance.getSelectedItem().equals(getString(R.string.create_personne_naissance))) 133 if (!mNaissance.getSelectedItem().equals(getString(R.string.create_personne_naissance)))
131 jsonObject.put("naissance", mNaissance.getSelectedItem()); 134 jsonObject.put("naissance", mNaissance.getSelectedItem());
@@ -136,7 +139,6 @@ public class CreatePersonne extends DialogFragment implements NFCSupport { @@ -136,7 +139,6 @@ public class CreatePersonne extends DialogFragment implements NFCSupport {
136 @Override 139 @Override
137 public void onResponse(JSONObject response) { 140 public void onResponse(JSONObject response) {
138 mProgressBar.setVisibility(View.GONE); 141 mProgressBar.setVisibility(View.GONE);
139 - Toast.makeText(getContext(), response.toString(), Toast.LENGTH_LONG).show();  
140 dismiss(); 142 dismiss();
141 } 143 }
142 }, new Response.ErrorListener() { 144 }, new Response.ErrorListener() {
@@ -241,4 +243,17 @@ public class CreatePersonne extends DialogFragment implements NFCSupport { @@ -241,4 +243,17 @@ public class CreatePersonne extends DialogFragment implements NFCSupport {
241 public void processNFC(String idCard) { 243 public void processNFC(String idCard) {
242 mCarte.setText(idCard); 244 mCarte.setText(idCard);
243 } 245 }
  246 +
  247 +
  248 + public void setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) {
  249 + this.onDismissListener = onDismissListener;
  250 + }
  251 +
  252 + @Override
  253 + public void onDismiss(DialogInterface dialog) {
  254 + super.onDismiss(dialog);
  255 + if (onDismissListener != null) {
  256 + onDismissListener.onDismiss(dialog);
  257 + }
  258 + }
244 } 259 }
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/MyPersonneRecyclerViewAdapter.java
@@ -53,14 +53,6 @@ public class MyPersonneRecyclerViewAdapter extends RecyclerView.Adapter<MyPerson @@ -53,14 +53,6 @@ public class MyPersonneRecyclerViewAdapter extends RecyclerView.Adapter<MyPerson
53 } 53 }
54 }); 54 });
55 55
56 - holder.mView.setOnLongClickListener(new View.OnLongClickListener() {  
57 - @Override  
58 - public boolean onLongClick(View v) {  
59 - mListener.onListFragmentInteractionLong(holder.mItem);  
60 - return true;  
61 - }  
62 - });  
63 -  
64 holder.mButton.setOnClickListener(new View.OnClickListener() { 56 holder.mButton.setOnClickListener(new View.OnClickListener() {
65 @Override 57 @Override
66 public void onClick(View v) { 58 public void onClick(View v) {
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/PersonOverviewFragment.java
@@ -26,8 +26,6 @@ import java.util.Locale; @@ -26,8 +26,6 @@ import java.util.Locale;
26 */ 26 */
27 public class PersonOverviewFragment extends DialogFragment{ 27 public class PersonOverviewFragment extends DialogFragment{
28 28
29 - private OnFragmentInteractionListener mListener;  
30 -  
31 TextView mCarte; 29 TextView mCarte;
32 TextView mNaissance; 30 TextView mNaissance;
33 TextView mSolde; 31 TextView mSolde;
@@ -80,27 +78,4 @@ public class PersonOverviewFragment extends DialogFragment{ @@ -80,27 +78,4 @@ public class PersonOverviewFragment extends DialogFragment{
80 return inflater.inflate(R.layout.fragment_person_overview, container, false); 78 return inflater.inflate(R.layout.fragment_person_overview, container, false);
81 } 79 }
82 80
83 -  
84 - @Override  
85 - public void onAttach(Context context) {  
86 - super.onAttach(context);  
87 - if (context instanceof OnFragmentInteractionListener) {  
88 - mListener = (OnFragmentInteractionListener) context;  
89 - } else {  
90 - throw new RuntimeException(context.toString()  
91 - + " must implement OnFragmentInteractionListener");  
92 - }  
93 - }  
94 -  
95 - @Override  
96 - public void onDetach() {  
97 - super.onDetach();  
98 - mListener = null;  
99 - }  
100 -  
101 -  
102 - public interface OnFragmentInteractionListener {  
103 - // TODO: Update argument type and name  
104 - void onFragmentInteraction(Uri uri);  
105 - }  
106 } 81 }
app/src/main/java/net/plil/clubinfo/etunicorn/app/personne/PersonneFragment.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.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;
@@ -43,6 +45,7 @@ public class PersonneFragment extends Fragment implements NFCSupport { @@ -43,6 +45,7 @@ public class PersonneFragment extends Fragment implements NFCSupport {
43 private OnListFragmentInteractionListener mListener; 45 private OnListFragmentInteractionListener mListener;
44 private ArrayList<Personne> personnes = new ArrayList<>(); 46 private ArrayList<Personne> personnes = new ArrayList<>();
45 private RecyclerView.Adapter mAdapter; 47 private RecyclerView.Adapter mAdapter;
  48 + private SwipeRefreshLayout mSwipeRefreshLayout;
46 49
47 /** 50 /**
48 * Mandatory empty constructor for the fragment manager to instantiate the 51 * Mandatory empty constructor for the fragment manager to instantiate the
@@ -77,10 +80,24 @@ public class PersonneFragment extends Fragment implements NFCSupport { @@ -77,10 +80,24 @@ public class PersonneFragment extends Fragment implements NFCSupport {
77 @Override 80 @Override
78 public void onClick(View v) { 81 public void onClick(View v) {
79 CreatePersonne newFragment = new CreatePersonne(); 82 CreatePersonne newFragment = new CreatePersonne();
  83 + newFragment.setOnDismissListener(new DialogInterface.OnDismissListener() {
  84 + @Override
  85 + public void onDismiss(DialogInterface dialog) {
  86 + setPersonnes();
  87 + }
  88 + });
80 newFragment.show(getFragmentManager(), getString(R.string.tag_create_personne)); 89 newFragment.show(getFragmentManager(), getString(R.string.tag_create_personne));
81 } 90 }
82 }); 91 });
83 92
  93 + mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.personne_swipeRefresh);
  94 + mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
  95 + @Override
  96 + public void onRefresh() {
  97 + setPersonnes();
  98 + }
  99 + });
  100 +
84 return view; 101 return view;
85 } 102 }
86 103
@@ -112,6 +129,7 @@ public class PersonneFragment extends Fragment implements NFCSupport { @@ -112,6 +129,7 @@ public class PersonneFragment extends Fragment implements NFCSupport {
112 personnes.add(JsonConverter.getConverter().fromJson(String.valueOf(response.getJSONObject(i)), Personne.class)); 129 personnes.add(JsonConverter.getConverter().fromJson(String.valueOf(response.getJSONObject(i)), Personne.class));
113 } 130 }
114 mAdapter.notifyDataSetChanged(); 131 mAdapter.notifyDataSetChanged();
  132 + mSwipeRefreshLayout.setRefreshing(false);
115 } catch (JSONException e) { 133 } catch (JSONException e) {
116 e.printStackTrace(); 134 e.printStackTrace();
117 } 135 }
@@ -120,7 +138,10 @@ public class PersonneFragment extends Fragment implements NFCSupport { @@ -120,7 +138,10 @@ public class PersonneFragment extends Fragment implements NFCSupport {
120 }, new Response.ErrorListener() { 138 }, new Response.ErrorListener() {
121 @Override 139 @Override
122 public void onErrorResponse(VolleyError error) { 140 public void onErrorResponse(VolleyError error) {
123 - Toast.makeText(getContext(), ConvertBytesToString.bytesToStringVolLey(error.networkResponse.data), Toast.LENGTH_LONG).show(); 141 + if (error.networkResponse == null)
  142 + Toast.makeText(getActivity(), "Unknow error SORRY", Toast.LENGTH_LONG).show();
  143 + else
  144 + Toast.makeText(getActivity(), ConvertBytesToString.bytesToStringVolLey(error.networkResponse.data), Toast.LENGTH_LONG).show();
124 } 145 }
125 } 146 }
126 ) { 147 ) {
@@ -158,8 +179,6 @@ public class PersonneFragment extends Fragment implements NFCSupport { @@ -158,8 +179,6 @@ public class PersonneFragment extends Fragment implements NFCSupport {
158 * >Communicating with Other Fragments</a> for more information. 179 * >Communicating with Other Fragments</a> for more information.
159 */ 180 */
160 public interface OnListFragmentInteractionListener { 181 public interface OnListFragmentInteractionListener {
161 - // TODO: Update argument type and name  
162 void onListFragmentInteraction(Personne personne); 182 void onListFragmentInteraction(Personne personne);
163 - void onListFragmentInteractionLong(Personne personne);  
164 } 183 }
165 } 184 }
app/src/main/res/layout/fragment_personne_list.xml
@@ -5,6 +5,12 @@ @@ -5,6 +5,12 @@
5 android:layout_width="match_parent" 5 android:layout_width="match_parent"
6 android:layout_height="match_parent"> 6 android:layout_height="match_parent">
7 7
  8 + <android.support.v4.widget.SwipeRefreshLayout
  9 + android:id="@+id/personne_swipeRefresh"
  10 + android:layout_width="match_parent"
  11 + android:layout_height="match_parent">
  12 +
  13 +
8 <android.support.v7.widget.RecyclerView 14 <android.support.v7.widget.RecyclerView
9 android:id="@+id/personne_list" 15 android:id="@+id/personne_list"
10 android:name="net.plil.clubinfo.etunicorn.app.personne.PersonneFragment" 16 android:name="net.plil.clubinfo.etunicorn.app.personne.PersonneFragment"
@@ -15,7 +21,10 @@ @@ -15,7 +21,10 @@
15 app:layoutManager="LinearLayoutManager" 21 app:layoutManager="LinearLayoutManager"
16 tools:context="net.plil.clubinfo.etunicorn.app.personne.PersonneFragment" 22 tools:context="net.plil.clubinfo.etunicorn.app.personne.PersonneFragment"
17 tools:listitem="@layout/fragment_personne" 23 tools:listitem="@layout/fragment_personne"
  24 + android:scrollbars="vertical"
18 /> 25 />
  26 + </android.support.v4.widget.SwipeRefreshLayout>
  27 +
19 28
20 <android.support.design.widget.FloatingActionButton 29 <android.support.design.widget.FloatingActionButton
21 android:layout_width="wrap_content" 30 android:layout_width="wrap_content"