Exemple #1
0
        public void SetupPage(Subreddit subreddit, SortTypes sortType)
        {
            // Capture the subreddit
            m_subreddit = subreddit;

            // Get the sort type
            SetCurrentSort(sortType);

            // Set the sub status
            SetSubscribeStatus();

            // Get the collector and register for updates.
            m_collector = SubredditCollector.GetCollector(m_subreddit, App.BaconMan, m_currentSortType);
            m_collector.OnCollectorStateChange += Collector_OnCollectorStateChange;
            m_collector.OnCollectionUpdated    += Collector_OnCollectionUpdated;

            // Kick off an update of the subreddits if needed.
            m_collector.Update(false, 30);

            // Set any posts that exist right now
            SetPosts(0, m_collector.GetCurrentPosts(), true);

            // Setup the UI with the name.
            ui_subredditName.Text = $"/r/{m_subreddit.DisplayName}";
        }
Exemple #2
0
        /// <summary>
        /// Updates the content in all of the panels in flipview.
        /// </summary>
        private void UpdatePanelContent()
        {
            // Lock the list
            lock (m_postsLists)
            {
                int minContentLoad = ui_flipView.SelectedIndex - CACHE_BACK_COUNT;
                int maxContentLoad = ui_flipView.SelectedIndex + CACHE_FORWARD_COUNT;

                for (int i = 0; i < m_postsLists.Count; i++)
                {
                    Post post = m_postsLists[i];
                    if (i >= minContentLoad && i <= maxContentLoad)
                    {
                        // We found an item to preload, ask it to.
                        SetPostContent(ref post, ui_flipView.SelectedIndex == i);

                        // If this is the current item also preload the comments
                        if (ui_flipView.SelectedIndex == i)
                        {
                            PreFetchPostComments(ref post);
                        }
                    }
                    else
                    {
                        ClearPostContent(ref post);
                        ClearPostComments(ref post);
                    }
                }

                // 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)
                {
                    m_collector.ExtendCollection(25);
                }
            }

            // Update the header sizes
            SetHeaderSizes();
        }
Exemple #3
0
        /// <summary>
        /// Fired when the collector state is updated.
        /// </summary>
        /// <param name="state">The new state</param>
        private async void Collector_OnCollectorStateChange(object sender, OnCollectorStateChangeArgs args)
        {
            // Set loading if needed.
            ToggleLoadingBar(args.State == CollectorState.Updating || args.State == CollectorState.Extending);

            // Toggle the suppress depending on if we are updating, extending, or idle
            ui_postList.SuppressEndOfListEvent = args.State == CollectorState.Updating || args.State == CollectorState.Extending;

            // If we had an error show a message.
            if (m_isVisible && args.State == CollectorState.Error)
            {
                App.BaconMan.MessageMan.ShowMessageSimple("That's Not Right", "We can't update this subreddit right now, check your internet connection.");
            }

            // Show no posts if nothing was loaded
            if (args.State == CollectorState.Idle)
            {
                bool postLoaded = m_collector.GetCurrentPosts().Count != 0;
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    ui_noPostText.Visibility = postLoaded ? Visibility.Collapsed : Visibility.Visible;
                });
            }
        }
Exemple #4
0
        /// <summary>
        /// Fired when the panel is being created.
        /// </summary>
        /// <param name="host">A reference to the host.</param>
        /// <param name="arguments">Arguments for the panel</param>
        public void PanelSetup(IPanelHost host, Dictionary <string, object> arguments)
        {
            // Capture the host
            m_host = host;

            // Check for the subreddit arg
            if (!arguments.ContainsKey(PanelManager.NAV_ARGS_SUBREDDIT_NAME))
            {
                throw new Exception("No subreddit was given!");
            }
            string subredditName = (string)arguments[PanelManager.NAV_ARGS_SUBREDDIT_NAME];

            // Kick off a background task to do the work
            Task.Run(async() =>
            {
                // Try to get the subreddit from the local cache.
                Subreddit subreddit = App.BaconMan.SubredditMan.GetSubredditByDisplayName(subredditName);

                // It is very rare that we can't get it from the cache because something
                // else usually request it from the web and then it will be cached.
                if (subreddit == null)
                {
                    // Since this can take some time, show the loading overlay
                    ShowFullScreenLoading();

                    // Try to get the subreddit from the web
                    subreddit = await App.BaconMan.SubredditMan.GetSubredditFromWebByDisplayName((string)arguments[PanelManager.NAV_ARGS_SUBREDDIT_NAME]);
                }

                // Check again.
                if (subreddit == null)
                {
                    // Hmmmm. We can't load the subreddit. Show a message and go back
                    App.BaconMan.MessageMan.ShowMessageSimple("Hmmm, That's Not Right", "We can't load this subreddit right now, check your Internet connection.");

                    // We need to wait some time until the transition animation is done or we can't go back.
                    // If we call GoBack while we are still navigating it will be ignored.
                    await Task.Delay(1000);

                    // Now try to go back.
                    await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                    {
                        m_host.GoBack();
                    });

                    // Get out of here.
                    return;
                }

                // Capture the subreddit
                m_subreddit = subreddit;

                // Get the current sort
                m_currentSort = arguments.ContainsKey(PanelManager.NAV_ARGS_SUBREDDIT_SORT) ? (SortTypes)arguments[PanelManager.NAV_ARGS_SUBREDDIT_SORT] : SortTypes.Hot;

                // Try to get the target post id
                if (arguments.ContainsKey(PanelManager.NAV_ARGS_POST_ID))
                {
                    m_targetPost = (string)arguments[PanelManager.NAV_ARGS_POST_ID];
                }

                // Try to get the force post, this will make us show only one post for the subreddit,
                // which is the post given.
                string forcePostId = null;
                if (arguments.ContainsKey(PanelManager.NAV_ARGS_FORCE_POST_ID))
                {
                    forcePostId = (string)arguments[PanelManager.NAV_ARGS_FORCE_POST_ID];

                    // If the UI isn't already shown show the loading UI. Most of the time this post wont' be cached
                    // so it can take some time to load.
                    ShowFullScreenLoading();
                }

                // See if we are targeting a comment
                if (arguments.ContainsKey(PanelManager.NAV_ARGS_FORCE_COMMENT_ID))
                {
                    m_targetComment = (string)arguments[PanelManager.NAV_ARGS_FORCE_COMMENT_ID];
                }

                // Get the collector and register for updates.
                m_collector = SubredditCollector.GetCollector(m_subreddit, App.BaconMan, m_currentSort, forcePostId);
                m_collector.OnCollectionUpdated += Collector_OnCollectionUpdated;

                // Kick off an update of the subreddits if needed.
                m_collector.Update();

                // Set any posts that exist right now
                UpdatePosts(0, m_collector.GetCurrentPosts());

                // Set the command bar
                m_host.OnScreenModeChanged += OnScreenModeChanged;
            });
        }
Exemple #5
0
        public void SetupPage(Subreddit subreddit, SortTypes sortType)
        {
            // Capture the subreddit
            m_subreddit = subreddit;

            // Get the sort type
            SetCurrentSort(sortType);

            // Get the collector and register for updates.
            m_collector = SubredditCollector.GetCollector(m_subreddit, App.BaconMan, m_currentSortType);
            m_collector.OnCollectorStateChange += Collector_OnCollectorStateChange;
            m_collector.OnCollectionUpdated += Collector_OnCollectionUpdated;

            // Kick off an update of the subreddits if needed.
            m_collector.Update(false, 30);

            // Set any posts that exist right now
            SetPosts(0, m_collector.GetCurrentPosts(), true);

            // Setup the UI with the name.
            ui_subredditName.Text = $"/r/{m_subreddit.DisplayName}";
        }
        /// <summary>
        /// Fired when the panel is being created.
        /// </summary>
        /// <param name="host">A reference to the host.</param>
        /// <param name="arguments">Arguments for the panel</param>
        public void PanelSetup(IPanelHost host, Dictionary<string, object> arguments)
        {
            // Capture the host
            m_host = host;

            // Check for the subreddit arg
            if (!arguments.ContainsKey(PanelManager.NAV_ARGS_SUBREDDIT_NAME))
            {
                throw new Exception("No subreddit was given!");
            }
            string subredditName = (string)arguments[PanelManager.NAV_ARGS_SUBREDDIT_NAME];

            // Kick off a background task to do the work
            Task.Run(async () =>
            {
                // Try to get the subreddit from the local cache.
                Subreddit subreddit = App.BaconMan.SubredditMan.GetSubredditByDisplayName(subredditName);

                // It is very rare that we can't get it from the cache because something
                // else usually request it from the web and then it will be cached.
                if (subreddit == null)
                {
                    // Since this can take some time, show the loading overlay
                    ShowFullScreenLoading();

                    // Try to get the subreddit from the web
                    subreddit = await App.BaconMan.SubredditMan.GetSubredditFromWebByDisplayName((string)arguments[PanelManager.NAV_ARGS_SUBREDDIT_NAME]);
                }

                // Check again.
                if (subreddit == null)
                {
                    // Hmmmm. We can't load the subreddit. Show a message and go back
                    App.BaconMan.MessageMan.ShowMessageSimple("Hmmm, That's Not Right", "We can't load this subreddit right now, check your Internet connection.");

                    // We need to wait some time until the transition animation is done or we can't go back.
                    // If we call GoBack while we are still navigating it will be ignored.
                    await Task.Delay(1000);

                    // Now try to go back.
                    await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                    {
                        m_host.GoBack();
                    });

                    // Get out of here.
                    return;
                }

                // Capture the subreddit
                m_subreddit = subreddit;

                // Get the current sort
                m_currentSort = arguments.ContainsKey(PanelManager.NAV_ARGS_SUBREDDIT_SORT) ? (SortTypes)arguments[PanelManager.NAV_ARGS_SUBREDDIT_SORT] : SortTypes.Hot;

                // Try to get the target post id
                if (arguments.ContainsKey(PanelManager.NAV_ARGS_POST_ID))
                {
                    m_targetPost = (string)arguments[PanelManager.NAV_ARGS_POST_ID];
                }

                // Try to get the force post, this will make us show only one post for the subreddit,
                // which is the post given.
                string forcePostId = null;
                if (arguments.ContainsKey(PanelManager.NAV_ARGS_FORCE_POST_ID))
                {
                    forcePostId = (string)arguments[PanelManager.NAV_ARGS_FORCE_POST_ID];

                    // If the UI isn't already shown show the loading UI. Most of the time this post wont' be cached
                    // so it can take some time to load.
                    ShowFullScreenLoading();
                }

                // See if we are targeting a comment
                if (arguments.ContainsKey(PanelManager.NAV_ARGS_FORCE_COMMENT_ID))
                {
                    m_targetComment = (string)arguments[PanelManager.NAV_ARGS_FORCE_COMMENT_ID];
                }

                // Get the collector and register for updates.
                m_collector = SubredditCollector.GetCollector(m_subreddit, App.BaconMan, m_currentSort, forcePostId);
                m_collector.OnCollectionUpdated += Collector_OnCollectionUpdated;

                // Kick off an update of the subreddits if needed.
                m_collector.Update();

                // Set any posts that exist right now
                UpdatePosts(0, m_collector.GetCurrentPosts());

                // Set the command bar
                m_host.OnScreenModeChanged += OnScreenModeChanged;
            });
        }