Commit 424c2dd6 authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

Optimization

All start are now in BaseActivity
Optimization
parent 4eb519a2
package fr.utc.simde.payutc;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.util.Log;
import com.fasterxml.jackson.databind.JsonNode;
import fr.utc.simde.payutc.tools.CASConnexion;
import fr.utc.simde.payutc.tools.Dialog;
import fr.utc.simde.payutc.tools.HTTPRequest;
import fr.utc.simde.payutc.tools.NemopaySession;
/**
......@@ -25,4 +33,52 @@ public abstract class BaseActivity extends NFCActivity {
dialog.errorDialog(getString(R.string.key_registration), getString(R.string.key_remove_temp));
}
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() {
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();
try {
if (request.getResponseCode() != 200)
throw new Exception("Malformed JSON");
JsonNode foundationList = request.getJsonResponse();
String response = request.getResponse();
if (!request.isJsonResponse() || !foundationList.isArray())
throw new Exception("JSON unexpected");
for (final JsonNode foundation : foundationList) {
if (!foundation.has("name") || !foundation.has("fun_id"))
throw new Exception("Unexpected JSON");
}
getIntent().getSerializableExtra("MyClass");
Intent intent = new Intent(activity, FoundationListActivity.class);
intent.putExtra("foundationList", response);
dialog.stopLoading();
activity.startActivity(intent);
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
dialog.errorDialog(getString(R.string.information_collection), getString(R.string.foundation_error_get_list));
}
}
});
}
}.start();
}
}
package fr.utc.simde.payutc;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
......@@ -28,41 +29,18 @@ public class FoundationListActivity extends BaseActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_foundation_list);
dialog.startLoading(FoundationListActivity.this, getString(R.string.nemopay_connection), getString(R.string.nemopay_authentification));
new Thread() {
@Override
public void run() {
try {
nemopaySession.getFoundations();
Thread.sleep(100);
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
try {
setFoundationList(new ObjectMapper().readTree(getIntent().getExtras().getString("foundationList")));
} catch (Exception e) {
Log.wtf(LOG_TAG, "error: " + e.getMessage());
dialog.errorDialog(getResources().getString(R.string.information_collection), getResources().getString(R.string.error_unexpected));
/*, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int id) {
finish();
}
runOnUiThread(new Runnable() {
@Override
public void run() {
HTTPRequest request = nemopaySession.getRequest();
dialog.stopLoading();
try {
if (request.getResponseCode() != 200)
throw new Exception("Malformed JSON");
JsonNode foundationList = request.getJsonResponse();
if (!request.isJsonResponse() || !foundationList.isArray())
throw new Exception("JSON unexpected");
setFoundationList(foundationList);
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
dialog.errorDialog(getString(R.string.information_collection), getString(R.string.foundation_error_get_list));
}
}
});
}
}.start();
}*/
}
}
@Override
......@@ -75,7 +53,7 @@ public class FoundationListActivity extends BaseActivity {
disconnect();
}
protected void setFoundationList(JsonNode foundationList) throws Exception {
protected void setFoundationList(final JsonNode foundationList) throws Exception {
LinearLayout linearLayout = findViewById(R.id.foundationList);
for (final JsonNode foundation : foundationList) {
......
......@@ -128,10 +128,6 @@ 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.startLoading(MainActivity.this, getString(R.string.cas_connection), getString(R.string.cas_in_url));
new Thread() {
......@@ -227,7 +223,7 @@ public class MainActivity extends BaseActivity {
else if (!nemopaySession.isRegistered())
keyDialog();
else
startFoundationListActivity();
startFoundationListActivity(MainActivity.this);
}
});
}
......@@ -256,7 +252,7 @@ public class MainActivity extends BaseActivity {
try {
if (nemopaySession.isConnected())
startFoundationListActivity();
startFoundationListActivity(MainActivity.this);
else if (nemopaySession.getRequest().getResponseCode() == 400)
dialog.errorDialog(getString(R.string.badge_dialog), getString(R.string.badge_pin_error_not_recognized));
else
......
......@@ -21,6 +21,9 @@
<string name="no_pin">Pas de PIN</string>
<string name="pin_required">Code PIN requis !</string>
<string name="username_and_password_required">Login CAS et mot de passe requis !</string>
<string name="error_unexpected">Une erreur improbable a eu lieu</string>
<string name="nfc_not_available">NFC non disponible</string>
<string name="nfc_not_enabled">NFC non activé</string>
<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>
......
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