Example #1
0
        public async void OnRequestComplete(object sender, ImageManager.ImageManagerResponseEventArgs response)
        {
            // Remove the event
            ImageManager.ImageManagerRequest request = (ImageManager.ImageManagerRequest)sender;
            request.OnRequestComplete -= OnRequestComplete;

            // Make sure we were successful.
            if (response.Success)
            {
                // Try to find the post
                Post owningPost = null;

                // Lock the list
                lock(m_postsLists)
                {
                    foreach (Post post in m_postsLists)
                    {
                        if (post.Id.Equals(response.Request.ImageId))
                        {
                            owningPost = post;
                            break;
                        }
                    }
                }

                // If we didn't find it just return
                if (owningPost == null)
                {
                    return;
                }

                // Dispatch to the UI thread
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    // Create a bitmap and set the source
                    owningPost.Image = new BitmapImage();
                    owningPost.Image.SetSource(response.ImageStream);

                    // Set the image visible
                    owningPost.ImageVisibility = Visibility.Visible;
                });
            }
        }
Example #2
0
        public BaconManager(bool isBackgroundTask)
        {
            // Set background task flag
            IsBackgroundTask = isBackgroundTask;

            // Init managers
            UserMan = new UserManager(this);
            CacheMan = new CacheManager(this);
            ImageMan = new ImageManager(this);
            SubredditMan = new SubredditManager(this);
            SettingsMan = new SettingsManager(this);
            NetworkMan = new NetworkManager(this);
            MessageMan = new MessageManager(this);
            UiSettingsMan = new UiSettingManager(this);
            TelemetryMan = new TelemetryManager();
            BackgroundMan = new BackgroundManager(this);
            MotdMan = new MessageOfTheDayManager(this);

            // Don't do this if we are a background task; it will
            // call this when it is ready.
            if (!isBackgroundTask)
            {
                FireOffUpdate();
            }
        }
Example #3
0
        public BaconManager(bool isBackgroundTask)
        {
            // Set background task flag
            IsBackgroundTask = isBackgroundTask;

            // Init managers
            UserMan = new UserManager(this);
            CacheMan = new CacheManager(this);
            ImageMan = new ImageManager(this);
            SubredditMan = new SubredditManager(this);
            SettingsMan = new SettingsManager(this);
            NetworkMan = new NetworkManager(this);
            MessageMan = new MessageManager(this);
            UiSettingsMan = new UiSettingManager(this);
            TelemetryMan = new TelemetryManager();
            BackgroundMan = new BackgroundManager(this);
            MotdMan = new MessageOfTheDayManager(this);
            TileMan = new TileManager(this);
            DraftMan = new DraftManager(this);

            // Don't do this if we are a background task; it will
            // call this when it is ready.
            if (!isBackgroundTask)
            {
                FireOffUpdate();
            }

            // Setup the in between invoke handler for the onBackButton event. This will allow us to stop
            // calling the handlers when one returns true.
            m_onBackButton.SetInBetweenInvokesAction(new Func<EventArgs, bool>(InBetweenInvokeHandlerForOnBackButton));
        }
        /// <summary>
        /// Callback when we get the image.
        /// </summary>
        /// <param name="response"></param>
        public async void OnRequestComplete(object sender, ImageManager.ImageManagerResponseEventArgs response)
        {
            // Remove the event
            ImageManager.ImageManagerRequest request = (ImageManager.ImageManagerRequest)sender;
            request.OnRequestComplete -= OnRequestComplete;

            // Jump back to the UI thread
            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                if (!response.Success)
                {
                    App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "BasicImageControlNoImageUrl");
                    m_base.FireOnFallbackToBrowser();
                    return;
                }

                lock (this)
                {
                    if (m_base.IsDestoryed)
                    {
                        // Get out of here if we should be destroyed.
                        return;
                    }

                    // Grab the source, we need this to make the image
                    m_imageSourceStream = response.ImageStream;

                    // Add the image to the UI
                    m_image = new Image();

                    // We don't want to wait on this.
#pragma warning disable CS4014
                    // Set the image.
                    ReloadImage(false);
#pragma warning restore CS4014

                    // Set the image into the UI.
                    ui_scrollViewer.Content = m_image;

                    // Setup the save image tap
                    m_image.RightTapped += ContentRoot_RightTapped;
                    m_image.Holding += ContentRoot_Holding;
                }
            });
        }
        /// <summary>
        /// Callback when we get the image.
        /// </summary>
        /// <param name="response"></param>
        public async void OnRequestComplete(object sender, ImageManager.ImageManagerResponseEventArgs response)
        {
            // Remove the event
            ImageManager.ImageManagerRequest request = (ImageManager.ImageManagerRequest)sender;
            request.OnRequestComplete -= OnRequestComplete;

            // Jump back to the UI thread
            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                if (!response.Success)
                {
                    App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "BasicImageControlNoImageUrl");
                    m_base.FireOnFallbackToBrowser();
                    return;
                }

                lock (this)
                {
                    if (m_base.IsDestoryed)
                    {
                        // Get out of here if we should be destroyed.
                        return;
                    }

                    // Set the current size of the control, this will also be set
                    // by the size changed listener but we want to make sure it is correct.
                    m_currentControlSize.Height = ui_contentRoot.ActualHeight;
                    m_currentControlSize.Width = ui_contentRoot.ActualWidth;

                    // Grab the source, we need this to make the image
                    m_imageSourceStream = response.ImageStream;

                    // Add the image to the UI
                    m_image = new Image();

                    // Add a loaded listener so we can size the image when loaded
                    m_image.Loaded += Image_Loaded;

                    // Set the image.
                    ReloadImage(false);

                    // Set the image into the UI.
                    ui_scrollViewer.Content = m_image;

                    // Setup the save image tap
                    m_image.RightTapped += ContentRoot_RightTapped;
                    m_image.Holding += ContentRoot_Holding;

                    m_base.FireOnLoading(false);
                }
            });
        }
        /// <summary>
        /// Callback when we get the image.
        /// </summary>
        /// <param name="response"></param>
        public async void OnRequestComplete(ImageManager.ImageManagerResponse response)
        {
            // Jump back to the UI thread
            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                if (!response.Success)
                {
                    App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "BasicImageControlNoImageUrl");
                    m_host.ShowError();
                    return;
                }

                lock (m_host)
                {
                    if(m_isDestoryed)
                    {
                        // Get out of here if we should be destroyed.
                        return;
                    }

                    // Create a bitmap and set the source
                    BitmapImage bitImage = new BitmapImage();
                    bitImage.SetSource(response.ImageStream);

                    // Add the image to the UI
                    m_image = new Image();
                    m_image.Source = bitImage;
                    ui_contentRoot.Children.Add(m_image);

                    // Hide the loading screen
                    m_host.HideLoading();

                    // Show the image
                    ui_storyContentRoot.Begin();
                }
            });
        }
        /// <summary>
        /// Callback when we get the image.
        /// </summary>
        /// <param name="response"></param>
        public async void OnRequestComplete(object sender, ImageManager.ImageManagerResponseEventArgs response)
        {
            // Remove the event
            ImageManager.ImageManagerRequest request = (ImageManager.ImageManagerRequest)sender;
            request.OnRequestComplete -= OnRequestComplete;

            // Jump back to the UI thread
            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                if (!response.Success)
                {
                    App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "BasicImageControlNoImageUrl");
                    m_host.ShowError();
                    return;
                }

                lock (m_host)
                {
                    if(m_isDestoryed)
                    {
                        // Get out of here if we should be destroyed.
                        return;
                    }

                    // Create a bitmap and set the source
                    // #todo, initially we can use a bitmap here decoded to the size of the control
                    // then when the user zooms in we can swap it for a larger image.
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.SetSource(response.ImageStream);

                    // Add the image to the UI
                    m_image = new Image();

                    // Add a loaded listener so we can size the image when loaded
                    m_image.Loaded += Image_Loaded;

                    // Set the image.
                    m_image.Source = bitmapImage;      

                    // Set the image into the UI.
                    ui_scrollViewer.Content = m_image;

                    // Setup the save image tap
                    m_image.RightTapped += ContentRoot_RightTapped;
                    m_image.Holding += ContentRoot_Holding;

                    // Hide the loading screen
                    m_host.HideLoading();

                    // Show the image
                    ui_storyContentRoot.Begin();
                }
            });
        }