Prise en compte de la configuration du serveur (Preference->Serveur) lors de la recuperation des parties.

This commit is contained in:
Bertrand BRUN 2011-02-09 00:13:18 +01:00
parent 08de1097aa
commit f03f061d6f
3 changed files with 44 additions and 68 deletions

View File

@ -98,7 +98,6 @@ public class BaseGame extends Activity implements OnClickListener {
Relation r = Relation.getInstance(); Relation r = Relation.getInstance();
// TODO : Pour l'instant la poubelle ne fait rien. Il faudra certainement la ranger dans un categorie dans GamePlayed pour calculer le score.
ImageView trash = ((ImageView)findViewById(R.id.trash)); ImageView trash = ((ImageView)findViewById(R.id.trash));
trash.setOnClickListener(this); trash.setOnClickListener(this);
trash.setImageResource(android.R.drawable.ic_menu_delete); trash.setImageResource(android.R.drawable.ic_menu_delete);

View File

@ -1,7 +1,7 @@
package org.pticlic.model; package org.pticlic.model;
public class Constant { public class Constant {
public static final String SERVER_URL = "SERVER_URL"; public static final String SERVER_URL = "server";
public static final String SERVER_AUTH = "SERVER_AUTH"; public static final String SERVER_AUTH = "SERVER_AUTH";

View File

@ -95,29 +95,32 @@ public class Network {
* @return <code>true</code> si la combinaison login/mdp est correct <code>false</code> sinon * @return <code>true</code> si la combinaison login/mdp est correct <code>false</code> sinon
*/ */
public static boolean isLoginCorrect(Context context, String id, String passwd) { public static boolean isLoginCorrect(Context context, String id, String passwd) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
String serverURL = sp.getString(Constant.SERVER_URL, "http://dumbs.fr/~bbrun/pticlic.json");
URL url; //TODO : A decommenter le jour ou ce sera implemente cote serveur
boolean res = false; // SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
try { // String serverURL = sp.getString(Constant.SERVER_URL, "http://dumbs.fr/~bbrun/pticlic.json");
url = new URL(serverURL); //
URLConnection connection = url.openConnection(); // URL url;
connection.addRequestProperty("action", "verifyAccess"); // boolean res = false;
connection.addRequestProperty("user", id); // try {
connection.addRequestProperty("passwd", passwd); // url = new URL(serverURL);
// URLConnection connection = url.openConnection();
InputStream in = connection.getInputStream(); // connection.addRequestProperty("action", "verifyAccess");
BufferedReader buf = new BufferedReader(new InputStreamReader(in)); // connection.addRequestProperty("user", id);
res = Boolean.getBoolean(buf.readLine()); // connection.addRequestProperty("passwd", passwd);
//
} catch (MalformedURLException e) { // InputStream in = connection.getInputStream();
return false; // BufferedReader buf = new BufferedReader(new InputStreamReader(in));
} catch (IOException e) { // res = Boolean.getBoolean(buf.readLine());
return false; //
} // } catch (MalformedURLException e) {
// return false;
return res; // } catch (IOException e) {
// return false;
// }
//
// return res;
return true;
} }
/** /**
@ -128,53 +131,27 @@ public class Network {
public DownloadedGame getGames(int nbGames) { public DownloadedGame getGames(int nbGames) {
DownloadedGame game = null; DownloadedGame game = null;
try { try {
//URL url = new URL(this.serverURL); // TODO : ne restera le temps que les requete du serveur passe du GET au POST
String urlS = this.serverURL+"/pticlic.php?"
+ "action=" + Action.GET_GAMES.value()
+ "&user=" + this.id
+ "&passwd=" + this.passwd
+ "&nb=" + String.valueOf(nbGames)
+ "&mode="+mode.value();
URL url = new URL(urlS);
URL url = new URL("http://dumbs.fr/~bbrun/pticlic/pticlic.php?" // URLConnection connection = url.openConnection();
+ "action=" + Action.GET_GAMES.value() // connection.addRequestProperty("action", Action.GET_GAMES.value());
+ "&user=" + this.id // connection.addRequestProperty("user", this.id);
+ "&passwd=" + this.passwd // connection.addRequestProperty("passwd", this.passwd);
+ "&nb=" + String.valueOf(nbGames) // connection.addRequestProperty("nb", String.valueOf(nbGames));
+ "&mode="+mode.value()); // connection.addRequestProperty("mode", mode.value());
URLConnection connection = url.openConnection();
connection.addRequestProperty("action", Action.GET_GAMES.value());
connection.addRequestProperty("user", this.id);
connection.addRequestProperty("passwd", this.passwd);
connection.addRequestProperty("nb", String.valueOf(nbGames));
connection.addRequestProperty("mode", mode.value());
Gson gson = new Gson(); Gson gson = new Gson();
//JsonReader reader = new JsonReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); //JsonReader reader = new JsonReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
JsonReader reader = new JsonReader(new InputStreamReader(url.openStream(), "UTF-8")); JsonReader reader = new JsonReader(new InputStreamReader(url.openStream(), "UTF-8"));
// //[
// {
// gid:2,
// pgid:117,
// cat1:10,
// cat2:5,
// cat3:0,
// cat4:-1,
// center:{id:173311, name:"nordafricain"},
// cloudsize:10,
// cloud:[
// {id:9894,name:"g\u00e9ographie"},
// {id:110821,name:"cannibale"},
// {id:131053,name:"motricit\u00e9"},
// {id:110821,name:"cannibale"},
// {id:110821,name:"cannibale"},
// {id:151567,name:"_FL:3"},
// {id:9894,name:"g\u00e9ographie"},
// {id:9894,name:"g\u00e9ographie"},
// {id:9894,name:"g\u00e9ographie"},
// {id:131053,name:"motricit\u00e9"}
// ]
// }
// ]
// FIXME : Attention lorsque l'on pourra vraiment recupere plusieur partie, il faudra changer ce qui suit. // FIXME : Attention lorsque l'on pourra vraiment recupere plusieur partie, il faudra changer ce qui suit.
reader.beginArray(); reader.beginArray();
while (reader.hasNext()) { while (reader.hasNext()) {