public async Task OnRefresh() { try { if (!SettingsApp.refreshFlag) { SettingsApp.refreshFlag = true; cts = new CancellationTokenSource (); cts.Token.ThrowIfCancellationRequested (); APIRequest ApiReq = new APIRequest (); var jListMatch = await ApiReq.GetJsonAsync (SettingsApp.ServerAPIAddress+SettingsApp.GameName+"/GetUpcomingMatches"); var listMatch = JsonConvert.DeserializeObject<List<SimpleMatchInfo>> (jListMatch.ToString()); SimpleMatchInfo_2 s2 = new SimpleMatchInfo_2 (); listTeams = await s2.ConvertToSimple2 (listMatch,cts.Token); if(this.Activity!=null) this.ListAdapter = new SimpleMatchAdapter(this.Activity,listTeams,3,cts.Token); cts = null; SettingsApp.refreshFlag = false; Toast.MakeText (context, context.Resources.GetString(Resource.String.updated), ToastLength.Long).Show (); } } catch { cts = null; SettingsApp.refreshFlag = false; Toast.MakeText (context, context.Resources.GetString(Resource.String.error), ToastLength.Long).Show (); } }
public async Task<List<SimpleMatchInfo_2>> ConvertToSimple2 (List<SimpleMatchInfo> sm, CancellationToken token) { TeamDb team = new TeamDb (); LeagueDb oleag = new LeagueDb (); List<SimpleMatchInfo_2> listExMatchInfo = new List<SimpleMatchInfo_2> (); foreach (var simpleInfo in sm) { token.ThrowIfCancellationRequested (); var team1 = await team.GetTeam (simpleInfo.Team1Id, SettingsApp.GameName); var team2 = await team.GetTeam (simpleInfo.Team2Id, SettingsApp.GameName); var league = await oleag.GetLeague (simpleInfo.LeagueId, SettingsApp.GameName); var exMatchInfo = new SimpleMatchInfo_2 () { MatchId=simpleInfo.MatchId, League=league, StartTime=simpleInfo.StartTime, Team1=team1, Team2=team2, MatchUrl=simpleInfo.MatchUrl, GameId=simpleInfo.GameId, MatchType=simpleInfo.MatchType }; listExMatchInfo.Add (exMatchInfo); } return listExMatchInfo; }