Commit 72541d14 authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

0 category fix

Check if 0 category is selected
parent b43a6c32
......@@ -156,93 +156,7 @@ public class ArticleCategoryActivity extends BaseActivity {
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();
configApp();
}
});
......@@ -322,6 +236,102 @@ public class ArticleCategoryActivity extends BaseActivity {
pay(badgeId);
}
protected void configApp() {
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) {
if (finalGroupAdapter.getList().size() == 0) {
Toast.makeText(ArticleCategoryActivity.this, getString(R.string.category_0_selected), Toast.LENGTH_LONG).show();
configApp();
}
else {
config.setFoundation(nemopaySession.getFoundationId(), nemopaySession.getFoundationName());
config.setGroupList(finalGroupAdapter.getList());
startMainActivity(ArticleCategoryActivity.this);
}
}
})
.setNegativeButton(R.string.cancel, null);
dialog.createDialog(alertDialogBuilder);
}
});
}
}.start();
}
public void clearPanier() {
for (GroupFragment groupFragment : groupFragmentList)
groupFragment.clear();
......
......@@ -70,9 +70,7 @@ public class GroupAdapter extends BaseAdapter {
}
@Override
public int getCount() {
return this.groupList.size();
}
public int getCount() { return this.groupList.size(); }
@Override
public Object getItem(int position) { return 0; }
......
......@@ -94,6 +94,7 @@
<string name="category_list">Liste des catégories</string>
<string name="keyboard_list">Liste des claviers de caisse</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="category_0_selected">Aucune catégorie n\'a été sélectionnée</string>
<string name="print_mode">Mode d\'affichage</string>
<string name="filters">Filtres d\'affichage</string>
......
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