Commit b1052491 authored by djamel's avatar djamel

gestion des places pour mineur

parent 3d8e3ed7
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" /> <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component> </component>
</project> </project>
\ No newline at end of file
...@@ -9,17 +9,20 @@ import java.io.Serializable; ...@@ -9,17 +9,20 @@ import java.io.Serializable;
* Created by djamel on 17/10/15. * Created by djamel on 17/10/15.
*/ */
public class Key_List implements Parcelable, Serializable { public class Key_List implements Parcelable, Serializable {
int id; private int id;
String key; private String key;
private boolean is_child;
public Key_List(int id, String key) { public Key_List(int id, String key, boolean is_child) {
this.id = id; this.id = id;
this.key = key; this.key = key;
this.is_child = is_child;
} }
protected Key_List(Parcel in) { protected Key_List(Parcel in) {
this.id = in.readInt(); this.id = in.readInt();
this.key = in.readString(); this.key = in.readString();
this.is_child = in.readByte() != 0;
} }
public int getId() { public int getId() {
...@@ -30,6 +33,10 @@ public class Key_List implements Parcelable, Serializable { ...@@ -30,6 +33,10 @@ public class Key_List implements Parcelable, Serializable {
return this.key; return this.key;
} }
public boolean getIs_child() {
return this.is_child;
}
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;
...@@ -39,6 +46,7 @@ public class Key_List implements Parcelable, Serializable { ...@@ -39,6 +46,7 @@ public class Key_List implements Parcelable, Serializable {
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(this.id); dest.writeInt(this.id);
dest.writeString(this.key); dest.writeString(this.key);
dest.writeByte((byte) (this.is_child ? 1 : 0));
} }
......
...@@ -76,7 +76,7 @@ public class Login extends ActionBarActivity implements View.OnClickListener { ...@@ -76,7 +76,7 @@ public class Login extends ActionBarActivity implements View.OnClickListener {
for (int index = 0; index < response.length(); index++) { for (int index = 0; index < response.length(); index++) {
element = response.getJSONObject(index); element = response.getJSONObject(index);
Key_List key = new Key_List(element.getInt("id"), element.getString Key_List key = new Key_List(element.getInt("id"), element.getString
("key")); ("key"), element.getBoolean("is_child"));
key_list.add(key); key_list.add(key);
} }
} catch (JSONException e) { } catch (JSONException e) {
......
...@@ -38,7 +38,7 @@ import cz.msebera.android.httpclient.entity.StringEntity; ...@@ -38,7 +38,7 @@ import cz.msebera.android.httpclient.entity.StringEntity;
public class Read_QR_Code extends ActionBarActivity implements View.OnClickListener { public class Read_QR_Code extends ActionBarActivity implements View.OnClickListener {
static final String ACTION_SCAN = "com.google.zxing.client.android.SCAN"; private static final String ACTION_SCAN = "com.google.zxing.client.android.SCAN";
private ArrayList<Key_List> key_list = null; private ArrayList<Key_List> key_list = null;
private String server; private String server;
private EditText _nbrPlace; private EditText _nbrPlace;
...@@ -153,69 +153,95 @@ public class Read_QR_Code extends ActionBarActivity implements View.OnClickListe ...@@ -153,69 +153,95 @@ public class Read_QR_Code extends ActionBarActivity implements View.OnClickListe
// Ticket is valid // Ticket is valid
idFound = true; idFound = true;
JSONObject jsonParams = new JSONObject(); if (key.getIs_child()) {
StringEntity entity = null; showChildDialog(Read_QR_Code.this, str[3], nbrPlaceTot, nbrPlaceSelect);
}
else {
sendRequest(str[3], nbrPlaceTot, nbrPlaceSelect);
}
}
}
}
if (!idFound) {
display(getString(R.string.ebillet_false), false);
}
}
try { private AlertDialog showChildDialog(final Activity act, final String hash, final int nbrPlaceTot,
// Set parameters in JSON structure final int nbrPlaceSelect) {
jsonParams.put("verif", str[3]); AlertDialog.Builder childDialog = new AlertDialog.Builder(act);
jsonParams.put("nb", nbrPlaceTot); childDialog.setMessage(R.string.ebillet_mineur);
jsonParams.put("qt", nbrPlaceSelect); childDialog.setPositiveButton(R.string.check, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
sendRequest(hash, nbrPlaceTot, nbrPlaceSelect);
}
});
childDialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
display(getString(R.string.cancelled), true);
}
});
return childDialog.show();
}
private void sendRequest(String hash, int nbrPlaceTot, int nbrPlaceSelect) {
JSONObject jsonParams = new JSONObject();
StringEntity entity = null;
// Set JSON parameters for Post request try {
entity = new StringEntity(jsonParams.toString()); // Set parameters in JSON structure
jsonParams.put("verif", hash);
jsonParams.put("nb", nbrPlaceTot);
jsonParams.put("qt", nbrPlaceSelect);
// Set JSON parameters for Post request
entity = new StringEntity(jsonParams.toString());
} catch (JSONException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
// Send Post Request } catch (JSONException e) {
AsyncHttpClient client = new AsyncHttpClient(); e.printStackTrace();
client.setTimeout(5000); } catch (UnsupportedEncodingException e) {
client.post(this, server + "/validate", entity, "application/json", e.printStackTrace();
new JsonHttpResponseHandler() { }
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) { // Send Post Request
try { AsyncHttpClient client = new AsyncHttpClient();
if (response.getBoolean("valid")) { client.setTimeout(5000);
display(getString(R.string.ebillet_true) + String.valueOf( client.post(this, server + "/validate", entity, "application/json",
response.getInt("available")), true); new JsonHttpResponseHandler() {
} @Override
else if (response.getInt("available") < 0) { public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
display(getString(R.string.ebillet_sizeOff), false); try {
} if (response.getBoolean("valid")) {
else { display(getString(R.string.ebillet_true) + String.valueOf(
display(getString(R.string.ebillet_false), false); response.getInt("available")), true);
} }
} catch (JSONException e) { else if (response.getInt("available") < 0) {
e.printStackTrace(); display(getString(R.string.ebillet_sizeOff), false);
}
else {
display(getString(R.string.ebillet_false), false);
} }
} catch (JSONException e) {
e.printStackTrace();
} }
}
@Override @Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
display(getString(R.string.serverError), false); display(getString(R.string.serverError), false);
} }
@Override @Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
display(getString(R.string.serverError), false); display(getString(R.string.serverError), false);
} }
@Override @Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONArray errorResponse) { public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONArray errorResponse) {
display(getString(R.string.serverError), false); display(getString(R.string.serverError), false);
} }
}); });
}
}
}
if (!idFound) {
display(getString(R.string.ebillet_false), false);
}
} }
/** /**
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<string name="label_ipAddress">Adresse IP</string> <string name="label_ipAddress">Adresse IP</string>
<string name="label_port">Numéro de Port</string> <string name="label_port">Numéro de Port</string>
<string name="connect">Se connecter</string> <string name="connect">Se connecter</string>
<string name="connecting">Connection en cours ...</string> <string name="connecting">Connection en cours </string>
<string name="nbPlace">Nombre de place</string> <string name="nbPlace">Nombre de place</string>
<string name="nbPlaceOversize">Le nombre de place selectionné excéde le nombre de place <string name="nbPlaceOversize">Le nombre de place selectionné excéde le nombre de place
disponible pour ce billet</string> disponible pour ce billet</string>
...@@ -24,4 +24,7 @@ ...@@ -24,4 +24,7 @@
\'192.168.0.1\'</string> \'192.168.0.1\'</string>
<string name="errorPORT">Erreur: Vérifiez le numéro de port</string> <string name="errorPORT">Erreur: Vérifiez le numéro de port</string>
<string name="ex_3">ex: 3</string> <string name="ex_3">ex: 3</string>
<string name="ebillet_mineur">Cette place est une place pour mineur !</string>
<string name="cancel">Annuler</string>
<string name="cancelled">L\'opération a été annulé</string>
</resources> </resources>
...@@ -57,11 +57,13 @@ data/keys.json.example ...@@ -57,11 +57,13 @@ data/keys.json.example
[ [
{ {
"id": 1120, "id": 1120,
"key": "VDLV7897IEetisuare" "key": "VDLV7897IEetisuare",
"is_child": true
}, },
{ {
"id": 7988, "id": 7988,
"key": "TISEdodp7897tesiuaV8V" "key": "TISEdodp7897tesiuaV8V",
"is_child": false
} }
] ]
``` ```
......
[ [
{ {
"id": 1120, "id": 1120,
"key": "VDLV7897IEetisuare" "key": "VDLV7897IEetisuare",
"is_child": true
}, },
{ {
"id": 7988, "id": 7988,
"key": "TISEdodp7897tesiuaV8V" "key": "TISEdodp7897tesiuaV8V",
"is_child", false
} }
] ]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment