Ejemplo n.º 1
0
        private void render()
        {
            _scheduleGapLines.ClearAllSubviews();
            _scheduleItemsColumn.ClearAllSubviews();
            _scheduleTimesColumn.ClearAllSubviews();
            _timetable.SetHeight(0);
            _timetableHeight = 0;

            if (Date == DateTime.MinValue || !SemesterItems.Semester.IsDateDuringThisSemester(Date))
            {
                UpdateVisibility();
                UpdateTotalHeight();
                return;
            }

            if (!_arrangedItems.IsValid())
            {
                UpdateVisibility();
                UpdateTotalHeight();
                return;
            }

            base.Hidden = false;

            float totalHeight = ((int)(_arrangedItems.EndTime - _arrangedItems.StartTime).TotalHours + 1) * HEIGHT_OF_HOUR;

            _timetable.SetHeight(totalHeight);
            _timetableHeight = totalHeight;

            UpdateTotalHeight();

            for (TimeSpan time = _arrangedItems.StartTime; time <= _arrangedItems.EndTime; time = time.Add(TimeSpan.FromHours(1)))
            {
                string text = DateTime.Today.Add(time).ToString("h:").TrimEnd(':');

                var label = new UILabel()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    Font          = UIFont.PreferredHeadline,
                    Lines         = 1,
                    Text          = text,
                    TextAlignment = UITextAlignment.Center,
                    TextColor     = UIColorCompat.SecondaryLabelColor
                };
                _scheduleTimesColumn.Add(label);
                label.StretchWidth(_scheduleTimesColumn);
                label.SetHeight(HEIGHT_OF_HOUR);
                label.PinToTop(_scheduleTimesColumn, GetTopMarginAsPx(time, _arrangedItems.StartTime));

                // Add the divider if not the first
                if (time != _arrangedItems.StartTime)
                {
                    var gap = new UIView()
                    {
                        TranslatesAutoresizingMaskIntoConstraints = false,
                        BackgroundColor = UIColorCompat.SecondaryLabelColor
                    };
                    _scheduleGapLines.Add(gap);
                    gap.StretchWidth(_scheduleGapLines);
                    gap.SetHeight(GAP_SIZE);
                    gap.PinToTop(_scheduleGapLines, GetTopMarginAsPx(time, _arrangedItems.StartTime));
                }
            }

            foreach (var s in _arrangedItems.ScheduleItems)
            {
                UIScheduleItemView visual = new UIScheduleItemView(s.Item);
                visual.TouchUpInside += new WeakEventHandler(ScheduleItem_TouchUpInside).Handler;

                AddVisualItem(visual, s);
            }

            // Reverse the order so that when items expand, they appear on top of the items beneath them.
            // Otherwise I would have to do some crazy Z-order logic.
            foreach (var e in _arrangedItems.EventItems.Reverse())
            {
                UIView visual;
                if (e.IsCollapsedMode)
                {
                    visual = new UIScheduleViewEventItemCollapsed()
                    {
                        Item = e
                    };
                }
                else
                {
                    visual = new UIScheduleViewEventItemFull()
                    {
                        Item = e
                    };
                }

                AddVisualItem(visual, e);
            }
        }
Ejemplo n.º 2
0
        private void RenderDate(DateTime date)
        {
            var col = _scheduleColumns[GetColumn(date.DayOfWeek)];

            // Clear all items
            foreach (var item in col.Subviews)
            {
                item.RemoveFromSuperview();
            }

            // Get arranger for the date
            var arranger = ViewModel.Items[date.DayOfWeek];
            int colIndex = GetColumn(date.DayOfWeek);

            // Assign all day items
            List <object> holidayAndAllDayItemsWithBlankBottomView = new List <object>(arranger.HolidayAndAllDayItems);

            holidayAndAllDayItemsWithBlankBottomView.Add("BottomView");
            _allDayItemSourceAdapters[colIndex].ItemsSource = holidayAndAllDayItemsWithBlankBottomView;

            foreach (var s in arranger.ScheduleItems)
            {
                UIControl scheduleItem = new UIScheduleItemView(s.Item);
                scheduleItem.TouchUpInside += new WeakEventHandler(ScheduleItem_TouchUpInside).Handler;

                AddVisualItem(scheduleItem, s, date.DayOfWeek);
            }

            // If Saturday or Sunday and no items on day, hide it
            if (!arranger.HolidayAndAllDayItems.Any() && !arranger.EventItems.Any() && !arranger.ScheduleItems.Any() && (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday))
            {
                col.SetWidth(0);
                _allDayItemsRow.Subviews[colIndex].SetWidth(0);
                var dayLabel = _dayLabels[colIndex];
                dayLabel.SetWidth(0);
                if (colIndex <= _dayLabels.Length - 2)
                {
                    // Remove padding from the next item to compensate for the padding that we are keeping around
                    _dayLabels[colIndex + 1].SetToRightOf(dayLabel, _daysRow, 0);
                }
                return;
            }
            else
            {
                col.SetWidth(COL_WIDTH);
                _allDayItemsRow.Subviews[colIndex].SetWidth(COL_WIDTH);
                var dayLabel = _dayLabels[colIndex];
                dayLabel.SetWidth(COL_WIDTH - COL_PADDING);
                if (colIndex <= _dayLabels.Length - 2)
                {
                    // Re-add padding
                    _dayLabels[colIndex + 1].SetToRightOf(dayLabel, _daysRow, COL_PADDING);
                }
            }

            // Reverse the order so that when items expand, they appear on top of the items beneath them.
            // Otherwise I would have to do some crazy Z-order logic.
            foreach (var e in arranger.EventItems.Reverse())
            {
                UIView visual;
                if (e.IsCollapsedMode)
                {
                    visual = new UIScheduleViewEventItemCollapsed()
                    {
                        Item = e
                    };
                }
                else
                {
                    visual = new UIScheduleViewEventItemFull()
                    {
                        Item = e
                    };
                }

                AddVisualItem(visual, e, arranger.Date.DayOfWeek);
            }

            if (arranger.HasHolidays)
            {
                var overlay = new UIView
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    BackgroundColor = UIColor.FromRGBA(228 / 255f, 0, 137 / 225f, 0.3f)
                };
                col.Add(overlay);
                overlay.StretchWidth(col, right: 1);
                overlay.StretchHeight(col);
            }

            if (arranger.IsDifferentSemester)
            {
                var diffSemesterOverlay = new DifferentSemesterOverlayControl(
                    topPadding: 40,
                    leftPadding: COL_PADDING,
                    rightPadding: COL_PADDING)
                {
                    TranslatesAutoresizingMaskIntoConstraints = false
                };
                col.Add(diffSemesterOverlay);
                diffSemesterOverlay.StretchWidth(col);
                diffSemesterOverlay.StretchHeight(col);
            }

            //_mainView.AddConstraints(NSLayoutConstraint.FromVisualFormat($"H:|[timesColumn][contentColumn({COL_WIDTH * 7})]|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, new NSDictionary(
            //    "timesColumn", _timesColumn,
            //    "contentColumn", _contentColumn)));
        }