Пример #1
0
        private void Setup()
        {
            if (!App.Crawler.HasCourse(courseId))
            {
                ErrorReporting.Log("App.Crawler.HasCourse is false");
                SafeGoBack();
                return;
            }

            var course = App.Crawler.GetCourse(courseId);

            title.Text = course.Topic.Name;
            ErrorReporting.Log(courseId + " = " + course.Topic.Name + " [" + course.Name + "]");

            if (pivot.ItemsSource == null)
            {
                Load(false);
            }
            else
            {
                foreach (var lectureSection in pivot.ItemsSource.Cast <LectureSection>())
                {
                    foreach (var lecture in lectureSection.Lectures)
                    {
                        lecture.DownloadInfo.RefreshStatus();
                    }
                }
            }
        }
Пример #2
0
        public static void Init(PhoneApplicationPage page)
        {
            if (!(page is SettingsPage))
            {
                var settingsMenuItem = new ApplicationBarMenuItem("Settings");
                settingsMenuItem.Click += delegate
                {
                    ErrorReporting.Log("OnSettingsClick");
                    page.NavigateToSettings();
                };
                page.ApplicationBar.MenuItems.Add(settingsMenuItem);
            }

            var aboutButton = new ApplicationBarIconButton(new Uri("/Assets/Icons/dark/appbar.information.png", UriKind.Relative))
            {
                Text = "About"
            };

            aboutButton.Click += delegate
            {
                ErrorReporting.Log("OnAboutClick");
                page.NavigationService.Navigate(page.GetUri <AboutPage>());
            };
            page.ApplicationBar.Buttons.Insert(0, aboutButton);
        }
Пример #3
0
 private void OnCourseCatalogClickFromAppBar(object sender, EventArgs e)
 {
     ErrorReporting.Log("OnCourseCatalogClickFromAppBar");
     new WebBrowserTask {
         Uri = new Uri("https://www.coursera.org/courses")
     }.Show();
 }
Пример #4
0
 private void OnCreateAccountClick(object sender, RoutedEventArgs e)
 {
     ErrorReporting.Log("OnCreateAccountClick");
     new WebBrowserTask {
         Uri = new Uri("https://accounts.coursera.org/signup")
     }.Show();
 }
Пример #5
0
        private void OnStationClick(object sender, RoutedEventArgs e)
        {
            ErrorReporting.Log("OnStationClick");
            var dataContext = ((Button)sender).DataContext;

            GoToStation(dataContext);
        }
Пример #6
0
        private void OnStreamClick(object sender, RoutedEventArgs e)
        {
            ErrorReporting.Log("OnStreamClick");

            var lecture = (Lecture)((Button)sender).DataContext;

            ErrorReporting.Log("Lecture = " + lecture.Title + " [" + lecture.Id + "]");

            if (videoLazyBlocks.ContainsKey(lecture.Id))
            {
                ErrorReporting.Log("Already fetching video url");
            }
            else
            {
                videoLazyBlocks.Add(lecture.Id, new LazyBlock <string>(
                                        "video location",
                                        null,
                                        lecture.VideoUrl,
                                        _ => false,
                                        new LazyBlockUI <string>(
                                            this,
                                            videoUrl =>
                {
                    ErrorReporting.Log("Launching video from url");
                    VideoPage.LaunchVideoFromUrl(this, videoUrl);
                },
                                            () => false,
                                            null),
                                        false,
                                        null,
                                        _ => videoLazyBlocks.Remove(lecture.Id),
                                        null));
            }
        }
Пример #7
0
        private void OnPlayOrDownloadOrCancelClick(object sender, RoutedEventArgs e)
        {
            ErrorReporting.Log("OnPlayOrDownloadOrCancelClick");

            var lecture = (Lecture)((Button)sender).DataContext;

            ErrorReporting.Log("Lecture = " + lecture.Title + " [" + lecture.Id + "]");

            if (videoLazyBlocks.ContainsKey(lecture.Id))
            {
                ErrorReporting.Log("Already fetching video url");
            }
            else if (lecture.DownloadInfo.Downloading)
            {
                ErrorReporting.Log("Cancelling download");
                ((DownloadInfo)lecture.DownloadInfo).Monitor.RequestCancel();
            }
            else if (lecture.DownloadInfo.Downloaded)
            {
                ErrorReporting.Log("Launching downloaded video");
                VideoPage.LaunchDownloadedVideo(this, lecture.DownloadInfo);
            }
            else
            {
                StartDownload(lecture);
            }
        }
Пример #8
0
        private void OnCourseClick(object sender, RoutedEventArgs e)
        {
            ErrorReporting.Log("OnCourseClick");
            var course = (Course)((Button)sender).DataContext;

            NavigationService.Navigate(new Uri("/CoursePage.xaml?courseId=" + course.Id, UriKind.Relative));
        }
Пример #9
0
 private void OnSaveClick(object sender, EventArgs e)
 {
     ErrorReporting.Log("OnSaveClick");
     Settings.Set(Setting.LocationServicesEnabled, enableLocationServices.IsChecked == true);
     Settings.Set(Setting.AutoRefresh, autoRefresh.IsChecked == true);
     LocationService.Setup();
     NavigationService.GoBack();
 }
Пример #10
0
 private void OnRefreshClick(object sender, EventArgs e)
 {
     ErrorReporting.Log("OnRefreshClick");
     if (journeyElementsLazyBlock != null)
     {
         journeyElementsLazyBlock.Refresh();
     }
 }
Пример #11
0
        private void OnRecentItemRemoveClick(object sender, RoutedEventArgs e)
        {
            ErrorReporting.Log("OnRecentItemRemoveClick");
            var dataContext = (DeparturesAndArrivalsTable)((MenuItem)sender).DataContext;

            RecentItems.Remove(dataContext);
            RefreshRecentItemsList();
        }
Пример #12
0
        private void OnLiveProgressFromArrivalsClick(object sender, EventArgs e)
        {
            ErrorReporting.Log("OnLiveProgressFromArrivalsClick");
            var arrival = (Arrival)((Button)sender).DataContext;
            var title   = departuresAndArrivalsTable.Match(_ => arrival.Origin, (_, origin) => origin.Name) + " to " + departuresAndArrivalsTable.Station.Name;

            LiveProgressPage.SetDetails(title, arrival.Details);
            NavigationService.Navigate(this.GetUri <LiveProgressPage>());
        }
Пример #13
0
        private void OnLiveProgressFromDeparturesClick(object sender, EventArgs e)
        {
            ErrorReporting.Log("OnLiveProgressFromDeparturesClick");
            var departure = (Departure)((Button)sender).DataContext;
            var title     = departuresAndArrivalsTable.Station.Name + " to " + departuresAndArrivalsTable.Match(_ => departure.Destination, (_, destination) => destination.Name);

            LiveProgressPage.SetDetails(title, departure.Details);
            NavigationService.Navigate(this.GetUri <LiveProgressPage>());
        }
Пример #14
0
        private void OnOpenInBrowserClick(object sender, EventArgs e)
        {
            ErrorReporting.Log("OnOpenInBrowserClick");

            var course = App.Crawler.GetCourse(courseId);

            new WebBrowserTask {
                Uri = new Uri(course.HomeLink)
            }.Show();
        }
Пример #15
0
        private void OnDeleteClick(object sender, RoutedEventArgs e)
        {
            ErrorReporting.Log("OnDeleteClick");

            var lecture = (Lecture)((MenuItem)sender).DataContext;

            ErrorReporting.Log("Lecture = " + lecture.Title + " [" + lecture.Id + "]");

            lecture.DownloadInfo.DeleteVideo();
        }
Пример #16
0
        private void OnPlayClick(object sender, RoutedEventArgs e)
        {
            ErrorReporting.Log("OnPlayClick");

            var downloadInfo = (DownloadInfo)((Button)sender).DataContext;

            ErrorReporting.Log("Course = " + downloadInfo.CourseTopicName + " [" + downloadInfo.CourseId + "] Lecture = " + downloadInfo.LectureTitle + " [" + downloadInfo.LectureId + "]");

            VideoPage.LaunchDownloadedVideo(this, downloadInfo);
        }
Пример #17
0
 private void OnDeleteAllClick(object sender, EventArgs e)
 {
     ErrorReporting.Log("OnDeleteAllClick");
     foreach (var downloadInfo in completed)
     {
         downloadInfo.DeleteVideo();
     }
     completed.Clear();
     RefreshEmptyMessagesVisibility();
 }
Пример #18
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            courseId = int.Parse(NavigationContext.QueryString["courseId"]);

            // settings changed
            if (lastEmail != null && lastEmail != Settings.GetString(Setting.Email))
            {
                ErrorReporting.Log("Settings changed");
                pivot.ItemsSource = null;
            }

            lastEmail = Settings.GetString(Setting.Email);

            // app was tombstoned or settings changed
            if (App.Crawler == null)
            {
                ErrorReporting.Log("App.Crawler is null");

                var email    = Settings.GetString(Setting.Email);
                var password = Settings.GetString(Setting.Password);
                if ((string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)))
                {
                    SafeGoBack();
                    return;
                }

                App.Crawler = new Crawler(email, password, Cache.GetFiles(), Cache.SaveFile, DownloadInfo.Create);
                new LazyBlock <Course[]>(
                    "courses",
                    "No courses",
                    App.Crawler.Courses,
                    a => a.Length == 0,
                    new LazyBlockUI <Course[]>(
                        this,
                        _ => Setup(),
                        () => false,
                        messageTextBlock),
                    false,
                    null,
                    success =>
                {
                    if (!success)
                    {
                        ErrorReporting.Log("Failed to get courses");
                        App.Crawler = null;
                        SafeGoBack();
                    }
                },
                    null);
            }
            else
            {
                Setup();
            }
        }
Пример #19
0
        private void OnPinToStartClick(object sender, EventArgs e)
        {
            ErrorReporting.Log("OnPinToStartClick");
            var uri = GetUri(departuresAndArrivalsTable);

            if (!IsStationPinnedToStart())
            {
                ShellTile.Create(GetUri(departuresAndArrivalsTable), GetTileData(), supportsWideTile: true);
            }
            GetPinToStartButton().IsEnabled = false;
        }
Пример #20
0
 private void SafeGoBack()
 {
     if (NavigationService.CanGoBack)
     {
         NavigationService.GoBack();
     }
     else
     {
         ErrorReporting.Log("Can not go back");
     }
 }
Пример #21
0
 private void OnRefreshClick(object sender, EventArgs e)
 {
     ErrorReporting.Log("OnRefreshClick");
     if (pivot.SelectedIndex != 1 && departuresLazyBlock != null)
     {
         departuresLazyBlock.Refresh();
     }
     if (pivot.SelectedIndex != 0 && arrivalsLazyBlock != null)
     {
         arrivalsLazyBlock.Refresh();
     }
 }
Пример #22
0
 private void OnFilterOrClearFilterClick(object sender, EventArgs e)
 {
     ErrorReporting.Log("OnFilterOrClearFilterClick");
     if (departuresAndArrivalsTable.HasDestinationFilter)
     {
         NavigationService.Navigate(GetUri(departuresAndArrivalsTable.WithoutFilter));
     }
     else
     {
         NavigationService.Navigate(MainAndFilterPage.GetUri(this, departuresAndArrivalsTable.Station));
     }
 }
Пример #23
0
        private void OnLectureNotesClick(object sender, RoutedEventArgs e)
        {
            ErrorReporting.Log("OnLectureNotesClick");

            var lecture = (Lecture)((Button)sender).DataContext;

            ErrorReporting.Log("Lecture = " + lecture.Title + " [" + lecture.Id + "]");

            new WebBrowserTask {
                Uri = new Uri(lecture.LectureNotesUrl)
            }.Show();
        }
Пример #24
0
 private void OnCancelAllClick(object sender, EventArgs e)
 {
     ErrorReporting.Log("OnCancelAllClick");
     foreach (var downloadInfo in inProgress)
     {
         // might be null if it was just completed, but hasn't been removed from the list yet
         if (downloadInfo.Monitor != null)
         {
             downloadInfo.Monitor.RequestCancel();
         }
     }
     inProgress.Clear();
     RefreshEmptyMessagesVisibility();
 }
Пример #25
0
        private void Load(bool refresh)
        {
            if (lecturesLazyBlock != null)
            {
                lecturesLazyBlock.Cancel();
                lecturesLazyBlock = null;
            }
            var course = App.Crawler.GetCourse(courseId);

            if (!course.Active)
            {
                if (course.HasFinished)
                {
                    messageTextBlock.Text = "Lectures no longer available";
                }
                else
                {
                    messageTextBlock.Text = "Lectures not available yet";
                }
            }
            else
            {
                if (refresh)
                {
                    course = App.Crawler.RefreshCourse(course.Id);
                }
                lecturesLazyBlock = new LazyBlock <LectureSection[]>(
                    "lectures",
                    "No lectures available. Make sure you have accepted the honor code.",
                    course.LectureSections,
                    a => a.Length == 0,
                    new LazyBlockUI <LectureSection[]>(
                        this,
                        lectureSections => pivot.ItemsSource = lectureSections,
                        () => pivot.ItemsSource != null,
                        messageTextBlock),
                    false,
                    null,
                    success =>
                {
                    if (!success)
                    {
                        ErrorReporting.Log("Failed to get lectures");
                    }
                },
                    null);
            }
        }
Пример #26
0
        private void OnRefreshClick(object sender, EventArgs e)
        {
            ErrorReporting.Log("OnRefreshClick");

            var email    = Settings.GetString(Setting.Email);
            var password = Settings.GetString(Setting.Password);

            if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
            {
                this.NavigateToSettings();
            }
            else
            {
                LoadCourses(email, password, true);
            }
        }
Пример #27
0
 private void OnSaveClick(object sender, EventArgs e)
 {
     ErrorReporting.Log("OnSaveClick");
     if (email.Text != Settings.GetString(Setting.Email))
     {
         Cache.DeleteAllFiles();
         App.Crawler = null;
     }
     else if (password.Password != Settings.GetString(Setting.Password))
     {
         App.Crawler = null;
     }
     Settings.Set(Setting.Email, email.Text);
     Settings.Set(Setting.Password, password.Password);
     Settings.Set(Setting.RunUnderLockScreen, runUnderLockScreen.IsChecked == true);
     EnableOrDisableLockScreen();
     NavigationService.GoBack();
 }
Пример #28
0
 private void OnDownloadAllClick(object sender, EventArgs e)
 {
     ErrorReporting.Log("OnDownloadAllClick");
     if (pivot.SelectedIndex != -1 && pivot.ItemsSource != null)
     {
         var lectureSections = (LectureSection[])pivot.ItemsSource;
         if (pivot.SelectedIndex < lectureSections.Length)
         {
             foreach (var lecture in lectureSections[pivot.SelectedIndex].Lectures)
             {
                 if (!videoLazyBlocks.ContainsKey(lecture.Id) && !lecture.DownloadInfo.Downloading && !lecture.DownloadInfo.Downloaded)
                 {
                     StartDownload(lecture);
                 }
             }
         }
     }
 }
Пример #29
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (journeyElementsLazyAsync == null)
            {
                ErrorReporting.Log("journeyElementsLazyAsync is null");
                if (NavigationService.CanGoBack)
                {
                    NavigationService.GoBack();
                }
                else
                {
                    ErrorReporting.Log("Can not go back");
                }
                return;
            }

            if (journeyElementsLazyBlock != null)
            {
                if (journeyElements.ItemsSource == null)
                {
                    journeyElementsLazyBlock.Refresh();
                }
            }
            else
            {
                title.Text = trainTitle;
                if (title.Text.Length > 40)
                {
                    title.Text = title.Text.Replace(" to ", "\nto ");
                }
                journeyElementsLazyBlock = new LazyBlock <JourneyElement[]>(
                    "live progress",
                    "No information available",
                    journeyElementsLazyAsync,
                    items => items.Length == 0,
                    new LazyBlockUI <JourneyElement>(this, journeyElements, journeyElementsMessageTextBlock, journeyElementsLastUpdatedTextBlock),
                    Settings.GetBool(Setting.AutoRefresh),
                    null,
                    null,
                    null);
            }
        }
Пример #30
0
        private void OnSendTextMessage(object sender, RoutedEventArgs e)
        {
            ErrorReporting.Log("OnSendTextMessage");
            var departure = (Departure)((MenuItem)sender).DataContext;
            var body      =
                "I'm taking the "
                + departure.Due
                + " train from "
                + departuresAndArrivalsTable.Station.Name
                + " to "
                + departuresAndArrivalsTable.Match(_ => departure.Destination, (_, destination) => destination.Name);

            if (departure.ArrivalIsKnown)
            {
                body += ". I'll be there at " + departure.Arrival.Value.Value.Expected.Value;
            }
            new SmsComposeTask {
                Body = body
            }.Show();
        }