Example #1
0
        /// <summary>
        /// Fired when the list is scrolled down a ways.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PostList_OnListEndDetectedEvent(object sender, HelperControls.ListEndDetected e)
        {
            if (_mUser == null)
            {
                return;
            }

            EnsurePostCollector();

            // Request a extension.
            _mPostCollector.ExtendCollection();
        }
Example #2
0
        /// <summary>
        /// Updates the content in all of the panels in flipview.
        /// </summary>
        private async void UpdatePanelContent()
        {
            // Create a list we need to set to the UI.
            var setToUiList      = new List <Tuple <FlipViewPostItem, bool> >();
            var clearList        = new List <FlipViewPostItem>();
            var extendCollection = false;

            // Get the min and max number of posts to load.
            var minContentLoad = ui_flipView.SelectedIndex;
            var maxContentLoad = ui_flipView.SelectedIndex;

            if (App.BaconMan.UiSettingsMan.FlipViewPreloadFutureContent)
            {
                maxContentLoad++;
            }

            // Lock the list
            lock (_postsLists)
            {
                for (var i = 0; i < _postsLists.Count; i++)
                {
                    var item = _postsLists[i];
                    if (i >= minContentLoad && i <= maxContentLoad)
                    {
                        // Add the post to the list of posts to set. We have to do this outside of the lock
                        // because we might delay while doing it.
                        setToUiList.Add(new Tuple <FlipViewPostItem, bool>(item, ui_flipView.SelectedIndex == i));
                    }
                    else
                    {
                        // Add the post to the list of posts to clear. We have to do this outside of the lock
                        // because we might delay while doing it.
                        clearList.Add(item);
                    }
                }

                // Check if we should load more posts. Note we want to check how many post the
                // collector has because this gets called when the m_postList is being built, thus
                // the count will be wrong.
                if (_postsLists.Count > 5 && _collector.GetCurrentPosts().Count < maxContentLoad + 4)
                {
                    extendCollection = true;
                }
            }

            // Extend if we should
            if (extendCollection)
            {
                _collector.ExtendCollection(25);
            }

            // Now that we are out of lock set the items we want to set.
            foreach (var tuple in setToUiList)
            {
                // We found an item to show or prelaod, do it.
                await SetPostContent(tuple.Item1, tuple.Item2);

                // If this is the first post to load delay for a while to give the UI time to setup.
                if (_isFirstPostLoad)
                {
                    _isFirstPostLoad = false;
                    await Task.Delay(1000);
                }

                // After the delay tell the post to prefetch the comments if we are visible.
                if (tuple.Item2)
                {
                    tuple.Item1.LoadComments = true;
                }
            }

            // Now set them all to not be visible and clear
            // the comments.
            foreach (var item in clearList)
            {
                item.IsVisible    = false;
                item.LoadComments = false;
            }

            // Kick off a background thread to clear out what we don't want.
            await Task.Run(() =>
            {
                // Get all of our content.
                var allContent = ContentPanelMaster.Current.GetAllAllowedContentForGroup(_uniqueId);

                // Find the ids that should be cleared and clear them.
                foreach (var contentId in allContent)
                {
                    var found = false;
                    foreach (var tuple in setToUiList)
                    {
                        if (!tuple.Item1.Context.Post.Id.Equals(contentId))
                        {
                            continue;
                        }
                        found = true;
                        break;
                    }

                    if (!found)
                    {
                        // If we didn't find it clear it.
                        ContentPanelMaster.Current.RemoveAllowedContent(contentId);
                    }
                }
            });
        }
 private void Ui_postList_OnListEndDetectedEvent(object sender, HelperControls.OnListEndDetected e)
 {
     // Suppress more event until we get more items.
     ui_postList.SuppressEndOfListEvent = true;
     m_collector.ExtendCollection();
 }