Commit 5aac6844 authored by Lucas Braz Cunha's avatar Lucas Braz Cunha

Issue AGILE#199: [WP] Initial behavior of update activity

Signed-off-by: Lucas Braz Cunha's avatarLucas B. Cunha <lbc16@inf.ufpr.br>
parent b5ffe0b6
package br.ufpr.c3sl.agendador.agendador;
import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.TextView;
import br.ufpr.c3sl.agendador.agendador.helpers.DateValidator;
import br.ufpr.c3sl.agendador.agendador.helpers.Mask;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.helpers.UserImgHelper;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.models.Dependent;
import br.ufpr.c3sl.agendador.agendador.models.FullDependent;
import br.ufpr.c3sl.agendador.agendador.presenters.DependentsUpdatePresenter;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
......@@ -22,12 +31,30 @@ public class DependentUpdateActivity extends AppCompatActivity implements Depend
private FullDependent dependent;
private boolean hasChanged;
private boolean isChangingPhoto, isPhotoDelete;
private ImageView imv_profile;
private ImageButton bt_photo;
private EditText et_name, et_cpf, et_rg, et_birthdate,
et_disability, et_cep, et_address, et_number, et_neighborhood,
et_city, et_state, et_complement, et_phone, et_phone2,
et_email;
private TextView tv_name_warning, tv_rg_warning, tv_birthdate_warning,
tv_phone_warning, tv_email_warning, tv_cpf_warning;
private RadioButton rb_no, rb_yes;
private UserImgHelper userImgHelper;
private ProgressBar pb_dependent;
private Button bt_create, btn_cancel;
private ObscuredSharedPreferences osb;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -52,6 +79,66 @@ public class DependentUpdateActivity extends AppCompatActivity implements Depend
bt_photo = (ImageButton) findViewById(R.id.btn_account_photo);
bt_photo.setVisibility(View.VISIBLE);
osb = ObscuredSharedPreferences.getPrefs(this, "Agendador", Context.MODE_PRIVATE);
//Getting references
pb_dependent = (ProgressBar) findViewById(R.id.pb_dependents);
imv_profile = (ImageView) findViewById(R.id.img_account_photo);
bt_photo = (ImageButton) findViewById(R.id.btn_account_photo);
bt_photo.setVisibility(View.VISIBLE);
btn_cancel = (Button) findViewById(R.id.btn_dependents_cancel);
bt_create = (Button) findViewById(R.id.btn_dependents_confirm);
bt_create.setText(getResources().getString(R.string.save));
et_name = (EditText) findViewById(R.id.et_dependents_name);
et_cpf = (EditText) findViewById(R.id.et_dependents_cpf);
et_rg = (EditText) findViewById(R.id.et_dependents_rg);
et_birthdate = (EditText) findViewById(R.id.et_dependents_birthday);
et_disability = (EditText) findViewById(R.id.et_dependents_disability_name);
et_cep = (EditText) findViewById(R.id.et_dependents_cep);
et_address = (EditText) findViewById(R.id.et_dependents_address);
et_neighborhood = (EditText) findViewById(R.id.et_dependents_neighborhood);
et_number = (EditText) findViewById(R.id.et_dependents_number);
et_city = (EditText) findViewById(R.id.et_dependents_city);
et_state = (EditText) findViewById(R.id.et_dependents_state);
et_complement = (EditText) findViewById(R.id.et_dependents_complement);
et_phone = (EditText) findViewById(R.id.et_dependents_phone);
et_phone2 = (EditText) findViewById(R.id.et_dependents_phone2);
et_email = (EditText) findViewById(R.id.et_dependents_email);
tv_name_warning = (TextView) findViewById(R.id.tv_dependents_name_warning);
tv_rg_warning = (TextView) findViewById(R.id.tv_dependents_rg_warning);
tv_birthdate_warning = (TextView) findViewById(R.id.tv_dependents_birthday_warning);
tv_phone_warning = (TextView) findViewById(R.id.tv_dependents_phone_warning);
tv_email_warning = (TextView) findViewById(R.id.tv_dependents_email_warning);
tv_cpf_warning = (TextView) findViewById(R.id.tv_dependents_cpf_warning);
rb_no = (RadioButton) findViewById(R.id.rb_has_disability_no);
rb_yes = (RadioButton) findViewById(R.id.rb_has_disability_yes);
//Initializations
setSupportActionBar(toolbar);
isChangingPhoto = false;
userImgHelper = new UserImgHelper(getBaseContext());
et_disability.setEnabled(false);
et_cep.addTextChangedListener(Mask.insert("#####-###", et_cep));
et_phone.addTextChangedListener(Mask.insert("(##)####-####", et_phone));
et_phone2.addTextChangedListener(Mask.insert("(##)####-####", et_phone2));
et_cpf.addTextChangedListener(Mask.insert("###.###.###-##", et_cpf));
et_birthdate.addTextChangedListener(Mask.insert("##/##/####", et_birthdate));
try{
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}catch (NullPointerException e){
e.printStackTrace();
}
//Adding listeners
final AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appbar_dependents);
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
......@@ -69,7 +156,6 @@ public class DependentUpdateActivity extends AppCompatActivity implements Depend
}catch (Exception e){
e.printStackTrace();
}
hasChanged = false;
}
@Override
......@@ -105,7 +191,54 @@ public class DependentUpdateActivity extends AppCompatActivity implements Depend
private void loadData(){
et_name.setText("");
et_cpf.setText("");
et_rg.setText("");
et_cep.setText("");
et_number.setText("");
et_birthdate.setText("");
et_disability.setText("");
et_address.setText("");
et_neighborhood.setText("");
et_city.setText("");
et_state.setText("");
et_complement.setText("");
et_phone.setText("");
et_phone2.setText("");
et_email.setText("");
String pcd = osb.getString("pcd", null);
String citizenName = osb.getString("name", null);
if (pcd == null || pcd.isEmpty()) {
rb_yes.setChecked(false);
rb_no.setChecked(true);
} else {
rb_yes.setChecked(true);
rb_no.setChecked(false);
}
et_name.setText(citizenName);
et_cpf.setText(osb.getString("cpf", null));
et_rg.setText(osb.getString("rg", null));
et_cep.setText(osb.getString("address.zipcode", null));
et_number.setText(osb.getString("address_number", null));
et_birthdate.setText(DateValidator.stringToDate(osb.getString("birth_date", null), true));
et_disability.setText(pcd);
et_address.setText(osb.getString("address.address", null));
et_neighborhood.setText(osb.getString("address.neighborhood", null));
et_city.setText(osb.getString("city.name", null));
et_state.setText(osb.getString("state.name", null));
et_complement.setText(osb.getString("address.complement", null));
et_phone.setText(osb.getString("phone1", null));
et_phone2.setText(osb.getString("phone2", null));
et_email.setText(osb.getString("email", null));
isChangingPhoto = false;
isPhotoDelete = false;
getSupportActionBar().setTitle(citizenName);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
......
......@@ -54,8 +54,6 @@ public class NewDependentActivity extends AppCompatActivity implements NewDepen
private NewDependentPresenter presenter;
private ImageView imv_profile;
private ImageButton btn_photo;
......
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