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