Commit 2c3810a7 authored by Lucas Braz Cunha's avatar Lucas Braz Cunha

Issue AGILE#199: [WP] Request Dependent image

Signed-off-by: Lucas Braz Cunha's avatarLucas B. Cunha <lbc16@inf.ufpr.br>
parent 5aac6844
......@@ -72,8 +72,7 @@ public class DependentUpdateActivity extends AppCompatActivity implements Depend
Bundle bundle = getIntent().getBundleExtra(Utils.CITIZEN_BUNDLE);
dependent = bundle.getParcelable(Utils.CITIZEN);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_acc);
setSupportActionBar(toolbar);
imv_profile = (ImageView) findViewById(R.id.img_account_photo);
bt_photo = (ImageButton) findViewById(R.id.btn_account_photo);
......@@ -117,6 +116,7 @@ public class DependentUpdateActivity extends AppCompatActivity implements Depend
rb_no = (RadioButton) findViewById(R.id.rb_has_disability_no);
rb_yes = (RadioButton) findViewById(R.id.rb_has_disability_yes);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_acc);
......@@ -130,9 +130,10 @@ public class DependentUpdateActivity extends AppCompatActivity implements Depend
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);
getSupportActionBar().setTitle(dependent.getInfo().getmName());
}catch (NullPointerException e){
e.printStackTrace();
}
......@@ -151,11 +152,13 @@ public class DependentUpdateActivity extends AppCompatActivity implements Depend
try {
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}catch (Exception e){
e.printStackTrace();
}
loadData();
}
@Override
......@@ -207,8 +210,8 @@ public class DependentUpdateActivity extends AppCompatActivity implements Depend
et_phone2.setText("");
et_email.setText("");
String pcd = osb.getString("pcd", null);
String citizenName = osb.getString("name", null);
String pcd = dependent.getInfo().getmPcd();
String citizenName = dependent.getInfo().getmName();
if (pcd == null || pcd.isEmpty()) {
rb_yes.setChecked(false);
......@@ -219,26 +222,25 @@ public class DependentUpdateActivity extends AppCompatActivity implements Depend
}
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_cpf.setText(dependent.getInfo().getmCpf());
et_rg.setText(dependent.getInfo().getmRg());
et_birthdate.setText(DateValidator.stringToDate(dependent.getInfo().getmBirth_Date(), 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));
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());
et_phone.setText(dependent.getInfo().getmPhone1());
et_phone2.setText(dependent.getInfo().getmPhone2());
et_email.setText(dependent.getInfo().getmEmail());
isChangingPhoto = false;
isPhotoDelete = false;
getSupportActionBar().setTitle(citizenName);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
......
......@@ -6,6 +6,7 @@ import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
......@@ -16,9 +17,11 @@ import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;
import java.io.IOException;
import java.util.List;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionErrorDialog;
import br.ufpr.c3sl.agendador.agendador.helpers.UserImgHelper;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.helpers.adapters.DependentsArrayAdapter;
import br.ufpr.c3sl.agendador.agendador.helpers.listeners.RecyclerViewItemListener;
......@@ -120,6 +123,23 @@ public class DependentsListActivity extends AppCompatActivity implements Depende
dg_connection_failure.show(getFragmentManager(), ConnectionErrorDialog.DIALOG_CONNECTION_ERROR);
}
@Override
public void afterSuccessfulPicture(Bitmap bitmap, long id){
// TODO: 17/04/17 user messages & error warning
UserImgHelper userImgHelper = new UserImgHelper(getBaseContext());
try {
userImgHelper.saveBitmap(bitmap, Utils.USR_PICT_FILE_NAME, id);
} catch (IOException e) {
Toast.makeText(this, "Ocorreu um problema ao atualizar sua foto de perfil", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
public void afterPictureFailed(){
Toast.makeText(this, "Ocorreu um problema ao carregar sua foto de perfil", Toast.LENGTH_SHORT).show();
}
@Override
public void onBackPressed() {
......
......@@ -156,7 +156,7 @@ public class ScheduleConfirmationActivity extends AppCompatActivity implements S
tv_sector.setText(sectorName);
tv_citizen.setText(citizen.getName());
tv_citizen.setText(citizen.getmName());
tv_location.setText(locationName);
tv_type.setText(typeName);
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy - HH:mm", Locale.getDefault());
......
......@@ -182,7 +182,7 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
TextView tv_citizen = (TextView) findViewById(R.id.tv_scheduling_citizen);
tv_citizen.setText(getResources().getString(R.string.scheduling_citizen) + " " + citizen.getName());
tv_citizen.setText(getResources().getString(R.string.scheduling_citizen) + " " + citizen.getmName());
spnr_sector = (Spinner) findViewById(R.id.spnr_scheduling_sector);
......
......@@ -42,7 +42,7 @@ public class CitizensArrayAdapter extends RecyclerView.Adapter {
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
CitizenHolder citizenHolder = (CitizenHolder) holder;
UserOutput citizen = citizens.get(position);
citizenHolder.name.setText(citizen.getName());
citizenHolder.name.setText(citizen.getmName());
}
/**
......
......@@ -27,7 +27,6 @@ public class City implements Parcelable{
this.mName = name;
}
/**reads back fields IN THE ORDER they were written */
private City(Parcel pc){
mId = pc.readLong();
......@@ -35,6 +34,7 @@ public class City implements Parcelable{
mName = pc.readString();
}
/** Static field used to regenerate object, individually or as arrays */
public static final Parcelable.Creator<City> CREATOR = new Parcelable.Creator<City>() {
public City createFromParcel(Parcel pc) {
......@@ -52,10 +52,14 @@ public class City implements Parcelable{
dest.writeString(mName);
}
@Override
public int describeContents() {
return 0;
}
public String getmName() {
return mName;
}
}
......@@ -43,7 +43,6 @@ public class FullDependent implements Parcelable{
}
};
/**
* Flatten this object in to a Parcel.
*
......@@ -58,8 +57,13 @@ public class FullDependent implements Parcelable{
dest.writeParcelable(info, flags);
}
@Override
public int describeContents() {
return 0;
}
public UserOutput getInfo() {
return info;
}
}
......@@ -49,7 +49,6 @@ public class State implements Parcelable{
}
};
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(mId);
......@@ -58,8 +57,13 @@ public class State implements Parcelable{
dest.writeString(mName);
}
@Override
public int describeContents() {
return 0;
}
public String getmName() {
return mName;
}
}
......@@ -20,7 +20,7 @@ public class UserOutput implements Parcelable {
private long mId;
@SerializedName("address_number")
private String mAddress_Number;
private String mAddressNumber;
@SerializedName("updated_at")
private String mUpdated_At;
......@@ -92,7 +92,7 @@ public class UserOutput implements Parcelable {
private String mAddressComplement;
public UserOutput(Map<String,String> values){
this.mAddress_Number = values.get("address_number");
this.mAddressNumber = values.get("address_number");
this.mRg = values.get("rg");
this.mEmail = values.get("email");
this.mPcd = values.get("pcd");
......@@ -114,7 +114,7 @@ public class UserOutput implements Parcelable {
City city, State state, Address address)
{
this.mAddress_Number = address_number;
this.mAddressNumber = address_number;
this.mUpdated_At = updated_at;
this.mId = id;
this.mPhoto_Update_At = photo_update_at;
......@@ -137,7 +137,6 @@ public class UserOutput implements Parcelable {
this.mAddress = address;
}
/** Static field used to regenerate object, individually or as arrays */
public static final Parcelable.Creator<UserOutput> CREATOR = new Parcelable.Creator<UserOutput>() {
public UserOutput createFromParcel(Parcel pc) {
......@@ -151,7 +150,7 @@ public class UserOutput implements Parcelable {
/**reads back fields IN THE ORDER they were written */
private UserOutput(Parcel pc){
mId = pc.readLong();
mAddress_Number = pc.readString();
mAddressNumber = pc.readString();
mUpdated_At = pc.readString();
mPhoto_Update_At = pc.readString();
mPhoto_Content_Type = pc.readString();
......@@ -177,12 +176,13 @@ public class UserOutput implements Parcelable {
mAddressComplement = pc.readString();
}
public void save(Context context) {
ObscuredSharedPreferences osb = ObscuredSharedPreferences.getPrefs(context, "Agendador",
Context.MODE_PRIVATE);
osb.edit().putString("address.neighborhood", this.mAddress.getNeighborhood()).apply();
osb.edit().putString("address_number", this.mAddress_Number).apply();
osb.edit().putString("address_number", this.mAddressNumber).apply();
osb.edit().putString("updated_at", this.mUpdated_At).apply();
osb.edit().putString("address.address", this.mAddress.getAddress()).apply();
osb.edit().putString("avatar_updated_at", this.mPhoto_Update_At).apply();
......@@ -210,7 +210,6 @@ public class UserOutput implements Parcelable {
osb.edit().putString("state.abbreviation", this.mState.mAbbreviation).apply();
}
/**
* Flatten this object in to a Parcel.
*
......@@ -221,7 +220,7 @@ public class UserOutput implements Parcelable {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(mId);
dest.writeString(mAddress_Number);
dest.writeString(mAddressNumber);
dest.writeString(mUpdated_At);
dest.writeString(mPhoto_Update_At);
dest.writeString(mPhoto_Content_Type);
......@@ -247,7 +246,7 @@ public class UserOutput implements Parcelable {
dest.writeString(mAddressComplement);
}
public String getName(){
public String getmName(){
return this.mName;
}
......@@ -262,4 +261,51 @@ public class UserOutput implements Parcelable {
}
public String getmRg() {
return mRg;
}
public String getmPcd() {
return mPcd;
}
public String getmPhone2() {
return mPhone2;
}
public String getmPhone1() {
return mPhone1;
}
public String getmCpf() {
return mCpf;
}
public String getmBirth_Date() {
return mBirth_Date;
}
public String getmEmail() {
return mEmail;
}
public City getmCity() {
return mCity;
}
public State getmState() {
return mState;
}
public Address getmAddress() {
return mAddress;
}
public String getmAddressComplement() {
return mAddressComplement;
}
public String getmAddressNumber() {
return mAddressNumber;
}
}
package br.ufpr.c3sl.agendador.agendador.presenters;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import com.firebase.jobdispatcher.Constraint;
import com.firebase.jobdispatcher.Job;
import com.firebase.jobdispatcher.Lifetime;
import com.firebase.jobdispatcher.RetryStrategy;
import com.firebase.jobdispatcher.Trigger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import br.ufpr.c3sl.agendador.agendador.DependentsListActivity;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
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.network.ApiEndpoints;
import br.ufpr.c3sl.agendador.agendador.network.ApiUtils;
import br.ufpr.c3sl.agendador.agendador.services.ImageUpdateService;
import okhttp3.Headers;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
......@@ -98,7 +109,7 @@ public class DependentsListPresenter extends BasePresenter<DependentsListActivit
case 200:
Log.d("Server response", getClass().getName() + ": 200 - Sucesso!");
presenter.view().setProgressBar(false);
presenter.view().onDependentReceived(dependent);
presenter.requestImage(dependent);
break;
default:
Log.e("Server response", getClass().getName() + ": ERRO:" + status);
......@@ -118,6 +129,51 @@ public class DependentsListPresenter extends BasePresenter<DependentsListActivit
}
private void requestImage(final FullDependent dependent) {
Map<String, String> header = new HashMap<>();
final String uid = osb.getString("uid", null);
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", uid);
ApiEndpoints service = ApiUtils.request(header);
Call<ResponseBody> listCall = service.requestPhoto(dependent.getInfo().getmId(), "large");
presenter.view().setProgressBar(true);
listCall.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
int status = response.code();
Log.d("Server response", this.getClass().getName() + ": Retorno da request de imagem: " + status);
switch (status) {
case 200:
presenter.view().afterSuccessfulPicture(BitmapFactory.decodeStream(response.body().byteStream()), osb.getLong("id", 0));
break;
case 404:
//user has no picture on back-end side
break;
default:
presenter.view().afterPictureFailed();
break;
}
presenter.view().onDependentReceived(dependent);
presenter.view().setProgressBar(false);
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
presenter.view().setProgressBar(false);
presenter.view().afterPictureFailed();
}
});
}
@Override
protected void updateView() {
......
......@@ -135,8 +135,6 @@ public class LoginPresenter extends BasePresenter<LoginView> {
header.put("client", osb.getString("client", null));
header.put("uid", uid);
loginPresenter.view().setProgressBar(true);
ApiEndpoints service = ApiUtils.request(header);
Call<ResponseBody> listCall = service.requestPhoto(osb.getLong("id", 0), "large");
......
package br.ufpr.c3sl.agendador.agendador.views;
import android.graphics.Bitmap;
import java.util.List;
import br.ufpr.c3sl.agendador.agendador.models.Dependent;
......@@ -18,4 +20,8 @@ public interface DependentsListView {
void successfulDependents(List<Dependent> dependents);
void onDependentReceived(FullDependent dependent);
void afterSuccessfulPicture(Bitmap bitmap, long id);
void afterPictureFailed();
}
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