Commit df0da51f authored by Lucas Braz Cunha's avatar Lucas Braz Cunha

AGILE#227: [Bug fix] Actvities Scheduling & History support orientation change

Signed-off-by: Lucas Braz Cunha's avatarLucas B. Cunha <lbc16@inf.ufpr.br>
parent d8fc25cf
......@@ -48,10 +48,7 @@
</service>
<activity android:name=".TermActivity" />
<activity
android:name=".SchedulingActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait" />
<activity android:name=".SchedulingActivity"/>
<activity android:name=".CitizenListActivity" />
<activity android:name=".SchedulesActivity" />
<activity android:name=".ScheduleConfirmationActivity" />
......
......@@ -2,7 +2,6 @@ package br.ufpr.c3sl.agendador.agendador;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
......@@ -16,7 +15,6 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.menu.MenuBuilder;
import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.util.Pair;
import android.view.Gravity;
import android.view.Menu;
......@@ -68,8 +66,13 @@ public class SchedulesHistoryActivity extends AppCompatActivity implements Navig
private FormFilters filters;
private long[] sectorsIdArray, serviceTypesIdArray, servicePlacesIdArray, situationIdArray;
private Button bt_search, bt_clear;
private FilterListener filterListener;
private static final String EXIT_CONFIRMATION_DIALOG_TAG = "exit_dialog";
private static final String SPINNER_SECTOR = "spinner_setor";
private static final String SPINNER_TYPE = "spinner_type";
private static final String SPINNER_PLACES = "spinner_places";
private static final String SPINNER_SITUATION = "spinner_situation";
private static final String FILTERS = "filters";
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -81,6 +84,7 @@ public class SchedulesHistoryActivity extends AppCompatActivity implements Navig
presenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
if (presenter == null)
presenter = new SchedulesHistoryPresenter(this);
}
historyListView = (ExpandableListView) findViewById(R.id.explv_history);
......@@ -234,14 +238,11 @@ public class SchedulesHistoryActivity extends AppCompatActivity implements Navig
bt_clear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sp_sector.setSelection(0);
sp_serviceType.setSelection(0);
sp_servicePlaces.setSelection(0);
sp_situation.setSelection(0);
onSuccessfulSectorRequest(filters);
}
});
FilterListener filterListener = new FilterListener(this);
filterListener = new FilterListener(this);
sp_sector.setOnItemSelectedListener(filterListener);
sp_sector.setOnTouchListener(filterListener);
......@@ -251,7 +252,34 @@ public class SchedulesHistoryActivity extends AppCompatActivity implements Navig
sp_servicePlaces.setOnItemSelectedListener(filterListener);
sp_servicePlaces.setOnTouchListener(filterListener);
if(savedInstanceState != null) {
filters = savedInstanceState.getParcelable(FILTERS);
onSuccessfulSectorRequest(filters);
int sectorPos = savedInstanceState.getInt(SPINNER_SECTOR, 0);
int typePos = savedInstanceState.getInt(SPINNER_TYPE, 0);
int placesPos = savedInstanceState.getInt(SPINNER_PLACES, 0);
int situationPos = savedInstanceState.getInt(SPINNER_SITUATION, 0);
if (sectorPos != 0) {
sp_sector.setSelection(sectorPos);
updateSpinners(sp_sector.getId());
}
if (typePos != 0) {
sp_serviceType.setSelection(typePos);
updateSpinners(sp_serviceType.getId());
}
if (placesPos != 0) {
sp_servicePlaces.setSelection(placesPos);
updateSpinners(sp_servicePlaces.getId());
}
if (situationPos != 0) {
sp_situation.setSelection(situationPos);
updateSpinners(sp_situation.getId());
}
}
}
......@@ -260,11 +288,17 @@ public class SchedulesHistoryActivity extends AppCompatActivity implements Navig
super.onResume();
presenter.bindView(this);
navigationView.setCheckedItem(R.id.nav_schedules_history);
if (expandableListDetail == null) {
if (filters == null) {
presenter.requestSectors();
}
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
}
@Override
protected void onPause() {
super.onPause();
......@@ -274,9 +308,16 @@ public class SchedulesHistoryActivity extends AppCompatActivity implements Navig
@Override
public void onSaveInstanceState(Bundle outState) {
PresenterManager.getInstance().savePresenter(presenter, outState);
outState.putInt(SPINNER_SECTOR, sp_sector.getSelectedItemPosition());
outState.putInt(SPINNER_TYPE, sp_serviceType.getSelectedItemPosition());
outState.putInt(SPINNER_PLACES, sp_servicePlaces.getSelectedItemPosition());
outState.putInt(SPINNER_SITUATION, sp_situation.getSelectedItemPosition());
outState.putParcelable(FILTERS, filters);
super.onSaveInstanceState(outState);
}
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Intent intent;
......@@ -526,8 +567,13 @@ public class SchedulesHistoryActivity extends AppCompatActivity implements Navig
break;
case R.id.spnr_history_type:
//to keep selection, if list(of options) is updated
selectedPlaceId = servicePlacesIdArray[sp_servicePlaces.getSelectedItemPosition()];
if(sp_serviceType.getSelectedItemPosition() != 0){
//Selecting the respective sector for this service type.
selectedServiceTypeId = serviceTypesIdArray[sp_serviceType.getSelectedItemPosition()];
serviceTypeSectorId = -1;
......@@ -624,12 +670,13 @@ public class SchedulesHistoryActivity extends AppCompatActivity implements Navig
case R.id.spnr_history_place:
selectedTypeId = serviceTypesIdArray[sp_serviceType.getSelectedItemPosition()];
if(sp_servicePlaces.getSelectedItemPosition() != 0){
selectedPlaceId = servicePlacesIdArray[sp_servicePlaces.getSelectedItemPosition()];
long selectedServicePlaceId = servicePlacesIdArray[sp_servicePlaces.getSelectedItemPosition()];
ServicePlace servicePlace = null;
ServicePlace servicePlace = null;
for(ServicePlace sv : filters.getServicePlaces()){
if(sv.getId() == selectedServicePlaceId)
if(sv.getId() == selectedPlaceId)
servicePlace = sv;
}
......@@ -645,7 +692,9 @@ public class SchedulesHistoryActivity extends AppCompatActivity implements Navig
serviceTypesArray.add(filters.getServiceTypes().get(j));
}
if(serviceTypesArray.size() > 0){
serviceTypesNamesArray = new String[serviceTypesArray.size()];
serviceTypesIdArray = new long[serviceTypesArray.size()];
for (i = 0; i < serviceTypesArray.size(); ++i) {
......
......@@ -18,7 +18,7 @@ import br.ufpr.c3sl.agendador.agendador.models.ServicePlace;
* Created by Lucas B. Cunha on 05/07/17.
*/
public class LocationSpinnerListener implements AdapterView.OnItemSelectedListener, View.OnTouchListener {
public class ServicePlaceSpinnerListener implements AdapterView.OnItemSelectedListener, View.OnTouchListener {
private boolean userSelect;
......@@ -35,8 +35,8 @@ public class LocationSpinnerListener implements AdapterView.OnItemSelectedListen
private String[] days_short, months_short;
public LocationSpinnerListener(MaterialCalendarView mcv, TextView calendarHeaderYear,
TextView calendarHeaderDayHour, String[] days_short, String[] months_short){
public ServicePlaceSpinnerListener(MaterialCalendarView mcv, TextView calendarHeaderYear,
TextView calendarHeaderDayHour, String[] days_short, String[] months_short){
this.mcv = mcv;
this.tv_calendarHeaderYear = calendarHeaderYear;
this.tv_calendarHeaderDayHour = calendarHeaderDayHour;
......
......@@ -74,7 +74,6 @@ public class ServiceTypeSpinnerListener implements AdapterView.OnItemSelectedLis
}
userSelect = false;
Log.v("Array out of Bounds bug", "Selecionou o item "+ pos +" do spinner de tipos de serviço");
}
@Override
......
......@@ -40,4 +40,5 @@ public class FilterListener implements AdapterView.OnItemSelectedListener, View.
public void onNothingSelected(AdapterView<?> parent) {
}
}
package br.ufpr.c3sl.agendador.agendador.models;
import android.os.Parcel;
import android.os.Parcelable;
import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import java.util.List;
/**
* Created by Lucas B. Cunha on 23/10/17.
*/
public class FormFilters {
public class FormFilters implements Parcelable {
@SerializedName("sectors")
private List<SectorInput> sectors;
......@@ -29,6 +33,38 @@ public class FormFilters {
this.situationList = situationList;
}
public FormFilters(Parcel pc) {
pc.readList(sectors, SectorInput.class.getClassLoader());
pc.readList(serviceTypes, ServiceType.class.getClassLoader());
pc.readList(servicePlaces, ServicePlace.class.getClassLoader());
pc.readList(situationList, Situation.class.getClassLoader());
}
/** Static field used to regenerate object, individually or as arrays */
public static final Parcelable.Creator<FormFilters> CREATOR = new Parcelable.Creator<FormFilters>() {
public FormFilters createFromParcel(Parcel pc) {
return new FormFilters(pc);
}
public FormFilters[] newArray(int size) {
return new FormFilters[size];
}
};
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeList(sectors);
dest.writeList(serviceTypes);
dest.writeList(servicePlaces);
dest.writeList(situationList);
}
@Override
public int describeContents() {
return 0;
}
public List<SectorInput> getSectors() {
return sectors;
}
......@@ -41,17 +77,51 @@ public class FormFilters {
return servicePlaces;
}
public List<Situation> getSituationList() {
return situationList;
}
public static class Situation{
public static class Situation implements Parcelable{
@SerializedName("id")
public int id;
@SerializedName("description")
public String description;
Situation(Parcel pc){
id = pc.readInt();
description = pc.readString();
}
/**
* Flatten this object in to a Parcel.
*
* @param dest The Parcel in which the object should be written.
* @param flags Additional flags about how the object should be written.
* May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}.
*/
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeString(description);
}
/** Static field used to regenerate object, individually or as arrays */
public static final Parcelable.Creator<Situation> CREATOR = new Parcelable.Creator<Situation>() {
public Situation createFromParcel(Parcel pc) {
return new Situation(pc);
}
public Situation[] newArray(int size) {
return new Situation[size];
}
};
@Override
public int describeContents() {
return 0;
}
}
}
\ No newline at end of file
......@@ -157,7 +157,7 @@ public class SchedulingPresenter extends BasePresenter<SchedulingView> {
switch (status) {
case 200:
Log.d("Server response", getClass().getName() + " SCHEDULES: 200 - Sucesso!");
schedulingPresenter.view().setServiceLocationList(servicePlaces);
schedulingPresenter.view().setServicePlacesList(servicePlaces);
schedulingPresenter.view().setProgressBar(false, servicePlaces.size() > 0 ? SchedulingActivity.TYPE_SELECTED : SchedulingActivity.NO_AVAILABLE_LOCATION);
break;
default:
......
......@@ -18,7 +18,7 @@ public interface SchedulingView {
void setServiceTypesList(List<ServiceType> serviceTypes);
void setServiceLocationList(List<ServicePlace> servicePlaces);
void setServicePlacesList(List<ServicePlace> servicePlaces);
void onSuccessfulConfirm(ScheduleConfirmation confirmation);
......
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