Commit d0d7e98d authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

QRCode & API management

Manage comedmus API
Optimization
parent 1c394bd0
......@@ -102,7 +102,8 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
public void onResume() {
super.onResume();
resumeReading();
if (!dialog.isShowing())
resumeReading();
}
@Override
......@@ -128,14 +129,12 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
QRCodeResponse qrCodeResponse = new ObjectMapper().readValue(result.getText(), QRCodeResponse.class);
if (!this.apiName.contains(qrCodeResponse.getSystem())) {
/* dialog.infoDialog(QRCodeReaderActivity.this, result.getBarcodeFormat().toString() + ": " + getString(R.string.not_understood), result.getText(), new DialogInterface.OnClickListener() {
dialog.infoDialog(QRCodeReaderActivity.this, result.getBarcodeFormat().toString() + ": " + getString(R.string.not_understood), result.getText(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
resumeReading();
}
});*/
handleQRCode(qrCodeResponse, 0);
});
}
else
handleQRCode(qrCodeResponse, this.apiName.indexOf(qrCodeResponse.getSystem()));
......@@ -236,7 +235,7 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
if (apiIndex == 0)
payWithBottomatik(api, (BottomatikResponse) apiResponse, gingerResponse.getBadgeId());
else if (apiIndex == 1) {
seeReservation(api, (ComedmusResponse) apiResponse);
checkReservation(api, (ComedmusResponse) apiResponse);
}
}
}.start();
......@@ -314,7 +313,7 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
@Override
public void run() {
dialog.stopLoading();
Toast.makeText(QRCodeReaderActivity.this, getString(R.string.transaction_realized), Toast.LENGTH_LONG).show();
Toast.makeText(QRCodeReaderActivity.this, getString(R.string.ticket_realized), Toast.LENGTH_LONG).show();
((Vibrator) getSystemService(QRCodeReaderActivity.VIBRATOR_SERVICE)).vibrate(250);
final LayoutInflater layoutInflater = LayoutInflater.from(QRCodeReaderActivity.this);
......@@ -337,7 +336,7 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
dialog.startLoading(QRCodeReaderActivity.this, getResources().getString(R.string.paiement), getResources().getString(R.string.transaction_in_validation));
dialog.startLoading(QRCodeReaderActivity.this, getResources().getString(R.string.paiement), getResources().getString(R.string.ticket_in_validation));
new Thread() {
@Override
......@@ -350,7 +349,7 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
@Override
public void run() {
dialog.stopLoading();
Toast.makeText(QRCodeReaderActivity.this, getString(R.string.transaction_validated), Toast.LENGTH_LONG).show();
Toast.makeText(QRCodeReaderActivity.this, getString(R.string.ticket_validated), Toast.LENGTH_LONG).show();
resumeReading();
}
......@@ -373,7 +372,7 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
dialog.startLoading(QRCodeReaderActivity.this, getResources().getString(R.string.qrcode_reading), getResources().getString(R.string.transaction_in_cancelation));
dialog.startLoading(QRCodeReaderActivity.this, getResources().getString(R.string.qrcode_reading), getResources().getString(R.string.ticket_in_cancelation));
new Thread() {
@Override
......@@ -386,7 +385,7 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
@Override
public void run() {
dialog.stopLoading();
Toast.makeText(QRCodeReaderActivity.this, getString(R.string.transaction_refunded), Toast.LENGTH_LONG).show();
Toast.makeText(QRCodeReaderActivity.this, getString(R.string.ticket_refunded), Toast.LENGTH_LONG).show();
((Vibrator) getSystemService(QRCodeReaderActivity.VIBRATOR_SERVICE)).vibrate(250);
resumeReading();
......@@ -474,66 +473,131 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
}
}
protected void seeReservation(final API api, final ComedmusResponse comedmusAPI) {
protected void checkReservation(final API api, final ComedmusResponse comedmusResponse) {
if ((System.currentTimeMillis() / 1000) < comedmusResponse.getCreatedAt()) {
runOnUiThread(new Runnable() {
@Override
public void run() {
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(QRCodeReaderActivity.this);
alertDialogBuilder
.setTitle(getString(R.string.reservation_number) + comedmusResponse.getReservationId())
.setMessage(getString(R.string.ticket_not_created_yet))
.setCancelable(false)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
resumeReading();
}
})
.setNeutralButton(R.string.more, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
seeReservation(api, comedmusResponse);
}
});
dialog.createDialog(alertDialogBuilder);
((Vibrator) getSystemService(QRCodeReaderActivity.VIBRATOR_SERVICE)).vibrate(500);
}
});
return;
}
if ((System.currentTimeMillis() / 1000) > comedmusResponse.getExpiresAt()) {
runOnUiThread(new Runnable() {
@Override
public void run() {
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(QRCodeReaderActivity.this);
alertDialogBuilder
.setTitle(getString(R.string.reservation_number) + comedmusResponse.getReservationId())
.setMessage(getString(R.string.ticket_expired))
.setCancelable(false)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
resumeReading();
}
})
.setNeutralButton(R.string.more, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
seeReservation(api, comedmusResponse);
}
});
dialog.createDialog(alertDialogBuilder);
((Vibrator) getSystemService(QRCodeReaderActivity.VIBRATOR_SERVICE)).vibrate(500);
}
});
return;
}
runOnUiThread(new Runnable() {
@Override
public void run() {
final View keyView = getLayoutInflater().inflate(R.layout.dialog_reservation_info, null);
final TextView nameText = keyView.findViewById(R.id.text_name);
final TextView seanceText = keyView.findViewById(R.id.text_seance);
final TextView priceText = keyView.findViewById(R.id.text_price);
nameText.setText(comedmusAPI.getUsername());
seanceText.setText(comedmusAPI.getSeance());
priceText.setText(comedmusAPI.getType());
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(QRCodeReaderActivity.this);
alertDialogBuilder
.setTitle(getString(R.string.reservation_number) + comedmusAPI.getReservationId())
.setView(keyView)
.setCancelable(false)
.setPositiveButton(R.string.register, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {dialog.startLoading(QRCodeReaderActivity.this, getResources().getString(R.string.paiement), getResources().getString(R.string.transaction_in_validation));
new Thread() {
@Override
public void run() {
try {
api.validate(comedmusAPI.getId(), false, true);
Thread.sleep(100);
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
Toast.makeText(QRCodeReaderActivity.this, getString(R.string.transaction_validated), Toast.LENGTH_LONG).show();
resumeReading();
}
});
} catch (final Exception e) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Log.e(LOG_TAG, "error: " + e.getMessage());
dialog.errorDialog(QRCodeReaderActivity.this, getString(R.string.qrcode_reading), e.getMessage());
resumeReading();
}
});
}
}
}.start();
}
})
.setNegativeButton(R.string.ok, new DialogInterface.OnClickListener() {
seeReservation(api, comedmusResponse);
}
});
}
protected void seeReservation(final API api, final ComedmusResponse comedmusResponse) {
final View keyView = getLayoutInflater().inflate(R.layout.dialog_reservation_info, null);
final TextView nameText = keyView.findViewById(R.id.text_name);
final TextView seanceText = keyView.findViewById(R.id.text_seance);
final TextView priceText = keyView.findViewById(R.id.text_price);
nameText.setText(comedmusResponse.getUsername());
seanceText.setText(comedmusResponse.getSeance());
priceText.setText(comedmusResponse.getType());
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(QRCodeReaderActivity.this);
alertDialogBuilder
.setTitle(getString(R.string.reservation_number) + comedmusResponse.getReservationId())
.setView(keyView)
.setCancelable(false)
.setPositiveButton(R.string.register, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {dialog.startLoading(QRCodeReaderActivity.this, getResources().getString(R.string.paiement), getResources().getString(R.string.ticket_in_validation));
new Thread() {
@Override
public void onClick(DialogInterface dialog, int which) {
resumeReading();
public void run() {
try {
api.validate(comedmusResponse.getId());
Thread.sleep(100);
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
Toast.makeText(QRCodeReaderActivity.this, getString(R.string.ticket_validated), Toast.LENGTH_LONG).show();
resumeReading();
}
});
} catch (final Exception e) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Log.e(LOG_TAG, "error: " + e.getMessage());
dialog.errorDialog(QRCodeReaderActivity.this, getString(R.string.qrcode_reading), e.getMessage());
resumeReading();
}
});
}
}
});
}.start();
}
})
.setNegativeButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
resumeReading();
}
});
dialog.createDialog(alertDialogBuilder);
}
});
dialog.createDialog(alertDialogBuilder);
}
}
......@@ -110,7 +110,7 @@ public class SellActivity extends ArticleGroupActivity {
@Override
public void run() {
dialog.stopLoading();
Toast.makeText(SellActivity.this, getString(R.string.transaction_realized), Toast.LENGTH_LONG).show();
Toast.makeText(SellActivity.this, getString(R.string.ticket_realized), Toast.LENGTH_LONG).show();
setBackgroundColor(getResources().getColor(R.color.success));
((Vibrator) getSystemService(ArticleGroupActivity.VIBRATOR_SERVICE)).vibrate(250);
}
......
......@@ -6,6 +6,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.AsyncTask;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
......@@ -147,25 +148,26 @@ public abstract class ArticlesAdapter extends BaseAdapter {
}
public void setImage(final ImageView imageView, final String url, final int position) {
final HTTPRequest[] request = new HTTPRequest[1];
if (imageList[position] != null)
imageView.setImageBitmap(imageList[position]);
else if (url != null && !url.equals("")) {
new Thread(){
@Override
public void run() {
request[0] = new HTTPRequest(url);
final HTTPRequest httpRequest = new HTTPRequest(url);
if (request[0].get() == 200) {
if (httpRequest.get() == 200) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
imageList[position] = request[0].getImageResponse();
if (!httpRequest.isImageResponse())
throw new Exception("Not an Image");
imageList[position] = httpRequest.getImageResponse();
imageView.setImageBitmap(imageList[position]);
} catch (Exception e) {
e.printStackTrace();
Log.e(LOG_TAG, e.getMessage());
}
}
});
......
......@@ -8,9 +8,9 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown = true)
public class ComedmusResponse extends APIResponse {
protected Integer reservationId;
protected Integer reservation_id;
protected String seance;
public Integer getReservationId() { return this.reservationId; }
public Integer getReservationId() { return this.reservation_id; }
public String getSeance() { return this.seance; }
}
......@@ -46,6 +46,11 @@ public class API {
public HTTPRequest getRequest() { return this.request; }
public int validate(final String id) throws Exception {
return request(
id + "/validate"
);
}
public int validate(final String id, final boolean paid, final boolean served) throws Exception {
return request(
id + "/validate",
......
......@@ -183,7 +183,7 @@ public class HTTPRequest {
}
catch (Exception e) {
this.BitmapResponse = null;
throw new Exception("Malformed JSON");
throw new Exception("Malformed IMG");
}
}
else {
......@@ -198,7 +198,7 @@ public class HTTPRequest {
in.close();
this.StringResponse = builder.toString();
if (this.request.getContentType().equals("application/json")) {
if (this.request.getContentType().contains("application/json")) {
try {
this.JSONResponse = new ObjectMapper().readTree(this.StringResponse);
this.responseType = "JSON";
......
......@@ -19,6 +19,7 @@
<string name="erase">Effacer</string>
<string name="cancel">Annuler</string>
<string name="add">Ajouter</string>
<string name="more">En savoir plus</string>
<string name="do_nothing">Ne rien faire</string>
<string name="quit">Quitter</string>
<string name="app_registred">Appareil enregistré</string>
......@@ -176,15 +177,15 @@
<string name="need_camera_permission">Il est nécessaire d\'autoriser l\'application à utiliser la caméra pour lire un QR Code</string>
<string name="qrcode_reading">Lecture d\'un QR Code</string>
<string name="article_name">Nom de l\'article</string>
<string name="bottomatik_get_transaction">Récupération de la transaction auprès de Bottomatik</string>
<string name="bottomatik_already_validated">La commande a déjà été servie</string>
<string name="can_not_sell_other_foundation">Il n\'est pas possible de vendre des produits d\'une autre fondation</string>
<string name="transaction_realized">Paiement effectué</string>
<string name="transaction_in_validation">Transaction en cours de validation</string>
<string name="transaction_validated">Transaction validée</string>
<string name="transaction_in_cancelation">Transaction en cours d\'annulation</string>
<string name="transaction_refunded">Remboursement réalisé</string>
<string name="transaction_no">Aucune commande récente n\'a été réalisée</string>
<string name="ticket_realized">Paiement effectué</string>
<string name="ticket_in_validation">Ticket en cours de validation</string>
<string name="ticket_validated">Ticket validée</string>
<string name="ticket_in_cancelation">Ticket en cours d\'annulation</string>
<string name="ticket_refunded">Remboursement réalisé</string>
<string name="ticket_no">Aucune commande récente n\'a été réalisée</string>
<string name="ticket_not_created_yet">Le ticket n\'est pas encore valide</string>
<string name="ticket_expired">Le ticket n\'est plus valide, il a expiré</string>
<string name="variable_price">Prix variable</string>
<string name="not_understood">Non compris</string>
<string name="getting_informations_from">Récupérations des informations depuis</string>
......
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