mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-23 13:59:29 +00:00
Made login activity more modern
This commit is contained in:
parent
eed86ea221
commit
22c51480a6
@ -1,8 +1,9 @@
|
||||
package org.communiquons.android.comunic.client.ui.activities;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ProgressBar;
|
||||
@ -11,7 +12,6 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.communiquons.android.comunic.client.R;
|
||||
import org.communiquons.android.comunic.client.data.asynctasks.APIRequestTask;
|
||||
import org.communiquons.android.comunic.client.data.helpers.APIRequestHelper;
|
||||
import org.communiquons.android.comunic.client.data.helpers.AccountHelper;
|
||||
import org.communiquons.android.comunic.client.data.models.APIRequest;
|
||||
@ -45,6 +45,8 @@ public class LoginActivity extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_login);
|
||||
assert getSupportActionBar() != null;
|
||||
getSupportActionBar().hide();
|
||||
|
||||
//Create utilities object
|
||||
utils = new Utilities(this);
|
||||
@ -84,8 +86,8 @@ public class LoginActivity extends AppCompatActivity {
|
||||
void submitLogin(){
|
||||
|
||||
//Get the fields
|
||||
final EditText login_mail = (EditText) findViewById(R.id.email_field);
|
||||
EditText login_password = (EditText) findViewById(R.id.password_field);
|
||||
EditText login_mail = findViewById(R.id.email_field);
|
||||
EditText login_password = findViewById(R.id.password_field);
|
||||
|
||||
|
||||
int stop = 0;
|
||||
@ -120,40 +122,79 @@ public class LoginActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
//Perform a request on the API to check user credentials and get login tokens
|
||||
APIRequest params = new APIRequest(this, "user/connectUSER");
|
||||
final APIRequest params = new APIRequest(this, "user/connectUSER");
|
||||
params.addString("userMail", ""+login_mail.getText());
|
||||
params.addString("userPassword", ""+login_password.getText());
|
||||
|
||||
//Create Request
|
||||
new APIRequestTask(){
|
||||
new Thread(new SubmitLoginRequest(params)).start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runnable used to submit login request and retrieve login tokens
|
||||
*/
|
||||
private class SubmitLoginRequest implements Runnable {
|
||||
|
||||
private APIRequest mRequest;
|
||||
|
||||
SubmitLoginRequest(APIRequest request){
|
||||
mRequest = request;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(APIResponse result) {
|
||||
public void run() {
|
||||
|
||||
//Check for errors
|
||||
if(result == null) {
|
||||
APIResponse response = null;
|
||||
try {
|
||||
response = new APIRequestHelper().exec(mRequest);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(!isFinishing()){
|
||||
findViewById(R.id.email_field).post(new ServerResponseRunnable(response));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runnable used on the UI Thread to pre-process server response
|
||||
*/
|
||||
private class ServerResponseRunnable implements Runnable {
|
||||
|
||||
private APIResponse mResponse;
|
||||
|
||||
ServerResponseRunnable(APIResponse response){
|
||||
mResponse = response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
handle_server_response(mResponse);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle server response
|
||||
*
|
||||
* @param response The server response
|
||||
*/
|
||||
void handle_server_response(@Nullable APIResponse response){
|
||||
|
||||
if(response == null){
|
||||
//Hide loading wheel
|
||||
enter_loading_state(false);
|
||||
|
||||
//Put the error on the login mail field
|
||||
show_form_error(getString(R.string.activity_login_err_invalid_credentials));
|
||||
return;
|
||||
}
|
||||
|
||||
else
|
||||
//Perform next actions
|
||||
handle_server_response(result);
|
||||
|
||||
}
|
||||
}.execute(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle server responses that seems to accept a response
|
||||
*
|
||||
* @param response The server reponse
|
||||
*/
|
||||
void handle_server_response(APIResponse response){
|
||||
|
||||
JSONObject data = response.getJSONObject();
|
||||
|
||||
//Check for decoding response errors
|
||||
@ -214,12 +255,12 @@ public class LoginActivity extends AppCompatActivity {
|
||||
/**
|
||||
* Switch between loading state and ready state for the login form
|
||||
*
|
||||
* @param show_progress Specify wether a progress bar should be shown or not
|
||||
* @param show_progress Specify whether a progress bar should be shown or not
|
||||
*/
|
||||
void enter_loading_state(boolean show_progress){
|
||||
//Grab elements
|
||||
ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress_bar);
|
||||
ScrollView login_form = (ScrollView) findViewById(R.id.login_form);
|
||||
ProgressBar progressBar = findViewById(R.id.progress_bar);
|
||||
ScrollView login_form = findViewById(R.id.login_form);
|
||||
|
||||
progressBar.setVisibility(show_progress ? View.VISIBLE : View.GONE);
|
||||
login_form.setVisibility(show_progress ? View.GONE : View.VISIBLE);
|
||||
@ -233,7 +274,7 @@ public class LoginActivity extends AppCompatActivity {
|
||||
void show_form_error(String message){
|
||||
|
||||
//Retrieve error field
|
||||
TextView v_error = (TextView) findViewById(R.id.login_error_message);
|
||||
TextView v_error = findViewById(R.id.login_error_message);
|
||||
|
||||
//Check what to do
|
||||
boolean display = message.length() > 0;
|
||||
|
9
app/src/main/res/drawable/activity_login_bg.xml
Normal file
9
app/src/main/res/drawable/activity_login_bg.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<gradient
|
||||
android:angle="135"
|
||||
android:centerColor="#3f51b5"
|
||||
android:endColor="#283593"
|
||||
android:startColor="#7986cb"
|
||||
android:type="linear" />
|
||||
</shape>
|
@ -2,8 +2,8 @@
|
||||
android:shape="rectangle">
|
||||
<gradient
|
||||
android:angle="135"
|
||||
android:centerColor="#009688"
|
||||
android:endColor="#00695C"
|
||||
android:startColor="#4DB6AC"
|
||||
android:centerColor="#3f51b5"
|
||||
android:endColor="#283593"
|
||||
android:startColor="#7986cb"
|
||||
android:type="linear" />
|
||||
</shape>
|
@ -1,30 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:orientation="vertical"
|
||||
android:background="@drawable/activity_login_bg"
|
||||
tools:context="org.communiquons.android.comunic.client.ui.activities.LoginActivity">
|
||||
|
||||
<!-- Login form -->
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:text="@string/app_name"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@android:color/background_light"
|
||||
android:textSize="24sp" />
|
||||
|
||||
<!-- Login loading progress -->
|
||||
<ProgressBar
|
||||
android:id="@+id/progress_bar"
|
||||
style="?android:attr/progressBarStyleLarge"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_centerVertical="true"
|
||||
android:scrollbarAlwaysDrawVerticalTrack="false"
|
||||
android:visibility="gone" />
|
||||
|
||||
<!-- Login form -->
|
||||
<ScrollView
|
||||
android:id="@+id/login_form"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_centerVertical="true">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@ -37,22 +55,24 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAlignment="center"
|
||||
android:textColor="#FF2222"
|
||||
tools:text="Error content"
|
||||
android:visibility="gone"/>
|
||||
android:textColor="@color/colorAccent"
|
||||
android:textStyle="bold"
|
||||
android:visibility="gone"
|
||||
tools:text="Error content" />
|
||||
|
||||
<!-- Email field -->
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/LoginInput">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/email_field"
|
||||
style="@style/LoginInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/activity_login_email_hint"
|
||||
android:inputType="textEmailAddress"
|
||||
/>
|
||||
android:inputType="textEmailAddress" />
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
@ -60,7 +80,8 @@
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp">
|
||||
android:layout_marginTop="8dp"
|
||||
style="@style/LoginInput">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/password_field"
|
||||
@ -68,7 +89,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/activity_login_password_hint"
|
||||
android:inputType="textPassword"
|
||||
/>
|
||||
style="@style/LoginInput" />
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
@ -85,4 +106,4 @@
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<resources>
|
||||
<color name="colorPrimary">#3F51B5</color>
|
||||
<color name="colorPrimaryDark">#303F9F</color>
|
||||
<color name="colorAccent">#FF4081</color>
|
||||
<color name="colorAccent">#ff4081</color>
|
||||
|
||||
<color name="holo_green_dark">#ff669900</color>
|
||||
<color name="darker_gray">#aaa</color>
|
||||
|
@ -12,6 +12,15 @@
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
|
||||
<!-- Login activity -->
|
||||
<style name="LoginInput">
|
||||
<item name="android:textColor">@android:color/white</item>
|
||||
<item name="android:textColorHint">@android:color/white</item>
|
||||
<item name="android:textColorLink">@android:color/white</item>
|
||||
<item name="android:textColorHighlight">@android:color/white</item>
|
||||
</style>
|
||||
|
||||
<!-- User page fragment -->
|
||||
<!-- User page header -->
|
||||
<style name="UserPageHeader">
|
||||
|
Loading…
Reference in New Issue
Block a user