Commit 7e08fac3 authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

Card info

Print all card info
parent d8ebd545
......@@ -39,6 +39,9 @@
<activity android:name=".BuyerInfoActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".ReadCardInfoActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
</application>
</manifest>
\ No newline at end of file
......@@ -380,4 +380,13 @@ public abstract class BaseActivity extends NFCActivity {
}
}.start();
}
protected void startReadCardInfoActivity(final Activity activity) {
hasRights(getString(R.string.user_rights_list_collecting), getResources().getStringArray(R.array.options_rights)[2].split(" "), new Runnable() {
@Override
public void run() {dialog.startLoading(activity, activity.getResources().getString(R.string.information_collection), activity.getResources().getString(R.string.buyer_info_collecting));
activity.startActivity(new Intent(activity, ReadCardInfoActivity.class));
}
});
}
}
......@@ -32,8 +32,6 @@ public class FoundationsOptionsActivity extends BaseActivity {
ListView foundationList;
ListView optionList;
String[] rightsNeeded;
FoundationsAdapter foundationsAdapter;
@Override
......@@ -45,8 +43,6 @@ public class FoundationsOptionsActivity extends BaseActivity {
this.foundationList = findViewById(R.id.list_foundations);
this.optionList = findViewById(R.id.list_options);
this.rightsNeeded = getResources().getStringArray(R.array.options_rights);
this.tabHost.setup();
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));
......@@ -93,13 +89,9 @@ public class FoundationsOptionsActivity extends BaseActivity {
protected void setOptionList() {
this.optionList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
hasRights(getString(R.string.user_rights_list_collecting), rightsNeeded[position].split(" "), new Runnable() {
@Override
public void run() {
dialog.infoDialog(FoundationsOptionsActivity.this, getString(R.string.user_rights_list_collecting), "C'est ok !");
}
});
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
if (position == 2)
startReadCardInfoActivity(FoundationsOptionsActivity.this);
}
});
}
......
package fr.utc.simde.payutc;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
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 fr.utc.simde.payutc.adapters.ListAdapater;
import fr.utc.simde.payutc.tools.HTTPRequest;
/**
* Created by Samy on 29/10/2017.
*/
public class ReadCardInfoActivity extends BaseActivity {
private static final String LOG_TAG = "_ReadCardInfoActivity";
TextView textUserId;
TextView textUsername;
TextView textFirstname;
TextView textLastname;
TextView textEmail;
TextView textAdult;
TextView textCotisant;
TextView textTagId;
TextView textTag;
TextView textShortTag;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_read_card_info);
this.textUserId = findViewById(R.id.text_user_id);
this.textUsername = findViewById(R.id.text_username);
this.textFirstname = findViewById(R.id.text_firstname);
this.textLastname = findViewById(R.id.text_lastname);
this.textEmail = findViewById(R.id.text_email);
this.textAdult = findViewById(R.id.text_adult);
this.textCotisant = findViewById(R.id.text_cotisant);
this.textTagId = findViewById(R.id.text_tag_id);
this.textTag = findViewById(R.id.text_tag);
this.textShortTag = findViewById(R.id.text_short_tag);
dialog.startLoading(ReadCardInfoActivity.this, getString(R.string.information_collection), getString(R.string.badge_waiting));
}
@Override
protected void onIdentification(final String badgeId) {
dialog.startLoading(ReadCardInfoActivity.this, getResources().getString(R.string.information_collection), getResources().getString(R.string.buyer_info_collecting));
new Thread() {
@Override
public void run() {
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");
} 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(ReadCardInfoActivity.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(ReadCardInfoActivity.this, getString(R.string.information_collection), e.getMessage());
}
});
}
return;
}
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.changeLoading(getResources().getString(R.string.user_searching));
}
});
try {
nemopaySession.foundUser(nemopaySession.getRequest().getJSONResponse().get("username").textValue());
Thread.sleep(100);
} 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(ReadCardInfoActivity.this, getString(R.string.information_collection), getString(R.string.user_not_recognized));
}
});
else
throw new Exception("");
} catch (Exception e1) {
runOnUiThread(new Runnable() {
@Override
public void run() {
fatal(ReadCardInfoActivity.this, getString(R.string.information_collection), e.getMessage());
}
});
}
return;
}
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.changeLoading(getResources().getString(R.string.user_info_collecting));
}
});
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());
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");
runOnUiThread(new Runnable() {
@Override
public void run() {
setUserInfo(userInfo.get("user"), userInfo.get("tag"));
dialog.stopLoading();
}
});
} 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(ReadCardInfoActivity.this, getString(R.string.information_collection), getString(R.string.user_error_collecting));
}
});
else
throw new Exception("");
} catch (Exception e1) {
runOnUiThread(new Runnable() {
@Override
public void run() {
fatal(ReadCardInfoActivity.this, getString(R.string.information_collection), e.getMessage());
}
});
}
return;
}
}
}.start();
}
void setUserInfo(JsonNode userInfo, JsonNode tagInfo) {
try {
this.textUserId.setText(Integer.toString(userInfo.get("id").intValue()));
this.textUsername.setText(userInfo.get("username").textValue());
this.textFirstname.setText(userInfo.get("first_name").textValue());
this.textLastname.setText(userInfo.get("last_name").textValue());
this.textEmail.setText(userInfo.get("email").textValue());
this.textAdult.setText(userInfo.get("adult").booleanValue() ? getString(R.string.yes) : getString(R.string.no));
this.textCotisant.setText(userInfo.get("cotisant").booleanValue() ? getString(R.string.yes) : getString(R.string.no));
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());
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
dialog.errorDialog(this, getResources().getString(R.string.information_collection), getResources().getString(R.string.error_view), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int id) {
finish();
}
});
}
}
}
......@@ -157,19 +157,51 @@ public class NemopaySession {
);
}
public int getUser(final int id) throws Exception {
if (!isConnected())
throw new Exception(this.notLogged);
return request(
"GESUSERS",
"getUser",
new HashMap<String, String>() {{
put("id", String.valueOf(id));
}},
new String[]{
"GESUSERS"
}
);
}
public int foundUser(final String username) throws Exception {
if (!isConnected())
throw new Exception(this.notLogged);
return request(
"GESUSERS",
"userAutocompleteUsername",
new HashMap<String, String>() {{
put("queryString", username);
}},
new String[]{
"GESUSERS"
}
);
}
public int getBuyerInfoByLogin(final String login) throws Exception {
if (!isConnected())
throw new Exception(this.notLogged);
return request(
"POSS3",
"getBuyerInfoByLogin",
new HashMap<String, String>() {{
put("login", login);
}},
new String[]{
"POSS3"
}
"POSS3",
"getBuyerInfoByLogin",
new HashMap<String, String>() {{
put("login", login);
}},
new String[]{
"POSS3"
}
);
}
......@@ -178,16 +210,16 @@ public class NemopaySession {
throw new Exception(this.notLogged);
return request(
"POSS3",
"getBuyerInfo",
new HashMap<String, String>() {{
if (foundationId != -1)
put("fun_id", Integer.toString(foundationId));
put("badge_id", badgeId);
}},
new String[]{
"POSS3"
}
"POSS3",
"getBuyerInfo",
new HashMap<String, String>() {{
if (foundationId != -1)
put("fun_id", Integer.toString(foundationId));
put("badge_id", badgeId);
}},
new String[]{
"POSS3"
}
);
}
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="20dp"
android:text="@string/read_card_information" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:text="@string/nemopay_information" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:orientation="horizontal">
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="@string/user_id" />
<TextView
android:id="@+id/text_user_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:orientation="horizontal">
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="@string/username" />
<TextView
android:id="@+id/text_username"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:orientation="horizontal">
<TextView
android:layout_width="150dp"
android:textColor="#000000"
android:layout_height="wrap_content"
android:text="@string/firstname" />
<TextView
android:id="@+id/text_firstname"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:orientation="horizontal">
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="@string/lastname" />
<TextView
android:id="@+id/text_lastname"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:orientation="horizontal">
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="@string/email" />
<TextView
android:id="@+id/text_email"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:orientation="horizontal">
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="@string/adult" />
<TextView
android:id="@+id/text_adult"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:orientation="horizontal">
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="@string/cotisant" />
<TextView
android:id="@+id/text_cotisant"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:orientation="horizontal">
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="@string/tag_id" />
<TextView
android:id="@+id/text_tag_id"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:orientation="horizontal">
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="@string/tag" />
<TextView
android:id="@+id/text_tag"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:orientation="horizontal">
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="@string/short_tag" />
<TextView
android:id="@+id/text_short_tag"
android:textColor="#000000"