//Loads the current game if there is one
        public static async Task <ContentView> loadCurrentGameView(Summoner summoner, Region region, Page SearchPage)
        {
            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(App.PlatformToRegion(region), summoner.Id);

                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, new List <ChampionData> {
                                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.Icon,
                                                                        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.Icon,
                                                                       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.Icon,
                                                                        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.Icon,
                                                                       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) =>
                {
                    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 = new SearchedSummonerPage(summonerAsync, myItem.Region);
                        UserDialogs.Instance.HideLoading();
                        await SearchPage.Navigation.PushAsync(test);

                        SearchPage.Navigation.RemovePage(page);
                    }
                    catch
                    {
                        UserDialogs.Instance.Alert("Whoops", "Something went wrong", "Okay");
                    }
                };
                if (!DependencyService.Get <ISaveAndLoad>().FileExists("haveyou"))
                {
                    var adView = new AdMobView {
                        WidthRequest = 320, HeightRequest = 50
                    };
                    list.Header = adView;
                }
                gameView.Content = list;
            }
            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."
                };
            }
            return(gameView);
        }
Esempio n. 2
0
        public SearchTabPage()
        {
            searchBar = new CustomSearchBar {
                Placeholder = "Search Summoner"
            };

            searchBar.SearchButtonPressed += async(sender, e) =>
            {
                string searchText = searchBar.Text.Replace(" ", "");
                searchBar.Text = "";
                searchBar.Unfocus();
                try
                {
                    UserDialogs.Instance.ShowLoading("Loading", MaskType.Black);
                    var summoner = await App.api.GetSummonerAsync(region, searchText);

                    icon = string.Format(icon, summoner.Region, summoner.Id);
                    var test = new SearchedSummonerPage(summoner, summoner.Region);
                    UserDialogs.Instance.HideLoading();
                    await Navigation.PushAsync(test);
                }
                catch
                {
                    UserDialogs.Instance.HideLoading();
                    await UserDialogs.Instance.AlertAsync("Try again", "Summoner not found!", "Okay");
                }
            };

            picker       = new Picker();
            picker.Title = "Region";

            picker.Items.Add(Region.euw.ToString().ToUpper());
            picker.Items.Add(Region.eune.ToString().ToUpper());
            picker.Items.Add(Region.na.ToString().ToUpper());
            picker.Items.Add(Region.kr.ToString().ToUpper());
            picker.Items.Add(Region.br.ToString().ToUpper());
            picker.Items.Add(Region.lan.ToString().ToUpper());
            picker.Items.Add(Region.las.ToString().ToUpper());
            picker.Items.Add(Region.oce.ToString().ToUpper());
            picker.Items.Add(Region.ru.ToString().ToUpper());
            picker.Items.Add(Region.tr.ToString().ToUpper());

            picker.SelectedIndex = 0;

            picker.SelectedIndexChanged += (sender, args) =>
            {
                switch (picker.SelectedIndex)
                {
                case 0:
                    region = Region.euw;
                    break;

                case 1:
                    region = Region.eune;
                    break;

                case 2:
                    region = Region.na;
                    break;

                case 3:
                    region = Region.kr;
                    break;

                case 4:
                    region = Region.br;
                    break;

                case 5:
                    region = Region.lan;
                    break;

                case 6:
                    region = Region.las;
                    break;

                case 7:
                    region = Region.oce;
                    break;

                case 8:
                    region = Region.ru;
                    break;

                case 9:
                    region = Region.tr;
                    break;
                }
            };
            var adView = new AdMobView {
                WidthRequest = 320, HeightRequest = 50
            };

            Content = new StackLayout
            {
                Children =
                {
                    searchBar,
                    picker,
                    adView
                }
            };
        }
Esempio n. 3
0
        public ProfilePage(Summoner summoner, Region region)
        {
            InitializeComponent();
            search.IsVisible         = false;
            nameText.BackgroundColor = Color.FromRgba(0, 0, 0, 0.6);
            Title = "Profile";

            storeService = DependencyService.Get <ICredentialsService>();
            var logoutButton = new ToolbarItem {
                Text = "Logout", Priority = 1
            };
            var searchButton = new ToolbarItem {
                Text = "Search", Icon = "Search.png", Priority = 0
            };

            ToolbarItems.Add(logoutButton);
            ToolbarItems.Add(searchButton);

            logoutButton.Clicked += async(sender, e) =>
            {
                var logout = await UserDialogs.Instance.ConfirmAsync("", "Are you sure you want to Logout?", "Yes", "No");

                if (logout)
                {
                    if (storeService.DoCredentialsExist())
                    {
                        storeService.DeleteCredentials();
                        Application.Current.MainPage = new NavigationPage(new loginXaml());
                        await Navigation.PopToRootAsync();
                    }
                }
            };

            search.ScopeChanged += (sender, e) =>
            {
                searchRegion = App.regFromString(search.SelectedScopeText);
            };

            searchButton.Clicked += (sender, e) =>
            {
                if (search.IsFocused)
                {
                    search.Unfocus();
                    searchFilterControl.Unfocus();
                }
                else
                {
                    search.IsVisible = true;
                    search.Focus();
                }
            };

            search.SearchButtonPressed += async(sender, e) =>
            {
                string searchText = System.Net.WebUtility.HtmlEncode(search.Text);                 //search.Text.Replace(" ", "");
                search.Text = "";
                search.Unfocus();
                try
                {
                    UserDialogs.Instance.ShowLoading("Loading", MaskType.Black);
                    var searchedSummoner = await App.api.GetSummonerAsync(searchRegion, searchText);

                    icon = string.Format(icon, searchedSummoner.Region, searchedSummoner.Id);
                    var test = new SearchedSummonerPage(searchedSummoner, searchedSummoner.Region);
                    UserDialogs.Instance.HideLoading();
                    await Navigation.PushAsync(test);
                }
                catch
                {
                    UserDialogs.Instance.HideLoading();
                    await UserDialogs.Instance.AlertAsync("Try again", "Summoner not found!", "Okay");
                }
            };

            var task = Task.Run(async() =>
            {
                if (freqPlayedChamp.Source == null)
                {
                    GameList       = await api.GetRecentGamesAsync(region, summoner.Id);
                    var freqPlayed = GameList.GroupBy(q => q.ChampionId)
                                     .OrderByDescending(gp => gp.Count())
                                     .Select(g => g.Key)
                                     .First();
                    var championPlayedMost = await staticApi.GetChampionAsync(Reg, (int)freqPlayed, new List <ChampionData> {
                        ChampionData.skins
                    });
                    freqPlayedChamp.Source = new UriImageSource
                    {
                        Uri            = new Uri(string.Format(skinString, championPlayedMost.Key, championPlayedMost.Skins[0].Num)),
                        CachingEnabled = false
                    };
                    updated = true;
                }
            });

            task.Wait();


            search.Unfocused += (sender, e) =>
            {
                search.IsVisible = false;
            };

            Reg           = region;
            Summoner      = summoner;
            filterControl = new FilterControl {
                Items = new List <string> {
                    "Match History", "Ranked", "Current Game", "Champions"
                }
            };
            filterControl.SelectedIndex = 0;
            contentViewFilter.Content   = filterControl;
            //contentVue.VerticalOptions = LayoutOptions.FillAndExpand;

            nameText.Text = "\n\t\t  " + summoner.Name;

            summonerIcon.Source = new UriImageSource
            {
                Uri            = new Uri(string.Format(icon, region, summoner.Id)),
                CachingEnabled = true
            };

            switch (App.device.HardwareVersion)
            {
            case "iPhone SE":
            case "iPhone 5S":
            case "iPhone 5S GSM":
            case "iPhone 5S CDMA":
            case "iPhone 5":
            case "iPhone 5 GSM":
            case "iPhone 5 CDMA":
                contentVue.HeightRequest = 230;
                break;

            case "iPhone 6":
            case "iPhone 6S":
            case "iPhone 7":
                contentVue.HeightRequest = 330;
                break;

            case "iPhone 6+":
            case "iPhone 6s+":
            case "iPhone 6 Plus":
            case "iPhone 6S Plus":
            case "iPhone 7 Plus":
            case "iPhone 7+":
                contentVue.HeightRequest = 410;
                break;
            }
            try
            {
                allLeagues = api.GetLeagues(region, new List <int> {
                    (int)summoner.Id
                });
                ranked5v5League     = allLeagues[summoner.Id].Single(x => x.Queue == Queue.RankedSolo5x5);
                filterControl.Items = new List <string> {
                    "Match History", "Ranked", "Current Game"
                };
            }
            catch
            {
                filterControl.Items = new List <string> {
                    "Match History", "Current Game"
                };
            }

            filterControl.SelectedIndexChanged += async(object sender, EventArgs e) =>
            {
                UserDialogs.Instance.ShowLoading("Loading", MaskType.Black);
                try
                {
                    allLeagues = await api.GetLeaguesAsync(region, new List <int> {
                        (int)summoner.Id
                    });

                    ranked5v5League = allLeagues[summoner.Id].Single(x => x.Queue == Queue.RankedSolo5x5);

                    switch (filterControl.SelectedIndex)
                    {
                    case 0:
                        var MatchList = await loadMatchHistory(summoner, region, this);

                        contentVue.Content = MatchList;
                        UserDialogs.Instance.HideLoading();
                        break;

                    case 1:
                        var statsPage = await loadRanked(summoner, summoner.Region, this);

                        contentVue.Content = statsPage;
                        UserDialogs.Instance.HideLoading();
                        break;

                    case 2:
                        currentGameView = await loadCurrentGameView(summoner, summoner.Region, this);

                        contentVue.Content = currentGameView;
                        UserDialogs.Instance.HideLoading();
                        break;
                    }
                }
                catch
                {
                    switch (filterControl.SelectedIndex)
                    {
                    case 0:
                        var MatchList = await loadMatchHistory(summoner, region, this);

                        contentVue.Content = MatchList;
                        UserDialogs.Instance.HideLoading();
                        break;

                    case 1:
                        currentGameView = await loadCurrentGameView(summoner, summoner.Region, this);

                        contentVue.Content = currentGameView;
                        UserDialogs.Instance.HideLoading();
                        break;
                    }
                }
            };


            var soloRankString = "";
            var soloIcon       = "";
            var flexRankString = "";
            var flexIcon       = "";

            try
            {
                div = ranked5v5League.Entries.Where(x => x.PlayerOrTeamId == summoner.Id.ToString()).Select(x => x.Division).Single();
                var soloLP = ranked5v5League.Entries.FirstOrDefault(x => x.PlayerOrTeamName == summoner.Name).LeaguePoints;
                soloRankString = ranked5v5League.Tier + " " + div + " " + soloLP + "LP\nSolo Queue";

                switch (ranked5v5League.Tier)
                {
                case RiotSharp.LeagueEndpoint.Enums.Tier.Bronze:
                    soloIcon = "Bronze.png";
                    break;

                case RiotSharp.LeagueEndpoint.Enums.Tier.Silver:
                    soloIcon = "Silver.png";
                    break;

                case RiotSharp.LeagueEndpoint.Enums.Tier.Gold:
                    soloIcon = "Gold.png";
                    break;

                case RiotSharp.LeagueEndpoint.Enums.Tier.Platinum:
                    soloIcon = "Platinum.png";
                    break;

                case RiotSharp.LeagueEndpoint.Enums.Tier.Diamond:
                    soloIcon = "Diamond.png";
                    break;

                case RiotSharp.LeagueEndpoint.Enums.Tier.Master:
                    soloIcon = "Master.png";
                    break;

                case RiotSharp.LeagueEndpoint.Enums.Tier.Challenger:
                    soloIcon = "Challenger.png";
                    break;
                }
            }
            catch
            {
                soloRankString = "Unranked";
                soloIcon       = "Unranked.png";
            }
            try
            {
                rankedFlexLeague = allLeagues[summoner.Id].Single(x => x.Queue == Queue.RankedFlexSR);
                flexDiv          = rankedFlexLeague.Entries.Where(x => x.PlayerOrTeamId == summoner.Id.ToString()).Select(x => x.Division).Single();
                var flexLP = rankedFlexLeague.Entries.FirstOrDefault(x => x.PlayerOrTeamName == summoner.Name).LeaguePoints;
                flexRankString = rankedFlexLeague.Tier + " " + flexDiv + " " + flexLP + "LP\nFlex 5v5";

                switch (rankedFlexLeague.Tier)
                {
                case RiotSharp.LeagueEndpoint.Enums.Tier.Bronze:
                    flexIcon = "Bronze.png";
                    break;

                case RiotSharp.LeagueEndpoint.Enums.Tier.Silver:
                    flexIcon = "Silver.png";
                    break;

                case RiotSharp.LeagueEndpoint.Enums.Tier.Gold:
                    flexIcon = "Gold.png";
                    break;

                case RiotSharp.LeagueEndpoint.Enums.Tier.Platinum:
                    flexIcon = "Platinum.png";
                    break;

                case RiotSharp.LeagueEndpoint.Enums.Tier.Diamond:
                    flexIcon = "Diamond.png";
                    break;

                case RiotSharp.LeagueEndpoint.Enums.Tier.Master:
                    flexIcon = "Master.png";
                    break;

                case RiotSharp.LeagueEndpoint.Enums.Tier.Challenger:
                    flexIcon = "Challenger.png";
                    break;
                }
            }
            catch
            {
                flexRankString = "Unranked";
                flexIcon       = "Unranked.png";
            }

            var grid = new Grid
            {
                RowDefinitions =
                {
                    new RowDefinition {
                        Height = new GridLength(50, GridUnitType.Absolute)
                    }
                },
                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = new GridLength(50, GridUnitType.Absolute)
                    },
                    new ColumnDefinition {
                        Width = GridLength.Auto
                    },
                    new ColumnDefinition {
                        Width = new GridLength(50, GridUnitType.Absolute)
                    },
                    new ColumnDefinition {
                        Width = GridLength.Auto
                    },
                }
            };

            grid.Children.Add(new Image {
                Source = soloIcon
            }, 0, 0);
            grid.Children.Add(new Label {
                TextColor = Color.White, Text = soloRankString
            }, 1, 0);

            grid.Children.Add(new Image {
                Source = flexIcon
            }, 2, 0);
            grid.Children.Add(new Label {
                TextColor = Color.White, Text = flexRankString
            }, 3, 0);

            grid.BackgroundColor      = Color.FromRgba(0, 0, 0, 0.6);
            rankedImagesStuff.Content = grid;
        }