Ejemplo n.º 1
0
        public TimetablePage()
        {
            InitializeComponent();
            AppSettings settings = SettingsRepository.GetSettings();

            lastTimeLeftVisible                 = TimeLeft.IsVisible;
            Timetable.VerticalOptions           = LayoutOptions.FillAndExpand;
            Timetable.VisibleDatesChangedEvent += Timetable_VisibleDatesChangedEvent;
            string activeCultureCode = Cultures.SupportedCultures[0].TwoLetterISOLanguageName;

            if (Cultures.SupportedCultures.Any(c => c.TwoLetterISOLanguageName == CultureInfo.CurrentCulture.TwoLetterISOLanguageName))
            {
                activeCultureCode = CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
            }
            Timetable.Locale = activeCultureCode;
            switch (settings.TimetableViewMode)
            {
            case TimetableViewMode.Day:
                Timetable.ScheduleView = ScheduleView.DayView;
                break;

            case TimetableViewMode.Week:
                Timetable.ScheduleView = ScheduleView.WeekView;
                break;

            case TimetableViewMode.Month:
                Timetable.ScheduleView = ScheduleView.MonthView;
                break;
            }

            MessagingCenter.Subscribe <Application, SavedEntity>(this, MessageTypes.SelectedEntityChanged, (sender, newSelectedEntity) =>
            {
                UpdateEvents(newSelectedEntity);
            });
            MessagingCenter.Subscribe <Application, SavedEntity>(this, MessageTypes.TimetableUpdated, (sender, entity) =>
            {
                SavedEntity selectedEntity = UniversityEntitiesRepository.GetSelected();
                if (selectedEntity == null || selectedEntity != entity)
                {
                    return;
                }
                UpdateEvents(selectedEntity);
            });
            MessagingCenter.Subscribe <Application, SavedEntity>(this, MessageTypes.LessonSettingsChanged, (sender, entity) =>
            {
                SavedEntity selectedEntity = UniversityEntitiesRepository.GetSelected();
                if (selectedEntity == null || selectedEntity != entity)
                {
                    return;
                }
                UpdateEvents(selectedEntity);
            });
        }
Ejemplo n.º 2
0
        public static async Task <IReadOnlyList <Entity> > CheckCistTimetableUpdateRightsAsync(params Entity[] entitiesToUpdate)
        {
            List <Entity> allowedEntities = new();

            entitiesToUpdate ??= Array.Empty <Entity>();

            List <SavedEntity> savedEntities = await UniversityEntitiesRepository.GetSavedAsync();

            foreach (var entity in entitiesToUpdate)
            {
                SavedEntity?savedEntity = savedEntities.SingleOrDefault(e => e == entity);
                if (savedEntity == null)
                {
                    // Cannot update timetable for entity that is not saved
                    continue;
                }

                DateTime nowInUkraine = TimeZoneInfo.ConvertTime(DateTime.Now, Config.UkraineTimezone);
                if (savedEntity.LastUpdated == null ||
                    nowInUkraine.TimeOfDay >= Config.CistDailyTimetableUpdateStartTime && nowInUkraine.TimeOfDay < Config.CistDailyTimetableUpdateEndTime)
                {
                    // Update allowed if never updated before
                    // Unlimited updates between 5 and 6 AM
                    allowedEntities.Add(savedEntity);
                    continue;
                }

                // Update is allowed once per day (day begins at 6 AM)
                DateTime lastUpdatedInUkraine = TimeZoneInfo.ConvertTime(savedEntity.LastUpdated.Value, Config.UkraineTimezone);
                TimeSpan timeBeforeAnotherUpdate;
                if (lastUpdatedInUkraine.TimeOfDay < Config.CistDailyTimetableUpdateEndTime)
                {
                    timeBeforeAnotherUpdate = Config.CistDailyTimetableUpdateEndTime - lastUpdatedInUkraine.TimeOfDay;
                }
                else
                {
                    timeBeforeAnotherUpdate = TimeSpan.FromDays(1) - lastUpdatedInUkraine.TimeOfDay + Config.CistDailyTimetableUpdateEndTime;
                }
                if (nowInUkraine - lastUpdatedInUkraine > timeBeforeAnotherUpdate)
                {
                    allowedEntities.Add(savedEntity);
                    continue;
                }

#if DEBUG
                allowedEntities.Add(savedEntity);
#endif
            }
            return(allowedEntities);
        }
Ejemplo n.º 3
0
        private void UpdateEventsWithUI()
        {
            Timetable.IsEnabled      = false;
            ProgressLayout.IsVisible = true;

            Task.Factory.StartNew(() =>
            {
                UpdateEvents(UniversityEntitiesRepository.GetSelected());

                Device.BeginInvokeOnMainThread(() =>
                {
                    ProgressLayout.IsVisible = false;
                    Timetable.IsEnabled      = true;
                });
            });
        }
            public async Task SettingsClicked()
            {
                List <string> actionList = new List <string> {
                    LN.UpdateTimetable, LN.SetUpLessonDisplay, LN.Delete
                };

                if (!IsSelected)
                {
                    actionList.Insert(0, LN.Select);
                }
                if (Device.RuntimePlatform == Device.Android &&
                    CrossDeviceInfo.Current.VersionNumber.Major > 0 &&
                    CrossDeviceInfo.Current.VersionNumber.Major < 5)
                {
                    // SfCheckBox doesn`t support Android 4
                    actionList.Remove(LN.SetUpLessonDisplay);
                }

                string action = await App.Current.MainPage.DisplayActionSheet(LN.ChooseAction, LN.Cancel, null, actionList.ToArray());

                if (action == LN.Select)
                {
                    UniversityEntitiesRepository.UpdateSelected(SavedEntity);
                    await _manageEntitiesViewModel.Navigation.PopToRootAsync();
                }
                else if (action == LN.UpdateTimetable)
                {
                    await _manageEntitiesViewModel.UpdateTimetable(SavedEntity);
                }
                else if (action == LN.SetUpLessonDisplay)
                {
                    await _manageEntitiesViewModel.Navigation.PushAsync(new ManageLessonsPage(SavedEntity));
                }
                else if (action == LN.Delete)
                {
                    _manageEntitiesViewModel.Entities.Remove(this);
                    UniversityEntitiesRepository.UpdateSaved(_manageEntitiesViewModel.Entities.Select(vm => vm.SavedEntity).ToList());
                }
            }
Ejemplo n.º 5
0
 protected override List <Group> GetAllEntities()
 {
     return(UniversityEntitiesRepository.GetAllGroups().ToList());
 }
Ejemplo n.º 6
0
 protected override List <Room> GetAllEntitiesFromCist()
 {
     return(UniversityEntitiesRepository.GetAllRooms().ToList());
 }
Ejemplo n.º 7
0
 protected override List <Teacher> GetAllEntitiesFromCist()
 {
     return(UniversityEntitiesRepository.GetAllTeachers().ToList());
 }