Commit a3aafaf0 authored by Lucas Braz Cunha's avatar Lucas Braz Cunha
Browse files

Issue AGILE#203 [WP] Implemented creation of dependent


Signed-off-by: Lucas Braz Cunha's avatarLucas B. Cunha <lbc16@inf.ufpr.br>
parent ec35e16d
......@@ -62,7 +62,7 @@ import br.ufpr.c3sl.agendador.agendador.views.AccountView;
public class AccountActivity extends AppCompatActivity implements AccountView {
private EditText et_name, et_cpf, et_rg, et_sus_number, et_birthdate,
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, et_new_password, et_password_confirmation;
......@@ -150,7 +150,7 @@ public class AccountActivity extends AppCompatActivity implements AccountView {
et_name = (EditText) findViewById(R.id.et_account_name);
et_cpf = (EditText) findViewById(R.id.et_account_cpf);
et_rg = (EditText) findViewById(R.id.et_account_rg);
et_sus_number = (EditText) findViewById(R.id.et_account_sus);
et_birthdate = (EditText) findViewById(R.id.et_account_birthday);
et_disability = (EditText) findViewById(R.id.et_account_disability_name);
et_cep = (EditText) findViewById(R.id.et_account_cep);
......@@ -185,7 +185,6 @@ public class AccountActivity extends AppCompatActivity implements AccountView {
et_phone2.addTextChangedListener(Mask.insert("(##)####-####", et_phone2));
et_cpf.addTextChangedListener(Mask.insert("###.###.###-##", et_cpf));
et_birthdate.addTextChangedListener(Mask.insert("##/##/####", et_birthdate));
et_sus_number.addTextChangedListener(Mask.insert("###.####.####.####", et_sus_number));
loadData();
......@@ -515,7 +514,6 @@ public class AccountActivity extends AppCompatActivity implements AccountView {
editable = enable;
et_name.setEnabled(enable);
et_rg.setEnabled(enable);
et_sus_number.setEnabled(enable);
et_birthdate.setEnabled(enable);
et_cep.setEnabled(enable);
et_number.setEnabled(enable);
......@@ -546,7 +544,7 @@ public class AccountActivity extends AppCompatActivity implements AccountView {
//has to be done before load data.
if(isChangingPhoto){
if(isPhotoDelete)
userImgHelper.deletePhoto(Utils.USR_PICT_FILE_NAME, id);
userImgHelper.deleteImgFile(Utils.USR_PICT_FILE_NAME, id);
else
userImgHelper.copyFromTo(userImgHelper.getTempFileUri(Utils.USR_PICT_FILE_NAME, id), userImgHelper.getFileUri(Utils.USR_PICT_FILE_NAME, id));
}
......@@ -579,7 +577,6 @@ public class AccountActivity extends AppCompatActivity implements AccountView {
et_rg.setText("");
et_cep.setText("");
et_number.setText("");
et_sus_number.setText("");
et_birthdate.setText("");
et_disability.setText("");
et_address.setText("");
......@@ -605,7 +602,6 @@ public class AccountActivity extends AppCompatActivity implements AccountView {
et_name.setText(citizenName);
et_cpf.setText(osb.getString("cpf", null));
et_rg.setText(osb.getString("rg", null));
et_sus_number.setText(osb.getString("sus", 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));
......
......@@ -44,6 +44,7 @@ import br.ufpr.c3sl.agendador.agendador.helpers.UserImgHelper;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.helpers.adapters.PhotoSelectionAdapter;
import br.ufpr.c3sl.agendador.agendador.models.Dependent;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
import br.ufpr.c3sl.agendador.agendador.presenters.NewDependentPresenter;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.views.NewDependentsView;
......@@ -65,7 +66,7 @@ public class NewDependentActivity extends AppCompatActivity implements NewDepen
private Button btn_create, btn_cancel;
private EditText et_name, et_cpf, et_rg, et_sus_number, et_birthdate,
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;
......@@ -77,15 +78,13 @@ public class NewDependentActivity extends AppCompatActivity implements NewDepen
private UserImgHelper userImgHelper;
private boolean isChangingPhoto;
private final int REQUEST_PERMISSIONS = 1;
private final int LOAD_IMAGE_INTENT = 1;
private static final int TEMP_FILE_ID = 0;
// TODO: 28/08/17 Verificar a imagem salva, apagar se cancelar a criação!!
// verificar onde ela fica salva.
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -115,7 +114,6 @@ public class NewDependentActivity extends AppCompatActivity implements NewDepen
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_sus_number = (EditText) findViewById(R.id.et_dependents_sus);
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);
......@@ -151,7 +149,6 @@ public class NewDependentActivity extends AppCompatActivity implements NewDepen
et_phone2.addTextChangedListener(Mask.insert("(##)####-####", et_phone2));
et_cpf.addTextChangedListener(Mask.insert("###.###.###-##", et_cpf));
et_birthdate.addTextChangedListener(Mask.insert("##/##/####", et_birthdate));
et_sus_number.addTextChangedListener(Mask.insert("###.####.####.####", et_sus_number));
try{
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
......@@ -245,8 +242,7 @@ public class NewDependentActivity extends AppCompatActivity implements NewDepen
boolean validated = validateData();
if(validated){
if(ConnectionChecker.hasConnection(getBaseContext())){
dependent = new Dependent(0, "aniversario", "Nome", "RG", "CPF");
presenter.requestCreateDependent();
presenter.requestCreateDependent();
}
else{
setNoConnection(true);
......@@ -264,15 +260,17 @@ public class NewDependentActivity extends AppCompatActivity implements NewDepen
@Override
public void onClick(View view) {
//if(!userImgHelper.existsPhoto()){
//checkBuildVersion();
// return;
//}
if(!userImgHelper.existsPhoto(Utils.USR_TEMP_PICT_FILE_NAME, TEMP_FILE_ID)){
checkBuildVersion();
return;
}
android.support.v7.app.AlertDialog.Builder builderSingle = new android.support.v7.app.AlertDialog.Builder(NewDependentActivity.this);
//builderSingle.setIcon(R.drawable.ic_action_search);
builderSingle.setIcon(R.drawable.ic_action_search);
//TODO: this message is too long for the dialog.
builderSingle.setTitle(getString(R.string.prof_pic_dialog));
// TODO: 30/08/17 Change alert dialog layout
//builderSingle.setView(Layout bonito);
final String[] opts = {getString(R.string.prof_pic_update), getString(R.string.prof_pic_remove)};
int[] drawableIds = {android.R.drawable.ic_menu_camera, android.R.drawable.ic_menu_close_clear_cancel};
......@@ -295,7 +293,7 @@ public class NewDependentActivity extends AppCompatActivity implements NewDepen
imv_profile.setImageBitmap(null);
}
else{
//checkBuildVersion();
checkBuildVersion();
}
}
});
......@@ -341,7 +339,6 @@ public class NewDependentActivity extends AppCompatActivity implements NewDepen
et_name.setEnabled(enabled);
et_cpf.setEnabled(enabled);
et_rg.setEnabled(enabled);
et_sus_number.setEnabled(enabled);
et_birthdate.setEnabled(enabled);
et_disability.setEnabled(enabled);
et_cep.setEnabled(enabled);
......@@ -422,7 +419,6 @@ public class NewDependentActivity extends AppCompatActivity implements NewDepen
}
// TODO: 28/08/17 verificar se os valores estão corretos
@Override
public HashMap<String, String> getValues() {
HashMap<String, String> values = new HashMap<>();
......@@ -449,13 +445,14 @@ public class NewDependentActivity extends AppCompatActivity implements NewDepen
values.put("phone2", Mask.unmask(et_phone2.getText().toString()));
values.put("email", et_email.getText().toString());
values.put("active", "true");
if(isChangingPhoto) {
/* values.put("photo_content", Utils.getBase64FromFile(userImgHelper.getTempFilePath()));
values.put("photo_content", Utils.getBase64FromFile(userImgHelper.getTempFilePath(Utils.USR_TEMP_PICT_FILE_NAME, 0)));
values.put("photo_type", "image/png");
// TODO: 03/05/17 Change here to work with multi photo types
values.put("photo_name", userImgHelper.getUserUid() + ".png");
*/
values.put("photo_name", values.get("cpf") + ".png");
}
return values;
......@@ -560,10 +557,9 @@ public class NewDependentActivity extends AppCompatActivity implements NewDepen
return true;
}
//handling picture selection
/*
//handling picture selection
private void checkBuildVersion(){
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M )
openIntentChooser(true, true);
......@@ -625,8 +621,8 @@ public class NewDependentActivity extends AppCompatActivity implements NewDepen
final Intent intent = new Intent(captureIntent);
intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
intent.setPackage(packageName);
intent.putExtra(MediaStore.EXTRA_OUTPUT, userImgHelper.getTempFileUri());
getBaseContext().grantUriPermission(packageName, userImgHelper.getTempFileUri(), Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(MediaStore.EXTRA_OUTPUT, userImgHelper.getTempFileUri(Utils.USR_TEMP_PICT_FILE_NAME, TEMP_FILE_ID));
getBaseContext().grantUriPermission(packageName, userImgHelper.getTempFileUri(Utils.USR_TEMP_PICT_FILE_NAME, TEMP_FILE_ID), Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
cameraIntents.add(intent);
}
......@@ -679,10 +675,10 @@ public class NewDependentActivity extends AppCompatActivity implements NewDepen
//selected image path is returned by data.getData();
try {
if (isCamera) {
userImgHelper.convertToPng();
userImgHelper.convertToPng(Utils.USR_TEMP_PICT_FILE_NAME, TEMP_FILE_ID);
}
else {
userImgHelper.copyFileToPrivate(data.getData());
userImgHelper.copyFileToPrivate(Utils.USR_TEMP_PICT_FILE_NAME, TEMP_FILE_ID, data.getData());
}
} catch (Exception e) {
// TODO: 04/05/17 user messages & error warning
......@@ -691,7 +687,7 @@ public class NewDependentActivity extends AppCompatActivity implements NewDepen
}
isChangingPhoto = true;
Bitmap content = userImgHelper.getRoundBitmap(userImgHelper.getTempFileUri());
Bitmap content = userImgHelper.getRoundBitmap(userImgHelper.getTempFileUri(Utils.USR_TEMP_PICT_FILE_NAME, TEMP_FILE_ID));
//TODO: user messages & error warning (same as above).
if(content == null)
......@@ -707,7 +703,33 @@ public class NewDependentActivity extends AppCompatActivity implements NewDepen
}
}
*/
public void onRequestError(){
scrollUp();
if (connectionErrorDialog == null) {
connectionErrorDialog = new ConnectionErrorDialog();
}
Bundle bundle = new Bundle();
bundle.putString(ConnectionErrorDialog.DIALOG_MESSAGE, getString(R.string.dialog_connection_error_message));
connectionErrorDialog.setArguments(bundle);
connectionErrorDialog.show(getFragmentManager(), ConnectionErrorDialog.DIALOG_CONNECTION_ERROR);
}
public void onDependentReceived(UserOutput dependent){
try {
userImgHelper.copyFromTo(userImgHelper.getTempFileUri(Utils.USR_TEMP_PICT_FILE_NAME, 0), userImgHelper.getFileUri(Utils.USR_PICT_FILE_NAME, dependent.getmId()));
} catch (Exception e) {
// TODO: 31/08/17 change to snackBar
Toast.makeText(this, "Ocorreu um erro ao armazenar a foto!", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
finally {
finish();
}
}
}
......@@ -98,11 +98,16 @@ public class UserImgHelper {
out.close();
}
public boolean deletePhoto(String fileName, long id)throws Exception{
public boolean deleteImgFile(String fileName, long id)throws Exception{
File photoDelete = new File(getFilePath(fileName, id));
return photoDelete.delete();
}
public boolean deleteTempFile(String fileName, long id)throws Exception{
File photoDelete = new File(getTempFilePath(fileName, id));
return photoDelete.delete();
}
public boolean existsPhoto(String fileName, long id) {
String filePath = fileDir + File.separator + fileName + id;
File photo = new File(filePath + extension);
......
......@@ -39,12 +39,16 @@ public class Utils {
public static final String USR_PICT_FILE_NAME = "usr_prof_pic";
public static final String USR_TEMP_PICT_FILE_NAME = "new_dependent_pic";
public static final String SCHEDULE_CONFIRMATION = "selected_schedule";
public static final String CITIZEN = "citizen_object";
public static final String CITIZEN_BUNDLE = "br.ufpr.c3sl.agendador.agendador.citizen_bundle";
public static final String JOB_FILE_NAME = "fileName_tag";
public static int getPixelValue(int dp, Context context) {
Resources resources = context.getResources();
......
......@@ -9,7 +9,7 @@ import com.google.gson.annotations.SerializedName;
public class AccountUpdate {
@SerializedName("citizen")
private UserUpdate mUser;
private UserData mUser;
@SerializedName("current_password")
private String mcurrentPassword;
......@@ -21,14 +21,14 @@ public class AccountUpdate {
private String mPasswordConfirmation;
public AccountUpdate(UserUpdate user, String currentPassword, String password, String passwordConfirmation) {
public AccountUpdate(UserData user, String currentPassword, String password, String passwordConfirmation) {
this.mUser = user;
this.mPassword = password;
this.mPasswordConfirmation = passwordConfirmation;
this.mcurrentPassword = currentPassword;
}
public AccountUpdate(UserUpdate user) {
public AccountUpdate(UserData user) {
this.mUser = user;
}
......
package br.ufpr.c3sl.agendador.agendador.models;
import com.google.gson.annotations.SerializedName;
import java.util.Map;
/**
* Created by lbc16 on 30/08/17.
*/
public class DependentCreation {
@SerializedName("dependant")
private DependentData data;
public DependentCreation(Map<String, String> values){
data = new DependentData(values);
}
public DependentData getData() {
return data;
}
public class DependentData{
@SerializedName("address_number")
private String mAddress_Number;
@SerializedName("note")
private String mNote;
@SerializedName("rg")
private String mRg;
@SerializedName("email")
private String mEmail;
@SerializedName("pcd")
private String mPcd;
@SerializedName("phone2")
private String mPhone2;
@SerializedName("phone1")
private String mPhone1;
@SerializedName("name")
private String mName;
@SerializedName("birth_date")
private String mBirth_Date;
@SerializedName("cep")
private String mCep;
@SerializedName("address_complement")
private String mAddressComplement;
@SerializedName("active")
private boolean active;
@SerializedName("image")
private Image image;
DependentData(Map<String, String> values) {
this.mAddress_Number = values.get("address_number");
this.mRg = values.get("rg");
this.mEmail = values.get("email");
this.mPcd = values.get("pcd");
this.mPhone2 = values.get("phone2");
this.mPhone1 = values.get("phone1");
this.mName = values.get("name");
this.mBirth_Date = values.get("birth_date");
this.mCep = values.get("cep");
this.mAddressComplement = values.get("address_complement");
this.active = values.get("active").equals("true");
}
public void setImage(String contentType, String fileName, String content) {
this.image = new Image(contentType, fileName, content);
}
}
private class Image {
@SerializedName("content")
String mContent;
@SerializedName("filename")
String mFileName;
@SerializedName("content_type")
String mContentType;
private Image(String contentType, String fileName, String content) {
this.mContent = content;
this.mFileName = fileName;
this.mContentType = contentType;
}
}
}
......@@ -8,7 +8,7 @@ import java.util.Map;
* Created by Bruno Freitas Tissei on 2/3/17.
*/
public class UserUpdate {
public class UserData {
@SerializedName("address_number")
private String mAddress_Number;
......@@ -46,7 +46,7 @@ public class UserUpdate {
@SerializedName("image")
private Image mImage;
public UserUpdate(Map<String, String> values) {
public UserData(Map<String, String> values) {
this.mAddress_Number = values.get("address_number");
this.mRg = values.get("rg");
this.mEmail = values.get("email");
......
......@@ -8,6 +8,7 @@ import br.ufpr.c3sl.agendador.agendador.models.AccountUpdate;
import br.ufpr.c3sl.agendador.agendador.models.Address;
import br.ufpr.c3sl.agendador.agendador.models.CepInput;
import br.ufpr.c3sl.agendador.agendador.models.Dependent;
import br.ufpr.c3sl.agendador.agendador.models.DependentCreation;
import br.ufpr.c3sl.agendador.agendador.models.FullDependent;
import br.ufpr.c3sl.agendador.agendador.models.ScheduleConfirmation;
import br.ufpr.c3sl.agendador.agendador.models.SectorInput;
......@@ -47,7 +48,7 @@ public interface ApiEndpoints {
Call<Address> validateCep(@Body CepInput cepInput);
@GET("citizens/{id}/picture")
Call<ResponseBody> requestPhoto(@Path("id") int id, @Query("size") String size);
Call<ResponseBody> requestPhoto(@Path("id") long id, @Query("size") String size);
@GET("accounts/self")
Call<AccountOutput> requestSelf();
......@@ -77,6 +78,6 @@ public interface ApiEndpoints {
Call<FullDependent> requestDependentInfo(@Path("id_user") long citizenId, @Path("id_dependent") long dependentId);
@POST("citizens/{id_user}/dependants")
Call<Dependent> createNewDependent(@Path("id_user") long citizenId, @Body Dependent dependent);
Call<UserOutput> createNewDependent(@Path("id_user") long citizenId, @Body DependentCreation dependent);
}
\ No newline at end of file
......@@ -18,7 +18,7 @@ import br.ufpr.c3sl.agendador.agendador.models.AccountOutput;
import br.ufpr.c3sl.agendador.agendador.models.AccountUpdate;
import br.ufpr.c3sl.agendador.agendador.models.Address;
import br.ufpr.c3sl.agendador.agendador.models.CepInput;
import br.ufpr.c3sl.agendador.agendador.models.UserUpdate;
import br.ufpr.c3sl.agendador.agendador.models.UserData;
import br.ufpr.c3sl.agendador.agendador.network.ApiEndpoints;
import br.ufpr.c3sl.agendador.agendador.network.ApiUtils;
import br.ufpr.c3sl.agendador.agendador.views.AccountView;
......@@ -46,13 +46,20 @@ public class AccountPresenter extends BasePresenter<AccountView> {
}
private void onSuccessfulCheck(AccountOutput accountOutput, Headers headers){
osb.edit().putString("expiry", headers.get("expiry")).apply();
updateHeaders(headers);
accountOutput.getCitizen().save(context);
String token = headers.get("access-token");
if(token != null)
osb.edit().putString("access-token", token).apply();
}
private void onSuccessfulUpdate(AccountOutput accountOutput) {
accountOutput.getCitizen().save(context);
//cancelling job because photo has been updated from app.
if(isPicUpdate){
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
dispatcher.cancel(Utils.SERVICE_UPDATE_IMAGE);
isPicUpdate = false;
}
}
public void updateCheck(){
accountPresenter.view().setProgressBar(true);
......@@ -104,22 +111,10 @@ public class AccountPresenter extends BasePresenter<AccountView> {
}
});
}
private void onSuccessfulUpdate(AccountOutput accountOutput) {
accountOutput.getCitizen().save(context);
//cancelling job because photo has been updated from app.
if(isPicUpdate){
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
dispatcher.cancel(Utils.SERVICE_UPDATE_IMAGE);
isPicUpdate = false;
}
}
@Override
protected void updateView() {}
public void onUpdateClicked(){
Map<String, String> header = new HashMap<>();
......@@ -131,7 +126,7 @@ public class AccountPresenter extends BasePresenter<AccountView> {
ApiEndpoints service = ApiUtils.request(header);
Map<String, String> body;
body = accountPresenter.view().getValues();
UserUpdate user = new UserUpdate(body);
UserData user = new UserData(body);
final AccountUpdate account;
if(body.get("photo_type") != null) {
......
......@@ -139,7 +139,7 @@ public class LoginPresenter extends BasePresenter<LoginView> {
ApiEndpoints service = ApiUtils.request(header);
Call<ResponseBody> listCall = service.requestPhoto(osb.getInt("id", 0), "large");
Call<ResponseBody> listCall = service.requestPhoto(osb.getLong("id", 0), "large");
loginPresenter.view().setProgressBar(true);
listCall.enqueue(new Callback<ResponseBody>() {
......@@ -176,7 +176,9 @@ public class LoginPresenter extends BasePresenter<LoginView> {
extras.putString("client",osb.getString("client", null));
extras.putInt("id",osb.getInt("id", 0));
extras.putLong("id",osb.getLong("id", 0));
extras.putString(Utils.JOB_FILE_NAME, Utils.USR_PICT_FILE_NAME);
Job job = dispatcher.newJobBuilder()
......
......@@ -14,8 +14,8 @@ import br.ufpr.c3sl.agendador.agendador.NewDependentActivity;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.models.Address;
import br.ufpr.c3sl.agendador.agendador.models.CepInput;
import br.ufpr.c3sl.agendador.agendador.models.Dependent;
import br.ufpr.c3sl.agendador.agendador.models.FullDependent;
import br.ufpr.c3sl.agendador.agendador.models.DependentCreation;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
import br.ufpr.c3sl.agendador.agendador.network.ApiEndpoints;
import br.ufpr.c3sl.agendador.agendador.network.ApiUtils;
import okhttp3.Headers;
......@@ -31,6 +31,8 @@ public class NewDependentPresenter extends BasePresenter<NewDependentActivity> {
private NewDependentPresenter presenter;
private boolean isPicUpdate;