From f26226c8804453ce9d84f88a085bc3cfc240d46c Mon Sep 17 00:00:00 2001 From: Quinn Damerell Date: Tue, 19 Jan 2016 20:34:32 -0800 Subject: [PATCH] Final fixes for this release. Fixing up the image control. Adding the subpost header, more. --- .gitignore | 1 + BaconBackend/DataObjects/Post.cs | 29 +-- .../Panels/BasicImageContentPanel.xaml.cs | 40 ++-- Baconit/HelperControls/CommentBox.xaml.cs | 12 +- Baconit/MainPage.xaml.cs | 5 +- Baconit/Panels/FlipView/FlipViewPanel.xaml.cs | 24 ++- .../FlipView/FlipViewPostCommentManager.cs | 111 ++++++---- .../Panels/FlipView/FlipViewPostContext.cs | 7 +- Baconit/Panels/FlipView/FlipViewPostItem.cs | 4 +- .../Panels/FlipView/FlipViewPostPanel.xaml | 7 +- .../Panels/FlipView/FlipViewPostPanel.xaml.cs | 197 ++++++++++-------- Baconit/Panels/Search.xaml | 5 +- UniversalMarkdown | 2 +- 13 files changed, 250 insertions(+), 194 deletions(-) diff --git a/.gitignore b/.gitignore index 25012d2..1038c34 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ *.sln.docstates *.orig *.appx +*.opendb # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs diff --git a/BaconBackend/DataObjects/Post.cs b/BaconBackend/DataObjects/Post.cs index 80902bc..05d5416 100644 --- a/BaconBackend/DataObjects/Post.cs +++ b/BaconBackend/DataObjects/Post.cs @@ -154,12 +154,12 @@ public bool? Likes return m_likes; } set - { + { if (this.SetProperty(ref this.m_likes, value)) { this.OnPropertyChanged(nameof(DownVoteColor)); this.OnPropertyChanged(nameof(UpVoteColor)); - } + } } } [JsonIgnore] @@ -380,7 +380,7 @@ public Color TitleTextColor set { m_titleTextColor = value; - OnPropertyChanged(nameof(TitleTextBrush)); + OnPropertyChanged(nameof(TitleTextBrush)); } } [JsonIgnore] @@ -696,29 +696,6 @@ public string CommentingOnId [JsonIgnore] string m_commentingOnId = ""; - /// - /// Used by flip view to cache the size of the header - /// - [JsonIgnore] - public double FlipViewHeaderHeight = 0; - - /// - /// Flip view post header visibility - /// - [JsonIgnore] - public Visibility FlipviewHeaderVisibility - { - get - { - return m_flipviewHeaderVisibility; - } - set - { - SetProperty(ref m_flipviewHeaderVisibility, value); - } - } - [JsonIgnore] - Visibility m_flipviewHeaderVisibility = Visibility.Visible; /// /// Indicates how many comments we are showing diff --git a/Baconit/ContentPanels/Panels/BasicImageContentPanel.xaml.cs b/Baconit/ContentPanels/Panels/BasicImageContentPanel.xaml.cs index 2d1badc..984cc6d 100644 --- a/Baconit/ContentPanels/Panels/BasicImageContentPanel.xaml.cs +++ b/Baconit/ContentPanels/Panels/BasicImageContentPanel.xaml.cs @@ -1,6 +1,7 @@ using BaconBackend.Managers; using Baconit.Interfaces; using System; +using System.Diagnostics; using System.Threading.Tasks; using Windows.Foundation; using Windows.Graphics.Display; @@ -45,7 +46,7 @@ enum ImageState /// The calculated min zoom factor for this image. /// float m_minZoomFactor = 1.0f; - + /// /// Holds the current size of the control. /// @@ -207,7 +208,7 @@ public void OnDestroyContent() bmpImage.ImageOpened -= BitmapImage_ImageOpened; bmpImage.ImageFailed -= BitmapImage_ImageFailed; } - } + } // Kill the image m_image.Source = null; @@ -340,8 +341,6 @@ public bool ReloadImage(bool useFullsize) m_lastImageSetSize.Height = m_currentControlSize.Height; } - - // Create a bitmap and BitmapImage bitmapImage = new BitmapImage(); bitmapImage.CreateOptions = BitmapCreateOptions.None; @@ -392,8 +391,6 @@ public bool ReloadImage(bool useFullsize) } } - - // Set the image. m_image.Source = bitmapImage; return true; @@ -427,7 +424,7 @@ private async void BitmapImage_ImageOpened(object sender, RoutedEventArgs e) catch(Exception) { return; - } + } // wait a little bit before we set the new state so things can settle. await Task.Delay(50); @@ -630,7 +627,7 @@ private async void ContentRoot_SizeChanged(object sender, SizeChangedEventArgs e // if we didn't resize the image just set the new zoom. if (!didImageResize) - { + { m_state = ImageState.NormalSizeUpdating; await SetScrollerZoomFactors(); @@ -650,20 +647,35 @@ private async Task SetScrollerZoomFactors() { return; } - + // Get the image and the size. BitmapImage bitmapImage = (BitmapImage)m_image.Source; Size imageSize = new Size(bitmapImage.PixelWidth, bitmapImage.PixelHeight); - // If we are using logical pixels and have a decode width or height we want to + // No matter what they pixel type, the scroller always seems to look at decoded pixel values + // and not the real sizes. So we need to make this size match the decoded size. + if (bitmapImage.DecodePixelWidth != 0) + { + double ratio = ((double)bitmapImage.PixelWidth) / ((double)bitmapImage.DecodePixelWidth); + imageSize.Width /= ratio; + imageSize.Height /= ratio; + } + else if (bitmapImage.DecodePixelHeight != 0) + { + double ratio = ((double)bitmapImage.PixelHeight) / ((double)bitmapImage.DecodePixelHeight); + + imageSize.Width /= ratio; + imageSize.Height /= ratio; + } + + // If we are using logical pixels and have a decode width or height we want to // scale the actual height and width down. We must do this because the scroller // expects logical pixels. - if (bitmapImage.DecodePixelType == DecodePixelType.Logical && (bitmapImage.DecodePixelHeight != 0 || bitmapImage.DecodePixelWidth != 0)) + if (bitmapImage.DecodePixelType == DecodePixelType.Logical)// && (bitmapImage.DecodePixelHeight != 0 || bitmapImage.DecodePixelWidth != 0)) { - imageSize.Width /= m_deviceScaleFactor; - imageSize.Height /= m_deviceScaleFactor; + } - + await SetScrollerZoomFactors(imageSize); } diff --git a/Baconit/HelperControls/CommentBox.xaml.cs b/Baconit/HelperControls/CommentBox.xaml.cs index 4d0b187..58d9077 100644 --- a/Baconit/HelperControls/CommentBox.xaml.cs +++ b/Baconit/HelperControls/CommentBox.xaml.cs @@ -421,8 +421,18 @@ private void PreviewTimer_Tick(object sender, object e) // Update the markdown text. ui_livePreviewBox.Markdown = ui_textBox.Text; + // For some reason the SelectionStart count /r/n as 1 instead of two. So add one for each /r/n we find. + int selectionStart = ui_textBox.SelectionStart; + for (int count = 0; count < selectionStart; count++) + { + if (ui_textBox.Text[count] == '\r' && count + 1 < ui_textBox.Text.Length && ui_textBox.Text[count + 1] == '\n') + { + selectionStart++; + } + } + // If the entry point is at the bottom of the text box, scroll the preview - if (Math.Abs(ui_textBox.SelectionStart - ui_textBox.Text.Length) < 30) + if (Math.Abs(selectionStart - ui_textBox.Text.Length) < 30) { ui_livePreviewScroller.ChangeView(null, ui_livePreviewScroller.ScrollableHeight, null); } diff --git a/Baconit/MainPage.xaml.cs b/Baconit/MainPage.xaml.cs index 1116820..81d417b 100644 --- a/Baconit/MainPage.xaml.cs +++ b/Baconit/MainPage.xaml.cs @@ -316,7 +316,10 @@ private void UpdateSubredditList(List newSubreddits) if (m_subreddits.Count > insertCount && m_subreddits[insertCount].Id.Equals(newSubreddit.Id)) { // If they are the same just update it - m_subreddits[insertCount] = newSubreddit; + m_subreddits[insertCount].DisplayName = newSubreddit.DisplayName; + m_subreddits[insertCount].FavIconUri = newSubreddit.FavIconUri; + m_subreddits[insertCount].IsFavorite = newSubreddit.IsFavorite; + m_subreddits[insertCount].Title = newSubreddit.Title; } // (subreddit insert) If the next element in the new list is the same as the current element in the old list, insert. else if (m_subreddits.Count > insertCount && newSubreddits.Count > newListCount + 1 && newSubreddits[newListCount + 1].Id.Equals(m_subreddits[insertCount].Id)) diff --git a/Baconit/Panels/FlipView/FlipViewPanel.xaml.cs b/Baconit/Panels/FlipView/FlipViewPanel.xaml.cs index f792e14..cfd5838 100644 --- a/Baconit/Panels/FlipView/FlipViewPanel.xaml.cs +++ b/Baconit/Panels/FlipView/FlipViewPanel.xaml.cs @@ -81,7 +81,7 @@ public sealed partial class FlipViewPanel : UserControl, IPanel /// Indicates that there is a target comment we are trying to get to. /// string m_targetComment = ""; - + /// /// Holds a reference to the loading overlay if there is one. /// @@ -439,7 +439,7 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch // Try catch is a work around for bug https://github.com/QuinnDamerell/Baconit/issues/53 try { - m_postsLists.Add(new FlipViewPostItem(m_host, m_collector, post)); + m_postsLists.Add(new FlipViewPostItem(m_host, m_collector, post, m_targetComment)); } catch (Exception e) { @@ -458,7 +458,7 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch // Try catch is a work around for bug https://github.com/QuinnDamerell/Baconit/issues/53 try { - m_postsLists.Add(new FlipViewPostItem(m_host, m_collector, post)); + m_postsLists.Add(new FlipViewPostItem(m_host, m_collector, post, m_targetComment)); } catch(Exception e) { @@ -540,7 +540,7 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch else { // If not add it to the end. - m_postsLists.Add(new FlipViewPostItem(m_host, m_collector, post)); + m_postsLists.Add(new FlipViewPostItem(m_host, m_collector, post, m_targetComment)); } } } @@ -550,7 +550,7 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch // as possible. foreach (Post post in insertList.Reverse()) { - m_postsLists.Insert(0, new FlipViewPostItem(m_host, m_collector, post)); + m_postsLists.Insert(0, new FlipViewPostItem(m_host, m_collector, post, m_targetComment)); } // Clear the deferrals @@ -563,7 +563,7 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch UpdatePanelContent(); }); }); - } + } #region Flippping Logic @@ -716,8 +716,8 @@ await Task.Run(() => }); } - #endregion - + #endregion + #region Full Screen Loading /// @@ -853,7 +853,7 @@ private void CommentBox_OnCommentSubmitted(object sender, OnCommentSubmittedArgs { ui_commentBox.HideLoadingOverlay(); } - } + } } /// @@ -867,7 +867,9 @@ private void SetCommentBoxHeight(double height) // it isn't bound by the grid. if (ui_commentBox != null) { - ui_commentBox.MaxHeight = height; + // -1 is needed to work around a layout cycle bug + // https://github.com/QuinnDamerell/Baconit/issues/54 + ui_commentBox.MaxHeight = height - 1; } } @@ -878,7 +880,7 @@ private void SetCommentBoxHeight(double height) /// private void ContentRoot_SizeChanged(object sender, SizeChangedEventArgs e) { - SetCommentBoxHeight(e.NewSize.Height - 1); + SetCommentBoxHeight(e.NewSize.Height); } #endregion diff --git a/Baconit/Panels/FlipView/FlipViewPostCommentManager.cs b/Baconit/Panels/FlipView/FlipViewPostCommentManager.cs index ba6ae5a..0eb3ebd 100644 --- a/Baconit/Panels/FlipView/FlipViewPostCommentManager.cs +++ b/Baconit/Panels/FlipView/FlipViewPostCommentManager.cs @@ -17,8 +17,16 @@ namespace Baconit.Panels { public class FlipViewPostCommentManager { + /// + /// The comment collector for this + /// DeferredCollector m_commentCollector; + /// + /// A lock object for the comment collector. + /// + object m_commentCollectorLock = new object(); + /// /// The current post for the comment manager /// @@ -102,16 +110,16 @@ public bool PreFetchComments() Task.Run(() => { // Ensure we have a collector - EnsureCollector(); + DeferredCollector collector = EnsureCollector(); // We have to ask for all the comments here bc we can't extend. - if (!m_commentCollector.PreLoadItems(false, m_post.CurrentCommentShowingCount)) + if (!collector.PreLoadItems(false, m_post.CurrentCommentShowingCount)) { // If update returns false it isn't going to update because it has a cache. So just show the // cache. OnCollectionUpdatedArgs args = new OnCollectionUpdatedArgs() { - ChangedItems = m_commentCollector.GetCurrentItems(false), + ChangedItems = collector.GetCurrentItems(false), IsFreshUpdate = true, IsInsert = false, StartingPosition = 0 @@ -134,29 +142,20 @@ public void ChangeCommentSort() // Do this in a background thread Task.Run(() => { - // Kill the current collector - if (m_commentCollector != null) - { - m_commentCollector.OnCollectionUpdated -= CommentCollector_OnCollectionUpdated; - m_commentCollector.OnCollectorStateChange -= CommentCollector_OnCollectorStateChange; - } - m_commentCollector = null; - - // Get a new collector with the new sort - m_commentCollector = new DeferredCollector(CommentCollector.GetCollector(m_post, App.BaconMan)); + // Delete the collector + DeleteCollector(); - // Sub to collection callbacks for the comments. - m_commentCollector.OnCollectionUpdated += CommentCollector_OnCollectionUpdated; - m_commentCollector.OnCollectorStateChange += CommentCollector_OnCollectorStateChange; + // Make a new one. + DeferredCollector collector = EnsureCollector(); // Force our collector to update. - if (!m_commentCollector.LoadAllItems(true, m_post.CurrentCommentShowingCount)) + if (!collector.LoadAllItems(true, m_post.CurrentCommentShowingCount)) { // If update returns false it isn't going to update because it has a cache. So just show the // cache. OnCollectionUpdatedArgs args = new OnCollectionUpdatedArgs() { - ChangedItems = m_commentCollector.GetCurrentItems(true), + ChangedItems = collector.GetCurrentItems(true), IsFreshUpdate = true, IsInsert = false, StartingPosition = 0 @@ -169,16 +168,39 @@ public void ChangeCommentSort() /// /// Ensures a collector exists /// - private void EnsureCollector() + private DeferredCollector EnsureCollector() { - if (m_commentCollector == null) + lock(m_commentCollectorLock) { - // Get the comment collector, if we don't want to show a subset don't give it the target comment - m_commentCollector = new DeferredCollector(CommentCollector.GetCollector(m_post, App.BaconMan, m_showThreadSubset ? m_targetComment : null)); + if (m_commentCollector == null) + { + // Get the comment collector, if we don't want to show a subset don't give it the target comment + m_commentCollector = new DeferredCollector(CommentCollector.GetCollector(m_post, App.BaconMan, m_showThreadSubset ? m_targetComment : null)); + + // Sub to collection callbacks for the comments. + m_commentCollector.OnCollectionUpdated += CommentCollector_OnCollectionUpdated; + m_commentCollector.OnCollectorStateChange += CommentCollector_OnCollectorStateChange; + } + return m_commentCollector; + } + } + + + /// + /// Deletes the current collector + /// + private void DeleteCollector() + { + lock (m_commentCollectorLock) + { + // Kill the current collector + if (m_commentCollector != null) + { + m_commentCollector.OnCollectionUpdated -= CommentCollector_OnCollectionUpdated; + m_commentCollector.OnCollectorStateChange -= CommentCollector_OnCollectorStateChange; + } + m_commentCollector = null; - // Sub to collection callbacks for the comments. - m_commentCollector.OnCollectionUpdated += CommentCollector_OnCollectionUpdated; - m_commentCollector.OnCollectorStateChange += CommentCollector_OnCollectorStateChange; } } @@ -215,9 +237,10 @@ public void Refresh() Task.Run(() => { // If we have a collector kick off an update. - if (m_commentCollector != null) + DeferredCollector collector = EnsureCollector(); + if (collector != null) { - m_commentCollector.LoadAllItems(true, m_post.CurrentCommentShowingCount); + collector.LoadAllItems(true, m_post.CurrentCommentShowingCount); } }); } @@ -228,7 +251,8 @@ public void Refresh() /// public bool IsOnlyShowingSubset() { - return m_commentCollector.GetState() == DeferredLoadState.Subset; + DeferredCollector collector = EnsureCollector(); + return collector != null ? collector.GetState() == DeferredLoadState.Subset : true; } /// @@ -237,10 +261,10 @@ public bool IsOnlyShowingSubset() public async void RequestMorePosts() { // Ensure we have a collector. - EnsureCollector(); + DeferredCollector collector = EnsureCollector(); // As the deferred collector to load all items, if we are doing work show loading. - if (m_commentCollector.LoadAllItems()) + if (collector.LoadAllItems()) { // Dispatch to the UI thread await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => @@ -265,12 +289,7 @@ public void PrepareForDeletion() } // Kill the collector - if (m_commentCollector != null) - { - m_commentCollector.OnCollectionUpdated -= CommentCollector_OnCollectionUpdated; - m_commentCollector.OnCollectorStateChange -= CommentCollector_OnCollectorStateChange; - } - m_commentCollector = null; + DeleteCollector(); } private async void CommentCollector_OnCollectorStateChange(object sender, OnCollectorStateChangeArgs e) @@ -331,6 +350,12 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch Comment newComment = e.ChangedItems[i]; Comment currentComment = i >= Comments.Count ? null : Comments[i]; + // Check for highlight + if (!String.IsNullOrWhiteSpace(m_targetComment) && newComment.Id.Equals(m_targetComment)) + { + newComment.IsHighlighted = true; + } + if (currentComment == null) { Comments.Add(newComment); @@ -386,7 +411,7 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch // First update the main list foreach (Comment comment in e.ChangedItems) { - if (m_targetComment != null && comment.Id.Equals(m_targetComment)) + if (!String.IsNullOrWhiteSpace(m_targetComment) && comment.Id.Equals(m_targetComment)) { comment.IsHighlighted = true; } @@ -498,12 +523,14 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch public void UpVote_Tapped(Comment comment) { - ((CommentCollector)m_commentCollector.GetCollector()).ChangeCommentVote(comment, PostVoteAction.UpVote); + DeferredCollector collector = EnsureCollector(); + ((CommentCollector)collector.GetCollector()).ChangeCommentVote(comment, PostVoteAction.UpVote); } public void DownVote_Tapped(Comment comment) { - ((CommentCollector)m_commentCollector.GetCollector()).ChangeCommentVote(comment, PostVoteAction.DownVote); + DeferredCollector collector = EnsureCollector(); + ((CommentCollector)collector.GetCollector()).ChangeCommentVote(comment, PostVoteAction.DownVote); } public void Share_Tapped(Comment comment) @@ -558,7 +585,8 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch /// public bool CommentAddedOrEdited(string parentOrOrgionalId, OnCommentSubmittedArgs args) { - return ((CommentCollector)m_commentCollector.GetCollector()).CommentAddedOrEdited(parentOrOrgionalId, args.Response, args.IsEdit); + DeferredCollector collector = EnsureCollector(); + return ((CommentCollector)collector.GetCollector()).CommentAddedOrEdited(parentOrOrgionalId, args.Response, args.IsEdit); } /// @@ -566,7 +594,8 @@ public bool CommentAddedOrEdited(string parentOrOrgionalId, OnCommentSubmittedAr /// public void CommentDeleteRequest(Comment comment) { - ((CommentCollector)m_commentCollector.GetCollector()).CommentDeleteRequest(comment); + DeferredCollector collector = EnsureCollector(); + ((CommentCollector)collector.GetCollector()).CommentDeleteRequest(comment); } #endregion diff --git a/Baconit/Panels/FlipView/FlipViewPostContext.cs b/Baconit/Panels/FlipView/FlipViewPostContext.cs index 062012b..dfa77ee 100644 --- a/Baconit/Panels/FlipView/FlipViewPostContext.cs +++ b/Baconit/Panels/FlipView/FlipViewPostContext.cs @@ -16,11 +16,12 @@ namespace Baconit.Panels.FlipView /// public class FlipViewPostContext : BindableBase { - public FlipViewPostContext(IPanelHost host, PostCollector collector, Post post) + public FlipViewPostContext(IPanelHost host, PostCollector collector, Post post, string targetComment) { Post = post; Collector = collector; Host = host; + TargetComment = targetComment; } public Post Post { get; set; } @@ -29,6 +30,8 @@ public FlipViewPostContext(IPanelHost host, PostCollector collector, Post post) public IPanelHost Host { get; set; } + public string TargetComment { get; set; } + #region UI Vars @@ -62,7 +65,7 @@ public Visibility PostMenuIconVisibility SetProperty(ref m_postMenuIcon, value); } } - Visibility m_postMenuIcon = Visibility.Collapsed; + Visibility m_postMenuIcon = Visibility.Collapsed; #endregion } diff --git a/Baconit/Panels/FlipView/FlipViewPostItem.cs b/Baconit/Panels/FlipView/FlipViewPostItem.cs index b15dde3..9c072a5 100644 --- a/Baconit/Panels/FlipView/FlipViewPostItem.cs +++ b/Baconit/Panels/FlipView/FlipViewPostItem.cs @@ -15,9 +15,9 @@ namespace Baconit.Panels.FlipView /// class FlipViewPostItem : BindableBase { - public FlipViewPostItem(IPanelHost host, PostCollector collector, Post post) + public FlipViewPostItem(IPanelHost host, PostCollector collector, Post post, string targetComment) { - Context = new FlipViewPostContext(host, collector, post); + Context = new FlipViewPostContext(host, collector, post, targetComment); IsVisible = false; } diff --git a/Baconit/Panels/FlipView/FlipViewPostPanel.xaml b/Baconit/Panels/FlipView/FlipViewPostPanel.xaml index f71269b..c5c07ba 100644 --- a/Baconit/Panels/FlipView/FlipViewPostPanel.xaml +++ b/Baconit/Panels/FlipView/FlipViewPostPanel.xaml @@ -95,9 +95,7 @@ - + @@ -554,9 +552,8 @@ - CommentBoxOpened; public Func CommentBoxSubmitted; } - + public sealed partial class FlipViewPostPanel : UserControl { const int c_hiddenCommentHeaderHeight = 36; @@ -53,11 +53,6 @@ public sealed partial class FlipViewPostPanel : UserControl /// FlipViewPostCommentManager m_commentManager = null; - /// - /// Indicates if we have a header size change that we haven't updated yet. - /// - bool m_hasDeferredHeaderSizeUpdate = false; - /// /// The last known scroll position. /// @@ -75,7 +70,7 @@ public sealed partial class FlipViewPostPanel : UserControl /// /// Indicates if the user has overwritten full screen. - /// + /// bool? m_fullScreenOverwrite = null; /// @@ -250,6 +245,12 @@ private void OnContextChanged(FlipViewPostContext newContext) PreFetchPostComments(); } + // If we have a target comment show the UI now. + if(!String.IsNullOrWhiteSpace(newContext.TargetComment)) + { + newContext.Post.FlipViewShowEntireThreadMessage = Visibility.Visible; + } + // Setup the UI for the new context SetupListViewForNewContext(); SetupHeaderForNewContext(); @@ -322,7 +323,7 @@ private async void OpenBrowser_Tapped(object sender, EventArgs e) await Windows.System.Launcher.LaunchUriAsync(new Uri(url, UriKind.Absolute)); App.BaconMan.TelemetryMan.ReportEvent(this, "OpenInBrowser"); } - } + } } private void More_Tapped(object sender, EventArgs e) @@ -372,7 +373,7 @@ private void CopyLink_Click(object sender, RoutedEventArgs e) } Clipboard.SetContent(data); App.BaconMan.TelemetryMan.ReportEvent(this, "CopyLinkTapped"); - } + } } private void CopyPermalink_Click(object sender, RoutedEventArgs e) @@ -384,7 +385,7 @@ private void CopyPermalink_Click(object sender, RoutedEventArgs e) data.SetText("http://www.reddit.com" + context.Post.Permalink); Clipboard.SetContent(data); App.BaconMan.TelemetryMan.ReportEvent(this, "CopyLinkTapped"); - } + } } private void SaveImage_Click(object sender, RoutedEventArgs e) @@ -394,7 +395,7 @@ private void SaveImage_Click(object sender, RoutedEventArgs e) { App.BaconMan.ImageMan.SaveImageLocally(context.Post.Url); App.BaconMan.TelemetryMan.ReportEvent(this, "CopyLinkTapped"); - } + } } // I threw up a little while I wrote this. @@ -413,7 +414,7 @@ private void SharePost_Click(object sender, RoutedEventArgs e) DataTransferManager.ShowShareUI(); App.BaconMan.TelemetryMan.ReportEvent(this, "SharePostTapped"); } - } + } } private void DataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args) @@ -468,7 +469,7 @@ private async void DeletePost_Click(object sender, RoutedEventArgs e) // Delete it. context.Collector.DeletePost(context.Post); } - } + } } /// @@ -532,7 +533,7 @@ private void GoToUser_Click(object sender, RoutedEventArgs e) args.Add(PanelManager.NAV_ARGS_USER_NAME, context.Post.Author); context.Host.Navigate(typeof(UserProfile), context.Post.Author, args); App.BaconMan.TelemetryMan.ReportEvent(this, "GoToUserFlipView"); - } + } } #endregion @@ -566,7 +567,7 @@ private void PreFetchPostComments(bool forcePreFetch = false, bool showThreadSub // Create a comment manager for the post Post refPost = context.Post; - m_commentManager = new FlipViewPostCommentManager(ref refPost, "", false);//m_targetComment, showThreadSubset); + m_commentManager = new FlipViewPostCommentManager(ref refPost, context.TargetComment, showThreadSubset); // Set the comment list to the list view ui_listView.ItemsSource = m_commentManager.Comments; @@ -588,7 +589,7 @@ private void ClearCommentManger() { m_commentManager.PrepareForDeletion(); m_commentManager = null; - } + } } /// @@ -608,9 +609,6 @@ private FlipViewPostCommentManager GetCommentManger() /// private void ViewEntireThread_Tapped(object sender, TappedRoutedEventArgs e) { - // Get the post and the manager - Post post = ((Post)((FrameworkElement)sender).DataContext); - // First remove the current comment manager ClearCommentManger(); @@ -698,7 +696,7 @@ private void List_OnListEndDetectedEvent(object sender, OnListEndDetected e) // If we have a differed header update and we are near the top (not showing the header) // do the update now. For a full story see the comment on m_hasDeferredHeaderSizeUpdate - if (m_hasDeferredHeaderSizeUpdate && !showHeader) + if (currentScrollAera != context.HeaderSize && context.HeaderSize + 80 > e.ListScrollTotalDistance && e.ScrollDirection == ScrollDirection.Up) { SetHeaderSize(); } @@ -715,12 +713,10 @@ private void List_OnListEndDetectedEvent(object sender, OnListEndDetected e) if (m_commentManager.IsOnlyShowingSubset()) { m_commentManager.RequestMorePosts(); - } + } } } - bool headerVis = true; - /// /// Fired when a item is selected, just clear it. /// @@ -985,6 +981,12 @@ private void SetupFullScreenForNewContext() m_fullScreenOverwrite = null; m_isfullScreenOverwriteUser = null; ToggleFullscreen(false, true); + + if (m_storyHeader != null) + { + Grid headerGrid = (Grid)m_storyHeader.FindName("ui_storyHeaderBlock"); + headerGrid.MaxHeight = double.PositiveInfinity; + } } /// @@ -1059,60 +1061,86 @@ private void ToggleFullscreen(bool goFullscreen, bool force = false) { return; } - } + } } m_isFullscreen = goFullscreen; - // Get our elements for the sticky header - Storyboard storyboard = (Storyboard)m_stickyHeader.FindName("ui_storyCollapseHeader"); - DoubleAnimation animBody = (DoubleAnimation)m_stickyHeader.FindName("ui_animHeaderBodyTranslate"); - DoubleAnimation animTitle = (DoubleAnimation)m_stickyHeader.FindName("ui_animHeaderTitleTranslate"); - DoubleAnimation animSubtext = (DoubleAnimation)m_stickyHeader.FindName("ui_animHeaderSubtextTranslate"); - DoubleAnimation animIcons = (DoubleAnimation)m_stickyHeader.FindName("ui_animHeaderIconsTranslate"); - DoubleAnimation animFullscreenButton = (DoubleAnimation)m_stickyHeader.FindName("ui_animHeaderFullscreenButtonRotate"); - Grid stickyGrid = (Grid)m_stickyHeader.FindName("ui_storyHeaderBlock"); - - // Stop any past animations. - if (storyboard.GetCurrentState() != ClockState.Stopped) - { - storyboard.Stop(); - } - - // Setup the animations. - double animTo = goFullscreen ? -stickyGrid.ActualHeight : 0; - double animFrom = goFullscreen ? 0 : -stickyGrid.ActualHeight; - animBody.To = animTo; - animBody.From = animFrom; - animTitle.To = animTo; - animTitle.From = animFrom; - animSubtext.To = animTo; - animSubtext.From = animFrom; - animIcons.To = animTo; - animIcons.From = animFrom; - animFullscreenButton.To = goFullscreen ? 0 : 180; - animFullscreenButton.From = goFullscreen ? 180 : 0; - - // For the normal header - Storyboard storyNormal = (Storyboard)m_storyHeader.FindName("ui_storyCollapseHeaderHeight"); - Grid headerGrid = (Grid)m_storyHeader.FindName("ui_storyHeaderBlock"); - DoubleAnimation animNormal = (DoubleAnimation)m_storyHeader.FindName("ui_animHeaderHeightCollapse"); - DoubleAnimation animNormalFullscreenButton = (DoubleAnimation)m_storyHeader.FindName("ui_animHeaderHeightButtonRotate"); - - // Stop any past animations. - if (storyNormal.GetCurrentState() != ClockState.Stopped) - { - storyNormal.Stop(); - } - - // Set the normal animations. - animNormal.To = goFullscreen ? 0 : headerGrid.ActualHeight; - animNormal.From = goFullscreen ? headerGrid.ActualHeight : 0; - animNormalFullscreenButton.To = goFullscreen ? 0 : 180; - animNormalFullscreenButton.From = goFullscreen ? 180 : 0; - - // Play the animations. - storyboard.Begin(); - storyNormal.Begin(); + if (IsVisible) + { + // Get our elements for the sticky header + Storyboard storyboard = (Storyboard)m_stickyHeader.FindName("ui_storyCollapseHeader"); + DoubleAnimation animBody = (DoubleAnimation)m_stickyHeader.FindName("ui_animHeaderBodyTranslate"); + DoubleAnimation animTitle = (DoubleAnimation)m_stickyHeader.FindName("ui_animHeaderTitleTranslate"); + DoubleAnimation animSubtext = (DoubleAnimation)m_stickyHeader.FindName("ui_animHeaderSubtextTranslate"); + DoubleAnimation animIcons = (DoubleAnimation)m_stickyHeader.FindName("ui_animHeaderIconsTranslate"); + DoubleAnimation animFullscreenButton = (DoubleAnimation)m_stickyHeader.FindName("ui_animHeaderFullscreenButtonRotate"); + Grid stickyGrid = (Grid)m_stickyHeader.FindName("ui_storyHeaderBlock"); + + // Stop any past animations. + if (storyboard.GetCurrentState() != ClockState.Stopped) + { + storyboard.Stop(); + } + + // Setup the animations. + double animTo = goFullscreen ? -stickyGrid.ActualHeight : 0; + double animFrom = goFullscreen ? 0 : -stickyGrid.ActualHeight; + animBody.To = animTo; + animBody.From = animFrom; + animTitle.To = animTo; + animTitle.From = animFrom; + animSubtext.To = animTo; + animSubtext.From = animFrom; + animIcons.To = animTo; + animIcons.From = animFrom; + animFullscreenButton.To = goFullscreen ? 0 : 180; + animFullscreenButton.From = goFullscreen ? 180 : 0; + + // For the normal header + Storyboard storyNormal = (Storyboard)m_storyHeader.FindName("ui_storyCollapseHeaderHeight"); + Grid headerGrid = (Grid)m_storyHeader.FindName("ui_storyHeaderBlock"); + DoubleAnimation animNormal = (DoubleAnimation)m_storyHeader.FindName("ui_animHeaderHeightCollapse"); + DoubleAnimation animNormalFullscreenButton = (DoubleAnimation)m_storyHeader.FindName("ui_animHeaderHeightButtonRotate"); + + // Stop any past animations. + if (storyNormal.GetCurrentState() != ClockState.Stopped) + { + storyNormal.Stop(); + } + + // Set the normal animations. + animNormal.To = goFullscreen ? 0 : headerGrid.ActualHeight; + animNormal.From = goFullscreen ? headerGrid.ActualHeight : 0; + animNormalFullscreenButton.To = goFullscreen ? 0 : 180; + animNormalFullscreenButton.From = goFullscreen ? 180 : 0; + + // Play the animations. + storyboard.Begin(); + storyNormal.Begin(); + } + else + { + // If not visible, just reset the UI. + + // For the normal header set the size and the button + Grid headerGrid = (Grid)m_storyHeader.FindName("ui_storyHeaderBlock"); + RotateTransform headerFullscreenButtonRotate = (RotateTransform)m_storyHeader.FindName("ui_headerFullscreenButtonRotate"); + headerFullscreenButtonRotate.Angle = goFullscreen ? 0 : 180; + headerGrid.MaxHeight = goFullscreen ? double.NaN : headerGrid.ActualHeight; + + + // For the sticky header reset the transforms. + TranslateTransform titleTrans = (TranslateTransform)m_storyHeader.FindName("ui_headerTitleTransform"); + TranslateTransform subtextTrans = (TranslateTransform)m_storyHeader.FindName("ui_headerSubtextTransform"); + TranslateTransform iconTrans = (TranslateTransform)m_storyHeader.FindName("ui_headerIconsTransform"); + TranslateTransform bodyTrans = (TranslateTransform)m_storyHeader.FindName("ui_headerBodyTransform"); + Grid stickyGrid = (Grid)m_stickyHeader.FindName("ui_storyHeaderBlock"); + double setTo = goFullscreen ? -stickyGrid.ActualHeight : 0; + titleTrans.Y = setTo; + subtextTrans.Y = setTo; + iconTrans.Y = setTo; + bodyTrans.Y = setTo; + } } /// @@ -1309,15 +1337,11 @@ private int GetCurrentScrollArea() screenSize += c_hiddenShowAllCommentsHeight; } - // If we are not hiding the large header also add the height of the comment bar so it will be off screen by default - // or if we are full screen from the flip control. - if (context.Post.FlipviewHeaderVisibility == Visibility.Visible) - { - screenSize += c_hiddenCommentHeaderHeight; - } + // Add a the comment header size. + screenSize += c_hiddenCommentHeaderHeight; // If we are full screen account for the header being gone. - if(m_isFullscreen) + if (m_isFullscreen) { Grid headerGrid = (Grid)m_storyHeader.FindName("ui_storyHeaderBlock"); screenSize += (int)headerGrid.ActualHeight; @@ -1335,13 +1359,10 @@ private void ContentRoot_SizeChanged(object sender, SizeChangedEventArgs e) { // We do this so we jump the UI ever time the comment box is open. // see the description on m_hasDeferredHeaderSizeUpdate for a full story. - // This isn't 100% correct, but we are looking for comment box changes. + // This isn't 100% correct, but we are looking for comment box changes. // So if the width doesn't change assume it is the comment box. - if (e.PreviousSize.Width == e.NewSize.Width && m_lastKnownScrollOffset > 30) - { - m_hasDeferredHeaderSizeUpdate = true; - } - else + int currentScrollArea = GetCurrentScrollArea(); + if (m_lastKnownScrollOffset < currentScrollArea) { // Fire a header size change to fix them up. SetHeaderSize(); @@ -1350,7 +1371,7 @@ private void ContentRoot_SizeChanged(object sender, SizeChangedEventArgs e) #endregion - #region Comment Box + #region Comment Box /// /// Shows the comment box diff --git a/Baconit/Panels/Search.xaml b/Baconit/Panels/Search.xaml index 9de5246..494cd57 100644 --- a/Baconit/Panels/Search.xaml +++ b/Baconit/Panels/Search.xaml @@ -48,9 +48,10 @@ --> + OnMarkdownLinkTapped="MarkdownTextBlock_OnMarkdownLinkTapped" + Visibility="{x:Bind ShowMarkdownText}" />