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

Merge branch 'release/v0.8.0' into develop

parents 88573421 07bb74d7
......@@ -20,7 +20,6 @@ import android.widget.Toast;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.ArrayList;
import java.util.HashMap;
......
......@@ -73,7 +73,8 @@ public abstract class BaseActivity extends NFCActivity {
});
}
protected void hasRights(final String titre, final String[] rightList, final Runnable runnable) {
protected void hasRights(final String title, final String[] rightList, final Runnable runnable) { hasRights(title, rightList, false, runnable);}
protected void hasRights(final String title, final String[] rightList, final boolean needToBeSuper, final Runnable runnable) {
dialog.startLoading(BaseActivity.this, getString(R.string.information_collection), getString(R.string.user_rights_list_collecting));
new Thread() {
@Override
......@@ -93,10 +94,12 @@ public abstract class BaseActivity extends NFCActivity {
}
}
if (myRightList.has(String.valueOf(nemopaySession.getFoundationId()))) {
for (JsonNode myRight : myRightList.get(String.valueOf(nemopaySession.getFoundationId()))) {
if (rights.contains(myRight.textValue()))
sameRights.add(myRight.textValue());
if (!needToBeSuper) {
for (JsonNode foundation : myRightList) {
for (JsonNode myRight : foundation) {
if (rights.contains(myRight.textValue()) && !sameRights.contains(myRight.textValue()))
sameRights.add(myRight.textValue());
}
}
}
......@@ -113,7 +116,7 @@ public abstract class BaseActivity extends NFCActivity {
@Override
public void run() {
dialog.stopLoading();
dialog.errorDialog(BaseActivity.this, titre, nemopaySession.forbidden(rightList));
dialog.errorDialog(BaseActivity.this, title, nemopaySession.forbidden(rightList, needToBeSuper));
}
});
}
......@@ -175,7 +178,7 @@ public abstract class BaseActivity extends NFCActivity {
public void run() {
dialog.stopLoading();
if (activity.getClass().getSimpleName().equals("FoundationsOptionsActivity"))
if (activity instanceof FoundationsOptionsActivity)
finish();
activity.startActivity(intent);
......@@ -347,7 +350,7 @@ public abstract class BaseActivity extends NFCActivity {
public void run() {
dialog.stopLoading();
if (activity.getClass().getSimpleName().equals("ArticleKeyboardActivity") || activity.getClass().getSimpleName().equals("ArticleCategoryActivity"))
if (activity instanceof ArticleGroupActivity)
finish();
activity.startActivity(intent);
......@@ -395,7 +398,7 @@ public abstract class BaseActivity extends NFCActivity {
public void run() {
dialog.stopLoading();
if (activity.getClass().getSimpleName().equals("BuyerInfoActivity"))
if (activity instanceof BuyerInfoActivity)
finish();
activity.startActivity(intent);
......@@ -428,7 +431,7 @@ public abstract class BaseActivity extends NFCActivity {
}
protected void startCardManagementActivity(final Activity activity) {
hasRights(getString(R.string.user_rights_list_collecting), new String[]{"STAFF", "POSS3", "GESUSERS"}, new Runnable() {
hasRights(getString(R.string.user_rights_list_collecting), new String[]{"GESUSERS"}, true, new Runnable() {
@Override
public void run() {
activity.startActivity(new Intent(activity, CardManagementActivity.class));
......
......@@ -23,7 +23,7 @@ import java.util.Date;
*/
public class CardManagementActivity extends BaseActivity {
private static final String LOG_TAG = "CardManagementActivity";
private static final String LOG_TAG = "_CardManagementActivity";
TextView textUserId;
TextView textUsername;
......@@ -120,45 +120,50 @@ public class CardManagementActivity extends BaseActivity {
}.start();
}
else if (toRun == 2) {
dialog.dismiss();
final View view = getLayoutInflater().inflate(R.layout.dialog_contribute, null);
final RadioGroup radioGroup = view.findViewById(R.id.radio_type);
final RadioButton radioButton = view.findViewById(R.id.radio_student);
final EditText editText = view.findViewById(R.id.nbr_days);
radioButton.setChecked(true);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(CardManagementActivity.this);
alertDialogBuilder
.setTitle(R.string.contribute)
.setView(view)
.setCancelable(false)
.setPositiveButton(R.string.contribute, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
dialog.startLoading(CardManagementActivity.this, getString(R.string.information_collection), getString(R.string.buyer_info_collecting));
new Thread(){
@Override
public void run() {
int id = radioGroup.indexOfChild(radioGroup.findViewById(radioGroup.getCheckedRadioButtonId()));
if (contributeCard(id == 3 ? new SimpleDateFormat("yyyy-MM-dd").format(new Date(new Date().getTime() + (Long.parseLong(String.valueOf(editText.getText())) * 86400000L))) : (Integer.parseInt(new SimpleDateFormat("MM").format(new Date())) > 8 ? Integer.toString(Integer.parseInt(new SimpleDateFormat("yyyy").format(new Date())) + 1) : new SimpleDateFormat("yyyy").format(new Date())) + "-08-31", id < 2 ? 20 : 1))
runOnUiThread(new Runnable() {
hasRights(getString(R.string.contribute), new String[]{"GESUSERS"}, true, new Runnable() {
@Override
public void run() {
dialog.dismiss();
final View view = getLayoutInflater().inflate(R.layout.dialog_contribute, null);
final RadioGroup radioGroup = view.findViewById(R.id.radio_type);
final RadioButton radioButton = view.findViewById(R.id.radio_student);
final EditText editText = view.findViewById(R.id.nbr_days);
radioButton.setChecked(true);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(CardManagementActivity.this);
alertDialogBuilder
.setTitle(R.string.contribute)
.setView(view)
.setCancelable(false)
.setPositiveButton(R.string.contribute, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
dialog.startLoading(CardManagementActivity.this, getString(R.string.information_collection), getString(R.string.buyer_info_collecting));
new Thread(){
@Override
public void run() {
Toast.makeText(CardManagementActivity.this, R.string.contribute_now, Toast.LENGTH_LONG).show();
}
});
int id = radioGroup.indexOfChild(radioGroup.findViewById(radioGroup.getCheckedRadioButtonId()));
readCard();
}
}.start();
}
})
.setNegativeButton(R.string.cancel, null);
if (contributeCard(id == 3 ? new SimpleDateFormat("yyyy-MM-dd").format(new Date(new Date().getTime() + (Long.parseLong(String.valueOf(editText.getText())) * 86400000L))) : (Integer.parseInt(new SimpleDateFormat("MM").format(new Date())) > 8 ? Integer.toString(Integer.parseInt(new SimpleDateFormat("yyyy").format(new Date())) + 1) : new SimpleDateFormat("yyyy").format(new Date())) + "-08-31", id < 2 ? 20 : 1))
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(CardManagementActivity.this, R.string.contribute_now, Toast.LENGTH_LONG).show();
}
});
readCard();
}
}.start();
}
})
.setNegativeButton(R.string.cancel, null);
dialog.createDialog(alertDialogBuilder, editText);
dialog.createDialog(alertDialogBuilder, editText);
}
});
}
this.toRun = null;
......@@ -180,8 +185,8 @@ public class CardManagementActivity extends BaseActivity {
this.textTagId.setText(Integer.toString(tagInfo.get("id").intValue()));
this.textTag.setText(tagInfo.get("tag").textValue());
this.textShortTag.setText(tagInfo.get("short_tag").textValue() == null ? getString(R.string.none) : tagInfo.get("short_tag").textValue());
this.textSolde.setText(String.format("%.2f", new Float(this.solde) / 100.00f) + "€");
this.textCotisantGinger.setTextColor(this.solde == 0 ? Color.RED : Color.BLUE);
this.textSolde.setText(this.solde == null ? nemopaySession.forbidden(new String[]{"POSS3"}, false) : String.format("%.2f", new Float(this.solde) / 100.00f) + "€");
this.textSolde.setTextColor(this.solde == null || this.solde == 0 ? Color.RED : Color.BLUE);
this.textUsernameGinger.setText(gingerInfo.get("login").textValue());
this.textFirstnameGinger.setText(gingerInfo.get("prenom").textValue());
......@@ -205,49 +210,6 @@ public class CardManagementActivity extends BaseActivity {
}
protected Boolean contributeCard(final String fin, final Integer paid) {
try {
nemopaySession.getBuyerInfo(badgeId);
Thread.sleep(100);
// Toute une série de vérifications avant de lancer l'activité
final JsonNode buyerInfo = nemopaySession.getRequest().getJSONResponse();
if (!buyerInfo.has("lastname") || !buyerInfo.has("username") || !buyerInfo.has("firstname") || !buyerInfo.has("solde") || !buyerInfo.has("last_purchases") || !buyerInfo.get("last_purchases").isArray())
throw new Exception("Unexpected JSON");
username = nemopaySession.getRequest().getJSONResponse().get("username").textValue();
} catch (final Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
try {
if (nemopaySession.getRequest().getResponseCode() == 400)
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.errorDialog(CardManagementActivity.this, getString(R.string.information_collection), getString(R.string.badge_error_not_recognized));
}
});
else
throw new Exception("");
} catch (Exception e1) {
runOnUiThread(new Runnable() {
@Override
public void run() {
fatal(CardManagementActivity.this, getString(R.string.information_collection), e.getMessage());
}
});
}
return false;
}
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.changeLoading(getResources().getString(R.string.user_ginger_info_collecting));
}
});
try {
ginger.addCotisation(username, fin, paid);
Thread.sleep(100);
......@@ -297,19 +259,23 @@ public class CardManagementActivity extends BaseActivity {
if (!buyerInfo.has("lastname") || !buyerInfo.has("username") || !buyerInfo.has("firstname") || !buyerInfo.has("solde") || !buyerInfo.has("last_purchases") || !buyerInfo.get("last_purchases").isArray())
throw new Exception("Unexpected JSON");
username = nemopaySession.getRequest().getJSONResponse().get("username").textValue();
solde = buyerInfo.get("solde").intValue();
} catch (final Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
try {
if (nemopaySession.getRequest().getResponseCode() == 400)
if (nemopaySession.getRequest().getResponseCode() == 400) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.errorDialog(CardManagementActivity.this, getString(R.string.information_collection), getString(R.string.badge_error_not_recognized));
}
});
return;
}
if (nemopaySession.getRequest().getResponseCode() == 403)
solde = null;
else
throw new Exception("");
} catch (Exception e1) {
......@@ -319,26 +285,34 @@ public class CardManagementActivity extends BaseActivity {
fatal(CardManagementActivity.this, getString(R.string.information_collection), e.getMessage());
}
});
}
return;
return;
}
}
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.changeLoading(getResources().getString(R.string.user_searching));
dialog.changeLoading(getResources().getString(R.string.user_ginger_info_collecting));
}
});
try {
nemopaySession.foundUser(username);
ginger.getInfoFromBadge(badgeId);
Thread.sleep(100);
// Toute une série de vérifications avant de lancer l'activité
final JsonNode gingerInfo = new ObjectMapper().readTree(ginger.getRequest().getResponse()); // La réponse n'est pas considérée comme une réponse json.. (l'en-tête ne renvoie pas une application/json)
if (!gingerInfo.has("login") || !gingerInfo.has("nom") || !gingerInfo.has("prenom") || !gingerInfo.has("mail") || !gingerInfo.has("type") || !gingerInfo.has("is_adulte") || !gingerInfo.has("is_cotisant"))
throw new Exception("Unexpected JSON");
username = gingerInfo.get("login").textValue();
} catch (final Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
try {
if (nemopaySession.getRequest().getResponseCode() == 400)
if (ginger.getRequest().getResponseCode() == 404)
runOnUiThread(new Runnable() {
@Override
public void run() {
......@@ -362,24 +336,13 @@ public class CardManagementActivity extends BaseActivity {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.changeLoading(getResources().getString(R.string.user_nemopay_info_collecting));
dialog.changeLoading(getResources().getString(R.string.information_collection));
}
});
try {
final JsonNode usersFounded = nemopaySession.getRequest().getJSONResponse();
if (!usersFounded.has(0) || !usersFounded.get(0).has("id"))
throw new Exception(getString(R.string.user_not_recognized));
nemopaySession.getUser(usersFounded.get(0).get("id").intValue());
nemopaySession.foundUser(username);
Thread.sleep(100);
// Toute une série de vérifications avant de lancer l'activité
final JsonNode userInfo = nemopaySession.getRequest().getJSONResponse();
if (!userInfo.has("user") || !userInfo.has("tag"))
throw new Exception("Unexpected JSON");
} catch (final Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
......@@ -388,7 +351,7 @@ public class CardManagementActivity extends BaseActivity {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.errorDialog(CardManagementActivity.this, getString(R.string.information_collection), getString(R.string.user_error_collecting));
dialog.errorDialog(CardManagementActivity.this, getString(R.string.information_collection), getString(R.string.user_not_recognized));
}
});
else
......@@ -408,19 +371,24 @@ public class CardManagementActivity extends BaseActivity {
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.changeLoading(getResources().getString(R.string.user_ginger_info_collecting));
dialog.changeLoading(getResources().getString(R.string.user_nemopay_info_collecting));
}
});
try {
ginger.getInfoFromBadge(badgeId);
final JsonNode usersFounded = nemopaySession.getRequest().getJSONResponse();
final JsonNode gingerInfo = new ObjectMapper().readTree(ginger.getRequest().getResponse()); // La réponse n'est pas considérée comme une réponse json.. (l'en-tête ne renvoie pas une application/json)
if (!usersFounded.has(0) || !usersFounded.get(0).has("id"))
throw new Exception(getString(R.string.user_not_recognized));
nemopaySession.getUser(usersFounded.get(0).get("id").intValue());
Thread.sleep(100);
// Toute une série de vérifications avant de lancer l'activité
final JsonNode userInfo = nemopaySession.getRequest().getJSONResponse();
final JsonNode gingerInfo = new ObjectMapper().readTree(ginger.getRequest().getResponse()); // La réponse n'est pas considérée comme une réponse json.. (l'en-tête ne renvoie pas une application/json)
if (!gingerInfo.has("login") || !gingerInfo.has("nom") || !gingerInfo.has("prenom") || !gingerInfo.has("mail") || !gingerInfo.has("type") || !gingerInfo.has("is_adulte") || !gingerInfo.has("is_cotisant"))
if (!userInfo.has("user") || !userInfo.has("tag"))
throw new Exception("Unexpected JSON");
runOnUiThread(new Runnable() {
......@@ -434,11 +402,11 @@ public class CardManagementActivity extends BaseActivity {
Log.e(LOG_TAG, "error: " + e.getMessage());
try {
if (ginger.getRequest().getResponseCode() == 404)
if (nemopaySession.getRequest().getResponseCode() == 400)
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.errorDialog(CardManagementActivity.this, getString(R.string.information_collection), getString(R.string.user_not_recognized));
dialog.errorDialog(CardManagementActivity.this, getString(R.string.information_collection), getString(R.string.user_error_collecting));
}
});
else
......
package fr.utc.simde.jessy;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Created by Samy on 26/10/2017.
*/
public class FoundationListActivity extends BaseActivity {
private static final String LOG_TAG = "_FoundationListActivity";
LinearLayout listLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_foundation_list);
listLayout = findViewById(R.id.foundationList);
try {
setFoundationList(new ObjectMapper().readTree(getIntent().getExtras().getString("foundationList")));
} catch (Exception e) {
Log.wtf(LOG_TAG, "error: " + e.getMessage());
dialog.errorDialog(this, getResources().getString(R.string.information_collection), getResources().getString(R.string.error_unexpected), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int id) {
finish();
}
});
}
}
@Override
protected void onIdentification(final String badgeId) {}
protected void setFoundationList(final JsonNode foundationList) throws Exception {
for (final JsonNode foundation : foundationList) {
Button foundationButton = new Button(this);
if (!foundation.has("name") || !foundation.has("fun_id"))
throw new Exception("Unexpected JSON");
foundationButton.setText(foundation.get("name").textValue());
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 foundationId;
final String foundationName;
public onClickFoundation(final int foundationId, final String foundationName) {
this.foundationId = foundationId;
this.foundationName = foundationName;
}
@Override
public void onClick(View view) {
nemopaySession.setFoundation(this.foundationId, this.foundationName, -1);
startArticleGroupActivity(FoundationListActivity.this);
}
};
}
......@@ -20,8 +20,8 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import java.util.Arrays;
import java.util.List;
import fr.utc.simde.jessy.adapters.OptionChoicesAdapter;
import fr.utc.simde.jessy.adapters.FoundationsAdapter;
import fr.utc.simde.jessy.adapters.OptionChoicesAdapter;
import fr.utc.simde.jessy.adapters.OptionsAdapter;
/**
......@@ -79,7 +79,8 @@ public class FoundationsOptionsActivity extends BaseActivity {
this.foundationList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
startArticlesActivity(FoundationsOptionsActivity.this, foundationsAdapter.getFoundationId(position), foundationsAdapter.getFoundationName(position));
nemopaySession.setFoundation(foundationsAdapter.getFoundationId(position), foundationsAdapter.getFoundationName(position), -1);
startArticleGroupActivity(FoundationsOptionsActivity.this);
}
});
......@@ -108,7 +109,7 @@ 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", "Pour la version 0.8");
dialog.infoDialog(FoundationsOptionsActivity.this, "Non encore fait", "Pour la version 0.9");
else if (isOption(position,1))
dialog.infoDialog(FoundationsOptionsActivity.this, "Non encore fait", "Pour la version 0.9");
else if (isOption(position,2))
......@@ -187,7 +188,7 @@ public class FoundationsOptionsActivity extends BaseActivity {
final ListView listView = popupView.findViewById(R.id.list_groups);
final Switch canSellSwitch = popupView.findViewById(R.id.switch_cancel);
((TextView) popupView.findViewById(R.id.text_to_print)).setText(R.string.option_list);
canSellSwitch.setText(R.string.print_foundations);
canSellSwitch.setText(R.string.can_sell);
OptionChoicesAdapter allOptionsAdapter = null;
try {
......
......@@ -4,10 +4,9 @@ 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;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.View;
import android.widget.Button;
......@@ -21,7 +20,6 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import fr.utc.simde.jessy.tools.CASConnexion;
import fr.utc.simde.jessy.tools.Config;
......
......@@ -5,14 +5,10 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import fr.utc.simde.jessy.R;
......
......@@ -12,7 +12,6 @@ import android.widget.Toast;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import fr.utc.simde.jessy.R;
import fr.utc.simde.jessy.adapters.ArticlesAdapter;
import fr.utc.simde.jessy.adapters.GridAdapter;
......
......@@ -3,7 +3,6 @@ package fr.utc.simde.jessy.tools;
import android.content.SharedPreferences;
import android.util.Log;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
......
......@@ -33,6 +33,8 @@ public class NemopaySession {
private String notLogged;
private String noRight;
private String noRights;
private String noSuperRight;
private String noSuperRights;
private String allRightsNeeded;
private String serviceText;
private String notFound;
......@@ -63,6 +65,8 @@ public class NemopaySession {
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.noSuperRight = activity.getString(R.string.no_super_right);
this.noSuperRights = activity.getString(R.string.no_super_rights);
this.serviceText = activity.getString(R.string.service);
this.notFound = activity.getString(R.string.not_found);