Esempio n. 1
0
        private void RenderDate(DateTime date)
        {
            // Clear current items
            var col = _scheduleHost.GetChildAt(getColumn(date.DayOfWeek)) as ViewGroup;

            // Remove all but the day header and all day items
            while (col.ChildCount > 2)
            {
                col.RemoveViewAt(2);
            }

            // Get arranger for the date
            var arranger = ViewModel.Items[date.DayOfWeek];

            foreach (var s in arranger.ScheduleItems)
            {
                var scheduleItem = new MyScheduleItemView(Context, s.Item);
                scheduleItem.Clickable = true;
                scheduleItem.Click    += ScheduleItem_Click;

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

            // 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())
            {
                View visual;
                if (e.IsCollapsedMode)
                {
                    visual = new MyCollapsedEventItem(Context)
                    {
                        Item = e
                    };
                }
                else
                {
                    visual = new MyFullEventItem(Context)
                    {
                        Item = e
                    };
                }

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

            if (!arranger.HolidayAndAllDayItems.Any() && !arranger.EventItems.Any() && !arranger.ScheduleItems.Any() && (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday))
            {
                col.Visibility = ViewStates.Gone;
            }
            else
            {
                col.Visibility = ViewStates.Visible;
            }

            if (arranger.HasHolidays)
            {
                var overlay = new View(Context)
                {
                    Background       = new ColorDrawable(new Color(228, 0, 137, 40)),
                    LayoutParameters = new ViewGroup.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent)
                };
                col.AddView(overlay);
            }

            if (arranger.IsDifferentSemester)
            {
                var diffSemesterOverlay = new DifferentSemesterOverlayControl(Context)
                {
                    LayoutParameters = new ViewGroup.LayoutParams(
                        ViewGroup.LayoutParams.MatchParent,
                        ViewGroup.LayoutParams.MatchParent)
                };
                diffSemesterOverlay.PinButtonToTop(60);
                col.AddView(diffSemesterOverlay);
            }

            //UpdateTimePaddingBasedOnAllDayItems();
        }
Esempio n. 2
0
        private void render()
        {
            if (_holidaysLayout == null)
            {
                _holidaysLayout = new LinearLayout(Context)
                {
                    Orientation = Orientation.Vertical
                };

                _holidaysItemsWrapper = new ItemsControlWrapper(_holidaysLayout)
                {
                    ItemTemplate = new CustomDataTemplate <ViewItemHoliday>(CreateHolidayView)
                };

                base.AddView(_holidaysLayout);
            }

            if (_schedulesContent == null)
            {
                _schedulesContent = new RelativeLayout(Context);
                base.AddView(_schedulesContent);
            }
            else
            {
                _schedulesContent.RemoveAllViews();
            }

            if (Classes == null || Date == DateTime.MinValue || !ViewModel.Semester.IsDateDuringThisSemester(Date))
            {
                base.Visibility = ViewStates.Gone;
                return;
            }

            if (!_arrangedItems.IsValid())
            {
                base.Visibility = ViewStates.Gone;
                return;
            }

            base.Visibility = ViewStates.Visible;

            //put in the vertical gap divider
            View verticalGap = new View(Context)
            {
                LayoutParameters = new RelativeLayout.LayoutParams(
                    GapSize,
                    RelativeLayout.LayoutParams.MatchParent)
                {
                    LeftMargin = TimeIndicatorSize + GapSize
                }
            };

            verticalGap.SetBackgroundResource(Resource.Color.scheduleSnapshotDividers);
            _schedulesContent.AddView(verticalGap);

            int row = 0;

            for (TimeSpan time = _arrangedItems.StartTime; time <= _arrangedItems.EndTime; time = time.Add(TimeSpan.FromHours(1)), row++)
            {
                int startHeight = row * HeightOfHour;

                _schedulesContent.AddView(new TextView(Context)
                {
                    Text             = Android.Text.Format.DateFormat.Is24HourFormat(Context) ? time.Hours.ToString() : new DateTime().Add(time).ToString("h ").TrimEnd(),
                    TextSize         = 26,
                    LayoutParameters = new RelativeLayout.LayoutParams(
                        TimeIndicatorSize,
                        TimeIndicatorSize)
                    {
                        TopMargin = startHeight
                    },
                    Gravity = GravityFlags.Center
                });

                //if not last row, add the divider
                if (time + TimeSpan.FromHours(1) <= _arrangedItems.EndTime)
                {
                    var v = new View(Context)
                    {
                        Background       = new ColorDrawable(Color.White),
                        LayoutParameters = new RelativeLayout.LayoutParams(
                            RelativeLayout.LayoutParams.MatchParent,
                            GapSize)
                        {
                            TopMargin = startHeight + TimeIndicatorSize
                        }
                    };
                    v.SetBackgroundResource(Resource.Color.scheduleSnapshotDividers);
                    _schedulesContent.AddView(v);
                }
            }

            // Render the schedules
            foreach (var s in _arrangedItems.ScheduleItems)
            {
                MyScheduleItem visual = new MyScheduleItem(Context, s.Item);
                visual.Click += TimeItem_Click;

                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())
            {
                View visual;
                if (e.IsCollapsedMode)
                {
                    visual = new MyCollapsedEventItem(Context)
                    {
                        Item = e
                    };
                }
                else
                {
                    visual = new MyFullEventItem(Context)
                    {
                        Item = e
                    };
                }

                AddVisualItem(visual, e);
            }
        }