Commit 0f5cdf58 authored by Lucas Braz Cunha's avatar Lucas Braz Cunha

AGILE#301: Issue completed

Signed-off-by: Lucas Braz Cunha's avatarLucas B. Cunha <lbc16@inf.ufpr.br>
parent 947a48ee
......@@ -257,7 +257,7 @@ public class ScheduleConfirmationActivity extends AppCompatActivity implements S
});
if(savedInstanceState == null){
scheduleConfirmationPresenter = new ScheduleConfirmationPresenter(getBaseContext());
scheduleConfirmationPresenter = new ScheduleConfirmationPresenter(this);
}else{
scheduleConfirmationPresenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
if(scheduleConfirmationPresenter == null)
......@@ -387,7 +387,8 @@ public class ScheduleConfirmationActivity extends AppCompatActivity implements S
schedule.getLocationName(), schedule.getAddressStreet(), schedule.getAddressNumber(),
sdfDate.format(schedule.getStartTime()), sdfHour.format(schedule.getStartTime()));
notification.reminderTime = sdfServer.format(schedule.getStartTime().getTime() - (reminderTimeArray[sp_notification.getSelectedItemPosition()]));
// TODO: 15/01/18 Apagar aqui o tempo a mais que está sendo usado no calculo da notificaçõa, está em dobro.
notification.reminderTime = sdfServer.format(schedule.getStartTime().getTime() - (reminderTimeArray[sp_notification.getSelectedItemPosition()]) - (reminderTimeArray[sp_notification.getSelectedItemPosition()]));
if(rb_yes.isChecked()){
notification.emailAddres = et_email.getText().toString();
......@@ -443,7 +444,6 @@ public class ScheduleConfirmationActivity extends AppCompatActivity implements S
bt_schedule.setEnabled(true);
bt_back.setEnabled(true);
}
}
@Override
......
......@@ -20,6 +20,7 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.w3c.dom.Text;
......@@ -28,12 +29,17 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat;
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.UserImgHelper;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.models.CheckSchedules;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.presenters.ScheduleConfirmationPresenter;
import br.ufpr.c3sl.agendador.agendador.presenters.ScheduleInfoPresenter;
import br.ufpr.c3sl.agendador.agendador.views.ScheduleInfoView;
public class ScheduleInfoActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{
public class ScheduleInfoActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, ScheduleInfoView{
private MenuBuilder menuBuilder;
......@@ -43,7 +49,6 @@ public class ScheduleInfoActivity extends AppCompatActivity implements Navigatio
private long id;
private static final String EXIT_CONFIRMATION_DIALOG_TAG = "exit_dialog";
private int caller;
......@@ -51,7 +56,15 @@ public class ScheduleInfoActivity extends AppCompatActivity implements Navigatio
private TextView tv_name, tv_sector, tv_location, tv_type,
tv_date, tv_address, tv_situation, tv_situation_content;
private ScheduleInfoPresenter presenter;
private ConnectionErrorDialog connectionErrorDialog;
private Button bt_back;
private ProgressBar pb_scheduleInfo;
private boolean hasToRequest;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -125,17 +138,39 @@ public class ScheduleInfoActivity extends AppCompatActivity implements Navigatio
tv_address = (TextView) findViewById(R.id.tv_schedule_street_content);
tv_situation = (TextView) findViewById(R.id.tv_schedule_situation);
tv_situation_content = (TextView) findViewById(R.id.tv_schedule_situation_content);
pb_scheduleInfo = (ProgressBar) findViewById(R.id.pb_schedule_info);
bt_back = (Button) findViewById(R.id.btn_schedule_info_back);
bt_back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
id = getIntent().getIntExtra(Utils.ID, 0);
if(savedInstanceState == null){
presenter = new ScheduleInfoPresenter(this);
}else{
presenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
if(presenter == null) {
presenter = new ScheduleInfoPresenter(this);
}
}
Bundle bundle = getIntent().getBundleExtra(Utils.SCHEDULE_BUNDLE);
CheckSchedules.Schedule schedule = null;
if(bundle != null){
hasToRequest = true;
if(bundle != null && bundle.getParcelable(Utils.SCHEDULE) != null){
String name = bundle.getString(Utils.NAME);
id = bundle.getLong(Utils.ID);
schedule = bundle.getParcelable(Utils.SCHEDULE);
tv_name.setText(name);
showScheduleContent(schedule);
showScheduleContent(schedule, null);
caller = bundle.getInt(Utils.CALLER_ACTIVITY);
if(caller == Utils.SCHEDULES_ACTIVITY){
......@@ -146,27 +181,32 @@ public class ScheduleInfoActivity extends AppCompatActivity implements Navigatio
navigationView.setCheckedItem(R.id.nav_schedules_history);
tv_situation_content.setText(schedule.getSituation());
}
}else if(id != 0 ){
//pega schedule
// TODO: caso a intent veio da notificação, realizar requisição para pegar os dados.
//showScheduleContent(schedule);
hasToRequest = false;
}
navigationView.setNavigationItemSelectedListener(this);
Button bt_back = (Button) findViewById(R.id.btn_schedule_info_back);
bt_back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
}
private void showScheduleContent(CheckSchedules.Schedule schedule){
@Override
protected void onPause() {
super.onPause();
presenter.unbindView();
}
@Override
protected void onResume() {
super.onResume();
presenter.bindView(this);
if(hasToRequest && id != 0 ){
presenter.requestScheduleInfo(id);
}
}
// TODO: 16/01/18 extract date pattern to utils class
public void showScheduleContent(CheckSchedules.Schedule schedule, String citizenName){
DateFormat df = new SimpleDateFormat("dd/MM/yyyy - HH:mm", Locale.getDefault());
tv_sector.setText(schedule.getSectorName());
tv_location.setText(schedule.getLocationName());
......@@ -174,6 +214,10 @@ public class ScheduleInfoActivity extends AppCompatActivity implements Navigatio
tv_date.setText(df.format(schedule.getStartTime()));
String address = schedule.getAddressStreet() + ", " + schedule.getAddressNumber();
tv_address.setText(address);
tv_situation_content.setText(schedule.getSituation());
if(citizenName != null && !citizenName.equals("")){
tv_name.setText(citizenName);
}
}
@Override
......@@ -232,6 +276,42 @@ public class ScheduleInfoActivity extends AppCompatActivity implements Navigatio
}
}
@Override
public void setProgressBar(boolean enabled) {
if (enabled) {
pb_scheduleInfo.setVisibility(View.VISIBLE);
} else {
pb_scheduleInfo.setVisibility(View.INVISIBLE);
}
bt_back.setEnabled(!enabled);
}
@Override
public void setConnectionError(boolean enabled) {
if(enabled){
if(connectionErrorDialog == null){
connectionErrorDialog = new ConnectionErrorDialog();
}
Bundle bundle = new Bundle();
bundle.putString(ConnectionErrorDialog.DIALOG_MESSAGE, getString(R.string.dialog_connection_error_message));
connectionErrorDialog.setArguments(bundle);
connectionErrorDialog.show(getFragmentManager(), ConnectionErrorDialog.DIALOG_CONNECTION_ERROR);
}
}
@Override
public void setNoConnection(boolean enabled) {
if(enabled){
if(connectionErrorDialog == null){
connectionErrorDialog = new ConnectionErrorDialog();
}
Bundle bundle = new Bundle();
bundle.putString(ConnectionErrorDialog.DIALOG_MESSAGE, getString(R.string.dialog_connection_error_message));
connectionErrorDialog.setArguments(bundle);
connectionErrorDialog.show(getFragmentManager(), ConnectionErrorDialog.DIALOG_CONNECTION_ERROR);
}
}
public static class ConfirmationDialogFragment extends DialogFragment {
@NonNull
@Override
......
package br.ufpr.c3sl.agendador.agendador.models;
import com.google.gson.annotations.SerializedName;
import java.util.Date;
/**
* Created by Lucas Braz Cunha on 16/01/18.
*
* model to receive request schedules/{id_schdule}?permission=citizen
*
* with complete schedule information.
*/
public class ScheduleInfo {
@SerializedName("citizen_data")
CitizenSchedule citizen;
@SerializedName("service_place_data")
ServicePlaceSchedule servicePlace;
@SerializedName("schedule_data")
ScheduleData schedule;
public long getId(){
return citizen.id;
}
public Date getStartTime(){
return schedule.startTime;
}
public String getSectorName(){
return schedule.sectorName;
}
public String getServiceTypeName(){
return schedule.serviceTypeName;
}
public String getLocationName(){
return servicePlace.name;
}
public String getAddressStreet(){
return servicePlace.address.address;
}
public String getAddressNumber(){
return servicePlace.number;
}
public String getSituation(){
return schedule.situation;
}
public String getCitizenName(){
return citizen.name;
}
public static class CitizenSchedule{
@SerializedName("id")
long id;
@SerializedName("name")
String name;
@SerializedName("birth_date")
String birthDate;
@SerializedName("rg")
String rg;
@SerializedName("cpf")
String cpf;
@SerializedName("note")
String note;
}
public static class ServicePlaceSchedule{
@SerializedName("name")
String name;
@SerializedName("complement")
String complement;
@SerializedName("phone1")
String phone;
@SerializedName("address_number")
String number;
@SerializedName("address")
ShortAddress address;
}
public static class ScheduleData{
@SerializedName("id")
long id;
@SerializedName("service_type_name")
String serviceTypeName;
@SerializedName("service_start_time")
Date startTime;
@SerializedName("professional_performer")
String professionalName;
@SerializedName("situation")
String situation;
@SerializedName("sector_name")
String sectorName;
@SerializedName("sector_id")
long sectorId;
}
}
package br.ufpr.c3sl.agendador.agendador.models;
import com.google.gson.annotations.SerializedName;
/**
* Created by Lucas Braz Cunha on 16/01/18.
*
* model for request: schedules/{id_schedule}?permission=citizen
*
*
*/
public class ShortAddress {
@SerializedName("id")
long id;
@SerializedName("zipcode")
String zipcode;
@SerializedName("address")
String address;
@SerializedName("neighborhood")
String neighborhood;
@SerializedName("complement")
String complement;
@SerializedName("complement2")
String complement2;
}
......@@ -17,6 +17,7 @@ import br.ufpr.c3sl.agendador.agendador.models.FullDependent;
import br.ufpr.c3sl.agendador.agendador.models.Notification;
import br.ufpr.c3sl.agendador.agendador.models.NotificationReturn;
import br.ufpr.c3sl.agendador.agendador.models.ScheduleConfirmation;
import br.ufpr.c3sl.agendador.agendador.models.ScheduleInfo;
import br.ufpr.c3sl.agendador.agendador.models.ScheduleNote;
import br.ufpr.c3sl.agendador.agendador.models.SectorInput;
import br.ufpr.c3sl.agendador.agendador.models.ServicePlace;
......@@ -95,5 +96,6 @@ public interface ApiEndpoints {
@POST("notifications?permission=2")
Call<NotificationReturn> requestCreateNotification(@Body Notification notification);
@GET("schedules/{id_schedule}?permission=citizen")
Call<ScheduleInfo> requestScheduleInfo(@Path("id_schedule") long id);
}
\ No newline at end of file
package br.ufpr.c3sl.agendador.agendador.presenters;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import java.util.HashMap;
import java.util.Map;
import br.ufpr.c3sl.agendador.agendador.ScheduleInfoActivity;
import br.ufpr.c3sl.agendador.agendador.SchedulesActivity;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.models.CheckSchedules;
import br.ufpr.c3sl.agendador.agendador.models.ScheduleInfo;
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 Braz Cunha on 15/01/18.
*/
public class ScheduleInfoPresenter extends BasePresenter<ScheduleInfoActivity> {
private ScheduleInfoPresenter presenter;
public ScheduleInfoPresenter(Context context) {
this.context = context;
presenter = this;
osb = ObscuredSharedPreferences.getPrefs(context, "Agendador", Context.MODE_PRIVATE);
}
public void requestScheduleInfo(long id){
Map<String, String> header = new HashMap<>();
header.put("Content-Type", "application/json");
header.put(Utils.ACCESS_TOKEN, osb.getString(Utils.ACCESS_TOKEN, null));
header.put(Utils.CLIENT, osb.getString(Utils.CLIENT, null));
header.put(Utils.UID, osb.getString(Utils.UID, null));
final ApiEndpoints service = ApiUtils.request(header);
Call<ScheduleInfo> listCall = service.requestScheduleInfo(id);
presenter.view().setProgressBar(true);
listCall.enqueue(new Callback<ScheduleInfo>() {
@Override
public void onResponse(Call<ScheduleInfo> call, Response<ScheduleInfo> response) {
Headers headers = response.headers();
int status = response.code();
ScheduleInfo scheduleInfo = response.body();
updateHeaders(headers);
switch (status) {
case 200:
CheckSchedules.Schedule schedule = new CheckSchedules.Schedule(scheduleInfo.getId(), scheduleInfo.getStartTime(),
scheduleInfo.getSectorName(),
scheduleInfo.getServiceTypeName(), scheduleInfo.getLocationName(),
scheduleInfo.getAddressStreet(), scheduleInfo.getAddressNumber(),
scheduleInfo.getSituation());
Log.d("Server response", getClass().getName() + ": 200 - Sucesso!");
presenter.view().showScheduleContent(schedule,scheduleInfo.getCitizenName());
presenter.view().setProgressBar(false);
break;
default:
Log.e("Server response", getClass().getName() + ": ERRO:" + status);
Log.v("Server response", "Redirecionando para tela de visualizar agendamentos.");
Intent i = new Intent(context, SchedulesActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
presenter.view().finish();
context.startActivity(i);
break;
}
}
@Override
public void onFailure(Call<ScheduleInfo> call, Throwable t) {
Log.e("Server response", getClass().getName() + ": Requisição falhou!!");
presenter.view().setProgressBar(false);
presenter.view().setNoConnection(true);
t.printStackTrace();
}
});
}
@Override
protected void updateView() {
}
}
......@@ -30,7 +30,6 @@ import static android.content.Context.ALARM_SERVICE;
*/
public abstract class LocalNotificationManager {
......@@ -98,7 +97,9 @@ public abstract class LocalNotificationManager {
// TODO: 15/12/17 Testar o retorno da lista.
public static List<Notification> getList(ObscuredSharedPreferences osb, Gson gson){
String jsonList = osb.getString(Utils.NOTIFICATION_LIST, "");
return gson.fromJson(jsonList, new TypeToken<List<Notification>>(){}.getType());
List<Notification> notifications = gson.fromJson(jsonList, new TypeToken<List<Notification>>(){}.getType());
return notifications == null ? new ArrayList<Notification>() : notifications;
}
// TODO: 15/12/17 Testar o remove.
......
package br.ufpr.c3sl.agendador.agendador.views;
import br.ufpr.c3sl.agendador.agendador.models.CheckSchedules;
/**
* Created by Lucas B. Cunha on 15/01/18.
*/
public interface ScheduleInfoView {
void setProgressBar(boolean enabled);
void setConnectionError(boolean enabled);
void setNoConnection(boolean enabled);
void showScheduleContent(CheckSchedules.Schedule schedule, String citizenName);
}
......@@ -242,4 +242,13 @@
</LinearLayout>
<ProgressBar
android:layout_width="80dp"
android:id="@+id/pb_schedule_info"
android:layout_height="80dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminate="true"
android:visibility="invisible" />
</RelativeLayout>
\ No newline at end of file
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