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

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()));
}
......
......@@ -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");
}
presenter.view().setProgressBar(false);
break;
case 422:
values.put("zipcode_su", null);
values.put("address_su", null);
values.put("neighborhood_su", null);
values.put("complement_su", null);
values.put("complement2_su", null);
values.put("cityname_su", null);
values.put("statename_su", null);
presenter.view().setProgressBar(false);
break;
default:
break;
}
presenter.view().setCepFields(values);
}
@Override
public void onFailure(Call<Address> call, Throwable t) {
presenter.view().setProgressBar(false);
presenter.view().setConnectionCepError(true);
}
});
}
@Override
protected void updateView() {
......
......@@ -117,13 +117,14 @@ public class DependentsListPresenter extends BasePresenter<DependentsListActivit
Log.d("Server response", getClass().getName() + ": 200 - Sucesso!");
Locale locale = new Locale("pt", "BR");
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", locale);
DateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", locale);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
sdf.setLenient(false);
Date remotePicture = null;
Date localPicture = null;
try {
localPicture = sdf.parse(osb.getString(Utils.PHOTO_NAME + dependent.getInfo().getmId(), ""));
remotePicture = sdf.parse(dependent.getInfo().getmPhoto_Update_At());
remotePicture = sdf2.parse(dependent.getInfo().getmPhoto_Update_At());
} catch (ParseException e) {
e.printStackTrace();
}
......
......@@ -91,7 +91,6 @@ public class LoginPresenter extends BasePresenter<LoginView> {
Call<AccountOutput> listCall = service.signIn(account);
loginPresenter.view().setProgressBar(true);
Log.d("Login Request", "pedindo login!!!");
listCall.enqueue(new Callback<AccountOutput>() {
@Override
......@@ -167,7 +166,7 @@ public class LoginPresenter extends BasePresenter<LoginView> {
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Bundle extras = new Bundle();
// TODO: 11/09/17 Corrigir o job para que pegue o token do momento!
// TODO: 11/09/17 Correct job take updated access-token!
extras.putString("access-token", osb.getString(Utils.ACCESS_TOKEN, null));
extras.putString("uid",osb.getString(Utils.UID, null));
......
......@@ -17,7 +17,6 @@ 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.models.UserOutput;
import br.ufpr.c3sl.agendador.agendador.network.ApiEndpoints;
import br.ufpr.c3sl.agendador.agendador.network.ApiUtils;
import okhttp3.Headers;
......@@ -55,8 +54,8 @@ public class NewDependentPresenter extends BasePresenter<NewDependentActivity> {
DependentCreation data = new DependentCreation(body);
if(body.get("photo_type") != null) {
data.getData().setImage(body.get("photo_type"), body.get("photo_name"), body.get("photo_content"));
if(body.get(Utils.PHOTO_TYPE) != null) {
data.getData().setImage(body.get(Utils.PHOTO_TYPE), body.get(Utils.PHOTO_NAME), body.get(Utils.PHOTO_CONTENT));
}
Call<FullDependent> listCall = service.createNewDependent(osb.getLong("id", 0), data);
......
......@@ -69,7 +69,7 @@ public class ScheduleConfirmationPresenter extends BasePresenter<ScheduleConfirm
public void onResponse(Call<ScheduleConfirmation> call, Response<ScheduleConfirmation> response) {
Headers headers = response.headers();
int status = response.code();
ScheduleConfirmation confirmationResponse = response.body();
//ScheduleConfirmation confirmationResponse = response.body();
updateHeaders(headers);
switch (status) {
case 200:
......
......@@ -12,4 +12,8 @@ public interface DependentUpdateView {
void setProgressBar(boolean enabled);
void setCepFields(HashMap<String, String> values);
void setConnectionCepError(boolean enable);
}
......@@ -172,4 +172,5 @@
<string name="attention">Atenção!</string>
<string name="dependents_description">Selecione o dependente:</string>
<string name="save">Salvar</string>
<string name="blocked">bloqueado</string>
</resources>
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