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

Creation of the FoundationList activity

Preparation of FoundationListActivity
Cleaning
Launch the new activity after login
Fix bugs
parent 384e6708
......@@ -19,6 +19,7 @@
</intent-filter>
</activity>
<activity android:name=".BaseActivity" />
<activity android:name=".FoundationListActivity" />
</application>
</manifest>
\ No newline at end of file
package fr.utc.simde.payutc;
import android.os.Bundle;
import android.widget.TextView;
import fr.utc.simde.payutc.tools.CASConnexion;
import fr.utc.simde.payutc.tools.Dialog;
import fr.utc.simde.payutc.tools.NemopaySession;
......
package fr.utc.simde.payutc;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.util.Log;
import fr.utc.simde.payutc.tools.HTTPRequest;
/**
* Created by Samy on 26/10/2017.
*/
public class FoundationListActivity extends BaseActivity {
private static final String LOG_TAG = "_FoundationListActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_foundation_list);
final ProgressDialog loading = ProgressDialog.show(FoundationListActivity.this, getString(R.string.nemopay_connection), getString(R.string.nemopay_authentification), true);
loading.setCancelable(false);
new Thread() {
@Override
public void run() {
try {
nemopaySession.getFoundations();
Thread.sleep(100);
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
}
runOnUiThread(new Runnable() {
@Override
public void run() {
HTTPRequest request = nemopaySession.getRequest();
loading.dismiss();
try {
if (request.getResponseCode() == 200 && request.isJsonResponse())
return; // setFoundationList(request.getJsonResponse();
else
dialog.errorDialog(getString(R.string.information_collection), getString(R.string.foundation_error_get_list));
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
}
}
});
}
}.start();
}
@Override
protected void onIdentification(String idBadge) {}
@Override
protected void onDestroy() {
super.onDestroy();
disconnect();
}
}
......@@ -3,6 +3,7 @@ package fr.utc.simde.payutc;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AlertDialog;
import android.os.Bundle;
......@@ -78,6 +79,7 @@ public class MainActivity extends BaseActivity {
@Override
protected void unregister() {
super.unregister();
((TextView) findViewById(R.id.text_app_registered)).setText(R.string.app_not_registred);
}
......@@ -97,7 +99,6 @@ public class MainActivity extends BaseActivity {
final ProgressDialog loading = ProgressDialog.show(MainActivity.this, getString(R.string.nemopay_connection), getString(R.string.nemopay_authentification), true);
loading.setCancelable(false);
new Thread() {
@Override
public void run() {
......@@ -128,6 +129,10 @@ public class MainActivity extends BaseActivity {
}.start();
}
protected void startFoundationListActivity() {
MainActivity.this.startActivity(new Intent(MainActivity.this, FoundationListActivity.class));
}
protected void connectWithCAS(final String username, final String password) throws InterruptedException {
dialog.dismiss();
......@@ -227,7 +232,7 @@ public class MainActivity extends BaseActivity {
else if (!nemopaySession.isRegistered())
keyDialog();
else
Toast.makeText(MainActivity.this, "Tout est bon !", Toast.LENGTH_SHORT).show();
startFoundationListActivity();
}
});
}
......@@ -259,7 +264,7 @@ public class MainActivity extends BaseActivity {
try {
if (nemopaySession.isConnected())
Toast.makeText(MainActivity.this, "Tout est bon !", Toast.LENGTH_SHORT).show();
startFoundationListActivity();
else if (nemopaySession.getRequest().getResponseCode() == 400)
dialog.errorDialog(getString(R.string.badge_dialog), getString(R.string.badge_pin_error_not_recognized));
else
......
......@@ -20,8 +20,6 @@ import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.widget.Toast;
import fr.utc.simde.payutc.R;
public abstract class NFCActivity extends Activity {
private static final String LOG_TAG = "_NFCActivity";
private static NfcAdapter NFCAdapter;
......@@ -34,9 +32,6 @@ public abstract class NFCActivity extends Activity {
NFCAdapter = NfcAdapter.getDefaultAdapter(getApplicationContext());
NFCAlertDialog = new AlertDialog.Builder(this);
IntentFilter filter = new IntentFilter(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
this.registerReceiver(NFCReceiver, filter);
if (NFCAdapter == null) {
Toast.makeText(this, R.string.nfc_not_available, Toast.LENGTH_LONG).show();
NFCAlertDialog
......@@ -53,6 +48,9 @@ public abstract class NFCActivity extends Activity {
AlertDialog alertDialog = NFCAlertDialog.create();
alertDialog.show();
}
IntentFilter filter = new IntentFilter(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
this.registerReceiver(NFCReceiver, filter);
}
protected abstract void onIdentification(final String idBadge);
......@@ -100,7 +98,7 @@ public abstract class NFCActivity extends Activity {
NFCAdapter.disableForegroundDispatch(this);
}
public void onDestroy() {
protected void onDestroy() {
super.onDestroy();
this.unregisterReceiver(NFCReceiver);
......
......@@ -43,12 +43,19 @@ public class CASConnexion {
}
public void disconnect() {
if (isConnected()) {
new Thread() {
@Override
public void run() {
HTTPRequest request = new HTTPRequest(url + "logout");
request.post();
}
}.start();
}
this.username = "";
this.location = "";
this.ticket = "";
HTTPRequest request = new HTTPRequest(this.url + "logout");
request.post();
}
public Boolean isConnected() { return !this.location.isEmpty(); }
......
package fr.utc.simde.payutc.tools;
import android.app.Activity;
import android.content.Context;
import android.content.res.XmlResourceParser;
import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParser;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import fr.utc.simde.payutc.R;
import static java.lang.System.in;
/**
* Created by Samy on 24/10/2017.
*/
......@@ -57,8 +49,10 @@ public class NemopaySession {
public Boolean isRegistered() { return !this.name.isEmpty() && !this.key.isEmpty() && !this.session.isEmpty(); }
public void disconnect() {
this.session = "";
this.username = "";
if (!isRegistered())
this.session = "";
}
public void unregister() {
......@@ -73,16 +67,33 @@ public class NemopaySession {
public String getUsername() { return username; }
public HTTPRequest getRequest() { return this.request; }
public int getFoundations() throws IOException, JSONException {
return request(
"POSS3",
"getFundations",
new String[]{
"sale"
}
);
}
public int getCASUrl() throws IOException {
return request("POSS3", "getCasUrl");
return request(
"POSS3",
"getCasUrl"
);
}
public int registerApp(final String name, final String description, final String service) throws IOException, JSONException {
int reponseCode = request("KEY", "registerApplication", new HashMap<String, String>() {{
put("app_url", service);
put("app_name", name);
put("app_desc", description);
}});
int reponseCode = request(
"KEY",
"registerApplication",
new HashMap<String, String>() {{
put("app_url", service);
put("app_name", name);
put("app_desc", description);
}}
);
if (reponseCode == 200 && this.request.isJsonResponse())
this.key = this.request.getJsonResponse().getString("app_key");
......@@ -102,9 +113,13 @@ public class NemopaySession {
return reponseCode;
}
public int loginApp(final String key) throws Exception {
int reponseCode = request("POSS3", "loginApp", new HashMap<String, String>() {{
put("key", key);
}});
int reponseCode = request(
"POSS3",
"loginApp",
new HashMap<String, String>() {{
put("key", key);
}}
);
JSONObject response;
if (reponseCode == 200 && this.request.isJsonResponse())
......@@ -124,12 +139,17 @@ public class NemopaySession {
}
public int loginBadge(final String idBadge, final String pin) throws Exception {
int reponseCode = request("POSS3", "loginBadge2", new HashMap<String, String>() {{
put("badge_id", idBadge);
put("pin", pin);
}}, new String[]{
"sale"
});
int reponseCode = request(
"POSS3",
"loginBadge2",
new HashMap<String, String>() {{
put("badge_id", idBadge);
put("pin", pin);
}},
new String[]{
"sale"
}
);
JSONObject response;
if (reponseCode == 200 && this.request.isJsonResponse())
......@@ -148,10 +168,14 @@ public class NemopaySession {
}
public int loginCas(final String ticket, final String service) throws Exception {
int reponseCode = request("POSS3", "loginCas2", new HashMap<String, String>() {{
put("ticket", ticket);
put("service", service);
}});
int reponseCode = request(
"POSS3",
"loginCas2",
new HashMap<String, String>() {{
put("ticket", ticket);
put("service", service);
}}
);
JSONObject response;
if (reponseCode == 200 && this.request.isJsonResponse())
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
\ No newline at end of file
......@@ -54,6 +54,9 @@
<string name="key_add_explication">Il est possible d\'ajouter directement une clé d\'application si celle-ci est connue</string>
<string name="key_remove_temp">L\'application a été désauthentifiée temporairement. Il suffit de relancer l\'application pour qu\'elle soit de nouveau connectée</string>
<string name="already_connected">Déjà connecté sous</string>
<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="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>
......
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