Skip to content

Commit

Permalink
Added getters for isOverflowDateVisible and isMultiDaySelectedEnabled
Browse files Browse the repository at this point in the history
Start to work on #32
  • Loading branch information
jonatansalas committed Jan 22, 2017
1 parent 6c147a6 commit 77b9007
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

public final class MainActivity extends AppCompatActivity implements MainView {
private static final String DATE_TEMPLATE = "dd/MM/yyyy";
private static final String MONTH_TEMPLATE = "MMMM yyyy";

private final MainPresenter presenter = new MainPresenter(this);

Expand All @@ -53,9 +54,6 @@ public final class MainActivity extends AppCompatActivity implements MainView {
@BindView(R.id.calendar_view)
CalendarView calendarView;

@NonNull
private final SimpleDateFormat formatter = new SimpleDateFormat(DATE_TEMPLATE, Locale.getDefault());

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -86,27 +84,24 @@ public boolean onNavigationItemSelected(MenuItem item) {

@Override
public void prepareTextView() {
textView.setText(String.format("Today is %s", formatter.format(new Date(System.currentTimeMillis()))));
textView.setText(String.format("Today is %s", formatDate(DATE_TEMPLATE, new Date(System.currentTimeMillis()))));
}

@Override
public void prepareCalendarView() {
final ActionBar actionBar = getSupportActionBar();
calendarView.setFirstDayOfWeek(Calendar.MONDAY)
.setOnDateClickListener(this::onDateClick)
.setOnMonthChangeListener(this::onMonthChange)
.setOnDateLongClickListener(this::onDateLongClick)
.setOnMonthTitleClickListener(this::onMonthTitleClick);

if (calendarView.isMultiSelectDayEnabled()) {
calendarView.setOnMultipleDaySelectedListener((month, dates) -> {
//Do something with your current selection
});
}

calendarView.setFirstDayOfWeek(Calendar.MONDAY);
calendarView.setIsOverflowDateVisible(true);
calendarView.update(Calendar.getInstance(Locale.getDefault()));
calendarView.setOnDateLongClickListener(selectedDate -> textView.setText(formatter.format(selectedDate)));
calendarView.setOnMonthChangeListener(monthDate -> {
final SimpleDateFormat df = new SimpleDateFormat("MMMM yyyy", Locale.getDefault());

if (null != actionBar) {
String dateStr = df.format(monthDate);
dateStr = dateStr.substring(0, 1).toUpperCase() + dateStr.substring(1, dateStr.length());

actionBar.setTitle(dateStr);
}
});
}

@Override
Expand All @@ -131,4 +126,31 @@ public void animateViews() {
animate(fab, getApplicationContext());
animate(textView, getApplicationContext());
}

private void onDateLongClick(@NonNull final Date date) {
textView.setText(formatDate(DATE_TEMPLATE, date));
}

private void onDateClick(@NonNull final Date date) {
textView.setText(formatDate(DATE_TEMPLATE, date));
}

private void onMonthTitleClick(@NonNull final Date date) {
//Do something after month selection
}

private void onMonthChange(@NonNull final Date date) {
final ActionBar actionBar = getSupportActionBar();

if (null != actionBar) {
String dateStr = formatDate(MONTH_TEMPLATE, date);
dateStr = dateStr.substring(0, 1).toUpperCase() + dateStr.substring(1, dateStr.length());

actionBar.setTitle(dateStr);
}
}

private String formatDate(@NonNull String dateTemplate, @NonNull Date date) {
return new SimpleDateFormat(dateTemplate, Locale.getDefault()).format(date);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Parcelable;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
Expand Down Expand Up @@ -190,7 +191,6 @@ public final class CalendarView extends LinearLayout {
private int backButtonDrawable;
private int nextButtonDrawable;
private boolean isOverflowDateVisible;

private boolean isMultiSelectDayEnabled;

private int firstDayOfWeek;
Expand Down Expand Up @@ -231,6 +231,16 @@ public CalendarView(Context context, AttributeSet attrs) {
drawCalendar();
}

@Override
protected Parcelable onSaveInstanceState() {
return super.onSaveInstanceState();
}

@Override
protected void onRestoreInstanceState(Parcelable state) {
super.onRestoreInstanceState(state);
}

private void initTouchVariables() {
final ViewConfiguration configuration = ViewConfiguration.get(getContext());
final float density = getContext().getResources().getDisplayMetrics().density;
Expand Down Expand Up @@ -1268,4 +1278,12 @@ public CalendarView setMultiSelectDayEnabled(boolean multiSelectDayEnabled) {
invalidate();
return this;
}

public boolean isOverflowDateVisible() {
return isOverflowDateVisible;
}

public boolean isMultiSelectDayEnabled() {
return isMultiSelectDayEnabled;
}
}

0 comments on commit 77b9007

Please sign in to comment.