diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 4f4bc9a..d504afa 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -25,6 +25,7 @@
+
\ No newline at end of file
diff --git a/app/src/main/java/com/speculos/myapplicationoc/ClientAlreadyExistConfirmation.java b/app/src/main/java/com/speculos/myapplicationoc/ClientAlreadyExistConfirmation.java
new file mode 100644
index 0000000..592d54c
--- /dev/null
+++ b/app/src/main/java/com/speculos/myapplicationoc/ClientAlreadyExistConfirmation.java
@@ -0,0 +1,179 @@
+package com.speculos.myapplicationoc;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.os.StrictMode;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import androidx.annotation.Nullable;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+import okhttp3.MediaType;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import okhttp3.Response;
+
+public class ClientAlreadyExistConfirmation extends Activity {
+
+ String hexa_id, mail, srvURL;
+ float solde, idClient;
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ // Tweak pour contourner l'erreur android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork
+ StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
+ StrictMode.setThreadPolicy(policy);
+
+ // recuperation de MyApplication contenant les variables globales
+ MyApplication myApplication = (MyApplication) getApplication();
+ srvURL = myApplication.getServerURL();
+
+ setContentView(R.layout.activity_client_exist_confirmation);
+
+ hexa_id = getIntent().getStringExtra("hexa_id");
+
+ if (hexa_id == null) {
+ // TODO: afficher une erreur manque hexa_id
+ Toast.makeText(ClientAlreadyExistConfirmation.this, "Hexa_id non trouvé", Toast.LENGTH_LONG).show();
+ finish();
+ }
+
+ mail = getIntent().getStringExtra("mail");
+
+ /* Initialisation des info client*/
+ // Call API info client à partir du bracelet
+ String stringAPI = "";
+
+ try {
+
+ OkHttpClient client = new OkHttpClient().newBuilder()
+ .connectTimeout(2000, TimeUnit.MILLISECONDS)
+ .callTimeout(2000, TimeUnit.MILLISECONDS)
+ .build();
+ Request request = new Request.Builder()
+ .url(srvURL + "/api/clients.json?email=" + mail)
+ .method("GET", null)
+ .addHeader("Content-Type", "application/json")
+ .build();
+ Response response = client.newCall(request).execute();
+
+ String in = response.body().string();
+ in = in.substring(1, in.length() - 1); // on retire le [] autour de notre json premier et dernier char
+ Log.d("API-debug-in", in);
+
+ JSONObject jsonObject = null;
+
+ try {
+ jsonObject = new JSONObject(in);
+ Log.d("API-debug", "json: "+ jsonObject.toString());
+ // jsonObject = new JSONObject(jsonObject.get("client").toString()); // recup client embed dans l'objet parent
+ } catch (JSONException e) {
+ Log.d("API-debug", e.getMessage());
+ }
+
+
+ String mail = null;
+ mail = jsonObject.getString("email");
+ solde = Float.parseFloat(jsonObject.getString("solde"));
+
+ idClient = Float.parseFloat(jsonObject.getString("id"));
+
+ TextView value_mail = findViewById(R.id.value_mail);
+ value_mail.setText(mail);
+
+ JSONArray jsonBracelets = new JSONArray(jsonObject.get("bracelets").toString());
+ Log.d("API-debug", "NBBRACELETS: " + jsonBracelets.length());
+
+ int nbBracelets = jsonBracelets.length();
+ if (nbBracelets > 0) {
+ TextView textNbBracelets = findViewById(R.id.textNbBracelets);
+
+ // 1 bracelet
+ textNbBracelets.setText("avec " + nbBracelets + " bracelet");
+ // plusieurs bracelets
+ if (nbBracelets > 1)
+ textNbBracelets.setText("avec " + nbBracelets + " bracelets");
+
+ } else {
+ TextView textNbBracelets = findViewById(R.id.textNbBracelets);
+ textNbBracelets.setText("sans bracelet");
+ }
+
+
+ } catch (IOException | JSONException e) {
+ e.printStackTrace();
+ Log.d("API-debug-exception", e.getMessage());
+ Toast.makeText(ClientAlreadyExistConfirmation.this, e.getMessage(), Toast.LENGTH_LONG).show();
+ finish();
+ }
+
+ TextView value_solde = findViewById(R.id.value_solde);
+ value_solde.setText(solde + " €");
+
+ // Bouton de confirmation d'enregistrement
+ Button button_enregistrer = findViewById(R.id.button_enregistrer);
+
+ button_enregistrer.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ // Requête ajout du bracelet au compte
+
+ // On peut maintenant link le bracelet grace à l'hexa_id et l'idClient
+ try {
+
+ OkHttpClient client = new OkHttpClient().newBuilder()
+ .build();
+ MediaType mediaType = MediaType.parse("application/json");
+ RequestBody body = RequestBody.create(mediaType, "{\"nfcId\": \"" + hexa_id + "\",\"client\": \"/api/clients/" + idClient + "\",\"state\": 0}");
+ Request request = new Request.Builder()
+ .url(srvURL + "/api/bracelets")
+ .method("POST", body)
+ .addHeader("Content-Type", "application/json")
+ .build();
+ Response responseHttp = client.newCall(request).execute();
+
+ if (responseHttp.code() == 400) {
+ try {
+ JSONObject jsonReader = null;
+ jsonReader = new JSONObject(responseHttp.body().string());
+ Log.d("JSON-MSG", "violations: " + jsonReader.getJSONArray("violations").getString(0));
+ Toast.makeText(ClientAlreadyExistConfirmation.this, "violations: " + jsonReader.getJSONArray("violations").getString(0), Toast.LENGTH_LONG).show();
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ }
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ finish();
+ }
+ });
+
+ // Bouton de retour
+ Button button_retour = findViewById(R.id.button_non);
+
+ button_retour.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ finish();
+
+ }
+ });
+
+ }
+}
diff --git a/app/src/main/java/com/speculos/myapplicationoc/MyApplication.java b/app/src/main/java/com/speculos/myapplicationoc/MyApplication.java
index 404b5f6..900c8f9 100644
--- a/app/src/main/java/com/speculos/myapplicationoc/MyApplication.java
+++ b/app/src/main/java/com/speculos/myapplicationoc/MyApplication.java
@@ -1,12 +1,12 @@
-package com.speculos.myapplicationoc;
-
-import android.app.Application;
-
-public class MyApplication extends Application {
-
- private String serverURL = "http://art-dev:8080";
-
- public String getServerURL(){
- return serverURL;
- }
-}
+package com.speculos.myapplicationoc;
+
+import android.app.Application;
+
+public class MyApplication extends Application {
+
+ private String serverURL = "http://192.168.1.72:8080";
+
+ public String getServerURL(){
+ return serverURL;
+ }
+}
diff --git a/app/src/main/java/com/speculos/myapplicationoc/TagDetectedActivityAdmin.java b/app/src/main/java/com/speculos/myapplicationoc/TagDetectedActivityAdmin.java
index 3517490..65ca1d5 100644
--- a/app/src/main/java/com/speculos/myapplicationoc/TagDetectedActivityAdmin.java
+++ b/app/src/main/java/com/speculos/myapplicationoc/TagDetectedActivityAdmin.java
@@ -1,6 +1,7 @@
package com.speculos.myapplicationoc;
import android.app.Activity;
+import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
@@ -181,7 +182,12 @@ public class TagDetectedActivityAdmin extends Activity {
} else {
// Le mail est déjà present en base
- Toast.makeText(TagDetectedActivityAdmin.this, "Le mail est déjà présent en base. Souhaitez vous ajouter ce bracelet au compte: " + mail, Toast.LENGTH_LONG).show();
+ // TODO: rediriger vers une vue de confirmation
+ // Toast.makeText(TagDetectedActivityAdmin.this, "Le mail est déjà présent en base. Souhaitez vous ajouter ce bracelet au compte: " + mail, Toast.LENGTH_LONG).show();
+ Intent myIntent = new Intent(TagDetectedActivityAdmin.this, ClientAlreadyExistConfirmation.class);
+ myIntent.putExtra("hexa_id", hexa_id);
+ myIntent.putExtra("mail",mail);
+ startActivity(myIntent);
}
@@ -202,6 +208,5 @@ public class TagDetectedActivityAdmin extends Activity {
}
});
}
-
}
diff --git a/app/src/main/java/com/speculos/myapplicationoc/ThreadPing.java b/app/src/main/java/com/speculos/myapplicationoc/ThreadPing.java
index e42b6d1..62e757d 100644
--- a/app/src/main/java/com/speculos/myapplicationoc/ThreadPing.java
+++ b/app/src/main/java/com/speculos/myapplicationoc/ThreadPing.java
@@ -1,77 +1,77 @@
-package com.speculos.myapplicationoc;
-
-import java.io.IOException;
-
-import okhttp3.OkHttpClient;
-import okhttp3.Request;
-import okhttp3.Response;
-
-
-public class ThreadPing extends Thread {
-
- /* Ce ThreadPing n'est pas un "ping" à proprement parler
- * on réalise un call GET sur http://domain.dev/api
- * pour savoir si le serveur répond
- * */
-
- public static Boolean isReachable;
- private String url;
-
- // Constructeur
- public ThreadPing(String url) {
- this.url = url;
- }
-
- private int delay = 3000; // temps entre chaque ping 5sec
-
- private PingListener listen = null;
-
- public void addListener(PingListener listen) {
- this.listen = listen;
- }
-
- public void run() {
-
- while (true) {
- try {
- String apiResponse = "";
- try {
- OkHttpClient client = new OkHttpClient().newBuilder()
- .build();
- Request request = new Request.Builder()
- .url(url + "/api")
- .method("GET", null)
- .build();
- Response response = client.newCall(request).execute();
- apiResponse = response.body().toString();
-
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- if (apiResponse != "") {
-
- // Si PING OK declenche l'event ping(isReachable)
- isReachable = true;
- if (listen != null) listen.ping(isReachable);
-
- } else {
-
- isReachable = false;
- if (listen != null) listen.ping(isReachable);
-
- }
- } catch (Exception e) {
- System.out.println("Exception:" + e.getMessage());
-
- }
-
- try {
- sleep(delay);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- }
-}
+package com.speculos.myapplicationoc;
+
+import java.io.IOException;
+
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
+
+
+public class ThreadPing extends Thread {
+
+ /* Ce ThreadPing n'est pas un "ping" à proprement parler
+ * on réalise un call GET sur http://domain.dev/api
+ * pour savoir si le serveur répond
+ * */
+
+ public static Boolean isReachable;
+ private String url;
+
+ // Constructeur
+ public ThreadPing(String url) {
+ this.url = url;
+ }
+
+ private int delay = 3000; // temps entre chaque ping 5sec
+
+ private PingListener listen = null;
+
+ public void addListener(PingListener listen) {
+ this.listen = listen;
+ }
+
+ public void run() {
+
+ while (true) {
+ try {
+ String apiResponse = "";
+ try {
+ OkHttpClient client = new OkHttpClient().newBuilder()
+ .build();
+ Request request = new Request.Builder()
+ .url(url + "/api")
+ .method("GET", null)
+ .build();
+ Response response = client.newCall(request).execute();
+ apiResponse = response.body().toString();
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ if (apiResponse != "") {
+
+ // Si PING OK declenche l'event ping(isReachable)
+ isReachable = true;
+ if (listen != null) listen.ping(isReachable);
+
+ } else {
+
+ isReachable = false;
+ if (listen != null) listen.ping(isReachable);
+
+ }
+ } catch (Exception e) {
+ System.out.println("Exception:" + e.getMessage());
+
+ }
+
+ try {
+ sleep(delay);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ }
+}
diff --git a/app/src/main/res/layout/activity_client_exist_confirmation.xml b/app/src/main/res/layout/activity_client_exist_confirmation.xml
new file mode 100644
index 0000000..83fcaf3
--- /dev/null
+++ b/app/src/main/res/layout/activity_client_exist_confirmation.xml
@@ -0,0 +1,131 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 661e50a..575dc43 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Sun Apr 12 12:33:05 CEST 2020
-distributionBase=GRADLE_USER_HOME
-distributionPath=wrapper/dists
-zipStoreBase=GRADLE_USER_HOME
-zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
+#Sun Apr 12 12:33:05 CEST 2020
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
diff --git a/gradlew.bat b/gradlew.bat
index f955316..e95643d 100644
--- a/gradlew.bat
+++ b/gradlew.bat
@@ -1,84 +1,84 @@
-@if "%DEBUG%" == "" @echo off
-@rem ##########################################################################
-@rem
-@rem Gradle startup script for Windows
-@rem
-@rem ##########################################################################
-
-@rem Set local scope for the variables with windows NT shell
-if "%OS%"=="Windows_NT" setlocal
-
-set DIRNAME=%~dp0
-if "%DIRNAME%" == "" set DIRNAME=.
-set APP_BASE_NAME=%~n0
-set APP_HOME=%DIRNAME%
-
-@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-set DEFAULT_JVM_OPTS=
-
-@rem Find java.exe
-if defined JAVA_HOME goto findJavaFromJavaHome
-
-set JAVA_EXE=java.exe
-%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto init
-
-echo.
-echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:findJavaFromJavaHome
-set JAVA_HOME=%JAVA_HOME:"=%
-set JAVA_EXE=%JAVA_HOME%/bin/java.exe
-
-if exist "%JAVA_EXE%" goto init
-
-echo.
-echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:init
-@rem Get command-line arguments, handling Windows variants
-
-if not "%OS%" == "Windows_NT" goto win9xME_args
-
-:win9xME_args
-@rem Slurp the command line arguments.
-set CMD_LINE_ARGS=
-set _SKIP=2
-
-:win9xME_args_slurp
-if "x%~1" == "x" goto execute
-
-set CMD_LINE_ARGS=%*
-
-:execute
-@rem Setup the command line
-
-set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
-
-@rem Execute Gradle
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
-
-:end
-@rem End local scope for the variables with windows NT shell
-if "%ERRORLEVEL%"=="0" goto mainEnd
-
-:fail
-rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
-rem the _cmd.exe /c_ return code!
-if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
-exit /b 1
-
-:mainEnd
-if "%OS%"=="Windows_NT" endlocal
-
-:omega
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega