Esempio n. 1
0
        /// <summary>
        /// You CAN call this multiple times, it'll successfully clear previous
        /// </summary>
        /// <param name="classes"></param>
        /// <param name="date"></param>
        public async void Initialize(SemesterItemsViewGroup viewModel, DateTime date)
        {
            ViewModel = viewModel;
            Date      = date;

            try
            {
                _request++;
                var currRequest = _request;
                await viewModel.LoadingTask;
                if (currRequest != _request)
                {
                    // Another initialize happened while loading, so stop here on this old request
                    // (No concern about int overflow since it wraps by default)
                    return;
                }

                if (_arrangedItemsOnItemsChangedHandler == null)
                {
                    _arrangedItemsOnItemsChangedHandler = new WeakEventHandler <EventArgs>(_arrangedItems_OnItemsChanged).Handler;
                }
                else if (_arrangedItems != null)
                {
                    _arrangedItems.OnItemsChanged -= _arrangedItemsOnItemsChangedHandler;
                }

                _arrangedItems = DayScheduleItemsArranger.Create(PowerPlannerApp.Current.GetCurrentAccount(), ViewModel, PowerPlannerApp.Current.GetMainScreenViewModel().ScheduleViewItemsGroup, Date, TIME_INDICATOR_SIZE + GAP_SIZE, MyCollapsedEventItem.SPACING_WITH_NO_ADDITIONAL, MyCollapsedEventItem.SPACING_WITH_ADDITIONAL, MyCollapsedEventItem.WIDTH_OF_COLLAPSED_ITEM, includeTasksAndEventsAndHolidays: true);
                _arrangedItems.OnItemsChanged += _arrangedItemsOnItemsChangedHandler;

                render();

                if (_holidaysOnDay != null && _holidaysChangedHandler != null)
                {
                    _holidaysOnDay.CollectionChanged -= _holidaysChangedHandler;
                }
                if (_holidaysChangedHandler == null)
                {
                    _holidaysChangedHandler = new WeakEventHandler <NotifyCollectionChangedEventArgs>(HolidaysOnDay_CollectionChanged).Handler;
                }
                _holidaysOnDay = HolidaysOnDay.Create(viewModel.Items, date);
                _holidaysOnDay.CollectionChanged += _holidaysChangedHandler;
                _holidaysItemsWrapper.ItemsSource = _holidaysOnDay;
                UpdateHolidayOpacity();
            }

            // We want to allow ObjectDisposed to bubble up, so recyclers can know to dispose the view
            catch (ObjectDisposedException) { throw; }

            catch (Exception ex)
            {
                TelemetryExtension.Current?.TrackException(ex);
            }
        }
        public MainCalendarSquare(MainCalendarGrid calendarGrid, DateTime date, MyObservableList<BaseViewItemHomeworkExamGrade> allItems) : base(calendarGrid, date)
        {
            // Render is called before this

            AllowDrop = true;
            DragOver += MainCalendarSquare_DragOver;
            Drop += MainCalendarSquare_Drop;
            _itemsControl.ItemsSource = HomeworksOnDay.Get(allItems, date);
            _holidays = HolidaysOnDay.Create(allItems, date);
            _holidays.CollectionChanged += new WeakEventHandler<NotifyCollectionChangedEventArgs>(delegate { UpdateIsHoliday(); }).Handler;
            UpdateIsHoliday();
        }
Esempio n. 3
0
        public async void Initialize(SemesterItemsViewGroup semesterItems, DateTime date)
        {
            SemesterItems = semesterItems;
            Date          = date;

            try
            {
                _request++;
                var currRequest = _request;
                await semesterItems.LoadingTask;
                if (currRequest != _request)
                {
                    // Another initialize happened while loading, so stop here on this old request
                    // (No concern about int overflow since it wraps by default)
                    return;
                }

                if (_currHolidays != null && _currHolidaysChangedHandler != null)
                {
                    _currHolidays.CollectionChanged -= _currHolidaysChangedHandler;
                    _currHolidays = null;
                }

                _currHolidays = HolidaysOnDay.Create(semesterItems.Items, Date);
                _currHolidaysChangedHandler      = new WeakEventHandler <NotifyCollectionChangedEventArgs>(_currHolidays_CollectionChanged).Handler;
                _currHolidays.CollectionChanged += _currHolidaysChangedHandler;

                _holidaysItemsSourceAdapter.ItemsSource = _currHolidays;
                UpdateHolidaysBehavior();

                if (_arrangedItemsOnItemsChangedHandler == null)
                {
                    _arrangedItemsOnItemsChangedHandler = new WeakEventHandler <EventArgs>(_arrangedItems_OnItemsChanged).Handler;
                }
                else if (_arrangedItems != null)
                {
                    _arrangedItems.OnItemsChanged -= _arrangedItemsOnItemsChangedHandler;
                }

                _arrangedItems = DayScheduleItemsArranger.Create(PowerPlannerApp.Current.GetCurrentAccount(), semesterItems, PowerPlannerApp.Current.GetMainScreenViewModel().ScheduleViewItemsGroup, Date, HEIGHT_OF_HOUR, UIScheduleViewEventItemCollapsed.SPACING_WITH_NO_ADDITIONAL, UIScheduleViewEventItemCollapsed.SPACING_WITH_ADDITIONAL, UIScheduleViewEventItemCollapsed.WIDTH_OF_COLLAPSED_ITEM, includeTasksAndEventsAndHolidays: true);
                _arrangedItems.OnItemsChanged += _arrangedItemsOnItemsChangedHandler;

                render();
            }
            catch (Exception ex)
            {
                // There might have been a data error loading the main data, don't want to crash because of that
                TelemetryExtension.Current?.TrackException(ex);
            }
        }
Esempio n. 4
0
        public MainCalendarSquare(MainCalendarGrid calendarGrid, DateTime date, MyObservableList <BaseViewItemHomeworkExamGrade> allItems) : base(calendarGrid, date)
        {
            // Render is called before this

            _calendarViewModel = calendarGrid.ViewModel;
            _allItems          = allItems;
            AllowDrop          = true;
            DragOver          += MainCalendarSquare_DragOver;
            Drop += MainCalendarSquare_Drop;
            _calendarViewModel.PropertyChanged += new WeakEventHandler <PropertyChangedEventArgs>(_calendarViewModel_PropertyChanged).Handler;
            UpdateItemsSource();
            _holidays = HolidaysOnDay.Create(allItems, date);
            _holidays.CollectionChanged += new WeakEventHandler <NotifyCollectionChangedEventArgs>(delegate { UpdateIsHoliday(); }).Handler;
            UpdateIsHoliday();
        }
                public void UpdateDay(DateTime date, DayType dayType, bool isToday)
                {
                    _date = date;

                    if (isToday)
                    {
                        _backgroundView.SetBackgroundResource(Resource.Color.calendarBackgroundToday);
                    }
                    else
                    {
                        switch (dayType)
                        {
                        case DayType.ThisMonth:
                            _backgroundView.SetBackgroundResource(Resource.Color.calendarBackgroundThisMonth);
                            break;

                        default:
                            _backgroundView.SetBackgroundResource(Resource.Color.calendarBackgroundOther);
                            break;
                        }
                    }

                    _tv.Text = date.Day.ToString();

                    if (isToday)
                    {
                        _tv.SetTextColor(ColorTools.GetColor(this.Context, Resource.Color.calendarTextToday));
                    }
                    else
                    {
                        _tv.SetTextColor(_defaultTextColors);
                    }

                    UpdateSelectedStatus();

                    _myHomeworkCircles.SetItemsSource(_viewModel.SemesterItemsViewGroup.Items.Sublist(i => i is BaseViewItemHomeworkExam && i.Date.Date == date.Date && !(i as BaseViewItemHomeworkExam).IsComplete()));

                    if (_holidaysOnDay != null && _holidaysChangedHandler != null)
                    {
                        _holidaysOnDay.CollectionChanged -= _holidaysChangedHandler;
                    }
                    _holidaysOnDay                    = HolidaysOnDay.Create(_viewModel.SemesterItemsViewGroup.Items, date.Date);
                    _holidaysChangedHandler           = new WeakEventHandler <NotifyCollectionChangedEventArgs>(_holidaysOnDay_CollectionChanged).Handler;
                    _holidaysOnDay.CollectionChanged += _holidaysChangedHandler;
                    UpdateIsHoliday();
                }
Esempio n. 6
0
                public void UpdateDay(DateTime date, DayType dayType, bool isToday)
                {
                    _date = date;

                    if (isToday)
                    {
                        _backgroundView.Background = new ColorDrawable(Color.Argb(255, 117, 117, 117));
                    }
                    else
                    {
                        switch (dayType)
                        {
                        case DayType.ThisMonth:
                            _backgroundView.Background = new ColorDrawable(Color.Argb(255, 240, 240, 240));
                            break;

                        default:
                            _backgroundView.Background = new ColorDrawable(Color.Argb(255, 228, 228, 228));
                            break;
                        }
                    }

                    _tv.Text = date.Day.ToString();

                    if (isToday)
                    {
                        _tv.SetTextColor(Color.White);
                    }
                    else
                    {
                        _tv.SetTextColor(_defaultTextColors);
                    }

                    UpdateSelectedStatus();

                    _myHomeworkCircles.SetItemsSource(_viewModel.SemesterItemsViewGroup.Items.Sublist(i => i is BaseViewItemHomeworkExam && i.Date.Date == date.Date && !(i as BaseViewItemHomeworkExam).IsComplete()));

                    if (_holidaysOnDay != null && _holidaysChangedHandler != null)
                    {
                        _holidaysOnDay.CollectionChanged -= _holidaysChangedHandler;
                    }
                    _holidaysOnDay                    = HolidaysOnDay.Create(_viewModel.SemesterItemsViewGroup.Items, date.Date);
                    _holidaysChangedHandler           = new WeakEventHandler <NotifyCollectionChangedEventArgs>(_holidaysOnDay_CollectionChanged).Handler;
                    _holidaysOnDay.CollectionChanged += _holidaysChangedHandler;
                    UpdateIsHoliday();
                }