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

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));
......
......@@ -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;
public NewDependentPresenter(Context context){
presenter = this;
......@@ -38,50 +40,59 @@ public class NewDependentPresenter extends BasePresenter<NewDependentActivity> {
}
// TODO: 28/08/17 Arrumar a classe que engloba os dados enviados, e verificar o que é recebido.
// TODO: 28/08/17 Arrumar a requisição, retorno 201 atualmente.
public void requestCreateDependent(){
Map<String, String> header = new HashMap<>();
header.put("Content-Type", "application/json");
header.put("access-token", osb.getString("access-token", null));
header.put("client", osb.getString("client", null));
header.put("uid", osb.getString("uid", null));
Map<String, String> body;
body = presenter.view().getValues();
final ApiEndpoints service = ApiUtils.request(header);
//Dependent dependent = new Dependent(body);
DependentCreation data = new DependentCreation(body);
isPicUpdate = false;
Call<Dependent> listCall = service.createNewDependent(osb.getLong("id", 0), null);
if(body.get("photo_type") != null) {
data.getData().setImage(body.get("photo_type"), body.get("photo_name"), body.get("photo_content"));
isPicUpdate = true;
}
Call<UserOutput> listCall = service.createNewDependent(osb.getLong("id", 0), data);
presenter.view().setProgressBar(true);
listCall.enqueue(new Callback<Dependent>() {
listCall.enqueue(new Callback<UserOutput>() {
@Override
public void onResponse(Call<Dependent> call, Response<Dependent> response) {
public void onResponse(Call<UserOutput> call, Response<UserOutput> response) {
Headers headers = response.headers();
int status = response.code();
//FullDependent dependent = response.body();
UserOutput dependent = response.body();
updateHeaders(headers);
switch (status) {
case 200:
case 201:
Log.d("Server response", getClass().getName() + ": 200 - Sucesso!");
// presenter.view().onDependentReceived(dependent);
presenter.view().onDependentReceived(dependent);
presenter.view().setProgressBar(false);
break;
default:
Log.e("Server response", getClass().getName() + ": ERRO:" + status);
// presenter.view().onRequestFailure();
presenter.view().onRequestError();
presenter.view().setProgressBar(false);
break;
}
}
@Override
public void onFailure(Call<Dependent> call, Throwable t) {
public void onFailure(Call<UserOutput> call, Throwable t) {
Log.e("Server response", getClass().getName() + ": Requisição falhou!!");
presenter.view().setProgressBar(false);
// presenter.view().onRequestFailure();
presenter.view().setNoConnection(true);
t.printStackTrace();
}
});
......
......@@ -46,9 +46,11 @@ public class ImageUpdateService extends JobService {
header.put("client", extras.getString("client", null));
header.put("uid", uid);
final long id = extras.getLong("id", 0);
ApiEndpoints service = ApiUtils.request(header);
Call<ResponseBody> listCall = service.requestPhoto(extras.getInt("id", 0), "large");
Call<ResponseBody> listCall = service.requestPhoto(id, "large");
listCall.enqueue(new Callback<ResponseBody>() {
......@@ -60,7 +62,7 @@ public class ImageUpdateService extends JobService {
case 200:
UserImgHelper userImgHelper = new UserImgHelper(getBaseContext());
try {
userImgHelper.saveBitmap(BitmapFactory.decodeStream(response.body().byteStream()), Utils.USR_PICT_FILE_NAME, extras.getInt("id", 0));
userImgHelper.saveBitmap(BitmapFactory.decodeStream(response.body().byteStream()), extras.getString(Utils.JOB_FILE_NAME), id);
} catch (IOException e) {
Log.d("AGNDDR-ImgService", "Ocorreu um problema ao atualizar sua foto de perfil");
e.printStackTrace();
......
......@@ -2,6 +2,8 @@ package br.ufpr.c3sl.agendador.agendador.views;
import java.util.HashMap;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
/**
* Created by lbc16 on 18/08/17.
*/
......@@ -19,4 +21,7 @@ public interface NewDependentsView {
HashMap<String, String> getValues();
void onRequestError();
void onDependentReceived(UserOutput dependent);
}
......@@ -219,45 +219,13 @@
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_accountact_sus_container"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignEnd="@+id/ll_accountact_name_container"
android:layout_alignStart="@id/ll_accountact_name_container"
android:layout_below="@+id/ll_accountact_rg_container"
android:layout_centerHorizontal="true"
android:layout_marginTop="3dp"
android:background="@drawable/gray_container_shape">
<TextView
android:id="@+id/tv_account_sus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:text="@string/sus_number"
android:textColor="@color/colorBlack"
android:textSize="16sp" />
<EditText
android:id="@+id/et_account_sus"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:inputType="number"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_accountact_birthday_container"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignEnd="@+id/ll_accountact_name_container"
android:layout_alignStart="@id/ll_accountact_name_container"
android:layout_below="@+id/ll_accountact_sus_container"
android:layout_below="@+id/ll_accountact_rg_container"
android:layout_centerHorizontal="true"
android:layout_marginTop="3dp"
android:background="@drawable/gray_container_shape">
......
......@@ -219,45 +219,13 @@
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_dependents_sus_container"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignEnd="@+id/ll_dependents_name_container"
android:layout_alignStart="@id/ll_dependents_name_container"
android:layout_below="@+id/ll_dependents_rg_container"
android:layout_centerHorizontal="true"
android:layout_marginTop="3dp"
android:background="@drawable/gray_container_shape">
<TextView
android:id="@+id/tv_dependents_sus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:text="@string/sus_number"
android:textColor="@color/colorBlack"
android:textSize="16sp" />
<EditText
android:id="@+id/et_dependents_sus"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:inputType="number"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_dependents_birthday_container"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_alignEnd="@+id/ll_dependents_name_container"
android:layout_alignStart="@id/ll_dependents_name_container"
android:layout_below="@+id/ll_dependents_sus_container"
android:layout_below="@+id/ll_dependents_rg_container"
android:layout_centerHorizontal="true"
android:layout_marginTop="3dp"
android:background="@drawable/gray_container_shape">
......
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