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"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fr.utc.simde.jessy" package="fr.utc.simde.jessy"
android:versionCode="32" android:versionCode="33"
android:versionName="0.10.2"> android:versionName="0.11.0">
<uses-permission android:name="android.permission.NFC" /> <uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
...@@ -40,7 +40,10 @@ ...@@ -40,7 +40,10 @@
<activity android:name="fr.utc.simde.jessy.CardManagementActivity" <activity android:name="fr.utc.simde.jessy.CardManagementActivity"
android:configChanges="orientation" android:configChanges="orientation"
android:screenOrientation="portrait" /> 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:configChanges="orientation"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<activity android:name="fr.utc.simde.jessy.QRCodeReaderActivity" <activity android:name="fr.utc.simde.jessy.QRCodeReaderActivity"
......
...@@ -2,7 +2,6 @@ package fr.utc.simde.jessy; ...@@ -2,7 +2,6 @@ package fr.utc.simde.jessy;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.os.Vibrator;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
...@@ -14,8 +13,6 @@ import android.widget.ListView; ...@@ -14,8 +13,6 @@ import android.widget.ListView;
import android.widget.RadioButton; import android.widget.RadioButton;
import android.widget.Switch; import android.widget.Switch;
import android.widget.TabHost; import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
...@@ -27,24 +24,21 @@ import java.util.HashMap; ...@@ -27,24 +24,21 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import fr.utc.simde.jessy.adapters.LocationsAdapter; 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.HTTPRequest;
import fr.utc.simde.jessy.tools.Panier;
/** /**
* Created by Samy on 27/10/2017. * 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"; private static final String LOG_TAG = "_ArticleGroupActivity";
protected ImageButton paramButton; protected ImageButton optionButton;
protected ImageButton deleteButton; protected ImageButton deleteButton;
protected TabHost tabHost; protected TabHost tabHost;
protected Panier panier; protected List<ArticleGroupFragment> groupFragmentList;
protected List<GroupFragment> groupFragmentList;
protected int nbrGroups; protected int nbrGroups;
@Override @Override
...@@ -52,16 +46,16 @@ public class ArticleGroupActivity extends BaseActivity { ...@@ -52,16 +46,16 @@ public class ArticleGroupActivity extends BaseActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_article_group); setContentView(R.layout.activity_article_group);
TextView textView = findViewById(R.id.text_price); this.optionButton = findViewById(R.id.image_param);
this.panier = new Panier(textView);
this.paramButton = findViewById(R.id.image_param);
this.deleteButton = findViewById(R.id.image_delete); this.deleteButton = findViewById(R.id.image_delete);
this.tabHost = findViewById(R.id.tab_categories); this.tabHost = findViewById(R.id.tab_categories);
this.tabHost.setup(); this.tabHost.setup();
this.groupFragmentList = new ArrayList<GroupFragment>(); this.groupFragmentList = new ArrayList<ArticleGroupFragment>();
this.nbrGroups = 0; this.nbrGroups = 0;
}
protected void generate() {
try { try {
if (getIntent().getExtras().getString("categoryList") != null) 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"))); 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 { ...@@ -92,132 +86,12 @@ public class ArticleGroupActivity extends BaseActivity {
}); });
} }
this.paramButton.setOnClickListener(new View.OnClickListener() { setOptionButton();
@Override setDeleteButton();
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);
}
})
.setNegativeButton(R.string.cancel, null);
dialog.createDialog(alertDialogBuilder);
}
}
});
this.deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
clearPanier();
}
});
} }
@Override protected abstract void setOptionButton();
protected void onIdentification(final String badgeId) { protected abstract void setDeleteButton();
if (dialog.isShowing())
return;
if (this.panier.isEmpty())
startBuyerInfoActivity(ArticleGroupActivity.this, badgeId);
else
pay(badgeId);
}
protected void configDialog() { 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)); 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 { ...@@ -319,94 +193,6 @@ public class ArticleGroupActivity extends BaseActivity {
}.start(); }.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 { protected void createCategories(final JsonNode categoryList, final List<Integer> authorizedList, final JsonNode articleList) throws Exception {
HashMap<Integer, ArrayNode> articlesPerCategory = new HashMap<Integer, ArrayNode>(); HashMap<Integer, ArrayNode> articlesPerCategory = new HashMap<Integer, ArrayNode>();
final int foundationId = nemopaySession.getFoundationId(); final int foundationId = nemopaySession.getFoundationId();
...@@ -431,13 +217,11 @@ public class ArticleGroupActivity extends BaseActivity { ...@@ -431,13 +217,11 @@ public class ArticleGroupActivity extends BaseActivity {
ArrayNode articlesForThisCategory = articlesPerCategory.get(category.get("id").intValue()); ArrayNode articlesForThisCategory = articlesPerCategory.get(category.get("id").intValue());
if (config.getFoundationId() != -1) if (!authorizedList.contains(category.get("id").intValue())) if (config.getFoundationId() != -1) if (!authorizedList.contains(category.get("id").intValue()))
continue; continue;
else if (articlesForThisCategory.size() == 0)
continue;
if (articlesForThisCategory == null) 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 { ...@@ -481,24 +265,10 @@ public class ArticleGroupActivity extends BaseActivity {
articlesForThisKeyboard.add(new ObjectMapper().createObjectNode()); articlesForThisKeyboard.add(new ObjectMapper().createObjectNode());
} }
if (articlesForThisKeyboard.size() == 0) 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()));
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()));
} }
} }
protected void createNewGroup(final String name, final ArrayNode articleList) throws Exception { createNewGroup(name, articleList, 3); } protected abstract void createNewGroup(final String name, final Integer id, final ArrayNode articleList) throws Exception;
protected void createNewGroup(final String name, final ArrayNode articleList, int gridColumns) throws Exception { protected abstract void createNewGroup(final String name, final Integer id, 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++;
}
} }
...@@ -12,8 +12,6 @@ import android.content.Intent; ...@@ -12,8 +12,6 @@ import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
...@@ -22,11 +20,10 @@ import android.os.StrictMode; ...@@ -22,11 +20,10 @@ import android.os.StrictMode;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.util.Log; import android.util.Log;
import android.widget.BaseAdapter;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -35,6 +32,8 @@ import java.util.List; ...@@ -35,6 +32,8 @@ import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; 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.CASConnexion;
import fr.utc.simde.jessy.tools.Config; import fr.utc.simde.jessy.tools.Config;
import fr.utc.simde.jessy.tools.Dialog; import fr.utc.simde.jessy.tools.Dialog;
...@@ -196,7 +195,7 @@ public abstract class BaseActivity extends InternetActivity { ...@@ -196,7 +195,7 @@ public abstract class BaseActivity extends InternetActivity {
protected void startFoundationListActivity(final Activity activity) { protected void startFoundationListActivity(final Activity activity) {
if (config.getFoundationId() != -1) { if (config.getFoundationId() != -1) {
startArticleGroupActivity(activity); startSellActivity(activity);
return; return;
} }
...@@ -248,9 +247,16 @@ public abstract class BaseActivity extends InternetActivity { ...@@ -248,9 +247,16 @@ public abstract class BaseActivity extends InternetActivity {
}.start(); }.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)); 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() { new Thread() {
@Override @Override
...@@ -511,6 +517,8 @@ public abstract class BaseActivity extends InternetActivity { ...@@ -511,6 +517,8 @@ public abstract class BaseActivity extends InternetActivity {
}); });
else else
throw new Exception(""); throw new Exception("");
return;
} catch (Exception e1) { } catch (Exception e1) {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
...@@ -549,6 +557,9 @@ public abstract class BaseActivity extends InternetActivity { ...@@ -549,6 +557,9 @@ public abstract class BaseActivity extends InternetActivity {
} }
protected void setNemopayKey(final String key) { protected void setNemopayKey(final String key) {
if (key.equals(""))
return;
dialog.startLoading(BaseActivity.this, getString(R.string.nemopay_connection), getString(R.string.nemopay_authentification)); dialog.startLoading(BaseActivity.this, getString(R.string.nemopay_connection), getString(R.string.nemopay_authentification));
new Thread() { new Thread() {
...@@ -590,12 +601,16 @@ public abstract class BaseActivity extends InternetActivity { ...@@ -590,12 +601,16 @@ public abstract class BaseActivity extends InternetActivity {
}.start(); }.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(); SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("key_ginger", key); editor.putString("key_" + name, key);
editor.apply(); editor.apply();
ginger.setKey(key); if (name.equals("ginger"))
ginger.setKey(key);
} }
protected boolean haveStoragePermission() { protected boolean haveStoragePermission() {
...@@ -661,7 +676,19 @@ public abstract class BaseActivity extends InternetActivity { ...@@ -661,7 +676,19 @@ public abstract class BaseActivity extends InternetActivity {
} }
} }
}) })
.setNegativeButton(R.string.cancel, null); .setNegativeButton(R.string.cancel, null)
.setNeutralButton(R