Commit 96cf88d28ee7343efa542c79e895cedc427e6f31
1 parent
973d84fa
Réception de JSON pour la connexion
Showing
1 changed file
with
19 additions
and
2 deletions
Show diff stats
PremiereActivite/app/src/main/java/com/example/app_10p5/MainActivite.java
... | ... | @@ -2,6 +2,7 @@ package com.example.app_10p5; |
2 | 2 | |
3 | 3 | import android.content.Intent; |
4 | 4 | import android.os.Bundle; |
5 | +import android.os.SystemClock; | |
5 | 6 | import android.support.design.widget.TabLayout; |
6 | 7 | import android.support.v4.app.FragmentActivity; |
7 | 8 | import android.support.v4.view.ViewPager; |
... | ... | @@ -107,7 +108,7 @@ public class MainActivite extends FragmentActivity implements ASyncResponse { |
107 | 108 | |
108 | 109 | public void valideRechargement(View v) |
109 | 110 | { |
110 | - if((mToken != "") && ((System.currentTimeMillis() - mTimeToken) > 0)) { | |
111 | + if((mToken != "") && ((System.currentTimeMillis() - mTimeToken) < EXPIRATION)) { | |
111 | 112 | |
112 | 113 | } |
113 | 114 | else{ |
... | ... | @@ -171,6 +172,22 @@ public class MainActivite extends FragmentActivity implements ASyncResponse { |
171 | 172 | /* Retour du network thread */ |
172 | 173 | @Override |
173 | 174 | public void processFinish(JSONObject output) { |
174 | - //TODO: Uniquement pour la connexion | |
175 | + if(output.length() != 0){ | |
176 | + try{ | |
177 | + if(output.get("status").toString() == "ok"){ | |
178 | + mToken = output.get("token").toString(); | |
179 | + mTimeToken = System.currentTimeMillis(); | |
180 | + } | |
181 | + else{ | |
182 | + Toast.makeText(this, "Erreur dans la requête: " + output.get("status"), Toast.LENGTH_LONG).show(); | |
183 | + } | |
184 | + } | |
185 | + catch(Throwable t){ | |
186 | + Toast.makeText(this, "WTF, le cancer est dans l'application!!", Toast.LENGTH_LONG).show(); | |
187 | + } | |
188 | + } | |
189 | + else{ | |
190 | + Toast.makeText(this, "Impossible de se connecter au serveur", Toast.LENGTH_LONG).show(); | |
191 | + } | |
175 | 192 | } |
176 | 193 | } | ... | ... |