Commit 63f7e9d6 authored by Lucas Braz Cunha's avatar Lucas Braz Cunha

Issue AGILE#152 Done ActivityScheduling

Signed-off-by: Lucas Braz Cunha's avatarLucas B. Cunha <lbc16@inf.ufpr.br>
parent 575575ab
......@@ -35,19 +35,18 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionErrorDialog;
import br.ufpr.c3sl.agendador.agendador.helpers.adapters.HintEnableAdapter;
import br.ufpr.c3sl.agendador.agendador.helpers.decorators.SchedulesDecorator;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.helpers.decorators.NotAvailableDecorator;
import br.ufpr.c3sl.agendador.agendador.helpers.UserPhotoHelper;
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;
import br.ufpr.c3sl.agendador.agendador.helpers.decorators.NotAvailableDecorator;
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;
......@@ -147,11 +146,6 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
private static final String SCHEDULES_TIME_ARRAY = "schedules_time_array";
// TODO: 12/07/17 Tarefas
// levar o calendário para o primeiro dia de agendamento? - ordenar aqui as chaves das hashs.
// pegar do back-end o limite superior de data.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -307,7 +301,7 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
spnr_type.setOnItemSelectedListener(serviceTypeSpinnerListener);
spnr_type.setOnTouchListener(serviceTypeSpinnerListener);
locationSpinnerListener = new LocationSpinnerListener(schedulingPresenter, mcv, tv_year, tv_day_month, days_short, months_short);
locationSpinnerListener = new LocationSpinnerListener(mcv, tv_year, tv_day_month, days_short, months_short);
spnr_location.setOnItemSelectedListener(locationSpinnerListener);
spnr_location.setOnTouchListener(locationSpinnerListener);
......@@ -392,6 +386,11 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
} else {
pb_scheduling.setVisibility(View.INVISIBLE);
spnr_sector.setEnabled(true);
serviceTypeSpinnerListener.setUserSelect(false);
locationSpinnerListener.setUserSelect(false);
sectorSpinnerListener.setUserSelect(false);
if(flag == REQUEST_TYPES_ERROR){
spnr_sector.setSelection(hintAdapterSector.getCount());
spnr_location.setSelection(hintAdapterLocation.getCount());
......@@ -471,8 +470,9 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
else{
btn_confirm.setEnabled(false);
}
// TODO: 13/07/17 keep calendar header as the selected or set it to "today"?
// null -> selectedDate
//always update calendar header to today, because when a click is fired on a "useful" date
// the header is updated by 'onScheduleTimeSelected'
Utils.updateCalendarHeaderDate(mcv,tv_year, tv_day_month, days_short, months_short, null);
}
......@@ -496,6 +496,7 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
//block listener call for the spinners.
locationSpinnerListener.setUserSelect(false);
serviceTypeSpinnerListener.setUserSelect(false);
sectorSpinnerListener.setUserSelect(false);
serviceTypeSpinnerListener.setServiceTypes(serviceTypes);
......@@ -518,45 +519,30 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
}
hintAdapterType = new HintAdapter(this, android.R.layout.simple_list_item_1, types);
spnr_type.setAdapter(hintAdapterType);
serviceTypeSpinnerListener.setUserSelect(false);
spnr_type.setSelection(hintAdapterType.getCount());
}
public void setServiceLocationList(List<ServiceLocation> serviceLocations){
int i, schedulesListSize;
int i;
int max = 0;
boolean hasCreatedDecorator1 = false;
boolean hasCreatedDecorator2 = false;
locationSpinnerListener.setUserSelect(false);
locationSpinnerListener.setServiceLocations(serviceLocations);
// TODO: 13/07/17 is the list ordered? -- receive "max date sum" from back-end
//get max available date to this type of service
//checking only the last position of each location
i = 0;
ServiceLocation serviceLocation = serviceLocations.get(0);
List<ServiceSchedule> scheduleList = serviceLocation.getSchedules();
Date max = new Date();
schedulesListSize = serviceLocation.getSchedules().size();
for(; i < serviceLocations.size() && schedulesListSize != 0; ++i)
{
if(max.before(scheduleList.get(schedulesListSize -1).getEnd())) {
max = scheduleList.get(schedulesListSize -1).getEnd();
}
serviceLocation = serviceLocations.get(i);
scheduleList = serviceLocation.getSchedules();
schedulesListSize = serviceLocation.getSchedules().size();
for(ServiceLocation location : serviceLocations){
if(location.getmPeriod() > max)
max = location.getmPeriod();
}
//adding 2 months to make calendar more friendly
//cal set to today, then add maxPeriod and go to end of month.
Calendar cal = Calendar.getInstance();
cal.setTime(max);
cal.add(Calendar.MONTH, 2);
cal.add(Calendar.DATE, max);
cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
mcv.state().edit().setMaximumDate(cal).commit();
// TODO: 13/07/17 end of control for max date.
String[] locations;
......@@ -582,6 +568,7 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
}
hintAdapterLocation = new HintEnableAdapter(this, android.R.layout.simple_list_item_1, locations, enableView);
spnr_location.setAdapter(hintAdapterLocation);
locationSpinnerListener.setUserSelect(false);
spnr_location.setSelection(hintAdapterLocation.getCount());
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
......@@ -602,6 +589,7 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
listOfScheduleDays.add(hashMap);
}
if(notAvailableDecorator == null){
notAvailableDecorator = new NotAvailableDecorator(listOfScheduleDays, this);
notAvailableDecorator.setScheduleType(NotAvailableDecorator.INVALID_STATE);
......@@ -611,8 +599,8 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
mcv.addDecorator(notAvailableDecorator);
}
else {
notAvailableDecorator.setListOfScheduleDays(listOfScheduleDays);
notAvailableDecorator.setScheduleType(SchedulesDecorator.INVALID_STATE);
notAvailableDecorator.setListOfScheduleDays(listOfScheduleDays);
hasCreatedDecorator1 = true;
}
......@@ -625,8 +613,8 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
mcv.addDecorator(schedulesDecorator);
}
else {
schedulesDecorator.setListOfScheduleDays(listOfScheduleDays);
schedulesDecorator.setScheduleType(SchedulesDecorator.INVALID_STATE);
schedulesDecorator.setListOfScheduleDays(listOfScheduleDays);
hasCreatedDecorator2 = true;
}
......
......@@ -97,8 +97,6 @@ public class Utils {
Calendar calendar = Calendar.getInstance();
if(date != null)
date.copyTo(calendar);
else
CalendarDay.today().copyTo(calendar);
String s = calendar.get(Calendar.YEAR) + "";
tv_calendarHeaderYear.setText(s);
......
......@@ -47,7 +47,7 @@ public class NotAvailableDecorator implements DayViewDecorator {
*/
@Override
public boolean shouldDecorate(CalendarDay day) {
return scheduleType != INVALID_STATE && !listOfScheduleDays.get(scheduleType).containsKey(dateFormat.format(day.getDate()));
return scheduleType != INVALID_STATE && !listOfScheduleDays.get(scheduleType).containsKey(dateFormat.format(day.getDate()));
}
/**
......
package br.ufpr.c3sl.agendador.agendador.helpers.listeners;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;
import android.widget.Toast;
import com.prolificinteractive.materialcalendarview.MaterialCalendarView;
import java.util.List;
import br.ufpr.c3sl.agendador.agendador.helpers.decorators.SchedulesDecorator;
import br.ufpr.c3sl.agendador.agendador.helpers.decorators.NotAvailableDecorator;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.helpers.decorators.NotAvailableDecorator;
import br.ufpr.c3sl.agendador.agendador.helpers.decorators.SchedulesDecorator;
import br.ufpr.c3sl.agendador.agendador.models.ServiceLocation;
import br.ufpr.c3sl.agendador.agendador.presenters.SchedulingPresenter;
/**
* Created by Lucas B. Cunha on 05/07/17.
......@@ -22,9 +21,7 @@ import br.ufpr.c3sl.agendador.agendador.presenters.SchedulingPresenter;
public class LocationSpinnerListener implements AdapterView.OnItemSelectedListener, View.OnTouchListener {
private boolean userSelect = false;
private SchedulingPresenter presenter;
private boolean userSelect;
private List<ServiceLocation> serviceLocations;
......@@ -39,33 +36,43 @@ public class LocationSpinnerListener implements AdapterView.OnItemSelectedListen
private String[] days_short, months_short;
public LocationSpinnerListener(SchedulingPresenter presenter, MaterialCalendarView mcv, TextView calendarHeaderYear,
public LocationSpinnerListener(MaterialCalendarView mcv, TextView calendarHeaderYear,
TextView calendarHeaderDayHour, String[] days_short, String[] months_short){
this.presenter = presenter;
this.mcv = mcv;
this.tv_calendarHeaderYear = calendarHeaderYear;
this.tv_calendarHeaderDayHour = calendarHeaderDayHour;
this.days_short = days_short;
this.months_short = months_short;
userSelect = false;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
userSelect = true;
Log.v("Array out of Bounds bug", "Clicou no spinner de locais");
return false;
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
if (userSelect && serviceLocations != null && serviceLocations.size() > 0) {
if (userSelect && serviceLocations != null && serviceLocations.size() > 0 ) {
mcv.setSelectionMode(MaterialCalendarView.SELECTION_MODE_SINGLE);
schedulesDecorator.setScheduleType(pos);
notAvailableDecorator.setScheduleType(pos);
mcv.invalidateDecorators();
userSelect = false;
//if the position is the hint.
if(pos == serviceLocations.size()){
schedulesDecorator.setScheduleType(SchedulesDecorator.INVALID_STATE);
notAvailableDecorator.setScheduleType(NotAvailableDecorator.INVALID_STATE);
}
else{
schedulesDecorator.setScheduleType(pos);
notAvailableDecorator.setScheduleType(pos);
}
mcv.invalidateDecorators();
Utils.updateCalendarHeaderDate(mcv, tv_calendarHeaderYear, tv_calendarHeaderDayHour, days_short, months_short, null);
}
userSelect = false;
Log.v("Array out of Bounds bug", "Selecionou o item "+ pos +" do spinner de locais");
}
@Override
......
package br.ufpr.c3sl.agendador.agendador.helpers.listeners;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AdapterView;
......@@ -9,9 +10,9 @@ import com.prolificinteractive.materialcalendarview.MaterialCalendarView;
import java.util.List;
import br.ufpr.c3sl.agendador.agendador.helpers.decorators.SchedulesDecorator;
import br.ufpr.c3sl.agendador.agendador.helpers.decorators.NotAvailableDecorator;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.helpers.decorators.NotAvailableDecorator;
import br.ufpr.c3sl.agendador.agendador.helpers.decorators.SchedulesDecorator;
import br.ufpr.c3sl.agendador.agendador.models.SectorInput;
import br.ufpr.c3sl.agendador.agendador.presenters.SchedulingPresenter;
......@@ -21,7 +22,8 @@ import br.ufpr.c3sl.agendador.agendador.presenters.SchedulingPresenter;
public class SectorSpinnerListener implements AdapterView.OnItemSelectedListener, View.OnTouchListener {
private boolean userSelect = false;
private boolean userSelect;
private SchedulingPresenter presenter;
......@@ -46,20 +48,21 @@ public class SectorSpinnerListener implements AdapterView.OnItemSelectedListener
this.tv_calendarHeaderDayHour = calendarHeaderDayHour;
this.days_short = days_short;
this.months_short = months_short;
userSelect = false;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
userSelect = true;
Log.v("Array out of Bounds bug", "Clicou no spinner de setores");
return false;
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
if (userSelect && sectorList != null && sectorList.size() > 0) {
presenter.requestServiceTypes(sectorList.get((int)id).getmId());
userSelect = false;
presenter.requestServiceTypes(sectorList.get(pos).getmId());
Utils.updateCalendarHeaderDate(mcv, tv_calendarHeaderYear, tv_calendarHeaderDayHour, days_short, months_short, null);
if(schedulesDecorator != null){
......@@ -71,6 +74,9 @@ public class SectorSpinnerListener implements AdapterView.OnItemSelectedListener
mcv.invalidateDecorators();
}
userSelect = false;
Log.v("Array out of Bounds bug", "Selecionou o item "+ pos + " do spinner de setores");
}
@Override
......@@ -84,4 +90,9 @@ public class SectorSpinnerListener implements AdapterView.OnItemSelectedListener
public void setNotAvailableDecorator(NotAvailableDecorator notAvailableDecorator) {
this.notAvailableDecorator = notAvailableDecorator;
}
public void setUserSelect(boolean userSelect) {
this.userSelect = userSelect;
}
}
package br.ufpr.c3sl.agendador.agendador.helpers.listeners;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AdapterView;
......@@ -9,9 +10,9 @@ import com.prolificinteractive.materialcalendarview.MaterialCalendarView;
import java.util.List;
import br.ufpr.c3sl.agendador.agendador.helpers.decorators.SchedulesDecorator;
import br.ufpr.c3sl.agendador.agendador.helpers.decorators.NotAvailableDecorator;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.helpers.decorators.NotAvailableDecorator;
import br.ufpr.c3sl.agendador.agendador.helpers.decorators.SchedulesDecorator;
import br.ufpr.c3sl.agendador.agendador.models.ServiceType;
import br.ufpr.c3sl.agendador.agendador.presenters.SchedulingPresenter;
......@@ -46,19 +47,20 @@ public class ServiceTypeSpinnerListener implements AdapterView.OnItemSelectedLis
this.tv_calendarHeaderDayHour = calendarHeaderDayHour;
this.days_short = days_short;
this.months_short = months_short;
userSelect = false;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
userSelect = true;
Log.v("Array out of Bounds bug", "Clicou no spinner de tipos de serviço");
return false;
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
if (userSelect && serviceTypes != null && serviceTypes.size() > 0 ) {
presenter.requestAvailableSchedules(serviceTypes.get((int)id).getmId());
userSelect = false;
presenter.requestAvailableSchedules(serviceTypes.get(pos).getmId());
Utils.updateCalendarHeaderDate(mcv, tv_calendarHeaderYear, tv_calendarHeaderDayHour, days_short, months_short, null);
......@@ -71,6 +73,9 @@ public class ServiceTypeSpinnerListener implements AdapterView.OnItemSelectedLis
mcv.invalidateDecorators();
}
userSelect = false;
Log.v("Array out of Bounds bug", "Selecionou o item "+ pos +" do spinner de tipos de serviço");
}
@Override
......
......@@ -16,6 +16,9 @@ public class ServiceLocation {
@SerializedName("name")
private String mName;
@SerializedName("schedule_period")
private int mPeriod;
@SerializedName("schedules")
private List<ServiceSchedule> schedules;
......@@ -33,5 +36,7 @@ public class ServiceLocation {
return mId;
}
public int getmPeriod(){return this.mPeriod;}
public List<ServiceSchedule> getSchedules(){return this.schedules;}
}
......@@ -24,8 +24,6 @@ import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import static android.util.Log.d;
/**
* Created by Horstmann on 02/03/17.
*/
......@@ -96,11 +94,11 @@ public class AccountPresenter extends BasePresenter<AccountView> {
switch (status) {
case 404:
Log.d("Server response", "404 - Falha!");
Log.e("Server response", "404 - Falha!");
accountPresenter.view().setProgressBar(false);
break;
case 422:
Log.d("Server response", "422 - Erro na requisição!");
Log.e("Server response", "422 - Erro na requisição!");
accountPresenter.view().showPasswordWarning();
accountPresenter.view().setProgressBar(false);
updateToken(headers);
......@@ -118,8 +116,7 @@ public class AccountPresenter extends BasePresenter<AccountView> {
@Override
public void onFailure(Call<AccountOutput> call, Throwable t) {
Log.d("Server response", "Requisição falhou!!");
Log.e("Server response", "Requisição falhou!!");
accountPresenter.view().setProgressBar(false);
accountPresenter.view().setNoConnection(true);
}
......
......@@ -79,7 +79,7 @@ public class CitizensPresenter extends BasePresenter<CitizenActivity> {
citizensPresenter.view().setProgressBar(false);
break;
default:
Log.d("Server response", getClass().getName() + ": ERRO:" + status);
Log.e("Server response", getClass().getName() + ": ERRO:" + status);
citizensPresenter.view().onRequestFailure();
break;
}
......@@ -88,7 +88,7 @@ public class CitizensPresenter extends BasePresenter<CitizenActivity> {
@Override
public void onFailure(Call<List<UserOutput>> call, Throwable t) {
Log.d("Server response", getClass().getName() + ": Requisição falhou!!");
Log.e("Server response", getClass().getName() + ": Requisição falhou!!");
citizensPresenter.view().setProgressBar(false);
citizensPresenter.view().onRequestFailure();
}
......
......@@ -89,13 +89,13 @@ public class SchedulingPresenter extends BasePresenter<SchedulingView> {
schedulingPresenter.view().setProgressBar(false, serviceTypes.size() > 0 ? SchedulingActivity.SECTOR_SElECTED : SchedulingActivity.NO_AVAILABLE_TYPE);
break;
default:
Log.d("Server response", getClass().getName() + ": ERRO:" + status);
Log.e("Server response", getClass().getName() + ": ERRO:" + status);
break;
}
}
@Override
public void onFailure(Call<List<ServiceType>> call, Throwable t) {
Log.d("Server response", "REQUEST FAIL");
Log.e("Server response", "REQUEST FAIL");
schedulingPresenter.view().setNoConnection(true);
schedulingPresenter.view().setProgressBar(false, SchedulingActivity.REQUEST_TYPES_ERROR);
}
......@@ -131,13 +131,13 @@ public class SchedulingPresenter extends BasePresenter<SchedulingView> {
schedulingPresenter.view().setProgressBar(false, serviceLocations.size() > 0 ? SchedulingActivity.TYPE_SELECTED : SchedulingActivity.NO_AVAILABLE_LOCATION);
break;
default:
Log.d("Server response", getClass().getName() + " SCHEDULES: ERRO:" + status);
Log.e("Server response", getClass().getName() + " SCHEDULES: ERRO:" + status);
break;
}
}
@Override
public void onFailure(Call<List<ServiceLocation>> call, Throwable t) {
Log.d("Server response", "REQUEST FAIL");
Log.e("Server response", "REQUEST FAIL");
schedulingPresenter.view().setNoConnection(true);
schedulingPresenter.view().setProgressBar(false, SchedulingActivity.REQUEST_SCHEDULES_ERROR);
}
......
......@@ -81,7 +81,7 @@ public class TermPresenter extends BasePresenter<TermActivity>{
termPresenter.view().setProgressBar(false);
break;
default:
Log.d("Server response", getClass().getName() + ": ERRO:" + status);
Log.e("Server response", getClass().getName() + ": ERRO:" + status);
termPresenter.view().onRequestFailure();
break;
}
......@@ -90,7 +90,7 @@ public class TermPresenter extends BasePresenter<TermActivity>{
@Override
public void onFailure(Call<List<SectorInput>> call, Throwable t) {
Log.d("Server response", getClass().getName() + ": Requisição falhou!!");
Log.e("Server response", getClass().getName() + ": Requisição falhou!!");
termPresenter.view().setProgressBar(false);
termPresenter.view().onRequestFailure();
}
......
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