Skip to content

Commit

Permalink
Adding too much for one commit. Converting to using x:Binding for pre…
Browse files Browse the repository at this point in the history
…f. Updating json.net. Updating the target platform version. Tweaking some annimations. Adding a delay load.
  • Loading branch information
QuinnDamerell committed Jan 11, 2016
1 parent 7d8019b commit 09948f7
Show file tree
Hide file tree
Showing 17 changed files with 283 additions and 244 deletions.
3 changes: 2 additions & 1 deletion BaconBackend/BaconBackend.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<AssemblyName>BaconBackend</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.10240.0</TargetPlatformVersion>
<TargetPlatformVersion>10.0.10586.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
Expand Down Expand Up @@ -102,6 +102,7 @@
<Compile Include="Collectors\SearchPostCollector.cs" />
<Compile Include="Collectors\SearchSubredditCollector.cs" />
<Compile Include="Collectors\PostCollector.cs" />
<Compile Include="DataObjects\BindableBase.cs" />
<Compile Include="DataObjects\Comment.cs" />
<Compile Include="DataObjects\Message.cs" />
<Compile Include="DataObjects\MessageOfTheDay.cs" />
Expand Down
52 changes: 52 additions & 0 deletions BaconBackend/DataObjects/BindableBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace BaconBackend.DataObjects
{
/// <summary>
/// A helper class for objects that bind.
/// </summary>
public class BindableBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = delegate { };

/// <summary>
/// Checks if a property already matches a desired value. Sets the property and
/// notifies listeners only when necessary.
/// </summary>
/// <typeparam name="T">Type of the property.</typeparam>
/// <param name="storage">Reference to a property with both getter and setter.</param>
/// <param name="value">Desired value for the property.</param>
/// <param name="propertyName">Name of the property used to notify listeners. This
/// value is optional and can be provided automatically when invoked from compilers that
/// support CallerMemberName.</param>
/// <returns>True if the value was changed, false if the existing value matched the
/// desired value.</returns>
protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] String propertyName = null)
{
if (object.Equals(storage, value))
{
return false;
}
storage = value;
this.OnPropertyChanged(propertyName);
return true;
}

/// <summary>
/// Notifies listeners that a property value has changed.
/// </summary>
/// <param name="propertyName">Name of the property used to notify listeners. This
/// value is optional and can be provided automatically when invoked from compilers
/// that support <see cref="CallerMemberNameAttribute"/>.</param>
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
125 changes: 49 additions & 76 deletions BaconBackend/DataObjects/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ namespace BaconBackend.DataObjects
{
/// <summary>
/// A reddit post, either of a link or of text.
/// A post has a score, which is the total number of upvotes - total number of downvotes.
/// A post has a score, which is the total number of up votes - total number of down votes.
/// </summary>
[JsonObject(MemberSerialization.OptOut)]
public class Post : INotifyPropertyChanged
public class Post : BindableBase
{
/// <summary>
/// The comment's unique ID. Prefixed with "t3_", this
Expand Down Expand Up @@ -55,7 +55,7 @@ public class Post : INotifyPropertyChanged
public string Author { get; set; }

/// <summary>
/// The comment's score: total upvotes - total downvotes.
/// The comment's score: total up votes - total down votes.
/// </summary>
[JsonProperty(PropertyName = "score")]
public int Score
Expand All @@ -66,8 +66,7 @@ public int Score
}
set
{
m_score = value;
NotifyPropertyChanged(nameof(Score));
this.SetProperty(ref this.m_score, value);
}
}
[JsonIgnore]
Expand Down Expand Up @@ -155,10 +154,12 @@ public bool? Likes
return m_likes;
}
set
{
m_likes = value;
NotifyPropertyChanged(nameof(DownVoteColor));
NotifyPropertyChanged(nameof(UpVoteColor));
{
if (this.SetProperty(ref this.m_likes, value))
{
this.OnPropertyChanged(nameof(DownVoteColor));
this.OnPropertyChanged(nameof(UpVoteColor));
}
}
}
[JsonIgnore]
Expand All @@ -176,8 +177,10 @@ public bool IsSaved
}
set
{
m_isSaved = value;
NotifyPropertyChanged(nameof(IsSavedMenuText));
if(this.SetProperty(ref this.m_isSaved, value))
{
OnPropertyChanged(nameof(IsSavedMenuText));
}
}
}
[JsonIgnore]
Expand All @@ -195,8 +198,10 @@ public bool IsHidden
}
set
{
m_isHidden = value;
NotifyPropertyChanged(nameof(IsHiddenMenuText));
if (this.SetProperty(ref this.m_isHidden, value))
{
OnPropertyChanged(nameof(IsHiddenMenuText));
}
}
}
[JsonIgnore]
Expand All @@ -214,8 +219,10 @@ public CommentSortTypes CommentSortType
}
set
{
m_commentSortType = value;
NotifyPropertyChanged(nameof(CommentCurrentSortTypeString));
if(SetProperty(ref m_commentSortType, value))
{
OnPropertyChanged(nameof(CommentCurrentSortTypeString));
}
}
}
[JsonIgnore]
Expand Down Expand Up @@ -314,8 +321,7 @@ public bool IsPostVisible
}
set
{
m_isPostVisible = value;
NotifyPropertyChanged(nameof(IsPostVisible));
SetProperty(ref m_isPostVisible, value);
}
}
[JsonIgnore]
Expand All @@ -333,10 +339,11 @@ public string NewCommentText
}
set
{
m_newCommentText = value;
NotifyPropertyChanged(nameof(NewCommentText));
NotifyPropertyChanged(nameof(NewCommentColor));
NotifyPropertyChanged(nameof(NewCommentMargin));
if(SetProperty(ref m_newCommentText, value))
{
OnPropertyChanged(nameof(NewCommentColor));
OnPropertyChanged(nameof(NewCommentMargin));
}
}
}
[JsonIgnore]
Expand All @@ -354,8 +361,7 @@ public Visibility ImageVisibility
}
set
{
m_imageVisibility = value;
NotifyPropertyChanged(nameof(ImageVisibility));
SetProperty(ref m_imageVisibility, value);
}
}
[JsonIgnore]
Expand All @@ -373,8 +379,7 @@ public BitmapImage Image
}
set
{
m_image = value;
NotifyPropertyChanged(nameof(Image));
SetProperty(ref m_image, value);
}
}
[JsonIgnore]
Expand All @@ -394,7 +399,7 @@ public Color TitleTextColor
set
{
m_titleTextColor = value;
NotifyPropertyChanged(nameof(TitleTextBrush));
OnPropertyChanged(nameof(TitleTextBrush));
}
}
[JsonIgnore]
Expand All @@ -412,8 +417,7 @@ public int TitleMaxLines
}
set
{
m_titleMaxLines = value;
NotifyPropertyChanged(nameof(TitleMaxLines));
SetProperty(ref m_titleMaxLines, value);
}
}
[JsonIgnore]
Expand Down Expand Up @@ -625,8 +629,7 @@ public int HeaderSize
}
set
{
m_headerSize = value;
NotifyPropertyChanged(nameof(HeaderSize));
SetProperty(ref m_headerSize, value);
}
}
[JsonIgnore]
Expand All @@ -644,8 +647,7 @@ public ObservableCollection<Comment> Comments
}
set
{
m_comments = value;
NotifyPropertyChanged(nameof(Comments));
SetProperty(ref m_comments, value);
}
}
[JsonIgnore]
Expand All @@ -663,8 +665,7 @@ public ScrollBarVisibility VerticalScrollBarVisibility
}
set
{
m_verticalScrollBarVisibility = value;
NotifyPropertyChanged(nameof(VerticalScrollBarVisibility));
SetProperty(ref m_verticalScrollBarVisibility, value);
}
}
[JsonIgnore]
Expand All @@ -683,8 +684,7 @@ public Visibility ShowCommentLoadingMessage
}
set
{
m_showCommentLoadingMessage = value;
NotifyPropertyChanged(nameof(ShowCommentLoadingMessage));
SetProperty(ref m_showCommentLoadingMessage, value);
}
}
[JsonIgnore]
Expand All @@ -702,8 +702,7 @@ public string ShowCommentsErrorMessage
}
set
{
m_showCommentsErrorMessage = value;
NotifyPropertyChanged(nameof(ShowCommentsErrorMessage));
SetProperty(ref m_showCommentsErrorMessage, value);
}
}
[JsonIgnore]
Expand All @@ -721,8 +720,7 @@ public Visibility FlipViewMenuButton
}
set
{
m_flipViewMenuButton = value;
NotifyPropertyChanged(nameof(FlipViewMenuButton));
SetProperty(ref m_flipViewMenuButton, value);
}
}
[JsonIgnore]
Expand All @@ -741,8 +739,7 @@ public Visibility FlipViewStickyHeaderVis
}
set
{
m_flipViewStickyHeaderVis = value;
NotifyPropertyChanged(nameof(FlipViewStickyHeaderVis));
SetProperty(ref m_flipViewStickyHeaderVis, value);
}
}
[JsonIgnore]
Expand All @@ -760,8 +757,7 @@ public Thickness FlipViewStickyHeaderMargin
}
set
{
m_flipViewStickyHeaderMargin = value;
NotifyPropertyChanged(nameof(FlipViewStickyHeaderMargin));
SetProperty(ref m_flipViewStickyHeaderMargin, value);
}
}
[JsonIgnore]
Expand All @@ -780,8 +776,7 @@ public Visibility FlipViewShowEntireThreadMessage
}
set
{
m_flipViewShowEntireThreadMessage = value;
NotifyPropertyChanged(nameof(FlipViewShowEntireThreadMessage));
SetProperty(ref m_flipViewShowEntireThreadMessage, value);
}
}
[JsonIgnore]
Expand All @@ -805,8 +800,7 @@ public string CommentingOnId
}
set
{
m_commentingOnId = value;
NotifyPropertyChanged(nameof(CommentingOnId));
SetProperty(ref m_commentingOnId, value);
}
}
[JsonIgnore]
Expand All @@ -830,8 +824,7 @@ public Visibility FlipviewHeaderVisibility
}
set
{
m_flipviewHeaderVisibility = value;
NotifyPropertyChanged(nameof(FlipviewHeaderVisibility));
SetProperty(ref m_flipviewHeaderVisibility, value);
}
}
[JsonIgnore]
Expand All @@ -849,8 +842,7 @@ public int HeaderCollpaseToggleAngle
}
set
{
m_headerCollpaseToggleAngle = value;
NotifyPropertyChanged(nameof(HeaderCollpaseToggleAngle));
SetProperty(ref m_headerCollpaseToggleAngle, value);
}
}
[JsonIgnore]
Expand All @@ -869,8 +861,7 @@ public int CurrentCommentShowingCount
}
set
{
m_currentCommentCount = value;
NotifyPropertyChanged(nameof(CurrentCommentShowingCount));
SetProperty(ref m_currentCommentCount, value);
}
}
[JsonIgnore]
Expand All @@ -888,9 +879,10 @@ public bool FlipViewShowLoadingMoreComments
}
set
{
m_flipViewShowLoadingMoreComments = value;
NotifyPropertyChanged(nameof(FlipViewShowLoadingMoreComments));
NotifyPropertyChanged(nameof(FlipViewShowLoadingMoreCommentsVis));
if (SetProperty(ref m_flipViewShowLoadingMoreComments, value))
{
OnPropertyChanged(nameof(FlipViewShowLoadingMoreCommentsVis));
}
}
}
[JsonIgnore]
Expand All @@ -908,25 +900,6 @@ public Visibility FlipViewShowLoadingMoreCommentsVis
}
}


#endregion

/// <summary>
/// UI property changed handler that's called when a property of this comment is changed.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;

/// <summary>
/// Called to indicate a property of this object has changed.
/// </summary>
/// <param name="propertyName">Name of the changed property.</param>
private void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
Loading

0 comments on commit 09948f7

Please sign in to comment.