Commit 9142a0505a0044b4e267237e5eb623c03e9d8067
1 parent
6ff8ec9b
Ajout de l'appel API /deconnexion
Showing
2 changed files
with
23 additions
and
3 deletions
Show diff stats
PremiereActivite/app/src/main/java/com/example/app_10p5/MainActivite.java
... | ... | @@ -40,6 +40,7 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr |
40 | 40 | public static final int STATE_CONNEXION = 5; |
41 | 41 | public static final int STATE_ANNULER= 6; |
42 | 42 | public static final int STATE_REFAIRE = 7; |
43 | + public static final int STATE_DECONNEXION = 8; | |
43 | 44 | |
44 | 45 | public static final long EXPIRATION = 1000*60*10; |
45 | 46 | |
... | ... | @@ -392,11 +393,11 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr |
392 | 393 | Fragment frag = getFragmentManager().findFragmentById(R.id.fragment_container); |
393 | 394 | |
394 | 395 | if(NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())){ |
395 | - if(mState != STATE_RIEN && frag instanceof NFCFragment){ | |
396 | + if(((mState == STATE_RECHARGEMENT) || (mState == STATE_COMMANDE) || (mState == STATE_VIDANGE) || (mState == STATE_CREATION_COMPTE)) && (frag instanceof NFCFragment)){ | |
396 | 397 | NFCFragment nfc = (NFCFragment) frag; |
397 | 398 | nfc.handleIntent(intent); |
398 | 399 | } |
399 | - else if(mState == STATE_RIEN && frag instanceof ConnectionFragment){ | |
400 | + else if((mState == STATE_RIEN) && (frag instanceof ConnectionFragment)){ | |
400 | 401 | mState = STATE_CONNEXION; |
401 | 402 | ConnectionFragment co = (ConnectionFragment) frag; |
402 | 403 | co.handleIntent(intent); |
... | ... | @@ -439,6 +440,9 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr |
439 | 440 | case STATE_REFAIRE: |
440 | 441 | 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(); |
441 | 442 | break; |
443 | + case STATE_DECONNEXION: | |
444 | + System.out.println("Déconnexion réussie."); | |
445 | + break; | |
442 | 446 | case STATE_RIEN: |
443 | 447 | default: |
444 | 448 | Toast.makeText(this, "WTF, le cancer est dans l'application!!", Toast.LENGTH_LONG).show(); |
... | ... | @@ -470,11 +474,26 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr |
470 | 474 | } |
471 | 475 | |
472 | 476 | public void disconnect(){ |
477 | + try{ | |
478 | + SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); | |
479 | + URL url = new URL(settings.getString("server_address", null) + "api/utilisateur/deconnexion"); | |
480 | + HashMap<String, String> param = new HashMap<String, String>(); | |
481 | + param.put("jeton", mToken); | |
482 | + NetworkThread nt = new NetworkThread(url, param); | |
483 | + nt.delegate = this; | |
484 | + nt.execute(); | |
485 | + } | |
486 | + catch (Throwable t){ | |
487 | + Toast.makeText(this, "WTF, le cancer est dans l'application!!" + t.toString(), Toast.LENGTH_LONG).show(); | |
488 | + System.out.println(t.toString()); | |
489 | + } | |
490 | + | |
491 | + | |
473 | 492 | mToken = ""; |
474 | 493 | mDroit = 0; |
475 | 494 | mUser = null; |
476 | 495 | mTimeToken = -1; |
477 | - mState = STATE_RIEN; | |
496 | + mState = STATE_DECONNEXION; | |
478 | 497 | |
479 | 498 | Snackbar.make(findViewById(R.id.coordinator), "Veuillez vous reconnecter", Snackbar.LENGTH_SHORT).show(); |
480 | 499 | getFragmentManager().beginTransaction().replace(R.id.fragment_container, new ConnectionFragment()).commit(); | ... | ... |
PremiereActivite/app/src/main/java/com/example/app_10p5/NFCFragment.java
... | ... | @@ -58,6 +58,7 @@ public class NFCFragment extends NFC { |
58 | 58 | case MainActivite.STATE_ANNULER: |
59 | 59 | case MainActivite.STATE_REFAIRE: |
60 | 60 | case MainActivite.STATE_RIEN: |
61 | + case MainActivite.STATE_DECONNEXION: | |
61 | 62 | default: |
62 | 63 | Snackbar.make(getActivity().findViewById(R.id.coordinator), "WTF, le cancer est dans l'application!!", Snackbar.LENGTH_INDEFINITE).show(); |
63 | 64 | } | ... | ... |