Esempio n. 1
0
        /// <summary>
        /// Sets the post content. For now all we give the flip view control is the URL
        /// and it must figure out the rest on it's own.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="isVisiblePost"></param>
        private async Task SetPostContent(FlipViewPostItem item, bool isVisiblePost)
        {
            // Set that the post is visible if it is
            item.IsVisible = isVisiblePost;

            // Only load the content if we are doing it with out action. (most of the time)
            if (App.BaconMan.UiSettingsMan.FlipViewLoadPostContentWithoutAction)
            {
                await Task.Run(() =>
                {
                    ContentPanelMaster.Current.AddAllowedContent(ContentPanelSource.CreateFromPost(item.Context.Post), _uniqueId, !isVisiblePost);
                });
            }
        }
        /// <summary>
        /// Sets the post content. For now all we give the flip view control is the URL
        /// and it must figure out the rest on it's own.
        /// </summary>
        /// <param name="post"></param>
        private async Task SetPostContent(FlipViewPostItem item, bool isVisiblePost)
        {
            // Set that the post is visible if it is
            item.IsVisible = isVisiblePost;

            // Only load the content if we are doing it with out action. (most of the time)
            if (App.BaconMan.UiSettingsMan.FlipView_LoadPostContentWithoutAction)
            {
                await Task.Run(() =>
                {
                    ContentPanelMaster.Current.AddAllowedContent(ContentPanelSource.CreateFromPost(item.Context.Post), m_uniqueId, !isVisiblePost);
                });
            }
        }
Esempio n. 3
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.
            List <Tuple <FlipViewPostItem, bool> > setToUiList = new List <Tuple <FlipViewPostItem, bool> >();
            List <FlipViewPostItem> clearList = new List <FlipViewPostItem>();
            bool extendCollection             = false;

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

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

            // Lock the list
            lock (m_postsLists)
            {
                for (int i = 0; i < m_postsLists.Count; i++)
                {
                    FlipViewPostItem item = m_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 (m_postsLists.Count > 5 && m_collector.GetCurrentPosts().Count < maxContentLoad + 4)
                {
                    extendCollection = true;
                }
            }

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

            // Now that we are out of lock set the items we want to set.
            foreach (Tuple <FlipViewPostItem, bool> 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 (m_isFirstPostLoad)
                {
                    m_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 (FlipViewPostItem 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.
                List <string> allContent = ContentPanelMaster.Current.GetAllAllowedContentForGroup(m_uniqueId);

                // Find the ids that should be cleared and clear them.
                List <string> removeId = new List <string>();
                foreach (string contentId in allContent)
                {
                    bool found = false;
                    foreach (Tuple <FlipViewPostItem, bool> tuple in setToUiList)
                    {
                        if (tuple.Item1.Context.Post.Id.Equals(contentId))
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        // If we didn't find it clear it.
                        ContentPanelMaster.Current.RemoveAllowedContent(contentId);
                    }
                }
            });
        }