Commit cc1b1898 authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

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"
......
......@@ -2,7 +2,6 @@ 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;
......@@ -14,8 +13,6 @@ import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.Switch;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
......@@ -27,24 +24,21 @@ import java.util.HashMap;
import java.util.List;
import fr.utc.simde.jessy.adapters.LocationsAdapter;
import fr.utc.simde.jessy.fragments.GroupFragment;
import fr.utc.simde.jessy.fragments.ArticleGroupFragment;
import fr.utc.simde.jessy.tools.HTTPRequest;
import fr.utc.simde.jessy.tools.Panier;
/**
* Created by Samy on 27/10/2017.
*/
public class ArticleGroupActivity extends BaseActivity {
public abstract class ArticleGroupActivity extends BaseActivity {
private static final String LOG_TAG = "_ArticleGroupActivity";
protected ImageButton paramButton;
protected ImageButton optionButton;
protected ImageButton deleteButton;
protected TabHost tabHost;
protected Panier panier;
protected List<GroupFragment> groupFragmentList;
protected List<ArticleGroupFragment> groupFragmentList;
protected int nbrGroups;
@Override
......@@ -52,16 +46,16 @@ public class ArticleGroupActivity extends BaseActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_article_group);
TextView textView = findViewById(R.id.text_price);
this.panier = new Panier(textView);
this.paramButton = findViewById(R.id.image_param);
this.optionButton = findViewById(R.id.image_param);
this.deleteButton = findViewById(R.id.image_delete);
this.tabHost = findViewById(R.id.tab_categories);
this.tabHost.setup();
this.groupFragmentList = new ArrayList<GroupFragment>();
this.groupFragmentList = new ArrayList<ArticleGroupFragment>();
this.nbrGroups = 0;
}
protected void generate() {
try {
if (getIntent().getExtras().getString("categoryList") != null)
createCategories(new ObjectMapper().readTree(getIntent().getExtras().getString("categoryList")), getIntent().getExtras().getIntegerArrayList("categoryListAuthorized"), new ObjectMapper().readTree(getIntent().getExtras().getString("articleList")));
......@@ -92,132 +86,12 @@ public class ArticleGroupActivity extends BaseActivity {
});
}
this.paramButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (config.getFoundationId() == -1) {
final View popupView = LayoutInflater.from(ArticleGroupActivity.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.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(ArticleGroupActivity.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());
startArticleGroupActivity(ArticleGroupActivity.this);
}
})
.setNegativeButton(R.string.cancel, null);
dialog.createDialog(alertDialogBuilder);
}
else {
final View popupView = LayoutInflater.from(ArticleGroupActivity.this).inflate(R.layout.dialog_config_restore, null, false);
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);
switchCotisant.setChecked(config.getPrintCotisant());
swtich18.setChecked(config.getPrint18());
configButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
hasRights(getString(R.string.configurate_by_default), new String[]{
"STAFF",
"GESAPPLICATIONS"
}, new Runnable() {
@Override
public void run() {
config.setFoundation(-1, "");
config.setLocation(-1, "");
config.setCanCancel(true);
startMainActivity(ArticleGroupActivity.this);
}
});
}
});
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ArticleGroupActivity.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.setPrintCotisant(switchCotisant.isChecked());
config.setPrint18(swtich18.isChecked());
startArticleGroupActivity(ArticleGroupActivity.this);
setOptionButton();
setDeleteButton();
}
})
.setNegativeButton(R.string.cancel, null);
dialog.createDialog(alertDialogBuilder);
}
}
});
this.deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
clearPanier();
}
});
}
@Override
protected void onIdentification(final String badgeId) {
if (dialog.isShowing())
return;
if (this.panier.isEmpty())
startBuyerInfoActivity(ArticleGroupActivity.this, badgeId);
else
pay(badgeId);
}
protected abstract void setOptionButton();
protected abstract void setDeleteButton();
protected void configDialog() {
dialog.startLoading(ArticleGroupActivity.this, getResources().getString(R.string.information_collection), getString(config.getInCategory() ? R.string.category_list_collecting : R.string.keyboard_list_collecting));
......@@ -319,94 +193,6 @@ public class ArticleGroupActivity extends BaseActivity {
}.start();
}
public void clearPanier() {
for (GroupFragment groupFragment : groupFragmentList)
groupFragment.clear();
panier.clear();
}
public void setBackgroundColor(int color) {
this.tabHost.setBackgroundColor(color);
new Thread(){
@Override
public void run() {
try {
Thread.sleep(2500);
runOnUiThread(new Runnable() {
@Override
public void run() {
tabHost.setBackgroundColor(getResources().getColor(R.color.white));
}
});
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
}
}
}.start();
}
protected void pay(final String badgeId) {
dialog.startLoading(this, getResources().getString(R.string.paiement), getResources().getString(R.string.transaction_in_progress));
final List<Integer> articleList = new ArrayList<Integer>(panier.getArticleList());
clearPanier();
new Thread() {
@Override
public void run() {
try {
nemopaySession.setTransaction(badgeId, articleList);
Thread.sleep(100);
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
Toast.makeText(ArticleGroupActivity.this, "Paiement effectué", Toast.LENGTH_LONG).show();
setBackgroundColor(getResources().getColor(R.color.success));
((Vibrator) getSystemService(ArticleGroupActivity.VIBRATOR_SERVICE)).vibrate(250);
}
});
} 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(ArticleGroupActivity.this, getString(R.string.paiement), response.get("error").get("message").textValue());
setBackgroundColor(getResources().getColor(R.color.error));
((Vibrator) getSystemService(ArticleGroupActivity.VIBRATOR_SERVICE)).vibrate(500);
}
});
}
else
throw new Exception("");
} catch (Exception e1) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
dialog.errorDialog(ArticleGroupActivity.this, getString(R.string.paiement), e.getMessage());
setBackgroundColor(getResources().getColor(R.color.error));
((Vibrator) getSystemService(ArticleGroupActivity.VIBRATOR_SERVICE)).vibrate(500);
}
});
}
}
}
}.start();
}
protected void createCategories(final JsonNode categoryList, final List<Integer> authorizedList, final JsonNode articleList) throws Exception {
HashMap<Integer, ArrayNode> articlesPerCategory = new HashMap<Integer, ArrayNode>();
final int foundationId = nemopaySession.getFoundationId();
......@@ -431,13 +217,11 @@ public class ArticleGroupActivity extends BaseActivity {
ArrayNode articlesForThisCategory = articlesPerCategory.get(category.get("id").intValue());
if (config.getFoundationId() != -1) if (!authorizedList.contains(category.get("id").intValue()))
continue;
else if (articlesForThisCategory.size() == 0)
continue;
if (articlesForThisCategory == null)
continue;
articlesForThisCategory = new ObjectMapper().createArrayNode();
createNewGroup(category.get("name").textValue(), articlesForThisCategory);
createNewGroup(category.get("name").textValue(), category.get("id").intValue(), articlesForThisCategory);
}
}
......@@ -481,24 +265,10 @@ public class ArticleGroupActivity extends BaseActivity {
articlesForThisKeyboard.add(new ObjectMapper().createObjectNode());
}
if (articlesForThisKeyboard.size() == 0)
continue;
createNewGroup(keyboard.get("name").textValue(), articlesForThisKeyboard, keyboard.get("data").get("nbColumns").isInt() ? keyboard.get("data").get("nbColumns").intValue() : Integer.valueOf(keyboard.get("data").get("nbColumns").textValue()));
createNewGroup(keyboard.get("name").textValue(), keyboard.get("id").intValue(), articlesForThisKeyboard, keyboard.get("data").get("nbColumns").isInt() ? keyboard.get("data").get("nbColumns").intValue() : Integer.valueOf(keyboard.get("data").get("nbColumns").textValue()));
}
}
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 {
GroupFragment articleGroupFragment = new GroupFragment(ArticleGroupActivity.this, articleList, this.panier, this.config, gridColumns);
TabHost.TabSpec newTabSpec = this.tabHost.newTabSpec(name);
newTabSpec.setIndicator(name);
newTabSpec.setContent(articleGroupFragment);
this.groupFragmentList.add(articleGroupFragment);
this.tabHost.addTab(newTabSpec);
nbrGroups++;
}
protected abstract void createNewGroup(final String name, final Integer id, final ArrayNode articleList) throws Exception;
protected abstract void createNewGroup(final String name, final Integer id, final ArrayNode articleList, int gridColumns) throws Exception;
}
......@@ -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,11 +601,15 @@ 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();
if (name.equals("ginger"))
ginger.setKey(key);
}
......@@ -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,7 +734,18 @@ public abstract class BaseActivity extends InternetActivity {
final DownloadManager manager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
final long downloadId = manager.enqueue(request);
BroadcastReceiver onComplete = new BroadcastReceiver() {
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);
}
};
}
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");
......@@ -716,6 +755,7 @@ public abstract class BaseActivity extends InternetActivity {
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) {
......
package fr.utc.simde.jessy;
import android.os.Bundle;
import android.text.InputFilter;
import android.text.Spanned;
import android.util.Log;
import android.view.View;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Switch;
import android.widget.TabHost;
import android.widget.Toast;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.ArrayList;
import java.util.List;
import fr.utc.simde.jessy.adapters.ArticlesAdapter;
import fr.utc.simde.jessy.fragments.ArticleGroupFragment;
import fr.utc.simde.jessy.fragments.EditFragment;
/**
* Created by Samy on 20/11/2017.
*/