Search in sources :

Example 1 with InfiniteViewPager

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);
}
Also used : DateWindow(com.instructure.candroid.model.DateWindow) InfiniteViewPager(com.antonyt.infiniteviewpager.InfiniteViewPager) CaldroidListener(com.roomorama.caldroid.CaldroidListener) Button(android.widget.Button) TextView(android.widget.TextView) DateFormatSymbols(java.text.DateFormatSymbols) ImageView(android.widget.ImageView) View(android.view.View) PageView(com.instructure.canvasapi2.utils.pageview.PageView) TextView(android.widget.TextView) Date(java.util.Date) DateTime(hirondelle.date4j.DateTime)

Aggregations

View (android.view.View)1 Button (android.widget.Button)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 InfiniteViewPager (com.antonyt.infiniteviewpager.InfiniteViewPager)1 DateWindow (com.instructure.candroid.model.DateWindow)1 PageView (com.instructure.canvasapi2.utils.pageview.PageView)1 CaldroidListener (com.roomorama.caldroid.CaldroidListener)1 DateTime (hirondelle.date4j.DateTime)1 DateFormatSymbols (java.text.DateFormatSymbols)1 Date (java.util.Date)1