Commit 8a8bc493 authored by Lucas Braz Cunha's avatar Lucas Braz Cunha
Browse files

Issue AGILE#218: Done layout for Schedule visualization


Signed-off-by: Lucas Braz Cunha's avatarLucas B. Cunha <lbc16@inf.ufpr.br>
parent a34c10d8
......@@ -33,9 +33,8 @@ dependencies {
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.android.support.test.espresso:espresso-core:2.2.2'
compile 'com.firebase:firebase-jobdispatcher:0.6.0'
compile 'com.android.support.constraint:constraint-layout:1.0.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.prolificinteractive:material-calendarview:1.4.3'
compile 'com.android.support:recyclerview-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
}
......@@ -58,7 +58,9 @@
<activity android:name=".DependentUpdateActivity" />
<activity android:name=".NewDependentActivity" />
<activity android:name=".RetrievalFailureActivity" />
<activity android:name=".RetrievalSuccessActivity"/>
<activity android:name=".RetrievalSuccessActivity" />
<activity android:name=".SchedulesHistoryActivity" />
<activity android:name=".ScheduleInfoActivity"></activity>
</application>
</manifest>
\ No newline at end of file
......@@ -132,9 +132,9 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
navigationView.setNavigationItemSelectedListener(this);
Button btn_schedule = (Button) findViewById(R.id.btn_homeact_schedule);
Button bt_schedule = (Button) findViewById(R.id.btn_homeact_schedule);
btn_schedule.setOnClickListener(new View.OnClickListener() {
bt_schedule.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(HomeActivity.this, CitizenListActivity.class);
......@@ -142,11 +142,21 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
}
});
Button bt_checkSchedules = (Button) findViewById(R.id.btn_homeact_check);
bt_checkSchedules.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(HomeActivity.this, SchedulesActivity.class);
startActivity(intent);
}
});
snackbar = Snackbar.make(findViewById(R.id.coordinator_home), R.string.snackbar_home_description,Snackbar.LENGTH_LONG)
.setAction(R.string.snackbar_home_action, new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getBaseContext(), "Abrir a tela de agendamentos", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(HomeActivity.this, SchedulesActivity.class);
startActivity(intent);
}
});
changeTextColor();
......@@ -242,6 +252,10 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
intent = new Intent(this, DependentsListActivity.class);
startActivity(intent);
break;
case R.id.nav_schedules_history:
intent = new Intent(this, SchedulesHistoryActivity.class);
startActivity(intent);
break;
default:
break;
}
......
......@@ -217,6 +217,18 @@ public class ScheduleConfirmationActivity extends AppCompatActivity implements S
case R.id.nav_schedule:
//do nothing.
break;
case R.id.nav_check_schedules:
intent = new Intent(this, SchedulesActivity.class);
startActivity(intent);
break;
case R.id.nav_dependants:
intent = new Intent(this, DependentsListActivity.class);
startActivity(intent);
break;
case R.id.nav_schedules_history:
intent = new Intent(this, SchedulesHistoryActivity.class);
startActivity(intent);
break;
default:
break;
}
......
package br.ufpr.c3sl.agendador.agendador;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.app.DialogFragment;
import android.support.v4.widget.DrawerLayout;
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.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Locale;
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;
public class ScheduleInfoActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{
private MenuBuilder menuBuilder;
private ConfirmationDialogFragment confirmationDialogFragment;
private NavigationView navigationView;
private long id;
private CheckSchedules.Schedule schedule;
private static final String EXIT_CONFIRMATION_DIALOG_TAG = "exit_dialog";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_schedule_info);
Toolbar toolbar = (Toolbar) findViewById(R.id.agendador_toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(null);
ObscuredSharedPreferences osb = ObscuredSharedPreferences.getPrefs(this, "Agendador", Context.MODE_PRIVATE);
String citizenName = osb.getString("name", null);
String citizenCity = osb.getString("city.name", null);
ImageView drawerHamburger = (ImageView) toolbar.findViewById(R.id.img_toolbar_hamburger);
final DrawerLayout drawer;
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
navigationView = (NavigationView) findViewById(R.id.schedule_info_navigation_view);
View headerView = navigationView.getHeaderView(0);
ImageView drawerProfilePicture = (ImageView) headerView.findViewById(R.id.img_drawerheader_citizen_photo);
UserImgHelper userImgHelper = new UserImgHelper(getBaseContext());
TextView drawerCitizenName = (TextView) headerView.findViewById(R.id.tv_drawerheader_citizen_name);
TextView drawerCityName = (TextView) headerView.findViewById(R.id.tv_drawerheader_city_name);
drawerCitizenName.setText(citizenName);
drawerCityName.setText(citizenCity);
confirmationDialogFragment = new ConfirmationDialogFragment();
if(userImgHelper.existsPhoto(Utils.USR_PICT_FILE_NAME, osb.getLong(Utils.ID, 0))){
drawerProfilePicture.setImageBitmap(userImgHelper.getRoundBitmap(userImgHelper.getFileUri(Utils.USR_PICT_FILE_NAME, osb.getLong(Utils.ID, 0))));
}
drawerHamburger.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
drawer.openDrawer(Gravity.START);
}
});
navigationView.setCheckedItem(R.id.nav_check_schedules);
navigationView.setNavigationItemSelectedListener(this);
ActionMenuView actionMenuView = (ActionMenuView) toolbar.findViewById(R.id.agendador_toolbar_menu);
menuBuilder = (MenuBuilder) actionMenuView.getMenu();
//noinspection RestrictedApi
menuBuilder.setCallback(new MenuBuilder.Callback() {
@Override
public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
return onOptionsItemSelected(item);
}
@Override
public void onMenuModeChange(MenuBuilder menu) {
}
});
Bundle bundle = getIntent().getBundleExtra(Utils.SCHEDULE_BUNDLE);
if(bundle != null){
DateFormat df = new SimpleDateFormat("dd/MM/yyyy - HH:mm", Locale.getDefault());
String name = bundle.getString(Utils.NAME);
id = bundle.getLong(Utils.ID);
schedule = bundle.getParcelable(Utils.SCHEDULE);
TextView tv_name = (TextView) findViewById(R.id.tv_schedule_citizen_content);
TextView tv_sector = (TextView) findViewById(R.id.tv_schedule_sector_content);
TextView tv_location = (TextView) findViewById(R.id.tv_schedule_location_content);
TextView tv_type = (TextView) findViewById(R.id.tv_schedule_type_content);
TextView tv_date = (TextView) findViewById(R.id.tv_schedule_date_content);
TextView tv_address = (TextView) findViewById(R.id.tv_schedule_street_content);
tv_name.setText(name);
tv_sector.setText(schedule.getSectorName());
tv_location.setText(schedule.getLocationName());
tv_type.setText(schedule.getServiceTypeName());
tv_date.setText(df.format(schedule.getStartTime()));
String address = schedule.getAddressStreet() + ", " + schedule.getAddressNumber();
tv_address.setText(address);
}
Button bt_back = (Button) findViewById(R.id.btn_schedule_info_back);
bt_back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
}
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Intent intent;
switch (item.getItemId()) {
case R.id.nav_my_info:
intent = new Intent(this, AccountActivity.class);
startActivity(intent);
break;
case R.id.nav_schedule:
intent = new Intent(this, CitizenListActivity.class);
startActivity(intent);
break;
case R.id.nav_check_schedules:
break;
case R.id.nav_dependants:
intent = new Intent(this, DependentsListActivity.class);
startActivity(intent);
break;
case R.id.nav_schedules_history:
intent = new Intent(this, SchedulesHistoryActivity.class);
startActivity(intent);
break;
default:
}
return true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menuBuilder);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.logout_actionbtn:
confirmationDialogFragment.show(getSupportFragmentManager(), EXIT_CONFIRMATION_DIALOG_TAG);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public static class ConfirmationDialogFragment extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
super.onCreateDialog(savedInstanceState);
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.signout_confirmation)
.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
SchedulesActivity activity = (SchedulesActivity) getActivity();
// TODO: 05/10/17 fix here
//activity.presenter.onSignOutClicked();
}
})
.setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
// Create the AlertDialog object and return it
return builder.create();
}
}
}
package br.ufpr.c3sl.agendador.agendador;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.app.DialogFragment;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.menu.MenuBuilder;
import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.MaterialCalendarView;
import com.prolificinteractive.materialcalendarview.OnDateSelectedListener;
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.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.helpers.UserImgHelper;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.helpers.decorators.CheckSchedulesDecorator;
import br.ufpr.c3sl.agendador.agendador.models.CheckSchedules;
import br.ufpr.c3sl.agendador.agendador.presenters.PresenterManager;
import br.ufpr.c3sl.agendador.agendador.presenters.SchedulesPresenter;
import br.ufpr.c3sl.agendador.agendador.views.SchedulesView;
public class SchedulesActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
public class SchedulesActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, OnDateSelectedListener, SchedulesView {
private SchedulesPresenter presenter;
private ProgressBar pb_schedules;
private NavigationView navigationView;
private TextView tv_year, tv_day_month;
private MaterialCalendarView mcv;
private String[] months_short;
private String[] days_short;
private ConnectionErrorDialog connectionErrorDialog;
private ConfirmationDialogFragment confirmationDialogFragment;
private CheckSchedulesDecorator checkSchedulesDecorator;
private HashMap<String,ArrayList<CheckSchedules.Schedule>> hashSchedulesDays;
private List<CheckSchedules.Schedule> selectedSchedulesDay;
private CheckSchedules.Schedule selectedSchedule;
private CheckSchedules schedules;
private Date maxDate;
private DateFormat dateFormat, hourFormat;
private CalendarDay selectedDate;
private MenuBuilder menuBuilder;
private static final String SCHEDULES_TIME_ARRAY = "schedules_time_array";
private static final String SCHEDULE_TIME_DIALOG_TAG = "schedule_dialog";
private static final String EXIT_CONFIRMATION_DIALOG_TAG = "exit_dialog";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_schedules);
//fazer parecido com o agendador antigo e colocar uma string que diz quantos dias faltam
//arrumar os spinners pra terem duas coisas - ????
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rv_schedules);
if (savedInstanceState == null) {
presenter = new SchedulesPresenter(this);
} else {
presenter = PresenterManager.getInstance().restorePresenter(savedInstanceState);
if(presenter == null)
presenter = new SchedulesPresenter(this);
}
setContentView(R.layout.activity_schedules);
Toolbar toolbar = (Toolbar) findViewById(R.id.agendador_toolbar);
setSupportActionBar(toolbar);
......@@ -45,7 +115,6 @@ public class SchedulesActivity extends AppCompatActivity implements NavigationVi
String citizenCity = osb.getString("city.name", null);
MenuBuilder menuBuilder;
final DrawerLayout drawer;
ActionMenuView actionMenuView = (ActionMenuView) toolbar.findViewById(R.id.agendador_toolbar_menu);
menuBuilder = (MenuBuilder) actionMenuView.getMenu();
......@@ -66,7 +135,7 @@ public class SchedulesActivity extends AppCompatActivity implements NavigationVi
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
navigationView = (NavigationView) findViewById(R.id.home_navigation_view);
navigationView = (NavigationView) findViewById(R.id.schedules_navigation_view);
View headerView = navigationView.getHeaderView(0);
......@@ -81,6 +150,7 @@ public class SchedulesActivity extends AppCompatActivity implements NavigationVi
drawerCitizenName.setText(citizenName);
drawerCityName.setText(citizenCity);
confirmationDialogFragment = new ConfirmationDialogFragment();
if(userImgHelper.existsPhoto(Utils.USR_PICT_FILE_NAME, osb.getLong(Utils.ID, 0))){
drawerProfilePicture.setImageBitmap(userImgHelper.getRoundBitmap(userImgHelper.getFileUri(Utils.USR_PICT_FILE_NAME, osb.getLong(Utils.ID, 0))));
......@@ -98,12 +168,134 @@ public class SchedulesActivity extends AppCompatActivity implements NavigationVi
navigationView.setCheckedItem(R.id.nav_check_schedules);
navigationView.setNavigationItemSelectedListener(this);
pb_schedules = (ProgressBar) findViewById(R.id.pb_schedules);
dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
hourFormat = new SimpleDateFormat("HH:mm", Locale.getDefault());
hashSchedulesDays = new HashMap<>();
//Calendar view setup
days_short = getResources().getStringArray(R.array.days_pt);
months_short = getResources().getStringArray(R.array.months_short_pt);
LinearLayout ll_fields = (LinearLayout) findViewById(R.id.ll_schedules);
View v = ll_fields.findViewById(R.id.ll_schedules_calendar).findViewById(R.id.ll_schedules_calendar_header);
tv_year = (TextView) v.findViewById(R.id.tv_schedules_calendar_year);
tv_day_month = (TextView) v.findViewById(R.id.tv_schedules_calendar_day_month);
mcv = (MaterialCalendarView) ll_fields.findViewById(R.id.ll_schedules_calendar).findViewById(R.id.mcv_schedules_date);
mcv.setOnDateChangedListener(this);
mcv.state().edit().setMinimumDate(CalendarDay.today()).commit();
months_short = getResources().getStringArray(R.array.months_short_pt);
Calendar calendar = Calendar.getInstance();
String s = calendar.get(Calendar.YEAR) + "";
tv_year.setText(s);
tv_day_month.setText(days_short[calendar.get(Calendar.DAY_OF_WEEK) - 1] + ", " +
months_short[calendar.get(Calendar.MONTH)] + " " + calendar.get(Calendar.DAY_OF_MONTH));
//end of calendar setup
}
@Override
protected void onResume() {
super.onResume();
presenter.bindView(this);
navigationView.setCheckedItem(R.id.nav_check_schedules);
if(schedules == null)
presenter.requestSchedules();
}
@Override
protected void onPause() {
super.onPause();
presenter.unbindView();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menuBuilder);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.logout_actionbtn:
confirmationDialogFragment.show(getSupportFragmentManager(), EXIT_CONFIRMATION_DIALOG_TAG);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void onSuccessfulRequest(CheckSchedules schedules){
//calendar decorator setup
this.schedules = schedules;
//setup of schedules list & decorators
maxDate = new Date();
String date;
if(schedules.getSchedulesList() != null) {
for (CheckSchedules.Schedule schedule : schedules.getSchedulesList()) {
date = dateFormat.format(schedule.getStartTime());
if(schedule.getStartTime().after(maxDate)){
maxDate = schedule.getStartTime();
}
if (hashSchedulesDays.containsKey(date)) {
hashSchedulesDays.get(date).add(schedule);
} else {
ArrayList<CheckSchedules.Schedule> list = new ArrayList<>();
list.add(schedule);
hashSchedulesDays.put(date, list);
}
}
}
//getting dependents schedules
if(schedules.getDependentSchedulesList() != null) {
for (CheckSchedules.DependentSchedules dependentSchedules : schedules.getDependentSchedulesList()) {
for (CheckSchedules.Schedule schedule : dependentSchedules.getScheduleList()){
date = dateFormat.format(schedule.getStartTime());
if(schedule.getStartTime().after(maxDate)){
maxDate = schedule.getStartTime();
}
if (hashSchedulesDays.containsKey(date)) {
hashSchedulesDays.get(date).add(schedule);
} else {
ArrayList<CheckSchedules.Schedule> list = new ArrayList<>();
list.add(schedule);
hashSchedulesDays.put(date, list);
}
}
}
}