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

Merge branch 'release/v0.5.0'

parents d4a61168 5f02e869
......@@ -8,22 +8,30 @@ 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.Button;
import android.widget.CheckBox;
import android.widget.ImageButton;
import android.widget.LinearLayout;
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 android.widget.ToggleButton;
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.HashMap;
import java.util.List;
import fr.utc.simde.payutc.articles.GroupAdapter;
import fr.utc.simde.payutc.articles.GroupFragment;
import fr.utc.simde.payutc.articles.ListAdapater;
import fr.utc.simde.payutc.tools.HTTPRequest;
/**
......@@ -122,32 +130,169 @@ public class ArticleCategoryActivity extends BaseActivity {
this.paramButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final View popupView = LayoutInflater.from(ArticleCategoryActivity.this).inflate(R.layout.dialog_config, null, false);
final ToggleButton gridOrList = popupView.findViewById(R.id.toggle_grid);
final Switch switchCotisant = popupView.findViewById(R.id.swtich_cotisant);
final Switch swtich18 = popupView.findViewById(R.id.swtich_18);
gridOrList.setChecked(config.getInGrid());
switchCotisant.setChecked(config.getPrintCotisant());
swtich18.setChecked(config.getPrint18());
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ArticleCategoryActivity.this);
alertDialogBuilder
.setTitle(R.string.configuration)
.setView(popupView)
.setCancelable(false)
.setPositiveButton(R.string.applicate, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
config.setInGrid(gridOrList.isChecked());
config.setPrintCotisant(switchCotisant.isChecked());
config.setPrint18(swtich18.isChecked());
startCategoryArticlesActivity(ArticleCategoryActivity.this);
if (config.getFoundationId() == -1) {
final View popupView = LayoutInflater.from(ArticleCategoryActivity.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.getInKeyboard())
radioKeyboard.setChecked(true);
else
radioCategory.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) {
dialog.startLoading(ArticleCategoryActivity.this, getResources().getString(R.string.information_collection), getResources().getString(R.string.category_list_collecting));
new Thread() {
@Override
public void run() {
try {
nemopaySession.getCategories();
Thread.sleep(100);
final HTTPRequest request = nemopaySession.getRequest();
final JsonNode categoryList = request.getJSONResponse();
if (!categoryList.isArray())
throw new Exception("Malformed JSON");
if (categoryList.size() == 0) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
dialog.errorDialog(ArticleCategoryActivity.this, getString(R.string.information_collection), nemopaySession.getFoundationName() + " " + getString(R.string.category_error_0));
}
});
return;
}
for (final JsonNode category : categoryList) {
if (!category.has("id") || !category.has("name") || !category.has("fundation_id") || category.get("fundation_id").intValue() != nemopaySession.getFoundationId())
throw new Exception("Unexpected JSON");
}
} catch (final Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
fatal(ArticleCategoryActivity.this, getString(R.string.category_list_collecting), e.getMessage());
}
});
}
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
LayoutInflater layoutInflater = LayoutInflater.from(ArticleCategoryActivity.this);
View popupView = layoutInflater.inflate(R.layout.dialog_group, null);
ListView listView = popupView.findViewById(R.id.list_groups);
JsonNode categoryList = null;
GroupAdapter groupAdapter = null;
try {
categoryList = nemopaySession.getRequest().getJSONResponse();
groupAdapter = new GroupAdapter(ArticleCategoryActivity.this, categoryList);
final GroupAdapter finalGroupAdapter = groupAdapter;
listView.setAdapter(groupAdapter);
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
fatal(ArticleCategoryActivity.this, getString(R.string.category_list_collecting), e.getMessage());
}
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ArticleCategoryActivity.this);
final GroupAdapter finalGroupAdapter = groupAdapter;
alertDialogBuilder
.setTitle(R.string.category_list)
.setView(popupView)
.setCancelable(false)
.setPositiveButton(R.string.applicate, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
config.setFoundation(nemopaySession.getFoundationId(), nemopaySession.getFoundationName());
config.setGroupList(finalGroupAdapter.getList());
startMainActivity(ArticleCategoryActivity.this);
}
})
.setNegativeButton(R.string.cancel, null);
dialog.createDialog(alertDialogBuilder);
}
});
}
}.start();
}
})
.setNegativeButton(R.string.cancel, null);
});
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ArticleCategoryActivity.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.setInKeyboard(radioKeyboard.isChecked());
config.setInGrid(radioGrid.isChecked());
config.setPrintCotisant(switchCotisant.isChecked());
config.setPrint18(swtich18.isChecked());
startCategoryArticlesActivity(ArticleCategoryActivity.this);
}
})
.setNegativeButton(R.string.cancel, null);
dialog.createDialog(alertDialogBuilder);
}
else {
final View popupView = LayoutInflater.from(ArticleCategoryActivity.this).inflate(R.layout.dialog_config_restore, null, false);
final Button configButton = popupView.findViewById(R.id.button_config);
dialog.createDialog(alertDialogBuilder);
configButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
config.setFoundation(-1, "");
config.setGroupList(new ObjectMapper().createObjectNode());
startMainActivity(ArticleCategoryActivity.this);
}
});
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ArticleCategoryActivity.this);
alertDialogBuilder
.setTitle(R.string.configuration)
.setView(popupView)
.setCancelable(false)
.setPositiveButton(R.string.reload, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
startCategoryArticlesActivity(ArticleCategoryActivity.this);
}
})
.setNegativeButton(R.string.cancel, null);
dialog.createDialog(alertDialogBuilder);
}
}
});
......@@ -265,6 +410,8 @@ public class ArticleCategoryActivity extends BaseActivity {
protected void createCategories(final JsonNode categoryList, final JsonNode articleList) throws Exception {
HashMap<Integer, ArrayList<JsonNode>> articlesPerCategory = new HashMap<Integer, ArrayList<JsonNode>>();
final int foundationId = nemopaySession.getFoundationId();
final JsonNode authorizedList = config.getGroupList();
Log.d(LOG_TAG, authorizedList.toString());
for (final JsonNode article : articleList) {
if (!article.has("id") || !article.has("price") || !article.has("name") || !article.has("active") || !article.has("cotisant") || !article.has("alcool") || !article.has("categorie_id") || !article.has("image_url") || !article.has("fundation_id") || article.get("fundation_id").intValue() != foundationId)
......@@ -283,8 +430,11 @@ public class ArticleCategoryActivity extends BaseActivity {
if (!category.has("id") || !category.has("name") || !category.has("fundation_id") || category.get("fundation_id").intValue() != foundationId)
throw new Exception("Unexpected JSON");
Log.d(LOG_TAG, category.toString());
ArrayList<JsonNode> articlesForThisCategory = articlesPerCategory.get(category.get("id").intValue());
if (articlesForThisCategory == null || articlesForThisCategory.size() == 0)
if (config.getFoundationId() != -1) if (!authorizedList.has(Integer.toString(category.get("id").intValue())))
continue;
else if (articlesForThisCategory == null || articlesForThisCategory.size() == 0)
continue;
createNewCategory(category.get("name").textValue(), (ArrayNode) new ObjectMapper().readTree(articlesForThisCategory.toString()));
......
......@@ -11,6 +11,7 @@ import android.widget.TextView;
import com.fasterxml.jackson.databind.JsonNode;
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.HTTPRequest;
import fr.utc.simde.payutc.tools.NemopaySession;
......@@ -26,48 +27,6 @@ public abstract class BaseActivity extends NFCActivity {
protected static CASConnexion casConnexion;
protected static Config config;
public class Config {
private SharedPreferences sharedPreferences;
private Boolean inGrid;
private Boolean printCotisant;
private Boolean print18;
protected Config(final SharedPreferences sharedPreferences) {
this.sharedPreferences = sharedPreferences;
this.inGrid = sharedPreferences.getBoolean("config_in_grid", true);
this.printCotisant = sharedPreferences.getBoolean("config_print_cotisant", false);
this.print18 = sharedPreferences.getBoolean("config_print_18", false);
}
public Boolean getInGrid() { return this.inGrid; }
public void setInGrid(final Boolean inGrid) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("config_in_grid", inGrid);
editor.apply();
this.inGrid = inGrid;
}
public Boolean getPrintCotisant() { return this.printCotisant; }
public void setPrintCotisant(final Boolean printCotisant) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("config_print_cotisant", printCotisant);
editor.apply();
this.printCotisant = printCotisant;
}
public Boolean getPrint18() { return this.print18; }
public void setPrint18(final Boolean print18) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("config_print_18", print18);
editor.apply();
this.print18 = print18;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -98,16 +57,27 @@ public abstract class BaseActivity extends NFCActivity {
dialog.fatalDialog(activity, title, message, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent(activity, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
activity.startActivity(intent);
startMainActivity(activity);
}
});
disconnect();
}
protected void startMainActivity(final Activity activity) {
disconnect();
Intent intent = new Intent(activity, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
activity.startActivity(intent);
}
protected void startFoundationListActivity(final Activity activity) {
if (config.getFoundationId() != -1) {
startCategoryArticlesActivity(activity);
return;
}
dialog.startLoading(activity, getString(R.string.information_collection), getString(R.string.foundation_list_collecting));
final Intent intent = new Intent(activity, FoundationListActivity.class);
......
......@@ -10,6 +10,7 @@ import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.support.v7.app.AlertDialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
......@@ -18,14 +19,19 @@ import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.fasterxml.jackson.databind.JsonNode;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
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.NemopaySession;
......@@ -33,8 +39,9 @@ public class MainActivity extends BaseActivity {
private static final String LOG_TAG = "_MainActivity";
private static final String service = "https://assos.utc.fr";
private static TextView AppConfigText;
private static TextView AppRegisteredText;
private static TextView appNameText;
private static TextView appConfigText;
private static TextView appRegisteredText;
private static Button usernameButton;
private static SharedPreferences sharedPreferences;
......@@ -54,11 +61,12 @@ public class MainActivity extends BaseActivity {
if (!key.equals(""))
setKey(key);
AppConfigText = findViewById(R.id.text_app_config);
AppRegisteredText = findViewById(R.id.text_app_registered);
appNameText = findViewById(R.id.text_app_name);
appConfigText = findViewById(R.id.text_app_config);
appRegisteredText = findViewById(R.id.text_app_registered);
usernameButton = findViewById(R.id.button_username);
AppRegisteredText.setOnLongClickListener(new View.OnLongClickListener() {
appRegisteredText.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (!nemopaySession.isRegistered())
......@@ -76,6 +84,22 @@ public class MainActivity extends BaseActivity {
casDialog();
}
});
setConfig();
}
@Override
public void onResume() {
super.onResume();
setConfig();
}
@Override
public void onRestart() {
super.onRestart();
startMainActivity(MainActivity.this);
}
@Override
......@@ -98,6 +122,24 @@ public class MainActivity extends BaseActivity {
((TextView) findViewById(R.id.text_app_registered)).setText(R.string.app_not_registred);
}
protected void setConfig() {
if (config.getFoundationId() == -1) {
appNameText.setText(R.string.app_name);
appConfigText.setText("");
}
else {
String list = "";
Iterator<Map.Entry<String, JsonNode>> nodes = config.getGroupList().fields();
while (nodes.hasNext())
list += ", " + nodes.next().getValue().textValue();
appNameText.setText(config.getFoundationName());
appConfigText.setText(list.length() == 0 ? "" : list.substring(2));
nemopaySession.setFoundation(config.getFoundationId(), config.getFoundationName());
}
}
protected void delKey() {
SharedPreferences.Editor edit = sharedPreferences.edit();
edit.remove("key");
......
package fr.utc.simde.payutc.articles;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
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.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import fr.utc.simde.payutc.ArticleCategoryActivity;
import fr.utc.simde.payutc.R;
import fr.utc.simde.payutc.tools.HTTPRequest;
/**
* Created by Samy on 29/10/2017.
*/
public class GroupAdapter extends BaseAdapter {
private static final String LOG_TAG = "_GroupAdapter";
protected Activity activity;
protected JsonNode groupList;
protected CheckBox[] checkBoxList;
public GroupAdapter(final Activity activity, final JsonNode groupList) throws Exception {
this.activity = activity;
this.groupList = groupList;
this.checkBoxList = new CheckBox[groupList.size()];
}
@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());
((LinearLayout) view).addView(checkBox);
Log.d(LOG_TAG, Integer.toString(position));
if (this.checkBoxList[position] == null)
this.checkBoxList[position] = checkBox;
}
return view;
}
@Override
public int getCount() {
return this.groupList.size();
}
@Override
public Object getItem(int position) { return 0; }
@Override
public long getItemId(int position) { return position; }
public JsonNode getList() {
ObjectNode groupList = new ObjectMapper().createObjectNode();
Integer i = 0;
for (CheckBox checkBox : this.checkBoxList) {
if (checkBox.isChecked())
groupList.put(Integer.toString(this.groupList.get(i).get("id").intValue()), this.groupList.get(i).get("name").textValue());
i++;
}
return groupList;
}
}
......@@ -18,6 +18,7 @@ import java.util.List;
import fr.utc.simde.payutc.ArticleCategoryActivity;
import fr.utc.simde.payutc.BaseActivity;
import fr.utc.simde.payutc.R;
import fr.utc.simde.payutc.tools.Config;
/**
* Created by Samy on 27/10/2017.
......@@ -36,9 +37,9 @@ public class GroupFragment implements TabHost.TabContentFactory {
private ArticlesAdapter articlesAdapter;
private ArticleCategoryActivity.Panier panier;
private BaseActivity.Config config;
private Config config;
public GroupFragment(final Activity activity, final ArrayNode articleList, final ArticleCategoryActivity.Panier panier, final BaseActivity.Config config) throws Exception {
public GroupFragment(final Activity activity, final ArrayNode articleList, final ArticleCategoryActivity.Panier panier, final Config config) throws Exception {
this.layoutInflater = LayoutInflater.from(activity);
this.panier = panier;
this.config = config;
......
package fr.utc.simde.payutc.tools;
import android.content.SharedPreferences;
import android.util.Log;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.List;
/**
* Created by Samy on 04/11/2017.
*/
public class Config {
private static final String LOG_TAG = "_Config";
private SharedPreferences sharedPreferences;
private String