//Loads the match history
        public static async Task <ListView> loadMatchHistory(Summoner summoner, Region region)
        {
            var allItems = await staticApi.GetItemsAsync(region, ItemData.image);

            var allSummonerSpells = await staticApi.GetSummonerSpellsAsync(region, SummonerSpellData.image);

            var previousMatches = await summoner.GetRecentGamesAsync();

            var previousAll = new List <Previous>();

            for (int i = 0; i < previousMatches.Count; i++)
            {
                var gameType    = gameTypeName(previousMatches[i].GameSubType);
                var champPlayed = await staticApi.GetChampionAsync(region, previousMatches[i].ChampionId, ChampionData.image);

                var summonerSpellList = new List <string>
                {
                    allSummonerSpells.SummonerSpells.FirstOrDefault(y => y.Value.Id == previousMatches[i].SummonerSpell1).Value.Image.Full,
                    allSummonerSpells.SummonerSpells.FirstOrDefault(y => y.Value.Id == previousMatches[i].SummonerSpell2).Value.Image.Full
                };
                var itemList = new List <ItemStatic>
                {
                    allItems.Items.FirstOrDefault((x) => x.Value.Id == previousMatches[i].Statistics.Item0).Value,
                    allItems.Items.FirstOrDefault((x) => x.Value.Id == previousMatches[i].Statistics.Item1).Value,
                    allItems.Items.FirstOrDefault((x) => x.Value.Id == previousMatches[i].Statistics.Item2).Value,
                    allItems.Items.FirstOrDefault((x) => x.Value.Id == previousMatches[i].Statistics.Item3).Value,
                    allItems.Items.FirstOrDefault((x) => x.Value.Id == previousMatches[i].Statistics.Item4).Value,
                    allItems.Items.FirstOrDefault((x) => x.Value.Id == previousMatches[i].Statistics.Item5).Value,
                    allItems.Items.FirstOrDefault((x) => x.Value.Id == previousMatches[i].Statistics.Item6).Value
                };
                var itemNameList = new List <string>();
                for (int j = 0; j < itemList.Count; j++)
                {
                    if (itemList[j] != null)
                    {
                        itemNameList.Add(itemList[j].Image.Full);
                    }
                    else
                    {
                        itemNameList.Add("Empty.png");
                    }
                }

                var prev = new Previous(
                    gameType,
                    previousMatches[i].Level,
                    previousMatches[i].Statistics.Win,
                    FormatNumber(previousMatches[i].Statistics.GoldEarned),
                    previousMatches[i].Statistics.MinionsKilled.ToString(),
                    itemNameList,
                    summonerSpellList,
                    champPlayed.Image.Full,
                    previousMatches[i].CreateDate.ToString("g"),
                    previousMatches[i].Statistics.ChampionsKilled + "/" + previousMatches[i].Statistics.NumDeaths + "/" + previousMatches[i].Statistics.Assists,
                    previousMatches[i]
                    );
                previousAll.Add(prev);
            }

            var imageTemplate = new DataTemplate(typeof(PreviousGameCell));

            var MatchList = new ListView
            {
                ItemTemplate  = imageTemplate,
                ItemsSource   = previousAll,
                HasUnevenRows = true
            };

            MatchList.ItemTapped += async(object sender, ItemTappedEventArgs e) =>
            {
                var myListView = (ListView)sender;
                var myItem     = (Previous)myListView.SelectedItem;
                UserDialogs.Instance.ShowLoading("Loading Game", MaskType.Black);
                try
                {
                    Debug.WriteLine(myItem.ThisGame.GameId);
                    await Task.Delay(1000);

                    var match = await api.GetMatchAsync(region, myItem.ThisGame.GameId);

                    var previousPage = await PreviousGamePage.loadPrevious(match, myItem.ThisGame, region, summoner, myItem.ThisGame.FellowPlayers);

                    UserDialogs.Instance.HideLoading();
                    await SearchPage.Navigation.PushAsync(previousPage);
                }
                catch (Exception ex)
                {
                    UserDialogs.Instance.HideLoading();
                    Debug.WriteLine(ex);
                    await UserDialogs.Instance.AlertAsync("Are you connected to the internet?\nTry again", "An Error Occured", "Okay");
                }
            };

            return(MatchList);
        }
        public static async Task <ListView> loadMatchHistory(Summoner summoner, Region region, Page SearchPage)
        {
            var allItems          = App.itemList;
            var allSummonerSpells = App.summonerSpellList;

            var previousMatches = await summoner.GetRecentGamesAsync();

            var previousAll = new List <Previous>();

            for (int i = 0; i < previousMatches.Count; i++)
            {
                var gameType          = App.gameTypeName(previousMatches[i].GameSubType);
                var champPlayed       = App.championList.First(c => c.Id == previousMatches[i].ChampionId);
                var summonerSpellList = new List <UriImageSource>
                {
                    allSummonerSpells.FirstOrDefault(y => y.Id == previousMatches[i].SummonerSpell1).Icon,
                    allSummonerSpells.FirstOrDefault(y => y.Id == previousMatches[i].SummonerSpell2).Icon
                };
                var itemList = new List <ItemStatic>
                {
                    allItems.FirstOrDefault((x) => x.Id == previousMatches[i].Statistics.Item0),
                    allItems.FirstOrDefault((x) => x.Id == previousMatches[i].Statistics.Item1),
                    allItems.FirstOrDefault((x) => x.Id == previousMatches[i].Statistics.Item2),
                    allItems.FirstOrDefault((x) => x.Id == previousMatches[i].Statistics.Item3),
                    allItems.FirstOrDefault((x) => x.Id == previousMatches[i].Statistics.Item4),
                    allItems.FirstOrDefault((x) => x.Id == previousMatches[i].Statistics.Item5),
                    allItems.FirstOrDefault((x) => x.Id == previousMatches[i].Statistics.Item6)
                };
                var itemNameList = new List <UriImageSource>();
                for (int j = 0; j < itemList.Count; j++)
                {
                    if (itemList[j] != null)
                    {
                        itemNameList.Add(itemList[j].Icon);
                    }
                    else
                    {
                        itemNameList.Add(App.emptyIcon);
                    }
                }

                var prev = new Previous(
                    gameType,
                    previousMatches[i].Level,
                    previousMatches[i].Statistics.Win,
                    App.FormatNumber(previousMatches[i].Statistics.GoldEarned),
                    previousMatches[i].Statistics.MinionsKilled.ToString(),
                    itemNameList,
                    summonerSpellList,
                    champPlayed.Icon,
                    previousMatches[i].CreateDate.ToString("g"),
                    previousMatches[i].Statistics.ChampionsKilled + "/" + previousMatches[i].Statistics.NumDeaths + "/" + previousMatches[i].Statistics.Assists,
                    previousMatches[i]
                    );
                previousAll.Add(prev);
            }

            var imageTemplate = new DataTemplate(typeof(PreviousGameCell));
            var listView      = new ListView
            {
                ItemTemplate  = imageTemplate,
                HasUnevenRows = true,
                ItemsSource   = previousAll
            };

            listView.ItemTapped += async(object sender, ItemTappedEventArgs e) =>
            {
                var myListView = (ListView)sender;
                var myItem     = (Previous)myListView.SelectedItem;
                UserDialogs.Instance.ShowLoading("Loading Game", MaskType.Black);
                try
                {
                    Debug.WriteLine(myItem.ThisGame.GameId);
                    var match = await api.GetMatchAsync(Region, myItem.ThisGame.GameId);

                    var previousPage = await PreviousGamePage.loadPrevious(match, myItem.ThisGame, Region, Summoner, myItem.ThisGame.FellowPlayers);

                    UserDialogs.Instance.HideLoading();
                    await SearchPage.Navigation.PushAsync(previousPage);
                }
                catch (Exception ex)
                {
                    UserDialogs.Instance.HideLoading();
                    Debug.WriteLine(ex);
                    await UserDialogs.Instance.AlertAsync("Are you connected to the internet?\nTry again", "An Error Occured", "Okay");
                }
            };
            if (!DependencyService.Get <ISaveAndLoad>().FileExists("haveyou"))
            {
                var adView = new AdMobView {
                    WidthRequest = 320, HeightRequest = 50
                };
                listView.Header = adView;
            }
            return(listView);
        }