Exemple #1
0
        public async Task <CurrentGame> GetCurrentGameInfo(int gameId)
        {
            try
            {
                var currentGame =
                    await Task.Run(() => api.GetCurrentGameAsync(Region.na, gameId)).ConfigureAwait(false);

                return(currentGame);
            }
            catch (RiotSharpException ex)
            {
                // Handle the exception however you want.
                await _logging.OnLogAsync(ex).ConfigureAwait(false);

                return(null);
            }
        }
        //Loads the current game if there is one
        public static async Task <ContentView> loadCurrentGameView(Summoner summoner, Region region)
        {
            var gameView = new ContentView();

            var currentTemplate = new DataTemplate(typeof(ImageCell));

            currentTemplate.SetBinding(TextCell.TextProperty, "Name");
            currentTemplate.SetBinding(ImageCell.ImageSourceProperty, "Icon");
            currentTemplate.SetBinding(TextCell.DetailProperty, "Rank");
            try
            {
                var currentGame = await api.GetCurrentGameAsync(PlatformToRegion(region), summoner.Id);

                var currentGameStack = new StackLayout();
                grouped = new ObservableCollection <GroupedSummoners>();
                var blueTeam = new GroupedSummoners {
                    LongName = "Blue Team", ShortName = "B"
                };
                var redTeam = new GroupedSummoners {
                    LongName = "Red Team", ShortName = "R"
                };

                var list   = new ListView();
                var idList = new List <string>();
                summoners = new List <Summoner>();
                for (int i = 0; i < currentGame.Participants.Count; i++)
                {
                    idList.Add(currentGame.Participants[i].SummonerName);
                }
                summoners = await api.GetSummonersAsync(region, idList);

                for (int i = 0; i < currentGame.Participants.Count; i++)
                {
                    for (int j = 0; j < summoners.Count; j++)
                    {
                        if (currentGame.Participants[i].SummonerName == summoners[j].Name)
                        {
                            var champPlayed = await staticApi.GetChampionAsync(region, (int)currentGame.Participants[i].ChampionId, ChampionData.image);

                            try
                            {
                                allLeagues = await api.GetLeaguesAsync(region, new List <int> {
                                    (int)summoners[j].Id
                                });

                                ranked5v5League = allLeagues[summoners[j].Id].Single(x => x.Queue == Queue.RankedSolo5x5);
                                div             = ranked5v5League.Entries.Where(x => x.PlayerOrTeamId == summoners[j].Id.ToString()).Select(x => x.Division).Single();

                                if (currentGame.Participants[i].TeamId == 100)
                                {
                                    blueTeam.Add(new CurrentGamePlayers(summoners[j].Name, ranked5v5League.Tier + " " + div, (int)currentGame.Participants[i].ChampionId, champPlayed.Image.Full, summoners[i].Region));
                                }
                                else if (currentGame.Participants[i].TeamId == 200)
                                {
                                    redTeam.Add(new CurrentGamePlayers(summoners[j].Name, ranked5v5League.Tier + " " + div, (int)currentGame.Participants[i].ChampionId, champPlayed.Image.Full, summoners[i].Region));
                                }
                            }
                            catch
                            {
                                if (currentGame.Participants[i].TeamId == 100)
                                {
                                    blueTeam.Add(new CurrentGamePlayers(summoners[j].Name, "Level " + summoners[i].Level, (int)currentGame.Participants[i].ChampionId, champPlayed.Image.Full, summoners[i].Region));
                                }
                                else if (currentGame.Participants[i].TeamId == 200)
                                {
                                    redTeam.Add(new CurrentGamePlayers(summoners[j].Name, "Level " + summoners[i].Level, (int)currentGame.Participants[i].ChampionId, champPlayed.Image.Full, summoners[i].Region));
                                }
                            }
                        }
                    }
                }
                grouped.Add(blueTeam);
                grouped.Add(redTeam);

                list.ItemsSource         = grouped;
                list.IsGroupingEnabled   = true;
                list.GroupDisplayBinding = new Binding("LongName");
                list.ItemTemplate        = currentTemplate;

                list.ItemTapped += async(object sender, ItemTappedEventArgs e) =>
                {
                    icon = iconReset;
                    var myListView = (ListView)sender;
                    var myItem     = (CurrentGamePlayers)myListView.SelectedItem;
                    try
                    {
                        UserDialogs.Instance.ShowLoading("Loading " + myItem.Name, MaskType.Black);
                        var summonerAsync = await api.GetSummonerAsync(myItem.Region, myItem.Name);

                        var page = SearchPage.Navigation.NavigationStack.Last();
                        var test = await loadPage(summonerAsync, myItem.Region, SearchPage);

                        UserDialogs.Instance.HideLoading();
                        await SearchPage.Navigation.PushAsync(test);

                        SearchPage.Navigation.RemovePage(page);
                    }
                    catch
                    {
                        UserDialogs.Instance.Alert("Whoops", "Something went wrong", "Okay");
                    }
                };
                currentGameStack.Children.Add(
                    new Label {
                    Text = currentGame.GameMode.ToString()
                }
                    );
                currentGameStack.Children.Add(list);
                gameView.Content = currentGameStack;
            }
            catch
            {
                gameView.Content = new Label {
                    Text = summoner.Name + " is not in an active game. Please try again later if the summoner is currently in game."
                };
            }

            gameView.HeightRequest = 425;
            return(gameView);
        }