Skip to content

Commit

Permalink
Refactoring out the flip post panel from flip view so the code has be…
Browse files Browse the repository at this point in the history
…tter separation. Also adding some nice animations for the header when viewing comments.
  • Loading branch information
QuinnDamerell committed Jan 19, 2016
1 parent ed39735 commit 2d6bc0d
Show file tree
Hide file tree
Showing 22 changed files with 3,076 additions and 2,389 deletions.
27 changes: 18 additions & 9 deletions BaconBackend/Collectors/DeferredCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@

namespace BaconBackend.Collectors
{
/// <summary>
/// Indicates the state of this collector
/// </summary>
public enum DeferredLoadState
{
Subset,
All
};

/// <summary>
/// Used to support deferred loading of items from a collector. We get all of the items at once,
/// but only return a subset of them at a time.
Expand All @@ -16,15 +25,6 @@ namespace BaconBackend.Collectors
/// <typeparam name="T"></typeparam>
public class DeferredCollector<T>
{
/// <summary>
/// Indicates the state of this collector
/// </summary>
enum DeferredLoadState
{
Subset,
All
};

/// <summary>
/// Fired when the state of the collector is changing.
/// </summary>
Expand Down Expand Up @@ -83,6 +83,15 @@ public bool PreLoadItems(bool forceUpdate = false, int requestCount = 50)
return m_collector.Update(forceUpdate, requestCount);
}

/// <summary>
/// Gets the current state of the deferred collector.
/// </summary>
/// <returns></returns>
public DeferredLoadState GetState()
{
return m_state;
}

/// <summary>
/// Loads all of the items the collector has. If we already have the items loaded we will just send them,
/// if they aren't loaded we will wait for the collector to load them.
Expand Down
129 changes: 0 additions & 129 deletions BaconBackend/DataObjects/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,25 +308,6 @@ private static SolidColorBrush GetDarkenedAccentBrush()
[JsonIgnore]
public string FlipViewSecondary { get; set; }


/// <summary>
/// Used by flip view to indicate when the post is visible
/// </summary>
[JsonIgnore]
public bool IsPostVisible
{
get
{
return m_isPostVisible;
}
set
{
SetProperty(ref m_isPostVisible, value);
}
}
[JsonIgnore]
bool m_isPostVisible = false;

/// <summary>
/// Used by subreddit view to show unread comment count
/// </summary>
Expand Down Expand Up @@ -617,60 +598,6 @@ public Visibility GildedVisibility

#region FlipView Vars

/// <summary>
/// The number of pixels the UI needs to display the post's header.
/// </summary>
[JsonIgnore]
public int HeaderSize
{
get
{
return m_headerSize;
}
set
{
SetProperty(ref m_headerSize, value);
}
}
[JsonIgnore]
int m_headerSize = 500;

/// <summary>
/// The list of comments on this post.
/// </summary>
[JsonIgnore]
public ObservableCollection<Comment> Comments
{
get
{
return m_comments;
}
set
{
SetProperty(ref m_comments, value);
}
}
[JsonIgnore]
ObservableCollection<Comment> m_comments = new ObservableCollection<Comment>();

/// <summary>
/// The visibility of the scroll bar depending on if the any comments are loaded.
/// </summary>
[JsonIgnore]
public ScrollBarVisibility VerticalScrollBarVisibility
{
get
{
return m_verticalScrollBarVisibility;
}
set
{
SetProperty(ref m_verticalScrollBarVisibility, value);
}
}
[JsonIgnore]
ScrollBarVisibility m_verticalScrollBarVisibility = ScrollBarVisibility.Hidden;


/// <summary>
/// The visibility of "Loading Comments", depending on if the comments have loaded yet.
Expand Down Expand Up @@ -726,43 +653,6 @@ public Visibility FlipViewMenuButton
[JsonIgnore]
Visibility m_flipViewMenuButton = Visibility.Collapsed;

/// <summary>
/// The visibility of the post's header as sticky to the top of the flip view.
/// Note!!! The default should be visible so the FlipViewStickyHeaderMargin trick works!
/// </summary>
[JsonIgnore]
public Visibility FlipViewStickyHeaderVis
{
get
{
return m_flipViewStickyHeaderVis;
}
set
{
SetProperty(ref m_flipViewStickyHeaderVis, value);
}
}
[JsonIgnore]
Visibility m_flipViewStickyHeaderVis = Visibility.Visible;

/// <summary>
/// Fun trick, this is used to make the flipview sticky header render off screen so it is ready when we want
/// to show it. We use -3000 to make sure it is way off screen.
/// </summary>
public Thickness FlipViewStickyHeaderMargin
{
get
{
return m_flipViewStickyHeaderMargin;
}
set
{
SetProperty(ref m_flipViewStickyHeaderMargin, value);
}
}
[JsonIgnore]
Thickness m_flipViewStickyHeaderMargin = new Thickness(0,-3000,0,0);

/// <summary>
/// The visibility of the button to show all comments on a post.
/// This should be visible when only some comments are visible.
Expand Down Expand Up @@ -830,25 +720,6 @@ public Visibility FlipviewHeaderVisibility
[JsonIgnore]
Visibility m_flipviewHeaderVisibility = Visibility.Visible;

/// <summary>
/// The current angle of the header toggle button
/// </summary>
[JsonIgnore]
public int HeaderCollpaseToggleAngle
{
get
{
return m_headerCollpaseToggleAngle;
}
set
{
SetProperty(ref m_headerCollpaseToggleAngle, value);
}
}
[JsonIgnore]
int m_headerCollpaseToggleAngle = 180;


/// <summary>
/// Indicates how many comments we are showing
/// </summary>
Expand Down
28 changes: 28 additions & 0 deletions BaconBackend/Managers/UiSettingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,34 @@ public bool FlipView_ShowCommentScrollTip
}
private bool? m_flipView_ShowCommentScrollTip = null;

/// <summary>
/// If the user wants us to minimize the story header.
/// </summary>
public bool FlipView_MinimizeStoryHeader
{
get
{
if (!m_flipView_MinimizeStoryHeader.HasValue)
{
if (m_baconMan.SettingsMan.RoamingSettings.ContainsKey("UiSettingManager.FlipView_MinimizeStoryHeader"))
{
m_flipView_MinimizeStoryHeader = m_baconMan.SettingsMan.ReadFromRoamingSettings<bool>("UiSettingManager.FlipView_MinimizeStoryHeader");
}
else
{
m_flipView_MinimizeStoryHeader = true;
}
}
return m_flipView_MinimizeStoryHeader.Value;
}
set
{
m_flipView_MinimizeStoryHeader = value;
m_baconMan.SettingsMan.WriteToRoamingSettings<bool>("UiSettingManager.FlipView_MinimizeStoryHeader", m_flipView_MinimizeStoryHeader.Value);
}
}
private bool? m_flipView_MinimizeStoryHeader = null;

#endregion

#region Developer
Expand Down
16 changes: 13 additions & 3 deletions Baconit/Baconit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
<DependentUpon>CommentsLoadingFooter.xaml</DependentUpon>
</Compile>
<Compile Include="HelperControls\EndDetectingListView.cs" />
<Compile Include="HelperControls\ExtendedVisualStateManger.cs" />
<Compile Include="HelperControls\GlobalContentPresenter.xaml.cs">
<DependentUpon>GlobalContentPresenter.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -191,7 +192,12 @@
<Compile Include="PanelManager.xaml.cs">
<DependentUpon>PanelManager.xaml</DependentUpon>
</Compile>
<Compile Include="Panels\FlipViewPostCommentManager.cs" />
<Compile Include="Panels\FlipView\FlipViewPostCommentManager.cs" />
<Compile Include="Panels\FlipView\FlipViewPostContext.cs" />
<Compile Include="Panels\FlipView\FlipViewPostItem.cs" />
<Compile Include="Panels\FlipView\FlipViewPostPanel.xaml.cs">
<DependentUpon>FlipViewPostPanel.xaml</DependentUpon>
</Compile>
<Compile Include="Panels\MessageInbox.xaml.cs">
<DependentUpon>MessageInbox.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -222,7 +228,7 @@
<Compile Include="Panels\SettingsPanels\SubredditViewSettings.xaml.cs">
<DependentUpon>SubredditViewSettings.xaml</DependentUpon>
</Compile>
<Compile Include="Panels\FlipViewPanel.xaml.cs">
<Compile Include="Panels\FlipView\FlipViewPanel.xaml.cs">
<DependentUpon>FlipViewPanel.xaml</DependentUpon>
</Compile>
<Compile Include="Panels\LoginPanel.xaml.cs">
Expand Down Expand Up @@ -418,10 +424,14 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Panels\FlipViewPanel.xaml">
<Page Include="Panels\FlipView\FlipViewPanel.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Panels\FlipView\FlipViewPostPanel.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Panels\LoginPanel.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
2 changes: 1 addition & 1 deletion Baconit/ContentPanels/Panels/WebPageContentPanel.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private void NavigationCompleted(WebView sender, WebViewNavigationCompletedEvent
}
private void NavigationFailed(object sender, WebViewNavigationFailedEventArgs e)
{
m_base.FireOnError(true, "This web page having trouble loading");
m_base.FireOnError(true, "This web page is broken");
}

private void NavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args)
Expand Down
35 changes: 33 additions & 2 deletions Baconit/HelperControls/EndDetectingListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,31 @@

namespace Baconit.HelperControls
{
/// <summary>
/// Indicates which way the list is scrolling.
/// </summary>
public enum ScrollDirection
{
WiggleRoomUp, // Used to indicate when we are going up but might not want to react.
Up,
Down
}

/// <summary>
/// The args class for the OnListEndDetected event.
/// </summary>
public class OnListEndDetected : EventArgs
{
public double ListScrollPercent;
public double ListScrollTotalDistance;
public ScrollDirection ScrollDirection;
}

public class EndDetectingListView : ListView
{
ScrollBar m_listeningScrollBar = null;
double m_lastValue = 0;
double m_lastDirectionChangeValue = 0;

public EndDetectingListView()
{
Expand Down Expand Up @@ -66,6 +79,9 @@ public bool SuppressEndOfListEvent
/// <param name="e"></param>
private void EndDetectingListView_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
// Stop listening to the event. We only want to do this once.
Loaded -= EndDetectingListView_Loaded;

// Get the scroll bars
List<DependencyObject> scrollBars = new List<DependencyObject>();
UiControlHelpers<ScrollBar>.RecursivelyFindElement(this, ref scrollBars);
Expand Down Expand Up @@ -100,9 +116,24 @@ private void ScrollBar_ValueChanged(object sender, RangeBaseValueChangedEventArg
{
// Calculate the percent and fire when it meets the threshold
double scrollPercentage = m_listeningScrollBar.Value / m_listeningScrollBar.Maximum;
if (!m_supressEndOfListEvent && scrollPercentage > m_endOfListDetectionThreshold)
ScrollDirection direction = m_lastValue > m_listeningScrollBar.Value ? ScrollDirection.Up : ScrollDirection.Down;
m_lastValue = m_listeningScrollBar.Value;

// We need to account for some play in the numbers when it comes to this, don't report a
// direction of up until we move up 50px from the last down position. This prevents us from
// jump back and forth when on a small point.
if(direction == ScrollDirection.Up && (m_lastDirectionChangeValue - m_lastValue) < 50)
{
direction = ScrollDirection.WiggleRoomUp;
}
else if(direction == ScrollDirection.Down)
{
m_lastDirectionChangeValue = m_listeningScrollBar.Value;
}

if ((!m_supressEndOfListEvent && scrollPercentage > m_endOfListDetectionThreshold) || m_listeningScrollBar.Value == 0)
{
m_onListEndDetectedEvent.Raise(this, new OnListEndDetected() { ListScrollPercent = scrollPercentage, ListScrollTotalDistance = m_listeningScrollBar.Value });
m_onListEndDetectedEvent.Raise(this, new OnListEndDetected() { ListScrollPercent = scrollPercentage, ListScrollTotalDistance = m_listeningScrollBar.Value, ScrollDirection = direction });
}
}
}
Expand Down
Loading

0 comments on commit 2d6bc0d

Please sign in to comment.