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

Issue AGILE#182 [WIP] showing dates on calendar

Signed-off-by: Lucas Braz Cunha's avatarLucas B. Cunha <lbc16@inf.ufpr.br>
parent 011330b3
......@@ -31,7 +31,11 @@
<activity android:name=".AccountActivity" />
<activity android:name=".ForgotPasswordActivity" />
<activity android:name=".TermActivity" />
<activity android:name=".SchedulingActivity" />
<activity android:name=".SchedulingActivity"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize"
/>
<activity android:name=".CitizenActivity"></activity>
</application>
......
......@@ -45,10 +45,10 @@ import java.util.List;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionChecker;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionErrorDialog;
import br.ufpr.c3sl.agendador.agendador.helpers.PhotoSelectionAdapter;
import br.ufpr.c3sl.agendador.agendador.helpers.DataValidador;
import br.ufpr.c3sl.agendador.agendador.helpers.DateValidator;
import br.ufpr.c3sl.agendador.agendador.helpers.Mask;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.helpers.PhotoSelectionAdapter;
import br.ufpr.c3sl.agendador.agendador.helpers.UserPhotoHelper;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.presenters.AccountPresenter;
......@@ -569,7 +569,7 @@ public class AccountActivity extends AppCompatActivity implements AccountView {
et_sus_number.setText(osb.getString("sus", null));
et_cep.setText(osb.getString("address.zipcode", null));
et_number.setText(osb.getString("address_number", null));
et_birthdate.setText(DataValidador.stringToDate(osb.getString("birth_date", null), true));
et_birthdate.setText(DateValidator.stringToDate(osb.getString("birth_date", null), true));
et_disability.setText(pcd);
et_address.setText(osb.getString("address.address", null));
et_neighborhood.setText(osb.getString("address.neighborhood", null));
......@@ -593,7 +593,7 @@ public class AccountActivity extends AppCompatActivity implements AccountView {
private boolean validateData() {
clearWarnings();
boolean openDialog = false;
String bDate = DataValidador.stringToDate(et_birthdate.getText().toString(), false);
String bDate = DateValidator.stringToDate(et_birthdate.getText().toString(), false);
if (et_name.getText().toString().replaceAll("\\s+", "").isEmpty()) {
tv_name_warning.setText(R.string.null_name);
......@@ -603,7 +603,7 @@ public class AccountActivity extends AppCompatActivity implements AccountView {
tv_name_warning.setVisibility(View.INVISIBLE);
}
if (bDate.isEmpty() || !DataValidador.isValidBirthDate(bDate)) {
if (bDate.isEmpty() || !DateValidator.isValidBirthDate(bDate)) {
tv_birthdate_warning.setText(R.string.invalid_birthdate);
tv_birthdate_warning.setVisibility(View.VISIBLE);
openDialog = true;
......@@ -616,7 +616,7 @@ public class AccountActivity extends AppCompatActivity implements AccountView {
tv_email_warning.setVisibility(View.VISIBLE);
openDialog = true;
} else {
if (DataValidador.isValidEmail(et_email.getText().toString())) {
if (DateValidator.isValidEmail(et_email.getText().toString())) {
tv_email_warning.setVisibility(View.INVISIBLE);
} else {
tv_email_warning.setText(R.string.invalid_email);
......@@ -815,7 +815,7 @@ public class AccountActivity extends AppCompatActivity implements AccountView {
values.put("name", et_name.getText().toString());
values.put("rg", et_rg.getText().toString());
values.put("birth_date", DataValidador.stringToDate(et_birthdate.getText().toString(), false));
values.put("birth_date", DateValidator.stringToDate(et_birthdate.getText().toString(), false));
if (rb_no.isChecked()) {
values.put("pcd", null);
......
......@@ -6,10 +6,7 @@ import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
......@@ -80,13 +77,12 @@ public class CitizenActivity extends AppCompatActivity implements CitizenView{
}
public void onLongClickItem(View v, int position) {
//Log.d("AAAAAAaaaaa", "On long Click Item interface");
//do nothing.
}
}));
citizensPresenter.bindView(this);
citizensPresenter.requestCitizens();
citizensPresenter.bindView(this);
citizensPresenter.requestCitizens();
}
......
......@@ -24,6 +24,7 @@ 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;
......@@ -36,6 +37,11 @@ import br.ufpr.c3sl.agendador.agendador.views.HomeView;
* Created by Bruno Freitas Tissei on 2/7/17.
*/
// TODO: 03/07/17 Sugestão: após agendamento perguntar se usuário quer visualizar sua lista de agendamentos.
public class HomeActivity extends AppCompatActivity implements HomeView,
NavigationView.OnNavigationItemSelectedListener {
private HomePresenter presenter;
......@@ -52,6 +58,8 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
private ConfirmationDialog confirmationDialog;
private Button btn_schedule;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -64,8 +72,8 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
setContentView(R.layout.activity_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.agendador_toolbar);
toolbar.setTitle(null);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(null);
osb = ObscuredSharedPreferences.getPrefs(this, "Agendador", Context.MODE_PRIVATE);
String citizenName = osb.getString("name", null);
......@@ -125,6 +133,16 @@ public class HomeActivity extends AppCompatActivity implements HomeView,
navigationView.setNavigationItemSelectedListener(this);
btn_schedule = (Button) findViewById(R.id.btn_homeact_schedule);
btn_schedule.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(HomeActivity.this, TermActivity.class);
startActivity(intent);
}
});
changeTextColor();
}
......
......@@ -18,7 +18,7 @@ import java.util.HashMap;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionChecker;
import br.ufpr.c3sl.agendador.agendador.helpers.ConnectionErrorDialog;
import br.ufpr.c3sl.agendador.agendador.helpers.DataValidador;
import br.ufpr.c3sl.agendador.agendador.helpers.DateValidator;
import br.ufpr.c3sl.agendador.agendador.helpers.Mask;
import br.ufpr.c3sl.agendador.agendador.presenters.SignupPresenter;
import br.ufpr.c3sl.agendador.agendador.views.SignupView;
......@@ -144,7 +144,7 @@ public class SignupActivity extends AppCompatActivity implements SignupView {
public boolean validateData() {
boolean openDialog = false;
String bDate = DataValidador.stringToDate(et_birthday.getText().toString(), false);
String bDate = DateValidator.stringToDate(et_birthday.getText().toString(), false);
if (et_name.getText().toString().replaceAll("\\s+", "").isEmpty()) {
openDialog = true;
......@@ -157,7 +157,7 @@ public class SignupActivity extends AppCompatActivity implements SignupView {
tv_cpf_warning.setText(R.string.cpf_empty);
tv_cpf_warning.setVisibility(View.VISIBLE);
} else {
if (DataValidador.isValidCPF(Mask.unmask(et_cpf.getText().toString()))) {
if (DateValidator.isValidCPF(Mask.unmask(et_cpf.getText().toString()))) {
tv_cpf_warning.setVisibility(View.INVISIBLE);
} else {
......@@ -166,7 +166,7 @@ public class SignupActivity extends AppCompatActivity implements SignupView {
openDialog = true;
}
}
if (bDate.isEmpty() || !DataValidador.isValidBirthDate(bDate)) {
if (bDate.isEmpty() || !DateValidator.isValidBirthDate(bDate)) {
openDialog = true;
tv_birthday_warning.setVisibility(View.VISIBLE);
} else {
......@@ -177,7 +177,7 @@ public class SignupActivity extends AppCompatActivity implements SignupView {
tv_email_warning.setVisibility(View.VISIBLE);
openDialog = true;
} else {
if (DataValidador.isValidEmail(et_email.getText().toString())) {
if (DateValidator.isValidEmail(et_email.getText().toString())) {
tv_email_warning.setVisibility(View.INVISIBLE);
} else {
tv_email_warning.setText(R.string.invalid_email);
......@@ -295,7 +295,7 @@ public class SignupActivity extends AppCompatActivity implements SignupView {
HashMap<String,String> values = new HashMap<String,String>();
values.put("cpf",Mask.unmask(et_cpf.getText().toString()));
values.put("birth_date",DataValidador.stringToDate(et_birthday.getText().toString(),false));
values.put("birth_date", DateValidator.stringToDate(et_birthday.getText().toString(),false));
values.put("name",et_name.getText().toString());
values.put("cep",Mask.unmask(et_cep.getText().toString()));
values.put("password_confirmation",et_password_confirm.getText().toString());
......
......@@ -170,6 +170,12 @@ public class TermActivity extends AppCompatActivity implements TermView {
return builder.create();
}
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
getActivity().onBackPressed();
}
}
/**
......
......@@ -6,12 +6,13 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.InputMismatchException;
import java.util.Locale;
/**
* Created by horstmann on 18/02/17.
*/
public class DataValidador {
public class DateValidator {
public static boolean isValidEmail(String email) {
return !(email.isEmpty()) && android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches();
......@@ -37,7 +38,7 @@ public class DataValidador {
sm = 0;
peso = 10;
for (i = 0; i < 9; i++) {
num = (int) (cpf.charAt(i) - 48);
num = cpf.charAt(i) - 48;
sm = sm + (num * peso);
peso = peso - 1;
}
......@@ -52,7 +53,7 @@ public class DataValidador {
sm = 0;
peso = 11;
for (i = 0; i < 10; i++) {
num = (int) (cpf.charAt(i) - 48);
num = cpf.charAt(i) - 48;
sm = sm + (num * peso);
peso = peso - 1;
}
......@@ -76,11 +77,11 @@ public class DataValidador {
public static String stringToDate(String birth_date, boolean invert) {
SimpleDateFormat formatter, formatter2;
if (invert) {
formatter = new SimpleDateFormat("yyyy-MM-dd");
formatter2 = new SimpleDateFormat("dd/MM/yyyy");
formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
formatter2 = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
}else {
formatter = new SimpleDateFormat("dd/MM/yyyy");
formatter2 = new SimpleDateFormat("MMM dd yyyy");
formatter = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
formatter2 = new SimpleDateFormat("MMM dd yyyy", Locale.getDefault());
}
formatter.setLenient(false);
formatter2.setLenient(false);
......@@ -97,7 +98,7 @@ public class DataValidador {
public static boolean isValidBirthDate(String birth_date){
Date today = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("MMM dd yyyy");
SimpleDateFormat formatter = new SimpleDateFormat("MMM dd yyyy", Locale.getDefault());
try {
Date birth = formatter.parse(birth_date);
Log.d("DataV:is_valid_birth", birth.toString());
......
......@@ -7,24 +7,36 @@ import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.DayViewDecorator;
import com.prolificinteractive.materialcalendarview.DayViewFacade;
import java.util.Collection;
import java.util.HashSet;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import br.ufpr.c3sl.agendador.agendador.R;
import br.ufpr.c3sl.agendador.agendador.models.ServiceSchedule;
/**
* Created by lbc16 on 25/05/17.
* Created by Lucas B. Cunha on 25/05/17.
*/
public class EventDecorator implements DayViewDecorator {
private final HashSet<CalendarDay> dates;
public static int INVALID_STATE = -1;
private List<HashMap<String,ArrayList<ServiceSchedule>>> listOfScheduleDays;
private Context context;
public EventDecorator(Collection<CalendarDay> dates, Context context) {
this.dates = new HashSet<>(dates);
private int scheduleType;
private DateFormat dateFormat;
public EventDecorator(List<HashMap<String,ArrayList<ServiceSchedule>>> listOfScheduleDays, Context context) {
this.listOfScheduleDays = listOfScheduleDays;
this.context = context;
dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
}
/**
......@@ -35,7 +47,7 @@ public class EventDecorator implements DayViewDecorator {
*/
@Override
public boolean shouldDecorate(CalendarDay day) {
return dates.contains(day);
return scheduleType != INVALID_STATE && listOfScheduleDays.get(scheduleType).containsKey(dateFormat.format(day.getDate()));
}
/**
......@@ -46,5 +58,16 @@ public class EventDecorator implements DayViewDecorator {
@Override
public void decorate(DayViewFacade view) {
view.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.date_highlight));
}
public void setScheduleType(int scheduleType){
this.scheduleType = scheduleType;
}
public void setListOfScheduleDays(List<HashMap<String, ArrayList<ServiceSchedule>>> listOfScheduleDays) {
this.listOfScheduleDays = listOfScheduleDays;
}
}
......@@ -38,7 +38,6 @@ public abstract class Mask {
for (char m : mask.toCharArray()) {
if (m != '#') {
mask2 += m;
continue;
}else{
try {
mask2 += str.charAt(i);
......
package br.ufpr.c3sl.agendador.agendador.helpers;
import android.content.Context;
import android.support.v4.content.ContextCompat;
import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.DayViewDecorator;
import com.prolificinteractive.materialcalendarview.DayViewFacade;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import br.ufpr.c3sl.agendador.agendador.R;
import br.ufpr.c3sl.agendador.agendador.models.ServiceSchedule;
/**
* Created by Lucas B. Cunha on 13/07/17.
*/
public class SchedulingDecorator implements DayViewDecorator {
public static int INVALID_STATE = -1;
private List<HashMap<String,ArrayList<ServiceSchedule>>> listOfScheduleDays;
private Context context;
private int scheduleType;
private DateFormat dateFormat;
public SchedulingDecorator(List<HashMap<String,ArrayList<ServiceSchedule>>> listOfScheduleDays, Context context) {
this.listOfScheduleDays = listOfScheduleDays;
this.context = context;
dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
}
/**
* Determine if a specific day should be decorated
*
* @param day {@linkplain CalendarDay} to possibly decorate
* @return true if this decorator should be applied to the provided day
*/
@Override
public boolean shouldDecorate(CalendarDay day) {
return scheduleType != INVALID_STATE && !listOfScheduleDays.get(scheduleType).containsKey(dateFormat.format(day.getDate()));
}
/**
* Set decoration options onto a facade to be applied to all relevant days
*
* @param view View to decorate
*/
@Override
public void decorate(DayViewFacade view) {
view.setSelectionDrawable(ContextCompat.getDrawable(context, R.drawable.date_transparent));
}
public void setScheduleType(int scheduleType){
this.scheduleType = scheduleType;
}
public void setListOfScheduleDays(List<HashMap<String, ArrayList<ServiceSchedule>>> listOfScheduleDays) {
this.listOfScheduleDays = listOfScheduleDays;
}
}
......@@ -4,15 +4,22 @@ import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Base64;
import android.util.Base64OutputStream;
import android.util.TypedValue;
import android.widget.TextView;
import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.MaterialCalendarView;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Calendar;
/**
* Created by Lucas B. Cunha on 31/03/17.
......@@ -28,10 +35,11 @@ public class Utils {
public static final String SECTORS_CITIZENS_BUNDLE = "br.ufpr.c3sl.agendador.agendador.sectors_citizens_bundle";
public final static String DIR_PICTRS = "pictures";
public final static String USR_PICT_FILE_NAME = "usr_prof_pic";
public static final String DIR_PICTRS = "pictures";
static final String USR_PICT_FILE_NAME = "usr_prof_pic";
public final static String CITIZEN = "citizen_object";
public static final String CITIZEN = "citizen_object";
public static int getPixelValue(int dp, Context context) {
Resources resources = context.getResources();
......@@ -39,7 +47,7 @@ public class Utils {
dp, resources.getDisplayMetrics());
}
public static boolean isImage(File file) {
static boolean isImage(File file) {
if (file == null || !file.exists()) {
return false;
}
......@@ -53,9 +61,7 @@ public class Utils {
byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
return decodedByte;
return BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
}
// Converting File to Base64.encode String type using Method
......@@ -83,4 +89,23 @@ public class Utils {
return encodedFile;
}
public static void updateCalendarHeaderDate(@NonNull MaterialCalendarView mcv, @NonNull TextView tv_calendarHeaderYear,
@NonNull TextView tv_calendarHeaderDayHour, @NonNull String[] days_short,
@NonNull String[] months_short, @Nullable CalendarDay date){
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);
tv_calendarHeaderDayHour.setText(days_short[calendar.get(Calendar.DAY_OF_WEEK) - 1] + ", " +
months_short[calendar.get(Calendar.MONTH)] + " " + calendar.get(Calendar.DAY_OF_MONTH));
}
}
package br.ufpr.c3sl.agendador.agendador.helpers;
package br.ufpr.c3sl.agendador.agendador.helpers.adapters;
import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.widget.ArrayAdapter;
import java.util.List;
/**
* Created by Lucas B. Cunha on 07/07/17.
*
* Thanks to Ranjith Kumar at http://stackoverflow.com/questions/37019941/how-to-add-a-hint-in-spinner-in-xml
*/
public class HintAdapter extends ArrayAdapter<String>{
public HintAdapter(Context context, int resource) {
super(context, resource);
}
public HintAdapter(Context context, int resource, int textViewResourceId) {
super(context, resource, textViewResourceId);
}
public class HintAdapter extends ArrayAdapter<String> {
public HintAdapter(Context context, int resource, String[] objects) {
super(context, resource, objects);
}
public HintAdapter(Context context, int resource, int textViewResourceId, String[] objects) {
super(context, resource, textViewResourceId, objects);
}
public HintAdapter(Context context, int resource, List<String> objects) {
super(context, resource, objects);
}
public HintAdapter(Context context, int resource, int textViewResourceId, List<String> objects) {
super(context, resource, textViewResourceId, objects);
public HintAdapter(@NonNull Context context, @LayoutRes int resource) {
super(context, resource);
}
@Override
......
package br.ufpr.c3sl.agendador.agendador.helpers.listeners;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;
import com.prolificinteractive.materialcalendarview.MaterialCalendarView;
import java.util.List;
import br.ufpr.c3sl.agendador.agendador.helpers.EventDecorator;
import br.ufpr.c3sl.agendador.agendador.helpers.SchedulingDecorator;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
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.
*/
public class LocationSpinnerListener implements AdapterView.OnItemSelectedListener, View.OnTouchListener {
private boolean userSelect = false;
private SchedulingPresenter presenter;
private List<ServiceLocation> serviceLocations;
private EventDecorator decorator;
private SchedulingDecorator schedulingDecorator;
private MaterialCalendarView mcv;
private TextView tv_calendarHeaderYear, tv_calendarHeaderDayHour;
private String[] days_short, months_short;
public LocationSpinnerListener(SchedulingPresenter presenter, 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;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
userSelect = true;
return false;
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
if (userSelect && serviceLocations != null && serviceLocations.size() > 0) {
mcv.setSelectionMode(MaterialCalendarView.SELECTION_MODE_SINGLE);
decorator.setScheduleType(pos);
schedulingDecorator.setScheduleType(pos);
mcv.invalidateDecorators();
userSelect = false;
Utils.updateCalendarHeaderDate(mcv, tv_calendarHeaderYear, tv_calendarHeaderDayHour, days_short, months_short, null);
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
public void setServiceLocations(List<ServiceLocation> serviceLocations) {
this.serviceLocations = serviceLocations;
}
public void setUserSelect(boolean userSelect){
this.userSelect = userSelect;
}
public void setDecorator(EventDecorator decorator) {
this.decorator = decorator;
}
public void setSchedulingDecorator(SchedulingDecorator schedulingDecorator) {
this.schedulingDecorator = schedulingDecorator;
}
}
package br.ufpr.c3sl.agendador.agendador.helpers.listeners;
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.EventDecorator;
import br.ufpr.c3sl.agendador.agendador.helpers.SchedulingDecorator;
import br.ufpr.c3sl.agendador.agendador.helpers.Utils;
import br.ufpr.c3sl.agendador.agendador.models.SectorInput;
import br.ufpr.c3sl.agendador.agendador.presenters.SchedulingPresenter;