private void InitializeArrangers()
        {
            foreach (var arranger in Items.Values)
            {
                arranger.OnItemsChanged -= _arrangerItemsChangedHandler.Handler;
            }

            DateTime date = StartDate;

            for (int i = 0; i < 7; i++, date = date.AddDays(1))
            {
                var arranger = DayScheduleItemsArranger.Create(
                    account: Account,
                    semesterItems: SemesterViewItemsGroup,
                    scheduleGroup: MainScreenViewModel.ScheduleViewItemsGroup,
                    date: date,
                    heightOfHour: _heightOfHour,
                    spacingWhenNoAdditionalItems: _spacingWhenNoAdditionalItems,
                    spacingWithAdditionalItems: _spacingWithAdditionalItems,
                    widthOfCollapsed: WidthOfCollapsed,
                    includeHomeworkAndHolidays: true);

                arranger.OnItemsChanged += _arrangerItemsChangedHandler.Handler;

                Items[date.DayOfWeek] = arranger;
            }

            CalibrateMaxStartEndTimes();
            UpdateHasAllDayItems();
            NotifyDisplayDatesChanged();
        }
Example #2
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);
            }
        }
Example #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);
            }
        }
Example #4
0
        public void Deinitialize()
        {
            // Make sure to cancel the async initialize
            _request++;

            if (_arrangedItems != null && _arrangedItemsOnItemsChangedHandler != null)
            {
                _arrangedItems.OnItemsChanged -= _arrangedItemsOnItemsChangedHandler;
            }
            if (_holidaysOnDay != null && _holidaysChangedHandler != null)
            {
                _holidaysOnDay.CollectionChanged -= _holidaysChangedHandler;
            }

            _arrangedItems = null;
            _holidaysOnDay = null;

            if (_holidaysItemsWrapper != null)
            {
                _holidaysItemsWrapper.ItemsSource = null;
            }
        }