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

Issue AGILE#203: [WP] Implementing NewDependentActivity

Signed-off-by: Lucas Braz Cunha's avatarLucas B. Cunha <lbc16@inf.ufpr.br>
parent 532080c0
package br.ufpr.c3sl.agendador.agendador;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
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.presenters.DependentsUpdatePresenter;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.views.DependentsUpdateView;
......@@ -15,7 +20,14 @@ public class DependentUpdateActivity extends AppCompatActivity implements Depend
private DependentsUpdatePresenter presenter;
private Dependent dependent;
private FullDependent dependent;
private boolean hasChanged;
private ImageView imv_profile;
private ImageButton bt_photo;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -35,8 +47,29 @@ public class DependentUpdateActivity extends AppCompatActivity implements Depend
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_acc);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
imv_profile = (ImageView) findViewById(R.id.img_account_photo);
bt_photo = (ImageButton) findViewById(R.id.btn_account_photo);
bt_photo.setVisibility(View.VISIBLE);
final AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appbar_dependents);
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
float percentage = 1.5f * ((float) Math.abs(verticalOffset) / appBarLayout.getTotalScrollRange());
imv_profile.setAlpha(1 - percentage);
bt_photo.setAlpha(1 - percentage);
}
});
try {
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}catch (Exception e){
e.printStackTrace();
}
hasChanged = false;
}
@Override
......@@ -68,4 +101,16 @@ public class DependentUpdateActivity extends AppCompatActivity implements Depend
return super.onOptionsItemSelected(item);
}
}
private void loadData(){
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
}
......@@ -23,6 +23,7 @@ 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;
import br.ufpr.c3sl.agendador.agendador.models.Dependent;
import br.ufpr.c3sl.agendador.agendador.models.FullDependent;
import br.ufpr.c3sl.agendador.agendador.presenters.DependentsListPresenter;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.views.DependentsListView;
......@@ -75,11 +76,7 @@ public class DependentsListActivity extends AppCompatActivity implements Depende
rv_dependents.addOnItemTouchListener(new RecyclerViewItemListener(getApplicationContext(), rv_dependents,
new RecyclerViewItemListener.RecyclerTouchListener() {
public void onClickItem(View v, int position) {
Intent intent = new Intent(DependentsListActivity.this, DependentUpdateActivity.class);
Bundle bundle = new Bundle();
bundle.putParcelable(Utils.CITIZEN, dependents.get(position));
intent.putExtra(Utils.CITIZEN_BUNDLE, bundle);
startActivity(intent);
presenter.requestDependentInfo(dependents.get(position).getId());
}
public void onLongClickItem(View v, int position) {
......@@ -102,6 +99,17 @@ public class DependentsListActivity extends AppCompatActivity implements Depende
}
public void onDependentReceived(FullDependent dependent){
Intent intent = new Intent(DependentsListActivity.this, DependentUpdateActivity.class);
Bundle bundle = new Bundle();
bundle.putParcelable(Utils.CITIZEN, dependent);
intent.putExtra(Utils.CITIZEN_BUNDLE, bundle);
startActivity(intent);
finish();
}
public void onRequestFailure(){
Bundle bundle = new Bundle();
if(dg_connection_failure == null){
......
......@@ -21,7 +21,6 @@ import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.Toolbar;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
......@@ -32,7 +31,8 @@ import android.widget.TextView;
import android.widget.Toast;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.helpers.UserPhotoHelper;
import br.ufpr.c3sl.agendador.agendador.helpers.UserImgHelper;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.presenters.HomePresenter;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.views.HomeView;
......@@ -49,13 +49,15 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
private DrawerLayout drawer;
private NavigationView navigationView;
private TextView tv_presentation;
private ConfirmationDialog confirmationDialog;
private UserImgHelper userImgHelper;
private ImageView drawerProfilePicture;
private Snackbar snackbar;
public static String SHOW_SCHEDULE_SNACKBAR = "snack_bar";
private long id;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -75,7 +77,7 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
ObscuredSharedPreferences osb = ObscuredSharedPreferences.getPrefs(this, "Agendador", Context.MODE_PRIVATE);
String citizenName = osb.getString("name", null);
String citizenCity = osb.getString("city.name", null);
id = osb.getLong("id", 0);
ActionMenuView actionMenuView = (ActionMenuView) toolbar.findViewById(R.id.agendador_toolbar_menu);
menuBuilder = (MenuBuilder) actionMenuView.getMenu();
//noinspection RestrictedApi
......@@ -104,9 +106,9 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
View headerView = navigationView.getHeaderView(0);
ImageView drawerProfilePicture = (ImageView) headerView.findViewById(R.id.img_drawerheader_citizen_photo);
drawerProfilePicture = (ImageView) headerView.findViewById(R.id.img_drawerheader_citizen_photo);
UserPhotoHelper userPhotoHelper = new UserPhotoHelper(getBaseContext());
userImgHelper = new UserImgHelper(getBaseContext());
TextView drawerCitizenName = (TextView) headerView.findViewById(R.id.tv_drawerheader_citizen_name);
......@@ -116,8 +118,8 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
drawerCityName.setText(citizenCity);
if(userPhotoHelper.existsPhoto()){
userPhotoHelper.updateImgView(drawerProfilePicture, userPhotoHelper.getPhotoFileUri());
if(userImgHelper.existsPhoto(Utils.USR_PICT_FILE_NAME, id)){
drawerProfilePicture.setImageBitmap(userImgHelper.getRoundBitmap(userImgHelper.getFileUri(Utils.USR_PICT_FILE_NAME, id)));
}
drawerHamburger.setOnClickListener(new View.OnClickListener() {
......@@ -172,8 +174,16 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
protected void onResume() {
super.onResume();
presenter.bindView(this);
MenuItem item = navigationView.getMenu().findItem(R.id.nav_my_info);
item.setChecked(false);
int size = navigationView.getMenu().size();
for (int i = 0; i < size; i++) {
navigationView.getMenu().getItem(i).setChecked(false);
}
if(userImgHelper.existsPhoto(Utils.USR_PICT_FILE_NAME, id)){
drawerProfilePicture.setImageBitmap(userImgHelper.getRoundBitmap(userImgHelper.getFileUri(Utils.USR_PICT_FILE_NAME, id)));
}else{
drawerProfilePicture.setImageBitmap(null);
}
}
@Override
......
......@@ -24,7 +24,8 @@ import java.io.IOException;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionChecker;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionErrorDialog;
import br.ufpr.c3sl.agendador.agendador.helpers.Mask;
import br.ufpr.c3sl.agendador.agendador.helpers.UserPhotoHelper;
import br.ufpr.c3sl.agendador.agendador.helpers.UserImgHelper;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.presenters.LoginPresenter;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.views.LoginView;
......@@ -207,13 +208,12 @@ public class LoginActivity extends AppCompatActivity implements LoginView {
}
@Override
public void afterSuccessfulPhoto(Bitmap bitmap, String uid){
public void afterSuccessfulPhoto(Bitmap bitmap, long id){
Log.d("AAAAAAAAAa", "CHEGUEI NO PHOTO SUCCESFULL");
// TODO: 17/04/17 user messages & error warning
UserPhotoHelper userPhotoHelper = new UserPhotoHelper(getBaseContext(), uid);
UserImgHelper userImgHelper = new UserImgHelper(getBaseContext());
try {
userPhotoHelper.saveBitmap(bitmap);
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();
......
......@@ -30,7 +30,7 @@ import java.util.Locale;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionErrorDialog;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.helpers.UserPhotoHelper;
import br.ufpr.c3sl.agendador.agendador.helpers.UserImgHelper;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.models.ScheduleConfirmation;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
......@@ -61,6 +61,8 @@ public class ScheduleConfirmationActivity extends AppCompatActivity implements S
private static final String EXIT_CONFIRMATION_DIALOG_TAG = "exit_dialog";
private long id;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -88,6 +90,7 @@ public class ScheduleConfirmationActivity extends AppCompatActivity implements S
ObscuredSharedPreferences osb = ObscuredSharedPreferences.getPrefs(this, "Agendador", Context.MODE_PRIVATE);
String citizenName = osb.getString("name", null);
String citizenCity = osb.getString("city.name", null);
id = osb.getLong("id", 0);
ActionMenuView actionMenuView = (ActionMenuView) toolbar.findViewById(R.id.agendador_toolbar_menu);
menuBuilder = (MenuBuilder) actionMenuView.getMenu();
......@@ -119,7 +122,7 @@ public class ScheduleConfirmationActivity extends AppCompatActivity implements S
ImageView drawerProfilePicture = (ImageView) headerView.findViewById(R.id.img_drawerheader_citizen_photo);
UserPhotoHelper userPhotoHelper = new UserPhotoHelper(getBaseContext());
UserImgHelper userImgHelper = new UserImgHelper(getBaseContext());
TextView drawerCitizenName = (TextView) headerView.findViewById(R.id.tv_drawerheader_citizen_name);
......@@ -129,8 +132,8 @@ public class ScheduleConfirmationActivity extends AppCompatActivity implements S
drawerCityName.setText(citizenCity);
if(userPhotoHelper.existsPhoto()){
userPhotoHelper.updateImgView(drawerProfilePicture, userPhotoHelper.getPhotoFileUri());
if(userImgHelper.existsPhoto(Utils.USR_PICT_FILE_NAME, id)){
drawerProfilePicture.setImageBitmap(userImgHelper.getRoundBitmap(userImgHelper.getFileUri(Utils.USR_PICT_FILE_NAME, id)));
}
drawerHamburger.setOnClickListener(new View.OnClickListener() {
......
......@@ -41,7 +41,7 @@ import java.util.Locale;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionErrorDialog;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.helpers.UserPhotoHelper;
import br.ufpr.c3sl.agendador.agendador.helpers.UserImgHelper;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.helpers.adapters.HintAdapter;
import br.ufpr.c3sl.agendador.agendador.helpers.adapters.HintEnableAdapter;
......@@ -137,6 +137,8 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
private static final String SCHEDULES_TIME_ARRAY = "schedules_time_array";
private long id;
@Override
......@@ -193,6 +195,7 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
ObscuredSharedPreferences osb = ObscuredSharedPreferences.getPrefs(this, "Agendador", Context.MODE_PRIVATE);
String citizenName = osb.getString("name", null);
final String citizenCity = osb.getString("city.name", null);
id = osb.getLong("id", 0);
NavigationView navigationView = (NavigationView) findViewById(R.id.scheduling_navigation_view);
navigationView.getMenu().findItem(R.id.nav_schedule).setChecked(true);
......@@ -201,7 +204,7 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
ImageView drawerProfilePicture = (ImageView) headerView.findViewById(R.id.img_drawerheader_citizen_photo);
UserPhotoHelper userPhotoHelper = new UserPhotoHelper(getBaseContext());
UserImgHelper userImgHelper = new UserImgHelper(getBaseContext());
TextView drawerCitizenName = (TextView) headerView.findViewById(R.id.tv_drawerheader_citizen_name);
......@@ -225,8 +228,8 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
confirmationDialogFragment = new ConfirmationDialogFragment();
if (userPhotoHelper.existsPhoto()) {
userPhotoHelper.updateImgView(drawerProfilePicture, userPhotoHelper.getPhotoFileUri());
if (userImgHelper.existsPhoto(Utils.USR_PICT_FILE_NAME, id)) {
drawerProfilePicture.setImageBitmap(userImgHelper.getRoundBitmap(userImgHelper.getFileUri(Utils.USR_PICT_FILE_NAME, id)));
}
navigationView.setNavigationItemSelectedListener(this);
......
......@@ -10,8 +10,8 @@ import android.graphics.Shader;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.util.Log;
import android.webkit.MimeTypeMap;
import android.widget.ImageView;
import java.io.File;
import java.io.FileDescriptor;
......@@ -25,66 +25,47 @@ import java.io.IOException;
// TODO: 03/05/17 Add multi file extension usage.
public class UserPhotoHelper {
public class UserImgHelper {
private String filePath;
private String fileDir;
private Context mContext;
private String userUid;
private ObscuredSharedPreferences osb;
//File used to store selected picture during update "stage"
private File tempPhoto;
//file used to store the actual picture
private File photo;
private Uri photoFileUri;
private Uri tempPhotoFileUri;
private static String extension = ".bmp";
private static String tempFileIdentifier = "temp_";
//Temp* is used during update "stage", when it's not confirmed.
//Constructor for LoginActivity use
// TODO: 08/05/17 check usage of getExternalFilesDirs
//https://developer.android.com/guide/topics/data/data-storage.html
public UserPhotoHelper(Context context, String uid){
public UserImgHelper(Context context){
this.mContext = context;
this.filePath = mContext.getExternalFilesDir(null) + File.separator + Utils.DIR_PICTRS + File.separator + Utils.USR_PICT_FILE_NAME;
this.photo = new File(filePath + uid + ".bmp");
this.photoFileUri = Uri.fromFile(photo);
this.fileDir = mContext.getExternalFilesDir(null) + File.separator + Utils.DIR_PICTRS;
}
//Function to save bitmap received from server on login
public void saveBitmap(Bitmap bmp) throws IOException {
File f2 = new File(mContext.getExternalFilesDir(null) + File.separator + Utils.DIR_PICTRS + File.separator);
public void saveBitmap(Bitmap bmp, String fileName, long id) throws IOException {
File f2 = new File(fileDir + File.separator);
f2.mkdirs();
File f = new File(photoFileUri.getPath());
File f = new File(getFilePath(fileName, id));
f.createNewFile();
FileOutputStream out = new FileOutputStream(photoFileUri.getPath());
FileOutputStream out = new FileOutputStream(getFilePath(fileName, id));
bmp.compress(Bitmap.CompressFormat.PNG, 100, out); //100-best quality
out.close();
}
//Adding user id to handle multi-user experience
public UserPhotoHelper(Context context) {
this.mContext = context;
osb = ObscuredSharedPreferences.getPrefs(mContext, "Agendador", Context.MODE_PRIVATE);
this.filePath = mContext.getExternalFilesDir(null) + File.separator + Utils.DIR_PICTRS + File.separator + Utils.USR_PICT_FILE_NAME;
initVariables();
}
private void initVariables() {
this.userUid = osb.getString("uid", null);
this.photo = new File(filePath + userUid + ".bmp");
this.tempPhoto = new File(filePath + "temp_" + userUid);
this.photoFileUri = Uri.fromFile(photo);
this.tempPhotoFileUri = Uri.fromFile(tempPhoto);
}
//TODO: check usage of ".gif" files
public void copyFileToPrivate(Uri src) throws Exception {
public void copyFileToPrivate(String fileName, long id, Uri src) throws Exception {
String srcExtension = MimeTypeMap.getSingleton().
getExtensionFromMimeType(mContext.getContentResolver().getType(photoFileUri));
getExtensionFromMimeType(mContext.getContentResolver().getType(getFileUri(fileName, id)));
if (MimeTypeMap.getSingleton().hasMimeType(mContext.getContentResolver().getType(photoFileUri))) {
if (MimeTypeMap.getSingleton().hasMimeType(mContext.getContentResolver().getType(getFileUri(fileName, id)))) {
srcExtension = srcExtension.toLowerCase();
if (!srcExtension.equals("jpeg") && !srcExtension.equals("jpg") &&
!srcExtension.equals("png")) {
......@@ -92,11 +73,11 @@ public class UserPhotoHelper {
}
}
copyFileToUri(src, tempPhotoFileUri);
copyFromTo(src, getTempFileUri(fileName, id));
}
private void copyFileToUri(Uri src, Uri dest) throws Exception {
public void copyFromTo(Uri src, Uri dest) throws Exception {
ParcelFileDescriptor parcelFD = mContext.getContentResolver().openFileDescriptor(src, "r");
FileDescriptor fileSource = parcelFD.getFileDescriptor();
......@@ -108,29 +89,34 @@ public class UserPhotoHelper {
}
public void convertToPng(String fileName, long id) throws IOException {
public void convertToPng() throws IOException {
Bitmap bmp = BitmapFactory.decodeFile(getTempFilePath(fileName,id));
Bitmap bmp = BitmapFactory.decodeFile(tempPhotoFileUri.getPath());
FileOutputStream out = new FileOutputStream(tempPhotoFileUri.getPath());
FileOutputStream out = new FileOutputStream(getTempFilePath(fileName, id));
bmp.compress(Bitmap.CompressFormat.PNG, 100, out); //100-best quality
out.close();
}
public void confirmUpdate(boolean isDelete) throws Exception {
if (isDelete) {
photo.delete();
return;
}
copyFileToUri(tempPhotoFileUri, photoFileUri);
public boolean deletePhoto(String fileName, long id)throws Exception{
File photoDelete = new File(getFilePath(fileName, id));
return photoDelete.delete();
}
public boolean updateImgView(ImageView imgView, Uri fileUri) {
public boolean existsPhoto(String fileName, long id) {
String filePath = fileDir + File.separator + fileName + id;
File photo = new File(filePath + extension);
return photo.exists();
}
public Bitmap getRoundBitmap(Uri fileUri) {
Bitmap circleBitmap;
File f = new File(fileUri.getPath());
if (f.exists() && !Utils.isImage(f)) {
return false;
return null;
}
ParcelFileDescriptor parcelFD = null;
try {
......@@ -168,7 +154,7 @@ public class UserPhotoHelper {
bitmap = ThumbnailUtils.extractThumbnail(bitmap, dimension, dimension, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
//rounding the image
Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Paint paint = new Paint();
......@@ -178,12 +164,10 @@ public class UserPhotoHelper {
c.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint);
imgView.setImageBitmap(circleBitmap);
} catch (FileNotFoundException e) {
// as the file is created previously this catch is not needed.
e.printStackTrace();
return false;
return null;
} finally {
if (parcelFD != null)
try {
......@@ -192,27 +176,27 @@ public class UserPhotoHelper {
// ignored
}
}
return true;
}
public boolean existsPhoto() {
return photo.exists();
return circleBitmap;
}
public Uri getTempFileUri() {
return tempPhotoFileUri;
private String getFilePath(String fileName, long id) {
return fileDir + File.separator + fileName + id + extension;
}
public String getUserUid() {
return this.userUid;
public String getTempFilePath(String fileName, long id){
return fileDir + File.separator + tempFileIdentifier + fileName + id + extension;
}
public String getTempFilePath() {
return tempPhoto.getAbsolutePath();
public Uri getTempFileUri(String fileName, long id) {
String filePath = fileDir + File.separator + tempFileIdentifier +fileName + id + extension;
File tempFile = new File(filePath);
return Uri.fromFile(tempFile);
}
public Uri getPhotoFileUri() {
return photoFileUri;
public Uri getFileUri(String fileName, long id) {
String filePath = fileDir + File.separator + fileName + id;
File photo = new File(filePath + extension);
return Uri.fromFile(photo);
}
......
......@@ -26,7 +26,7 @@ public class Dependent implements Parcelable{
@SerializedName("cpf")
private String cpf;
Dependent(Parcel pc){
private Dependent(Parcel pc){
id = pc.readLong();
birthDate = pc.readString();
name = pc.readString();
......@@ -69,4 +69,8 @@ public class Dependent implements Parcelable{
public String getName() {
return name;
}
public long getId() {
return id;
}
}
package br.ufpr.c3sl.agendador.agendador.models;
import android.os.Parcel;
import android.os.Parcelable;
import com.google.gson.annotations.SerializedName;
/**
* Created by lbc16 on 24/08/17.
*/
public class FullDependent implements Parcelable{
@SerializedName("id")
private long id;
@SerializedName("deactivated")
private String deactivatedDate;
@SerializedName("citizen")
private UserOutput info;
public FullDependent(long id, String deactivatedDate, UserOutput info) {
this.id = id;
this.deactivatedDate = deactivatedDate;
this.info = info;
}
/**reads back fields IN THE ORDER they were written */
private FullDependent(Parcel pc){
id = pc.readLong();
deactivatedDate = pc.readString();
info = pc.readParcelable(UserOutput.class.getClassLoader());
}
/** Static field used to regenerate object, individually or as arrays */
public static final Parcelable.Creator<FullDependent> CREATOR = new Parcelable.Creator<FullDependent>() {
public FullDependent createFromParcel(Parcel pc) {
return new FullDependent(pc);
}
public FullDependent[] newArray(int size) {
return new FullDependent[size];
}
};
/**
* Flatten this object in to a Parcel.
*
* @param dest The Parcel in which the object should be written.
* @param flags Additional flags about how the object should be written.
* May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}.
*/
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(id);
dest.writeString(deactivatedDate);
dest.writeParcelable(info, flags);
}
@Override
public int describeContents() {
return 0;
}
}
......@@ -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.FullDependent;
import br.ufpr.c3sl.agendador.agendador.models.ScheduleConfirmation;
import br.ufpr.c3sl.agendador.agendador.models.SectorInput;
import br.ufpr.c3sl.agendador.agendador.models.ServiceLocation;
......@@ -21,6 +22,7 @@ import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.PATCH;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Path;
......@@ -70,4 +72,11 @@ public interface ApiEndpoints {
@GET("citizens/{id_user}/dependants")
Call<List<Dependent>> requestDependentsList(@Path("id_user") long citizenId);
@GET("citizens/{id_user}/dependants/{id_dependent}")
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);
}
\ No newline at end of file
......@@ -10,6 +10,7 @@ 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.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 okhttp3.Headers;
......@@ -74,6 +75,49 @@ public class DependentsListPresenter extends BasePresenter<DependentsListActivit
}
public void requestDependentInfo(long dependentId){