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

Location sell

Jackson bugs fixed
Handle location sell
parent b956ba23
......@@ -100,7 +100,7 @@ public abstract class BaseActivity extends NFCActivity {
}
}
if ((rights.size() == sameRights.size()) || (rights.size() == 0 && myRightList.has("0") && myRightList.get("0").size() > 75)) // Si on a plus de 75 droits sur toutes les fondations, on estime qu'on a le full access
if ((rights.size() == sameRights.size() && rights.size() != 0) || (rights.size() == 0 && myRightList.has("0") && myRightList.get("0").size() > 75)) // Si on a plus de 75 droits sur toutes les fondations, on estime qu'on a le full access
runOnUiThread(new Runnable() {
@Override
public void run() {
......@@ -164,35 +164,11 @@ public abstract class BaseActivity extends NFCActivity {
if (!request.isJSONResponse() || !foundationList.isArray())
throw new Exception("Malformed JSON");
if (foundationList.size() == 0) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
fatal(activity, getString(R.string.information_collection), nemopaySession.getUsername() + " " + getString(R.string.user_no_rights));
}
});
return;
}
for (final JsonNode foundation : foundationList) {
if (!foundation.has("name") || !foundation.has("fun_id"))
throw new Exception("Unexpected JSON");
}
if (foundationList.size() == 1) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
startArticlesActivity(activity, foundationList.get(0).get("fun_id").intValue(), foundationList.get(0).get("name").textValue());
}
});
return;
}
intent.putExtra("foundationList", request.getResponse());
runOnUiThread(new Runnable() {
@Override
......@@ -391,13 +367,6 @@ public abstract class BaseActivity extends NFCActivity {
}.start();
}
protected void startArticlesActivity(final Activity activity, final int foundationId, final String foundationName) {
nemopaySession.setFoundation(foundationId, foundationName);
Log.d(LOG_TAG, String.valueOf(foundationId));
startArticleGroupActivity(activity);
}
protected void startBuyerInfoActivity(final Activity activity, final String badgeId) {
dialog.startLoading(activity, activity.getResources().getString(R.string.information_collection), activity.getResources().getString(R.string.buyer_info_collecting));
final Intent intent = new Intent(activity, BuyerInfoActivity.class);
......
......@@ -67,7 +67,8 @@ public class FoundationListActivity extends BaseActivity {
@Override
public void onClick(View view) {
startArticlesActivity(FoundationListActivity.this, this.foundationId, this.foundationName);
nemopaySession.setFoundation(this.foundationId, this.foundationName, -1);
startArticleGroupActivity(FoundationListActivity.this);
}
};
......
......@@ -51,15 +51,17 @@ public class FoundationsOptionsActivity extends BaseActivity {
this.tabHost.setup();
if (config.getCanSell())
this.tabHost.addTab(this.tabHost.newTabSpec(getString(R.string.foundations)).setIndicator(getString(R.string.foundations)).setContent(R.id.list_foundations));
this.tabHost.addTab(this.tabHost.newTabSpec(getString(R.string.options)).setIndicator(getString(R.string.options)).setContent(R.id.list_options));
try {
ArrayNode foundationList = (ArrayNode) new ObjectMapper().readTree(getIntent().getExtras().getString("foundationList"));
this.allOptionList = Arrays.asList(getResources().getStringArray(R.array.options));
if (config.getCanSell() && foundationList.size() != 0)
this.tabHost.addTab(this.tabHost.newTabSpec(getString(R.string.foundations)).setIndicator(getString(R.string.foundations)).setContent(R.id.list_foundations));
this.tabHost.addTab(this.tabHost.newTabSpec(getString(R.string.options)).setIndicator(getString(R.string.options)).setContent(R.id.list_options));
try {
if (config.getCanSell())
setFoundationList((ArrayNode) new ObjectMapper().readTree(getIntent().getExtras().getString("foundationList")));
this.allOptionList = Arrays.asList(getResources().getStringArray(R.array.options));
if (config.getCanSell() && foundationList.size() != 0)
setFoundationList(foundationList);
setOptionList(config.getOptionList().size() == 0 ? (ArrayNode) new ObjectMapper().valueToTree(this.allOptionList) : config.getOptionList());
} catch (Exception e) {
......@@ -106,11 +108,11 @@ public class FoundationsOptionsActivity extends BaseActivity {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
if (isOption(position,0))
dialog.infoDialog(FoundationsOptionsActivity.this, "Non encore fait", "A faire");
dialog.infoDialog(FoundationsOptionsActivity.this, "Non encore fait", "Pour la version 0.8");
else if (isOption(position,1))
dialog.infoDialog(FoundationsOptionsActivity.this, "Non encore fait", "A faire");
dialog.infoDialog(FoundationsOptionsActivity.this, "Non encore fait", "Pour la version 0.9");
else if (isOption(position,2))
dialog.infoDialog(FoundationsOptionsActivity.this, "Non encore fait", "A faire");
dialog.infoDialog(FoundationsOptionsActivity.this, "Non encore fait", "Pour la version 0.10");
else if (isOption(position,3))
startCardManagementActivity(FoundationsOptionsActivity.this);
else if (isOption(position,4))
......
......@@ -4,6 +4,7 @@ import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.support.v7.app.AlertDialog;
import android.os.Bundle;
......@@ -132,7 +133,7 @@ public class MainActivity extends BaseActivity {
if (config.getFoundationId() != -1) {
appNameText.setText(config.getFoundationName());
appConfigText.setText(config.getLocationName());
nemopaySession.setFoundation(config.getFoundationId(), config.getFoundationName());
nemopaySession.setFoundation(config.getFoundationId(), config.getFoundationName(), config.getLocationId());
}
else if (config.getOptionList().size() != 0) {
String list = "";
......@@ -146,10 +147,12 @@ public class MainActivity extends BaseActivity {
appNameText.setText(R.string.app_name);
appConfigText.setText(list.length() == 0 ? "" : list.substring(2));
nemopaySession.setFoundation(-1, "", -1);
}
else {
appNameText.setText(R.string.app_name);
appConfigText.setText("");
nemopaySession.setFoundation(-1, "", -1);
}
}
......
......@@ -25,6 +25,7 @@ public class NemopaySession {
private String username;
private int foundationId;
private String foundationName;
private int locationId;
private HTTPRequest request;
......@@ -32,7 +33,7 @@ public class NemopaySession {
private String notLogged;
private String noRight;
private String noRights;
private String noRightsNeeded;
private String allRightsNeeded;
private String serviceText;
private String notFound;
private String badRequest;
......@@ -59,7 +60,7 @@ public class NemopaySession {
this.sessionNull = activity.getString(R.string.session_null);
this.notLogged = activity.getString(R.string.no_longer_connected);
this.noRightsNeeded = activity.getString(R.string.no_need_rights);
this.allRightsNeeded = activity.getString(R.string.all_rights_needed);
this.noRight = activity.getString(R.string.no_right);
this.noRights = activity.getString(R.string.no_rights);
this.serviceText = activity.getString(R.string.service);
......@@ -86,9 +87,10 @@ public class NemopaySession {
disconnect();
}
public void setFoundation(final int foundationId, final String foundationName) {
public void setFoundation(final int foundationId, final String foundationName, final int locationId) {
this.foundationId = foundationId;
this.foundationName = foundationName;
this.locationId = locationId;
}
public String getName() { return this.name; }
......@@ -96,6 +98,7 @@ public class NemopaySession {
public String getUsername() { return username; }
public HTTPRequest getRequest() { return this.request; }
public int getFoundationId() { return foundationId; }
public int getLocationId() { return locationId; }
public String getFoundationName() { return foundationName; }
public int cancelTransaction(final int foundationId, final int purchaseId) throws Exception {
......@@ -134,6 +137,9 @@ public class NemopaySession {
put("fun_id", Integer.toString(foundationId));
put("badge_id", badgeId);
put("obj_ids", obj_ids);
if (locationId != -1)
put("location_id", Integer.toString(locationId));
}},
new String[]{
"POSS3"
......@@ -442,7 +448,7 @@ public class NemopaySession {
public String forbidden(final String[] rightsNeeded) {
String result;
if (rightsNeeded.length == 0)
result = this.noRightsNeeded;
return this.allRightsNeeded;
else if (rightsNeeded.length == 1)
result = this.noRight;
else
......
......@@ -4,7 +4,7 @@
<string name="ginger_no_rights">La clé donnée n\'a pas les droits</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>
<string name="all_rights_needed">Il est nécessaire d\'avoir tous les droits</string>
<string name="error_rights">Impossible de récupérer les droits de la personne</string>
<string name="not_found">n\'a pas réussi à trouver l\'élement souhaité</string>
<string name="bad_request">n\'a pas compris la requête reçue</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