Commit f5506a08921ba0a497a4667502a76836ee3df5bc

Authored by badetitou
1 parent 3e933aa6

Fix error leave during payment

app/src/main/java/net/plil/clubinfo/etunicorn/app/Event/PaiementEvent.java
@@ -66,11 +66,13 @@ public class PaiementEvent extends DialogFragment { @@ -66,11 +66,13 @@ public class PaiementEvent extends DialogFragment {
66 .setView(view) 66 .setView(view)
67 .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { 67 .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
68 public void onClick(DialogInterface dialog, int id) { 68 public void onClick(DialogInterface dialog, int id) {
69 - // User cancelled the dialog 69 + VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll("PAYMENT");
70 } 70 }
71 }); 71 });
72 // Create the AlertDialog object and return it 72 // Create the AlertDialog object and return it
73 - return builder.create(); 73 + Dialog dialog = builder.create();
  74 + dialog.setCanceledOnTouchOutside(false);
  75 + return dialog;
74 } 76 }
75 77
76 78
@@ -101,6 +103,7 @@ public class PaiementEvent extends DialogFragment { @@ -101,6 +103,7 @@ public class PaiementEvent extends DialogFragment {
101 } 103 }
102 ); 104 );
103 105
  106 + jsonObjectRequest.setTag("PAYMENT");
104 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); 107 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
105 } 108 }
106 } 109 }
app/src/main/java/net/plil/clubinfo/etunicorn/app/MainActivity.java
@@ -63,7 +63,7 @@ public class MainActivity extends AppCompatActivity @@ -63,7 +63,7 @@ public class MainActivity extends AppCompatActivity
63 private Toolbar toolbar; 63 private Toolbar toolbar;
64 private AppBarLayout appBarLayout; 64 private AppBarLayout appBarLayout;
65 65
66 - private List<Consommation> consommationsToModify = new ArrayList<>(); 66 + private Personne p;
67 67
68 NfcAdapter mAdapter; 68 NfcAdapter mAdapter;
69 PendingIntent mPendingIntent; 69 PendingIntent mPendingIntent;
@@ -74,7 +74,7 @@ public class MainActivity extends AppCompatActivity @@ -74,7 +74,7 @@ public class MainActivity extends AppCompatActivity
74 74
75 // config tabbed pan 75 // config tabbed pan
76 Intent intent = this.getIntent(); 76 Intent intent = this.getIntent();
77 - Personne p = (Personne) intent.getSerializableExtra("user"); 77 + p = (Personne) intent.getSerializableExtra("user");
78 //TODO remove this line 78 //TODO remove this line
79 Toast.makeText(getApplicationContext(), p.getRole().getPermissions().get(0).getNom(), Toast.LENGTH_SHORT).show(); 79 Toast.makeText(getApplicationContext(), p.getRole().getPermissions().get(0).getNom(), Toast.LENGTH_SHORT).show();
80 if (p.getRole().getPermissions().get(0).getNom().equals("ROLE_ADMIN")){ 80 if (p.getRole().getPermissions().get(0).getNom().equals("ROLE_ADMIN")){
app/src/main/java/net/plil/clubinfo/etunicorn/app/consommation/PaiementConsommation.java
@@ -71,11 +71,14 @@ public class PaiementConsommation extends DialogFragment { @@ -71,11 +71,14 @@ public class PaiementConsommation extends DialogFragment {
71 .setView(view) 71 .setView(view)
72 .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { 72 .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
73 public void onClick(DialogInterface dialog, int id) { 73 public void onClick(DialogInterface dialog, int id) {
74 - // User cancelled the dialog 74 + VolleyUtils.getInstance(getContext()).getRequestQueue().cancelAll("PAYMENT");
75 } 75 }
76 }); 76 });
77 // Create the AlertDialog object and return it 77 // Create the AlertDialog object and return it
78 - return builder.create(); 78 +
  79 + Dialog dialog = builder.create();
  80 + dialog.setCanceledOnTouchOutside(false);
  81 + return dialog;
79 } 82 }
80 83
81 84
@@ -105,7 +108,7 @@ public class PaiementConsommation extends DialogFragment { @@ -105,7 +108,7 @@ public class PaiementConsommation extends DialogFragment {
105 } 108 }
106 } 109 }
107 ); 110 );
108 - 111 + jsonObjectRequest.setTag("PAYMENT");
109 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest); 112 VolleyUtils.getInstance(getContext()).addToRequestQueue(jsonObjectRequest);
110 } 113 }
111 } 114 }
app/src/main/java/net/plil/clubinfo/etunicorn/app/credit/Crediter.java
@@ -2,6 +2,8 @@ package net.plil.clubinfo.etunicorn.app.credit; @@ -2,6 +2,8 @@ package net.plil.clubinfo.etunicorn.app.credit;
2 2
3 import android.content.Context; 3 import android.content.Context;
4 import android.os.Bundle; 4 import android.os.Bundle;
  5 +import android.support.design.widget.CoordinatorLayout;
  6 +import android.support.design.widget.Snackbar;
5 import android.view.LayoutInflater; 7 import android.view.LayoutInflater;
6 import android.view.View; 8 import android.view.View;
7 import android.view.ViewGroup; 9 import android.view.ViewGroup;
@@ -15,6 +17,7 @@ import com.android.volley.toolbox.JsonObjectRequest; @@ -15,6 +17,7 @@ import com.android.volley.toolbox.JsonObjectRequest;
15 17
16 import net.plil.clubinfo.etunicorn.R; 18 import net.plil.clubinfo.etunicorn.R;
17 import net.plil.clubinfo.etunicorn.app.FragmentNFC; 19 import net.plil.clubinfo.etunicorn.app.FragmentNFC;
  20 +import net.plil.clubinfo.etunicorn.data.Personne;
18 import net.plil.clubinfo.etunicorn.utils.VolleyUtils; 21 import net.plil.clubinfo.etunicorn.utils.VolleyUtils;
19 22
20 import org.json.JSONException; 23 import org.json.JSONException;
@@ -24,6 +27,7 @@ public class Crediter extends FragmentNFC { @@ -24,6 +27,7 @@ public class Crediter extends FragmentNFC {
24 27
25 private EditText mMoneyEditText; 28 private EditText mMoneyEditText;
26 private ProgressBar mProgressBar; 29 private ProgressBar mProgressBar;
  30 + private CoordinatorLayout coordinatorLayout;
27 31
28 public Crediter() { 32 public Crediter() {
29 // Required empty public constructor 33 // Required empty public constructor
@@ -44,6 +48,7 @@ public class Crediter extends FragmentNFC { @@ -44,6 +48,7 @@ public class Crediter extends FragmentNFC {
44 View view = inflater.inflate(R.layout.fragment_crediter, container, false); 48 View view = inflater.inflate(R.layout.fragment_crediter, container, false);
45 mMoneyEditText = (EditText) view.findViewById(R.id.crediter_ask_money); 49 mMoneyEditText = (EditText) view.findViewById(R.id.crediter_ask_money);
46 mProgressBar = (ProgressBar) view.findViewById(R.id.crediter_progress_bar); 50 mProgressBar = (ProgressBar) view.findViewById(R.id.crediter_progress_bar);
  51 + coordinatorLayout = (CoordinatorLayout) view.findViewById(R.id.crediter_layout);
47 return view; 52 return view;
48 } 53 }
49 54
@@ -62,11 +67,17 @@ public class Crediter extends FragmentNFC { @@ -62,11 +67,17 @@ public class Crediter extends FragmentNFC {
62 67
63 @Override 68 @Override
64 public void processNFC(String idCardUser) { 69 public void processNFC(String idCardUser) {
  70 + if(mMoneyEditText.getText().toString().isEmpty()){
  71 + mMoneyEditText.setError(getString(R.string.error_enter_debit));
  72 + return;
  73 + }
65 mProgressBar.setVisibility(View.VISIBLE); 74 mProgressBar.setVisibility(View.VISIBLE);
  75 + mMoneyEditText.setVisibility(View.GONE);
66 JSONObject jsonObject = new JSONObject(); 76 JSONObject jsonObject = new JSONObject();
67 try { 77 try {
68 - jsonObject.put("participant", 1);  
69 - jsonObject.put("acteur", 2); 78 + Personne p = new Personne();
  79 + p.setIdCarte(idCardUser);
  80 + jsonObject.put("participant", p);
70 jsonObject.put("prix", Double.parseDouble(mMoneyEditText.getText().toString())); 81 jsonObject.put("prix", Double.parseDouble(mMoneyEditText.getText().toString()));
71 } catch (JSONException e){ 82 } catch (JSONException e){
72 e.printStackTrace(); 83 e.printStackTrace();
@@ -75,11 +86,16 @@ public class Crediter extends FragmentNFC { @@ -75,11 +86,16 @@ public class Crediter extends FragmentNFC {
75 @Override 86 @Override
76 public void onResponse(JSONObject response) { 87 public void onResponse(JSONObject response) {
77 mProgressBar.setVisibility(View.GONE); 88 mProgressBar.setVisibility(View.GONE);
  89 + mMoneyEditText.setText("");
  90 + mMoneyEditText.setVisibility(View.VISIBLE);
  91 + Snackbar.make(coordinatorLayout, "DONE", Snackbar.LENGTH_LONG).show();
78 } 92 }
79 }, new Response.ErrorListener() { 93 }, new Response.ErrorListener() {
80 @Override 94 @Override
81 public void onErrorResponse(VolleyError error) { 95 public void onErrorResponse(VolleyError error) {
82 mProgressBar.setVisibility(View.GONE); 96 mProgressBar.setVisibility(View.GONE);
  97 + mMoneyEditText.setVisibility(View.VISIBLE);
  98 + Snackbar.make(coordinatorLayout, error.getMessage(), Snackbar.LENGTH_LONG).show();
83 } 99 }
84 } 100 }
85 ); 101 );
app/src/main/java/net/plil/clubinfo/etunicorn/app/debit/Debiter.java
@@ -2,10 +2,12 @@ package net.plil.clubinfo.etunicorn.app.debit; @@ -2,10 +2,12 @@ package net.plil.clubinfo.etunicorn.app.debit;
2 2
3 import android.content.Context; 3 import android.content.Context;
4 import android.os.Bundle; 4 import android.os.Bundle;
  5 +import android.support.design.widget.CoordinatorLayout;
  6 +import android.support.design.widget.Snackbar;
  7 +import android.support.design.widget.TextInputEditText;
5 import android.view.LayoutInflater; 8 import android.view.LayoutInflater;
6 import android.view.View; 9 import android.view.View;
7 import android.view.ViewGroup; 10 import android.view.ViewGroup;
8 -import android.widget.EditText;  
9 import android.widget.ProgressBar; 11 import android.widget.ProgressBar;
10 12
11 import com.android.volley.Request; 13 import com.android.volley.Request;
@@ -15,6 +17,7 @@ import com.android.volley.toolbox.JsonObjectRequest; @@ -15,6 +17,7 @@ import com.android.volley.toolbox.JsonObjectRequest;
15 17
16 import net.plil.clubinfo.etunicorn.R; 18 import net.plil.clubinfo.etunicorn.R;
17 import net.plil.clubinfo.etunicorn.app.FragmentNFC; 19 import net.plil.clubinfo.etunicorn.app.FragmentNFC;
  20 +import net.plil.clubinfo.etunicorn.data.Personne;
18 import net.plil.clubinfo.etunicorn.utils.VolleyUtils; 21 import net.plil.clubinfo.etunicorn.utils.VolleyUtils;
19 22
20 import org.json.JSONException; 23 import org.json.JSONException;
@@ -23,9 +26,9 @@ import org.json.JSONObject; @@ -23,9 +26,9 @@ import org.json.JSONObject;
23 public class Debiter extends FragmentNFC { 26 public class Debiter extends FragmentNFC {
24 27
25 28
26 - private EditText mMoneyEditText; 29 + private TextInputEditText mMoneyEditText;
27 private ProgressBar mProgressBar; 30 private ProgressBar mProgressBar;
28 - 31 + private CoordinatorLayout coordinatorLayout;
29 32
30 public Debiter() { 33 public Debiter() {
31 // Required empty public constructor 34 // Required empty public constructor
@@ -48,7 +51,8 @@ public class Debiter extends FragmentNFC { @@ -48,7 +51,8 @@ public class Debiter extends FragmentNFC {
48 Bundle savedInstanceState) { 51 Bundle savedInstanceState) {
49 View view = inflater.inflate(R.layout.fragment_debiter, container, false); 52 View view = inflater.inflate(R.layout.fragment_debiter, container, false);
50 mProgressBar = (ProgressBar) view.findViewById(R.id.debiter_progress); 53 mProgressBar = (ProgressBar) view.findViewById(R.id.debiter_progress);
51 - mMoneyEditText = (EditText) view.findViewById(R.id.debiter_edit_text_money); 54 + mMoneyEditText = (TextInputEditText) view.findViewById(R.id.debiter_edit_text_money);
  55 + coordinatorLayout = (CoordinatorLayout) view.findViewById(R.id.debiter_layout);
52 return view; 56 return view;
53 } 57 }
54 58
@@ -64,25 +68,39 @@ public class Debiter extends FragmentNFC { @@ -64,25 +68,39 @@ public class Debiter extends FragmentNFC {
64 68
65 @Override 69 @Override
66 public void processNFC(String iDCardUser) { 70 public void processNFC(String iDCardUser) {
  71 + if(mMoneyEditText.getText().toString().isEmpty()){
  72 + mMoneyEditText.setError(getString(R.string.error_enter_debit));
  73 + return;
  74 + }
  75 + mMoneyEditText.setVisibility(View.GONE);
67 mProgressBar.setVisibility(View.VISIBLE); 76 mProgressBar.setVisibility(View.VISIBLE);
68 JSONObject jsonObject = new JSONObject(); 77 JSONObject jsonObject = new JSONObject();
69 //TODO verifier champ complet avant de construire la requete 78 //TODO verifier champ complet avant de construire la requete
70 try { 79 try {
71 - jsonObject.put("participant", 1);  
72 - jsonObject.put("acteur", 2);  
73 - jsonObject.put("prix", Double.parseDouble(mMoneyEditText.getText().toString())); 80 + Personne p = new Personne();
  81 + p.setIdCarte(iDCardUser);
  82 + jsonObject.put("participant", p);
  83 + jsonObject.put("prix", -Double.parseDouble(mMoneyEditText.getText().toString()));
  84 + mMoneyEditText.setError(null);
74 } catch (JSONException e){ 85 } catch (JSONException e){
75 e.printStackTrace(); 86 e.printStackTrace();
76 } 87 }
77 - 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/credit" ,jsonObject , new Response.Listener<JSONObject>() {
78 @Override 89 @Override
79 public void onResponse(JSONObject response) { 90 public void onResponse(JSONObject response) {
80 mProgressBar.setVisibility(View.GONE); 91 mProgressBar.setVisibility(View.GONE);
  92 + mMoneyEditText.setText("");
  93 + mMoneyEditText.setVisibility(View.VISIBLE);
  94 + Snackbar.make(coordinatorLayout, "DONE", Snackbar.LENGTH_LONG).show();
  95 +
81 } 96 }
82 }, new Response.ErrorListener() { 97 }, new Response.ErrorListener() {
83 @Override 98 @Override
84 public void onErrorResponse(VolleyError error) { 99 public void onErrorResponse(VolleyError error) {
85 mProgressBar.setVisibility(View.GONE); 100 mProgressBar.setVisibility(View.GONE);
  101 + mMoneyEditText.setVisibility(View.VISIBLE);
  102 + Snackbar.make(coordinatorLayout, error.getMessage(), Snackbar.LENGTH_LONG).show();
  103 +
86 } 104 }
87 } 105 }
88 ); 106 );
app/src/main/java/net/plil/clubinfo/etunicorn/utils/VolleyUtils.java
@@ -12,7 +12,7 @@ import com.android.volley.toolbox.Volley; @@ -12,7 +12,7 @@ import com.android.volley.toolbox.Volley;
12 12
13 public class VolleyUtils { 13 public class VolleyUtils {
14 14
15 - private static final String uri = "http://blablapatate"; 15 + private static final String uri = "http://192.168.0.21:8080/";
16 private static final String version = "v1"; 16 private static final String version = "v1";
17 17
18 public static final String baseUri = VolleyUtils.uri + VolleyUtils.version ; 18 public static final String baseUri = VolleyUtils.uri + VolleyUtils.version ;
app/src/main/res/layout/fragment_crediter.xml
1 -<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 1 +<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 xmlns:tools="http://schemas.android.com/tools" 2 xmlns:tools="http://schemas.android.com/tools"
3 android:layout_width="match_parent" 3 android:layout_width="match_parent"
4 android:layout_height="match_parent" 4 android:layout_height="match_parent"
5 - tools:context="net.plil.clubinfo.etunicorn.app.credit.Crediter">  
6 -  
7 - <EditText  
8 - android:inputType="numberSigned|numberDecimal"  
9 - android:layout_width="wrap_content"  
10 - android:layout_height="wrap_content"  
11 - android:hint="@string/enter_money"  
12 - android:id="@+id/crediter_ask_money"  
13 - android:ems="10"  
14 - android:layout_centerVertical="true"  
15 - android:layout_centerHorizontal="true"  
16 - android:gravity="center"/>  
17 -  
18 - <ProgressBar  
19 - style="?android:attr/progressBarStyle"  
20 - android:layout_width="wrap_content"  
21 - android:layout_height="wrap_content"  
22 - android:layout_alignParentTop="true"  
23 - android:layout_alignParentStart="true"  
24 - android:id="@+id/crediter_progress_bar"  
25 - android:layout_alignParentBottom="true"  
26 - android:layout_alignParentEnd="true"  
27 - android:visibility="gone"/>  
28 -  
29 -</RelativeLayout> 5 + tools:context="net.plil.clubinfo.etunicorn.app.credit.Crediter"
  6 + android:id="@+id/crediter_layout">
  7 + <RelativeLayout
  8 + android:layout_width="match_parent"
  9 + android:layout_height="match_parent">
  10 +
  11 + <android.support.design.widget.TextInputLayout
  12 + android:layout_width="wrap_content"
  13 + android:layout_height="wrap_content"
  14 + android:layout_centerVertical="true"
  15 + android:layout_centerHorizontal="true">
  16 +
  17 + <android.support.design.widget.TextInputEditText
  18 + android:inputType="numberDecimal"
  19 + android:layout_width="wrap_content"
  20 + android:layout_height="wrap_content"
  21 + android:hint="@string/enter_money"
  22 + android:id="@+id/crediter_ask_money"
  23 + android:ems="10"
  24 + android:gravity="center"/>
  25 +
  26 + </android.support.design.widget.TextInputLayout>
  27 +
  28 + <ProgressBar
  29 + style="?android:attr/progressBarStyleLarge"
  30 + android:layout_width="wrap_content"
  31 + android:layout_height="wrap_content"
  32 + android:id="@+id/crediter_progress_bar"
  33 + android:visibility="gone"
  34 + android:layout_centerVertical="true"
  35 + android:layout_centerHorizontal="true" />
  36 +
  37 + </RelativeLayout>
  38 +
  39 +
  40 +
  41 +</android.support.design.widget.CoordinatorLayout>
app/src/main/res/layout/fragment_debiter.xml
1 -<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 1 +<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 xmlns:tools="http://schemas.android.com/tools" 2 xmlns:tools="http://schemas.android.com/tools"
3 android:layout_width="match_parent" 3 android:layout_width="match_parent"
4 android:layout_height="match_parent" 4 android:layout_height="match_parent"
5 - tools:context="net.plil.clubinfo.etunicorn.app.debit.Debiter">  
6 -  
7 -  
8 - <EditText  
9 - android:inputType="numberSigned|numberDecimal"  
10 - android:ems="10"  
11 - android:id="@+id/debiter_edit_text_money"  
12 - android:gravity="center"  
13 - android:layout_width="wrap_content"  
14 - android:layout_height="wrap_content"  
15 - android:layout_centerVertical="true"  
16 - android:layout_centerHorizontal="true"  
17 - android:hint="@string/enter_money"  
18 - android:maxLines="1" />  
19 -  
20 - <ProgressBar  
21 - style="?android:attr/progressBarStyle"  
22 - android:layout_width="wrap_content"  
23 - android:layout_height="wrap_content"  
24 - android:layout_alignParentTop="true"  
25 - android:layout_alignParentStart="true"  
26 - android:id="@+id/debiter_progress"  
27 - android:layout_alignParentBottom="true"  
28 - android:layout_alignParentEnd="true"  
29 - android:visibility="gone"/>  
30 -</RelativeLayout> 5 + tools:context="net.plil.clubinfo.etunicorn.app.credit.Crediter"
  6 + android:id="@+id/debiter_layout">
  7 +
  8 + <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  9 + xmlns:tools="http://schemas.android.com/tools"
  10 + android:layout_width="match_parent"
  11 + android:layout_height="match_parent"
  12 + tools:context="net.plil.clubinfo.etunicorn.app.debit.Debiter">
  13 +
  14 +
  15 + <android.support.design.widget.TextInputLayout
  16 + android:layout_width="wrap_content"
  17 + android:layout_height="wrap_content"
  18 + android:layout_centerVertical="true"
  19 + android:layout_centerHorizontal="true"
  20 + >
  21 +
  22 + <android.support.design.widget.TextInputEditText
  23 + android:inputType="numberDecimal"
  24 + android:ems="10"
  25 + android:id="@+id/debiter_edit_text_money"
  26 + android:layout_width="wrap_content"
  27 + android:layout_height="wrap_content"
  28 + android:gravity="center"
  29 + android:hint="@string/enter_money"
  30 + android:maxLines="1" />
  31 +
  32 + </android.support.design.widget.TextInputLayout>
  33 +
  34 + <ProgressBar
  35 + style="?android:attr/progressBarStyleLarge"
  36 + android:layout_width="wrap_content"
  37 + android:layout_height="wrap_content"
  38 + android:layout_centerVertical="true"
  39 + android:layout_centerHorizontal="true"
  40 + android:id="@+id/debiter_progress"
  41 + android:visibility="gone"/>
  42 +
  43 + </RelativeLayout>
  44 +
  45 +
  46 +</android.support.design.widget.CoordinatorLayout>
app/src/main/res/values-fr/strings.xml
@@ -40,4 +40,5 @@ @@ -40,4 +40,5 @@
40 <string name="create_personne_login">Login</string> 40 <string name="create_personne_login">Login</string>
41 <string name="create_personne_naissance">Date de naissance</string> 41 <string name="create_personne_naissance">Date de naissance</string>
42 <string name="create_personne_role">Role</string> 42 <string name="create_personne_role">Role</string>
  43 + <string name="error_enter_debit">Veuillez entrer une valeur avant d\'utiliser la carte NFC</string>
43 </resources> 44 </resources>
44 \ No newline at end of file 45 \ No newline at end of file
app/src/main/res/values/strings.xml
@@ -41,4 +41,5 @@ @@ -41,4 +41,5 @@
41 <string name="create_personne_carte">Card ID</string> 41 <string name="create_personne_carte">Card ID</string>
42 <string name="create_personne_naissance">Birthday</string> 42 <string name="create_personne_naissance">Birthday</string>
43 <string name="create_personne_role">Role</string> 43 <string name="create_personne_role">Role</string>
  44 + <string name="error_enter_debit">Please enter a value before using your NFC card</string>
44 </resources> 45 </resources>