/// <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; }
private async void OnPropertyChanged(DependencyObject d, DependencyProperty prop) { if (prop == GameIdProperty) { firstbutton = true; //Just to be safe if ever the control is recycled if (LocalState.SupportedGames.ContainsKey(GameId)) { // Get game var game = LocalState.SupportedGames[GameId]; // Show Game basic details GameName.Text = game.Name; if (game.Developers != null && game.Developers.Count > 0) { DevName.Text = "by " + string.Join(",", game.Developers); DevName.Visibility = Visibility.Visible; } else { DevName.Visibility = Visibility.Collapsed; } // Show Game Icon if (!string.IsNullOrEmpty(game.Icon)) { GameIcon.Source = new BitmapImage(new Uri("https://cdn.discordapp.com/game-assets/" + game.Id + "/" + game.Icon + ".png")); GameIcon.Visibility = Visibility.Visible; } else { GameIcon.Visibility = Visibility.Collapsed; } // Show game splash if (!string.IsNullOrEmpty(game.Splash)) { SetupComposition(new Uri("https://cdn.discordapp.com/game-assets/" + game.Id + "/" + game.Splash + ".png?size=1024")); } // Summary if (!string.IsNullOrEmpty(game.Summary)) { GameDescription.Text = game.Summary; GameDescription.Visibility = Visibility.Visible; } else { GameDescription.Visibility = Visibility.Collapsed; } // Launch buttons if (game.DistributorGames != null) { foreach (var distributor in game.DistributorGames) { if (distributor.Distributor == "steam") { if (!string.IsNullOrEmpty(distributor.Sku)) { AddDistributorButton("Launch with Steam", "steam://run/" + distributor.Sku); } } else if (distributor.Distributor == "battlenet") { if (!string.IsNullOrEmpty(distributor.Sku)) { AddDistributorButton("Launch with Battlenet", "battlenet://" + distributor.Sku); } } else if (distributor.Distributor == "uplay") { if (!string.IsNullOrEmpty(distributor.Sku)) { AddDistributorButton("Launch with Uplay", "uplay://launch/" + distributor.Sku + "/0"); } } else if (distributor.Distributor == "origin") { if (!string.IsNullOrEmpty(distributor.Sku)) { AddDistributorButton("Open in Origin", "origin2://game/launch/?offerIds=0&title=" + Uri.EscapeUriString(game.Name)); } } } } // Game News try { var gamenews = await RESTCalls.GetGameNews(new string[] { game.Id }); if (gamenews != null && gamenews.Count > 0) { NewsFeed.Visibility = Visibility.Visible; for (var i = 0; i < Math.Min(gamenews.Count, 6); i++) { NewsFeed.Items.Insert(0, gamenews[i]); } NewsFeed.SelectedIndex = 0; } else { NewsFeed.Visibility = Visibility.Collapsed; } } catch { NewsFeed.Visibility = Visibility.Visible; } } } }