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,6 +40,7 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | ||
40 | public static final int STATE_CONNEXION = 5; | 40 | public static final int STATE_CONNEXION = 5; |
41 | public static final int STATE_ANNULER= 6; | 41 | public static final int STATE_ANNULER= 6; |
42 | public static final int STATE_REFAIRE = 7; | 42 | public static final int STATE_REFAIRE = 7; |
43 | + public static final int STATE_DECONNEXION = 8; | ||
43 | 44 | ||
44 | public static final long EXPIRATION = 1000*60*10; | 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,11 +393,11 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | ||
392 | Fragment frag = getFragmentManager().findFragmentById(R.id.fragment_container); | 393 | Fragment frag = getFragmentManager().findFragmentById(R.id.fragment_container); |
393 | 394 | ||
394 | if(NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())){ | 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 | NFCFragment nfc = (NFCFragment) frag; | 397 | NFCFragment nfc = (NFCFragment) frag; |
397 | nfc.handleIntent(intent); | 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 | mState = STATE_CONNEXION; | 401 | mState = STATE_CONNEXION; |
401 | ConnectionFragment co = (ConnectionFragment) frag; | 402 | ConnectionFragment co = (ConnectionFragment) frag; |
402 | co.handleIntent(intent); | 403 | co.handleIntent(intent); |
@@ -439,6 +440,9 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | @@ -439,6 +440,9 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | ||
439 | case STATE_REFAIRE: | 440 | case STATE_REFAIRE: |
440 | 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 | 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 | break; | 442 | break; |
443 | + case STATE_DECONNEXION: | ||
444 | + System.out.println("Déconnexion réussie."); | ||
445 | + break; | ||
442 | case STATE_RIEN: | 446 | case STATE_RIEN: |
443 | default: | 447 | default: |
444 | Toast.makeText(this, "WTF, le cancer est dans l'application!!", Toast.LENGTH_LONG).show(); | 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,11 +474,26 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr | ||
470 | } | 474 | } |
471 | 475 | ||
472 | public void disconnect(){ | 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 | mToken = ""; | 492 | mToken = ""; |
474 | mDroit = 0; | 493 | mDroit = 0; |
475 | mUser = null; | 494 | mUser = null; |
476 | mTimeToken = -1; | 495 | mTimeToken = -1; |
477 | - mState = STATE_RIEN; | 496 | + mState = STATE_DECONNEXION; |
478 | 497 | ||
479 | Snackbar.make(findViewById(R.id.coordinator), "Veuillez vous reconnecter", Snackbar.LENGTH_SHORT).show(); | 498 | Snackbar.make(findViewById(R.id.coordinator), "Veuillez vous reconnecter", Snackbar.LENGTH_SHORT).show(); |
480 | getFragmentManager().beginTransaction().replace(R.id.fragment_container, new ConnectionFragment()).commit(); | 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,6 +58,7 @@ public class NFCFragment extends NFC { | ||
58 | case MainActivite.STATE_ANNULER: | 58 | case MainActivite.STATE_ANNULER: |
59 | case MainActivite.STATE_REFAIRE: | 59 | case MainActivite.STATE_REFAIRE: |
60 | case MainActivite.STATE_RIEN: | 60 | case MainActivite.STATE_RIEN: |
61 | + case MainActivite.STATE_DECONNEXION: | ||
61 | default: | 62 | default: |
62 | Snackbar.make(getActivity().findViewById(R.id.coordinator), "WTF, le cancer est dans l'application!!", Snackbar.LENGTH_INDEFINITE).show(); | 63 | Snackbar.make(getActivity().findViewById(R.id.coordinator), "WTF, le cancer est dans l'application!!", Snackbar.LENGTH_INDEFINITE).show(); |
63 | } | 64 | } |