Commit f775eb7ebf7a55481819967669ed18c0adb26b74
1 parent
677d1d6f
Toast cancers + paramètres POST + recap transaction
Showing
1 changed file
with
26 additions
and
22 deletions
Show diff stats
PremiereActivite/app/src/main/java/com/example/app_10p5/CarteActivite.java
... | ... | @@ -35,24 +35,27 @@ public class CarteActivite extends Activity implements ASyncResponse { |
35 | 35 | |
36 | 36 | switch (getIntent().getIntExtra("state", MainActivite.STATE_RIEN)) { |
37 | 37 | case MainActivite.STATE_COMMANDE: |
38 | - mParam.put("quantite", String.valueOf(getIntent().getIntExtra("quantite", -1))); | |
38 | + //TODO: XOR du cancer | |
39 | + //mParam.put("quantite", String.valueOf(getIntent().getIntExtra("quantite", -1))); | |
39 | 40 | mParam.put("montant", String.valueOf(getIntent().getFloatExtra("montant", -1))); |
40 | - mParam.put("token", getIntent().getStringExtra("token")); | |
41 | + mParam.put("jeton", getIntent().getStringExtra("token")); | |
41 | 42 | mAPI = "api/client/payer"; |
42 | 43 | break; |
43 | 44 | case MainActivite.STATE_CREATION_COMPTE: |
44 | - //TODO: param | |
45 | + mParam.put("solde", String.valueOf(getIntent().getFloatExtra("montant", -1))); | |
46 | + mParam.put("jeton", getIntent().getStringExtra("token")); | |
45 | 47 | mAPI = "api/client/ajouter"; |
46 | 48 | break; |
47 | 49 | case MainActivite.STATE_RECHARGEMENT: |
48 | - //TODO: param | |
50 | + mParam.put("montant", String.valueOf(getIntent().getFloatExtra("montant", -1))); | |
51 | + mParam.put("jeton", getIntent().getStringExtra("token")); | |
49 | 52 | mAPI = "api/client/recharger"; |
50 | 53 | break; |
51 | 54 | case MainActivite.STATE_VIDANGE: |
52 | - //TODO: param | |
55 | + //pas de paramètre | |
53 | 56 | mAPI = "api/client/vidange"; |
54 | 57 | break; |
55 | - case MainActivite.STATE_CONNEXION: | |
58 | + case MainActivite.STATE_CONNEXION: //Impossible c'est pas géré ici | |
56 | 59 | case MainActivite.STATE_RIEN: |
57 | 60 | default: |
58 | 61 | Toast.makeText(this, "WTF, le cancer est dans l'application!!", Toast.LENGTH_LONG).show(); |
... | ... | @@ -107,11 +110,8 @@ public class CarteActivite extends Activity implements ASyncResponse { |
107 | 110 | |
108 | 111 | private void handleIntent(Intent intent){ |
109 | 112 | if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) { |
110 | - Toast toast; | |
111 | 113 | String id_carte = ByteArrayToHexString(intent.getByteArrayExtra(NfcAdapter.EXTRA_ID)); |
112 | - mParam.put("ID", id_carte); | |
113 | - toast = Toast.makeText(getApplicationContext(), "ID Carte : " + id_carte, Toast.LENGTH_SHORT); | |
114 | - toast.show(); | |
114 | + mParam.put("idCarte", id_carte); | |
115 | 115 | |
116 | 116 | //Lecture des données |
117 | 117 | Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); |
... | ... | @@ -145,16 +145,13 @@ public class CarteActivite extends Activity implements ASyncResponse { |
145 | 145 | prenom = dataStr; |
146 | 146 | else if (i == 3) //Nom |
147 | 147 | nom = dataStr; |
148 | - toast = Toast.makeText(getApplicationContext(), "Données lues : " + dataStr, Toast.LENGTH_SHORT); | |
149 | - toast.show(); | |
150 | 148 | } |
151 | 149 | } else { |
152 | - toast = Toast.makeText(getApplicationContext(), "Erreur lors de la connection au secteur 12.", Toast.LENGTH_SHORT); | |
153 | - toast.show(); | |
150 | + Toast.makeText(this, "Impossible de lire le secteur 12", Toast.LENGTH_LONG).show(); | |
154 | 151 | } |
155 | 152 | mfc.close(); |
156 | - } catch (IOException e) { | |
157 | - System.out.println(e.getLocalizedMessage()); | |
153 | + } catch (Throwable t) { | |
154 | + Toast.makeText(this, "WTF, le cancer est dans l'application!! " + t.toString(), Toast.LENGTH_LONG).show(); | |
158 | 155 | } |
159 | 156 | |
160 | 157 | //Concaténation des données récupérées en login |
... | ... | @@ -162,13 +159,9 @@ public class CarteActivite extends Activity implements ASyncResponse { |
162 | 159 | login.concat("."); |
163 | 160 | login.concat(nom); |
164 | 161 | } else { |
165 | - toast = Toast.makeText(getApplicationContext(), "Pas de connection possible à la technologie Mifare Classic.", Toast.LENGTH_SHORT); | |
166 | - toast.show(); | |
162 | + Toast.makeText(this, "Pas de Mifare Classic", Toast.LENGTH_SHORT).show(); | |
167 | 163 | } |
168 | 164 | |
169 | - toast = Toast.makeText(getApplicationContext(), "Login Lille 1 : " + login, Toast.LENGTH_SHORT); | |
170 | - toast.show(); | |
171 | - | |
172 | 165 | //Éxécution de la fonction |
173 | 166 | clientAPI(); |
174 | 167 | } |
... | ... | @@ -203,6 +196,17 @@ public class CarteActivite extends Activity implements ASyncResponse { |
203 | 196 | /* Retour du NetworkThread */ |
204 | 197 | @Override |
205 | 198 | public void processFinish(JSONObject output) { |
206 | - //TODO: faire un retour vers l'activity parente des données reçues. | |
199 | + try { | |
200 | + if (output.get("status").equals("ok")) { | |
201 | + Toast.makeText(this, "Tout c'est bien passé: " + output.get("status").toString(), Toast.LENGTH_LONG).show(); | |
202 | + } else { | |
203 | + Toast.makeText(this, "Erreur lors du traitement de la requête: " + output.get("status").toString(), Toast.LENGTH_LONG).show(); | |
204 | + } | |
205 | + } catch (Throwable t) { | |
206 | + Toast.makeText(this, "WTF, le cancer est dans l'application!! " + t.toString(), Toast.LENGTH_LONG).show(); | |
207 | + } | |
208 | + | |
209 | + finish(); | |
210 | + return; | |
207 | 211 | } |
208 | 212 | } | ... | ... |