示例#1
0
        /// <summary>
        /// Invoked, when the favorites -page is navigated to and updates
        /// the favorites list if invoked with drag'n'drop URL from the
        /// web-browser.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            string parameter = e.Parameter as string;

            if (!String.IsNullOrEmpty(parameter))
            {
                YtWebInterface webIf = new YtWebInterface();
                webIf.UpdateInfo(parameter);
            }
        }
        /// <summary>
        /// Updates individual channel.
        /// </summary>
        private async void btnUpdateVideo_Click(object sender, RoutedEventArgs e)
        {
            var tag = ((Button)sender).Tag;

            ObservableCollection <YtLocalFavChannelList> YtFavoritesList = ((App)Application.Current).GetFavoritesList();

            YtLocalFavChannelList videoInfo = new YtLocalFavChannelList();
            YtWebInterface        webIf     = new YtWebInterface();

            videoInfo = await webIf.GetYtChannelVideoList(tag.ToString());

            YtLocalFavChannelList channelItem = YtFavoritesList.Where(i => i.channelId.Equals(tag.ToString())).Single();
            int videoIndex = YtFavoritesList.IndexOf(channelItem);

            if (YtFavoritesList[videoIndex].videoId != videoInfo.videoId)
            {
                YtFavoritesList[videoIndex].imagePath   = videoInfo.imagePath;
                YtFavoritesList[videoIndex].publishedAt = videoInfo.publishedAt;
                YtFavoritesList[videoIndex].videoId     = videoInfo.videoId;
                YtFavoritesList[videoIndex].videoTitle  = videoInfo.videoTitle;
                ((App)Application.Current).SetFavoritesList(YtFavoritesList);
                ImgNewIcon.Visibility = Visibility.Visible;
            }
        }
        /// <summary>
        /// Refreshes all channels in the favorites list.
        /// </summary>
        private async void RefeshAllChannels()
        {
            try
            {
                YtWebInterface webIf = new YtWebInterface();
                ObservableCollection <YtLocalFavChannelList> YtFavoritesList;
                YtFavoritesList = ((App)Application.Current).GetFavoritesList();

                bool updated = false;

                // Null check.
                if (YtFavoritesList == null)
                {
                    throw new Exception("Cannot update empty favorites list, please add channels first.");
                }

                // Start progress ring animation.
                ProgressRing.Visibility = Visibility.Visible;
                ProgressRing.IsActive   = true;

                // Update favorites list items and check that the video id is really changed.
                for (int i = 0; i < YtFavoritesList.Count; i++)
                {
                    YtLocalFavChannelList videoInfo = new YtLocalFavChannelList();
                    videoInfo = await webIf.GetYtChannelVideoList(YtFavoritesList[i].channelId);

                    if (YtFavoritesList[i].videoId != videoInfo.videoId)
                    {
                        updated = true;
                        YtFavoritesList[i].imagePath   = videoInfo.imagePath;
                        YtFavoritesList[i].publishedAt = videoInfo.publishedAt;
                        YtFavoritesList[i].videoId     = videoInfo.videoId;
                        YtFavoritesList[i].videoTitle  = videoInfo.videoTitle;
                        YtFavoritesList[i].isNew       = true;
                    }
                }

                // Update the list if there has been updates in the list.
                if (updated)
                {
                    ((App)Application.Current).SetFavoritesList(YtFavoritesList);
                    ProgressRing.Visibility = Visibility.Collapsed;
                    ProgressRing.IsActive   = false;
                    ContentFrame.Navigate(typeof(FavoritesPage));
                }
                else
                {
                    ProgressRing.Visibility = Visibility.Collapsed;
                    ProgressRing.IsActive   = false;

                    if (isVideoListUpdatedOnStartup == false)
                    {
                        ContentFrame.Visibility = Visibility.Visible;
                        ContentFrame.Navigate(typeof(FavoritesPage));
                    }
                }

                // Disable auto-update after the startup.
                isVideoListUpdatedOnStartup = true;
            }
            catch (Exception exp)
            {
                ((App)Application.Current).ShowErrorMessage(exp.Message);
            }
            finally
            {
                isVideoListUpdatedOnStartup = true;
            }
        }