Пример #1
0
        void DaySelected(object sender, EventArgs args)
        {
            var calendarBarDay = sender as CalendarBarDayView;

            if (calendarBarDay == null)
            {
                System.Diagnostics.Debug.WriteLine("[CalendarBar] Day selected event can't be executed");
                return;
            }

            if (_selectedCalendarBarDay != null && calendarBarDay.Date == _selectedCalendarBarDay.Date)
            {
                return;
            }

            calendarBarDay.IsSelected = true;
            _selectedDate             = calendarBarDay.Date;
            if (_selectedCalendarBarDay != null)
            {
                _selectedCalendarBarDay.IsSelected = false;
            }
            _selectedCalendarBarDay = calendarBarDay;

            DayChanged?.Invoke(this, new CalendarBarEventArgs()
            {
                Date = calendarBarDay.Date, Source = DateSelectionSource.Bar
            });
        }
Пример #2
0
        public void CreateCalendar()
        {
            if (MeasuredWidth == 0)
            {
                return;
            }

            var metrics = Resources.System.DisplayMetrics;

            var dayCount         = 999;
            var originalDayCount = 999;

            RemoveAllViews();

            bool isCalendarEnabled = true;

            _maxDaysOnBar = (int)Math.Floor(
                (double)Utils.ConvertPixelsToDp(MeasuredWidth, Context) / CalendarBarDayView.CALENDAR_DAY_WIDTH
                );

            originalDayCount  = (int)(_endDate - _originalStartDate).TotalDays + 1;
            dayCount          = (int)(_endDate - _startDate).TotalDays + 1;
            isCalendarEnabled = originalDayCount > _maxDaysOnBar;

            if (isCalendarEnabled)
            {
                _maxDaysOnBar = (int)Math.Floor(
                    (double)(Utils.ConvertPixelsToDp(MeasuredWidth, Context) - CALENDAR_MORE_SECTION_MIN_WIDTH) / CalendarBarDayView.CALENDAR_DAY_WIDTH
                    );
            }

            int daysOnBar = (int)Math.Min(_maxDaysOnBar, dayCount);

            CalendarBarDayView calendarBarDay;
            DateTime           currentDate;

            for (int i = 0; i < daysOnBar; i++)
            {
                currentDate    = _startDate.AddDaysSafe(i).Date;
                calendarBarDay = AddDay(currentDate);

                if (calendarBarDay.IsSelected)
                {
                    _selectedCalendarBarDay = calendarBarDay;
                }
            }

            if (isCalendarEnabled)
            {
                AddMoreDaysSection();
            }

            if (_calendarMoreButton != null)
            {
                _calendarMoreButton.SetTextColor(TextColor);
                _calendarMoreButton.Text = CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedMonthName(_selectedDate.Month).ToUpper();
            }
        }
Пример #3
0
        CalendarBarDayView AddDay(DateTime currentDate)
        {
            var calendarBarDay = new CalendarBarDayView(Context)
            {
                Date                   = currentDate,
                TextColor              = TextColor,
                SelectedTextColor      = SelectedTextColor,
                IsSelected             = IsSelected(currentDate),
                TodayText              = TodayText,
                SelectedIndicatorColor = SelectedIndicatorColor,
                TextSize               = _textSize,
                DayTextSize            = _dayTextSize
            };

            calendarBarDay.Click += DaySelected;

            AddView(calendarBarDay);

            return(calendarBarDay);
        }