diff --git a/app/build.gradle b/app/build.gradle index 558c76a..93c3447 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -76,5 +76,7 @@ dependencies { // spinner loaders library implementation 'com.github.ybq:Android-SpinKit:1.2.0' // rx binding - implementation 'com.jakewharton.rxbinding:rxbinding:0.3.0' + implementation 'com.jakewharton.rxbinding:rxbinding:0.4.0' + implementation 'com.jakewharton.rxbinding:rxbinding-appcompat-v7:0.4.0' + implementation 'com.jakewharton.rxbinding:rxbinding-support-v4:0.4.0' } diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java index d49dc60..1823b50 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/LoginActivity.java @@ -10,24 +10,24 @@ import android.os.Bundle; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; +import android.util.Log; import android.view.View; import android.view.inputmethod.EditorInfo; -import android.widget.AutoCompleteTextView; import android.widget.Button; import android.widget.EditText; import com.auth0.android.jwt.Claim; import com.auth0.android.jwt.JWT; import com.jakewharton.retrofit2.adapter.rxjava2.HttpException; +import com.jakewharton.rxbinding.widget.RxTextView; +import com.jakewharton.rxbinding.widget.TextViewTextChangeEvent; import com.uam.wmi.findmytutor.R; import com.uam.wmi.findmytutor.model.JwtToken; -import com.uam.wmi.findmytutor.model.LdapUser; import com.uam.wmi.findmytutor.model.User; import com.uam.wmi.findmytutor.model.ValidateUser; import com.uam.wmi.findmytutor.network.ApiClient; import com.uam.wmi.findmytutor.service.LdapService; import com.uam.wmi.findmytutor.service.UserService; -import com.uam.wmi.findmytutor.utils.MapUtils; import com.uam.wmi.findmytutor.utils.PrefUtils; import com.uam.wmi.findmytutor.utils.RestApiHelper; @@ -35,6 +35,8 @@ import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; +import butterknife.BindView; +import butterknife.ButterKnife; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.schedulers.Schedulers; @@ -42,7 +44,13 @@ import okhttp3.ResponseBody; public class LoginActivity extends AppCompatActivity { - private AutoCompleteTextView mLoginNameView; + @BindView(R.id.password) + EditText password; + @BindView(R.id.email) + EditText email; + @BindView(R.id.email_sign_in_button) + Button sign_in_button; + private EditText mLoginNameView; private EditText mPasswordView; private View mProgressView; private View mLoginFormView; @@ -55,6 +63,7 @@ public class LoginActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); mLoginNameView = findViewById(R.id.email); + ButterKnife.bind(this); ldapService = ApiClient.getClient(getApplicationContext()) .create(LdapService.class); @@ -75,6 +84,30 @@ public class LoginActivity extends AppCompatActivity { mLoginFormView = findViewById(R.id.login_form); mProgressView = findViewById(R.id.login_progress); + + validateForm(); + } + + + private void validateForm() { + sign_in_button.setEnabled(false); + mLoginNameView.setError(null); + mPasswordView.setError(null); + + rx.Observable emailChangeObservable = RxTextView.textChangeEvents(email); + rx.Observable passwordChangeObservable = RxTextView.textChangeEvents(password); + + rx.Observable.combineLatest(emailChangeObservable, passwordChangeObservable, + (emailObservable, passwordObservable) -> { + boolean emailCheck = isEmailValid(emailObservable.text()); + boolean passwordCheck = passwordObservable.text().length() > 0; + + if (!emailCheck) { + mLoginNameView.setError(getString(R.string.error_invalid_login_name)); + } + + return emailCheck && passwordCheck; + }).subscribe(aBoolean -> sign_in_button.setEnabled(aBoolean)); } @@ -117,7 +150,9 @@ public class LoginActivity extends AppCompatActivity { } } - private boolean isEmailValid(String loginName) { + private boolean isEmailValid(CharSequence loginName) { + + Log.e("AAA", String.valueOf(loginName)); Pattern pattern = Pattern.compile("\\s"); Matcher matcher = pattern.matcher(loginName); return !matcher.find(); @@ -127,7 +162,6 @@ public class LoginActivity extends AppCompatActivity { private void showProgress(final boolean show) { int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime); - mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE); mLoginFormView.animate().setDuration(shortAnimTime).alpha( show ? 0 : 1).setListener(new AnimatorListenerAdapter() { @@ -217,5 +251,13 @@ public class LoginActivity extends AppCompatActivity { PrefUtils.storeUserLastName(getApplicationContext(), user.getLastName()); PrefUtils.storeUserName(getApplicationContext(), user.getUserName()); } + + @Override + public void onResume() { + super.onResume(); + mLoginNameView.setError(null); + mPasswordView.setError(null); + } + } diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index b192e97..c7e60fb 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -45,7 +45,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - -