Example #1
0
        /// <summary>
        /// Load Activites panel
        /// </summary>
        public async void LoadFeed()
        {
            //Get feed settings
            LocalState.FeedSettings = await RESTCalls.GetFeedSettings();

            // Get activies
            var activities = await RESTCalls.GetActivites();

            // Id list of Relevant Activites
            List <string> relevantIds = new List <string>();
            // Actives actually in use by friends
            List <ActivityData> relevantActivities = new List <ActivityData>();

            // Determine relevant activites
            foreach (var activity in activities)
            {
                if (!ContainsString(LocalState.FeedSettings.UnsubscribedUsers, activity.UserId) || !ContainsString(LocalState.FeedSettings.UnsubscribedGames, activity.ApplicationId))
                {
                    relevantIds.Add(activity.ApplicationId);
                    relevantActivities.Add(activity);
                }
            }

            // Get news feed
            var gamenews = await RESTCalls.GetGameNews(relevantIds.ToArray());

            Dictionary <string, GameNews> heroNews = new Dictionary <string, GameNews>();

            if (gamenews != null)
            {
                var gnCount = gamenews.Count();

                foreach (var news in gamenews)
                {
                    //The GameNews list is ordered by game and then by timestamp, so the hero feed must be the last news of every game in the list
                    if (heroNews.ContainsKey(news.GameId))
                    {
                        heroNews[news.GameId] = news;
                    }
                    else
                    {
                        heroNews.Add(news.GameId, news);
                    }
                    if (!LocalState.GameNews.ContainsKey(news.GameId))
                    {
                        LocalState.GameNews.Add(news.GameId, new List <GameNews>());
                        LocalState.GameNews[news.GameId].Add(news);
                    }
                    else
                    {
                        LocalState.GameNews[news.GameId].Add(news);
                    }
                }
            }

            // Hero news list is the FlipView news
            var heroNewsList = new List <GameNews>();

            foreach (var value in heroNews)
            {
                heroNewsList.Add(value.Value);
            }
            heroNewsList.Sort((x, y) => DateTimeOffset.Compare(y.Timestamp, x.Timestamp));

            // Add top 4 more recent news items to the FlipView in reverse order
            for (var i = 0; i < Math.Min(heroNewsList.Count, 4); i++)
            {
                if (LocalState.SupportedGames.ContainsKey(heroNewsList[i].GameId))
                {
                    heroNewsList[i].GameTitle = LocalState.SupportedGames[heroNewsList[i].GameId].Name.ToUpper();
                }
                HeroFeed.Items.Insert(0, heroNewsList[i]);
            }

            // If empty, hide FlipView
            if (HeroFeed.Items.Count == 0)
            {
                HeroFeed.Visibility = Visibility.Collapsed;
            }
            else
            {
                HeroFeed.SelectedIndex = 0;
            }

            // Show activites
            Feed.ItemsSource = relevantActivities;
        }