Commit 53ad2ccf authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

Merge fix...

parent 4e6c4a9a
......@@ -124,9 +124,14 @@ public class BuyerInfoActivity extends BaseActivity {
}
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(BuyerInfoActivity.this);
if (article.get("variable_price").booleanValue())
alertDialogBuilder.setMessage(getString(R.string.ask_cancel_transaction) + " " + article.get("name").textValue() + " (total: " + String.format("%.2f", new Float(article.get("price").intValue()) * article.get("quantity").intValue() / 100.00f) + "€) ?");
else
alertDialogBuilder.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) + "€) ?");
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) {
......
......@@ -4,6 +4,16 @@ import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
import android.view.View;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Vibrator;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.Switch;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;
......@@ -38,7 +48,62 @@ public class EditActivity extends ArticleGroupActivity {
this.optionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final View popupView = LayoutInflater.from(EditActivity.this).inflate(R.layout.dialog_config, null, false);
final RadioButton radioKeyboard = popupView.findViewById(R.id.radio_keyboard);
final RadioButton radioCategory = popupView.findViewById(R.id.radio_category);
final RadioButton radioGrid = popupView.findViewById(R.id.radio_grid);
final RadioButton radioList = popupView.findViewById(R.id.radio_list);
final Switch switchCotisant = popupView.findViewById(R.id.swtich_cotisant);
final Switch swtich18 = popupView.findViewById(R.id.swtich_18);
final Button configButton = popupView.findViewById(R.id.button_config);
if (config.getInCategory())
radioCategory.setChecked(true);
else
radioKeyboard.setChecked(true);
if (config.getInGrid())
radioGrid.setChecked(true);
else
radioList.setChecked(true);
switchCotisant.setChecked(config.getPrintCotisant());
swtich18.setChecked(config.getPrint18());
configButton.setText("Edit le nom");
configButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
hasRights(getString(R.string.configurate_by_default), new String[]{
"STAFF",
"GESAPPLICATIONS"
}, new Runnable() {
@Override
public void run() {
configDialog();
}
});
}
});
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(EditActivity.this);
alertDialogBuilder
.setTitle(R.string.configuration)
.setView(popupView)
.setCancelable(false)
.setPositiveButton(R.string.reload, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
config.setInCategory(radioCategory.isChecked());
config.setInGrid(radioGrid.isChecked());
config.setPrintCotisant(switchCotisant.isChecked());
config.setPrint18(swtich18.isChecked());
startSellActivity(EditActivity.this);
}
})
.setNegativeButton(R.string.cancel, null);
dialog.createDialog(alertDialogBuilder);
}
});
}
......
package fr.utc.simde.jessy;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Vibrator;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.Switch;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;
......@@ -90,7 +96,7 @@ public class SellActivity extends ArticleGroupActivity {
protected void pay(final String badgeId) {
dialog.startLoading(this, getString(R.string.paiement), getString(R.string.transaction_in_progress));
final List<Integer> articleList = new ArrayList<Integer>(panier.getArticleList());
final List<List<Integer>> articleList = new ArrayList<List<Integer>>(panier.getArticleList());
clearPanier();
new Thread() {
......@@ -157,7 +163,7 @@ public class SellActivity extends ArticleGroupActivity {
@Override
protected void createNewGroup(final String name, final ArrayNode articleList) throws Exception { createNewGroup(name, articleList, 3); }
protected void createNewGroup(final String name, final ArrayNode articleList, int gridColumns) throws Exception {
ArticleGroupFragment articleGroupFragment = new SellFragment(SellActivity.this, articleList, this.panier, this.config, gridColumns);
ArticleGroupFragment articleGroupFragment = new SellFragment(SellActivity.this, this.dialog, articleList, this.panier, this.config, gridColumns);
TabHost.TabSpec newTabSpec = this.tabHost.newTabSpec(name);
newTabSpec.setIndicator(name);
......
......@@ -233,7 +233,7 @@ public class SellByBottomatikActivity extends QRCodeReaderActivity {
});
List<ArticleResponse> articleResponseList = null;
List<Integer> articleIdList = bottomatikResponse.getArticleList();
List<List<Integer>> articleIdList = bottomatikResponse.getArticleList();
JsonNode articleList = null;
final ArrayNode purchaseList = new ObjectMapper().createArrayNode();
try {
......@@ -251,8 +251,8 @@ public class SellByBottomatikActivity extends QRCodeReaderActivity {
int j = 0;
int quantity = 0;
for (Integer articleId : articleIdList) {
if (articleId == articleResponse.getId()) {
for (List<Integer> articleId : articleIdList) {
if (articleId.get(0) == articleResponse.getId()) {
articleIdList.remove(j);
quantity++;
}
......
......@@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.AsyncTask;
import android.view.View;
import android.view.ViewGroup;
......@@ -19,6 +20,7 @@ import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import fr.utc.simde.jessy.R;
import fr.utc.simde.jessy.tools.HTTPRequest;
/**
......@@ -33,7 +35,7 @@ public abstract class ArticlesAdapter extends BaseAdapter {
protected Boolean print18;
protected Bitmap[] imageList;
protected Integer[] nbrClicksList;
protected Integer[] nbrList;
protected View[] viewList;
protected TextView[] clickViewList;
......@@ -47,13 +49,13 @@ public abstract class ArticlesAdapter extends BaseAdapter {
this.articleList = articleList;
this.imageList = new Bitmap[articleList.size()];
this.nbrClicksList = new Integer[articleList.size()];
this.nbrList = new Integer[articleList.size()];
this.viewList = new View[articleList.size()];
this.clickViewList = new TextView[articleList.size()];
for (int i = 0; i < this.nbrClicksList.length; i++)
this.nbrClicksList[i] = 0;
for (int i = 0; i < this.nbrList.length; i++)
this.nbrList[i] = 0;
}
@Override
......@@ -76,19 +78,31 @@ public abstract class ArticlesAdapter extends BaseAdapter {
public void setClickView(final int position) {
if (this.clickViewList[position] != null) {
if (this.nbrClicksList[position] == 0) {
if (this.nbrList[position] == 0) {
this.clickViewList[position].setText("");
this.clickViewList[position].setAlpha(0.0f);
}
else {
this.clickViewList[position].setText(Integer.toString(this.nbrClicksList[position]));
this.clickViewList[position].setText(this.nbrList[position] % 100 == 0 ? Integer.toString(this.nbrList[position] / 100) : Float.toString(this.nbrList[position] / 100.0f));
this.clickViewList[position].setAlpha(1.0f);
}
}
if (this.nbrList[position] < 0)
this.clickViewList[position].setBackgroundColor(Color.RED);
}
public void toast(final int position, int lengthLong) {
Toast.makeText(this.activity, articleList.get(position).get("name").textValue() + ": " + String.format("%.2f", new Float(articleList.get(position).get("price").intValue()) / 100.00f) + "€", lengthLong).show();
String text;
if (articleList.get(position).get("variable_price").booleanValue())
text = articleList.get(position).get("name").textValue() + ": " + activity.getString(R.string.variable_price);
else if (articleList.get(position).has("quantity"))
text = Integer.toString(articleList.get(position).get("quantity").intValue()) + "x " + articleList.get(position).get("name").textValue() + ": " + Integer.toString(articleList.get(position).get("quantity").intValue()) + "x " + String.format("%.2f", new Float(articleList.get(position).get("price").intValue()) / 100.00f) + "€";
else
text = articleList.get(position).get("name").textValue() + ": " + String.format("%.2f", new Float(articleList.get(position).get("price").intValue()) / 100.00f) + "€";
Toast.makeText(this.activity, text, lengthLong).show();
}
public void setInfos(JsonNode article, ImageView imageCotisant, ImageView image18) {
......@@ -111,15 +125,15 @@ public abstract class ArticlesAdapter extends BaseAdapter {
image18.setVisibility(View.GONE);
}
public void onClick(final int position) {
this.nbrClicksList[position]++;
public void onClick(final int position, final int number) {
this.nbrList[position] += number;
setClickView(position);
}
public void clear() {
for (int i = 0; i < getCount(); i++) {
this.nbrClicksList[i] = 0;
this.nbrList[i] = 0;
setClickView(i);
}
}
......@@ -128,6 +142,10 @@ public abstract class ArticlesAdapter extends BaseAdapter {
return this.articleList.get(position);
}
public Integer getNbr(final int position) {
return this.nbrList[position];
}
public void setImage(final ImageView imageView, final String url, final int position) {
final HTTPRequest[] request = new HTTPRequest[1];
......@@ -154,39 +172,6 @@ public abstract class ArticlesAdapter extends BaseAdapter {
}
}
}.start();
//new DownloadImageTask(imageView, imageList[position]).execute(url);
}
}
public class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
private ImageView imageView;
private Bitmap image;
public DownloadImageTask(ImageView imageView, Bitmap image) {
this.imageView = imageView;
this.image = image;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
try {
URL url = new URL(urldisplay);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
image = BitmapFactory.decodeStream(input);
} catch (Exception e) {
image = null;
}
return image;
}
@SuppressLint("NewApi")
protected void onPostExecute(Bitmap result) {
if (result != null) {
imageView.setImageBitmap(result);
}
}
}
}
......@@ -44,7 +44,11 @@ public class ListAdapater extends ArticlesAdapter {
nameText.setText(article.get("name").textValue());
TextView priceText = this.viewList[position].findViewById(R.id.text_price);
priceText.setText((article.has("quantity") ? Integer.toString(article.get("quantity").intValue()) + "x " : "") + String.format("%.2f", new Float(articleList.get(position).get("price").intValue()) / 100.00f) + "€");
if (article.get("variable_price").booleanValue())
priceText.setText("PV: " + String.format("%.2f", new Float(articleList.get(position).get("price").intValue() * articleList.get(position).get("quantity").intValue()) / 100.00f) + "€");
else
priceText.setText((article.has("quantity") ? Integer.toString(article.get("quantity").intValue()) + "x " : "") + String.format("%.2f", new Float(articleList.get(position).get("price").intValue()) / 100.00f) + "€");
ImageView imageCotisant = this.viewList[position].findViewById(R.id.image_cotisant);
ImageView image18 = this.viewList[position].findViewById(R.id.image_18);
......@@ -62,7 +66,7 @@ public class ListAdapater extends ArticlesAdapter {
setImage(imageView, article.get("image_url").textValue(), position);
if (article.has("quantity"))
nbrClicksList[position] = article.get("quantity").intValue();
nbrList[position] = article.get("quantity").intValue() * (article.get("variable_price").booleanValue() ? 1 : 100);
if (article.has("canceled") && article.get("canceled").booleanValue()) {
nameText.setPaintFlags(nameText.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
......@@ -71,7 +75,7 @@ public class ListAdapater extends ArticlesAdapter {
clickViewList[position].setPaintFlags(nameText.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}
if (this.nbrClicksList[position] < 0)
if (this.nbrList[position] < 0)
priceText.setTextColor(Color.RED);
setClickView(position);
......@@ -79,23 +83,4 @@ public class ListAdapater extends ArticlesAdapter {
return this.viewList[position];
}
public void toast(final int position, int lengthLong) {
Toast.makeText(this.activity, (articleList.get(position).has("quantity") ? Integer.toString(articleList.get(position).get("quantity").intValue()) + "x " : "") + articleList.get(position).get("name").textValue() + ": " + String.format("%.2f", new Float((articleList.get(position).has("quantity") ? articleList.get(position).get("quantity").intValue() : 1) * articleList.get(position).get("price").intValue()) / 100.00f) + "€", lengthLong).show();
}
public void setClickView(final int position) {
if (this.clickViewList[position] != null) {
if (this.nbrClicksList[position] == 0) {
this.clickViewList[position].setText("");
this.clickViewList[position].setAlpha(0.0f);
} else {
this.clickViewList[position].setText(Integer.toString(this.nbrClicksList[position]));
this.clickViewList[position].setAlpha(1.0f);
if (this.nbrClicksList[position] < 0)
this.clickViewList[position].setBackgroundColor(Color.RED);
}
}
}
}
package fr.utc.simde.jessy.fragments;
import android.app.Activity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
......@@ -80,14 +81,19 @@ public abstract class ArticleGroupFragment implements TabHost.TabContentFactory
protected abstract void setOnArticleClick(View view);
protected void setOnArticleLongClick(View view) {
((GridView) view).setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
AdapterView.OnItemLongClickListener onItemLongClickListener = new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int position, long id) {
articlesAdapter.toast(position, Toast.LENGTH_LONG);
return true;
}
});
};
if (this.config.getInGrid())
((GridView) view).setOnItemLongClickListener(onItemLongClickListener);
else
((ListView) view).setOnItemLongClickListener(onItemLongClickListener);
}
protected void createArticleGrid(final Activity activity, final ArrayNode articleList) throws Exception {
......
......@@ -8,6 +8,7 @@ import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.Switch;
import com.fasterxml.jackson.databind.JsonNode;
......@@ -40,7 +41,7 @@ public class EditFragment extends ArticleGroupFragment {
@Override
protected void setOnArticleClick(View view) {
((GridView) view).setOnItemClickListener(new AdapterView.OnItemClickListener() {
AdapterView.OnItemClickListener onItemClickListener = new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
final JsonNode article = articlesAdapter.getArticle(position);
......@@ -72,6 +73,11 @@ public class EditFragment extends ArticleGroupFragment {
dialog.createDialog(alertDialogBuilder);
}
});
};
if (this.config.getInGrid())
((GridView) view).setOnItemClickListener(onItemClickListener);
else
((ListView) view).setOnItemClickListener(onItemClickListener);
}
}
......@@ -4,11 +4,31 @@ import android.app.Activity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.text.InputFilter;
import android.text.Spanned;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.Toast;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import fr.utc.simde.jessy.tools.Config;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import fr.utc.simde.jessy.MainActivity;
import fr.utc.simde.jessy.R;
import fr.utc.simde.jessy.tools.Config;
import fr.utc.simde.jessy.tools.Dialog;
import fr.utc.simde.jessy.tools.Panier;
/**
......@@ -19,27 +39,92 @@ public class SellFragment extends ArticleGroupFragment {
private static final String LOG_TAG = "_SellFragment";
protected Panier panier;
protected Dialog dialog;
public SellFragment(final Activity activity, final ArrayNode articleList, final Panier panier, final Config config) throws Exception {
public SellFragment(final Activity activity, final Dialog dialog, final ArrayNode articleList, final Panier panier, final Config config) throws Exception {
super(activity, articleList, config);
this.dialog = dialog;
this.panier = panier;
}
public SellFragment(final Activity activity, final ArrayNode articleList, final Panier panier, final Config config, final int gridColumns) throws Exception {
public SellFragment(final Activity activity, final Dialog dialog, final ArrayNode articleList, final Panier panier, final Config config, final int gridColumns) throws Exception {
super(activity, articleList, config, gridColumns);
this.dialog = dialog;
this.panier = panier;
}
@Override
protected void setOnArticleClick(View view) {
((GridView) view).setOnItemClickListener(new AdapterView.OnItemClickListener() {
AdapterView.OnItemClickListener onItemClickListener = new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
JsonNode article = articlesAdapter.getArticle(position);
articlesAdapter.onClick(position);
panier.addArticle(article.get("id").intValue(), article.get("price").intValue());
if (article.get("variable_price").booleanValue()) {
priceDialog(position);
} else {
articlesAdapter.onClick(position, 100);
panier.addArticle(article.get("id").intValue(), article.get("price").intValue());
}
}
});
};
if (this.config.getInGrid())
((GridView) view).setOnItemClickListener(onItemClickListener);
else
((ListView) view).setOnItemClickListener(onItemClickListener);
}
protected void priceDialog(final Integer position) {
final View priceView = activity.getLayoutInflater().inflate(R.layout.dialog_price, null);
final EditText priceInput = priceView.findViewById(R.id.input_price);
InputFilter twoDecimalsOnly = new InputFilter() {
final int maxDigitsBeforeDecimalPoint = 3;
final int maxDigitsAfterDecimalPoint = 2;
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
StringBuilder builder = new StringBuilder(dest);
builder.replace(dstart, dend, source
.subSequence(start, end).toString());
if (!builder.toString().matches("(([1-9]{1})([0-9]{0,"+(maxDigitsBeforeDecimalPoint-1)+"})?)?(\\.[0-9]{0,"+maxDigitsAfterDecimalPoint+"})?")) {
if (source.length() == 0)
return dest.subSequence(dstart, dend);
return "";
}
return null;
}
};
priceInput.setFilters(new InputFilter[] { twoDecimalsOnly });
if (articlesAdapter.getNbr(position) != 0)
priceInput.setText(Float.toString(articlesAdapter.getNbr(position) / 100.0f));
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);
alertDialogBuilder
.setTitle(R.string.variable_price)
.setView(priceView)
.setCancelable(false)
.setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
if (priceInput.getText().toString().equals("")) {
Toast.makeText(activity, R.string.price_required, Toast.LENGTH_SHORT).show();
priceDialog(position);
}
else {
JsonNode article = articlesAdapter.getArticle(position);
panier.addArticle(article.get("id").intValue(), article.get("price").intValue(), Math.round(Float.parseFloat(priceInput.getText().toString()) * 100.0f) * article.get("price").intValue() - articlesAdapter.getNbr(position));
articlesAdapter.onClick(position, Math.round(Float.parseFloat(priceInput.getText().toString()) * 100.0f) - articlesAdapter.getNbr(position));
}
}
})
.setNegativeButton(R.string.cancel, null);
dialog.createDialog(alertDialogBuilder, priceInput);
}
}
......@@ -18,7 +18,7 @@ public class BottomatikResponse {
protected int fun_id;
protected long expires_at;
protected long creation_date;
protected List<String> articles;
protected List<List<String>> articles;
protected boolean paid;
protected boolean validated;
......@@ -28,11 +28,14 @@ public class BottomatikResponse {
public int getFoundationId() { return this.fun_id; }
public long getExpiresAt() { return this.expires_at; }
public long getCreatedAt() { return this.creation_date; }
public List<Integer> getArticleList() {
List<Integer> articleList = new ArrayList<Integer>();
public List<List<Integer>> getArticleList() {
List<