Commit 3a4804e6 authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

Merge branch 'feature/options' into develop

parents d359d8ce cd1677bc
......@@ -27,7 +27,7 @@
<activity android:name=".BaseActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".FoundationListActivity"
<activity android:name=".FoundationsOptionsActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".ArticleKeyboardActivity"
......@@ -39,6 +39,9 @@
<activity android:name=".BuyerInfoActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".CardManagementActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
</application>
</manifest>
\ No newline at end of file
......@@ -23,8 +23,8 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import java.util.ArrayList;
import java.util.List;
import fr.utc.simde.payutc.articles.GroupAdapter;
import fr.utc.simde.payutc.articles.GroupFragment;
import fr.utc.simde.payutc.adapters.GroupAdapter;
import fr.utc.simde.payutc.fragments.GroupFragment;
import fr.utc.simde.payutc.tools.HTTPRequest;
import fr.utc.simde.payutc.tools.Panier;
......@@ -115,7 +115,7 @@ public abstract class ArticleGroupActivity extends BaseActivity {
}, new Runnable() {
@Override
public void run() {
configApp();
configDialog();
}
});
}
......@@ -209,7 +209,7 @@ public abstract class ArticleGroupActivity extends BaseActivity {
protected abstract void createGroups(final JsonNode groupList, final JsonNode articleList) throws Exception;
protected void configApp() {
protected void configDialog() {
dialog.startLoading(ArticleGroupActivity.this, getResources().getString(R.string.information_collection), getString(config.getInKeyboard() ? R.string.keyboard_list_collecting : R.string.category_list_collecting));
new Thread() {
......@@ -261,10 +261,10 @@ public abstract class ArticleGroupActivity extends BaseActivity {
public void run() {
dialog.stopLoading();
LayoutInflater layoutInflater = LayoutInflater.from(ArticleGroupActivity.this);
View popupView = layoutInflater.inflate(R.layout.dialog_group, null);
ListView listView = popupView.findViewById(R.id.list_groups);
final Switch canCancelSwitch = popupView.findViewById(R.id.swtich_cancel);
final LayoutInflater layoutInflater = LayoutInflater.from(ArticleGroupActivity.this);
final View popupView = layoutInflater.inflate(R.layout.dialog_group, null);
final ListView listView = popupView.findViewById(R.id.list_groups);
final Switch canCancelSwitch = popupView.findViewById(R.id.switch_cancel);
canCancelSwitch.setChecked(config.getCanCancel());
if (config.getInKeyboard())
......@@ -296,7 +296,7 @@ public abstract class ArticleGroupActivity extends BaseActivity {
if (groupList == null || groupList.size() == 0) {
Toast.makeText(ArticleGroupActivity.this, getString(config.getInKeyboard() ? R.string.keyboard_0_selected : R.string.category_0_selected), Toast.LENGTH_LONG).show();
configApp();
configDialog();
}
else {
config.setFoundation(nemopaySession.getFoundationId(), nemopaySession.getFoundationName());
......
......@@ -3,16 +3,12 @@ package fr.utc.simde.payutc;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -21,8 +17,8 @@ import java.util.List;
import fr.utc.simde.payutc.tools.CASConnexion;
import fr.utc.simde.payutc.tools.Config;
import fr.utc.simde.payutc.tools.Dialog;
import fr.utc.simde.payutc.tools.Ginger;
import fr.utc.simde.payutc.tools.HTTPRequest;
import fr.utc.simde.payutc.tools.InternetBroadcast;
import fr.utc.simde.payutc.tools.NemopaySession;
/**
......@@ -33,11 +29,14 @@ public abstract class BaseActivity extends NFCActivity {
private static final String LOG_TAG = "_BaseActivity";
protected static NemopaySession nemopaySession;
protected static Ginger ginger;
protected static CASConnexion casConnexion;
protected static Config config;
protected static Dialog dialog;
protected static SharedPreferences sharedPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -68,11 +67,10 @@ public abstract class BaseActivity extends NFCActivity {
dialog.fatalDialog(activity, title, message, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
unregister(activity);
startMainActivity(activity);
}
});
disconnect();
}
protected void hasRights(final String titre, final String[] rightList, final Runnable runnable) {
......@@ -102,8 +100,14 @@ public abstract class BaseActivity extends NFCActivity {
}
}
if (rights.size() == sameRights.size())
runOnUiThread(runnable);
if ((rights.size() == sameRights.size()) || (rights.size() == 0 && myRightList.has("0") && myRightList.get("0").size() > 75)) // Si on a plus de 75 droits sur toutes les fondations, on estime qu'on a le full access
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
runnable.run();
}
});
else {
runOnUiThread(new Runnable() {
@Override
......@@ -144,7 +148,7 @@ public abstract class BaseActivity extends NFCActivity {
}
dialog.startLoading(activity, getString(R.string.information_collection), getString(R.string.foundation_list_collecting));
final Intent intent = new Intent(activity, FoundationListActivity.class);
final Intent intent = new Intent(activity, FoundationsOptionsActivity.class);
new Thread() {
@Override
......@@ -195,7 +199,7 @@ public abstract class BaseActivity extends NFCActivity {
public void run() {
dialog.stopLoading();
if (activity.getClass().getSimpleName().equals("FoundationListActivity"))
if (activity.getClass().getSimpleName().equals("FoundationsOptionsActivity"))
finish();
activity.startActivity(intent);
......@@ -367,7 +371,7 @@ public abstract class BaseActivity extends NFCActivity {
Log.e(LOG_TAG, "error: " + e.getMessage());
try {
if (nemopaySession.getRequest().getResponseCode() == 404)
if (nemopaySession.getRequest().getResponseCode() == 400)
runOnUiThread(new Runnable() {
@Override
public void run() {
......@@ -388,4 +392,70 @@ public abstract class BaseActivity extends NFCActivity {
}
}.start();
}
protected void startCardManagementActivity(final Activity activity) {
hasRights(getString(R.string.user_rights_list_collecting), new String[]{"STAFF", "POSS3", "GESUSERS"}, new Runnable() {
@Override
public void run() {
activity.startActivity(new Intent(activity, CardManagementActivity.class));
}
});
}
protected void delKey() {
SharedPreferences.Editor edit = sharedPreferences.edit();
edit.remove("key");
edit.apply();
unregister(BaseActivity.this);
}
protected void setNemopayKey(final String key) {
dialog.startLoading(BaseActivity.this, getString(R.string.nemopay_connection), getString(R.string.nemopay_authentification));
new Thread() {
@Override
public void run() {
try {
nemopaySession.loginApp(key, casConnexion);
Thread.sleep(100);
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
if (nemopaySession.isRegistered()) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("key", key);
editor.apply();
TextView textView = findViewById(R.id.text_app_registered);
if (textView != null)
textView.setText(nemopaySession.getName().substring(0, nemopaySession.getName().length() - (nemopaySession.getName().matches("^.* - ([0-9]{4})([/-])([0-9]{2})\\2([0-9]{2})$") ? 13 : 0)));
}
else
dialog.errorDialog(BaseActivity.this, getString(R.string.nemopay_connection), getString(R.string.nemopay_error_registering));
}
});
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.errorDialog(BaseActivity.this, getString(R.string.nemopay_connection), getString(R.string.nemopay_error_registering));
}
});
}
}
}.start();
}
protected void setGingerKey(final String key) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("key_ginger", key);
editor.apply();
ginger.setKey(key);
}
}
package fr.utc.simde.payutc;
import android.app.Activity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
......@@ -18,12 +17,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.w3c.dom.Text;
import java.io.IOException;
import fr.utc.simde.payutc.articles.GridAdapter;
import fr.utc.simde.payutc.articles.ListAdapater;
import fr.utc.simde.payutc.adapters.ListAdapater;
import fr.utc.simde.payutc.tools.HTTPRequest;
/**
......@@ -74,12 +68,7 @@ public class BuyerInfoActivity extends BaseActivity {
generatePurchases();
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
dialog.errorDialog(this, getResources().getString(R.string.information_collection), getResources().getString(R.string.error_view), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int id) {
finish();
}
});
fatal(this, getResources().getString(R.string.information_collection), getResources().getString(R.string.error_view));
}
}
......@@ -250,24 +239,26 @@ public class BuyerInfoActivity extends BaseActivity {
final ArrayNode articleList = new ObjectMapper().createArrayNode();
Boolean hasRight = true; //
for (JsonNode purchase : lastPurchaseList) {
int articleId = purchase.get("obj_id").intValue();
Boolean isIn = false;
for (JsonNode article : articleFoundationList) {
if (article.get("id").intValue() == articleId) {
((ObjectNode) article).put("info", getString(R.string.realized) + " " + purchase.get("pur_date").textValue().substring(purchase.get("pur_date").textValue().length() - 8));
((ObjectNode) article).put("quantity", Math.round(purchase.get("pur_qte").floatValue()));
((ObjectNode) article).put("purchase_id", purchase.get("pur_id").intValue());
articleList.add(article);
isIn = true;
break;
try {
for (JsonNode purchase : lastPurchaseList) {
int articleId = purchase.get("obj_id").intValue();
Boolean isIn = false;
for (JsonNode article : articleFoundationList) {
if (article.get("id").intValue() == articleId) {
ObjectNode toAdd = (ObjectNode) new ObjectMapper().readTree(article.toString());
toAdd.put("info", getString(R.string.realized) + " " + purchase.get("pur_date").textValue().substring(purchase.get("pur_date").textValue().length() - 8));
toAdd.put("quantity", Math.round(purchase.get("pur_qte").floatValue()));
toAdd.put("purchase_id", purchase.get("pur_id").intValue());
articleList.add(toAdd);
isIn = true;
break;
}
}
}
if (!isIn) {
try {
if (!isIn) {
articleList.add(new ObjectMapper().readTree("{" +
"\"name\":\"" + "N°: " + Integer.toString(purchase.get("obj_id").intValue()) + "\", " +
"\"price\":" + Integer.toString(purchase.get("pur_price").intValue()) + ", " +
......@@ -277,23 +268,23 @@ public class BuyerInfoActivity extends BaseActivity {
"\"image_url\":\"\"}"
));
}
catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
}
}
catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
runOnUiThread(new Runnable() {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
dialog.errorDialog(BuyerInfoActivity.this, getResources().getString(R.string.information_collection), getResources().getString(R.string.error_view), new DialogInterface.OnClickListener() {
@Override
public void run() {
dialog.stopLoading();
dialog.errorDialog(BuyerInfoActivity.this, getResources().getString(R.string.information_collection), getResources().getString(R.string.error_view), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int id) {
finish();
}
});
public void onClick(DialogInterface dialogInterface, int id) {
finish();
}
});
}
}
});
}
runOnUiThread(new Runnable() {
......
package fr.utc.simde.payutc;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
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;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.Arrays;
import java.util.List;
import fr.utc.simde.payutc.adapters.AllOptionsAdapter;
import fr.utc.simde.payutc.adapters.FoundationsAdapter;
import fr.utc.simde.payutc.adapters.GroupAdapter;
import fr.utc.simde.payutc.adapters.OptionsAdapter;
/**
* Created by Samy on 26/10/2017.
*/
public class FoundationsOptionsActivity extends BaseActivity {
private static final String LOG_TAG = "_FoundationsOptionsActi";
TabHost tabHost;
ListView foundationList;
ListView optionList;
FoundationsAdapter foundationsAdapter;
OptionsAdapter optionsAdapter;
List<String> allOptionList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_foundations_options);
this.tabHost = findViewById(R.id.tabs_foundations_options);
this.foundationList = findViewById(R.id.list_foundations);
this.optionList = findViewById(R.id.list_options);
this.tabHost.setup();
if (config.getCanSell())
this.tabHost.addTab(this.tabHost.newTabSpec(getString(R.string.foundations)).setIndicator(getString(R.string.foundations)).setContent(R.id.list_foundations));
this.tabHost.addTab(this.tabHost.newTabSpec(getString(R.string.options)).setIndicator(getString(R.string.options)).setContent(R.id.list_options));
this.allOptionList = Arrays.asList(getResources().getStringArray(R.array.options));
try {
if (config.getCanSell())
setFoundationList((ArrayNode) new ObjectMapper().readTree(getIntent().getExtras().getString("foundationList")));
setOptionList(config.getOptionList().size() == 0 ? (ArrayNode) new ObjectMapper().valueToTree(this.allOptionList) : config.getOptionList());
} catch (Exception e) {
Log.wtf(LOG_TAG, "error: " + e.getMessage());
fatal(this, getResources().getString(R.string.information_collection), getResources().getString(R.string.error_view));
}
}
@Override
protected void onIdentification(final String badgeId) {}
protected void setFoundationList(final ArrayNode foundationList) throws Exception {
this.foundationsAdapter = new FoundationsAdapter(FoundationsOptionsActivity.this, foundationList);
this.foundationList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
startArticlesActivity(FoundationsOptionsActivity.this, foundationsAdapter.getFoundationId(position), foundationsAdapter.getFoundationName(position));
}
});
this.foundationList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int position, long id) {
foundationsAdapter.toast(position);
return true;
}
});
this.foundationList.setAdapter(this.foundationsAdapter);
}
protected boolean isOption(final int position, final int option) {
return optionsAdapter.getOptionName(position).equals(this.allOptionList.get(option));
}
protected void setOptionList(ArrayNode optionList) throws Exception {
ArrayNode optionListAdded = (ArrayNode) new ObjectMapper().readTree(optionList.toString());
optionListAdded.add(getString(config.getOptionList().size() == 0 ? R.string.configurate : R.string.configurate_by_default));
this.optionsAdapter = new OptionsAdapter(FoundationsOptionsActivity.this, optionListAdded);
this.optionList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
if (isOption(position,0))
dialog.infoDialog(FoundationsOptionsActivity.this, "Non encore fait", "A faire");
else if (isOption(position,1))
dialog.infoDialog(FoundationsOptionsActivity.this, "Non encore fait", "A faire");
else if (isOption(position,2))
dialog.infoDialog(FoundationsOptionsActivity.this, "Non encore fait", "A faire");
else if (isOption(position,3))
startCardManagementActivity(FoundationsOptionsActivity.this);
else if (isOption(position,4))
keyNemopayDialog();
else if (isOption(position,5))
keyGingerDialog();
else
configDialog();
}
});
this.optionList.setAdapter(this.optionsAdapter);
}
protected void keyNemopayDialog() {
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 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.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);
dialog.createDialog(alertDialogBuilder, keyInput);
}
});
}
protected void configDialog() {
hasRights(getString(R.string.configuration), new String[]{}, new Runnable(){
@Override
public void run() {
if (config.getOptionList().size() == 0) {
final LayoutInflater layoutInflater = LayoutInflater.from(FoundationsOptionsActivity.this);
final View popupView = layoutInflater.inflate(R.layout.dialog_group, null);
final ListView listView = popupView.findViewById(R.id.list_groups);
final Switch canSellSwitch = popupView.findViewById(R.id.switch_cancel);
((TextView) popupView.findViewById(R.id.text_to_print)).setText(R.string.option_list);
canSellSwitch.setText(R.string.print_foundations);
AllOptionsAdapter allOptionsAdapter = null;
try {
allOptionsAdapter = new AllOptionsAdapter(FoundationsOptionsActivity.this, (ArrayNode) new ObjectMapper().valueToTree(allOptionList));
listView.setAdapter(allOptionsAdapter);
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
fatal(FoundationsOptionsActivity.this, getResources().getString(R.string.information_collection), getResources().getString(R.string.error_view));
}
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(FoundationsOptionsActivity.this);
final AllOptionsAdapter finalAllOptionsAdapter = allOptionsAdapter;
alertDialogBuilder
.setTitle(R.string.configuration)
.setView(popupView)
.setCancelable(false)
.setPositiveButton(R.string.applicate, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
config.setCanSell(canSellSwitch.isChecked());
ArrayNode optionList = finalAllOptionsAdapter.getList();
if (optionList == null || optionList.size() == 0) {
Toast.makeText(FoundationsOptionsActivity.this, getString(R.string.option_0_selected), Toast.LENGTH_LONG).show();
configDialog();