Commit 2596297c8e88e6be3e908c8a43d9d3c35dbc2770
1 parent
ae8b78ec
Ajout d'annuler et refaire dans les snackbar
Showing
3 changed files
with
65 additions
and
5 deletions
Show diff stats
PremiereActivite/app/src/main/java/com/example/app_10p5/MainActivite.java
... | ... | @@ -12,7 +12,6 @@ import android.nfc.NfcAdapter; |
12 | 12 | import android.os.Bundle; |
13 | 13 | import android.preference.PreferenceManager; |
14 | 14 | import android.support.design.widget.Snackbar; |
15 | -import android.support.v4.view.ViewPager; | |
16 | 15 | import android.text.TextUtils; |
17 | 16 | import android.view.Menu; |
18 | 17 | import android.view.MenuInflater; |
... | ... | @@ -39,6 +38,8 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr |
39 | 38 | public static final int STATE_RECHARGEMENT = 2; |
40 | 39 | public static final int STATE_CREATION_COMPTE = 1; |
41 | 40 | public static final int STATE_CONNEXION = 5; |
41 | + public static final int STATE_ANNULER= 6; | |
42 | + public static final int STATE_REFAIRE = 7; | |
42 | 43 | |
43 | 44 | public static final long EXPIRATION = 1000*60*10; |
44 | 45 | |
... | ... | @@ -388,7 +389,7 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr |
388 | 389 | if(output.get("status").toString().equals("ok")){ |
389 | 390 | switch (mState){ |
390 | 391 | case STATE_COMMANDE: |
391 | - Snackbar.make(findViewById(R.id.coordinator), "Client débité de " + output.get("montant") + "€. " + output.get("soldeAncien") + "€ → " + output.getString("soldeNouveau") + "€", Snackbar.LENGTH_INDEFINITE).show(); | |
392 | + Snackbar.make(findViewById(R.id.coordinator), "Client débité de " + output.get("montant") + "€. " + output.get("soldeAncien") + "€ → " + output.getString("soldeNouveau") + "€", Snackbar.LENGTH_LONG).setAction("ANNULER", new viewListenerAnnulerRefaire(output.getInt("idTransaction"), this, true)).show(); | |
392 | 393 | break; |
393 | 394 | case STATE_CONNEXION: |
394 | 395 | mToken = output.get("jeton").toString(); |
... | ... | @@ -399,13 +400,19 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr |
399 | 400 | getFragmentManager().beginTransaction().replace(R.id.fragment_container, new main_tab_frag()).commit(); |
400 | 401 | break; |
401 | 402 | case STATE_CREATION_COMPTE: |
402 | - Snackbar.make(findViewById(R.id.coordinator), "Client créé avec un solde de " + output.get("soldeNouveau") + "€", Snackbar.LENGTH_INDEFINITE).show(); | |
403 | + Snackbar.make(findViewById(R.id.coordinator), "Client créé avec un solde de " + output.get("soldeNouveau") + "€", Snackbar.LENGTH_LONG).setAction("ANNULER", new viewListenerAnnulerRefaire(output.getInt("idTransaction"), this, true)).show(); | |
403 | 404 | break; |
404 | 405 | case STATE_RECHARGEMENT: |
405 | - Snackbar.make(findViewById(R.id.coordinator), "Client rechargé: " + output.get("soldeAncien") + "€ →" + output.get("soldeNouveau") + "€", Snackbar.LENGTH_INDEFINITE).show(); | |
406 | + Snackbar.make(findViewById(R.id.coordinator), "Client rechargé: " + output.get("soldeAncien") + "€ → " + output.get("soldeNouveau") + "€", Snackbar.LENGTH_LONG).setAction("ANNULER", new viewListenerAnnulerRefaire(output.getInt("idTransaction"), this, true)).show(); | |
406 | 407 | break; |
407 | 408 | case STATE_VIDANGE: |
408 | - Snackbar.make(findViewById(R.id.coordinator), "Client vidé: " + output.get("soldeAncien") + "€ → 0€", Snackbar.LENGTH_INDEFINITE).show(); | |
409 | + Snackbar.make(findViewById(R.id.coordinator), "Client vidé: " + output.get("soldeAncien") + "€ → 0€", Snackbar.LENGTH_LONG).setAction("ANNULER", new viewListenerAnnulerRefaire(output.getInt("idTransaction"), this, true)).show(); | |
410 | + break; | |
411 | + case STATE_ANNULER: | |
412 | + Snackbar.make(findViewById(R.id.coordinator), "Transaction annulée: " + output.get("soldeAncien") + "€ → " + output.get("soldeNouveau") + "€", Snackbar.LENGTH_LONG).setAction("REFAIRE", new viewListenerAnnulerRefaire(output.getInt("idTransaction"), this, false)).show(); | |
413 | + break; | |
414 | + case STATE_REFAIRE: | |
415 | + Snackbar.make(findViewById(R.id.coordinator), "Transaction rétablie: " + output.get("soldeAncien") + "€ → " + output.get("soldeNouveau") + "€", Snackbar.LENGTH_LONG).setAction("ANNULER", new viewListenerAnnulerRefaire(output.getInt("idTransaction"), this, true)).show(); | |
409 | 416 | break; |
410 | 417 | case STATE_RIEN: |
411 | 418 | default: |
... | ... | @@ -447,4 +454,32 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr |
447 | 454 | Snackbar.make(findViewById(R.id.coordinator), "Veuillez vous reconnecter", Snackbar.LENGTH_SHORT).show(); |
448 | 455 | getFragmentManager().beginTransaction().replace(R.id.fragment_container, new ConnectionFragment()).commit(); |
449 | 456 | } |
457 | + | |
458 | + public void annulerTransaction(int idTransaction, boolean annuler){ | |
459 | + try{ | |
460 | + HashMap<String, String> param = new HashMap<String, String>(); | |
461 | + param.put("idTransaction", URLEncoder.encode(String.valueOf(idTransaction), "UTF-8")); | |
462 | + param.put("jeton", URLEncoder.encode(mToken, "UTF-8")); | |
463 | + | |
464 | + SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); | |
465 | + | |
466 | + URL url; | |
467 | + | |
468 | + if(annuler){ | |
469 | + mState = STATE_ANNULER; | |
470 | + url = new URL(settings.getString("server_address", null) + "api/annuler"); | |
471 | + } | |
472 | + else{ | |
473 | + mState = STATE_REFAIRE; | |
474 | + url = new URL(settings.getString("server_address", null) + "api/refaire"); | |
475 | + } | |
476 | + | |
477 | + NetworkThread nt = new NetworkThread(url, param); | |
478 | + nt.delegate = this; | |
479 | + nt.execute(); | |
480 | + } | |
481 | + catch (Throwable t){ | |
482 | + System.out.println(t.toString()); | |
483 | + } | |
484 | + } | |
450 | 485 | } | ... | ... |
PremiereActivite/app/src/main/java/com/example/app_10p5/NFCFragment.java
... | ... | @@ -61,6 +61,8 @@ public class NFCFragment extends Fragment { |
61 | 61 | mAPI = "api/client/vidange"; |
62 | 62 | break; |
63 | 63 | case MainActivite.STATE_CONNEXION: //Impossible c'est pas géré ici |
64 | + case MainActivite.STATE_ANNULER: | |
65 | + case MainActivite.STATE_REFAIRE: | |
64 | 66 | case MainActivite.STATE_RIEN: |
65 | 67 | default: |
66 | 68 | Snackbar.make(getActivity().findViewById(R.id.coordinator), "WTF, le cancer est dans l'application!!", Snackbar.LENGTH_INDEFINITE).show(); | ... | ... |
PremiereActivite/app/src/main/java/com/example/app_10p5/viewListenerAnnulerRefaire.java
0 → 100644
... | ... | @@ -0,0 +1,23 @@ |
1 | +package com.example.app_10p5; | |
2 | + | |
3 | +import android.view.View; | |
4 | + | |
5 | +/** | |
6 | + * Created by Jean-loup Beaussart on 06/05/2016. | |
7 | + */ | |
8 | +public class viewListenerAnnulerRefaire implements View.OnClickListener { | |
9 | + private int mIdTransaction; | |
10 | + private MainActivite mMain; | |
11 | + private boolean mAnnuler; | |
12 | + | |
13 | + viewListenerAnnulerRefaire(int idTransaction, MainActivite main, boolean annuler){ | |
14 | + mIdTransaction = idTransaction; | |
15 | + mMain = main; | |
16 | + mAnnuler = annuler; | |
17 | + } | |
18 | + | |
19 | + @Override | |
20 | + public void onClick(View v){ | |
21 | + mMain.annulerTransaction(mIdTransaction, mAnnuler); | |
22 | + } | |
23 | +} | ... | ... |