Exemple #1
0
        /// <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();

            // 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)
                    {
                        m_host.ShowError();
                        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);
                });
            });
        }
Exemple #2
0
        /// <summary>
        /// Called by the host when we should show content.
        /// </summary>
        /// <param name="post"></param>
        public async void OnPrepareContent(Post post)
        {
            // So the loading UI
            m_host.ShowLoading();
            m_loadingHidden = false;

            // 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, () =>
            {
                lock (this)
                {
                    if (m_isDestroyed)
                    {
                        return;
                    }

                    // Make the webview
                    m_webView = new WebView(WebViewExecutionMode.SeparateThread);

                    // Setup the listeners, we need all of these because some web pages don't trigger
                    // some of them.
                    m_webView.FrameNavigationCompleted += NavigationCompleted;
                    m_webView.NavigationFailed         += NavigationFailed;
                    m_webView.DOMContentLoaded         += DOMContentLoaded;
                    m_webView.ContentLoading           += ContentLoading;

                    // Navigate
                    m_webView.Navigate(new Uri(post.Url, UriKind.Absolute));
                    ui_contentRoot.Children.Add(m_webView);
                }
            });
        }
Exemple #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);
                });
            });
        }
Exemple #4
0
        /// <summary>
        /// Called by the host when we should show content.
        /// </summary>
        /// <param name="post"></param>
        public async void OnPrepareContent(Post post)
        {
            // So the loading UI
            m_host.ShowLoading();
            m_loadingHidden = false;

            // 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, () =>
            {
                lock (this)
                {
                    if (m_isDestroyed)
                    {
                        return;
                    }

                    // Get the post url
                    m_postUrl = post.Url;

                    // Make the webview
                    m_webView = new WebView(WebViewExecutionMode.SeparateThread);

                    // Setup the listeners, we need all of these because some web pages don't trigger
                    // some of them.
                    m_webView.FrameNavigationCompleted         += NavigationCompleted;
                    m_webView.NavigationFailed                 += NavigationFailed;
                    m_webView.DOMContentLoaded                 += DOMContentLoaded;
                    m_webView.ContentLoading                   += ContentLoading;
                    m_webView.ContainsFullScreenElementChanged += WebView_ContainsFullScreenElementChanged;

                    // Navigate
                    try
                    {
                        m_webView.Navigate(new Uri(post.Url, UriKind.Absolute));
                    }
                    catch (Exception e)
                    {
                        App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "FailedToMakeUriInWebControl", e);
                        m_host.ShowError();
                    }

                    // Now add an event for navigating.
                    m_webView.NavigationStarting += NavigationStarting;

                    // Insert this before the full screen button.
                    ui_contentRoot.Children.Insert(0, m_webView);
                }
            });
        }
        /// <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_postUrl = post.Url;

            // 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.ShowError();
                    });

                    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);
            });
        }
 public RedditMarkdownFlipControl(IFlipViewContentHost host)
 {
     m_host = host;
     this.InitializeComponent();
     m_host.ShowLoading();
 }
Exemple #7
0
 public RedditMarkdownFlipControl(IFlipViewContentHost host)
 {
     m_host = host;
     this.InitializeComponent();
     m_host.ShowLoading();
 }