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);
        }
Exemple #2
0
        private async void AnimWelcome_Completed(object sender, object e)
        {
            // Give it some screen time
            await Task.Delay(1000);

            if (m_isVisible)
            {
                // Tell the host to get us out of here.
                m_host.GoBack();
            }
        }
        /// <summary>
        /// This will ask the user if they want to leave the page now, save a draft, or discard.
        /// </summary>
        private async void PrmoptUserForBackout()
        {
            // Make a message to show the user
            bool?saveChanges = null;
            var  message     = new MessageDialog("It looks like you have a post in progress, what would you like to do with it? If you save a draft you can come back an pick up at anytime.", "Leaving So Fast?");

            message.Commands.Add(new UICommand(
                                     "Save a Draft",
                                     (IUICommand command) => { saveChanges = true; }));
            message.Commands.Add(new UICommand(
                                     "Discard Post",
                                     (IUICommand command) => { saveChanges = false; }));
            message.DefaultCommandIndex = 0;
            message.CancelCommandIndex  = 0;

            // Show the dialog
            await message.ShowAsync();

            // They hit cancel
            if (!saveChanges.HasValue)
            {
                return;
            }

            if (saveChanges.Value)
            {
                // They want to save and exit
                await SaveDraft();
            }
            else
            {
                // They want to discard changes and exit.
                DisableAutoSave();
                ClearDraft();
            }

            // Now go back
            _mHost.GoBack();
        }
        private async void ReportUserLoadFailed()
        {
            // Show a message
            App.BaconMan.MessageMan.ShowMessageSimple("Failed To Load", "Check your Internet connection.");

            // Report

            bool wentBack = false;

            do
            {
                // Try to go back
                wentBack = m_host.GoBack();

                // Wait for a bit and try again.
                await Task.Delay(100);
            }while (wentBack);
        }
        private async void ReportUserLoadFailed()
        {
            // Show a message
            App.BaconMan.MessageMan.ShowMessageSimple("Failed To Load", "Check your Internet connection.");

            // Report
            TelemetryManager.ReportEvent(this, "UserProfileFailedToLoad");

            var wentBack = false;

            do
            {
                // Try to go back
                wentBack = _mHost.GoBack();

                // Wait for a bit and try again.
                await Task.Delay(100);
            }while (wentBack);
        }
        /// <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());
            });
        }
Exemple #7
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());
            });
        }
        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 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);
        }