public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> suspensionState) { id = (suspensionState.ContainsKey(nameof(id))) ? (long)suspensionState[nameof(id)] : (long)parameter; //TODO: Should be a way to optimize this so it isn't so slow to get tournament matches. Might need to do on manager level //1) Make this function, GetMatchesForTournament, asyncrhonous and give it a delegate as a parameter. The delegate will refer to //a function in this class that will update the value of Tournament.Matches so that it can be done after page load //2) Implement the cache so getting individual team profiles is much less taxing and doesn't require you to call the API twice for every match var pastMatches = tournamentManager.GetMatchesForTournament(id); var liveJsonMatches = tournamentManager.GetLiveTournamentGames().Where(t => t.Tournament.ID == id); ObservableCollection <MatchModel> matches = new ObservableCollection <MatchModel>(); ObservableCollection <MatchModel> liveMatches = new ObservableCollection <MatchModel>(); foreach (var match in liveJsonMatches) { liveMatches.Add(convertMatchToMatchModel(match, true)); } foreach (var match in pastMatches) { matches.Add(convertMatchToMatchModel(match, false)); } LiveMatches = liveMatches; Tournament = new TournamentModel() { ID = id, Name = liveJsonMatches.First().Tournament.Name, Matches = matches, }; //TODO: Disable whatever the loading gif you create await Task.CompletedTask; }
public LiveGamesPageViewModel() { //Used to easily display information in the xaml editor without launching the program if (Windows.ApplicationModel.DesignMode.DesignModeEnabled) { Tournaments = new List <TournamentModel> { new TournamentModel { ID = 4664, Name = "The International 2016", Matches = new ObservableCollection <MatchModel> { new MatchModel { ID = 2558534849, Radiant = new TeamModel { ID = 2163, Name = "Team Liquid", LogoURL = new Uri("http://riki.dotabuff.net/t/l/XNAr01Hbpm.png") }, Dire = new TeamModel { ID = 36, Name = "Natus Vincere", LogoURL = new Uri("http://riki.dotabuff.net/t/l/3QxyeKbMK6.png") }, }, new MatchModel { ID = 2551474091, Radiant = new TeamModel { ID = 2512249, Name = "Digital Chaos", LogoURL = new Uri("http://riki.dotabuff.net/t/l/pAwIGd6wVT.png") }, Dire = new TeamModel { ID = 2163, Name = "Team Liquid", LogoURL = new Uri("http://riki.dotabuff.net/t/l/XNAr01Hbpm.png") }, } } }, new TournamentModel { ID = 3781, Name = "The Summit 4", Matches = new ObservableCollection <MatchModel> { new MatchModel { ID = 1995989266, Radiant = new TeamModel { ID = 39, Name = "Evil Geniuses", LogoURL = new Uri("http://riki.dotabuff.net/t/l/aI2hxnL46H.png") }, Dire = new TeamModel { ID = 726228, Name = "Vici Gaming", LogoURL = new Uri("http://riki.dotabuff.net/t/l/2bR6gRR8zG.png") }, } } } }; } else { tournamentManager = new TournamentManager(); _Tournaments = new List <TournamentModel>(); var liveGames = tournamentManager.GetLiveTournamentGames(); var tournaments = liveGames.GroupBy(t => t.Tournament.ID); foreach (var tournament in tournaments) { var matches = new ObservableCollection <MatchModel>(); foreach (var match in tournament) { matches.Add(new MatchModel { ID = match.ID, Radiant = new TeamModel { ID = match.Radiant.OfficialTeam.ID, LogoURL = match.Radiant.OfficialTeam.LogoURL, Name = match.Radiant.OfficialTeam.Name, }, Dire = new TeamModel { ID = match.Dire.OfficialTeam.ID, LogoURL = match.Dire.OfficialTeam.LogoURL, Name = match.Dire.OfficialTeam.Name, } }); } _Tournaments.Add(new TournamentModel { ID = tournament.Key, Name = tournament.Select(t => t.Tournament.Name).First(), Matches = matches }); } } }