/// <summary>
        /// Called when we should get the trending subs
        /// </summary>
        /// <param name="count"></param>
        public void GetTrendingSubreddits()
        {
            // Check to see if we should update.
            DateTime now = DateTime.Now;

            if (LastTrendingSubs.Count == 0 || now.Day != LastUpdate.Day || now.Month != LastUpdate.Month)
            {
                // Make the subreddit
                Subreddit trendingSub = new Subreddit()
                {
                    DisplayName       = "trendingsubreddits",
                    Id                = "311a2",
                    Title             = "Trending Subreddits",
                    PublicDescription = "Trending Subreddits",
                };

                // Get the collector
                m_collector = PostCollector.GetCollector(trendingSub, m_baconMan, SortTypes.New);
                m_collector.OnCollectionUpdated    += Collector_OnCollectionUpdated;
                m_collector.OnCollectorStateChange += Collector_OnCollectorStateChange;

                // Force an update, get only one story.
                m_collector.Update(true, 1);
            }
            else
            {
                // If not just fire the event now with the cached subs
                FireReadyEvent(LastTrendingSubs);
            }
        }
Example #2
0
 public FlipViewPostContext(IPanelHost host, PostCollector collector, Post post, string targetComment)
 {
     Post = post;
     Collector = collector;
     Host = host;
     TargetComment = targetComment;
 }
        public void SetupPage(Subreddit subreddit, SortTypes sortType, SortTimeTypes sortTimeType)
        {
            // Capture the subreddit
            m_subreddit = subreddit;

            // Get the sort type
            SetCurrentSort(sortType);

            // Set the time sort
            SetCurrentTimeSort(sortTimeType);

            // Get the collector and register for updates.
            m_collector = PostCollector.GetCollector(m_subreddit, App.BaconMan, m_currentSortType, m_currentSortTimeType);
            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}";
        }
 public FlipViewPostContext(IPanelHost host, PostCollector collector, Post post, string targetComment)
 {
     Post          = post;
     Collector     = collector;
     Host          = host;
     TargetComment = targetComment;
 }
        /// <summary>
        /// Called when we should get the trending subs
        /// </summary>
        public void GetTrendingSubreddits()
        {
            // Check to see if we should update.
            DateTime now = DateTime.Now;
            if(LastTrendingSubs.Count == 0 || now.Day != LastUpdate.Day || now.Month != LastUpdate.Month)
            {
                // Make the subreddit
                Subreddit trendingSub = new Subreddit()
                {
                    DisplayName = "trendingsubreddits",
                    Id = "311a2",
                    Title = "Trending Subreddits",
                    PublicDescription = "Trending Subreddits",
                };

                // Get the collector
                m_collector = PostCollector.GetCollector(trendingSub, m_baconMan, SortTypes.New);
                m_collector.OnCollectionUpdated += Collector_OnCollectionUpdated;
                m_collector.OnCollectorStateChange += Collector_OnCollectorStateChange;

                // Force an update, get only one story.
                m_collector.Update(true, 1);
            }
            else
            {
                // If not just fire the event now with the cached subs
                FireReadyEvent(LastTrendingSubs);
            }
        }
        /// <summary>
        /// This will kick off the process of getting the stories for a subreddit.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        private void GetSubredditStories(string name, UpdateTypes type)
        {
            // Create a fake subreddit, the ID needs to be unique
            Subreddit subreddit = new Subreddit()
            {
                Id = DateTime.Now.Ticks.ToString(), DisplayName = name
            };

            // Get the collector for the subreddit
            PostCollector collector = PostCollector.GetCollector(subreddit, m_baconMan);

            // Sub to the collector callback
            if (type == UpdateTypes.LockScreen)
            {
                collector.OnCollectionUpdated    += Collector_OnCollectionUpdatedLockScreen;
                collector.OnCollectorStateChange += Collector_OnCollectorStateChangeLockScreen;
            }
            else if (type == UpdateTypes.Band)
            {
                collector.OnCollectionUpdated    += Collector_OnCollectionUpdatedBand;
                collector.OnCollectorStateChange += Collector_OnCollectorStateChangeBand;
            }
            else
            {
                collector.OnCollectionUpdated    += Collector_OnCollectionUpdatedDesktop;
                collector.OnCollectorStateChange += Collector_OnCollectorStateChangeDesktop;
            }

            // Kick off the update
            collector.Update(true);
        }
Example #7
0
        /// <summary>
        /// Ensures a post collector has been made
        /// </summary>
        public void EnsurePostCollector(bool makeNew = false)
        {
            lock (this)
            {
                if (makeNew && _mPostCollector != null)
                {
                    _mPostCollector.OnCollectionUpdated    -= PostCollector_OnCollectionUpdated;
                    _mPostCollector.OnCollectorStateChange -= PostCollector_OnCollectorStateChange;
                    _mPostCollector = null;
                }

                if (_mPostCollector == null)
                {
                    _mPostCollector = PostCollector.GetCollector(_mUser, App.BaconMan, _mPostSort);
                    _mPostCollector.OnCollectionUpdated    += PostCollector_OnCollectionUpdated;
                    _mPostCollector.OnCollectorStateChange += PostCollector_OnCollectorStateChange;
                }
            }
        }
Example #8
0
        public void OnCleanupPanel()
        {
            lock (this)
            {
                if (_mPostCollector != null)
                {
                    _mPostCollector.OnCollectionUpdated    -= PostCollector_OnCollectionUpdated;
                    _mPostCollector.OnCollectorStateChange -= PostCollector_OnCollectorStateChange;
                    _mPostCollector = null;
                }

                if (_mCommentCollector != null)
                {
                    _mCommentCollector.OnCollectionUpdated    -= CommentCollector_OnCollectionUpdated;
                    _mCommentCollector.OnCollectorStateChange -= CommentCollector_OnCollectorStateChange;
                    _mCommentCollector = null;
                }
            }
        }
        /// <summary>
        /// This will kick off the process of getting the stories for a subreddit.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        private void GetSubredditStories(string name, UpdateTypes type)
        {
            // Create a fake subreddit, the ID needs to be unique
            var subreddit = new Subreddit {
                Id = DateTime.Now.Ticks.ToString(), DisplayName = name
            };

            // Get the collector for the subreddit
            var collector = PostCollector.GetCollector(subreddit, _baconMan);

            switch (type)
            {
            // Sub to the collector callback
            case UpdateTypes.LockScreen:
                collector.OnCollectionUpdated    += Collector_OnCollectionUpdatedLockScreen;
                collector.OnCollectorStateChange += Collector_OnCollectorStateChangeLockScreen;
                break;

            case UpdateTypes.Band:
                collector.OnCollectionUpdated    += Collector_OnCollectionUpdatedBand;
                collector.OnCollectorStateChange += Collector_OnCollectorStateChangeBand;
                break;

            case UpdateTypes.All:
                break;

            case UpdateTypes.Desktop:
                break;

            default:
                collector.OnCollectionUpdated    += Collector_OnCollectionUpdatedDesktop;
                collector.OnCollectorStateChange += Collector_OnCollectorStateChangeDesktop;
                break;
            }

            // Kick off the update
            collector.Update(true);
        }
        /// <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;

                // Get the current sort time
                m_currentSortTime = arguments.ContainsKey(PanelManager.NAV_ARGS_SUBREDDIT_SORT_TIME) ? (SortTimeTypes)arguments[PanelManager.NAV_ARGS_SUBREDDIT_SORT_TIME] : SortTimeTypes.Week;

                // 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 = PostCollector.GetCollector(m_subreddit, App.BaconMan, m_currentSort, m_currentSortTime, 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());
            });
        }
Example #11
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
            _host = host;

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

            // Kick off a background task to do the work
            Task.Run(async() =>
            {
                // Try to get the subreddit from the local cache.
                var 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.NavArgsSubredditName]);
                }

                // 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, () =>
                    {
                        _host.GoBack();
                    });

                    // Get out of here.
                    return;
                }

                // Capture the subreddit
                _subreddit = subreddit;

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

                // Get the current sort time
                _currentSortTime = arguments.ContainsKey(PanelManager.NavArgsSubredditSortTime) ? (SortTimeTypes)arguments[PanelManager.NavArgsSubredditSortTime] : SortTimeTypes.Week;

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

                // 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.NavArgsForcePostId))
                {
                    forcePostId = (string)arguments[PanelManager.NavArgsForcePostId];

                    // 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.NavArgsForceCommentId))
                {
                    _targetComment = (string)arguments[PanelManager.NavArgsForceCommentId];
                }

                // Get the collector and register for updates.
                _collector = PostCollector.GetCollector(_subreddit, App.BaconMan, _currentSort, _currentSortTime, forcePostId);
                _collector.OnCollectionUpdated += Collector_OnCollectionUpdated;

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

                // Set any posts that exist right now
                UpdatePosts(0, _collector.GetCurrentPosts());
            });
        }
Example #12
0
        public void SetupPage(Subreddit subreddit, SortTypes sortType, SortTimeTypes sortTimeType)
        {
            // Capture the subreddit
            m_subreddit = subreddit;

            // Get the sort type
            SetCurrentSort(sortType);

            // Set the time sort
            SetCurrentTimeSort(sortTimeType);

            // Get the collector and register for updates.
            m_collector = PostCollector.GetCollector(m_subreddit, App.BaconMan, m_currentSortType, m_currentSortTimeType);
            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>
        /// Ensures a post collector has been made
        /// </summary>
        public void EnsurePostCollector(bool makeNew = false)
        {
            lock (this)
            {
                if(makeNew && m_postCollector != null)
                {
                    m_postCollector.OnCollectionUpdated -= PostCollector_OnCollectionUpdated;
                    m_postCollector.OnCollectorStateChange -= PostCollector_OnCollectorStateChange;
                    m_postCollector = null;
                }

                if (m_postCollector == null)
                {
                    m_postCollector = PostCollector.GetCollector(m_user, App.BaconMan, m_postSort);
                    m_postCollector.OnCollectionUpdated += PostCollector_OnCollectionUpdated;
                    m_postCollector.OnCollectorStateChange += PostCollector_OnCollectorStateChange;
                }
            }
        }
        public void OnCleanupPanel()
        {
            lock (this)
            {
                if (m_postCollector != null)
                {
                    m_postCollector.OnCollectionUpdated -= PostCollector_OnCollectionUpdated;
                    m_postCollector.OnCollectorStateChange -= PostCollector_OnCollectorStateChange;
                    m_postCollector = null;
                }

                if (m_commentCollector != null)
                {
                    m_commentCollector.OnCollectionUpdated -= CommentCollector_OnCollectionUpdated;
                    m_commentCollector.OnCollectorStateChange -= CommentCollector_OnCollectorStateChange;
                    m_commentCollector = null;
                }
            }
        }
Example #15
0
 public FlipViewPostItem(IPanelHost host, PostCollector collector, Post post, string targetComment)
 {
     Context   = new FlipViewPostContext(host, collector, post, targetComment);
     IsVisible = false;
 }
Example #16
0
 public FlipViewPostItem(IPanelHost host, PostCollector collector, Post post, string targetComment)
 {
     Context = new FlipViewPostContext(host, collector, post, targetComment);
     IsVisible = false;
 }