Ejemplo n.º 1
0
        private async void TrendingSubsHelper_OnTrendingSubReady(object sender, TrendingSubsReadyEvent e)
        {
            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                // Loop through the results and add them to the UI.
                for (int i = 0; i < e.TrendingSubredditsDisplayNames.Count; i++)
                {
                    if (i > 4)
                    {
                        break;
                    }

                    switch (i)
                    {
                    case 0:
                        ui_trendingSubreddit1.Text = e.TrendingSubredditsDisplayNames[i];
                        break;

                    case 1:
                        ui_trendingSubreddit2.Text = e.TrendingSubredditsDisplayNames[i];
                        break;

                    case 2:
                        ui_trendingSubreddit3.Text = e.TrendingSubredditsDisplayNames[i];
                        break;

                    case 3:
                        ui_trendingSubreddit4.Text = e.TrendingSubredditsDisplayNames[i];
                        break;

                    default:
                    case 4:
                        ui_trendingSubreddit5.Text = e.TrendingSubredditsDisplayNames[i];
                        break;
                    }
                }
            });

            // Remove the callback
            m_trendingSubsHelper.OnTrendingSubReady -= TrendingSubsHelper_OnTrendingSubReady;

            // kill the object
            m_trendingSubsHelper = null;
        }
Ejemplo n.º 2
0
        /// <summary>
        ///  Updates the trending subreddits
        /// </summary>
        public void UpdateTrendingSubreddits()
        {
            // Kick off a thread so we dont use the Ui
            Task.Run(async() =>
            {
                // Make sure we don't already have one running.
                lock (this)
                {
                    if (m_trendingSubsHelper != null)
                    {
                        return;
                    }
                    m_trendingSubsHelper = new TrendingSubredditsHelper(App.BaconMan);
                }

                // Delay for a little while, give app time to process things it needs to.
                await Task.Delay(500);

                // Out side of the lock request an update
                m_trendingSubsHelper.OnTrendingSubReady += TrendingSubsHelper_OnTrendingSubReady;
                m_trendingSubsHelper.GetTrendingSubreddits();
            });
        }