Commit 5bd159f0 authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

Cancel config

Authorize or not to cancel transaction
parent 0b9fb476
......@@ -188,6 +188,7 @@ public class ArticleCategoryActivity extends BaseActivity {
public void onClick(View view) {
config.setFoundation(-1, "");
config.setGroupList(new ObjectMapper().createObjectNode());
config.setCanCancel(true);
startMainActivity(ArticleCategoryActivity.this);
}
......@@ -288,15 +289,15 @@ public class ArticleCategoryActivity extends BaseActivity {
LayoutInflater layoutInflater = LayoutInflater.from(ArticleCategoryActivity.this);
View popupView = layoutInflater.inflate(R.layout.dialog_group, null);
ListView listView = popupView.findViewById(R.id.list_groups);
final Switch canCancelSwitch = popupView.findViewById(R.id.swtich_cancel);
canCancelSwitch.setChecked(config.getCanCancel());
JsonNode categoryList = null;
JsonNode categoryList;
GroupAdapter groupAdapter = null;
try {
categoryList = nemopaySession.getRequest().getJSONResponse();
groupAdapter = new GroupAdapter(ArticleCategoryActivity.this, categoryList);
final GroupAdapter finalGroupAdapter = groupAdapter;
listView.setAdapter(groupAdapter);
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
......@@ -307,11 +308,13 @@ public class ArticleCategoryActivity extends BaseActivity {
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ArticleCategoryActivity.this);
final GroupAdapter finalGroupAdapter = groupAdapter;
alertDialogBuilder
.setTitle(R.string.category_list)
.setTitle(R.string.configuration)
.setView(popupView)
.setCancelable(false)
.setPositiveButton(R.string.applicate, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
config.setCanCancel(canCancelSwitch.isChecked());
if (finalGroupAdapter.getList().size() == 0) {
Toast.makeText(ArticleCategoryActivity.this, getString(R.string.category_0_selected), Toast.LENGTH_LONG).show();
configApp();
......@@ -323,7 +326,11 @@ public class ArticleCategoryActivity extends BaseActivity {
}
}
})
.setNegativeButton(R.string.cancel, null);
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
config.setCanCancel(true);
}
});
dialog.createDialog(alertDialogBuilder);
}
......
......@@ -113,92 +113,103 @@ public class BuyerInfoActivity extends BaseActivity {
this.linearLayout.addView(listView);
this.listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
final JsonNode article = lastArticleList.get(position);
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);
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();
}
});
}
}
});
if (config.getCanCancel()) {
this.listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
final JsonNode article = lastArticleList.get(position);
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);
dialog.createDialog(alertDialogBuilder);
}
});
} catch (final Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
try {
final JsonNode response = nemopaySession.getRequest().getJSONResponse();
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();
}
});
}
}
});
if (response.has("error") && response.get("error").has("message")) {
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();
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), response.get("error").get("message").textValue());
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);
}
});
}
else {
this.listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
dialog.infoDialog(BuyerInfoActivity.this, getString(R.string.cancel_transaction), getString(R.string.cant_cancel));
}
});
}
dialog.createDialog(alertDialogBuilder);
}
});
this.listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
......
......@@ -22,6 +22,7 @@ public class Config {
private Integer foundationId;
private JsonNode groupList;
private Boolean canCancel;
private Boolean inKeyboard;
private Boolean inGrid;
private Boolean printCotisant;
......@@ -39,6 +40,7 @@ public class Config {
Log.e(LOG_TAG, "error: " + e.getMessage());
}
this.canCancel = sharedPreferences.getBoolean("config_can_cancel", true);
this.inKeyboard = sharedPreferences.getBoolean("config_in_keyboard", false);
this.inGrid = sharedPreferences.getBoolean("config_in_grid", true);
this.printCotisant = sharedPreferences.getBoolean("config_print_cotisant", false);
......@@ -66,6 +68,15 @@ public class Config {
this.groupList = groupList;
}
public Boolean getCanCancel() { return this.canCancel; }
public void setCanCancel(final Boolean canCancel) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("config_can_cancel", canCancel);
editor.apply();
this.canCancel = canCancel;
}
public Boolean getInKeyboard() { return this.inKeyboard; }
public void setInKeyboard(final Boolean inKeyboard) {
SharedPreferences.Editor editor = sharedPreferences.edit();
......
......@@ -4,13 +4,37 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:text="@string/filters" />
<Switch
android:id="@+id/swtich_cancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:checked="true"
android:text="@string/can_cancel" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="25dp"
android:text="@string/category_list" />
<ListView
android:id="@+id/list_groups"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="25dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp">
</ListView>
android:layout_marginRight="25dp"
android:orientation="vertical" />
</LinearLayout>
\ No newline at end of file
......@@ -91,10 +91,13 @@
<string name="ask_cancel_transaction">Annuler la transaction suivante:</string>
<string name="transaction_canceled">L\'annulation a bien été effective</string>
<string name="no_longer_connected">L\'application nécessite d\'être reconnectée. Retour à la page d\'accueil</string>
<string name="category_list">Liste des catégories</string>
<string name="keyboard_list">Liste des claviers de caisse</string>
<string name="app_configurated">L\'application a été configurée par défaut sur ce mode d\'affichage. Seul une personne possédant tous les droits sur cette fondation peut reconfigurer l\'application par défaut</string>
<string name="category_list">Liste des catégories à afficher</string>
<string name="keyboard_list">Liste des claviers de caisse à afficher</string>
<string name="category_0_selected">Aucune catégorie n\'a été sélectionnée</string>
<string name="keyboard_0_selected">Aucun clavier n\'a été sélectionnée</string>
<string name="app_configurated">L\'application a été configurée par défaut sur ce mode d\'affichage. Seul une personne possédant tous les droits sur cette fondation peut reconfigurer l\'application par défaut</string>
<string name="can_cancel">Permettre l\'annulation</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="print_mode">Mode d\'affichage</string>
<string name="filters">Filtres d\'affichage</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