Commit 2c960dbd authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

Merge branch 'feature/qrcode' into develop

parents 53ad2ccf d0d7e98d
......@@ -43,9 +43,6 @@
<activity android:name="fr.utc.simde.jessy.SellActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name="fr.utc.simde.jessy.SellByBottomatikActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name="fr.utc.simde.jessy.EditActivity"
android:configChanges="orientation"
android:screenOrientation="portrait" />
......
......@@ -54,7 +54,6 @@ public abstract class BaseActivity extends InternetActivity {
protected static NemopaySession nemopaySession;
protected static Ginger ginger;
protected static Bottomatik bottomatik;
protected static CASConnexion casConnexion;
protected static Config config;
......@@ -252,13 +251,6 @@ public abstract class BaseActivity extends InternetActivity {
startArticleGroupActivity(activity, new Intent(activity, SellActivity.class));
}
public void startSellBottomatikActivity(final Activity activity) {
if (activity instanceof SellByBottomatikActivity)
finish();
startActivity(new Intent(activity, SellByBottomatikActivity.class));
}
public void startEditActivity(final Activity activity) {
startArticleGroupActivity(activity, new Intent(activity, EditActivity.class));
}
......@@ -609,26 +601,16 @@ public abstract class BaseActivity extends InternetActivity {
}.start();
}
protected void setGingerKey(final String key) {
if (key.equals(""))
return;
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("key_ginger", key);
editor.apply();
ginger.setKey(key);
}
protected void setBottomatikKey(final String key) {
if (key.equals(""))
protected void setKey(final String name, final String key) {
if (name.equals("") || key.equals(""))
return;
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("key_bottomatik", key);
editor.putString("key_" + name, key);
editor.apply();
bottomatik.setKey(key);
if (name.equals("ginger"))
ginger.setKey(key);
}
protected boolean haveStoragePermission() {
......
......@@ -26,7 +26,6 @@ import java.util.Arrays;
import java.util.List;
import fr.utc.simde.jessy.adapters.FoundationsAdapter;
import fr.utc.simde.jessy.adapters.LocationsAdapter;
import fr.utc.simde.jessy.adapters.OptionChoicesAdapter;
import fr.utc.simde.jessy.adapters.OptionsAdapter;
......@@ -134,12 +133,10 @@ public class FoundationsOptionsActivity extends BaseActivity {
else if (isOption(position,6))
keyNemopayDialog();
else if (isOption(position,7))
keyGingerDialog();
keyEditDialog();
else if (isOption(position,8))
keyBottomotikDialog();
else if (isOption(position,9))
checkUpdate();
else if (isOption(position,10))
else if (isOption(position,9))
creditDialog();
else
configDialog();
......@@ -153,73 +150,50 @@ public class FoundationsOptionsActivity extends BaseActivity {
hasRights(getString(R.string.nemopay), new String[]{}, new Runnable(){
@Override
public void run() {
final View keyView = getLayoutInflater().inflate(R.layout.dialog_key_force, null);
final EditText keyInput = keyView.findViewById(R.id.input_key);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(FoundationsOptionsActivity.this);
alertDialogBuilder
.setTitle(getString(R.string.key_registration) + " " + getString(R.string.nemopay))
.setView(keyView)
.setCancelable(false)
.setPositiveButton(R.string.register, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
if (!keyInput.getText().toString().equals(""))
setNemopayKey(keyInput.getText().toString());
}
})
.setNegativeButton(R.string.cancel, null);
dialog.createDialog(alertDialogBuilder, keyInput);
}
});
}
protected void keyGingerDialog() {
hasRights(getString(R.string.ginger), new String[]{}, new Runnable(){
@Override
public void run() {
final View keyView = getLayoutInflater().inflate(R.layout.dialog_key_force, null);
final View keyView = getLayoutInflater().inflate(R.layout.dialog_edit_key, null);
final EditText keyInput = keyView.findViewById(R.id.input_key);
keyView.findViewById(R.id.input_name).setVisibility(View.GONE);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(FoundationsOptionsActivity.this);
alertDialogBuilder
.setTitle(getString(R.string.key_registration) + " " + getString(R.string.ginger))
.setView(keyView)
.setCancelable(false)
.setPositiveButton(R.string.register, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
if (!keyInput.getText().toString().equals(""))
setGingerKey(keyInput.getText().toString());
}
})
.setNegativeButton(R.string.cancel, null);
.setTitle(getString(R.string.key_registration) + " " + getString(R.string.nemopay))
.setView(keyView)
.setCancelable(false)
.setPositiveButton(R.string.register, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
if (!keyInput.getText().toString().equals(""))
setNemopayKey(keyInput.getText().toString());
}
})
.setNegativeButton(R.string.cancel, null);
dialog.createDialog(alertDialogBuilder, keyInput);
}
});
}
protected void keyBottomotikDialog() {
hasRights(getString(R.string.bottomatik), new String[]{}, new Runnable(){
protected void keyEditDialog() {
hasRights(getString(R.string.key_registration), new String[]{}, new Runnable(){
@Override
public void run() {
final View keyView = getLayoutInflater().inflate(R.layout.dialog_key_force, null);
final View keyView = getLayoutInflater().inflate(R.layout.dialog_edit_key, null);
final EditText nameInput = keyView.findViewById(R.id.input_name);
final EditText keyInput = keyView.findViewById(R.id.input_key);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(FoundationsOptionsActivity.this);
alertDialogBuilder
.setTitle(getString(R.string.key_registration) + " " + getString(R.string.bottomatik))
.setTitle(getString(R.string.key_registration))
.setView(keyView)
.setCancelable(false)
.setPositiveButton(R.string.register, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
if (!keyInput.getText().toString().equals(""))
setBottomatikKey(keyInput.getText().toString());
if (!nameInput.getText().toString().equals("") || !keyInput.getText().toString().equals(""))
setKey(nameInput.getText().toString(), keyInput.getText().toString());
}
})
.setNegativeButton(R.string.cancel, null);
dialog.createDialog(alertDialogBuilder, keyInput);
dialog.createDialog(alertDialogBuilder, nameInput);
}
});
}
......
......@@ -5,10 +5,6 @@ import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.media.Image;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.util.Log;
......@@ -58,13 +54,11 @@ public class MainActivity extends BaseActivity {
nemopaySession = new NemopaySession(MainActivity.this);
ginger = new Ginger(MainActivity.this);
bottomatik = new Bottomatik(MainActivity.this);
casConnexion = new CASConnexion(nemopaySession);
config = new Config(sharedPreferences);
setNemopayKey(sharedPreferences.getString("key", ""));
setGingerKey(sharedPreferences.getString("key_ginger", ""));
setBottomatikKey(sharedPreferences.getString("key_bottomatik", ""));
ginger.setKey(sharedPreferences.getString("key_ginger", ""));
appImg = findViewById(R.id.img_payutc);
appNameText = findViewById(R.id.text_app_name);
......@@ -447,7 +441,7 @@ public class MainActivity extends BaseActivity {
}
protected void keyDialog() {
final View keyView = getLayoutInflater().inflate(R.layout.dialog_key, null);
final View keyView = getLayoutInflater().inflate(R.layout.dialog_add_key, null);
final EditText nameInput = keyView.findViewById(R.id.input_name);
final EditText descriptionInput = keyView.findViewById(R.id.input_description);
final String date = new SimpleDateFormat("yyyy/MM/dd", Locale.FRANCE).format(new Date());
......@@ -502,13 +496,14 @@ public class MainActivity extends BaseActivity {
}
protected void optionDialog() {
final View view = getLayoutInflater().inflate(R.layout.dialog_key_force, null);
final EditText keyInput = view.findViewById(R.id.input_key);
final View keyView = getLayoutInflater().inflate(R.layout.dialog_edit_key, null);
final EditText keyInput = keyView.findViewById(R.id.input_key);
keyView.findViewById(R.id.input_name).setVisibility(View.GONE);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
alertDialogBuilder
.setTitle(R.string.key_registration)
.setView(view)
.setTitle(getString(R.string.key_registration) + " " + getString(R.string.nemopay))
.setView(keyView)
.setCancelable(false)
.setPositiveButton(R.string.register, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
......
......@@ -43,7 +43,7 @@ public class SellActivity extends ArticleGroupActivity {
panierText.setOnLongClickListener(new TextView.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
startSellBottomatikActivity(SellActivity.this);
startQRCodeReaderActivity(SellActivity.this);
return false;
}
......@@ -110,7 +110,7 @@ public class SellActivity extends ArticleGroupActivity {
@Override
public void run() {
dialog.stopLoading();
Toast.makeText(SellActivity.this, getString(R.string.transaction_realized), Toast.LENGTH_LONG).show();
Toast.makeText(SellActivity.this, getString(R.string.ticket_realized), Toast.LENGTH_LONG).show();
setBackgroundColor(getResources().getColor(R.color.success));
((Vibrator) getSystemService(ArticleGroupActivity.VIBRATOR_SERVICE)).vibrate(250);
}
......
......@@ -6,6 +6,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.AsyncTask;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
......@@ -147,25 +148,26 @@ public abstract class ArticlesAdapter extends BaseAdapter {
}
public void setImage(final ImageView imageView, final String url, final int position) {
final HTTPRequest[] request = new HTTPRequest[1];
if (imageList[position] != null)
imageView.setImageBitmap(imageList[position]);
else if (url != null && !url.equals("")) {
new Thread(){
@Override
public void run() {
request[0] = new HTTPRequest(url);
final HTTPRequest httpRequest = new HTTPRequest(url);
if (request[0].get() == 200) {
if (httpRequest.get() == 200) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
imageList[position] = request[0].getImageResponse();
if (!httpRequest.isImageResponse())
throw new Exception("Not an Image");
imageList[position] = httpRequest.getImageResponse();
imageView.setImageBitmap(imageList[position]);
} catch (Exception e) {
e.printStackTrace();
Log.e(LOG_TAG, e.getMessage());
}
}
});
......
package fr.utc.simde.jessy.responses;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Samy on 10/11/2017.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class APIResponse {
protected String id;
protected String username;
protected String type;
protected Integer fun_id;
protected long expires_at;
protected long creation_date;
protected boolean paid;
protected boolean validated;
public String getId() { return this.id; }
public String getUsername() { return this.username; }
public String getType() { return this.type; }
public Integer getFoundationId() { return this.fun_id; }
public long getExpiresAt() { return this.expires_at; }
public long getCreatedAt() { return this.creation_date; }
public boolean isPaid() { return this.paid; }
public boolean isValidated() { return this.validated; }
}
......@@ -11,23 +11,9 @@ import java.util.List;
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class BottomatikResponse {
protected String id;
protected String username;
protected String type;
protected int fun_id;
protected long expires_at;
protected long creation_date;
public class BottomatikResponse extends APIResponse {
protected List<List<String>> articles;
protected boolean paid;
protected boolean validated;
public String getId() { return this.id; }
public String getUsername() { return this.username; }
public String getType() { return this.type; }
public int getFoundationId() { return this.fun_id; }
public long getExpiresAt() { return this.expires_at; }
public long getCreatedAt() { return this.creation_date; }
public List<List<Integer>> getArticleList() {
List<List<Integer>> articleList = new ArrayList<List<Integer>>();
......@@ -39,6 +25,4 @@ public class BottomatikResponse {
return articleList;
}
public boolean isPaid() { return this.paid; }
public boolean isValidated() { return this.validated; }
}
package fr.utc.simde.jessy.responses;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
/**
* Created by Samy on 10/11/2017.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class ComedmusResponse extends APIResponse {
protected Integer reservation_id;
protected String seance;
public Integer getReservationId() { return this.reservation_id; }
public String getSeance() { return this.seance; }
}
......@@ -10,7 +10,9 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
public class QRCodeResponse {
protected String username;
protected String id;
protected String system;
public String getUsername() { return this.username; }
public String getId() { return this.id; }
public String getSystem() { return this.system; }
}
package fr.utc.simde.jessy.tools;
import android.app.Activity;
import java.util.HashMap;
import java.util.Map;
import fr.utc.simde.jessy.R;
/**
* Created by Samy on 29/11/2017.
*/
public class API {
private static final String LOG_TAG = "_API";
private String name;
private String url;
private String key;
private HTTPRequest request;
private String noKey;
private String noRight;
private String serviceText;
private String notFound;
private String badRequest;
private String internalError;
private String errorRequest;
public API(final Activity activity, final String name, final String url) {
this.name = name;
this.url = url;
this.key = "";
this.noKey = activity.getString(R.string.ginger_no_key);
this.noRight = activity.getString(R.string.ginger_no_rights);
this.serviceText = activity.getString(R.string.service);
this.notFound = activity.getString(R.string.not_found);
this.badRequest = activity.getString(R.string.bad_request);
this.internalError = activity.getString(R.string.internal_error);
this.errorRequest = activity.getString(R.string.error_request);
}
public void setKey(final String key) { this.key = key; }
public HTTPRequest getRequest() { return this.request; }
public int validate(final String id) throws Exception {
return request(
id + "/validate"
);
}
public int validate(final String id, final boolean paid, final boolean served) throws Exception {
return request(
id + "/validate",
new HashMap<String, Object>() {{
put("paid", paid);
put("served", served);
}}
);
}
public int getInfosFromId(final String id) throws Exception {
return request(
id
);
}
public int getInfosFromUsername(final String username) throws Exception {
return request(
"user/" + username
);
}
protected int request(final String request) throws Exception { return request(request, new HashMap<String, Object>()); }
protected int request(final String request, Map<String, Object> postArgs) throws Exception {
this.request = new HTTPRequest(url + request);
int responseCode;
if (!this.key.equals(""))
this.request.setGet(new HashMap<String, String>(){{ put("app_key", key); }});
if (postArgs.size() == 0)
responseCode = this.request.get();
else {
this.request.setPost(postArgs);
responseCode = this.request.post();
}
if (responseCode == 200)
return 200;
else if (responseCode == 401)
throw new Exception(this.noKey);
else if (responseCode == 403)
throw new Exception(this.noRight);
else if (responseCode == 404)
throw new Exception(this.name + " " + this.notFound);
else if (responseCode == 400)
throw new Exception(this.name + " " + this.badRequest);
else if (responseCode == 500 || responseCode == 503) {
throw new Exception(this.name + " " + this.internalError);
}
else
throw new Exception(this.name + " " + this.errorRequest + " " + responseCode);
}
}
......@@ -28,6 +28,7 @@ import java.util.Map;
public class HTTPRequest {
private static final String LOG_TAG = "_HTTPRequest";
private String url;
private HttpURLConnection request;
......@@ -182,7 +183,7 @@ public class HTTPRequest {
}
catch (Exception e) {
this.BitmapResponse = null;
throw new Exception("Malformed JSON");
throw new Exception("Malformed IMG");
}
}
else {
......@@ -197,7 +198,7 @@ public class HTTPRequest {
in.close();
this.StringResponse = builder.toString();
if (this.request.getContentType().equals("application/json")) {
if (this.request.getContentType().contains("application/json")) {
try {
this.JSONResponse = new ObjectMapper().readTree(this.StringResponse);
this.responseType = "JSON";
......
......@@ -138,11 +138,12 @@ public class NemopaySession {
);
}
public int setTransaction(final String badgeId, final List<List<Integer>> articleList) throws Exception {
public int setTransaction(final String badgeId, final List<List<Integer>> articleList) throws Exception { return setTransaction(badgeId, articleList, this.foundationId); }
public int setTransaction(final String badgeId, final List<List<Integer>> articleList, final int foundationId) throws Exception {
if (!isConnected())
throw new Exception(this.notLogged);
if (this.foundationId == -1)
if (foundationId == -1)
throw new Exception("No foundation set");
return request(
......
<?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">
<TextView
android:id="@+id/text_key_explication"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:text="@string/key_explication"
android:layout_marginBottom="10dp" />
<EditText
android:id="@+id/input_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:inputType="textPersonName"
android:hint="@string/key_name" />