示例#1
0
        /// <summary>
        /// Attempts to prefetch comments. Returns true if it is going, or false it not.
        /// </summary>
        /// <returns></returns>
        public bool PreFetchComments()
        {
            // Only attempt to do this once.
            if (m_attemptedToLoadComments)
            {
                return(false);
            }
            m_attemptedToLoadComments = true;

            // Do this in a background thread
            Task.Run(() =>
            {
                // Ensure we have a collector
                DeferredCollector <Comment> collector = EnsureCollector();

                // We have to ask for all the comments here bc we can't extend.
                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 <Comment> args = new OnCollectionUpdatedArgs <Comment>()
                    {
                        ChangedItems     = collector.GetCurrentItems(false),
                        IsFreshUpdate    = true,
                        IsInsert         = false,
                        StartingPosition = 0
                    };
                    CommentCollector_OnCollectionUpdated(null, args);
                }
            });

            return(true);
        }
示例#2
0
        /// <summary>
        /// Fired when the comment sort is changed.
        /// </summary>
        public void ChangeCommentSort()
        {
            // Show loading
            m_post.FlipViewShowLoadingMoreComments = true;

            // Do this in a background thread
            Task.Run(() =>
            {
                // Delete the collector
                DeleteCollector();

                // Make a new one.
                DeferredCollector <Comment> collector = EnsureCollector();

                // Force our collector to update.
                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 <Comment> args = new OnCollectionUpdatedArgs <Comment>()
                    {
                        ChangedItems     = collector.GetCurrentItems(true),
                        IsFreshUpdate    = true,
                        IsInsert         = false,
                        StartingPosition = 0
                    };
                    CommentCollector_OnCollectionUpdated(null, args);
                }
            });
        }
        /// <summary>
        /// Ensures a collector exists
        /// </summary>
        private void EnsureCollector()
        {
            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 <Comment>(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;
            }
        }
示例#4
0
 /// <summary>
 /// Deletes the current collector
 /// </summary>
 private void DeleteCollector()
 {
     lock (_commentCollectorLock)
     {
         // Kill the current collector
         if (_commentCollector != null)
         {
             _commentCollector.OnCollectionUpdated    -= CommentCollector_OnCollectionUpdated;
             _commentCollector.OnCollectorStateChange -= CommentCollector_OnCollectorStateChange;
         }
         _commentCollector = null;
     }
 }
示例#5
0
        /// <summary>
        /// Kicks off a refresh of the comments.
        /// </summary>
        public void Refresh()
        {
            // Show loading
            m_post.FlipViewShowLoadingMoreComments = true;

            // Do this in a background thread
            Task.Run(() =>
            {
                // If we have a collector kick off an update.
                DeferredCollector <Comment> collector = EnsureCollector();
                if (collector != null)
                {
                    collector.LoadAllItems(true, m_post.CurrentCommentShowingCount);
                }
            });
        }
        public void PrepareForDeletion()
        {
            // Clear out, we are going to be deleted
            m_post.Comments.Clear();

            if (m_fullCommentList != null)
            {
                m_fullCommentList.Clear();
            }

            // Kill the collector
            if (m_commentCollector != null)
            {
                m_commentCollector.OnCollectionUpdated    -= CommentCollector_OnCollectionUpdated;
                m_commentCollector.OnCollectorStateChange -= CommentCollector_OnCollectorStateChange;
            }
            m_commentCollector = null;
        }
示例#7
0
        /// <summary>
        /// Ensures a collector exists
        /// </summary>
        private DeferredCollector <Comment> EnsureCollector()
        {
            lock (_commentCollectorLock)
            {
                if (_commentCollector != null)
                {
                    return(_commentCollector);
                }

                // Get the comment collector, if we don't want to show a subset don't give it the target comment
                _commentCollector = new DeferredCollector <Comment>(CommentCollector.GetCollector(_post, App.BaconMan, _showThreadSubset ? _targetComment : null));

                // Sub to collection callbacks for the comments.
                _commentCollector.OnCollectionUpdated    += CommentCollector_OnCollectionUpdated;
                _commentCollector.OnCollectorStateChange += CommentCollector_OnCollectorStateChange;
                return(_commentCollector);
            }
        }
示例#8
0
        /// <summary>
        /// Called when we need more posts because we are scrolling down.
        /// </summary>
        public async void RequestMorePosts()
        {
            // Ensure we have a collector.
            DeferredCollector <Comment> collector = EnsureCollector();

            // As the deferred collector to load all items, if we are doing work show loading.
            if (collector.LoadAllItems())
            {
                // Dispatch to the UI thread
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    // Only show the loading if the current number of comments is 0
                    if (Comments.Count == 0)
                    {
                        m_post.ShowCommentLoadingMessage = Visibility.Visible;
                    }
                });
            }
        }
        /// <summary>
        /// Fired when the comment sort is changed.
        /// </summary>
        public void ChangeCommentSort()
        {
            // Show loading
            m_post.FlipViewShowLoadingMoreComments = true;

            // 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 <Comment>(CommentCollector.GetCollector(m_post, App.BaconMan));

                // Sub to collection callbacks for the comments.
                m_commentCollector.OnCollectionUpdated    += CommentCollector_OnCollectionUpdated;
                m_commentCollector.OnCollectorStateChange += CommentCollector_OnCollectorStateChange;

                // Force our collector to update.
                if (!m_commentCollector.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 <Comment> args = new OnCollectionUpdatedArgs <Comment>()
                    {
                        ChangedItems     = m_commentCollector.GetCurrentItems(true),
                        IsFreshUpdate    = true,
                        IsInsert         = false,
                        StartingPosition = 0
                    };
                    CommentCollector_OnCollectionUpdated(null, args);
                }
            });
        }
示例#10
0
        /// <summary>
        /// Called when the comment should be deleted
        /// </summary>
        public void CommentDeleteRequest(Comment comment)
        {
            DeferredCollector <Comment> collector = EnsureCollector();

            ((CommentCollector)collector.GetCollector()).CommentDeleteRequest(comment);
        }
示例#11
0
        /// <summary>
        /// Called when is added or edited
        /// </summary>
        public bool CommentAddedOrEdited(string parentOrOrgionalId, OnCommentSubmittedArgs args)
        {
            DeferredCollector <Comment> collector = EnsureCollector();

            return(((CommentCollector)collector.GetCollector()).CommentAddedOrEdited(parentOrOrgionalId, args.Response, args.IsEdit));
        }
        /// <summary>
        /// Fired when the comment sort is changed.
        /// </summary>
        public void ChangeCommentSort()
        {
            // Show loading
            m_post.FlipViewShowLoadingMoreComments = true;

            // 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<Comment>(CommentCollector.GetCollector(m_post, App.BaconMan));

                // Sub to collection callbacks for the comments.
                m_commentCollector.OnCollectionUpdated += CommentCollector_OnCollectionUpdated;
                m_commentCollector.OnCollectorStateChange += CommentCollector_OnCollectorStateChange;

                // Force our collector to update.
                if (!m_commentCollector.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<Comment> args = new OnCollectionUpdatedArgs<Comment>()
                    {
                        ChangedItems = m_commentCollector.GetCurrentItems(true),
                        IsFreshUpdate = true,
                        IsInsert = false,
                        StartingPosition = 0
                    };
                    CommentCollector_OnCollectionUpdated(null, args);
                }
            });
        }
示例#13
0
        /// <summary>
        /// Returns if we are only showing a subset of the comments.
        /// </summary>
        /// <returns></returns>
        public bool IsOnlyShowingSubset()
        {
            DeferredCollector <Comment> collector = EnsureCollector();

            return(collector != null?collector.GetState() == DeferredLoadState.Subset : true);
        }
        public void PrepareForDeletion()
        {
            // Clear out, we are going to be deleted
            m_post.Comments.Clear();

            if(m_fullCommentList != null)
            {
                m_fullCommentList.Clear();
            }

            // Kill the collector
            if (m_commentCollector != null)
            {
                m_commentCollector.OnCollectionUpdated -= CommentCollector_OnCollectionUpdated;
                m_commentCollector.OnCollectorStateChange -= CommentCollector_OnCollectorStateChange;
            }
            m_commentCollector = null;
        }
        /// <summary>
        /// Ensures a collector exists
        /// </summary>
        private void EnsureCollector()
        {
            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<Comment>(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;
            }
        }
示例#16
0
        public void DownVote_Tapped(Comment comment)
        {
            DeferredCollector <Comment> collector = EnsureCollector();

            ((CommentCollector)collector.GetCollector()).ChangeCommentVote(comment, PostVoteAction.DownVote);
        }
        /// <summary>
        /// Deletes the current collector
        /// </summary>
        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;

            }
        }