Commit 2c75015e authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

Keyboard config

Add keyboard config
Optimization
parent ed56531e
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;
......@@ -43,8 +44,10 @@ public class ArticleCategoryActivity extends ArticleGroupActivity {
throw new Exception("Unexpected JSON");
ArrayNode articlesForThisCategory = articlesPerCategory.get(category.get("id").intValue());
if (config.getFoundationId() != -1) if (!authorizedList.has(Integer.toString(category.get("id").intValue())))
continue;
if (config.getFoundationId() != -1) {
if (!authorizedList.has(Integer.toString(category.get("id").intValue())) || articlesForThisCategory == null)
continue;
}
else if (articlesForThisCategory == null || articlesForThisCategory.size() == 0)
continue;
......
......@@ -134,8 +134,13 @@ public abstract class ArticleGroupActivity extends BaseActivity {
}
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) {
......@@ -152,8 +157,11 @@ public abstract class ArticleGroupActivity extends BaseActivity {
.setTitle(R.string.configuration)
.setView(popupView)
.setCancelable(false)
.setPositiveButton(R.string.reload, new DialogInterface.OnClickListener() {
.setPositiveButton(R.string.applicate, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
config.setPrintCotisant(switchCotisant.isChecked());
config.setPrint18(swtich18.isChecked());
startArticleGroupActivity(ArticleGroupActivity.this);
}
})
......@@ -193,36 +201,39 @@ 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), getString(R.string.category_list_collecting));
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() {
@Override
public void run() {
try {
nemopaySession.getCategories();
if (config.getInKeyboard())
nemopaySession.getKeyboards();
else
nemopaySession.getCategories();
Thread.sleep(100);
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 == null || groupList.size() == 0) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
dialog.errorDialog(ArticleGroupActivity.this, getString(R.string.information_collection), nemopaySession.getFoundationName() + " " + getString(R.string.category_error_0));
dialog.errorDialog(ArticleGroupActivity.this, 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())
for (final JsonNode group : groupList) {
if (!group.has("id") || !group.has("name"))
throw new Exception("Unexpected JSON");
}
} catch (final Exception e) {
......@@ -231,7 +242,7 @@ public abstract class ArticleGroupActivity extends BaseActivity {
runOnUiThread(new Runnable() {
@Override
public void run() {
fatal(ArticleGroupActivity.this, getString(R.string.category_list_collecting), e.getMessage());
fatal(ArticleGroupActivity.this, getString(config.getInKeyboard() ? R.string.keyboard_list_collecting : R.string.category_list_collecting), e.getMessage());
}
});
}
......@@ -247,17 +258,20 @@ public abstract class ArticleGroupActivity extends BaseActivity {
final Switch canCancelSwitch = popupView.findViewById(R.id.swtich_cancel);
canCancelSwitch.setChecked(config.getCanCancel());
JsonNode categoryList;
if (config.getInKeyboard())
((TextView) popupView.findViewById(R.id.text_to_print)).setText(R.string.keyboard_list);
JsonNode groupList;
GroupAdapter groupAdapter = null;
try {
categoryList = nemopaySession.getRequest().getJSONResponse();
groupAdapter = new GroupAdapter(ArticleGroupActivity.this, categoryList);
groupList = nemopaySession.getRequest().getJSONResponse();
groupAdapter = new GroupAdapter(ArticleGroupActivity.this, groupList);
listView.setAdapter(groupAdapter);
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
fatal(ArticleGroupActivity.this, getString(R.string.category_list_collecting), e.getMessage());
fatal(ArticleGroupActivity.this, getString(config.getInKeyboard() ? R.string.keyboard_list_collecting : R.string.category_list_collecting), e.getMessage());
}
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ArticleGroupActivity.this);
......@@ -269,9 +283,10 @@ public abstract class ArticleGroupActivity extends BaseActivity {
.setPositiveButton(R.string.applicate, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
config.setCanCancel(canCancelSwitch.isChecked());
JsonNode groupList = finalGroupAdapter.getList();
if (finalGroupAdapter.getList().size() == 0) {
Toast.makeText(ArticleGroupActivity.this, getString(R.string.category_0_selected), Toast.LENGTH_LONG).show();
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();
}
else {
......
......@@ -60,7 +60,7 @@ public class GridAdapter extends ArticlesAdapter {
RelativeLayout.LayoutParams parms = new RelativeLayout.LayoutParams(this.size, this.size);
imageView.setLayoutParams(parms);
if (article.size() == 0)
if (article == null || article.size() == 0)
view.setVisibility(View.INVISIBLE);
else {
if (clickViewList[position] == null)
......
package fr.utc.simde.payutc.articles;
import android.app.Activity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
......
......@@ -10,15 +10,47 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:text="@string/print_mode" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:textColor="#000000"
android:text="@string/app_configurated" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:text="@string/filters" />
<Switch
android:id="@+id/swtich_cotisant"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:text="@string/print_cotisant" />
<Switch
android:id="@+id/swtich_18"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:text="@string/print_18" />
<Button
android:id="@+id/button_config"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:text="@string/configurate_by_default" />
......
......@@ -5,24 +5,24 @@
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:text="@string/filters" />
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:text="@string/filters" />
<Switch
android:id="@+id/swtich_cancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:checked="true"
android:text="@string/can_cancel" />
<Switch
android:id="@+id/swtich_cancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:checked="true"
android:text="@string/can_cancel" />
<TextView
android:id="@+id/textView"
android:id="@+id/text_to_print"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
......
Supports Markdown
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