Skip to content

Commit

Permalink
Final fixes for this release. Fixing up the image control. Adding the…
Browse files Browse the repository at this point in the history
… subpost header, more.
  • Loading branch information
QuinnDamerell committed Jan 20, 2016
1 parent e667720 commit f26226c
Show file tree
Hide file tree
Showing 13 changed files with 250 additions and 194 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*.sln.docstates
*.orig
*.appx
*.opendb

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
Expand Down
29 changes: 3 additions & 26 deletions BaconBackend/DataObjects/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -380,7 +380,7 @@ public Color TitleTextColor
set
{
m_titleTextColor = value;
OnPropertyChanged(nameof(TitleTextBrush));
OnPropertyChanged(nameof(TitleTextBrush));
}
}
[JsonIgnore]
Expand Down Expand Up @@ -696,29 +696,6 @@ public string CommentingOnId
[JsonIgnore]
string m_commentingOnId = "";

/// <summary>
/// Used by flip view to cache the size of the header
/// </summary>
[JsonIgnore]
public double FlipViewHeaderHeight = 0;

/// <summary>
/// Flip view post header visibility
/// </summary>
[JsonIgnore]
public Visibility FlipviewHeaderVisibility
{
get
{
return m_flipviewHeaderVisibility;
}
set
{
SetProperty(ref m_flipviewHeaderVisibility, value);
}
}
[JsonIgnore]
Visibility m_flipviewHeaderVisibility = Visibility.Visible;

/// <summary>
/// Indicates how many comments we are showing
Expand Down
40 changes: 26 additions & 14 deletions Baconit/ContentPanels/Panels/BasicImageContentPanel.xaml.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -45,7 +46,7 @@ enum ImageState
/// The calculated min zoom factor for this image.
/// </summary>
float m_minZoomFactor = 1.0f;

/// <summary>
/// Holds the current size of the control.
/// </summary>
Expand Down Expand Up @@ -207,7 +208,7 @@ public void OnDestroyContent()
bmpImage.ImageOpened -= BitmapImage_ImageOpened;
bmpImage.ImageFailed -= BitmapImage_ImageFailed;
}
}
}

// Kill the image
m_image.Source = null;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -392,8 +391,6 @@ public bool ReloadImage(bool useFullsize)
}
}



// Set the image.
m_image.Source = bitmapImage;
return true;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}

Expand Down
12 changes: 11 additions & 1 deletion Baconit/HelperControls/CommentBox.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion Baconit/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,10 @@ private void UpdateSubredditList(List<Subreddit> 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))
Expand Down
24 changes: 13 additions & 11 deletions Baconit/Panels/FlipView/FlipViewPanel.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public sealed partial class FlipViewPanel : UserControl, IPanel
/// Indicates that there is a target comment we are trying to get to.
/// </summary>
string m_targetComment = "";

/// <summary>
/// Holds a reference to the loading overlay if there is one.
/// </summary>
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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));
}
}
}
Expand All @@ -550,7 +550,7 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch
// as possible.
foreach (Post post in insertList.Reverse<Post>())
{
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
Expand All @@ -563,7 +563,7 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatch
UpdatePanelContent();
});
});
}
}

#region Flippping Logic

Expand Down Expand Up @@ -716,8 +716,8 @@ await Task.Run(() =>
});
}

#endregion
#endregion

#region Full Screen Loading

/// <summary>
Expand Down Expand Up @@ -853,7 +853,7 @@ private void CommentBox_OnCommentSubmitted(object sender, OnCommentSubmittedArgs
{
ui_commentBox.HideLoadingOverlay();
}
}
}
}

/// <summary>
Expand All @@ -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;
}
}

Expand All @@ -878,7 +880,7 @@ private void SetCommentBoxHeight(double height)
/// <param name="e"></param>
private void ContentRoot_SizeChanged(object sender, SizeChangedEventArgs e)
{
SetCommentBoxHeight(e.NewSize.Height - 1);
SetCommentBoxHeight(e.NewSize.Height);
}

#endregion
Expand Down
Loading

0 comments on commit f26226c

Please sign in to comment.