public async Task<List<CSMatchInfo_2>> ParseMatchTitle(MatchInfo matchInfo)
		{
			var matchInfo_2 = new MatchInfo_2 ();
			var listMatchDetail = new List<CSMatchInfo_2> ();
			TeamDb teamDb = new TeamDb ();
			CSMapDb mapDb = new CSMapDb ();
			LeagueDb leagDb = new LeagueDb ();
			var radiantWin = matchInfo.Winner;
			var team1 = await teamDb.GetTeam (matchInfo.Team1Id, "CSGO");
			var team2 = await teamDb.GetTeam (matchInfo.Team2Id, "CSGO");
			var leag = await leagDb.GetLeague (matchInfo.LeagueId, "CSGO");

			var csMatchDetail = matchInfo.DetailsMatch.Cast<CSMatchInfo> ().ToList ();
			foreach (var match in csMatchDetail) {
				var csMatchInfo_2 = new CSMatchInfo_2 ();
				csMatchInfo_2.Team1 = team1;
				csMatchInfo_2.Team2 = team2;
				csMatchInfo_2.DeteilScoreTeam1 = match.DeteilScoreTeam1;
				csMatchInfo_2.DeteilScoreTeam2 = match.DeteilScoreTeam2;
				csMatchInfo_2.Team1Score = match.Team1Score;
				csMatchInfo_2.Team2Score = match.Team2Score;
				csMatchInfo_2.StartTime = matchInfo.StartTime;
				csMatchInfo_2.Url = matchInfo.Url;
				csMatchInfo_2.Team1Win = matchInfo.Winner;
				csMatchInfo_2.MatchLeague = leag;
				csMatchInfo_2.Map = await mapDb.GetMap(match.CSMapId);
				listMatchDetail.Add (csMatchInfo_2);
			}


			return listMatchDetail;
		}
		public async Task<List<HSMatchInfo_2>> ParseMatchTitle(MatchInfo matchInfo)
		{
			var matchInfo_2 = new MatchInfo_2 ();
			var listMatchDetail = new List<HSMatchInfo_2> ();
			TeamDb teamDb = new TeamDb ();
			DeckOfCardsDb deck = new DeckOfCardsDb();
			LeagueDb leagDb = new LeagueDb ();
			var radiantWin = matchInfo.Winner;
			var team1 = await teamDb.GetTeam (matchInfo.Team1Id, "Hearthstone");
			var team2 = await teamDb.GetTeam (matchInfo.Team2Id, "Hearthstone");
			var leag = await leagDb.GetLeague (matchInfo.LeagueId, "Hearthstone");

			var hsMatchDetail = matchInfo.DetailsMatch.Cast<HSMatchInfo> ().ToList ();
			foreach (var match in hsMatchDetail) {
				var hsMatchInfo_2 = new HSMatchInfo_2 ();
				hsMatchInfo_2.Team1 = team1;
				hsMatchInfo_2.Team2 = team2;
				hsMatchInfo_2.Team1Score = match.Team1Score;
				hsMatchInfo_2.Team2Score = match.Team2Score;
				hsMatchInfo_2.StartTime = matchInfo.StartTime;
				hsMatchInfo_2.Url = matchInfo.Url;
				hsMatchInfo_2.Team1Win = matchInfo.Winner;
				hsMatchInfo_2.Team1Deck = await deck.GetDeckFromSQL (match.Team1Deck);
				hsMatchInfo_2.Team2Deck = await deck.GetDeckFromSQL (match.Team2Deck);
				hsMatchInfo_2.MatchLeague = leag;
				listMatchDetail.Add (hsMatchInfo_2);
			}


			return listMatchDetail;
		}
 		protected  override async void OnCreate (Bundle bundle)
		{
			try{
				base.OnCreate (bundle);
				SetContentView (Resource.Layout.LayoutMatchInfo);

				title=Intent.GetStringExtra("title");
				ActionBarTitle.SetTitle (this,Resource.Layout.ActionBarLayout,title,Resources.GetString (Resource.String.nameDota2));
				buttonRefresh=FindViewById<Button>(Resource.Id.buttonRefreshActionBar);
				buttonRefresh.Click+=ButtonRefreshClick;
				buttonRefresh.Visibility=ViewStates.Invisible;
				var buttonBack=FindViewById<Button>(Resource.Id.buttonBackActionBar);
				buttonBack.Click+=ButtonBackClick;
				//var rl=FindViewById<RelativeLayout>(Resource.Id.rlayout_match_info);
				//var buttonPickBan = rl.FindViewById<Button> (Resource.Id.button_picks_bans);
				//var rlTowersViews=FindViewById<RelativeLayout>(Resource.Id.towersState);
				Button buttonPickBan =FindViewById<Button> (Resource.Id.buttonBattle);
				buttonPickBan.Click += buttonPickBansClick;
				Button buttonGameStats = FindViewById<Button> (Resource.Id.buttonGameStats);
				buttonGameStats.Click += buttomGameStatsClick;
				pb=FindViewById<ProgressBar> (Resource.Id.progressBar3);
				pb.Visibility= ViewStates.Visible;
				APIRequest apiReq = new APIRequest ();
				int match_id=Convert.ToInt32( Intent.GetStringExtra("match_id"));
				var url =SettingsApp.ServerAPIAddress+SettingsApp.GameName+"/GetDetailInfo?match_id=" + match_id;
				var jMatchResponce = await apiReq.GetJsonAsync (url);
				gameInfo=jMatchResponce.ToString();
				var jDetailMatchInfo= JsonConvert.DeserializeObject<JDetailMatchInfo>(gameInfo);
				var jMatchDetails=JToken.Parse(jDetailMatchInfo.JMatchDetails);
				matchDetail=JsonConvert.DeserializeObject<MatchInfo>(jMatchDetails.ToString());
				dotaMatchInfo=JsonConvert.DeserializeObject<List<DotaMatchInfo>>(jMatchDetails.SelectToken("DetailsMatch").ToString());
				List<DetailInfo> listDetail=new List<DetailInfo>();
				listDetail.AddRange(dotaMatchInfo);
				matchDetail.DetailsMatch=listDetail;
				liveFlag=Intent.GetStringExtra("liveFlag");
				cts= new CancellationTokenSource();
				cts.Token.ThrowIfCancellationRequested ();
				dotaMatchInfo_2=new DotaMatchInfo_2();
				refreshFlag = true;

				dotaMatchInfo_2 = await dotaMatchInfo_2.ParseMatchTitle (matchDetail);
				//Title match
				await RefreshData(cts.Token);

			}catch(Exception e) {
				Console.WriteLine (e.Data);
				Console.WriteLine (e.Message);
			}
			cts = null;
			pb.Visibility= ViewStates.Gone;
			buttonRefresh.Visibility = ViewStates.Visible;
		}
		protected async override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);
			SetContentView (Resource.Layout.CSMatchInfoLayout);
			title=Intent.GetStringExtra("title");
			pb = FindViewById<ProgressBar> (Resource.Id.progressBar3);
			ActionBarTitle.SetTitle (this,Resource.Layout.ActionBarLayout,title,Resources.GetString(Resource.String.nameCSGO));
			var buttonBack=FindViewById<Button>(Resource.Id.buttonBackActionBar);
			buttonBack.Click+=ButtonBackClick;
			buttonRefresh=FindViewById<Button>(Resource.Id.buttonRefreshActionBar);
			buttonRefresh.Click+=ButtonRefreshClick;
			buttonRefresh.Visibility=ViewStates.Invisible;
			pb=FindViewById<ProgressBar> (Resource.Id.progressBar3);
			pb.Visibility= ViewStates.Visible;
			APIRequest apiReq = new APIRequest ();
			int match_id=Convert.ToInt32( Intent.GetStringExtra("match_id"));
			var url =SettingsApp.ServerAPIAddress+SettingsApp.GameName+"/GetDetailInfo?match_id=" + match_id;
			var jMatchResponce = await apiReq.GetJsonAsync (url);

			gameInfo=jMatchResponce.ToString ();
			liveFlag=Intent.GetStringExtra("liveFlag");
			var jDetailMatchInfo= JsonConvert.DeserializeObject<JDetailMatchInfo>(gameInfo);
			var jMatchDetails=JToken.Parse(jDetailMatchInfo.JMatchDetails);
			matchInfo=JsonConvert.DeserializeObject<MatchInfo>(jMatchDetails.ToString());
			csMatchInfo=JsonConvert.DeserializeObject<List<CSMatchInfo>>(jMatchDetails.SelectToken("DetailsMatch").ToString());
			List<DetailInfo> listDetail=new List<DetailInfo>();
			listDetail.AddRange(csMatchInfo);
			matchInfo.DetailsMatch=listDetail;

			cts = new CancellationTokenSource ();
			matchInfo_2 = new CSMatchInfo_2 ();
			listMatchInfo = await matchInfo_2.ParseMatchTitle (matchInfo);
			if (listMatchInfo.Count > 0) {
				matchInfo_2 = listMatchInfo [0];
			}
			FillTitleMatch ();

			CreateFragment (Resource.Id.cs_llayout_match_draft, new FragmentCSMatchDraft (listMatchInfo));
			cts = null;
			pb.Visibility= ViewStates.Gone;
			buttonRefresh.Visibility = ViewStates.Visible;
			// Create your application here
		}
		public async Task<DotaMatchInfo_2> ParseMatchTitle(MatchInfo matchInfo)
		{
			var dotaMatchInfo_2 = new DotaMatchInfo_2 ();
			TeamDb teamDb = new TeamDb ();
			var radiantWin=matchInfo.Winner;
			var radiantTeam= await teamDb.GetTeam(matchInfo.Team1Id,"DOTA2");
			var direTeam= await teamDb.GetTeam(matchInfo.Team2Id,"DOTA2");
			var dotaMatchInfo = matchInfo.DetailsMatch.Cast<DotaMatchInfo>().ToList();

			var duration=TimeSpan.FromSeconds(dotaMatchInfo[0].Duration);
			var id=matchInfo.MatchId;
			PicksBansOld radiantPB=new PicksBansOld();
			//var listPicksBans=radiantPB.ConvertJRecentToPickBan(jMatch.SelectToken("picks_bans"));
			var radTower=dotaMatchInfo[0].TowerStatusRadiant;
			var direTower = dotaMatchInfo[0].TowerStatusDire;
			var radBarr=dotaMatchInfo[0].BarracksStatusRadiant;
			var direBarr=dotaMatchInfo[0].BarracksStatusDire;
			var startTime=matchInfo.StartTime;
			var players=dotaMatchInfo[0].Players;
			var allRadGold = 0;
			var allDireGold = 0;
			var allRadXp = 0;
			var allDireXp = 0;
			var radiantScore=0;
			var direScore=0;
			var playersUp=new PlayerStatsUpdate_2();
			for (int i = 0; i < players.Count (); i++) {
				var player=players[i];
				var lvl =(int) player.Level;
				var deaths = (int)player.Death;
				var networth = (int)player.Net_worth;
				if(i<5) {
					direScore+=deaths;
					allRadGold += networth;
					allRadXp += GetXpLevel (lvl);
				}
				else {
					radiantScore+=deaths;
					allDireGold +=networth;
					allDireXp += GetXpLevel (lvl);
				}
			}
			dotaMatchInfo_2=new DotaMatchInfo_2(){
				Team1Win=radiantWin,
				Team1=radiantTeam,
				Team2=direTeam,
				Duration=duration,
				Team1Score=radiantScore,
				Team2Score=direScore,
				MatchId=id,
				TowerStatusRadiant=radTower,
				TowerStatusDire=direTower,
				BarracksStatusRadiant=radBarr,
				BarracksStatusDire=direBarr,
				StartTime=startTime,
				RadiantPicks=dotaMatchInfo[0].RadiantPicks,
				DirePicks=dotaMatchInfo[0].DirePicks,
				RadiantGold = allRadGold,
				DireGold = allDireGold,
				RadiantXp = allRadXp,
				DireXp = allDireXp
			};
			return dotaMatchInfo_2;
		}
		protected override async void OnCreate (Bundle bundle)
		{
			//Window.RequestFeature(WindowFeatures.NoTitle);
			try{

				base.OnCreate (bundle);
				SetContentView (Resource.Layout.PicksLayout);
				pb = FindViewById<ProgressBar> (Resource.Id.progressBar3);
				ActionBarTitle.SetTitle (this,Resource.Layout.ActionBarLayout,Resources.GetString(Resource.String.capitanMod),"DOTA 2");
				buttonRefresh=FindViewById<Button>(Resource.Id.buttonRefreshActionBar);
				buttonRefresh.Click+=ButtonRefreshClick;
				buttonRefresh.Visibility=ViewStates.Invisible;
				var buttonBack=FindViewById<Button>(Resource.Id.buttonBackActionBar);
				buttonBack.Click+=ButtonBackClick;
				pb=FindViewById<ProgressBar> (Resource.Id.progressBar3);
				pb.Visibility= ViewStates.Visible;
				APIRequest ApiReq = new APIRequest ();
				PicksBansOld pickBans=new PicksBansOld();
				Player playerReq=new Player();
				gameInfo=Intent.GetStringExtra("matchDetail");
				var jDetailMatchInfo= JsonConvert.DeserializeObject<JDetailMatchInfo>(gameInfo);
				var jMatchDetails=JToken.Parse(jDetailMatchInfo.JMatchDetails);
				matchInfo=JsonConvert.DeserializeObject<MatchInfo>(jMatchDetails.ToString());
				dotaMatchInfo=JsonConvert.DeserializeObject<List<DotaMatchInfo>>(jMatchDetails.SelectToken("DetailsMatch").ToString());
				List<DetailInfo> listDetail=new List<DetailInfo>();
				listDetail.AddRange(dotaMatchInfo);
				matchInfo.DetailsMatch=listDetail;

				liveFlag=Intent.GetStringExtra("liveFlag");
				title=Intent.GetStringExtra("title");



			TextView radiantName, direName,textRadiant,textDire;
			ImageView radiantLogo, direLogo;
			LinearLayout llradiantTeam, lldireTeam;
				radiantName=FindViewById<TextView>(Resource.Id.radiantTeamName);
				direName=FindViewById<TextView>(Resource.Id.direTeamName);
				radiantLogo=FindViewById<ImageView>(Resource.Id.logoRadiantTeam);
				direLogo=FindViewById<ImageView>(Resource.Id.logoDireTeam);
				llradiantTeam=FindViewById<LinearLayout>(Resource.Id.llradiantTeam);
				lldireTeam=FindViewById<LinearLayout>(Resource.Id.lldireTeam);
					textRadiant=FindViewById<TextView>(Resource.Id.textTeamFP);
					textDire=FindViewById<TextView>(Resource.Id.textTeamSP);

				var analisPick=new AnalysisPick();
				var value=analisPick.GetAnalysisTeam(dotaMatchInfo[0].RadiantPicks.ListPicks,dotaMatchInfo[0].DirePicks.ListPicks);
				textRadiant.Text=Resources.GetString(Resource.String.radiant)+"  "+value[0].ToString();
				textDire.Text=Resources.GetString(Resource.String.dire)+"  "+(value[1].ToString());
				textRadiant.SetTextAppearance(this,Resource.Style.RadiantName);
				textDire.SetTextAppearance(this,Resource.Style.DireName);

				TeamDb teamDb=new TeamDb();
				var radiantTeam= await teamDb.GetTeam(matchInfo.Team1Id,"DOTA2");
				var direTeam= await teamDb.GetTeam(matchInfo.Team2Id,"DOTA2");
				if(radiantTeam != null){
					radiantName.Text=radiantTeam.Name;
					if(radiantTeam.LogoByte!=null){
						Bitmap bmp1= BitmapFactory.DecodeByteArray (radiantTeam.LogoByte, 0, radiantTeam.LogoByte.Length);
						radiantLogo.SetImageBitmap(bmp1);
					}
				}
				if(direTeam != null){
					direName.Text=direTeam.Name;
					if(direTeam.LogoByte!=null){
						Bitmap bmp2= BitmapFactory.DecodeByteArray (direTeam.LogoByte, 0, direTeam.LogoByte.Length);
						direLogo.SetImageBitmap(bmp2);
					}
				}
				var bluePlayer=llradiantTeam.FindViewById<TextView>(Resource.Id.textPlayer1);
				var cyanPlayer=llradiantTeam.FindViewById<TextView>(Resource.Id.textPlayer2);
				var purpurePlayer=llradiantTeam.FindViewById<TextView>(Resource.Id.textPlayer3);
				var yellowPlayer=llradiantTeam.FindViewById<TextView>(Resource.Id.textPlayer4);
				var orangePlayer=llradiantTeam.FindViewById<TextView>(Resource.Id.textPlayer5);
			 
			var pinkPlayer=lldireTeam.FindViewById<TextView>(Resource.Id.textPlayer1);
			var olivePlayer=lldireTeam.FindViewById<TextView>(Resource.Id.textPlayer2);
			var aquaPlayer=lldireTeam.FindViewById<TextView>(Resource.Id.textPlayer3);
			var darkgreenPlayer=lldireTeam.FindViewById<TextView>(Resource.Id.textPlayer4);
			var chokolatePlayer=lldireTeam.FindViewById<TextView>(Resource.Id.textPlayer5);
				var listTextView = new List<TextView> (){bluePlayer,cyanPlayer,purpurePlayer,yellowPlayer,orangePlayer,
				pinkPlayer,olivePlayer,aquaPlayer,darkgreenPlayer,chokolatePlayer};
			
				var allPlayerInfo = dotaMatchInfo[0].Players;
			for (var i = 0; i < allPlayerInfo.Count(); i++) {
					int color=ColorsOnMatch.GetColorPlayer(i);
				listTextView [i].Text = allPlayerInfo [i].PlayerName;
				listTextView[i].SetTextColor(Resources.GetColor(color));
			}
				radiantPB = pickBans.ParseJsonToRadPick (dotaMatchInfo[0].RadiantPicks);
				direPB = pickBans.ParseJsonToDirePick (dotaMatchInfo[0].DirePicks);
				cts=new CancellationTokenSource();
				cts.Token.ThrowIfCancellationRequested ();
				await SetHeroesImageInLayout (cts.Token);
				cts = null;
			}
			catch(Exception e){
				Console.WriteLine (e);
			}
			pb.Visibility= ViewStates.Gone;
			buttonRefresh.Visibility = ViewStates.Visible;
		}
		async Task OnRefresh(CancellationToken token)
		{
			APIRequest ApiReq = new APIRequest ();
			PicksBansOld pickBans=new PicksBansOld();
			//cts = new CancellationTokenSource ();
			refreshFlag = true;
			token.ThrowIfCancellationRequested ();
			var url =SettingsApp.ServerAPIAddress+SettingsApp.GameName+"/GetDetailInfo?match_id="+matchInfo.MatchId;
			var jMatchResponce = await ApiReq.GetJsonAsync (url);

			var jDetailMatchInfo= JsonConvert.DeserializeObject<JDetailMatchInfo>(jMatchResponce.ToString());
			var jMatchDetails=JToken.Parse(jDetailMatchInfo.JMatchDetails);
			matchInfo=JsonConvert.DeserializeObject<MatchInfo>(jMatchDetails.ToString());
			dotaMatchInfo=JsonConvert.DeserializeObject<List<DotaMatchInfo>>(jMatchDetails.SelectToken("DetailsMatch").ToString());
			List<DetailInfo> listDetail=new List<DetailInfo>();
			listDetail.AddRange(dotaMatchInfo);
			matchInfo.DetailsMatch=listDetail;

			radiantPB = pickBans.ParseJsonToRadPick (dotaMatchInfo[0].RadiantPicks);
			direPB = pickBans.ParseJsonToDirePick (dotaMatchInfo[0].DirePicks);
			token.ThrowIfCancellationRequested ();
			await SetHeroesImageInLayout (token);

			var analisPick=new AnalysisPick();
			var textRadiant=FindViewById<TextView>(Resource.Id.textTeamFP);
			var textDire=FindViewById<TextView>(Resource.Id.textTeamSP);
			var value=analisPick.GetAnalysisTeam(dotaMatchInfo[0].RadiantPicks.ListPicks,dotaMatchInfo[0].DirePicks.ListPicks);
			textRadiant.Text=Resources.GetString(Resource.String.radiant)+"  "+value[0].ToString();
			textDire.Text=Resources.GetString(Resource.String.dire)+"  "+(value[1].ToString());
			Toast.MakeText (this, Resources.GetString(Resource.String.updated), ToastLength.Short).Show ();
			refreshFlag = false;
		}
		async Task OnRefresh (CancellationToken token){

			APIRequest ApiReq = new APIRequest ();
			refreshFlag = true;
			titleFlag = false;
			token.ThrowIfCancellationRequested ();
			var url =SettingsApp.ServerAPIAddress+SettingsApp.GameName+"/GetDetailInfo?match_id="+matchDetail.MatchId;
			var jMatchResponce = await ApiReq.GetJsonAsync (url);

			var jDetailMatchInfo= JsonConvert.DeserializeObject<JDetailMatchInfo>(jMatchResponce.ToString());
			var jMatchDetails=JToken.Parse(jDetailMatchInfo.JMatchDetails);
			matchDetail=JsonConvert.DeserializeObject<MatchInfo>(jMatchDetails.ToString());
			dotaMatchInfo=JsonConvert.DeserializeObject<List<DotaMatchInfo>>(jMatchDetails.SelectToken("DetailsMatch").ToString());
			List<DetailInfo> listDetail=new List<DetailInfo>();
			listDetail.AddRange(dotaMatchInfo);
			matchDetail.DetailsMatch=listDetail;

			dotaMatchInfo_2 = await dotaMatchInfo_2.ParseMatchTitle (matchDetail);

			await RefreshData (token);
			Toast.MakeText (this, Resources.GetString(Resource.String.updated), ToastLength.Short).Show ();
			refreshFlag = false;

		}