Commit 011330b3 authored by Lucas Braz Cunha's avatar Lucas Braz Cunha

Issue AGILE#182 Added model and request for service types

Signed-off-by: Lucas Braz Cunha's avatarLucas B. Cunha <lbc16@inf.ufpr.br>
parent c4964ec9
...@@ -19,7 +19,6 @@ import android.view.Gravity; ...@@ -19,7 +19,6 @@ import android.view.Gravity;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
...@@ -43,6 +42,7 @@ import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences; ...@@ -43,6 +42,7 @@ import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.helpers.UserPhotoHelper; import br.ufpr.c3sl.agendador.agendador.helpers.UserPhotoHelper;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils; import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.models.SectorInput; import br.ufpr.c3sl.agendador.agendador.models.SectorInput;
import br.ufpr.c3sl.agendador.agendador.models.ServiceTypes;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput; import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
import br.ufpr.c3sl.agendador.agendador.presenters.SchedulingPresenter; import br.ufpr.c3sl.agendador.agendador.presenters.SchedulingPresenter;
import br.ufpr.c3sl.agendador.agendador.views.SchedulingView; import br.ufpr.c3sl.agendador.agendador.views.SchedulingView;
...@@ -92,6 +92,12 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV ...@@ -92,6 +92,12 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
private List<SectorInput> sectors; private List<SectorInput> sectors;
private List<ServiceTypes> serviceTypes;
// TODO: 30/06/17 adicionar o trecho que faz a requisição, e mostrar os compaos ativos e inativos corretamente.
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -245,6 +251,7 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV ...@@ -245,6 +251,7 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
spnr_type.setEnabled(false); spnr_type.setEnabled(false);
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
...@@ -329,10 +336,7 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV ...@@ -329,10 +336,7 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
} }
} }
public void showLayout(boolean enabled){
if(enabled)
ll_fields.setVisibility(View.VISIBLE);
}
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
...@@ -407,6 +411,13 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV ...@@ -407,6 +411,13 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
} }
@Override
public void setServicesList(List<ServiceTypes> serviceTypes) {
this.serviceTypes = serviceTypes;
}
public static class ConfirmationDialog extends DialogFragment { public static class ConfirmationDialog extends DialogFragment {
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
...@@ -432,4 +443,6 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV ...@@ -432,4 +443,6 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
} }
} }
package br.ufpr.c3sl.agendador.agendador.models;
import com.google.gson.annotations.SerializedName;
/**
* Created by Lucas Braz Cunha on 30/06/17.
*/
public class ServiceTypes {
@SerializedName("id")
private int mId;
@SerializedName("description")
private String mDescription;
@SerializedName("active")
private boolean isActive;
public ServiceTypes(int mId, String mDescription, boolean isActive){
this.mId = mId;
this.mDescription = mDescription;
this.isActive = isActive;
}
public boolean isActive() {
return isActive;
}
public String getmDescription() {
return mDescription;
}
}
...@@ -9,6 +9,7 @@ import br.ufpr.c3sl.agendador.agendador.models.AccountUpdate; ...@@ -9,6 +9,7 @@ import br.ufpr.c3sl.agendador.agendador.models.AccountUpdate;
import br.ufpr.c3sl.agendador.agendador.models.Address; import br.ufpr.c3sl.agendador.agendador.models.Address;
import br.ufpr.c3sl.agendador.agendador.models.CepInput; import br.ufpr.c3sl.agendador.agendador.models.CepInput;
import br.ufpr.c3sl.agendador.agendador.models.SectorInput; import br.ufpr.c3sl.agendador.agendador.models.SectorInput;
import br.ufpr.c3sl.agendador.agendador.models.ServiceTypes;
import br.ufpr.c3sl.agendador.agendador.models.SignOutOutput; import br.ufpr.c3sl.agendador.agendador.models.SignOutOutput;
import br.ufpr.c3sl.agendador.agendador.models.User; import br.ufpr.c3sl.agendador.agendador.models.User;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput; import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
...@@ -18,6 +19,7 @@ import retrofit2.http.DELETE; ...@@ -18,6 +19,7 @@ import retrofit2.http.DELETE;
import retrofit2.http.GET; import retrofit2.http.GET;
import retrofit2.http.POST; import retrofit2.http.POST;
import retrofit2.http.PUT; import retrofit2.http.PUT;
import retrofit2.http.Query;
/** /**
* Created by Bruno Freitas Tissei on 2/3/17. * Created by Bruno Freitas Tissei on 2/3/17.
...@@ -44,12 +46,16 @@ public interface ApiEndpoints { ...@@ -44,12 +46,16 @@ public interface ApiEndpoints {
/* /*
if it needs changing to dynamic permission if it needs changing to dynamic permission
@GET("citizens") @GET("citizens")
Call<AccountOutput> getDependents(@Query("permission") String permission); Call<AccountOutput> requestDependents(@Query("permission") String permission);
*/ */
@GET("citizens?permission=citizen") @GET("citizens?permission=citizen")
Call<List<UserOutput>> getDependents(); Call<List<UserOutput>> requestDependents();
@GET("sectors?permission=citizen") @GET("sectors?permission=citizen")
Call<List<SectorInput>> requestSectors(); Call<List<SectorInput>> requestSectors();
@GET("service_types")
Call<List<ServiceTypes>> requestServiceTypes(@Query("sector_id") int sectorId);
} }
\ No newline at end of file
...@@ -58,7 +58,7 @@ public class CitizensPresenter extends BasePresenter<CitizenActivity> { ...@@ -58,7 +58,7 @@ public class CitizensPresenter extends BasePresenter<CitizenActivity> {
header.put("uid", osb.getString("uid", null)); header.put("uid", osb.getString("uid", null));
final ApiEndpoints service = ApiUtils.request(header); final ApiEndpoints service = ApiUtils.request(header);
Call<List<UserOutput>> listCall = service.getDependents(); Call<List<UserOutput>> listCall = service.requestDependents();
citizensPresenter.view().setProgressBar(true); citizensPresenter.view().setProgressBar(true);
listCall.enqueue(new Callback<List<UserOutput>>() { listCall.enqueue(new Callback<List<UserOutput>>() {
......
...@@ -3,7 +3,6 @@ package br.ufpr.c3sl.agendador.agendador.presenters; ...@@ -3,7 +3,6 @@ package br.ufpr.c3sl.agendador.agendador.presenters;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.util.Log; import android.util.Log;
import android.widget.Toast;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -11,7 +10,7 @@ import java.util.Map; ...@@ -11,7 +10,7 @@ import java.util.Map;
import br.ufpr.c3sl.agendador.agendador.LoginActivity; import br.ufpr.c3sl.agendador.agendador.LoginActivity;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences; import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput; import br.ufpr.c3sl.agendador.agendador.models.ServiceTypes;
import br.ufpr.c3sl.agendador.agendador.network.ApiEndpoints; import br.ufpr.c3sl.agendador.agendador.network.ApiEndpoints;
import br.ufpr.c3sl.agendador.agendador.network.ApiUtils; import br.ufpr.c3sl.agendador.agendador.network.ApiUtils;
import br.ufpr.c3sl.agendador.agendador.views.SchedulingView; import br.ufpr.c3sl.agendador.agendador.views.SchedulingView;
...@@ -51,7 +50,6 @@ public class SchedulingPresenter extends BasePresenter<SchedulingView> { ...@@ -51,7 +50,6 @@ public class SchedulingPresenter extends BasePresenter<SchedulingView> {
schedulingPresenter.view().finish(); schedulingPresenter.view().finish();
} }
/*
private void updateToken(Headers headers) { private void updateToken(Headers headers) {
if(headers.get("access-token") != null) if(headers.get("access-token") != null)
...@@ -60,9 +58,54 @@ public class SchedulingPresenter extends BasePresenter<SchedulingView> { ...@@ -60,9 +58,54 @@ public class SchedulingPresenter extends BasePresenter<SchedulingView> {
osb.edit().putString("client", headers.get("client")).apply(); osb.edit().putString("client", headers.get("client")).apply();
} }
public void requestServiceTypes(int sectorId){
Map<String, String> header = new HashMap<>();
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", osb.getString("uid", null));
final ApiEndpoints service = ApiUtils.request(header);
Call<List<ServiceTypes>> listCall = service.requestServiceTypes(sectorId);
schedulingPresenter.view().setProgressBar(true);
listCall.enqueue(new Callback<List<ServiceTypes>>() {
@Override
public void onResponse(Call<List<ServiceTypes>> call, Response<List<ServiceTypes>> response) {
Headers headers = response.headers();
int status = response.code();
List<ServiceTypes> serviceTypes = response.body();
switch (status) {
case 200:
Log.d("Server response", getClass().getName() + ": 200 - Sucesso!");
updateToken(headers);
schedulingPresenter.view().setServicesList(serviceTypes);
schedulingPresenter.view().setProgressBar(false);
break;
default:
Log.d("Server response", getClass().getName() + ": ERRO:" + status);
break;
}
}
@Override
public void onFailure(Call<List<ServiceTypes>> call, Throwable t) {
schedulingPresenter.view().setNoConnection(true);
schedulingPresenter.view().setProgressBar(false);
}
});
}
/*
public void getDependents(){ public void requestDependents(){
Map<String, String> header = new HashMap<>(); Map<String, String> header = new HashMap<>();
header.put("Content-Type", "application/json"); header.put("Content-Type", "application/json");
...@@ -71,7 +114,7 @@ public class SchedulingPresenter extends BasePresenter<SchedulingView> { ...@@ -71,7 +114,7 @@ public class SchedulingPresenter extends BasePresenter<SchedulingView> {
header.put("uid", osb.getString("uid", null)); header.put("uid", osb.getString("uid", null));
final ApiEndpoints service = ApiUtils.request(header); final ApiEndpoints service = ApiUtils.request(header);
Call<List<UserOutput>> listCall = service.getDependents(); Call<List<UserOutput>> listCall = service.requestDependents();
schedulingPresenter.view().showLayout(false); schedulingPresenter.view().showLayout(false);
schedulingPresenter.view().setProgressBar(true); schedulingPresenter.view().setProgressBar(true);
......
...@@ -2,6 +2,7 @@ package br.ufpr.c3sl.agendador.agendador.views; ...@@ -2,6 +2,7 @@ package br.ufpr.c3sl.agendador.agendador.views;
import java.util.List; import java.util.List;
import br.ufpr.c3sl.agendador.agendador.models.ServiceTypes;
import br.ufpr.c3sl.agendador.agendador.models.UserOutput; import br.ufpr.c3sl.agendador.agendador.models.UserOutput;
/** /**
...@@ -20,4 +21,6 @@ public interface SchedulingView { ...@@ -20,4 +21,6 @@ public interface SchedulingView {
void finish(); void finish();
void setServicesList(List<ServiceTypes> serviceTypes);
} }
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