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}";
        }
        private void SetCurrentTimeSort(SortTimeTypes type)
        {
            m_currentSortTimeType = type;
            switch (type)
            {
            case SortTimeTypes.AllTime:
                ui_sortTimeText.Text = "All Time";
                break;

            case SortTimeTypes.Day:
                ui_sortTimeText.Text = "Past Day";
                break;

            case SortTimeTypes.Hour:
                ui_sortTimeText.Text = "Past Hour";
                break;

            case SortTimeTypes.Month:
                ui_sortTimeText.Text = "Past Month";
                break;

            case SortTimeTypes.Week:
                ui_sortTimeText.Text = "Past Week";
                break;

            case SortTimeTypes.Year:
                ui_sortTimeText.Text = "Past Year";
                break;
            }
        }
Esempio n. 3
0
        private void SetDefaultSortTimeType(SortTimeTypes type)
        {
            switch (type)
            {
            case SortTimeTypes.Hour:
                ui_defaultTimeSort.SelectedIndex = 0;
                break;

            case SortTimeTypes.Day:
                ui_defaultTimeSort.SelectedIndex = 1;
                break;

            case SortTimeTypes.Week:
                ui_defaultTimeSort.SelectedIndex = 2;
                break;

            case SortTimeTypes.Month:
                ui_defaultTimeSort.SelectedIndex = 3;
                break;

            case SortTimeTypes.Year:
                ui_defaultTimeSort.SelectedIndex = 4;
                break;

            case SortTimeTypes.AllTime:
                ui_defaultTimeSort.SelectedIndex = 5;
                break;
            }
        }
Esempio n. 4
0
        private void SetCurrentTimeSort(SortTimeTypes type)
        {
            _currentSortTimeType = type;
            switch (type)
            {
            case SortTimeTypes.AllTime:
                ui_sortTimeText.Text = "All Time";
                break;

            case SortTimeTypes.Day:
                ui_sortTimeText.Text = "Past Day";
                break;

            case SortTimeTypes.Hour:
                ui_sortTimeText.Text = "Past Hour";
                break;

            case SortTimeTypes.Month:
                ui_sortTimeText.Text = "Past Month";
                break;

            case SortTimeTypes.Week:
                ui_sortTimeText.Text = "Past Week";
                break;

            case SortTimeTypes.Year:
                ui_sortTimeText.Text = "Past Year";
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
        public async void PanelSetup(IPanelHost host, Dictionary <string, object> arguments)
        {
            // Capture the host
            m_host = host;

            Subreddit subreddit = null;

            if (arguments.ContainsKey(PanelManager.NAV_ARGS_SUBREDDIT_NAME))
            {
                // Try to get the subreddit locally
                subreddit = App.BaconMan.SubredditMan.GetSubredditByDisplayName((string)arguments[PanelManager.NAV_ARGS_SUBREDDIT_NAME]);

                // If that failed try to get it from the web
                if (subreddit == null)
                {
                    // Show the loading UI
                    ShowFullScreenLoading();

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

                    // Hide the loading UI
                    // The loading ring will be set inactive by the animation complete
                    HideFullScreenLoading();
                }
            }

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

                // We can't call go back with navigating, so use the dispatcher to make a delayed call.
                await Task.Run(async() =>
                {
                    // We need to wait some time until the transition animation is done or we can't go back.
                    await Task.Delay(500);

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

                // Get out of here.
                return;
            }

            // Get the sort type
            SortTypes     sortType     = arguments.ContainsKey(PanelManager.NAV_ARGS_SUBREDDIT_SORT) ? (SortTypes)arguments[PanelManager.NAV_ARGS_SUBREDDIT_SORT] : App.BaconMan.UiSettingsMan.SubredditList_DefaultSortType;
            SortTimeTypes postSortTime = arguments.ContainsKey(PanelManager.NAV_ARGS_SUBREDDIT_SORT_TIME) ? (SortTimeTypes)arguments[PanelManager.NAV_ARGS_SUBREDDIT_SORT_TIME] : App.BaconMan.UiSettingsMan.SubredditList_DefaultSortTimeType;

            // Do the rest of the setup
            SetupPage(subreddit, sortType, postSortTime);
        }
        /// <summary>
        /// Fired when a sort menu item is tapped.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SortTimeMenuItem_Click(object sender, RoutedEventArgs e)
        {
            // Get the new sort time
            MenuFlyoutItem item    = sender as MenuFlyoutItem;
            SortTimeTypes  newType = GetTimeSortFromString(item.Text);

            // Don't do anything if we already are.
            if (newType == m_currentSortTimeType)
            {
                return;
            }

            // Navigate to the new page
            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add(PanelManager.NAV_ARGS_SUBREDDIT_NAME, m_subreddit.DisplayName);
            args.Add(PanelManager.NAV_ARGS_SUBREDDIT_SORT, m_currentSortType);
            args.Add(PanelManager.NAV_ARGS_SUBREDDIT_SORT_TIME, newType);
            m_host.Navigate(typeof(SubredditPanel), m_subreddit.GetNavigationUniqueId(m_currentSortType, newType), args);
        }
        /// <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());
            });
        }
Esempio n. 8
0
        public PostCollector(PostCollectorContext collectorContext, BaconManager baconMan)
            : base(baconMan, collectorContext.UniqueId)
        {
            // Set the vars
            m_user         = collectorContext.User;
            m_subreddit    = collectorContext.subreddit;
            m_sortType     = collectorContext.sortType;
            m_sortTimeType = collectorContext.sortTimeType;
            m_baconMan     = baconMan;

            // If we are doing a top sort setup the sort time
            string optionalArgs = String.Empty;

            if (m_sortType == SortTypes.Top)
            {
                switch (m_sortTimeType)
                {
                case SortTimeTypes.AllTime:
                    optionalArgs = "sort=top&t=all";
                    break;

                case SortTimeTypes.Day:
                    optionalArgs = "sort=top&t=day";
                    break;

                case SortTimeTypes.Hour:
                    optionalArgs = "sort=top&t=hour";
                    break;

                case SortTimeTypes.Month:
                    optionalArgs = "sort=top&t=month";
                    break;

                case SortTimeTypes.Week:
                    optionalArgs = "sort=top&t=week";
                    break;

                case SortTimeTypes.Year:
                    optionalArgs = "sort=top&t=year";
                    break;
                }
            }

            string postCollectionUrl = "";
            bool   hasEmptyRoot      = false;


            if (m_subreddit != null)
            {
                if (m_subreddit.DisplayName.ToLower() == "frontpage")
                {
                    // Special case for the front page
                    postCollectionUrl = $"/{SortTypeToString(m_sortType)}/.json";
                }
                else if (m_subreddit.DisplayName.ToLower() == "saved")
                {
                    // Special case for the saved posts
                    postCollectionUrl = $"/user/{m_baconMan.UserMan.CurrentUser.Name}/saved/.json";
                }
                else if (!String.IsNullOrWhiteSpace(collectorContext.forcePostId))
                {
                    // We are only going to try to grab one specific post. This is used by search and inbox to
                    // link to a post. Since we are doing so, we need to make the unique id something unique for this post so we don't get
                    // a cache. This should match the unique id we use to look up the subreddit above.
                    SetUniqueId(m_subreddit.Id + m_sortType + collectorContext.forcePostId);
                    postCollectionUrl = $"/r/{m_subreddit.DisplayName}/comments/{collectorContext.forcePostId}/.json";
                    hasEmptyRoot      = true;
                }
                else
                {
                    postCollectionUrl = $"/r/{m_subreddit.DisplayName}/{SortTypeToString(m_sortType)}/.json";
                }
            }
            else
            {
                // Get posts for a user
                postCollectionUrl = $"user/{m_user.Name}/submitted/.json";

                switch (m_sortType)
                {
                case SortTypes.Controversial:
                    optionalArgs = "sort=controversial";
                    break;

                case SortTypes.Hot:
                    optionalArgs = "sort=hot";
                    break;

                case SortTypes.New:
                    optionalArgs = "sort=new";
                    break;

                case SortTypes.Top:
                    optionalArgs = "sort=top";
                    break;
                }
            }

            InitListHelper(postCollectionUrl, hasEmptyRoot, true, optionalArgs);
        }
Esempio n. 9
0
        /// <summary>
        /// Returns a collector for the given type. If the collector doesn't exist one will be created.
        /// </summary>
        /// <param name="subreddit"></param>
        /// <returns></returns>
        public static PostCollector GetCollector(User user, BaconManager baconMan, SortTypes sort = SortTypes.Hot, SortTimeTypes sortTime = SortTimeTypes.Week)
        {
            PostCollectorContext container = new PostCollectorContext()
            {
                User = user, sortType = sort, sortTimeType = sortTime
            };

            container.UniqueId = "t2_" + user.Id + sort + sortTime;
            return((PostCollector)Collector <Post> .GetCollector(typeof(PostCollector), container.UniqueId, container, baconMan));
        }
Esempio n. 10
0
        /// <summary>
        /// Returns a collector for the given type. If the collector doesn't exist one will be created.
        /// </summary>
        /// <param name="subreddit"></param>
        /// <returns></returns>
        public static PostCollector GetCollector(Subreddit subreddit, BaconManager baconMan, SortTypes sort = SortTypes.Hot, SortTimeTypes sortTime = SortTimeTypes.Week, string forcePostId = null)
        {
            PostCollectorContext container = new PostCollectorContext()
            {
                subreddit = subreddit, sortType = sort, forcePostId = forcePostId, sortTimeType = sortTime
            };

            // Make the uniqueId. If we have a force post add that also so we don't get an existing collector with the real subreddit.
            container.UniqueId = subreddit.Id + sort + sortTime + (String.IsNullOrWhiteSpace(forcePostId) ? String.Empty : forcePostId);
            return((PostCollector)Collector <Post> .GetCollector(typeof(PostCollector), container.UniqueId, container, baconMan));
        }
Esempio n. 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());
            });
        }
Esempio n. 12
0
 private void SetCurrentTimeSort(SortTimeTypes type)
 {
     m_currentSortTimeType = type;
     switch (type)
     {
         case SortTimeTypes.AllTime:
             ui_sortTimeText.Text = "All Time";
             break;
         case SortTimeTypes.Day:
             ui_sortTimeText.Text = "Past Day";
             break;
         case SortTimeTypes.Hour:
             ui_sortTimeText.Text = "Past Hour";
             break;
         case SortTimeTypes.Month:
             ui_sortTimeText.Text = "Past Month";
             break;
         case SortTimeTypes.Week:
             ui_sortTimeText.Text = "Past Week";
             break;
         case SortTimeTypes.Year:
             ui_sortTimeText.Text = "Past Year";
             break;
     }
 }
Esempio n. 13
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}";
        }
 private void SetDefaultSortTimeType(SortTimeTypes type)
 {
     switch (type)
     {
         case SortTimeTypes.Hour:
             ui_defaultTimeSort.SelectedIndex = 0;
             break;
         case SortTimeTypes.Day:
             ui_defaultTimeSort.SelectedIndex = 1;
             break;
         case SortTimeTypes.Week:
             ui_defaultTimeSort.SelectedIndex = 2;
             break;
         case SortTimeTypes.Month:
             ui_defaultTimeSort.SelectedIndex = 3;
             break;
         case SortTimeTypes.Year:
             ui_defaultTimeSort.SelectedIndex = 4;
             break;
         case SortTimeTypes.AllTime:
             ui_defaultTimeSort.SelectedIndex = 5;
             break;
     }
 }
Esempio n. 15
0
 public string GetNavigationUniqueId(SortTypes type, SortTimeTypes sortType)
 {
     return DisplayName + type + sortType;
 }
Esempio n. 16
0
 /// <summary>
 /// Generate an identifier for this subreddit with a particular sorting.
 /// </summary>
 /// <param name="type">The sorting this identifier should uniquely identify.</param>
 /// <param name="sortType">How recent a post could have been posted to be included in the sorting.</param>
 /// <returns>An ID that uniquely identifies a subreddit and a sorting.</returns>
 public string GetNavigationUniqueId(SortTypes type, SortTimeTypes sortType)
 {
     return(DisplayName + type + sortType);
 }