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

Option configuration

parent bca0190f
......@@ -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());
......
......@@ -100,7 +100,7 @@ public abstract class BaseActivity extends NFCActivity {
}
}
if ((rights.size() == sameRights.size()) || (myRightList.has("0") && rights.size() == 0))
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() {
......
......@@ -68,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));
}
}
......
......@@ -4,19 +4,27 @@ 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;
/**
......@@ -24,7 +32,7 @@ import fr.utc.simde.payutc.adapters.OptionsAdapter;
*/
public class FoundationsOptionsActivity extends BaseActivity {
private static final String LOG_TAG = "_FoundationsOptionsActivity";
private static final String LOG_TAG = "_FoundationsOptionsActi";
TabHost tabHost;
ListView foundationList;
......@@ -45,22 +53,21 @@ public class FoundationsOptionsActivity extends BaseActivity {
this.optionList = findViewById(R.id.list_options);
this.tabHost.setup();
this.tabHost.addTab(this.tabHost.newTabSpec(getString(R.string.foundations)).setIndicator(getString(R.string.foundations)).setContent(R.id.list_foundations));
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 {
setFoundationList((ArrayNode) new ObjectMapper().readTree(getIntent().getExtras().getString("foundationList")));
setOptionList((ArrayNode) new ObjectMapper().valueToTree(this.allOptionList));
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());
dialog.errorDialog(this, getResources().getString(R.string.information_collection), getResources().getString(R.string.error_unexpected), 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));
}
}
......@@ -89,22 +96,32 @@ public class FoundationsOptionsActivity extends BaseActivity {
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 {
this.optionsAdapter = new OptionsAdapter(FoundationsOptionsActivity.this, optionList);
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) {
final String text = optionsAdapter.getOptionName(position);
if (text.equals(allOptionList.get(3)))
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 (text.equals(allOptionList.get(4)))
else if (isOption(position,4))
keyNemopayDialog();
else if (text.equals(allOptionList.get(5)))
else if (isOption(position,5))
keyGingerDialog();
else
dialog.infoDialog(FoundationsOptionsActivity.this, "Non encore fait", "A faire");
configDialog();
}
});
......@@ -160,4 +177,69 @@ public class FoundationsOptionsActivity extends BaseActivity {
}
});
}
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();
}
else {
config.setOptionList(optionList);
startMainActivity(FoundationsOptionsActivity.this);
}
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
config.setCanSell(true);
}
});
dialog.createDialog(alertDialogBuilder);
}
else {
dialog.infoDialog(FoundationsOptionsActivity.this, getString(R.string.configuration), getString(R.string.app_configurated), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
config.setCanSell(true);
config.setOptionList(new ObjectMapper().createArrayNode());
startMainActivity(FoundationsOptionsActivity.this);
}
});
}
}
});
}
}
......@@ -137,21 +137,34 @@ public class MainActivity extends BaseActivity {
}
protected void setConfig() {
if (config.getFoundationId() == -1) {
appNameText.setText(R.string.app_name);
appConfigText.setText("");
}
else {
if (config.getFoundationId() != -1) {
String list = "";
Iterator<Map.Entry<String, JsonNode>> nodes = config.getGroupList().fields();
Iterator<Map.Entry<String, JsonNode>> foundations = config.getGroupList().fields();
while (nodes.hasNext())
list += ", " + nodes.next().getValue().textValue();
while (foundations.hasNext())
list += ", " + foundations.next().getValue().textValue();
appNameText.setText(config.getFoundationName());
appConfigText.setText(list.length() == 0 ? "" : list.substring(2));
nemopaySession.setFoundation(config.getFoundationId(), config.getFoundationName());
}
else if (config.getOptionList().size() != 0) {
String list = "";
Iterator<JsonNode> options = config.getOptionList().elements();
if (config.getCanSell())
list = ", " + getString(R.string.sell);
while (options.hasNext())
list += ", " + options.next().textValue();
appNameText.setText(R.string.app_name);
appConfigText.setText(list.length() == 0 ? "" : list.substring(2));
}
else {
appNameText.setText(R.string.app_name);
appConfigText.setText("");
}
}
protected void connectWithCAS(final String username, final String password) throws InterruptedException {
......
package fr.utc.simde.payutc.adapters;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.LinearLayout;
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;
/**
* Created by Samy on 29/10/2017.
*/
public class AllOptionsAdapter extends BaseAdapter {
private static final String LOG_TAG = "_AllOptionsAdapter";
protected Activity activity;
protected ArrayNode optionList;
protected CheckBox[] checkBoxList;
public AllOptionsAdapter(final Activity activity, final ArrayNode optionList) throws Exception {
this.activity = activity;
this.optionList = optionList;
this.checkBoxList = new CheckBox[optionList.size()];
}
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
if (view == null) {
view = new LinearLayout(this.activity);
CheckBox checkBox = new CheckBox(this.activity);
checkBox.setText(this.optionList.get(position).textValue());
((LinearLayout) view).addView(checkBox);
if (this.checkBoxList[position] == null)
this.checkBoxList[position] = checkBox;
}
return view;
}
@Override
public int getCount() { return this.optionList.size(); }
@Override
public Object getItem(int position) { return 0; }
@Override
public long getItemId(int position) { return position; }
public ArrayNode getList() {
ArrayNode optionList = new ObjectMapper().createArrayNode();
int i = 0;
for (CheckBox checkBox : this.checkBoxList) {
if (checkBox.isChecked())
optionList.add(this.optionList.get(i).textValue());
i++;
}
return optionList;
}
}
......@@ -52,12 +52,10 @@ public class GroupAdapter extends BaseAdapter {
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
JsonNode group = this.groupList.get(position);
if (view == null) {
view = new LinearLayout(this.activity);
CheckBox checkBox = new CheckBox(this.activity);
checkBox.setText(group.get("name").textValue());
checkBox.setText(this.groupList.get(position).get("name").textValue());
((LinearLayout) view).addView(checkBox);
......
......@@ -5,6 +5,7 @@ import android.util.Log;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import java.io.IOException;
import java.util.List;
......@@ -21,8 +22,10 @@ public class Config {
private String foundationName;
private Integer foundationId;
private JsonNode groupList;
private ArrayNode optionList;
private Boolean canCancel;
private Boolean canSell;
private Boolean inKeyboard;
private Boolean inGrid;
private Boolean printCotisant;
......@@ -40,7 +43,14 @@ public class Config {
Log.e(LOG_TAG, "error: " + e.getMessage());
}
try {
this.optionList = (ArrayNode) new ObjectMapper().readTree(sharedPreferences.getString("config_option_list", "[]"));
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
}
this.canCancel = sharedPreferences.getBoolean("config_can_cancel", true);
this.canSell = sharedPreferences.getBoolean("config_can_sell", true);
this.inKeyboard = sharedPreferences.getBoolean("config_in_keyboard", true);
this.inGrid = sharedPreferences.getBoolean("config_in_grid", true);
this.printCotisant = sharedPreferences.getBoolean("config_print_cotisant", false);
......@@ -68,6 +78,15 @@ public class Config {
this.groupList = groupList;
}
public ArrayNode getOptionList() { return this.optionList; }
public void setOptionList(final ArrayNode optionList) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("config_option_list", optionList.toString());
editor.apply();
this.optionList = optionList;
}
public Boolean getCanCancel() { return this.canCancel; }
public void setCanCancel(final Boolean canCancel) {
SharedPreferences.Editor editor = sharedPreferences.edit();
......@@ -77,6 +96,15 @@ public class Config {
this.canCancel = canCancel;
}
public Boolean getCanSell() { return this.canSell; }
public void setCanSell(final Boolean canSell) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("config_can_sell", canSell);
editor.apply();
this.canSell = canSell;
}
public Boolean getInKeyboard() { return this.inKeyboard; }
public void setInKeyboard(final Boolean inKeyboard) {
SharedPreferences.Editor editor = sharedPreferences.edit();
......
......@@ -12,7 +12,7 @@
android:text="@string/filters" />
<Switch
android:id="@+id/swtich_cancel"
android:id="@+id/switch_cancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
......
......@@ -7,6 +7,5 @@
<item>Gestion des cartes/cotisations</item>
<item>Modifier la clé Nemopay</item>
<item>Modifier la clé Ginger</item>
<item>Configurer l\'appareil</item>
</string-array>
</resources>
\ No newline at end of file
......@@ -29,6 +29,7 @@
<string name="no_pin">Aucun PIN</string>
<string name="pin_required">Code PIN requis !</string>
<string name="username_and_password_required">Login CAS et mot de passe requis !</string>
<string name="sell">Vente</string>
<string name="article">Article</string>
<string name="service">Le service</string>
<string name="realized">Réalisé à</string>
......@@ -128,9 +129,11 @@
<string name="no_longer_connected">L\'application nécessite d\'être reconnectée. Retour à la page d\'accueil</string>
<string name="category_list">Liste des catégories à afficher</string>
<string name="keyboard_list">Liste des claviers de caisse à afficher</string>
<string name="option_list">Liste des options à afficher</string>
<string name="category_0_selected">Aucune catégorie n\'a été sélectionnée</string>
<string name="keyboard_0_selected">Aucun clavier n\'a été sélectionnée</string>
<string name="app_configurated">L\'application a été configurée par défaut sur ce mode d\'affichage. Seul une personne possédant tous les droits sur cette fondation peut reconfigurer l\'application par défaut</string>
<string name="keyboard_0_selected">Aucun clavier n\'a été sélectionné</string>
<string name="option_0_selected">Aucune option n\'a été sélectionnée</string>
<string name="app_configurated">L\'application a été configurée par défaut sur ce mode d\'affichage. Seul une personne possédant les droits peut reconfigurer l\'application par défaut</string>
<string name="can_cancel">Permettre l\'annulation</string>
<string name="cant_cancel">L\'application a été configurée pour ne pas permettre l\'annulation d\'une transaction (contacter un adminstrateur pour annuler)</string>
<string name="read_card_information">Informations de la carte</string>
......@@ -150,4 +153,5 @@
<string name="filters">Filtres d\'affichage</string>
<string name="print_cotisant">Afficher le filtre cotisant</string>
<string name="print_18">Afficher le filtre majeur</string>
<string name="print_foundations">Afficher les différentes fondations</string>
</resources>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment