Commit 94c7e473 authored by Lucas Braz Cunha's avatar Lucas Braz Cunha

ISSUE AGILE#152: Added calendar with date highlight

Signed-off-by: Lucas Braz Cunha's avatarLucas B. Cunha <lbc16@inf.ufpr.br>
parent f0aabbce
...@@ -26,9 +26,11 @@ import android.widget.LinearLayout; ...@@ -26,9 +26,11 @@ import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import com.prolificinteractive.materialcalendarview.CalendarDay; import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.MaterialCalendarView; import com.prolificinteractive.materialcalendarview.MaterialCalendarView;
import com.prolificinteractive.materialcalendarview.OnDateSelectedListener;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collection; import java.util.Collection;
...@@ -39,13 +41,14 @@ import br.ufpr.c3sl.agendador.agendador.helpers.EventDecorator; ...@@ -39,13 +41,14 @@ import br.ufpr.c3sl.agendador.agendador.helpers.EventDecorator;
import br.ufpr.c3sl.agendador.agendador.helpers.HintAdapter; import br.ufpr.c3sl.agendador.agendador.helpers.HintAdapter;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences; import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.helpers.UserPhotoHelper; import br.ufpr.c3sl.agendador.agendador.helpers.UserPhotoHelper;
import br.ufpr.c3sl.agendador.agendador.presenters.SchedulingPresenter;
import br.ufpr.c3sl.agendador.agendador.views.SchedulingView; import br.ufpr.c3sl.agendador.agendador.views.SchedulingView;
/** /**
* Created by Lucas B. Cunha on 12/4/17. * Created by Lucas B. Cunha on 12/4/17.
*/ */
public class SchedulingActivity extends AppCompatActivity implements SchedulingView, NavigationView.OnNavigationItemSelectedListener { public class SchedulingActivity extends AppCompatActivity implements SchedulingView, NavigationView.OnNavigationItemSelectedListener, OnDateSelectedListener{
private MenuBuilder menuBuilder; private MenuBuilder menuBuilder;
...@@ -67,10 +70,15 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV ...@@ -67,10 +70,15 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
private MaterialCalendarView mcv; private MaterialCalendarView mcv;
private HashSet<CalendarDay> hash;
//TODO: create class "ConfirmationDialog" //TODO: create class "ConfirmationDialog"
private ConfirmationDialog confirmationDialog; private ConfirmationDialog confirmationDialog;
//requisição /citizens private String[] months_short;
private SchedulingPresenter schedulingPresenter;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -149,6 +157,8 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV ...@@ -149,6 +157,8 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
navigationView.setNavigationItemSelectedListener(this); navigationView.setNavigationItemSelectedListener(this);
schedulingPresenter = new SchedulingPresenter(this);
// TODO: 17/04/17 example on how to set hint to spinner // TODO: 17/04/17 example on how to set hint to spinner
String[] citizens = {"Lucas", "Selecione um cidadão"}; String[] citizens = {"Lucas", "Selecione um cidadão"};
...@@ -183,29 +193,29 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV ...@@ -183,29 +193,29 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
mcv = (MaterialCalendarView) ll_fields.findViewById(R.id.ll_scheduling_calendar).findViewById(R.id.mcv_scheduling_date); mcv = (MaterialCalendarView) ll_fields.findViewById(R.id.ll_scheduling_calendar).findViewById(R.id.mcv_scheduling_date);
mcv.setOnDateChangedListener(this);
if(mcv == null){ mcv.state().edit().setMinimumDate(CalendarDay.today()).commit();
Log.d("AAAAa", "aaaaaaaaaa");
}
else
mcv.state().edit().setMinimumDate(CalendarDay.today()).commit();
HashSet<CalendarDay> hash = new HashSet<>(); hash = new HashSet<>();
Calendar.getInstance().setTime(new Date()); Calendar.getInstance().setTime(new Date());
EventDecorator decorator; EventDecorator decorator;
hash.add(CalendarDay.today()); hash.add(CalendarDay.today());
decorator = new EventDecorator(ContextCompat.getColor(this, R.color.colorGreen), hash, this); decorator = new EventDecorator(hash, this);
mcv.addDecorator(decorator); mcv.addDecorator(decorator);
months_short = getResources().getStringArray(R.array.months_short_pt);
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
// TODO: 24/05/17 Arrumar a apresentação da data
String s = calendar.get(Calendar.YEAR) + ""; String s = calendar.get(Calendar.YEAR) + "";
tv_year.setText(s); tv_year.setText(s);
tv_day_month.setText(calendar.get(Calendar.DAY_OF_WEEK) + ", " + tv_day_month.setText(calendar.get(Calendar.DAY_OF_WEEK) + ", " +
calendar.get(Calendar.MONTH) + " " + calendar.get(Calendar.DAY_OF_MONTH)); months_short[calendar.get(Calendar.MONTH)] + " " + calendar.get(Calendar.DAY_OF_MONTH));
} }
...@@ -271,6 +281,31 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV ...@@ -271,6 +281,31 @@ public class SchedulingActivity extends AppCompatActivity implements SchedulingV
} }
} }
/**
* Called when a user clicks on a day.
* There is no logic to prevent multiple calls for the same date and state.
*
* @param widget the view associated with this listener
* @param date the date that was selected or unselected
* @param selected true if the day is now selected, false otherwise
*/
@Override
public void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull CalendarDay date, boolean selected) {
if(selected && hash.contains(date)) {
Toast.makeText(this, "Dia disponível selecionado", Toast.LENGTH_SHORT).show();
}
Calendar calendar = Calendar.getInstance();
date.copyTo(calendar);
String s = calendar.get(Calendar.YEAR) + "";
tv_year.setText(s);
tv_day_month.setText(calendar.get(Calendar.DAY_OF_WEEK) + ", " +
months_short[calendar.get(Calendar.MONTH)] + " " + calendar.get(Calendar.DAY_OF_MONTH));
}
public static class ConfirmationDialog extends DialogFragment { public static class ConfirmationDialog extends DialogFragment {
@Override @Override
......
...@@ -6,7 +6,6 @@ import android.support.v4.content.ContextCompat; ...@@ -6,7 +6,6 @@ import android.support.v4.content.ContextCompat;
import com.prolificinteractive.materialcalendarview.CalendarDay; import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.DayViewDecorator; import com.prolificinteractive.materialcalendarview.DayViewDecorator;
import com.prolificinteractive.materialcalendarview.DayViewFacade; import com.prolificinteractive.materialcalendarview.DayViewFacade;
import com.prolificinteractive.materialcalendarview.spans.DotSpan;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
...@@ -19,14 +18,11 @@ import br.ufpr.c3sl.agendador.agendador.R; ...@@ -19,14 +18,11 @@ import br.ufpr.c3sl.agendador.agendador.R;
public class EventDecorator implements DayViewDecorator { public class EventDecorator implements DayViewDecorator {
private final int color;
private final HashSet<CalendarDay> dates; private final HashSet<CalendarDay> dates;
private Context context; private Context context;
public EventDecorator(int color, Collection<CalendarDay> dates, Context context) { public EventDecorator(Collection<CalendarDay> dates, Context context) {
this.color = color;
this.dates = new HashSet<>(dates); this.dates = new HashSet<>(dates);
this.context = context; this.context = context;
} }
...@@ -49,6 +45,6 @@ public class EventDecorator implements DayViewDecorator { ...@@ -49,6 +45,6 @@ public class EventDecorator implements DayViewDecorator {
*/ */
@Override @Override
public void decorate(DayViewFacade view) { public void decorate(DayViewFacade view) {
view.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.green_button_shape)); view.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.date_highlight));
} }
} }
...@@ -10,6 +10,7 @@ import br.ufpr.c3sl.agendador.agendador.models.User; ...@@ -10,6 +10,7 @@ import br.ufpr.c3sl.agendador.agendador.models.User;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.http.Body; import retrofit2.http.Body;
import retrofit2.http.DELETE; import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.POST; import retrofit2.http.POST;
import retrofit2.http.PUT; import retrofit2.http.PUT;
...@@ -32,4 +33,8 @@ public interface ApiEndpoints { ...@@ -32,4 +33,8 @@ public interface ApiEndpoints {
@POST("validate_cep") @POST("validate_cep")
Call<Address> validateCep(@Body CepInput cepInput); Call<Address> validateCep(@Body CepInput cepInput);
// TODO: 29/05/17 is this the right class to receive back? need confirmation with back-end
@GET("citizens")
Call<AccountOutput> getDependents();
} }
\ No newline at end of file
package br.ufpr.c3sl.agendador.agendador.presenters;
import android.content.Context;
import br.ufpr.c3sl.agendador.agendador.helpers.ObscuredSharedPreferences;
import br.ufpr.c3sl.agendador.agendador.views.SchedulingView;
/**
* Created by lbc16 on 29/05/17.
*/
public class SchedulingPresenter extends BasePresenter<SchedulingView> {
private ObscuredSharedPreferences osb;
private Context context;
private SchedulingPresenter schedulingPresenter;
public SchedulingPresenter(Context context){
this.context = context;
this.schedulingPresenter = this;
}
@Override
protected void updateView() {
}
}
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="ring"
android:useLevel="false"
android:thickness="0dp">
<solid android:color="@color/colorGray"/>
<stroke android:color="@color/colorGreen" android:width="3dp"/>
</shape>
\ No newline at end of file
...@@ -115,6 +115,37 @@ ...@@ -115,6 +115,37 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
<LinearLayout
android:id="@+id/ll_accountact_state_container"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginEnd="35dp"
android:layout_marginStart="14dp">
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_gravity="center"
android:src="@drawable/date_highlight"/>
<TextView
android:id="@+id/tv_account_state"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="@string/scheduling_date"
android:textColor="@color/colorBlack"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/ll_scheduling_calendar" android:id="@+id/ll_scheduling_calendar"
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -159,8 +190,8 @@ ...@@ -159,8 +190,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
app:mcv_selectionColor="@color/colorGray"
app:mcv_showOtherDates="all" app:mcv_showOtherDates="all"
app:mcv_selectionColor="@color/colorGreen"
app:mcv_calendarMode="month" app:mcv_calendarMode="month"
app:mcv_monthLabels="@array/months_pt" app:mcv_monthLabels="@array/months_pt"
app:mcv_weekDayLabels="@array/days_pt"/> app:mcv_weekDayLabels="@array/days_pt"/>
......
...@@ -121,6 +121,20 @@ ...@@ -121,6 +121,20 @@
<item>Novembro</item> <item>Novembro</item>
<item>Dezembro</item> <item>Dezembro</item>
</string-array> </string-array>
<string-array name="months_short_pt">
<item>Jan</item>
<item>Fev</item>
<item>Mar</item>
<item>Abr</item>
<item>Mai</item>
<item>Jun</item>
<item>Jul</item>
<item>Ago</item>
<item>Set</item>
<item>Out</item>
<item>Nov</item>
<item>Dez</item>
</string-array>
<string-array name="days_pt"> <string-array name="days_pt">
<item>Seg</item> <item>Seg</item>
<item>Ter</item> <item>Ter</item>
...@@ -130,4 +144,5 @@ ...@@ -130,4 +144,5 @@
<item>Sab</item> <item>Sab</item>
<item>Dom</item> <item>Dom</item>
</string-array> </string-array>
<string name="scheduling_date">Datas disponíveis</string>
</resources> </resources>
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