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

Keyboard management

Add keyboard management
Can swap between keyboard and category mode
Optimize empty cell in grid view
parent 68de0c7e
......@@ -29,6 +29,9 @@
<activity android:name=".FoundationListActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".ArticleKeyboardActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".ArticleCategoryActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
......
package fr.utc.simde.payutc;
import android.os.Bundle;
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.util.ArrayList;
import java.util.HashMap;
/**
......@@ -23,10 +21,9 @@ public class ArticleCategoryActivity extends ArticleGroupActivity {
}
protected void createGroups(final JsonNode categoryList, final JsonNode articleList) throws Exception {
HashMap<Integer, ArrayList<JsonNode>> articlesPerCategory = new HashMap<Integer, ArrayList<JsonNode>>();
HashMap<Integer, ArrayNode> articlesPerCategory = new HashMap<Integer, ArrayNode>();
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)
......@@ -38,21 +35,20 @@ public class ArticleCategoryActivity extends ArticleGroupActivity {
if (articlesPerCategory.containsKey(article.get("categorie_id").intValue()))
articlesPerCategory.get(article.get("categorie_id").intValue()).add(article);
else
articlesPerCategory.put(article.get("categorie_id").intValue(), new ArrayList<JsonNode>(){{ add(article); }});
articlesPerCategory.put(article.get("categorie_id").intValue(), new ObjectMapper().createArrayNode().add(article));
}
for (JsonNode category : categoryList) {
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());
ArrayNode articlesForThisCategory = articlesPerCategory.get(category.get("id").intValue());
if (config.getFoundationId() != -1) if (!authorizedList.has(Integer.toString(category.get("id").intValue())))
continue;
else if (articlesForThisCategory == null || articlesForThisCategory.size() == 0)
continue;
createNewGroup(category.get("name").textValue(), (ArrayNode) new ObjectMapper().readTree(articlesForThisCategory.toString()));
createNewGroup(category.get("name").textValue(), articlesForThisCategory);
}
}
}
......@@ -21,7 +21,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import fr.utc.simde.payutc.articles.GroupAdapter;
......@@ -194,7 +193,7 @@ public abstract class ArticleGroupActivity extends BaseActivity {
protected abstract void createGroups(final JsonNode groupList, final JsonNode articleList) throws Exception;
protected void configApp() {
dialog.startLoading(ArticleGroupActivity.this, getResources().getString(R.string.information_collection), getResources().getString(R.string.category_list_collecting));
dialog.startLoading(ArticleGroupActivity.this, getResources().getString(R.string.information_collection), getString(R.string.category_list_collecting));
new Thread() {
@Override
......@@ -380,8 +379,9 @@ public abstract class ArticleGroupActivity extends BaseActivity {
}.start();
}
protected void createNewGroup(final String name, final ArrayNode articleList) throws Exception {
GroupFragment articleGroupFragment = new GroupFragment(ArticleGroupActivity.this, articleList, this.panier, this.config);
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);
......
package fr.utc.simde.payutc;
import android.os.Bundle;
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.util.ArrayList;
import java.util.HashMap;
import fr.utc.simde.payutc.ArticleGroupActivity;
/**
* Created by Samy on 27/10/2017.
*/
public class ArticleKeyboardActivity extends ArticleGroupActivity {
private static final String LOG_TAG = "_ArticleKeyboardActivit";
@Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
protected void createGroups(final JsonNode keyboardList, final JsonNode articleList) throws Exception {
final int foundationId = nemopaySession.getFoundationId();
final JsonNode authorizedList = config.getGroupList();
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)
throw new Exception("Unexpected JSON");
}
for (JsonNode keyboard : keyboardList) {
ArrayNode articlesForThisKeyboard = new ObjectMapper().createArrayNode();
if (!keyboard.has("id") || !keyboard.has("name") || !keyboard.has("fun_id") || keyboard.get("fun_id").intValue() != foundationId || !keyboard.has("data") || !keyboard.get("data").has("items") || !keyboard.get("data").get("items").isArray() || !keyboard.get("data").has("nbColumns"))
throw new Exception("Unexpected JSON");
if (config.getFoundationId() != -1) if (!authorizedList.has(Integer.toString(keyboard.get("id").intValue())))
continue;
else if (keyboard.get("data").get("items").size() == 0)
continue;
for (JsonNode article : keyboard.get("data").get("items")) {
if (article.has("itm_id")) {
boolean in = false;
for (JsonNode articleInList : articleList) {
if (articleInList.get("id").intValue() == article.get("itm_id").intValue()) {
articlesForThisKeyboard.add(articleInList);
in = true;
break;
}
}
if (!in)
articlesForThisKeyboard.add(new ObjectMapper().createObjectNode());
}
else if (config.getInGrid())
articlesForThisKeyboard.add(new ObjectMapper().createObjectNode());
}
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()));
}
}
}
......@@ -151,41 +151,39 @@ public abstract class BaseActivity extends NFCActivity {
}
protected void startArticleGroupActivity(final Activity activity) {
dialog.startLoading(activity, activity.getResources().getString(R.string.information_collection), activity.getResources().getString(R.string.category_list_collecting));
final Intent intent = new Intent(activity, ArticleCategoryActivity.class);
dialog.startLoading(activity, activity.getResources().getString(R.string.information_collection), activity.getResources().getString(config.getInKeyboard() ? R.string.keyboard_list_collecting : R.string.category_list_collecting));
final Intent intent = new Intent(activity, config.getInKeyboard() ? ArticleKeyboardActivity.class : ArticleCategoryActivity.class);
new Thread() {
@Override
public void run() {
try {
int responseCode = nemopaySession.getCategories();
if (config.getInKeyboard())
nemopaySession.getKeyboards();
else
nemopaySession.getCategories();
Thread.sleep(100);
// Toute une série de vérifications avant de lancer l'activité
final HTTPRequest request = nemopaySession.getRequest();
final JsonNode categoryList = request.getJSONResponse();
final JsonNode groupList = request.getJSONResponse();
if (!categoryList.isArray())
if (!groupList.isArray())
throw new Exception("Malformed JSON");
if (categoryList.size() == 0) {
if (groupList.size() == 0) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
dialog.errorDialog(activity, getString(R.string.information_collection), nemopaySession.getFoundationName() + " " + getString(R.string.category_error_0));
dialog.errorDialog(activity, getString(R.string.information_collection), nemopaySession.getFoundationName() + " " + getString(config.getInKeyboard() ? R.string.keyboard_error_0 : 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");
}
intent.putExtra("groupList", request.getResponse());
} catch (final Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
......@@ -193,7 +191,7 @@ public abstract class BaseActivity extends NFCActivity {
runOnUiThread(new Runnable() {
@Override
public void run() {
fatal(activity, getString(R.string.category_list_collecting), e.getMessage());
fatal(activity, getString(config.getInKeyboard() ? R.string.keyboard_list_collecting : R.string.category_list_collecting), e.getMessage());
}
});
}
......@@ -239,7 +237,7 @@ public abstract class BaseActivity extends NFCActivity {
public void run() {
dialog.stopLoading();
if (activity.getClass().getSimpleName().equals("ArticleCategoryActivity"))
if (activity.getClass().getSimpleName().equals("ArticleKeyboardActivity") || activity.getClass().getSimpleName().equals("ArticleCategoryActivity"))
finish();
activity.startActivity(intent);
......
......@@ -2,6 +2,7 @@ package fr.utc.simde.payutc.articles;
import android.app.Activity;
import android.media.Image;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -52,23 +53,22 @@ public class GridAdapter extends ArticlesAdapter {
JsonNode article = this.articleList.get(position);
if (view == null) {
if (article.size() == 0)
view = new View(this.activity);
else {
LayoutInflater layoutInflater = LayoutInflater.from(this.activity);
view = layoutInflater.inflate(R.layout.fragment_article_grid, null);
LayoutInflater layoutInflater = LayoutInflater.from(this.activity);
view = layoutInflater.inflate(R.layout.fragment_article_grid, null);
ImageView imageView = view.findViewById(R.id.image_article);
ImageView imageView = view.findViewById(R.id.image_article);
RelativeLayout.LayoutParams parms = new RelativeLayout.LayoutParams(this.size, this.size);
imageView.setLayoutParams(parms);
if (article.size() == 0)
view.setVisibility(View.INVISIBLE);
else {
if (clickViewList[position] == null)
clickViewList[position] = view.findViewById(R.id.text_nbr_clicks);
TextView textView = view.findViewById(R.id.text_article);
textView.setText(article.get("name").textValue());
RelativeLayout.LayoutParams parms = new RelativeLayout.LayoutParams(this.size, this.size);
imageView.setLayoutParams(parms);
ImageView imageCotisant = view.findViewById(R.id.image_cotisant);
ImageView image18 = view.findViewById(R.id.image_18);
......
......@@ -40,7 +40,8 @@ public class GroupFragment implements TabHost.TabContentFactory {
private Panier panier;
private Config config;
public GroupFragment(final Activity activity, final ArrayNode articleList, final Panier panier, final Config config) throws Exception {
public GroupFragment(final Activity activity, final ArrayNode articleList, final Panier panier, final Config config) throws Exception { new GroupFragment(activity, articleList, panier, config, 3); }
public GroupFragment(final Activity activity, final ArrayNode articleList, final Panier panier, final Config config, final int gridColumns) throws Exception {
this.layoutInflater = LayoutInflater.from(activity);
this.panier = panier;
this.config = config;
......@@ -48,7 +49,7 @@ public class GroupFragment implements TabHost.TabContentFactory {
if (config.getInGrid()) {
this.view = this.layoutInflater.inflate(R.layout.fragment_article_group_grid, null);
this.gridView = this.view.findViewById(R.id.grid_articles);
setGridLayout(3);
setGridLayout(gridColumns);
createArticleGrid(activity, articleList);
}
else {
......
......@@ -41,7 +41,7 @@ public class Config {
}
this.canCancel = sharedPreferences.getBoolean("config_can_cancel", true);
this.inKeyboard = sharedPreferences.getBoolean("config_in_keyboard", false);
this.inKeyboard = sharedPreferences.getBoolean("config_in_keyboard", true);
this.inGrid = sharedPreferences.getBoolean("config_in_grid", true);
this.printCotisant = sharedPreferences.getBoolean("config_print_cotisant", false);
this.print18 = sharedPreferences.getBoolean("config_print_18", false);
......
......@@ -195,6 +195,25 @@ public class NemopaySession {
);
}
public int getKeyboards() throws Exception {
if (!isConnected())
throw new Exception("Not connected");
if (this.foundationId == -1)
throw new Exception("No foundation set");
return request(
"POSS3",
"getKeyboards",
new HashMap<String, String>() {{
put("fun_id", Integer.toString(foundationId));
}},
new String[]{
"sale"
}
);
}
public int getCategories() throws Exception {
if (!isConnected())
throw new Exception("Not connected");
......
......@@ -79,8 +79,10 @@
<string name="already_connected">Déjà connecté sous</string>
<string name="information_collection">Récupération d\'informations</string>
<string name="foundation_list_collecting">Récupération de la liste des fondations</string>
<string name="keyboard_list_collecting">Récupération des claviers de caisse</string>
<string name="category_list_collecting">Récupération des catégories</string>
<string name="article_list_collecting">Récupération des articles</string>
<string name="keyboard_error_0">n\'a aucun clavier de caisse</string>
<string name="category_error_0">n\'a aucune catégorie</string>
<string name="article_error_0">n\'a aucun article à vendre</string>
<string name="article_error_0_categorie_not_0">Toutes les catégories sont vides</string>
......
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