Commit 64c6218e authored by Lucas Braz Cunha's avatar Lucas Braz Cunha

Merge branch 'schedule_confirmation' into 'develop'

Changed model for 'Citizens Request'

See merge request !13
parents 67d419c5 db7b900f
......@@ -19,6 +19,7 @@ import br.ufpr.c3sl.agendador.agendador.helpers.adapters.CitizensArrayAdapter;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionErrorDialog;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.helpers.listeners.CitizensItemListener;
import br.ufpr.c3sl.agendador.agendador.models.CitizenCompact;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
import br.ufpr.c3sl.agendador.agendador.presenters.CitizensPresenter;
import br.ufpr.c3sl.agendador.agendador.views.CitizenView;
......@@ -37,7 +38,7 @@ public class CitizenActivity extends AppCompatActivity implements CitizenView{
private CitizensPresenter citizensPresenter;
private List<UserOutput> citizens;
private List<CitizenCompact> citizens;
private ConnectionFailureDialog dg_connection_failure;
......@@ -109,7 +110,7 @@ public class CitizenActivity extends AppCompatActivity implements CitizenView{
rv_citizens.setVisibility(View.VISIBLE);
}
public void successfulCitizens(List<UserOutput> citizens) {
public void successfulCitizens(List<CitizenCompact> citizens) {
this.citizens = citizens;
}
......
......@@ -33,6 +33,7 @@ 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.Utils;
import br.ufpr.c3sl.agendador.agendador.models.CitizenCompact;
import br.ufpr.c3sl.agendador.agendador.models.ScheduleConfirmation;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
import br.ufpr.c3sl.agendador.agendador.presenters.ScheduleConfirmationPresenter;
......@@ -72,7 +73,7 @@ public class ScheduleConfirmationActivity extends AppCompatActivity implements S
setContentView(R.layout.activity_schedule_confirmation);
Bundle bundle = getIntent().getBundleExtra(Utils.SCHEDULE_BUNDLE);
final UserOutput citizen = bundle.getParcelable(Utils.CITIZEN);
final CitizenCompact citizen = bundle.getParcelable(Utils.CITIZEN);
final ScheduleConfirmation scheduleConfirmation = bundle.getParcelable(Utils.SCHEDULE_CONFIRMATION);
String sectorName = scheduleConfirmation.getSectorName();
String locationName = scheduleConfirmation.getLocationName();
......
......@@ -50,6 +50,7 @@ import br.ufpr.c3sl.agendador.agendador.helpers.decorators.SchedulesDecorator;
import br.ufpr.c3sl.agendador.agendador.helpers.listeners.LocationSpinnerListener;
import br.ufpr.c3sl.agendador.agendador.helpers.listeners.SectorSpinnerListener;
import br.ufpr.c3sl.agendador.agendador.helpers.listeners.ServiceTypeSpinnerListener;
import br.ufpr.c3sl.agendador.agendador.models.CitizenCompact;
import br.ufpr.c3sl.agendador.agendador.models.ScheduleConfirmation;
import br.ufpr.c3sl.agendador.agendador.models.SectorInput;
import br.ufpr.c3sl.agendador.agendador.models.ServiceLocation;
......@@ -90,7 +91,7 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
private SchedulingPresenter schedulingPresenter;
private UserOutput citizen;
private CitizenCompact citizen;
private ServiceTypeSpinnerListener serviceTypeSpinnerListener;
......
......@@ -25,6 +25,7 @@ import java.util.List;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionErrorDialog;
import br.ufpr.c3sl.agendador.agendador.helpers.adapters.SectorArrayAdapter;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.models.CitizenCompact;
import br.ufpr.c3sl.agendador.agendador.models.SectorInput;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
import br.ufpr.c3sl.agendador.agendador.presenters.TermPresenter;
......@@ -44,7 +45,7 @@ public class TermActivity extends AppCompatActivity implements TermView {
private ConnectionFailureDialog dg_connection_failure;
private UserOutput citizen;
private CitizenCompact citizen;
@Override
protected void onCreate(Bundle savedInstanceState) {
......
......@@ -9,6 +9,7 @@ import android.view.ViewGroup;
import java.util.List;
import br.ufpr.c3sl.agendador.agendador.R;
import br.ufpr.c3sl.agendador.agendador.models.CitizenCompact;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
......@@ -19,11 +20,11 @@ import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
public class CitizensArrayAdapter extends RecyclerView.Adapter {
private List<UserOutput> citizens;
private List<CitizenCompact> citizens;
private Context context;
public CitizensArrayAdapter(Context context, List<UserOutput> citizens){
public CitizensArrayAdapter(Context context, List<CitizenCompact> citizens){
super();
this.citizens = citizens;
this.context = context;
......@@ -41,7 +42,7 @@ public class CitizensArrayAdapter extends RecyclerView.Adapter {
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
CitizenHolder citizenHolder = (CitizenHolder) holder;
UserOutput citizen = citizens.get(position);
CitizenCompact citizen = citizens.get(position);
citizenHolder.name.setText(citizen.getName());
String s = citizen.getName() + "";
citizenHolder.name.setText(s);
......
package br.ufpr.c3sl.agendador.agendador.models;
import android.os.Parcel;
import android.os.Parcelable;
import com.google.gson.annotations.SerializedName;
/**
* Created by Lucas Braz Cunha on 10/08/17.
*/
public class CitizenCompact implements Parcelable{
@SerializedName("id")
private long id;
@SerializedName("name")
private String name;
@SerializedName("birth_date")
private String birthDate;
@SerializedName("rg")
private String rg;
@SerializedName("cpf")
private String cpf;
public CitizenCompact(long id, String name, String birth_Date, String rg, String cpf) {
this.id = id;
this.name = name;
this.birthDate = birth_Date;
this.rg = rg;
this.cpf = cpf;
}
/** Static field used to regenerate object, individually or as arrays */
public static final Parcelable.Creator<CitizenCompact> CREATOR = new Parcelable.Creator<CitizenCompact>() {
public CitizenCompact createFromParcel(Parcel pc) {
return new CitizenCompact(pc);
}
public CitizenCompact[] newArray(int size) {
return new CitizenCompact[size];
}
};
/**reads back fields IN THE ORDER they were written */
private CitizenCompact(Parcel pc){
id = pc.readLong();
name = pc.readString();
birthDate = pc.readString();
rg = pc.readString();
cpf = pc.readString();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(id);
dest.writeString(name);
dest.writeString(birthDate);
dest.writeString(rg);
dest.writeString(cpf);
}
@Override
public int describeContents() {
return 0;
}
public long getId() {
return id;
}
public String getName() {
return name;
}
}
......@@ -11,13 +11,13 @@ import com.google.gson.annotations.SerializedName;
public class City implements Parcelable{
//package private because they're used on UserOutput.
@SerializedName("id")
private long mId;
@SerializedName("ibge_code")
private int mIbge_code;
//package private because they're used on UserOutput.
@SerializedName("name")
String mName;
......
......@@ -7,18 +7,15 @@ 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.CitizenCompact;
import br.ufpr.c3sl.agendador.agendador.models.ScheduleConfirmation;
import br.ufpr.c3sl.agendador.agendador.models.SectorInput;
import br.ufpr.c3sl.agendador.agendador.models.ServiceLocation;
import br.ufpr.c3sl.agendador.agendador.models.ServiceSchedule;
import br.ufpr.c3sl.agendador.agendador.models.ServiceType;
import br.ufpr.c3sl.agendador.agendador.models.SignOutOutput;
import br.ufpr.c3sl.agendador.agendador.models.User;
import okhttp3.ResponseBody;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.PUT;
......@@ -49,8 +46,8 @@ public interface ApiEndpoints {
@GET("accounts/self")
Call<AccountOutput> requestSelf();
@GET("citizens?permission=citizen")
Call<List<UserOutput>> requestDependents();
@GET("citizens/{citizen_id}/schedule_options?permission=citizen")
Call<List<CitizenCompact>> requestScheduleOptions(@Path("citizen_id") long citizenId);
@GET("sectors?permission=citizen&schedule=true")
Call<List<SectorInput>> requestSectors(@Query("citizen_id") long citizenId);
......
......@@ -9,6 +9,7 @@ import java.util.Map;
import br.ufpr.c3sl.agendador.agendador.CitizenActivity;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.models.CitizenCompact;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
import br.ufpr.c3sl.agendador.agendador.network.ApiEndpoints;
import br.ufpr.c3sl.agendador.agendador.network.ApiUtils;
......@@ -58,16 +59,16 @@ 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<CitizenCompact>> listCall = service.requestScheduleOptions(osb.getLong("id", 0));
citizensPresenter.view().setProgressBar(true);
listCall.enqueue(new Callback<List<UserOutput>>() {
listCall.enqueue(new Callback<List<CitizenCompact>>() {
@Override
public void onResponse(Call<List<UserOutput>> call, Response<List<UserOutput>> response) {
public void onResponse(Call<List<CitizenCompact>> call, Response<List<CitizenCompact>> response) {
Headers headers = response.headers();
int status = response.code();
List<UserOutput> citizens = response.body();
List<CitizenCompact> citizens = response.body();
switch (status) {
case 200:
......@@ -87,7 +88,7 @@ public class CitizensPresenter extends BasePresenter<CitizenActivity> {
}
@Override
public void onFailure(Call<List<UserOutput>> call, Throwable t) {
public void onFailure(Call<List<CitizenCompact>> call, Throwable t) {
Log.e("Server response", getClass().getName() + ": Requisição falhou!!");
citizensPresenter.view().setProgressBar(false);
citizensPresenter.view().onRequestFailure();
......
......@@ -19,6 +19,7 @@ import br.ufpr.c3sl.agendador.agendador.LoginActivity;
import br.ufpr.c3sl.agendador.agendador.ScheduleConfirmationActivity;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.models.CitizenCompact;
import br.ufpr.c3sl.agendador.agendador.models.ScheduleConfirmation;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
import br.ufpr.c3sl.agendador.agendador.network.ApiEndpoints;
......@@ -66,7 +67,7 @@ public class ScheduleConfirmationPresenter extends BasePresenter<ScheduleConfirm
}
// TODO: 31/07/17 Check if the received id is the same as the sent one - is it necessary?
public void onScheduleClicked(final ScheduleConfirmation scheduleConfirmation, UserOutput citizen){
public void onScheduleClicked(final ScheduleConfirmation scheduleConfirmation, CitizenCompact citizen){
Map<String, String> header = new HashMap<>();
header.put("Content-Type", "application/json");
header.put("access-token", osb.getString("access-token", null));
......@@ -75,7 +76,7 @@ public class ScheduleConfirmationPresenter extends BasePresenter<ScheduleConfirm
final ApiEndpoints service = ApiUtils.request(header);
Call<ScheduleConfirmation> listCall = service.requestPerformScheduling(scheduleConfirmation.getId(), citizen.getmId());
Call<ScheduleConfirmation> listCall = service.requestPerformScheduling(scheduleConfirmation.getId(), citizen.getId());
scheduleConfirmationPresenter.view().setProgressBar(true);
listCall.enqueue(new Callback<ScheduleConfirmation>() {
......
......@@ -15,6 +15,7 @@ import br.ufpr.c3sl.agendador.agendador.LoginActivity;
import br.ufpr.c3sl.agendador.agendador.SchedulingActivity;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.models.CitizenCompact;
import br.ufpr.c3sl.agendador.agendador.models.ScheduleConfirmation;
import br.ufpr.c3sl.agendador.agendador.models.ServiceLocation;
import br.ufpr.c3sl.agendador.agendador.models.ServiceSchedule;
......@@ -117,7 +118,7 @@ public class SchedulingPresenter extends BasePresenter<SchedulingView> {
}
public void onScheduleButtonClicked(final ServiceSchedule schedule, final UserOutput citizen){
public void onScheduleButtonClicked(final ServiceSchedule schedule, final CitizenCompact citizen){
Map<String, String> header = new HashMap<>();
header.put("Content-Type", "application/json");
header.put("access-token", osb.getString("access-token", null));
......@@ -126,7 +127,7 @@ public class SchedulingPresenter extends BasePresenter<SchedulingView> {
final ApiEndpoints service = ApiUtils.request(header);
Call<ScheduleConfirmation> listCall = service.requestConfirmSchedule(schedule.getmId(), citizen.getmId());
Call<ScheduleConfirmation> listCall = service.requestConfirmSchedule(schedule.getmId(), citizen.getId());
schedulingPresenter.view().setProgressBar(true, SchedulingActivity.SHOW_PB);
listCall.enqueue(new Callback<ScheduleConfirmation>() {
......
......@@ -9,6 +9,7 @@ import java.util.Map;
import br.ufpr.c3sl.agendador.agendador.TermActivity;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.models.CitizenCompact;
import br.ufpr.c3sl.agendador.agendador.models.SectorInput;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
import br.ufpr.c3sl.agendador.agendador.network.ApiEndpoints;
......@@ -52,7 +53,7 @@ public class TermPresenter extends BasePresenter<TermActivity>{
}
public void requestSectors(UserOutput citizen){
public void requestSectors(CitizenCompact citizen){
Map<String, String> header = new HashMap<>();
header.put("Content-Type", "application/json");
......@@ -61,7 +62,7 @@ public class TermPresenter extends BasePresenter<TermActivity>{
header.put("uid", osb.getString("uid", null));
final ApiEndpoints service = ApiUtils.request(header);
Call<List<SectorInput>> listCall = service.requestSectors(citizen.getmId());
Call<List<SectorInput>> listCall = service.requestSectors(citizen.getId());
termPresenter.view().setProgressBar(true);
listCall.enqueue(new Callback<List<SectorInput>>() {
......
......@@ -6,7 +6,6 @@ package br.ufpr.c3sl.agendador.agendador.views;
public interface CitizenView {
void showLayout(boolean enabled);
void setProgressBar(boolean enabled);
......
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