Commit 1c394bd0 authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

API and QRCode management

Only one activity to manage QRCodes
Change api system. All is manage with the same system
Maybe move api management in config. Need to be seen
parent 4e6c4a9a
......@@ -43,9 +43,6 @@
<activity android:name="fr.utc.simde.jessy.SellActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name="fr.utc.simde.jessy.SellByBottomatikActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name="fr.utc.simde.jessy.EditActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
......
......@@ -54,7 +54,6 @@ public abstract class BaseActivity extends InternetActivity {
protected static NemopaySession nemopaySession;
protected static Ginger ginger;
protected static Bottomatik bottomatik;
protected static CASConnexion casConnexion;
protected static Config config;
......@@ -252,13 +251,6 @@ public abstract class BaseActivity extends InternetActivity {
startArticleGroupActivity(activity, new Intent(activity, SellActivity.class));
}
public void startSellBottomatikActivity(final Activity activity) {
if (activity instanceof SellByBottomatikActivity)
finish();
startActivity(new Intent(activity, SellByBottomatikActivity.class));
}
public void startEditActivity(final Activity activity) {
startArticleGroupActivity(activity, new Intent(activity, EditActivity.class));
}
......@@ -609,26 +601,16 @@ public abstract class BaseActivity extends InternetActivity {
}.start();
}
protected void setGingerKey(final String key) {
if (key.equals(""))
return;
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("key_ginger", key);
editor.apply();
ginger.setKey(key);
}
protected void setBottomatikKey(final String key) {
if (key.equals(""))
protected void setKey(final String name, final String key) {
if (name.equals("") || key.equals(""))
return;
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("key_bottomatik", key);
editor.putString("key_" + name, key);
editor.apply();
bottomatik.setKey(key);
if (name.equals("ginger"))
ginger.setKey(key);
}
protected boolean haveStoragePermission() {
......
......@@ -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);
}
});
}
......
......@@ -26,7 +26,6 @@ import java.util.Arrays;
import java.util.List;
import fr.utc.simde.jessy.adapters.FoundationsAdapter;
import fr.utc.simde.jessy.adapters.LocationsAdapter;
import fr.utc.simde.jessy.adapters.OptionChoicesAdapter;
import fr.utc.simde.jessy.adapters.OptionsAdapter;
......@@ -134,12 +133,10 @@ public class FoundationsOptionsActivity extends BaseActivity {
else if (isOption(position,6))
keyNemopayDialog();
else if (isOption(position,7))
keyGingerDialog();
keyEditDialog();
else if (isOption(position,8))
keyBottomotikDialog();
else if (isOption(position,9))
checkUpdate();
else if (isOption(position,10))
else if (isOption(position,9))
creditDialog();
else
configDialog();
......@@ -153,73 +150,50 @@ public class FoundationsOptionsActivity extends BaseActivity {
hasRights(getString(R.string.nemopay), new String[]{}, new Runnable(){
@Override
public void run() {
final View keyView = getLayoutInflater().inflate(R.layout.dialog_key_force, null);
final EditText keyInput = keyView.findViewById(R.id.input_key);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(FoundationsOptionsActivity.this);
alertDialogBuilder
.setTitle(getString(R.string.key_registration) + " " + getString(R.string.nemopay))
.setView(keyView)
.setCancelable(false)
.setPositiveButton(R.string.register, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
if (!keyInput.getText().toString().equals(""))
setNemopayKey(keyInput.getText().toString());
}
})
.setNegativeButton(R.string.cancel, null);
dialog.createDialog(alertDialogBuilder, keyInput);
}
});
}
protected void keyGingerDialog() {
hasRights(getString(R.string.ginger), new String[]{}, new Runnable(){
@Override
public void run() {
final View keyView = getLayoutInflater().inflate(R.layout.dialog_key_force, null);
final View keyView = getLayoutInflater().inflate(R.layout.dialog_edit_key, null);
final EditText keyInput = keyView.findViewById(R.id.input_key);
keyView.findViewById(R.id.input_name).setVisibility(View.GONE);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(FoundationsOptionsActivity.this);
alertDialogBuilder
.setTitle(getString(R.string.key_registration) + " " + getString(R.string.ginger))
.setView(keyView)
.setCancelable(false)
.setPositiveButton(R.string.register, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
if (!keyInput.getText().toString().equals(""))
setGingerKey(keyInput.getText().toString());
}
})
.setNegativeButton(R.string.cancel, null);
.setTitle(getString(R.string.key_registration) + " " + getString(R.string.nemopay))
.setView(keyView)
.setCancelable(false)
.setPositiveButton(R.string.register, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
if (!keyInput.getText().toString().equals(""))
setNemopayKey(keyInput.getText().toString());
}
})
.setNegativeButton(R.string.cancel, null);
dialog.createDialog(alertDialogBuilder, keyInput);
}
});
}
protected void keyBottomotikDialog() {
hasRights(getString(R.string.bottomatik), new String[]{}, new Runnable(){
protected void keyEditDialog() {
hasRights(getString(R.string.key_registration), new String[]{}, new Runnable(){
@Override
public void run() {
final View keyView = getLayoutInflater().inflate(R.layout.dialog_key_force, null);
final View keyView = getLayoutInflater().inflate(R.layout.dialog_edit_key, null);
final EditText nameInput = keyView.findViewById(R.id.input_name);
final EditText keyInput = keyView.findViewById(R.id.input_key);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(FoundationsOptionsActivity.this);
alertDialogBuilder
.setTitle(getString(R.string.key_registration) + " " + getString(R.string.bottomatik))
.setTitle(getString(R.string.key_registration))
.setView(keyView)
.setCancelable(false)
.setPositiveButton(R.string.register, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
if (!keyInput.getText().toString().equals(""))
setBottomatikKey(keyInput.getText().toString());
if (!nameInput.getText().toString().equals("") || !keyInput.getText().toString().equals(""))
setKey(nameInput.getText().toString(), keyInput.getText().toString());
}
})
.setNegativeButton(R.string.cancel, null);
dialog.createDialog(alertDialogBuilder, keyInput);
dialog.createDialog(alertDialogBuilder, nameInput);
}
});
}
......
......@@ -5,10 +5,6 @@ import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.media.Image;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.util.Log;
......@@ -58,13 +54,11 @@ public class MainActivity extends BaseActivity {
nemopaySession = new NemopaySession(MainActivity.this);
ginger = new Ginger(MainActivity.this);
bottomatik = new Bottomatik(MainActivity.this);
casConnexion = new CASConnexion(nemopaySession);
config = new Config(sharedPreferences);
setNemopayKey(sharedPreferences.getString("key", ""));
setGingerKey(sharedPreferences.getString("key_ginger", ""));
setBottomatikKey(sharedPreferences.getString("key_bottomatik", ""));
ginger.setKey(sharedPreferences.getString("key_ginger", ""));
appImg = findViewById(R.id.img_payutc);
appNameText = findViewById(R.id.text_app_name);
......@@ -447,7 +441,7 @@ public class MainActivity extends BaseActivity {
}
protected void keyDialog() {
final View keyView = getLayoutInflater().inflate(R.layout.dialog_key, null);
final View keyView = getLayoutInflater().inflate(R.layout.dialog_add_key, null);
final EditText nameInput = keyView.findViewById(R.id.input_name);
final EditText descriptionInput = keyView.findViewById(R.id.input_description);
final String date = new SimpleDateFormat("yyyy/MM/dd", Locale.FRANCE).format(new Date());
......@@ -502,13 +496,14 @@ public class MainActivity extends BaseActivity {
}
protected void optionDialog() {
final View view = getLayoutInflater().inflate(R.layout.dialog_key_force, null);
final EditText keyInput = view.findViewById(R.id.input_key);
final View keyView = getLayoutInflater().inflate(R.layout.dialog_edit_key, null);
final EditText keyInput = keyView.findViewById(R.id.input_key);
keyView.findViewById(R.id.input_name).setVisibility(View.GONE);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
alertDialogBuilder
.setTitle(R.string.key_registration)
.setView(view)
.setTitle(getString(R.string.key_registration) + " " + getString(R.string.nemopay))
.setView(keyView)
.setCancelable(false)
.setPositiveButton(R.string.register, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
......
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;
......@@ -37,7 +43,7 @@ public class SellActivity extends ArticleGroupActivity {
panierText.setOnLongClickListener(new TextView.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
startSellBottomatikActivity(SellActivity.this);
startQRCodeReaderActivity(SellActivity.this);
return false;
}
......@@ -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);