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

Merge branch 'release/v0.11.5' into develop

parents 58d12f7a 340c4717
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fr.utc.simde.jessy"
android:versionCode="37"
android:versionName="0.11.4">
android:versionCode="38"
android:versionName="0.11.5">
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.INTERNET" />
......
......@@ -25,10 +25,9 @@ import java.util.ArrayList;
import java.util.List;
import fr.utc.simde.jessy.adapters.ListAdapater;
import fr.utc.simde.jessy.responses.APIResponse;
import fr.utc.simde.jessy.responses.ArticleResponse;
import fr.utc.simde.jessy.responses.BottomatikResponse;
import fr.utc.simde.jessy.responses.ComedmusResponse;
import fr.utc.simde.jessy.responses.ReservationResponse;
import fr.utc.simde.jessy.responses.GingerResponse;
import fr.utc.simde.jessy.responses.QRCodeResponse;
import fr.utc.simde.jessy.tools.API;
......@@ -54,7 +53,6 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
protected List<Boolean> apiNeedKey;
protected List<Boolean> apiNeedGinger;
protected List<Class> apiResponseClass;
protected Object apiResponse;
@Override
public void onCreate(final Bundle savedInstanceState) {
......@@ -65,27 +63,33 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
this.apiName = new ArrayList<String>() {{
add("bottomatik");
add("comedmus");
add("reservations");
}};
this.apiUrl = new ArrayList<String>() {{
add("https://picasso.bottomatik.com/bot/transactions/");
add("https://www.lacomutc.fr/qr/" + sharedPreferences.getString("key_" + apiName.get(1), "no_key") + "/");
add("https://assos.utc.fr/simde/reservations/");
}};
this.apiNeedKey = new ArrayList<Boolean>() {{
add(true);
add(false);
add(true);
}};
this.apiNeedGinger = new ArrayList<Boolean>() {{
add(true);
add(false);
add(true);
}};
this.apiResponseClass = new ArrayList<Class>() {{
add(BottomatikResponse.class);
add(ComedmusResponse.class);
add(ReservationResponse.class);
add(ReservationResponse.class);
}};
this.scannerView = new ZXingScannerView(QRCodeReaderActivity.this) {
@Override
protected IViewFinder createViewFinderView(Context context) {
......@@ -109,13 +113,49 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
@Override
public void onIdentification(final String badgeId) {
this.scannerView.stopCamera();
/*
dialog.infoDialog(QRCodeReaderActivity.this, "Badge", badgeId, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
resumeReading();
}
});
*/
new Thread() {
@Override
public void run() {
Integer apiIndex = 2;
GingerResponse gingerResponse = null;
if (apiNeedGinger.get(apiIndex)) {
try {
ginger.getInfoFromBadge(badgeId);
Thread.sleep(100);
gingerResponse = new ObjectMapper().readValue(ginger.getRequest().getResponse(), GingerResponse.class);
}
catch (final Exception e) {
Log.e(LOG_TAG, e.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.infoDialog(QRCodeReaderActivity.this, getString(R.string.qrcode_reading), e.getMessage(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
resumeReading();
}
});
}
});
return;
}
}
handleAPI(gingerResponse.getLogin(), apiIndex, gingerResponse.getBadge_uid(), false);
}
}.start();
}
protected void resumeReading() {
......@@ -186,58 +226,65 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
}
}
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.changeLoading(getString(R.string.getting_informations_from) + " " + apiName.get(apiIndex));
}
});
API api = new API(QRCodeReaderActivity.this, apiName.get(apiIndex), apiUrl.get(apiIndex));
handleAPI(qrCodeResponse.getId(), apiIndex, gingerResponse == null ? null : gingerResponse.getBadge_uid(), true);
}
}.start();
}
if (apiNeedKey.get(apiIndex))
api.setKey(sharedPreferences.getString("key_" + apiName.get(apiIndex), ""));
protected void handleAPI(final String info, final Integer apiIndex, final String badgeId, final boolean byQRCode) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.changeLoading(getString(R.string.getting_informations_from) + " " + apiName.get(apiIndex));
}
});
try {
api.getInfosFromId(qrCodeResponse.getId());
Thread.sleep(100);
API api = new API(QRCodeReaderActivity.this, apiName.get(apiIndex), apiUrl.get(apiIndex));
apiResponse = new ObjectMapper().readValue(api.getRequest().getResponse(), apiResponseClass.get(apiIndex));
if (apiNeedKey.get(apiIndex))
api.setKey(sharedPreferences.getString("key_" + apiName.get(apiIndex), ""));
if (nemopaySession.getFoundationId() != -1 && ((APIResponse) apiResponse).getFoundationId() != null && ((APIResponse) apiResponse).getFoundationId() != nemopaySession.getFoundationId())
throw new Exception(getString(R.string.can_not_sell_other_foundation));
Object apiResponse;
try {
if (byQRCode)
api.getInfosFromId(info);
else
api.getInfosFromUsername(info);
Thread.sleep(100);
if (((APIResponse) apiResponse).isValidated())
throw new Exception(getString(R.string.already_validated));
apiResponse = new ObjectMapper().readValue(api.getRequest().getResponse(), apiResponseClass.get(apiIndex));
if (api.getRequest().getJSONResponse().has("type") && api.getRequest().getJSONResponse().get("type").textValue().equals("error") && api.getRequest().getJSONResponse().has("message"))
throw new Exception(api.getRequest().getJSONResponse().get("message").textValue());
}
catch (final Exception e) {
Log.e(LOG_TAG, e.getMessage());
if (api.getRequest().getJSONResponse().has("type") && api.getRequest().getJSONResponse().get("type").textValue().equals("error") && api.getRequest().getJSONResponse().has("message"))
throw new Exception(api.getRequest().getJSONResponse().get("message").textValue());
}
catch (final Exception e) {
Log.e(LOG_TAG, e.getMessage());
runOnUiThread(new Runnable() {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.infoDialog(QRCodeReaderActivity.this, getString(R.string.qrcode_reading), e.getMessage(), new DialogInterface.OnClickListener() {
@Override
public void run() {
dialog.infoDialog(QRCodeReaderActivity.this, getString(R.string.qrcode_reading), e.getMessage(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
resumeReading();
}
});
public void onClick(DialogInterface dialog, int which) {
resumeReading();
}
});
return;
}
});
if (apiIndex == 0)
payWithBottomatik(api, (BottomatikResponse) apiResponse, gingerResponse.getBadgeId());
else if (apiIndex == 1) {
checkReservation(api, (ComedmusResponse) apiResponse);
}
}
}.start();
return;
}
switch (apiIndex) {
case 0:
payWithBottomatik(api, (BottomatikResponse) apiResponse, badgeId);
break;
case 1:
case 2:
checkReservation(api, (ReservationResponse) apiResponse);
break;
}
}
public void payWithBottomatik(final API api, final BottomatikResponse bottomatikResponse, final String badgeId) {
......@@ -252,6 +299,12 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
List<List<Integer>> articleIdList = bottomatikResponse.getArticleList();
final ArrayNode purchaseList = new ObjectMapper().createArrayNode();
try {
if (nemopaySession.getFoundationId() != -1 && bottomatikResponse.getFun_id() != nemopaySession.getFoundationId())
throw new Exception(getString(R.string.can_not_sell_other_foundation));
if (bottomatikResponse.isValidated())
throw new Exception(getString(R.string.already_validated));
nemopaySession.getArticles();
Thread.sleep(100);
......@@ -304,7 +357,7 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
try {
if (!bottomatikResponse.isPaid()) {
nemopaySession.setTransaction(badgeId, bottomatikResponse.getArticleList(), bottomatikResponse.getFoundationId());
nemopaySession.setTransaction(badgeId, bottomatikResponse.getArticleList(), bottomatikResponse.getFun_id());
Thread.sleep(100);
}
......@@ -472,17 +525,17 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
}
}
protected void checkReservation(final API api, final ComedmusResponse comedmusResponse) {
protected void checkReservation(final API api, final ReservationResponse reservationResponse) {
long currentTimestamp = (System.currentTimeMillis() / 1000);
Log.d(LOG_TAG, "Current time: " + currentTimestamp);
if (currentTimestamp < comedmusResponse.getCreatedAt()) {
if (currentTimestamp < reservationResponse.getCreation_date()) {
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())
.setTitle(getString(R.string.reservation_number) + reservationResponse.getReservation_id())
.setMessage(getString(R.string.ticket_not_created_yet))
.setCancelable(false)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
......@@ -494,7 +547,7 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
.setNeutralButton(R.string.more, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
seeReservation(api, comedmusResponse);
seeReservation(api, reservationResponse);
}
});
......@@ -506,13 +559,13 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
return;
}
if (currentTimestamp > comedmusResponse.getExpiresAt()) {
if (currentTimestamp > reservationResponse.getExpires_at()) {
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())
.setTitle(getString(R.string.reservation_number) + reservationResponse.getReservation_id())
.setMessage(getString(R.string.ticket_expired))
.setCancelable(false)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
......@@ -524,7 +577,7 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
.setNeutralButton(R.string.more, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
seeReservation(api, comedmusResponse);
seeReservation(api, reservationResponse);
}
});
......@@ -539,24 +592,24 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
runOnUiThread(new Runnable() {
@Override
public void run() {
seeReservation(api, comedmusResponse);
seeReservation(api, reservationResponse);
}
});
}
protected void seeReservation(final API api, final ComedmusResponse comedmusResponse) {
protected void seeReservation(final API api, final ReservationResponse reservationResponse) {
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());
nameText.setText(reservationResponse.getUsername());
seanceText.setText(reservationResponse.getSeance());
priceText.setText(reservationResponse.getType());
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(QRCodeReaderActivity.this);
alertDialogBuilder
.setTitle(getString(R.string.reservation_number) + comedmusResponse.getReservationId())
.setTitle(getString(R.string.reservation_number) + reservationResponse.getReservation_id())
.setView(keyView)
.setCancelable(false)
.setPositiveButton(R.string.register, new DialogInterface.OnClickListener() {
......@@ -565,7 +618,7 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
@Override
public void run() {
try {
api.validate(comedmusResponse.getId());
api.validate(reservationResponse.getId());
Thread.sleep(100);
runOnUiThread(new Runnable() {
......
package fr.utc.simde.jessy.responses;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Created by Samy on 10/11/2017.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class APIResponse {
protected String id;
protected String username;
protected String type;
protected Integer fun_id;
protected long expires_at;
protected long creation_date;
protected boolean paid;
protected boolean validated;
protected long expires_at;
public String getId() { return this.id; }
public String getUsername() { return this.username; }
public String getType() { return this.type; }
public Integer getFoundationId() { return this.fun_id; }
public long getExpiresAt() { return this.expires_at; }
public long getCreatedAt() { return this.creation_date; }
public boolean isPaid() { return this.paid; }
public boolean isValidated() { return this.validated; }
public long getCreation_date() { return this.creation_date; }
public long getExpires_at() { return this.expires_at; }
}
package fr.utc.simde.jessy.responses;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.ArrayList;
import java.util.List;
......@@ -10,10 +10,19 @@ import java.util.List;
* Created by Samy on 10/11/2017.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class BottomatikResponse extends APIResponse {
protected String _id;
protected Integer fun_id;
protected boolean paid;
protected boolean validated;
protected List<List<String>> articles;
public String get_id() { return this._id; }
public Integer getFun_id() { return this.fun_id; }
public boolean isPaid() { return this.paid; }
public boolean isValidated() { return this.validated; }
public List<List<String>> getArticles() { return this.articles; }
public List<List<Integer>> getArticleList() {
List<List<Integer>> articleList = new ArrayList<List<Integer>>();
......
......@@ -17,12 +17,12 @@ public class GingerResponse {
protected boolean is_cotisant;
protected String badge_uid;
public String getUsername() { return login; }
public String getLastname() { return nom; }
public String getFirstname() { return prenom; }
public String getEmail() { return mail; }
public String getLogin() { return login; }
public String getNom() { return nom; }
public String getPrenom() { return prenom; }
public String getMail() { return mail; }
public String getType() { return type; }
public boolean getIsAdult() { return is_adulte; }
public boolean getIsContributer() { return is_cotisant; }
public String getBadgeId() { return badge_uid; }
public boolean getIs_adulte() { return is_adulte; }
public boolean getIs_cotisant() { return is_cotisant; }
public String getBadge_uid() { return badge_uid; }
}
......@@ -12,6 +12,10 @@ public class QRCodeResponse {
protected String id;
protected String system;
public void setUsername(String username) { this.username = username; }
public void setId(String id) { this.id = id; }
public void setSystem(String system) { this.system = system; }
public String getUsername() { return this.username; }
public String getId() { return this.id; }
public String getSystem() { return this.system; }
......
package fr.utc.simde.jessy.responses;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Created by Samy on 10/11/2017.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class ComedmusResponse extends APIResponse {
public class ReservationResponse extends APIResponse {
protected Integer reservation_id;
protected String seance;
public Integer getReservationId() { return this.reservation_id; }
public Integer getReservation_id() { return this.reservation_id; }
public String getSeance() { return this.seance; }
}
......@@ -55,7 +55,7 @@
android:layout_width="100dp"
android:textColor="#000000"
android:layout_height="wrap_content"
android:text="@string/price" />
android:text="@string/type" />
<TextView
android:id="@+id/text_price"
......
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