Commit 82b2ce1a authored by Lucas Braz Cunha's avatar Lucas Braz Cunha
Browse files

Issue AGILE#155: CPF validation done

parent 3cfa1754
...@@ -2,12 +2,18 @@ package br.ufpr.c3sl.agendador.agendador; ...@@ -2,12 +2,18 @@ package br.ufpr.c3sl.agendador.agendador;
import android.os.Bundle; import android.os.Bundle;
import android.os.PersistableBundle; import android.os.PersistableBundle;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import br.ufpr.c3sl.agendador.agendador.helpers.DataValidador;
import br.ufpr.c3sl.agendador.agendador.helpers.Mask;
import br.ufpr.c3sl.agendador.agendador.presenters.ForgotPasswordPresenter; import br.ufpr.c3sl.agendador.agendador.presenters.ForgotPasswordPresenter;
import br.ufpr.c3sl.agendador.agendador.views.ForgotPasswordView; import br.ufpr.c3sl.agendador.agendador.views.ForgotPasswordView;
...@@ -22,11 +28,11 @@ public class ForgotPasswordActivity extends AppCompatActivity implements ForgotP ...@@ -22,11 +28,11 @@ public class ForgotPasswordActivity extends AppCompatActivity implements ForgotP
private Button btn_send; private Button btn_send;
private EditText et_cpf; private EditText et_cpf;
private TextView tv_cpf, tv_cpf_warning; private TextView tv_cpf_warning;
private ProgressBar pb_waiting; private ProgressBar pb_waiting;
@Override @Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (savedInstanceState == null) { if (savedInstanceState == null) {
presenter = new ForgotPasswordPresenter(this); presenter = new ForgotPasswordPresenter(this);
...@@ -34,16 +40,94 @@ public class ForgotPasswordActivity extends AppCompatActivity implements ForgotP ...@@ -34,16 +40,94 @@ public class ForgotPasswordActivity extends AppCompatActivity implements ForgotP
presenter = PresenterManager.getInstance().restorePresenter(savedInstanceState); presenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
} }
setContentView(R.layout.activity_login); setContentView(R.layout.activity_forgot_password);
pb_waiting = (ProgressBar) findViewById(R.id.pb_forgot_paswordact);
et_cpf = (EditText) findViewById(R.id.et_forgot_password_cpf);
et_cpf.addTextChangedListener(Mask.insert("###.###.###-##", et_cpf));
et_cpf.addTextChangedListener(new CpfChangeListener());
tv_cpf = (TextView) findViewById(R.id.tv_forgot_password_cpf);
tv_cpf_warning = (TextView) findViewById(R.id.tv_forgot_password_invalid_cpf); tv_cpf_warning = (TextView) findViewById(R.id.tv_forgot_password_invalid_cpf);
btn_send = (Button) findViewById(R.id.btn_forgot_passwordact_send);
btn_send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(validateData())
presenter.onForgotPasswordClicked(Mask.unmask(et_cpf.getText().toString()));
}
});
}
@Override
protected void onResume() {
super.onResume();
presenter.bindView(this);
}
@Override
protected void onPause() {
super.onPause();
presenter.unbindView();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
PresenterManager.getInstance().savePresenter(presenter, outState);
} }
@Override @Override
public void setProgressBar(boolean enabled) { public void setProgressBar(boolean enabled) {
if(enabled) {
pb_waiting.setVisibility(View.VISIBLE);
et_cpf.setEnabled(false);
} else{
pb_waiting.setVisibility(View.INVISIBLE);
et_cpf.setEnabled(true);
}
}
@Override
public boolean validateData() {
if(Mask.unmask(et_cpf.getText().toString()).isEmpty()) {
tv_cpf_warning.setText(R.string.cpf_empty);
setWrongCpf(true);
return false;
} else if(!DataValidador.isValidCPF(Mask.unmask(et_cpf.getText().toString()))) {
tv_cpf_warning.setText(R.string.invalid_cpf);
setWrongCpf(true);
return false;
}
return true;
}
@Override
public void setWrongCpf(boolean enabled) {
if (enabled) {
tv_cpf_warning.setVisibility(View.VISIBLE);
} else {
tv_cpf_warning.setVisibility(View.INVISIBLE);
}
}
private class CpfChangeListener implements TextWatcher {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
setWrongCpf(false);
}
@Override
public void afterTextChanged(Editable s) {}
} }
} }
package br.ufpr.c3sl.agendador.agendador.presenters; package br.ufpr.c3sl.agendador.agendador.presenters;
import android.content.Context; import android.content.Context;
import android.util.Log;
import android.webkit.ConsoleMessage;
import java.io.Console;
import br.ufpr.c3sl.agendador.agendador.R;
import br.ufpr.c3sl.agendador.agendador.helpers.DataValidador;
import br.ufpr.c3sl.agendador.agendador.views.ForgotPasswordView;
import br.ufpr.c3sl.agendador.agendador.views.HomeView; import br.ufpr.c3sl.agendador.agendador.views.HomeView;
/** /**
* Created by Horstmann on 23/02/17. * Created by Horstmann on 23/02/17.
*/ */
public class ForgotPasswordPresenter extends BasePresenter<HomeView> { public class ForgotPasswordPresenter extends BasePresenter<ForgotPasswordView> {
private Context context; private Context context;
private ForgotPasswordPresenter forgotPasswordPresenter;
public ForgotPasswordPresenter(Context context) { public ForgotPasswordPresenter(Context context) {
this.context = context; this.context = context;
this.forgotPasswordPresenter = this;
} }
@Override @Override
protected void updateView() { protected void updateView() {
}
public void onForgotPasswordClicked(String cpf){
forgotPasswordPresenter.view().setProgressBar(true);
//TODO: colocar a parte de conexão
} }
} }
\ No newline at end of file
...@@ -7,4 +7,9 @@ package br.ufpr.c3sl.agendador.agendador.views; ...@@ -7,4 +7,9 @@ package br.ufpr.c3sl.agendador.agendador.views;
public interface ForgotPasswordView { public interface ForgotPasswordView {
void setProgressBar(boolean enabled); void setProgressBar(boolean enabled);
void setWrongCpf(boolean enabled);
boolean validateData();
} }
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center" android:layout_gravity="center"
android:inputType="number"
android:textSize="16sp"/> android:textSize="16sp"/>
</LinearLayout> </LinearLayout>
......
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
<string name="singup_warningDialog_message2">"Por favor retorne e preencha novamente. "</string> <string name="singup_warningDialog_message2">"Por favor retorne e preencha novamente. "</string>
<string name="signup_null_name">Nome vázio</string> <string name="signup_null_name">Nome vázio</string>
<string name="invalid_birthdate">Data nasc. inválida</string> <string name="invalid_birthdate">Data nasc. inválida</string>
<string name="cpf_empty">Cpf vázio</string> <string name="cpf_empty">CPF vázio</string>
<string name="empty_email">E-mail vázio</string> <string name="empty_email">E-mail vázio</string>
<string name="password_weak">Senha fraca</string> <string name="password_weak">Senha fraca</string>
<string name="password_doesnt_match">Senhas diferem</string> <string name="password_doesnt_match">Senhas diferem</string>
......
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