/// <summary> /// Fired when we should load the content. /// </summary> /// <param name="source"></param> public void OnPrepareContent() { // Run our work on a background thread. Task.Run(() => { // Get the image Url string imageUrl = ImageManager.GetImageUrl(m_base.Source.Url); // Make sure we got it. 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 m_base.FireOnFallbackToBrowser(); return; } // Make sure we aren't destroyed. if (m_base.IsDestoryed) { return; } // Fire off a request for the image. ImageManager.ImageManagerRequest request = new ImageManager.ImageManagerRequest() { ImageId = m_base.Source.Id, Url = imageUrl }; request.OnRequestComplete += OnRequestComplete; App.BaconMan.ImageMan.QueueImageRequest(request); }); }
/// <summary> /// Sets the posts to the UI. /// </summary> /// <param name="startingPos"></param> /// <param name="newPosts"></param> private async void SetPosts(int startingPos, List<Post> newPosts, bool isFreshUpdate) { // Dispatch to the UI thread await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { // Setup the insert int insertIndex = startingPos; // Lock the list lock(m_postsLists) { // Set up the objects for the UI foreach (Post post in newPosts) { // Check if we are adding or inserting. bool isReplace = insertIndex < m_postsLists.Count; // If this is a replace and the urls are the same just set the image if (isReplace && post.Url == m_postsLists[insertIndex].Url) { post.Image = m_postsLists[insertIndex].Image; post.ImageVisibility = m_postsLists[insertIndex].ImageVisibility; } else { // Request the image if there is one if (ImageManager.IsThumbnailImage(post.Thumbnail)) { ImageManager.ImageManagerRequest request = new ImageManager.ImageManagerRequest() { Url = post.Thumbnail, ImageId = post.Id }; request.OnRequestComplete += OnRequestComplete; App.BaconMan.ImageMan.QueueImageRequest(request); } } if (isReplace) { if(m_postsLists[insertIndex].Id.Equals(post.Id)) { // If the post is the same, just update the UI vars. // If we replace the entire post the UI freaks out. m_postsLists[insertIndex].Score = post.Score; m_postsLists[insertIndex].TitleTextColor = post.TitleTextColor; m_postsLists[insertIndex].Title = post.Title; m_postsLists[insertIndex].Likes = post.Likes; m_postsLists[insertIndex].SubTextLine1 = post.SubTextLine1; m_postsLists[insertIndex].NewCommentText = post.NewCommentText; m_postsLists[insertIndex].SubTextLine2PartOne = post.SubTextLine2PartOne; m_postsLists[insertIndex].SubTextLine2PartTwo = post.SubTextLine2PartTwo; } else { // Replace the current item m_postsLists[insertIndex] = post; } } else { // Add it to the end m_postsLists.Add(post); } insertIndex++; } // If it was a fresh update, remove anything past the last story sent. while(isFreshUpdate && m_postsLists.Count > newPosts.Count) { m_postsLists.RemoveAt(m_postsLists.Count - 1); } } }); }
/// <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; // 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() { Callback = this, ImageId = post.Id, Url = imageUrl }; App.BaconMan.ImageMan.QueueImageRequest(request); }); }