Commit cc1b1898 authored by Nastuzzi Samy's avatar Nastuzzi Samy

Merge branch 'release/v0.11.0'

parents 2605ea09 14a64220
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fr.utc.simde.jessy"
android:versionCode="32"
android:versionName="0.10.2">
android:versionCode="33"
android:versionName="0.11.0">
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.INTERNET" />
......@@ -40,7 +40,10 @@
<activity android:name="fr.utc.simde.jessy.CardManagementActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name="fr.utc.simde.jessy.ArticleGroupActivity"
<activity android:name="fr.utc.simde.jessy.SellActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name="fr.utc.simde.jessy.EditActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name="fr.utc.simde.jessy.QRCodeReaderActivity"
......
......@@ -12,8 +12,6 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
......@@ -22,11 +20,10 @@ import android.os.StrictMode;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.util.ArrayList;
......@@ -35,6 +32,8 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import fr.utc.simde.jessy.responses.BottomatikResponse;
import fr.utc.simde.jessy.tools.Bottomatik;
import fr.utc.simde.jessy.tools.CASConnexion;
import fr.utc.simde.jessy.tools.Config;
import fr.utc.simde.jessy.tools.Dialog;
......@@ -196,7 +195,7 @@ public abstract class BaseActivity extends InternetActivity {
protected void startFoundationListActivity(final Activity activity) {
if (config.getFoundationId() != -1) {
startArticleGroupActivity(activity);
startSellActivity(activity);
return;
}
......@@ -248,9 +247,16 @@ public abstract class BaseActivity extends InternetActivity {
}.start();
}
protected void startArticleGroupActivity(final Activity activity) {
public void startSellActivity(final Activity activity) {
startArticleGroupActivity(activity, new Intent(activity, SellActivity.class));
}
public void startEditActivity(final Activity activity) {
startArticleGroupActivity(activity, new Intent(activity, EditActivity.class));
}
public void startArticleGroupActivity(final Activity activity, final Intent intent) {
dialog.startLoading(activity, activity.getResources().getString(R.string.information_collection), getString(R.string.location_list_collecting));
final Intent intent = new Intent(activity, ArticleGroupActivity.class);
new Thread() {
@Override
......@@ -511,6 +517,8 @@ public abstract class BaseActivity extends InternetActivity {
});
else
throw new Exception("");
return;
} catch (Exception e1) {
runOnUiThread(new Runnable() {
@Override
......@@ -549,6 +557,9 @@ public abstract class BaseActivity extends InternetActivity {
}
protected void setNemopayKey(final String key) {
if (key.equals(""))
return;
dialog.startLoading(BaseActivity.this, getString(R.string.nemopay_connection), getString(R.string.nemopay_authentification));
new Thread() {
......@@ -590,12 +601,16 @@ public abstract class BaseActivity extends InternetActivity {
}.start();
}
protected void setGingerKey(final String key) {
protected void setKey(final String name, final String key) {
if (name.equals("") || key.equals(""))
return;
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("key_ginger", key);
editor.putString("key_" + name, key);
editor.apply();
ginger.setKey(key);
if (name.equals("ginger"))
ginger.setKey(key);
}
protected boolean haveStoragePermission() {
......@@ -661,7 +676,19 @@ public abstract class BaseActivity extends InternetActivity {
}
}
})
.setNegativeButton(R.string.cancel, null);
.setNegativeButton(R.string.cancel, null)
.setNeutralButton(R.string.set_download, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
if (!haveStoragePermission()) {
updateDialog.stopLoading();
updateDialog.errorDialog(BaseActivity.this, getString(R.string.update), getString(R.string.need_storage_permission));
}
else if (!update(matcher.group(2), true)) {
updateDialog.stopLoading();
updateDialog.errorDialog(BaseActivity.this, getString(R.string.download), getString(R.string.can_not_download));
}
}
});
updateDialog.createDialog(alertDialogBuilder);
}
......@@ -689,7 +716,8 @@ public abstract class BaseActivity extends InternetActivity {
}.start();
}
protected boolean update(final String version) {
protected boolean update(final String version) { return update(version, false); }
protected boolean update(final String version, final boolean downloadOnly) {
final String destination = this.downloadLocation + getString(R.string.app_name) + " " + version + ".apk";
final String url = this.gitUrl + getString(R.string.app_name) + " " + version + ".apk";
final Uri uri = Uri.parse("file://" + destination);
......@@ -706,16 +734,28 @@ public abstract class BaseActivity extends InternetActivity {
final DownloadManager manager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
final long downloadId = manager.enqueue(request);
BroadcastReceiver onComplete = new BroadcastReceiver() {
public void onReceive(Context ctx, Intent intent) {
Intent install = new Intent(Intent.ACTION_VIEW);
install.setDataAndType(uri, "application/vnd.android.package-archive");
install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(install);
BroadcastReceiver onComplete;
if (downloadOnly) {
onComplete = new BroadcastReceiver() {
public void onReceive(Context ctx, Intent intent) {
new Dialog(BaseActivity.this).infoDialog(BaseActivity.this, getString(R.string.download), getString(R.string.download_successful));
unregisterReceiver(this);
}
};
unregisterReceiver(this);
}
};
}
else {
onComplete = new BroadcastReceiver() {
public void onReceive(Context ctx, Intent intent) {
Intent install = new Intent(Intent.ACTION_VIEW);
install.setDataAndType(uri, "application/vnd.android.package-archive");
install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(install);
unregisterReceiver(this);
}
};
}
registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
......
......@@ -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) {
......
This diff is collapsed.
......@@ -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;
......@@ -27,6 +23,7 @@ import java.util.Date;
import java.util.Iterator;
import java.util.Locale;
import fr.utc.simde.jessy.tools.Bottomatik;
import fr.utc.simde.jessy.tools.CASConnexion;
import fr.utc.simde.jessy.tools.Config;
import fr.utc.simde.jessy.tools.Ginger;
......@@ -60,13 +57,8 @@ public class MainActivity extends BaseActivity {
casConnexion = new CASConnexion(nemopaySession);
config = new Config(sharedPreferences);
String key = sharedPreferences.getString("key", "");
if (!key.equals(""))
setNemopayKey(key);
key = sharedPreferences.getString("key_ginger", "");
if (!key.equals(""))
setGingerKey(key);
setNemopayKey(sharedPreferences.getString("key", ""));
ginger.setKey(sharedPreferences.getString("key_ginger", ""));
appImg = findViewById(R.id.img_payutc);
appNameText = findViewById(R.id.text_app_name);
......@@ -449,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());
......@@ -504,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) {
......
......@@ -29,7 +29,7 @@ public abstract class NFCActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
NFCAdapter = NfcAdapter.getDefaultAdapter(getApplicationContext());
NFCAdapter = NfcAdapter.getDefaultAdapter(this);
NFCAlertDialog = new AlertDialog.Builder(this);
if (NFCAdapter == null) {
......@@ -65,6 +65,9 @@ public abstract class NFCActivity extends Activity {
if (!NFCAdapter.isEnabled())
enableNFCDialog();
IntentFilter filter = new IntentFilter(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
this.registerReceiver(NFCReceiver, filter);
}
}
......@@ -72,15 +75,17 @@ public abstract class NFCActivity extends Activity {
protected void onPause() {
super.onPause();
if (identifierIsAvailable())
NFCAdapter.disableForegroundDispatch(this);
NFCAdapter = NfcAdapter.getDefaultAdapter(this);
NFCAdapter.disableForegroundDispatch(this);
this.unregisterReceiver(NFCReceiver);
}
@Override
protected void onDestroy() {
super.onDestroy();
this.unregisterReceiver(NFCReceiver);
try { this.unregisterReceiver(NFCReceiver); } catch (Exception e) {}
}
protected abstract void onIdentification(final String badgeId);
......
This diff is collapsed.
......@@ -4,7 +4,9 @@ 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.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
......@@ -19,6 +21,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 +36,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 +50,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 +79,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.price_variable);
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 +126,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,65 +143,37 @@ public abstract class ArticlesAdapter extends BaseAdapter {
return this.articleList.get(position);
}
public void setImage(final ImageView imageView, final String url, final int position) {
final HTTPRequest[] request = new HTTPRequest[1];
public Integer getNbr(final int position) {
return this.nbrList[position];
}
public void setImage(final ImageView imageView, final String url, final int position) {
if (imageList[position] != null)
imageView.setImageBitmap(imageList[position]);
else if (url != null && !url.equals("")) {
new Thread(){
@Override
public void run() {
request[0] = new HTTPRequest(url);
final HTTPRequest httpRequest = new HTTPRequest(url);
if (request[0].get() == 200) {
if (httpRequest.get() == 200) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
imageList[position] = request[0].getImageResponse();
if (!httpRequest.isImageResponse())
throw new Exception("Not an Image");
imageList[position] = httpRequest.getImageResponse();
imageView.setImageBitmap(imageList[position]);
} catch (Exception e) {
e.printStackTrace();
Log.e(LOG_TAG, e.getMessage());
}
}
});
}
}
}.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);
}
}
}
}
......@@ -26,24 +26,7 @@ public class GridAdapter extends ArticlesAdapter {
public GridAdapter(final Activity activity, final ArrayNode articleList, final int nbrColumns, final Boolean printCotisant, final Boolean print18) throws Exception {
super(activity, articleList, printCotisant, print18);
switch (nbrColumns) {
case 1:
this.size = 250;
break;
case 2:
this.size = 200;
break;
case 3:
this.size = 150;
break;
case 4:
this.size = 125;
break;
case 5:
default:
this.size = 100;
break;
}
this.size = nbrColumns > 5 ? 100 : 225 - (25 * nbrColumns);
}
@Override
......@@ -74,7 +57,13 @@ public class GridAdapter extends ArticlesAdapter {
imageCotisant.setLayoutParams(imageParms);
image18.setLayoutParams(imageParms);
setInfos(article, imageCotisant, image18);
if (article.get("id").intValue() == -1) {
imageCotisant.setVisibility(View.GONE);
image18.setVisibility(View.GONE);
}
else
setInfos(article, imageCotisant, image18);
setImage(imageView, article.get("image_url").textValue(), position);
setClickView(position);
}
......
......@@ -44,7 +44,15 @@ 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("id").intValue() == -1)
priceText.setVisibility(View.GONE);
else {
if (article.get("variable_price").booleanValue())
priceText.setText("PV: " + String.format("%.2f", new Float(articleList.get(position).get("price").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);
......@@ -56,13 +64,17 @@ public class ListAdapater extends ArticlesAdapter {
imageCotisant.setVisibility(View.GONE);
image18.setVisibility(View.GONE);
}
else if (article.get("id").intValue() == -1) {
imageCotisant.setVisibility(View.GONE);
image18.setVisibility(View.GONE);
}
else
setInfos(article, imageCotisant, image18);
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 +83,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 +91,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);