Ejemplo n.º 1
0
        /// <summary>
        /// Setup 4 pages contain date grid views. These pages are recycled to use
        /// memory efficient.
        /// </summary>
        /// <param name="view">View.</param>
        private void SetupDateGridPages(View view)
        {
            var currentDateTime = new DateTime(_year, _month, 1);

            _datePageChangeListener = new DatePageChangeListener(this);
            _datePageChangeListener.CurrentDateTime = currentDateTime;

            var currentMonthGridAdapter = CreateCalendarGridAdapter(currentDateTime.Year, currentDateTime.Month);

            _daysInMonths = currentMonthGridAdapter.DateTimes;

            var nextMonthDateTime    = CalendarHelper.LastDateTimeOfNextMonth(currentDateTime);
            var nextMonthGridAdapter = CreateCalendarGridAdapter(nextMonthDateTime.Year, nextMonthDateTime.Month);

            var secondNextMonthDateTime    = CalendarHelper.LastDateTimeOfNextMonth(nextMonthDateTime);
            var secondNextMonthGridAdapter = CreateCalendarGridAdapter(secondNextMonthDateTime.Year, secondNextMonthDateTime.Month);

            var prevMonthDateTime    = CalendarHelper.LastDateTimeOfPreviousMonth(currentDateTime);
            var prevMonthGridAdapter = CreateCalendarGridAdapter(prevMonthDateTime.Year, prevMonthDateTime.Month);

            _calendarGridAdapters.Add(currentMonthGridAdapter);
            _calendarGridAdapters.Add(nextMonthGridAdapter);
            _calendarGridAdapters.Add(secondNextMonthGridAdapter);
            _calendarGridAdapters.Add(prevMonthGridAdapter);

            _datePageChangeListener.CalendarGridAdapters = _calendarGridAdapters;

            _infiniteDateViewPager                   = view.FindViewById <InfiniteViewPager>(Resource.Id.months_infinite_pager);
            _infiniteDateViewPager.IsEnabled         = _isSwipeEnabled;
            _infiniteDateViewPager.IsMaxWeekPerMonth = _isMaxWeekPerMonth;
            _infiniteDateViewPager.DaysInMonth       = _daysInMonths;

            var monthPagerAdapter = new MonthPagerAdapter(ChildFragmentManager);

            _dateGridFragments = monthPagerAdapter.DateGridFragmentList;

            for (var i = 0; i < NUMBER_OF_PAGES; i++)
            {
                var dateGridFragment    = _dateGridFragments[i];
                var calendarGridAdapter = _calendarGridAdapters[i];

                dateGridFragment.GridViewResource    = ResourceGridView();
                dateGridFragment.CalendarGridAdapter = calendarGridAdapter;

                dateGridFragment.OnItemClickEvent     += OnDateGridFragmentItemClicked;
                dateGridFragment.OnItemLongClickEvent += OnDateGridFragmentItemLongClicked;
            }

            var infinitePagerAdapter = new InfinitePagerAdapter(monthPagerAdapter);

            _infiniteDateViewPager.Adapter = infinitePagerAdapter;
            _infiniteDateViewPager.AddOnPageChangeListener(_datePageChangeListener);
        }
Ejemplo n.º 2
0
            public void UpdateAdapters(int position)
            {
                var currentAdapter = CalendarGridAdapters[Current(position)];
                var prevAdapter    = CalendarGridAdapters[Previous(position)];
                var nextAdapter    = CalendarGridAdapters[Next(position)];

                if (position == CurrentPage)
                {
                    currentAdapter.SetAdapterDateTime(_dateTime);
                    currentAdapter.NotifyDataSetChanged();

                    var prevDateTime = CalendarHelper.LastDateTimeOfPreviousMonth(_dateTime);
                    prevAdapter.SetAdapterDateTime(prevDateTime);
                    prevAdapter.NotifyDataSetChanged();

                    var nextDateTime = CalendarHelper.LastDateTimeOfNextMonth(_dateTime);
                    nextAdapter.SetAdapterDateTime(nextDateTime);
                    nextAdapter.NotifyDataSetChanged();
                }
                // Swipe right
                else if (position > CurrentPage)
                {
                    _dateTime = CalendarHelper.LastDateTimeOfNextMonth(_dateTime);

                    var nextDateTime = CalendarHelper.LastDateTimeOfNextMonth(_dateTime);
                    nextAdapter.SetAdapterDateTime(nextDateTime);
                    nextAdapter.NotifyDataSetChanged();
                }
                // Swipe left
                else
                {
                    _dateTime = CalendarHelper.LastDateTimeOfPreviousMonth(_dateTime);

                    var prevDateTime = CalendarHelper.LastDateTimeOfPreviousMonth(_dateTime);
                    prevAdapter.SetAdapterDateTime(prevDateTime);
                    prevAdapter.NotifyDataSetChanged();
                }

                CurrentPage = position;
            }