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

Change completely the API protocol

Can now add easely new API
API have to dictate what to do
API can configurate 3 different responses for each request and set a special request
API can print a message or a list of information formatted
parent a63e1895
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/PayUTC.iml" filepath="$PROJECT_DIR$/PayUTC.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
<module fileurl="file://$PROJECT_DIR$/jessy.iml" filepath="$PROJECT_DIR$/jessy.iml" /> <module fileurl="file://$PROJECT_DIR$/jessy.iml" filepath="$PROJECT_DIR$/jessy.iml" />
</modules> </modules>
......
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
android { android {
signingConfigs {
config {
keyAlias 'jessy'
keyPassword 'kVg6ikc+(lTkre8//m%f1'
storeFile file('/root/jessy.jks')
storePassword 'kVg6ikc+(lTkre8//m%f1'
}
}
compileSdkVersion 26 compileSdkVersion 26
buildToolsVersion '26.0.2' buildToolsVersion '26.0.2'
defaultConfig { defaultConfig {
...@@ -13,6 +21,10 @@ android { ...@@ -13,6 +21,10 @@ android {
release { release {
minifyEnabled false minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFile '/root'
}
debug {
proguardFile '/root'
} }
} }
packagingOptions { packagingOptions {
......
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":42},"path":"app-release.apk","properties":{"packageId":"fr.utc.simde.jessy","split":"","minSdkVersion":"21"}}]
\ No newline at end of file
...@@ -2,11 +2,8 @@ package fr.utc.simde.jessy; ...@@ -2,11 +2,8 @@ package fr.utc.simde.jessy;
import android.Manifest; import android.Manifest;
import android.app.Activity; import android.app.Activity;
import android.app.AlarmManager;
import android.app.DownloadManager; import android.app.DownloadManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
...@@ -24,7 +21,6 @@ import android.util.Log; ...@@ -24,7 +21,6 @@ import android.util.Log;
import android.widget.TextView; import android.widget.TextView;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -33,8 +29,6 @@ import java.util.List; ...@@ -33,8 +29,6 @@ import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import fr.utc.simde.jessy.responses.BottomatikResponse;
import fr.utc.simde.jessy.tools.Bottomatik;
import fr.utc.simde.jessy.tools.CASConnexion; import fr.utc.simde.jessy.tools.CASConnexion;
import fr.utc.simde.jessy.tools.Config; import fr.utc.simde.jessy.tools.Config;
import fr.utc.simde.jessy.tools.Dialog; import fr.utc.simde.jessy.tools.Dialog;
...@@ -626,16 +620,41 @@ public abstract class BaseActivity extends InternetActivity { ...@@ -626,16 +620,41 @@ public abstract class BaseActivity extends InternetActivity {
}.start(); }.start();
} }
protected void setKey(final String name, final String key) { protected void setGingerKey(final String key) {
if (name.equals("") || key.equals("")) if (key.equals(""))
return; return;
SharedPreferences.Editor editor = sharedPreferences.edit(); dialog.startLoading(BaseActivity.this, getString(R.string.key_registration), getString(R.string.ginger_registering));
editor.putString("key_" + name, key);
editor.apply(); new Thread() {
@Override
public void run() {
try {
ginger.getInfo(nemopaySession.getUsername());
Thread.sleep(100);
if (name.equals("ginger")) runOnUiThread(new Runnable() {
ginger.setKey(key); @Override
public void run() {
dialog.stopLoading();
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("key_ginger", key);
editor.apply();
}
});
} catch (Exception e) {
Log.e(LOG_TAG, "error: " + e.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.errorDialog(BaseActivity.this, getString(R.string.key_registration), getString(R.string.ginger_error_registering));
}
});
}
}
}.start();
} }
protected boolean haveStoragePermission() { protected boolean haveStoragePermission() {
......
...@@ -116,27 +116,27 @@ public class FoundationsOptionsActivity extends BaseActivity { ...@@ -116,27 +116,27 @@ public class FoundationsOptionsActivity extends BaseActivity {
this.optionList.setOnItemClickListener(new AdapterView.OnItemClickListener() { this.optionList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) { public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
if (isOption(position,0)) { if (isOption(position, 0)) {
nemopaySession.setFoundation(-1, "", -1); nemopaySession.setFoundation(-1, "", -1);
startActivity(new Intent(FoundationsOptionsActivity.this, BuyerInfoActivity.class)); startActivity(new Intent(FoundationsOptionsActivity.this, BuyerInfoActivity.class));
} }
else if (isOption(position,1)) else if (isOption(position, 1))
editDialog(); editDialog();
else if (isOption(position,2)) else if (isOption(position, 2))
dialog.infoDialog(FoundationsOptionsActivity.this, "Non encore fait", "Pour la version 0.12"); editDialog();
else if (isOption(position,3)) else if (isOption(position, 3))
dialog.infoDialog(FoundationsOptionsActivity.this, "Non encore fait", "Pour la version 0.12");
else if (isOption(position,4))
startQRCodeReaderActivity(FoundationsOptionsActivity.this); startQRCodeReaderActivity(FoundationsOptionsActivity.this);
else if (isOption(position,5)) else if (isOption(position, 4))
startCardManagementActivity(FoundationsOptionsActivity.this); startCardManagementActivity(FoundationsOptionsActivity.this);
else if (isOption(position,6)) else if (isOption(position, 5))
keyNemopayDialog(); keyNemopayDialog();
else if (isOption(position,7)) else if (isOption(position, 6))
keyGingerDialog();
else if (isOption(position, 7))
keyEditDialog(); keyEditDialog();
else if (isOption(position,8)) else if (isOption(position, 8))
checkUpdate(); checkUpdate();
else if (isOption(position,9)) else if (isOption(position, 9))
creditDialog(); creditDialog();
else else
configDialog(); configDialog();
...@@ -150,22 +150,46 @@ public class FoundationsOptionsActivity extends BaseActivity { ...@@ -150,22 +150,46 @@ public class FoundationsOptionsActivity extends BaseActivity {
hasRights(getString(R.string.nemopay), new String[]{}, new Runnable(){ hasRights(getString(R.string.nemopay), new String[]{}, new Runnable(){
@Override @Override
public void run() { public void run() {
final View keyView = getLayoutInflater().inflate(R.layout.dialog_edit_key, null); final View keyView = getLayoutInflater().inflate(R.layout.dialog_key_edit, null);
final EditText keyInput = keyView.findViewById(R.id.input_key); 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); final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(FoundationsOptionsActivity.this);
alertDialogBuilder alertDialogBuilder
.setTitle(getString(R.string.key_registration) + " " + getString(R.string.nemopay)) .setTitle(getString(R.string.key_registration) + " " + getString(R.string.nemopay))
.setView(keyView) .setView(keyView)
.setCancelable(false) .setCancelable(false)
.setPositiveButton(R.string.register, new DialogInterface.OnClickListener() { .setPositiveButton(R.string.register, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) { public void onClick(DialogInterface dialogInterface, int id) {
if (!keyInput.getText().toString().equals("")) if (!keyInput.getText().toString().equals(""))
setNemopayKey(keyInput.getText().toString()); setNemopayKey(keyInput.getText().toString());
} }
}) })
.setNegativeButton(R.string.cancel, null); .setNegativeButton(R.string.cancel, null);
dialog.createDialog(alertDialogBuilder, keyInput);
}
});
}
protected void keyGingerDialog() {
hasRights(getString(R.string.nemopay), new String[]{}, new Runnable(){
@Override
public void run() {
final View keyView = getLayoutInflater().inflate(R.layout.dialog_key_edit, 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.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);
dialog.createDialog(alertDialogBuilder, keyInput); dialog.createDialog(alertDialogBuilder, keyInput);
} }
...@@ -176,8 +200,9 @@ public class FoundationsOptionsActivity extends BaseActivity { ...@@ -176,8 +200,9 @@ public class FoundationsOptionsActivity extends BaseActivity {
hasRights(getString(R.string.key_registration), new String[]{}, new Runnable(){ hasRights(getString(R.string.key_registration), new String[]{}, new Runnable(){
@Override @Override
public void run() { public void run() {
final View keyView = getLayoutInflater().inflate(R.layout.dialog_edit_key, null); final View keyView = getLayoutInflater().inflate(R.layout.dialog_key_set, null);
final EditText nameInput = keyView.findViewById(R.id.input_name); final EditText nameInput = keyView.findViewById(R.id.input_name);
final EditText urlInput = keyView.findViewById(R.id.input_url);
final EditText keyInput = keyView.findViewById(R.id.input_key); final EditText keyInput = keyView.findViewById(R.id.input_key);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(FoundationsOptionsActivity.this); final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(FoundationsOptionsActivity.this);
...@@ -187,8 +212,8 @@ public class FoundationsOptionsActivity extends BaseActivity { ...@@ -187,8 +212,8 @@ public class FoundationsOptionsActivity extends BaseActivity {
.setCancelable(false) .setCancelable(false)
.setPositiveButton(R.string.register, new DialogInterface.OnClickListener() { .setPositiveButton(R.string.register, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) { public void onClick(DialogInterface dialogInterface, int id) {
if (!nameInput.getText().toString().equals("") || !keyInput.getText().toString().equals("")) if (!nameInput.getText().toString().equals(""))
setKey(nameInput.getText().toString(), keyInput.getText().toString()); config.setApi(nameInput.getText().toString(), urlInput.getText().toString(), keyInput.getText().toString());
} }
}) })
.setNegativeButton(R.string.cancel, null); .setNegativeButton(R.string.cancel, null);
......
...@@ -23,7 +23,6 @@ import java.util.Date; ...@@ -23,7 +23,6 @@ import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.Locale; import java.util.Locale;
import fr.utc.simde.jessy.tools.Bottomatik;
import fr.utc.simde.jessy.tools.CASConnexion; import fr.utc.simde.jessy.tools.CASConnexion;
import fr.utc.simde.jessy.tools.Config; import fr.utc.simde.jessy.tools.Config;
import fr.utc.simde.jessy.tools.Ginger; import fr.utc.simde.jessy.tools.Ginger;
...@@ -449,7 +448,7 @@ public class MainActivity extends BaseActivity { ...@@ -449,7 +448,7 @@ public class MainActivity extends BaseActivity {
} }
protected void keyDialog() { protected void keyDialog() {
final View keyView = getLayoutInflater().inflate(R.layout.dialog_add_key, null); final View keyView = getLayoutInflater().inflate(R.layout.dialog_key_add, null);
final EditText nameInput = keyView.findViewById(R.id.input_name); final EditText nameInput = keyView.findViewById(R.id.input_name);
final EditText descriptionInput = keyView.findViewById(R.id.input_description); final EditText descriptionInput = keyView.findViewById(R.id.input_description);
final String date = new SimpleDateFormat("yyyy/MM/dd", Locale.FRANCE).format(new Date()); final String date = new SimpleDateFormat("yyyy/MM/dd", Locale.FRANCE).format(new Date());
...@@ -504,7 +503,7 @@ public class MainActivity extends BaseActivity { ...@@ -504,7 +503,7 @@ public class MainActivity extends BaseActivity {
} }
protected void optionDialog() { protected void optionDialog() {
final View keyView = getLayoutInflater().inflate(R.layout.dialog_edit_key, null); final View keyView = getLayoutInflater().inflate(R.layout.dialog_key_set, null);
final EditText keyInput = keyView.findViewById(R.id.input_key); final EditText keyInput = keyView.findViewById(R.id.input_key);
keyView.findViewById(R.id.input_name).setVisibility(View.GONE); keyView.findViewById(R.id.input_name).setVisibility(View.GONE);
......
package fr.utc.simde.jessy.responses; package fr.utc.simde.jessy.responses;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import java.util.Map;
/** /**
* Created by Samy on 10/11/2017. * Created by Samy on 10/11/2017.
*/ */
@JsonIgnoreProperties(ignoreUnknown = true)
public class APIResponse { public class APIResponse {
@JsonIgnoreProperties(ignoreUnknown = true)
public class APICommand {
// Informations nécessaires
protected String command;
// Informations complémentaires
protected String name;
protected String description;
protected Map<String, String> arguments;
public String getCommand() { return command; }
public String getName() { return name; }
public String getDescription() { return description; }
public Map<String, String> getArguments() { return arguments; }
}
// Informations nécessaires
protected String id; protected String id;
protected String username; protected String username;
protected String type; // Informations complémentaires
protected long creation_date; protected Long creationDate;
protected long expires_at; protected Long expirationDate;
// Affiche soit un message, soit une liste de données rangée par catégorie
protected String message;
protected Map<String, Map<String, String>> data;
// Permet d'exécuter des commandes suites à l'affichage (rien d'obligatoire mais button Ok par défaut)
protected APICommand neutralCommand;
protected APICommand negativeCommand;
protected APICommand positiveCommand;
public String getId() { return this.id; } public String getId() { return this.id; }
public String getUsername() { return this.username; } public String getUsername() { return this.username; }
public String getType() { return this.type; } public String getMessage() { return message; }
public long getCreation_date() { return this.creation_date; } public Map<String, Map<String, String>> getData() { return this.data; }
public long getExpires_at() { return this.expires_at; } public Long getCreationDate() { return this.creationDate; }
public Long getExpirationDate() { return this.expirationDate; }
public void removeExpirationDate() { this.expirationDate = null; }
public APICommand getNeutralCommand() { return neutralCommand; }
public APICommand getNegativeCommand() { return negativeCommand; }
public APICommand getPositiveCommand() { return positiveCommand; }
} }
package fr.utc.simde.jessy.responses; package fr.utc.simde.jessy.responses;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -10,15 +11,16 @@ import java.util.List; ...@@ -10,15 +11,16 @@ import java.util.List;
* Created by Samy on 10/11/2017. * Created by Samy on 10/11/2017.
*/ */
@JsonIgnoreProperties(ignoreUnknown = true)
public class BottomatikResponse extends APIResponse { public class BottomatikResponse extends APIResponse {
protected String _id; protected String _id;
protected Integer fun_id; protected Integer funId;
protected boolean paid; protected boolean paid;
protected boolean validated; protected boolean validated;
protected List<List<String>> articles; protected List<List<String>> articles;
public String get_id() { return this._id; } public String get_id() { return this._id; }
public Integer getFun_id() { return this.fun_id; } public Integer getFunId() { return this.funId; }
public boolean isPaid() { return this.paid; } public boolean isPaid() { return this.paid; }
public boolean isValidated() { return this.validated; } public boolean isValidated() { return this.validated; }
public List<List<String>> getArticles() { return this.articles; } public List<List<String>> getArticles() { return this.articles; }
......
package fr.utc.simde.jessy.responses;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Created by Samy on 10/11/2017.
*/
public class ReservationResponse extends APIResponse {
protected Integer reservation_id;
protected String seance;
public Integer getReservation_id() { return this.reservation_id; }
public String getSeance() { return this.seance; }
}
...@@ -2,6 +2,9 @@ package fr.utc.simde.jessy.tools; ...@@ -2,6 +2,9 @@ package fr.utc.simde.jessy.tools;
import android.app.Activity; import android.app.Activity;
import com.fasterxml.jackson.databind.node.ArrayNode;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -48,18 +51,15 @@ public class API { ...@@ -48,18 +51,15 @@ public class API {
public HTTPRequest getRequest() { return this.request; } public HTTPRequest getRequest() { return this.request; }
public int validate(final String id) throws Exception { public int interact(final String id, final String command) throws Exception {
return request( return request(
id + "/validate" id + "/" + command
); );
} }
public int validate(final String id, final boolean paid, final boolean served) throws Exception { public int interact(final String id, final String command, Map<String, Object> postArgs) throws Exception {
return request( return request(
id + "/validate", id + "/" + command,
new HashMap<String, Object>() {{ postArgs
put("paid", paid);
put("served", served);
}}
); );
} }
...@@ -88,7 +88,7 @@ public class API { ...@@ -88,7 +88,7 @@ public class API {
responseCode = this.request.get(); responseCode = this.request.get();
else { else {
this.request.setPost(postArgs); this.request.setPost(postArgs);
responseCode = this.request.post(); responseCode = this.request.post(false);
} }
if (responseCode == 200) if (responseCode == 200)
......
package fr.utc.simde.jessy.tools;
import android.app.Activity;
import android.util.Log;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import fr.utc.simde.jessy.R;
/**
* Created by Samy on 21/11/2017.
*/
public class Bottomatik {
private static final String LOG_TAG = "_Bottomatik";
private static final String url = "https://picasso.bottomatik.com/bot/transactions/";
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 Bottomatik(final Activity activity) {
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);