use of com.antonyt.infiniteviewpager.InfiniteViewPager in project instructure-android by instructure.
the class CalendarListViewFragment method setUpListeners.
private void setUpListeners() {
final CaldroidListener listener = new CaldroidListener() {
@Override
public void onSelectDate(Date date, View view) {
// New date selected, clear out prior
mCalendarFragment.clearSelectedDates();
mRecyclerAdapter.setSelectedDay(DateTime.forInstant(date.getTime(), TimeZone.getDefault()));
if (currentCalendarView == CalendarView.DAY_VIEW) {
mCalendarFragment.setSelectedDates(date, date);
} else if (currentCalendarView == CalendarView.WEEK_VIEW) {
DateWindow dateWindow = CanvasCalendarUtils.setSelectedWeekWindow(date, mRecyclerAdapter.isStartDayMonday());
mCalendarFragment.setSelectedDates(dateWindow.getStart(), dateWindow.getEnd());
}
mCalendarFragment.refreshView();
mRecyclerAdapter.refreshListView();
}
@Override
public void onCaldroidViewCreated() {
super.onCaldroidViewCreated();
// Removing styling for upper buttons
Button leftButton = mCalendarFragment.getLeftArrowButton();
Button rightButton = mCalendarFragment.getRightArrowButton();
TextView textView = mCalendarFragment.getMonthTitleTextView();
leftButton.setVisibility(View.GONE);
rightButton.setVisibility(View.GONE);
textView.setVisibility(View.GONE);
// Initialize post view created mCalendarFragment elements
InfiniteViewPager viewPager = mCalendarFragment.getDateViewPager();
viewPager.setPageMargin((int) ViewUtils.convertDipsToPixels(32, getContext()));
if (mRecyclerAdapter.getSelectedDay() == null) {
mRecyclerAdapter.setSelectedDay(DateTime.today(TimeZone.getDefault()));
Date today = new Date(mRecyclerAdapter.getSelectedDay().getMilliseconds(TimeZone.getDefault()));
mCalendarFragment.setSelectedDates(today, today);
}
mRecyclerAdapter.setCalendarViewCreated(true);
applyTheme();
}
@Override
public void onChangeMonth(int month, int year, boolean fromCreation) {
super.onChangeMonth(month, year, fromCreation);
if (mRecyclerAdapter != null && mRecyclerAdapter.getSelectedDay() != null && month == mRecyclerAdapter.getSelectedDay().getMonth()) {
// listener. We don't want to trigger the month change logic if the month is not changing.
return;
}
if (mMonthText != null) {
if (fromCreation || hasOrientationChanged()) {
hidePanda();
return;
}
// Update Actionbar
mMonthText.setText(new DateFormatSymbols().getMonths()[month - 1] + " " + year);
}
// First time loading the calendar will trigger this, but the API calls have already been made
if (!mRecyclerAdapter.isTodayPressed() && !fromCreation) {
// Refresh for month, unless this was triggered by "today" button
mCalendarFragment.clearSelectedDates();
DateTime today = DateTime.today(TimeZone.getDefault());
if (today.getMonth() == month && today.getYear() == year) {
mRecyclerAdapter.setSelectedDay(today);
} else {
mRecyclerAdapter.setSelectedDay(new DateTime(year, month, 1, null, null, null, null));
}
mRecyclerAdapter.refreshCalendar();
}
}
};
mCalendarFragment.setCaldroidListener(listener);
}
Aggregations