Commit 532080c0 authored by Lucas Braz Cunha's avatar Lucas Braz Cunha

Issue AGILE#201: Listing dependents

Signed-off-by: Lucas Braz Cunha's avatarLucas B. Cunha <lbc16@inf.ufpr.br>
parent 032b0613
......@@ -54,7 +54,8 @@
android:screenOrientation="portrait" />
<activity android:name=".CitizenActivity" />
<activity android:name=".ScheduleConfirmationActivity" />
<activity android:name=".DependentsActivity"></activity>
<activity android:name=".DependentUpdateActivity" />
<activity android:name=".NewDependentActivity"></activity>
</application>
</manifest>
\ No newline at end of file
package br.ufpr.c3sl.agendador.agendador;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.models.Dependent;
import br.ufpr.c3sl.agendador.agendador.presenters.DependentsUpdatePresenter;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.views.DependentsUpdateView;
public class DependentUpdateActivity extends AppCompatActivity implements DependentsUpdateView {
private DependentsUpdatePresenter presenter;
private Dependent dependent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dependents);
if(savedInstanceState == null){
presenter = new DependentsUpdatePresenter(this);
}
else{
presenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
if(presenter == null)
presenter = new DependentsUpdatePresenter(this);
}
Bundle bundle = getIntent().getBundleExtra(Utils.CITIZEN_BUNDLE);
dependent = bundle.getParcelable(Utils.CITIZEN);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_acc);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
protected void onResume() {
super.onResume();
presenter.bindView(this);
}
@Override
protected void onPause() {
super.onPause();
presenter.unbindView();
}
@Override
public void onSaveInstanceState(Bundle outState) {
PresenterManager.getInstance().savePresenter(presenter, outState);
super.onSaveInstanceState(outState);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
package br.ufpr.c3sl.agendador.agendador;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import br.ufpr.c3sl.agendador.agendador.presenters.DependentsPresenter;
import br.ufpr.c3sl.agendador.agendador.views.DependentsView;
public class DependentsActivity extends AppCompatActivity implements DependentsView {
private DependentsPresenter presenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dependents);
}
}
......@@ -7,19 +7,22 @@ import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;
import java.util.List;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionErrorDialog;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.helpers.adapters.CitizensArrayAdapter;
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.UserOutput;
import br.ufpr.c3sl.agendador.agendador.models.Dependent;
import br.ufpr.c3sl.agendador.agendador.presenters.DependentsListPresenter;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.views.DependentsListView;
......@@ -38,7 +41,8 @@ public class DependentsListActivity extends AppCompatActivity implements Depende
private ConnectionFailureDialog dg_connection_failure;
private List<UserOutput> dependents;
private List<Dependent> dependents;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -53,6 +57,8 @@ public class DependentsListActivity extends AppCompatActivity implements Depende
setContentView(R.layout.activity_dependents_list);
FloatingActionButton fab_new_dependent = (FloatingActionButton) findViewById(R.id.fab_new_dependent);
pb_dependents = (ProgressBar) findViewById(R.id.pb_dependentact);
rv_dependents = (RecyclerView) findViewById(R.id.rv_dependents);
......@@ -63,12 +69,13 @@ public class DependentsListActivity extends AppCompatActivity implements Depende
rv_dependents.setLayoutManager(layout);
rv_dependents.setVisibility(View.INVISIBLE);
rv_dependents.addOnItemTouchListener(new RecyclerViewItemListener(getApplicationContext(), rv_dependents,
new RecyclerViewItemListener.RecyclerTouchListener() {
public void onClickItem(View v, int position) {
Intent intent = new Intent(DependentsListActivity.this, DependentsActivity.class);
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);
......@@ -76,17 +83,25 @@ public class DependentsListActivity extends AppCompatActivity implements Depende
}
public void onLongClickItem(View v, int position) {
//do nothing.
//Do nothing
}
}));
fab_new_dependent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(DependentsListActivity.this, NewDependentActivity.class);
startActivity(intent);
}
});
}
/*public void successfulCitizens(List<UserOutput> citizens) {
this.citizens = citizens;
public void successfulDependents(List<Dependent> dependents) {
this.dependents = dependents;
showLayout(true);
}
*/
public void onRequestFailure(){
Bundle bundle = new Bundle();
if(dg_connection_failure == null){
......@@ -95,7 +110,12 @@ public class DependentsListActivity extends AppCompatActivity implements Depende
bundle.putString(ConnectionErrorDialog.DIALOG_MESSAGE, getString(R.string.dialog_term_error));
dg_connection_failure.setArguments(bundle);
dg_connection_failure.show(getFragmentManager(), ConnectionErrorDialog.DIALOG_CONNECTION_ERROR);
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
@Override
......@@ -118,9 +138,9 @@ public class DependentsListActivity extends AppCompatActivity implements Depende
super.onSaveInstanceState(outState);
}
public void showLayout(boolean enabled) {
private void showLayout(boolean enabled) {
if(enabled){
rv_dependents.setAdapter(new CitizensArrayAdapter(this, dependents));
rv_dependents.setAdapter(new DependentsArrayAdapter(dependents, this));
rv_dependents.setVisibility(View.VISIBLE);
}
}
......@@ -148,13 +168,19 @@ public class DependentsListActivity extends AppCompatActivity implements Depende
.setTitle(getString(R.string.warningDialog_title))
.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Activity activity = getActivity();
activity.onBackPressed();
dismiss();
}
});
return builder.create();
}
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
Activity activity = getActivity();
activity.onBackPressed();
}
}
}
......@@ -21,6 +21,7 @@ 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;
......
......@@ -11,6 +11,7 @@ import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextWatcher;
import android.text.style.StyleSpan;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
......@@ -207,6 +208,8 @@ public class LoginActivity extends AppCompatActivity implements LoginView {
@Override
public void afterSuccessfulPhoto(Bitmap bitmap, String uid){
Log.d("AAAAAAAAAa", "CHEGUEI NO PHOTO SUCCESFULL");
// TODO: 17/04/17 user messages & error warning
UserPhotoHelper userPhotoHelper = new UserPhotoHelper(getBaseContext(), uid);
try {
......
package br.ufpr.c3sl.agendador.agendador;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.models.Dependent;
import br.ufpr.c3sl.agendador.agendador.presenters.DependentsUpdatePresenter;
import br.ufpr.c3sl.agendador.agendador.presenters.NewDependentPresenter;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.views.NewDependentsView;
public class NewDependentActivity extends AppCompatActivity implements NewDependentsView{
private NewDependentPresenter presenter;
private Dependent dependent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dependents);
if(savedInstanceState == null){
presenter = new NewDependentPresenter(this);
}
else{
presenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
if(presenter == null)
presenter = new NewDependentPresenter(this);
}
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_acc);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
protected void onResume() {
super.onResume();
presenter.bindView(this);
}
@Override
protected void onPause() {
super.onPause();
presenter.unbindView();
}
@Override
public void onSaveInstanceState(Bundle outState) {
PresenterManager.getInstance().savePresenter(presenter, outState);
super.onSaveInstanceState(outState);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
......@@ -43,8 +43,6 @@ public class CitizensArrayAdapter extends RecyclerView.Adapter {
CitizenHolder citizenHolder = (CitizenHolder) holder;
UserOutput citizen = citizens.get(position);
citizenHolder.name.setText(citizen.getName());
String s = citizen.getName() + "";
citizenHolder.name.setText(s);
}
/**
......
package br.ufpr.c3sl.agendador.agendador.helpers.adapters;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.List;
import br.ufpr.c3sl.agendador.agendador.R;
import br.ufpr.c3sl.agendador.agendador.models.Dependent;
/**
* Created by Lucas Braz Cunha on 16/08/17.
*/
public class DependentsArrayAdapter extends RecyclerView.Adapter {
private List<Dependent> dependents;
private Context context;
public DependentsArrayAdapter(List<Dependent> dependents, Context context) {
this.dependents = dependents;
this.context = context;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context)
.inflate(R.layout.item_citizen_list, parent, false);
return new CitizenHolder(view);
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
CitizenHolder citizenHolder = (CitizenHolder) holder;
Dependent dependent = dependents.get(position);
citizenHolder.name.setText(dependent.getName());
}
@Override
public int getItemCount() {
return dependents.size();
}
}
package br.ufpr.c3sl.agendador.agendador.models;
import android.os.Parcel;
import android.os.Parcelable;
import com.google.gson.annotations.SerializedName;
/**
* Created by Lucas B. Cunha on 16/08/17.
*/
public class Dependent implements Parcelable{
@SerializedName("id")
private long id;
@SerializedName("birth_date")
private String birthDate;
@SerializedName("name")
private String name;
@SerializedName("rg")
private String rg;
@SerializedName("cpf")
private String cpf;
Dependent(Parcel pc){
id = pc.readLong();
birthDate = pc.readString();
name = pc.readString();
rg = pc.readString();
cpf = pc.readString();
}
public Dependent(int id, String birthDate, String name, String rg, String cpf) {
this.id = id;
this.birthDate = birthDate;
this.name = name;
this.rg = rg;
this.cpf = cpf;
}
/** Static field used to regenerate object, individually or as arrays */
public static final Parcelable.Creator<Dependent> CREATOR = new Parcelable.Creator<Dependent>() {
public Dependent createFromParcel(Parcel pc) {
return new Dependent(pc);
}
public Dependent[] newArray(int size) {
return new Dependent[size];
}
};
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(id);
dest.writeString(birthDate);
dest.writeString(name);
dest.writeString(rg);
dest.writeString(cpf);
}
@Override
public int describeContents() {
return 0;
}
public String getName() {
return name;
}
}
......@@ -7,6 +7,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.Dependent;
import br.ufpr.c3sl.agendador.agendador.models.ScheduleConfirmation;
import br.ufpr.c3sl.agendador.agendador.models.SectorInput;
import br.ufpr.c3sl.agendador.agendador.models.ServiceLocation;
......@@ -50,7 +51,7 @@ public interface ApiEndpoints {
Call<AccountOutput> requestSelf();
@GET("citizens?permission=citizen")
Call<List<UserOutput>> requestDependents();
Call<List<UserOutput>> requestDependentsScheduling();
@GET("sectors?permission=citizen&schedule=true")
Call<List<SectorInput>> requestSectors(@Query("citizen_id") long citizenId);
......@@ -66,4 +67,7 @@ public interface ApiEndpoints {
@GET("schedules/{id_schedule}/confirmation?permission=citizen")
Call<ScheduleConfirmation> requestConfirmSchedule(@Path("id_schedule") long scheduleId, @Query("citizen_id") long citizenId);
@GET("citizens/{id_user}/dependants")
Call<List<Dependent>> requestDependentsList(@Path("id_user") long citizenId);
}
\ No newline at end of file
......@@ -153,7 +153,7 @@ public class AccountPresenter extends BasePresenter<AccountView> {
Headers headers = response.headers();
int status = response.code();
AccountOutput accountOutput = response.body();
updateToken(headers);
updateHeaders(headers);
switch (status) {
case 422:
Log.e("Server response", this.getClass().getName() + ": 422 - Erro na requisição!");
......
......@@ -44,11 +44,15 @@ public abstract class BasePresenter<V> {
return view() != null;
}
protected void updateToken(Headers headers) {
protected void updateHeaders(Headers headers) {
if(headers.get("access-token") != null)
osb.edit().putString("access-token", headers.get("access-token")).apply();
if(headers.get("client") != null)
osb.edit().putString("client", headers.get("client")).apply();
if(headers.get("uid") != null)
osb.edit().putString("uid", headers.get("uid")).apply();
if(headers.get("expiry") != null)
osb.edit().putString("expiry", headers.get("expiry")).apply();;
}
}
\ No newline at end of file
......@@ -44,7 +44,7 @@ public class CitizensPresenter extends BasePresenter<CitizenActivity> {
header.put("uid", osb.getString("uid", null));
final ApiEndpoints service = ApiUtils.request(header);
Call<List<UserOutput>> listCall = service.requestDependents();
Call<List<UserOutput>> listCall = service.requestDependentsScheduling();
citizensPresenter.view().setProgressBar(true);
listCall.enqueue(new Callback<List<UserOutput>>() {
......@@ -54,11 +54,10 @@ public class CitizensPresenter extends BasePresenter<CitizenActivity> {
Headers headers = response.headers();
int status = response.code();
List<UserOutput> citizens = response.body();
updateHeaders(headers);
switch (status) {
case 200:
Log.d("Server response", getClass().getName() + ": 200 - Sucesso!");
updateToken(headers);
//has to be done before showing layout
citizensPresenter.view().successfulCitizens(citizens);
citizensPresenter.view().showLayout(true);
......
package br.ufpr.c3sl.agendador.agendador.presenters;
import android.content.Context;
import android.util.Log;
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.models.Dependent;
import br.ufpr.c3sl.agendador.agendador.network.ApiEndpoints;
import br.ufpr.c3sl.agendador.agendador.network.ApiUtils;
import okhttp3.Headers;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* Created by Lucas B. Cunha on 08/08/17.
......@@ -32,24 +38,22 @@ public class DependentsListPresenter extends BasePresenter<DependentsListActivit
header.put("uid", osb.getString("uid", null));
final ApiEndpoints service = ApiUtils.request(header);
//Call<List<UserOutput>> listCall = service.requestDependents();
Call<List<Dependent>> listCall = service.requestDependentsList(osb.getLong("id", 0));
presenter.view().setProgressBar(true);
/*listCall.enqueue(new Callback<List<UserOutput>>() {
listCall.enqueue(new Callback<List<Dependent>>() {
@Override
public void onResponse(Call<List<UserOutput>> call, Response<List<UserOutput>> response) {
public void onResponse(Call<List<Dependent>> call, Response<List<Dependent>> response) {
Headers headers = response.headers();
int status = response.code();
List<UserOutput> citizens = response.body();
List<Dependent> dependents = response.body();
updateHeaders(headers);
switch (status) {
case 200:
Log.d("Server response", getClass().getName() + ": 200 - Sucesso!");
updateToken(headers);
//has to be done before showing layout
presenter.view().successfulCitizens(citizens);
presenter.view().showLayout(true);
presenter.view().successfulDependents(dependents);
presenter.view().setProgressBar(false);
break;
default:
......@@ -61,12 +65,12 @@ public class DependentsListPresenter extends BasePresenter<DependentsListActivit
}
@Override
public void onFailure(Call<List<UserOutput>> call, Throwable t) {
public void onFailure(Call<List<Dependent>> call, Throwable t) {
Log.e("Server response", getClass().getName() + ": Requisição falhou!!");
presenter.view().setProgressBar(false);
presenter.view().onRequestFailure();
}
});*/
});
}
......
......@@ -2,19 +2,19 @@ package br.ufpr.c3sl.agendador.agendador.presenters;
import android.content.Context;
import br.ufpr.c3sl.agendador.agendador.DependentsActivity;
import br.ufpr.c3sl.agendador.agendador.DependentUpdateActivity;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
/**
* Created by Lucas Braz Cunha on 11/08/17.
*/
public class DependentsPresenter extends BasePresenter<DependentsActivity>{
public class DependentsUpdatePresenter extends BasePresenter<DependentUpdateActivity>{
private DependentsPresenter presenter;
private DependentsUpdatePresenter presenter;
public DependentsPresenter(Context context){
public DependentsUpdatePresenter(Context context){
presenter = this;
this.osb = ObscuredSharedPreferences.getPrefs(context, "Agendador", Context.MODE_PRIVATE);
}
......
......@@ -69,7 +69,7 @@ public class LoginPresenter extends BasePresenter<LoginView> {
}
private void onSuccessfulLogin(AccountOutput accountOutput, Headers headers) {
updateToken(headers);
updateHeaders(headers);
view().setWrongPassword(false);
accountOutput.getCitizen().save(context);
}
......@@ -129,7 +129,6 @@ public class LoginPresenter extends BasePresenter<LoginView> {
private void requestImage() {
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));
......@@ -137,6 +136,7 @@ public class LoginPresenter extends BasePresenter<LoginView> {
header.put("uid", uid);
loginPresenter.view().setProgressBar(true);
ApiEndpoints service = ApiUtils.request(header);
Call<ResponseBody> listCall = service.requestPhoto(osb.getInt("id", 0), "large");
......@@ -147,7 +147,6 @@ public class LoginPresenter extends BasePresenter<LoginView> {
@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 500:
......
package br.ufpr.c3sl.agendador.agendador.presenters;
import android.content.Context;
import br.ufpr.c3sl.agendador.agendador.NewDependentActivity;