/// <summary>
        /// Called by the host when we should show content.
        /// </summary>
        /// <param name="post"></param>
        public void OnPrepareContent(Post post)
        {
            // So the loading UI
            m_host.ShowLoading();

            m_post = post;

            // Since this can be costly kick it off to a background thread so we don't do work
            // as we are animating.
            Task.Run(async() =>
            {
                // Get the video Uri
                YouTubeUri youTubeUri = await GetYouTubeVideoUrl(post);

                // Back to the UI thread with pri
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    if (youTubeUri == null)
                    {
                        // If we failed fallback to the browser.
                        m_host.FallbackToWebBrowser(m_post);
                        App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "FailedToGetYoutubeVideoAfterSuccess");
                        return;
                    }

                    // Setup the video
                    m_youTubeVideo          = new MediaElement();
                    m_youTubeVideo.AutoPlay = false;
                    m_youTubeVideo.AreTransportControlsEnabled = true;
                    m_youTubeVideo.CurrentStateChanged        += MediaElement_CurrentStateChanged;
                    m_youTubeVideo.Source = youTubeUri.Uri;
                    ui_contentRoot.Children.Add(m_youTubeVideo);
                });
            });
        }
        /// <summary>
        /// Called when we should show content
        /// </summary>
        /// <param name="post"></param>
        public void OnPrepareContent(Post post)
        {
            // Set our flag
            m_isDestoryed = false;

            // First show loading
            m_host.ShowLoading();

            // Hide the content root
            ui_contentRoot.Opacity = 0;

            // Grab the post URL
            m_post = post;

            // Do the rest of the work on a background thread.
            Task.Run(async() =>
            {
                // Get the image Url
                string imageUrl = ImageManager.GetImageUrl(post.Url);

                if (String.IsNullOrWhiteSpace(imageUrl))
                {
                    // This is bad, we should be able to get the url.
                    App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "BasicImageControlNoImageUrl");

                    // Jump back to the UI thread
                    await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        m_host.FallbackToWebBrowser(post);
                    });

                    return;
                }

                // Fire off a request for the image.
                ImageManager.ImageManagerRequest request = new ImageManager.ImageManagerRequest()
                {
                    ImageId = post.Id,
                    Url     = imageUrl
                };
                request.OnRequestComplete += OnRequestComplete;
                App.BaconMan.ImageMan.QueueImageRequest(request);
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Called when the flip view consent should shown.
        /// </summary>
        /// <param name="url"></param>
        public void OnPrepareContent(Post post)
        {
            m_shouldBePlaying = false;
            m_loadingHidden   = false;

            // Show loading
            m_host.ShowLoading();

            // Run the rest on a background thread.
            Task.Run(async() =>
            {
                // Try to get the imgur url
                string gifUrl = GetImgurUrl(post.Url);

                // If that failed try to get a url from GfyCat
                if (gifUrl.Equals(String.Empty))
                {
                    // We have to get it from gyfcat
                    gifUrl = await GetGfyCatGifUrl(GetGfyCatApiUrl(post.Url));
                }

                // Since some of this can be costly, delay the work load until we aren't animating.
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    // Make sure we aren't destroyed.
                    if (m_isDestoryed)
                    {
                        return;
                    }

                    // If we didn't get anything something went wrong.
                    if (String.IsNullOrWhiteSpace(gifUrl))
                    {
                        m_host.FallbackToWebBrowser(post);
                        App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "FailedToShowGifAfterConfirm");
                        return;
                    }

                    // Create the media element
                    m_gifVideo = new MediaElement();
                    m_gifVideo.HorizontalAlignment = HorizontalAlignment.Stretch;
                    m_gifVideo.Tapped += OnVideoTapped;
                    m_gifVideo.CurrentStateChanged += OnVideoCurrentStateChanged;
                    m_gifVideo.Source = new Uri(gifUrl, UriKind.Absolute);
                    m_gifVideo.Play();
                    m_gifVideo.IsLooping = true;
                    ui_contentRoot.Children.Add(m_gifVideo);
                });
            });
        }