You need to sign in or sign up before continuing.
Unverified Commit 974c8bfa authored by Leonardo Aramaki's avatar Leonardo Aramaki Committed by GitHub

Merge branch 'develop' into animation

parents ccc8b9af a6c965cd
......@@ -4,14 +4,17 @@ import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.TextInputEditText;
import android.support.design.widget.TextInputLayout;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.util.Patterns;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.jakewharton.rxbinding2.widget.RxTextView;
import chat.rocket.android.R;
import chat.rocket.android.api.MethodCallHelper;
import chat.rocket.android.helper.TextUtils;
......@@ -24,7 +27,13 @@ public class UserRegistrationDialogFragment extends DialogFragment {
private String username;
private String email;
private String password;
private TextInputEditText txtUsername;
private TextInputEditText txtEmail;
private TextInputEditText txtPasswd;
private TextInputLayout textInputUsername;
private TextInputLayout textInputEmail;
private TextInputLayout textInputPassword;
private View waitingView;
public UserRegistrationDialogFragment() {
super();
}
......@@ -88,9 +97,8 @@ public class UserRegistrationDialogFragment extends DialogFragment {
View dialog = LayoutInflater.from(getContext())
.inflate(R.layout.dialog_user_registration, null, false);
final TextView txtUsername = (TextView) dialog.findViewById(R.id.editor_username);
final TextView txtEmail = (TextView) dialog.findViewById(R.id.editor_email);
final TextView txtPasswd = (TextView) dialog.findViewById(R.id.editor_passwd);
initViews(dialog);
setUpRxBinders();
if (!TextUtils.isEmpty(username)) {
txtUsername.setText(username);
......@@ -102,17 +110,19 @@ public class UserRegistrationDialogFragment extends DialogFragment {
txtPasswd.setText(password);
}
final View waitingView = dialog.findViewById(R.id.waiting);
waitingView.setVisibility(View.GONE);
dialog.findViewById(R.id.btn_register_user).setOnClickListener(view -> {
view.setEnabled(false);
dialog.findViewById(R.id.btn_register_user).setOnClickListener(registerButton -> {
if (checkIfEditTextsEmpty())
return;
registerButton.setEnabled(false);
registerButton.setAlpha(0.5f);
waitingView.setVisibility(View.VISIBLE);
username = txtUsername.getText().toString();
email = txtEmail.getText().toString();
password = txtPasswd.getText().toString();
MethodCallHelper methodCallHelper = new MethodCallHelper(getContext(), hostname);
methodCallHelper.registerUser(username, email, password, password)
.onSuccessTask(task -> methodCallHelper.loginWithEmail(email, password))
......@@ -126,7 +136,7 @@ public class UserRegistrationDialogFragment extends DialogFragment {
if (task.isFaulted()) {
Exception exception = task.getError();
showError(exception.getMessage());
view.setEnabled(true);
registerButton.setEnabled(true);
waitingView.setVisibility(View.GONE);
}
return null;
......@@ -135,6 +145,51 @@ public class UserRegistrationDialogFragment extends DialogFragment {
return dialog;
}
private void initViews(View dialog) {
txtUsername = dialog.findViewById(R.id.editor_username);
txtEmail = dialog.findViewById(R.id.editor_email);
txtPasswd = dialog.findViewById(R.id.editor_passwd);
textInputEmail = dialog.findViewById(R.id.text_input_email);
textInputUsername = dialog.findViewById(R.id.text_input_username);
textInputPassword = dialog.findViewById(R.id.text_input_passwd);
waitingView = dialog.findViewById(R.id.waiting);
}
private boolean checkIfEditTextsEmpty() {
boolean check = false;
if (TextUtils.isEmpty(txtEmail.getText().toString())) {
textInputEmail.setError("Enter an email address");
textInputEmail.setErrorEnabled(true);
check = true;
}
if (TextUtils.isEmpty(txtUsername.getText().toString())) {
textInputUsername.setError("Enter a username");
textInputUsername.setErrorEnabled(true);
check = true;
}
if (TextUtils.isEmpty(txtPasswd.getText().toString())) {
textInputPassword.setError("Enter a password");
textInputPassword.setErrorEnabled(true);
check = true;
}
return check;
}
private void setUpRxBinders() {
RxTextView.textChanges(txtUsername).subscribe(text -> {
if (!TextUtils.isEmpty(text) && textInputUsername.isErrorEnabled())
textInputUsername.setErrorEnabled(false);
});
RxTextView.textChanges(txtEmail).subscribe(text -> {
if (!TextUtils.isEmpty(text) && textInputEmail.isErrorEnabled())
textInputEmail.setErrorEnabled(false);
});
RxTextView.textChanges(txtPasswd).subscribe(text -> {
if (!TextUtils.isEmpty(text) && textInputPassword.isErrorEnabled())
textInputPassword.setErrorEnabled(false);
});
}
private void showError(String errMessage) {
Toast.makeText(getContext(), errMessage, Toast.LENGTH_SHORT).show();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment