Commit 0fb5e802 authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

ArticleCategory launch

Start ArticleCategoryActivity with information
Cleaning
parent 22d671f7
package fr.utc.simde.payutc;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.util.Log;
import android.widget.TabHost;
import android.widget.TextView;
import fr.utc.simde.payutc.fragments.ArticleGroupFragment;
......@@ -15,12 +11,16 @@ import fr.utc.simde.payutc.fragments.ArticleGroupFragment;
*/
public class ArticleCategoryActivity extends BaseActivity {
private static final String LOG_TAG = "_ArticleCategoryActivit";
@Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView (R.layout.activity_articles_category);
Log.d(LOG_TAG, "C: " + getIntent().getExtras().getString("categoryList"));
Log.d(LOG_TAG, "A: " + getIntent().getExtras().getString("articleList"));
TabHost host = findViewById(R.id.tab_categories);
host.setup();
......
......@@ -49,6 +49,7 @@ public abstract class BaseActivity extends NFCActivity {
protected void startFoundationListActivity(final Activity activity) {
dialog.startLoading(activity, getString(R.string.information_collection), getString(R.string.foundation_list_collecting));
new Thread() {
@Override
public void run() {
......@@ -65,15 +66,15 @@ public abstract class BaseActivity extends NFCActivity {
HTTPRequest request = nemopaySession.getRequest();
try {
// Tout une série de vérifications avant de lancer l'activité
// Toute une série de vérifications avant de lancer l'activité
if (request.getResponseCode() != 200)
throw new Exception("Malformed JSON");
throw new Exception("HTTP Error: " + Integer.toString(request.getResponseCode()));
JsonNode foundationList = request.getJsonResponse();
String response = request.getResponse();
if (!request.isJsonResponse() || !foundationList.isArray())
throw new Exception("JSON unexpected");
throw new Exception("Malformed JSON");
if (foundationList.size() == 0) {
dialog.stopLoading();
......@@ -90,7 +91,7 @@ public abstract class BaseActivity extends NFCActivity {
if (foundationList.size() == 1) {
dialog.stopLoading();
startArticlesActivity(activity, foundationList.get(0).get("fun_id").intValue());
startArticlesActivity(activity, foundationList.get(0).get("fun_id").intValue(), foundationList.get(0).get("name").textValue());
return;
}
......@@ -109,13 +110,116 @@ public abstract class BaseActivity extends NFCActivity {
}
protected void startCategoryArticlesActivity(final Activity activity) {
Intent intent = new Intent(activity, ArticleCategoryActivity.class);
activity.startActivity(intent);
dialog.startLoading(activity, activity.getResources().getString(R.string.information_collection), activity.getResources().getString(R.string.category_list_collecting));
final Thread categoryThread = new Thread() {
@Override
public void run() {
try {
nemopaySession.getCategories();
Thread.sleep(100);
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
}
runOnUiThread(new Runnable() {
@Override
public void run() {
HTTPRequest request = nemopaySession.getRequest();
try {
// Toute une série de vérifications avant de lancer l'activité
if (request.getResponseCode() != 200)
throw new Exception("HTTP Error: " + Integer.toString(request.getResponseCode()));
JsonNode categoryList = request.getJsonResponse();
String response = request.getResponse();
if (!request.isJsonResponse() || !categoryList.isArray())
throw new Exception("Malformed JSON");
if (categoryList.size() == 0) {
dialog.stopLoading();
dialog.errorDialog(activity, 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");
}
String extra_category = response;
dialog.changeLoading(getResources().getString(R.string.article_list_collecting));
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
dialog.errorDialog(activity, getString(R.string.information_collection), getString(R.string.category_error_get_list));
}
}
});
}
};
categoryThread.start();
new Thread() {
@Override
public void run() {
final Intent intent = new Intent(activity, ArticleCategoryActivity.class);
try {
categoryThread.join();
Thread.sleep(100);
intent.putExtra("categoryList", nemopaySession.getRequest().getResponse());
nemopaySession.getArticles();
Thread.sleep(100);
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
}
runOnUiThread(new Runnable() {
@Override
public void run() {
HTTPRequest request = nemopaySession.getRequest();
try {
// Toute une série de vérifications avant de lancer l'activité
if (request.getResponseCode() != 200)
throw new Exception("HTTP Error: " + Integer.toString(request.getResponseCode()));
JsonNode articleList = request.getJsonResponse();
String response = request.getResponse();
if (!request.isJsonResponse() || !articleList.isArray())
throw new Exception("Malformed JSON");
if (articleList.size() == 0) {
dialog.stopLoading();
dialog.errorDialog(activity, getString(R.string.information_collection), nemopaySession.getFoundationName() + " " + getString(R.string.article_error_0));
return;
}
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() != nemopaySession.getFoundationId())
throw new Exception("Unexpected JSON");
}
intent.putExtra("articleList", response);
dialog.stopLoading();
activity.startActivity(intent);
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
dialog.errorDialog(activity, getString(R.string.information_collection), getString(R.string.article_error_get_list));
}
}
});
}
}.start();
}
protected void startArticlesActivity(final Activity activity, final int idFoundation) {
nemopaySession.setFoundation(idFoundation);
Log.d(LOG_TAG, String.valueOf(idFoundation));
protected void startArticlesActivity(final Activity activity, final int foundationId, final String foundationName) {
nemopaySession.setFoundation(foundationId, foundationName);
Log.d(LOG_TAG, String.valueOf(foundationId));
// Plus tard, on pourra choisir quelle activité lancer
startCategoryArticlesActivity(activity);
......
......@@ -64,22 +64,24 @@ public class FoundationListActivity extends BaseActivity {
throw new Exception("Unexpected JSON");
foundationButton.setText(foundation.get("name").textValue());
foundationButton.setOnClickListener(new onClickFoundation(foundation.get("fun_id").intValue()));
foundationButton.setOnClickListener(new onClickFoundation(foundation.get("fun_id").intValue(), foundation.get("name").textValue()));
this.listLayout.addView(foundationButton);
}
}
public class onClickFoundation implements View.OnClickListener {
final int idFoundation;
final int foundationId;
final String foundationName;
public onClickFoundation(int idFoundation) {
this.idFoundation = idFoundation;
public onClickFoundation(final int foundationId, final String foundationName) {
this.foundationId = foundationId;
this.foundationName = foundationName;
}
@Override
public void onClick(View view) {
startArticlesActivity(FoundationListActivity.this, this.idFoundation);
startArticlesActivity(FoundationListActivity.this, this.foundationId, this.foundationName);
}
};
......
......@@ -25,7 +25,8 @@ public class NemopaySession {
private String key;
private String session;
private String username;
private int idFoundation;
private int foundationId;
private String foundationName;
private HTTPRequest request;
private String[] rightsNeeded;
......@@ -40,6 +41,8 @@ public class NemopaySession {
this.key = "";
this.session = "";
this.username = "";
this.foundationId = -1;
this.foundationName = "";
String[] keys = activity.getResources().getStringArray(R.array.rights_keys);
String[] values = activity.getResources().getStringArray(R.array.rights_values);
......@@ -64,16 +67,60 @@ public class NemopaySession {
disconnect();
}
public void setFoundation(final int idFoundation) {
this.idFoundation = idFoundation;
public void setFoundation(final int foundationId, final String foundationName) {
this.foundationId = foundationId;
this.foundationName = foundationName;
}
public String getName() { return this.name; }
public String getKey() { return this.key; }
public String getUsername() { return username; }
public HTTPRequest getRequest() { return this.request; }
public int getFoundationId() { return foundationId; }
public String getFoundationName() { return foundationName; }
public int getArticles() throws Exception {
if (!isConnected())
throw new Exception("Not connected");
if (this.foundationId == -1)
throw new Exception("No foundation set");
return request(
"POSS3",
"getProducts",
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");
if (this.foundationId == -1)
throw new Exception("No foundation set");
return request(
"POSS3",
"getCategories",
new HashMap<String, String>() {{
put("fun_id", Integer.toString(foundationId));
}},
new String[]{
"sale"
}
);
}
public int getFoundations() throws Exception {
if (!isConnected())
throw new Exception("Not connected");
public int getFoundations() throws IOException, JSONException {
return request(
"POSS3",
"getFundations",
......@@ -91,6 +138,9 @@ public class NemopaySession {
}
public int registerApp(final String name, final String description, final String service) throws Exception {
if (!isConnected())
throw new Exception("Not connected");
int reponseCode = request(
"KEY",
"registerApplication",
......@@ -151,6 +201,9 @@ public class NemopaySession {
}
public int loginBadge(final String idBadge, final String pin) throws Exception {
if (!isRegistered())
throw new Exception("Not registered");
int reponseCode = request(
"POSS3",
"loginBadge2",
......
......@@ -29,10 +29,10 @@
<string name="nfc_availability">L\'application nécessite que le NFC soit disponible sur le téléphone pour que celle-ci fonctionne correctement. Elle ne pourra donc être utilisée sur ce téléphone.</string>
<string name="nfc_accessibility">L\'application nécessite que le NFC soit activé pour fonctionner correctement.</string>
<string name="cas_connection">Connexion via CAS</string>
<string name="cas_in_url">Récupération du lien CAS...</string>
<string name="cas_in_connection">Connexion au CAS...</string>
<string name="cas_in_service_adding">Ajout du service au CAS...</string>
<string name="cas_in_service_connection">Connexion au service via le CAS...</string>
<string name="cas_in_url">Récupération du lien CAS</string>
<string name="cas_in_connection">Connexion au CAS</string>
<string name="cas_in_service_adding">Ajout du service au CAS</string>
<string name="cas_in_service_connection">Connexion au service via le CAS</string>
<string name="cas_error_url">Impossible de joindre le CAS</string>
<string name="cas_error_connection">Login et/ou mot de passe non reconnu par le CAS</string>
<string name="cas_error_service_adding">Une erreur a été détectée lors de l\'ajout du service</string>
......@@ -40,7 +40,7 @@
<string name="cas_error_service_linking">Erreur lors de la connexion entre le CAS et le service</string>
<string name="badge_connection">Connexion par badge</string>
<string name="badge_app_not_registered">Il est nécessaire que l\'application soit enregistrée pour permettre la connexion via badge</string>
<string name="badge_recognization">Authentification du badge...</string>
<string name="badge_recognization">Authentification du badge</string>
<string name="badge_error_no_rights">Impossible de vérifier le badge</string>
<string name="badge_pin_error_not_recognized">Badge ou code PIN non reconnu</string>
<string name="badge_pin_not_initialized">Pour pouvoir se connecter via son badge, il est impératif d\'avoir configuré son code PIN sur https://pay.utc.fr/</string>
......@@ -61,8 +61,14 @@
<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="foundation_error_get_list">Impossible de récupérer la liste des fondations</string>
<string name="user_no_rights">n\'a aucun droit. L\'utilisateur a été automatiquement déconnecté</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="category_error_0">n\'a aucune catégorie</string>
<string name="category_error_get_list">Impossible de récupérer la liste des catégories</string>
<string name="article_error_0">n\'a aucun article à vendre</string>
<string name="article_error_get_list">Impossible de récupérer la liste des articles</string>
<string name="user_no_rights">n\'a aucun droit. L\'utilisateur a été automatiquement déconnecté</string>
<string name="no_right">Il est nécessaire d\'avoir au moins le droit suivant:</string>
<string name="no_rights">Il est nécessaire d\'avoir au moins les droits suivants:</string>
<string name="no_need_rights">Aucun droit spécifique n\'est nécessaire</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