diff --git a/app/build.gradle b/app/build.gradle index 6569b5e..2a144f5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,6 +12,13 @@ android { testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { + + debug { + buildConfigField "String", "api_url", "\"http://devweb.local/comunic/api/\"" + buildConfigField "String", "api_service_name", "testService" + buildConfigField "String", "api_service_token", "testPasswd" + } + release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6b756d3..dff6697 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,12 @@ + + + + + + parameters; + + /** + * The URI on the server + */ + private String request_uri; + + /** + * The class constructor + * + * @param uri The request URI on the server + */ + APIParameters(String uri){ + //Save request URI + request_uri = uri; + + //Intializate parametres array + parameters = new ArrayList<>(); + } + + /** + * Add a new parameter to the request + * + * @param name The name of the new key + * @param value The value of the new key + */ + void addParameter(String name, String value){ + parameters.add(new APIPostData(name, value)); + } + +} diff --git a/app/src/main/java/org/communiquons/android/comunic/client/APIPostData.java b/app/src/main/java/org/communiquons/android/comunic/client/APIPostData.java new file mode 100644 index 0000000..27eb401 --- /dev/null +++ b/app/src/main/java/org/communiquons/android/comunic/client/APIPostData.java @@ -0,0 +1,57 @@ +package org.communiquons.android.comunic.client; + +import java.net.URLEncoder; + +/** + * This class stores on parameter for a POST request + * + * Created by pierre on 10/31/17. + */ + +class APIPostData { + + /** + * The name of the key + */ + private String key_name; + + /** + * The value of the key + */ + private String key_value; + + /** + * Public constructor of the class + * + * @param name The name of the parameter + * @param value The value of the parameter + */ + APIPostData(String name, String value){ + key_name = name; + key_value = value; + } + + /** + * Get the the name and the value of the key in an encoded form + * + * @return The result + */ + String get_encoded(){ + + String encoded_key; + String encoded_value; + + try { + encoded_key = URLEncoder.encode(key_name, "UTF-8"); + encoded_value = URLEncoder.encode(key_value, "UTF-8"); + } catch (java.io.UnsupportedEncodingException e){ + e.printStackTrace(); + + return ""; + } + + //Return result + return encoded_key + "&" + encoded_value; + } + +} diff --git a/app/src/main/java/org/communiquons/android/comunic/client/APIRequestTask.java b/app/src/main/java/org/communiquons/android/comunic/client/APIRequestTask.java new file mode 100644 index 0000000..4fcddb0 --- /dev/null +++ b/app/src/main/java/org/communiquons/android/comunic/client/APIRequestTask.java @@ -0,0 +1,15 @@ +package org.communiquons.android.comunic.client; + +import android.os.AsyncTask; + +import org.json.JSONObject; + +/** + * Created by pierre on 10/31/17. + */ + +abstract class APIRequestTask extends AsyncTask { + + + +} diff --git a/app/src/main/java/org/communiquons/android/comunic/client/LoginActivity.java b/app/src/main/java/org/communiquons/android/comunic/client/LoginActivity.java index 10da188..d7c82be 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/LoginActivity.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/LoginActivity.java @@ -2,12 +2,68 @@ package org.communiquons.android.comunic.client; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.view.View; +import android.widget.EditText; +import android.widget.Toast; public class LoginActivity extends AppCompatActivity { + /** + * Utilities object + */ + private Utilities utils; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); + + //Create utilities object + utils = new Utilities(this); + + //Make login submit button lives + findViewById(R.id.login_submit).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + //Submit login form + submitLogin(); + + } + }); + + + } + + /** + * Handle login form submission + */ + void submitLogin(){ + + //Get the fields + EditText login_mail = (EditText) findViewById(R.id.email_field); + EditText login_password = (EditText) findViewById(R.id.password_field); + + int stop = 0; + + //Check password + if(login_password.length()<3){ + login_password.setError(getString(R.string.activity_login_err_invalid_password)); + login_password.requestFocus(); + stop = 1; + } + + //Check email address + if(login_mail.length() < 3 || !utils.isValidMail(login_mail.getText())){ + login_mail.setError(getString(R.string.activity_login_err_invalid_email)); + login_mail.requestFocus(); + stop = 1; + } + + //Stop if required + if(stop != 0) + return; + + } } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/Utilities.java b/app/src/main/java/org/communiquons/android/comunic/client/Utilities.java index ddae22d..7de5149 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/Utilities.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/Utilities.java @@ -1,7 +1,9 @@ package org.communiquons.android.comunic.client; import android.content.Context; +import android.text.TextUtils; import android.util.Log; +import android.util.Patterns; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -91,4 +93,14 @@ class Utilities { //Success return true; } + + /** + * Check whether a specified email address is valid or not + * + * @param mail The E-Mail address to check + * @return True if the mail is valid / false else + */ + boolean isValidMail(CharSequence mail){ + return !TextUtils.isEmpty(mail) && Patterns.EMAIL_ADDRESS.matcher(mail).matches(); + } } diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 3da19c1..0f2d98d 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -65,6 +65,7 @@