Commit 806a83cf authored by Lucas Braz Cunha's avatar Lucas Braz Cunha
Browse files

Issue AGILE#199: Done Dependent activities behavior


Signed-off-by: Lucas Braz Cunha's avatarLucas B. Cunha <lbc16@inf.ufpr.br>
parent c7e669c2
......@@ -55,7 +55,7 @@
<activity android:name=".CitizenActivity" />
<activity android:name=".ScheduleConfirmationActivity" />
<activity android:name=".DependentUpdateActivity" />
<activity android:name=".NewDependentActivity"></activity>
<activity android:name=".NewDependentActivity"/>
</application>
</manifest>
\ No newline at end of file
......@@ -256,7 +256,6 @@ public class AccountActivity extends AppCompatActivity implements AccountView {
public void afterTextChanged(Editable s) {}
});
} else {
presenter.onCepNotFocused(Mask.unmask(et_cep.getText().toString()));
if(ConnectionChecker.hasConnection(getBaseContext())) {
presenter.onCepNotFocused(Mask.unmask(et_cep.getText().toString()));
}
......
......@@ -2,8 +2,8 @@ package br.ufpr.c3sl.agendador.agendador;
import android.Manifest;
import android.annotation.TargetApi;
import android.app.FragmentManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
......@@ -18,6 +18,9 @@ import android.support.design.widget.CoordinatorLayout;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
......@@ -39,7 +42,6 @@ import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionChecker;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionErrorDialog;
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.helpers.adapters.PhotoSelectionAdapter;
......@@ -80,17 +82,14 @@ public class DependentUpdateActivity extends AppCompatActivity implements Depend
private ConnectionErrorDialog connectionErrorDialog;
private ObscuredSharedPreferences osb;
private final int REQUEST_PERMISSIONS = 1;
private final int LOAD_IMAGE_INTENT = 1;
// TODO: 18/09/17 Cep error dialog shows twice on error
// TODO: 15/09/17 Conversar com o bruno sobre a pessoa apagar um campo, como enviar ele em vazio?
// TODO: 15/09/17 A atualização da foto vai junto com os dados? - conversar com o bruno
//problema da atualização da foto está na dependent activity.
@Override
......@@ -115,7 +114,6 @@ 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
......@@ -194,6 +192,7 @@ public class DependentUpdateActivity extends AppCompatActivity implements Depend
e.printStackTrace();
}
if(userImgHelper.existsPhoto(Utils.USR_PICT_FILE_NAME, dependent.getInfo().getmId())){
imv_profile.setImageBitmap(userImgHelper.getRoundBitmap(userImgHelper.getFileUri(Utils.USR_PICT_FILE_NAME, dependent.getInfo().getmId())));
}
......@@ -268,6 +267,46 @@ public class DependentUpdateActivity extends AppCompatActivity implements Depend
}
});
et_cep.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, final boolean hasFocus) {
if (hasFocus) {
et_cep.addTextChangedListener(new 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) {
if (Mask.unmask(et_cep.getText().toString()).length() < 8) {
et_state.setText("");
et_city.setText("");
et_neighborhood.setText("");
et_address.setText("");
}
}
@Override
public void afterTextChanged(Editable s) {}
});
} else {
if(ConnectionChecker.hasConnection(getBaseContext())) {
presenter.onCepNotFocused(Mask.unmask(et_cep.getText().toString()));
}
else{
Bundle bundle = new Bundle();
bundle.putString(ConnectionErrorDialog.DIALOG_MESSAGE, getString(R.string.dialog_cep_connection_error));
if(connectionErrorDialog == null){
connectionErrorDialog = new ConnectionErrorDialog();
}
connectionErrorDialog.setArguments(bundle);
connectionErrorDialog.show(getFragmentManager(), ConnectionErrorDialog.DIALOG_CONNECTION_ERROR);
}
}
}
});
loadData();
enableAllFields(false);
setButtonVisible(false);
......@@ -445,19 +484,27 @@ public class DependentUpdateActivity extends AppCompatActivity implements Depend
public void onSuccessfulUpdate(FullDependent dependent){
this.dependent = dependent;
enableAllFields(false);
loadData();
try{
//has to be done before load data.
if(isChangingPhoto){
if(isPhotoDelete)
if(isPhotoDelete){
userImgHelper.deleteImgFile(Utils.USR_PICT_FILE_NAME, dependent.getInfo().getmId());
else
}
else {
userImgHelper.copyFromTo(userImgHelper.getTempFileUri(Utils.USR_PICT_FILE_NAME, dependent.getInfo().getmId()), userImgHelper.getFileUri(Utils.USR_PICT_FILE_NAME, dependent.getInfo().getmId()));
}
isEditing = false;
}
}catch (Exception e){
// TODO: 04/05/17 user messages & error warning
Toast.makeText(this, "Ocorreu um erro ao salvar a imagem, tente novamente.", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
isPhotoDelete = false;
isChangingPhoto = false;
}
@Override
......@@ -465,16 +512,6 @@ public class DependentUpdateActivity extends AppCompatActivity implements Depend
HashMap<String, String> values = new HashMap<>();
values.put(Utils.NAME, et_name.getText().toString().trim());
if(!et_cpf.getText().toString().isEmpty())
values.put(Utils.CPF, et_cpf.getText().toString().replaceAll("\\.", "").replace("-",""));
if(!et_rg.getText().toString().isEmpty())
values.put(Utils.RG, et_rg.getText().toString().trim());
values.put(Utils.BIRTH_DATE, DateValidator.stringToDate(et_birthdate.getText().toString(), false));
if (rb_no.isChecked()) {
values.put(Utils.PCD, null);
} else {
......@@ -485,23 +522,25 @@ public class DependentUpdateActivity extends AppCompatActivity implements Depend
}
}
if(!et_cep.getText().toString().isEmpty())
values.put(Utils.CEP, Mask.unmask(et_cep.getText().toString()));
values.put(Utils.NAME, et_name.getText().toString().trim());
values.put(Utils.CPF, et_cpf.getText().toString().replaceAll("\\.", "").replace("-",""));
values.put(Utils.RG, et_rg.getText().toString().trim());
if(!et_number.getText().toString().isEmpty())
values.put(Utils.ADDRESS_NUMBER, et_number.getText().toString().trim());
values.put(Utils.BIRTH_DATE, DateValidator.stringToDate(et_birthdate.getText().toString(), false));
values.put(Utils.CEP, Mask.unmask(et_cep.getText().toString()));
if(!et_complement.getText().toString().isEmpty())
values.put(Utils.ADDRESS_COMPLEMENT, et_complement.getText().toString().trim());
values.put(Utils.ADDRESS_NUMBER, et_number.getText().toString().trim());
if(!et_phone.getText().toString().isEmpty())
values.put(Utils.PHONE_1, Mask.unmask(et_phone.getText().toString()));
values.put(Utils.ADDRESS_COMPLEMENT, et_complement.getText().toString().trim());
if(!et_phone2.getText().toString().isEmpty())
values.put(Utils.PHONE_2, Mask.unmask(et_phone2.getText().toString()));
values.put(Utils.PHONE_1, Mask.unmask(et_phone.getText().toString()));
if(!et_email.getText().toString().isEmpty())
values.put(Utils.EMAIL, et_email.getText().toString().trim());
values.put(Utils.PHONE_2, Mask.unmask(et_phone2.getText().toString()));
values.put(Utils.EMAIL, et_email.getText().toString().trim());
values.put(Utils.ACTIVE, "true");
......@@ -510,7 +549,7 @@ public class DependentUpdateActivity extends AppCompatActivity implements Depend
if(isPhotoDelete){
values.put(Utils.PHOTO_TYPE, "delete");
}else{
values.put(Utils.PHOTO_CONTENT, Utils.getBase64FromFile(userImgHelper.getTempFilePath(Utils.USR_TEMP_PICT_FILE_NAME, 0)));
values.put(Utils.PHOTO_CONTENT, Utils.getBase64FromFile(userImgHelper.getTempFilePath(Utils.USR_TEMP_PICT_FILE_NAME, dependent.getInfo().getmId())));
values.put(Utils.PHOTO_TYPE, "image/png");
// TODO: 03/05/17 Change here to work with multi photo types
values.put(Utils.PHOTO_NAME, values.get(Utils.NAME).replaceAll(" ","") + ".png");
......@@ -553,13 +592,23 @@ public class DependentUpdateActivity extends AppCompatActivity implements Depend
et_rg.setText(dependent.getInfo().getmRg());
et_birthdate.setText(DateValidator.stringToDate(dependent.getInfo().getmBirth_Date(), true));
et_disability.setText(pcd);
et_cep.setText(dependent.getInfo().getmAddress().getZipcode());
et_number.setText(dependent.getInfo().getmAddressNumber());
et_address.setText(dependent.getInfo().getmAddress().getAddress());
et_neighborhood.setText(dependent.getInfo().getmAddress().getNeighborhood());
et_complement.setText(dependent.getInfo().getmAddress().getComplement());
et_city.setText(dependent.getInfo().getmCity().getmName());
et_state.setText(dependent.getInfo().getmState().getmName());
if(dependent.getInfo().getmAddress() != null){
et_cep.setText(dependent.getInfo().getmAddress().getZipcode());
et_address.setText(dependent.getInfo().getmAddress().getAddress());
et_neighborhood.setText(dependent.getInfo().getmAddress().getNeighborhood());
et_complement.setText(dependent.getInfo().getmAddress().getComplement());
}
else{
et_cep.setText("");
et_address.setText("");
et_neighborhood.setText("");
et_complement.setText("");
}
et_city.setText(dependent.getInfo().getmCity().getmName() == null ? "" : dependent.getInfo().getmCity().getmName() );
et_state.setText(dependent.getInfo().getmState().getmName() == null ? "" : dependent.getInfo().getmState().getmName());
et_phone.setText(dependent.getInfo().getmPhone1());
et_phone2.setText(dependent.getInfo().getmPhone2());
et_email.setText(dependent.getInfo().getmEmail());
......@@ -764,4 +813,38 @@ public class DependentUpdateActivity extends AppCompatActivity implements Depend
}
@Override
public void setCepFields(HashMap<String, String> values) {
if (!(values.get("address_su") == null || values.get("address_su").isEmpty() ||
values.get("neighborhood_su") == null || values.get("neighborhood_su").isEmpty() ||
values.get("cityname_su") == null || values.get("cityname_su").isEmpty() ||
values.get("statename_su") == null || values.get("statename_su").isEmpty())) {
et_address.setText(values.get("address_su"));
et_neighborhood.setText(values.get("neighborhood_su"));
et_city.setText(values.get("cityname_su"));
et_state.setText(values.get("statename_su"));
} else {
FragmentManager manager = getFragmentManager();
AccountActivity.CepWarningDialog cepWarningDialog = new AccountActivity.CepWarningDialog();
cepWarningDialog.show(manager, "cepWarningDialog");
et_cep.requestFocus();
et_cep.setText("");
}
}
@Override
public void setConnectionCepError(boolean enable) {
if(enable){
if(connectionErrorDialog == null){
connectionErrorDialog = new ConnectionErrorDialog();
}
Bundle bundle = new Bundle();
bundle.putString(ConnectionErrorDialog.DIALOG_MESSAGE, getString(R.string.dialog_cep_connection_error));
connectionErrorDialog.setArguments(bundle);
connectionErrorDialog.show(getFragmentManager(), ConnectionErrorDialog.DIALOG_CONNECTION_ERROR);
}
}
}
......@@ -145,6 +145,7 @@ public class DependentsListActivity extends AppCompatActivity implements Depende
public void afterPictureFailed(){
// TODO: 17/04/17 user messages & error warning
Toast.makeText(this, "Ocorreu um problema ao carregar a foto", Toast.LENGTH_SHORT).show();
}
......
......@@ -21,6 +21,7 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
......@@ -82,7 +83,6 @@ public class NewDependentActivity extends AppCompatActivity implements NewDepen
private final int REQUEST_PERMISSIONS = 1;
private final int LOAD_IMAGE_INTENT = 1;
private static final int TEMP_FILE_ID = 0;
......@@ -199,7 +199,6 @@ public class NewDependentActivity extends AppCompatActivity implements NewDepen
public void afterTextChanged(Editable s) {}
});
} else {
presenter.onCepNotFocused(Mask.unmask(et_cep.getText().toString()));
if(ConnectionChecker.hasConnection(getBaseContext())) {
presenter.onCepNotFocused(Mask.unmask(et_cep.getText().toString()));
}
......@@ -260,7 +259,7 @@ public class NewDependentActivity extends AppCompatActivity implements NewDepen
@Override
public void onClick(View view) {
if(!userImgHelper.existsPhoto(Utils.USR_TEMP_PICT_FILE_NAME, TEMP_FILE_ID)){
if(!userImgHelper.existsPhoto(Utils.USR_TEMP_PICT_FILE_NAME, Utils.NO_ID)){
checkBuildVersion();
return;
}
......@@ -627,8 +626,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(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);
intent.putExtra(MediaStore.EXTRA_OUTPUT, userImgHelper.getTempFileUri(Utils.USR_TEMP_PICT_FILE_NAME, Utils.NO_ID));
getBaseContext().grantUriPermission(packageName, userImgHelper.getTempFileUri(Utils.USR_TEMP_PICT_FILE_NAME, Utils.NO_ID), Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
cameraIntents.add(intent);
}
......@@ -682,10 +681,10 @@ public class NewDependentActivity extends AppCompatActivity implements NewDepen
//selected image path is returned by data.getData();
try {
if (isCamera) {
userImgHelper.convertToPng(Utils.USR_TEMP_PICT_FILE_NAME, TEMP_FILE_ID);
userImgHelper.convertToPng(Utils.USR_TEMP_PICT_FILE_NAME, Utils.NO_ID);
}
else {
userImgHelper.copyFileToPrivate(Utils.USR_TEMP_PICT_FILE_NAME, TEMP_FILE_ID, data.getData());
userImgHelper.copyFileToPrivate(Utils.USR_TEMP_PICT_FILE_NAME, Utils.NO_ID, data.getData());
}
} catch (Exception e) {
// TODO: 04/05/17 user messages & error warning
......@@ -693,7 +692,7 @@ public class NewDependentActivity extends AppCompatActivity implements NewDepen
e.printStackTrace();
}
Bitmap content = userImgHelper.getRoundBitmap(userImgHelper.getTempFileUri(Utils.USR_TEMP_PICT_FILE_NAME, TEMP_FILE_ID));
Bitmap content = userImgHelper.getRoundBitmap(userImgHelper.getTempFileUri(Utils.USR_TEMP_PICT_FILE_NAME, Utils.NO_ID));
//TODO: user messages & error warning (same as above).
if(content == null)
......@@ -728,10 +727,11 @@ public class NewDependentActivity extends AppCompatActivity implements NewDepen
public void onDependentReceived(FullDependent dependent){
try {
userImgHelper.copyFromTo(userImgHelper.getTempFileUri(Utils.USR_TEMP_PICT_FILE_NAME, 0), userImgHelper.getFileUri(Utils.USR_PICT_FILE_NAME, dependent.getInfo().getmId()));
userImgHelper.copyFromTo(userImgHelper.getTempFileUri(Utils.USR_TEMP_PICT_FILE_NAME, Utils.NO_ID), userImgHelper.getFileUri(Utils.USR_PICT_FILE_NAME, dependent.getInfo().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();
Toast.makeText(this, "Ocorreu um erro ao armazenar a foto(Código: 101)!", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
finally {
......
......@@ -4,6 +4,7 @@ import android.util.Log;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.InputMismatchException;
import java.util.Locale;
......@@ -99,9 +100,14 @@ public class DateValidator {
public static boolean isValidBirthDate(String birth_date){
Date today = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("MMM dd yyyy", Locale.getDefault());
Date hundredFiftyYearsOld = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(hundredFiftyYearsOld);
cal.add(Calendar.YEAR, -150);
hundredFiftyYearsOld = cal.getTime();
try {
Date birth = formatter.parse(birth_date);
return birth.before(today);
return birth.before(today) && birth.after(hundredFiftyYearsOld);
} catch (ParseException e) {
e.printStackTrace();
}
......
......@@ -87,6 +87,8 @@ public class UserImgHelper {
out.close();
parcelFD.close();
Log.d("FOTO","Arquivo atualizado-----------------------");
}
public void convertToPng(String fileName, long id) throws IOException {
......
......@@ -90,6 +90,7 @@ public class Utils {
public static final String PASSWORD = "password";
public static final String PASSWORD_CONFIRMATION = "password_confirmation";
public static final String CURRENT_PASSWORD = "current_password";
public static final int NO_ID = 0;
public static int getPixelValue(int dp, Context context) {
Resources resources = context.getResources();
......
......@@ -21,12 +21,14 @@ public class SectorArrayAdapter extends RecyclerView.Adapter{
private List<SectorInput> sectors;
private Context context;
private String blocked;
public SectorArrayAdapter(Context context, List<SectorInput> sectors){
super();
this.sectors = sectors;
this.context = context;
blocked = context.getResources().getString(R.string.blocked).toUpperCase();
}
@Override
......@@ -45,7 +47,7 @@ public class SectorArrayAdapter extends RecyclerView.Adapter{
String s;
sectorHolder.name.setText(sector.getName());
if(sector.isBlocked()){
s = sector.getAbsenceMax() + " (BLOQUEADO)";
s = sector.getAbsenceMax() + " (" + blocked + ")";
sectorHolder.absences.setTextColor(Color.RED);
}else{
s = sector.getAbsenceMax() + "";
......
......@@ -40,7 +40,7 @@ public class AccountOutput {
this.mCitizen = citizen;
}
public UserOutput getmCitizen() {
UserOutput getmCitizen() {
return mCitizen;
}
......
......@@ -50,7 +50,7 @@ public class Address implements Parcelable{
/**reads back fields IN THE ORDER they were written */
public Address(Parcel pc){
Address(Parcel pc){
mId = pc.readLong();
mZipcode = pc.readString();
mAddress = pc.readString();
......
......@@ -10,7 +10,7 @@ public class Cep {
@SerializedName("number")
private String mNumber;
public Cep(String number) {
Cep(String number) {
this.mNumber = number;
}
}
......@@ -128,9 +128,6 @@ public class ScheduleConfirmation implements Parcelable {
return startTime;
}
public Date getEndTime() {
return endTime;
}
}
......@@ -62,12 +62,6 @@ public class ServiceLocation implements Parcelable{
return 0;
}
@Override
public String toString() {
return mName + " tamanho: "+ schedules.size();
}
public String getmName(){
return mName;
}
......
......@@ -3,12 +3,18 @@ package br.ufpr.c3sl.agendador.agendador.presenters;
import android.content.Context;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import br.ufpr.c3sl.agendador.agendador.DependentUpdateActivity;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.models.Address;
import br.ufpr.c3sl.agendador.agendador.models.CepInput;
import br.ufpr.c3sl.agendador.agendador.models.DependentCreation;
import br.ufpr.c3sl.agendador.agendador.models.FullDependent;
import br.ufpr.c3sl.agendador.agendador.network.ApiEndpoints;
......@@ -88,6 +94,76 @@ public class DependentUpdatePresenter extends BasePresenter<DependentUpdateActiv
}
public void onCepNotFocused(String cep) {
Map<String, String> header = new HashMap<>();
header.put("Content-Type", "application/json");
ApiEndpoints service = ApiUtils.request(header);
CepInput cepInput = new CepInput(cep);
Call<Address> listCall = service.validateCep(cepInput);
presenter.view().setProgressBar(true);
final HashMap<String, String> values = new HashMap<>();
listCall.enqueue(new Callback<Address>() {
@Override
public void onResponse(Call<Address> call, Response<Address> response) {
int status = response.code();
Address address = response.body();
switch (status) {
case 200:
values.put("zipcode_su", address.getZipcode());
values.put("address_su", address.getAddress());
values.put("neighborhood_su", address.getNeighborhood());
values.put("complement_su", address.getComplement());
values.put("complement2_su", address.getComplement2());
values.put("cityname_su", address.getCity_name());
values.put("statename_su", address.getState_name());
presenter.view().setProgressBar(false);
break;
case 404:
Gson gson = new Gson();
TypeAdapter<Address> adapter = gson.getAdapter(Address.class);
try {
address = adapter.fromJson(response.errorBody().string());
} catch (IOException e) {
e.printStackTrace();
}
if (address.getCity_name() != null) {
values.put("cityname_su", address.getCity_name());
values.put("statename_su", address.getState_name());
} else {
values.put("cityname_su", "null");
values.put("statename_su", "null");
}