Commit b63136431eb950a9d68bd768a221f306d7d7d082

Authored by JLo'w
1 parent 3cc8c195

Déconnexion + gestion commande

PremiereActivite/app/src/main/java/com/example/app_10p5/MainActivite.java
@@ -60,7 +60,7 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr @@ -60,7 +60,7 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr
60 60
61 mState = STATE_RIEN; 61 mState = STATE_RIEN;
62 mTimeToken = -1; 62 mTimeToken = -1;
63 - mToken = null; 63 + mToken = "";
64 64
65 getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary))); 65 getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary)));
66 mNfcAdapter = NfcAdapter.getDefaultAdapter(getApplicationContext()); 66 mNfcAdapter = NfcAdapter.getDefaultAdapter(getApplicationContext());
@@ -199,40 +199,60 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr @@ -199,40 +199,60 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr
199 public void valideCommande(View v) 199 public void valideCommande(View v)
200 { 200 {
201 if((TextUtils.getTrimmedLength(mToken) == 30) && ((System.currentTimeMillis() - mTimeToken) < EXPIRATION)) { 201 if((TextUtils.getTrimmedLength(mToken) == 30) && ((System.currentTimeMillis() - mTimeToken) < EXPIRATION)) {
202 - EditText champMontant = (EditText) findViewById(R.id.commande_prix);  
203 - EditText champQuantite = (EditText) findViewById(R.id.commande_quantite);  
204 - float montant = 0.0f;  
205 - int quantite = 0;  
206 -  
207 - //TODO: gérer le XOR de pute  
208 -  
209 - try{  
210 - montant = Float.parseFloat(champMontant.getText().toString());  
211 - quantite = Integer.parseInt(champQuantite.getText().toString());  
212 - }  
213 - catch (Throwable t)  
214 - {  
215 - Toast.makeText(this, "Remplir les champs avec des nombres: " + t.toString(), Toast.LENGTH_LONG).show();  
216 - }  
217 -  
218 - if ((montant > 0.0f) && (montant < 200.0f) && (quantite > 0) && (mDroit >= 1)) { 202 + if(mDroit >= 1){
219 mState = STATE_COMMANDE; 203 mState = STATE_COMMANDE;
220 - champMontant.setText(null);  
221 - champQuantite.setText(null);  
222 -  
223 Bundle b = new Bundle(); 204 Bundle b = new Bundle();
224 b.putString("token", mToken); 205 b.putString("token", mToken);
225 b.putInt("state", mState); 206 b.putInt("state", mState);
226 - b.putFloat("montant", montant);  
227 - b.putInt("quantite", quantite);  
228 207
229 NFCFragment nfc = new NFCFragment(); 208 NFCFragment nfc = new NFCFragment();
230 - nfc.setArguments(b);  
231 209
  210 + switch (v.getId()){
  211 + case R.id.commande_validation:
  212 + EditText champMontant = (EditText) findViewById(R.id.commande_prix);
  213 + float montant = 0.0f;
  214 +
  215 + try{
  216 + montant = Float.parseFloat(champMontant.getText().toString().replace(",", "."));
  217 + }
  218 + catch (Throwable t)
  219 + {
  220 + Toast.makeText(this, "Remplir le prix avec un nombre: " + t.toString(), Toast.LENGTH_SHORT).show();
  221 + }
  222 + if ((montant > 0.0f) && (montant < 200.0f)) {
  223 + champMontant.setText(null);
  224 + b.putFloat("montant", montant);
  225 + b.putInt("quantite", 0);
  226 + }
  227 + else{
  228 + Toast.makeText(this, "Valeur incorrecte.", Toast.LENGTH_SHORT).show();
  229 + }
  230 + break;
  231 + case R.id.button1:
  232 + b.putInt("quantite", 1);
  233 + break;
  234 + case R.id.button2:
  235 + b.putInt("quantite", 2);
  236 + break;
  237 + case R.id.button3:
  238 + b.putInt("quantite", 3);
  239 + break;
  240 + case R.id.button4:
  241 + b.putInt("quantite", 4);
  242 + break;
  243 + case R.id.button5:
  244 + b.putInt("quantite", 5);
  245 + break;
  246 + case R.id.button6:
  247 + b.putInt("quantite", 6);
  248 + break;
  249 + }
  250 +
  251 + nfc.setArguments(b);
232 getFragmentManager().beginTransaction().replace(R.id.fragment_container, nfc).addToBackStack(null).commit(); 252 getFragmentManager().beginTransaction().replace(R.id.fragment_container, nfc).addToBackStack(null).commit();
233 } 253 }
234 else{ 254 else{
235 - Toast.makeText(this, "Valeur incorrecte ou droit insuffisant.", Toast.LENGTH_LONG).show(); 255 + Toast.makeText(this, "Droit insuffisant.", Toast.LENGTH_SHORT).show();
236 } 256 }
237 } 257 }
238 else{ 258 else{
@@ -242,7 +262,6 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr @@ -242,7 +262,6 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr
242 262
243 public void valideRechargement(View v) 263 public void valideRechargement(View v)
244 { 264 {
245 - System.out.println(TextUtils.getTrimmedLength(mToken));  
246 if((TextUtils.getTrimmedLength(mToken) == 30) && ((System.currentTimeMillis() - mTimeToken) < EXPIRATION)) { 265 if((TextUtils.getTrimmedLength(mToken) == 30) && ((System.currentTimeMillis() - mTimeToken) < EXPIRATION)) {
247 EditText champMontant = (EditText) findViewById(R.id.rechargement_champ_montant); 266 EditText champMontant = (EditText) findViewById(R.id.rechargement_champ_montant);
248 float montant = 0.0f; 267 float montant = 0.0f;
@@ -419,14 +438,13 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr @@ -419,14 +438,13 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr
419 } 438 }
420 439
421 public void disconnect(){ 440 public void disconnect(){
422 - mToken = null; 441 + mToken = "";
423 mDroit = 0; 442 mDroit = 0;
424 mUser = null; 443 mUser = null;
425 mTimeToken = -1; 444 mTimeToken = -1;
426 mState = STATE_RIEN; 445 mState = STATE_RIEN;
427 446
428 - Toast.makeText(this, "Veuillez vous reconnecter.", Toast.LENGTH_SHORT).show();  
429 - final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);  
430 - viewPager.setCurrentItem(0); 447 + Snackbar.make(findViewById(R.id.coordinator), "Veuillez vous reconnecter", Snackbar.LENGTH_SHORT).show();
  448 + getFragmentManager().beginTransaction().replace(R.id.fragment_container, new ConnectionFragment()).commit();
431 } 449 }
432 } 450 }
PremiereActivite/app/src/main/java/com/example/app_10p5/main_tab_frag.java
1 package com.example.app_10p5; 1 package com.example.app_10p5;
2 2
3 -import android.app.Activity;  
4 import android.content.Context; 3 import android.content.Context;
5 import android.os.Bundle; 4 import android.os.Bundle;
6 import android.app.Fragment; 5 import android.app.Fragment;
@@ -9,8 +8,6 @@ import android.support.v4.view.ViewPager; @@ -9,8 +8,6 @@ import android.support.v4.view.ViewPager;
9 import android.view.LayoutInflater; 8 import android.view.LayoutInflater;
10 import android.view.View; 9 import android.view.View;
11 import android.view.ViewGroup; 10 import android.view.ViewGroup;
12 -import android.widget.Toast;  
13 -  
14 11
15 public class main_tab_frag extends Fragment { 12 public class main_tab_frag extends Fragment {
16 13
@@ -51,9 +48,7 @@ public class main_tab_frag extends Fragment { @@ -51,9 +48,7 @@ public class main_tab_frag extends Fragment {
51 viewPager.setCurrentItem(tab.getPosition()); 48 viewPager.setCurrentItem(tab.getPosition());
52 } 49 }
53 else{ 50 else{
54 - viewPager.setCurrentItem(tab.getPosition()); //Empeche un bug graphique  
55 - viewPager.setCurrentItem(0);  
56 - Toast.makeText(parent, "Veuillez vous connecter.", Toast.LENGTH_LONG).show(); 51 + parent.disconnect();
57 } 52 }
58 } 53 }
59 54