Commit 87b7400b authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

Cancel option

Can cancel all foundation articles
Adapt buyerInfoActivity
parent 4b7e2176
......@@ -50,6 +50,11 @@ public class BuyerInfoActivity extends BaseActivity {
this.textSolde = findViewById(R.id.text_solde);
this.linearLayout = findViewById(R.id.layout_articles);
if (getIntent().getExtras() == null || getIntent().getExtras().getString("buyerInfo") == null) {
generateNoPurchase(getString(R.string.badge_waiting));
return;
}
try {
JsonNode buyerInfo = new ObjectMapper().readTree(getIntent().getExtras().getString("buyerInfo"));
this.badgeId = getIntent().getExtras().getString("badgeId");
......@@ -73,21 +78,27 @@ public class BuyerInfoActivity extends BaseActivity {
}
@Override
protected void onIdentification(final String badgeId) { }
protected void onIdentification(final String badgeId) {
startBuyerInfoActivity(BuyerInfoActivity.this, badgeId);
}
protected void generateNoPurchase(final String text) {
TextView noPurchase = new TextView(this);
noPurchase.setText(text);
noPurchase.setTextSize(24);
noPurchase.setGravity(Gravity.CENTER);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
layoutParams.setMargins(100, 100, 100, 100);
noPurchase.setLayoutParams(layoutParams);
this.linearLayout.addView(noPurchase);
}
protected void generatePurchases() throws Exception {
if (this.lastPurchaseList.size() == 0) {
String foundationName = nemopaySession.getFoundationName();
TextView noPurchase = new TextView(this);
noPurchase.setText(getString(R.string.no_purchases) + (foundationName.equals("") ? "" : "\n(" + foundationName + ")"));
noPurchase.setTextSize(24);
noPurchase.setGravity(Gravity.CENTER);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
layoutParams.setMargins(100, 100, 100, 100);
noPurchase.setLayoutParams(layoutParams);
this.linearLayout.addView(noPurchase);
generateNoPurchase(getString(R.string.no_purchases) + (foundationName.equals("") ? "" : "\n(" + foundationName + ")"));
}
else {
generateArticleList();
......@@ -106,83 +117,86 @@ public class BuyerInfoActivity extends BaseActivity {
return;
}
if (article.get("fundation_id").intValue() == -1) {
dialog.infoDialog(BuyerInfoActivity.this, getString(R.string.cancel_transaction), getString(R.string.cant_cancel_other));
return;
}
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(BuyerInfoActivity.this);
alertDialogBuilder
.setTitle(R.string.cancel_transaction)
.setMessage(getString(R.string.ask_cancel_transaction) + " " + Integer.toString(article.get("quantity").intValue()) + "x " + article.get("name").textValue() + " (total: " + String.format("%.2f", new Float(article.get("price").intValue()) / 100.00f) + "€) ?")
.setCancelable(true)
.setPositiveButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
new Thread() {
@Override
public void run() {
if (nemopaySession.getFoundationId() != -1) {
try {
nemopaySession.cancelTransaction(nemopaySession.getFoundationId(), article.get("purchase_id").intValue());
Thread.sleep(100);
.setTitle(R.string.cancel_transaction)
.setMessage(getString(R.string.ask_cancel_transaction) + " " + Integer.toString(article.get("quantity").intValue()) + "x " + article.get("name").textValue() + " (total: " + String.format("%.2f", new Float(article.get("price").intValue()) / 100.00f) + "€) ?")
.setCancelable(true)
.setPositiveButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
new Thread() {
@Override
public void run() {
try {
nemopaySession.cancelTransaction(article.get("fundation_id").intValue(), article.get("purchase_id").intValue());
Thread.sleep(100);
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(BuyerInfoActivity.this);
alertDialogBuilder
.setTitle(R.string.cancel_transaction)
.setMessage(getString(R.string.transaction_canceled))
.setCancelable(true)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
try {
startBuyerInfoActivity(BuyerInfoActivity.this, badgeId);
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
dialog.errorDialog(BuyerInfoActivity.this, getResources().getString(R.string.information_collection), getResources().getString(R.string.error_view), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int id) {
finish();
}
});
}
}
});
dialog.createDialog(alertDialogBuilder);
}
});
} catch (final Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
try {
final JsonNode response = nemopaySession.getRequest().getJSONResponse();
if (response.has("error") && response.get("error").has("message")) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(BuyerInfoActivity.this);
alertDialogBuilder
.setTitle(R.string.cancel_transaction)
.setMessage(getString(R.string.transaction_canceled))
.setCancelable(true)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
try {
startBuyerInfoActivity(BuyerInfoActivity.this, badgeId);
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
dialog.errorDialog(BuyerInfoActivity.this, getResources().getString(R.string.information_collection), getResources().getString(R.string.error_view), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int id) {
finish();
}
});
}
}
});
dialog.createDialog(alertDialogBuilder);
dialog.errorDialog(BuyerInfoActivity.this, getString(R.string.cancel_transaction), response.get("error").get("message").textValue());
}
});
} catch (final Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
try {
final JsonNode response = nemopaySession.getRequest().getJSONResponse();
if (response.has("error") && response.get("error").has("message")) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
dialog.errorDialog(BuyerInfoActivity.this, getString(R.string.cancel_transaction), response.get("error").get("message").textValue());
}
});
}
else
throw new Exception("");
} catch (Exception e1) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
dialog.errorDialog(BuyerInfoActivity.this, getString(R.string.cancel_transaction), e.getMessage());
}
});
} else
throw new Exception("");
} catch (Exception e1) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
dialog.errorDialog(BuyerInfoActivity.this, getString(R.string.cancel_transaction), e.getMessage());
}
}
});
}
}
}.start();
}
})
.setNegativeButton(R.string.do_nothing, null);
}
}.start();
}
})
.setNegativeButton(R.string.do_nothing, null);
dialog.createDialog(alertDialogBuilder);
}
......@@ -216,30 +230,28 @@ public class BuyerInfoActivity extends BaseActivity {
@Override
public void run() {
ArrayNode articleFoundationList = new ObjectMapper().createArrayNode();
if (nemopaySession.getFoundationId() != -1) {
try {
int responseCode = nemopaySession.getArticles();
Thread.sleep(100);
// Toute une série de vérifications avant de lancer l'activité
final HTTPRequest request = nemopaySession.getRequest();
articleFoundationList = (ArrayNode) request.getJSONResponse();
for (final JsonNode article : articleFoundationList) {
if (!article.has("id") || !article.has("price") || !article.has("name") || !article.has("active") || !article.has("cotisant") || !article.has("alcool") || !article.has("categorie_id") || !article.has("image_url") || !article.has("fundation_id") || article.get("fundation_id").intValue() != nemopaySession.getFoundationId())
throw new Exception("Unexpected JSON");
}
} catch (final Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
dialog.errorDialog(BuyerInfoActivity.this, getString(R.string.article_list_collecting), e.getMessage());
}
});
try {
nemopaySession.getArticles();
Thread.sleep(100);
// Toute une série de vérifications avant de lancer l'activité
final HTTPRequest request = nemopaySession.getRequest();
articleFoundationList = (ArrayNode) request.getJSONResponse();
for (final JsonNode article : articleFoundationList) {
if (!article.has("id") || !article.has("price") || !article.has("name") || !article.has("cotisant") || !article.has("alcool") || !article.has("categorie_id") || !article.has("image_url") || !article.has("fundation_id"))
throw new Exception("Unexpected JSON");
}
} catch (final Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
dialog.errorDialog(BuyerInfoActivity.this, getString(R.string.article_list_collecting), e.getMessage());
}
});
}
final ArrayNode articleList = new ObjectMapper().createArrayNode();
......@@ -270,6 +282,7 @@ public class BuyerInfoActivity extends BaseActivity {
"\"price\":" + Integer.toString(purchase.get("pur_price").intValue()) + ", " +
"\"quantity\":" + Math.round(purchase.get("pur_qte").floatValue()) + ", " +
"\"purchase_id\":" + purchase.get("pur_id").intValue() + ", " +
"\"fundation_id\":-1, " +
"\"info\":\"" + getString(R.string.realized_by_other) + "\", " +
"\"canceled\":\"" + Boolean.toString(purchase.get("pur_removed").booleanValue()) + "\", " +
"\"image_url\":\"\"}"
......
package fr.utc.simde.jessy;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.support.v7.app.AlertDialog;
......@@ -114,8 +115,10 @@ public class FoundationsOptionsActivity extends BaseActivity {
this.optionList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
if (isOption(position,0))
dialog.infoDialog(FoundationsOptionsActivity.this, "Non encore fait", "Pour la version 0.10");
if (isOption(position,0)) {
nemopaySession.setFoundation(-1, "", -1);
startActivity(new Intent(FoundationsOptionsActivity.this, BuyerInfoActivity.class));
}
else if (isOption(position,1))
dialog.infoDialog(FoundationsOptionsActivity.this, "Non encore fait", "Pour la version 0.11");
else if (isOption(position,2))
......
......@@ -297,8 +297,6 @@ public class HTTPRequest {
synchronized void updateCookies(final List<String> cookiesHeader) {
if (cookiesHeader != null) {
Log.d(LOG_TAG, "cookies : " + cookiesHeader);
for (String cookie : cookiesHeader) {
try {
cookie = cookie.substring(0, cookie.indexOf(";"));
......
......@@ -231,14 +231,12 @@ public class NemopaySession {
if (!isConnected())
throw new Exception(this.notLogged);
if (this.foundationId == -1)
throw new Exception("No foundation set");
return request(
"POSS3",
"getProducts",
new HashMap<String, String>() {{
put("fun_id", Integer.toString(foundationId));
if (foundationId != -1)
put("fun_id", Integer.toString(foundationId));
}},
new String[]{
"POSS3"
......
......@@ -14,7 +14,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="20dp" />
android:textSize="20dp"
android:text="@string/information_collection" />
</LinearLayout>
......
......@@ -8,6 +8,8 @@
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_marginLeft="20dp"
android:gravity="center_vertical">
......@@ -70,18 +72,19 @@
android:layout_height="18dp"
android:src="@mipmap/image_18_round" />
</LinearLayout>
<TextView
android:id="@+id/text_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="75dp"/>
android:layout_marginRight="75dp" />
<TextView
android:id="@+id/text_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" />
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
......@@ -141,6 +141,7 @@
<string name="can_sell">Permettre la vente</string>
<string name="already_canceled">La transaction a déjà été annulée</string>
<string name="cant_cancel">L\'application a été configurée pour ne pas permettre l\'annulation d\'une transaction (contacter un adminstrateur pour annuler)</string>
<string name="cant_cancel_other">Il n\'est pas possible d\'annuler la transaction réalisée par une autre fondation</string>
<string name="read_card_information">Informations de la carte</string>
<string name="add_new_card">Ajouter</string>
<string name="read_new_card">Lire</string>
......
Supports Markdown
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