internal async void SeeMatchDetailsAsync(Match selectedMatch, bool refreshMatchesBySelectedDate) { _viewModel.SelectedMatch = selectedMatch; if (refreshMatchesBySelectedDate) { ShowSelectedPage(5); ShowMainTab(false); } else { _viewModel.SelectedMatchDetails = new MatchDetails(); } _viewModel.SelectedMatchDetails.Match = selectedMatch; await Task.Run(() => { _viewModel.AllMatchesWithDetails.ToList().ForEach(x => x.IsSelected = false); MatchDetails matchDetails = _viewModel.AllMatchesWithDetails?.FirstOrDefault(x => x.Match?.MatchID == selectedMatch?.MatchID); matchDetails.IsSelected = true; _viewModel.SelectedMatchDetails = matchDetails; if (refreshMatchesBySelectedDate) { _viewModel.SetMatchesBySelectedDate(); } }); Device.BeginInvokeOnMainThread(() => { MenuMatchesScrollView.BackgroundColor = Color.Transparent; int matchDetailsIndex = _viewModel.MatchesBySelectedDate.IndexOf(_viewModel.MatchesBySelectedDate.FirstOrDefault(x => x.Match.MatchID == selectedMatch?.MatchID)); if (matchDetailsIndex > -1) { MenuMatchesScrollView.ScrollTo(matchDetailsIndex, -1, ScrollToPosition.Center, true); } }); if (_viewModel.SelectedMatchDetails != null && !_viewModel.SelectedMatchDetails.IsDataLoaded) { _viewModel.IsLoadingSelectedMatch = true; _ = (Application.Current as App).ReloadAsync(LoadDataType.MatchDataOnly); } AnalyticsMatchDetails(selectedMatch); }
private void UpdateMatch(string matchID, MatchDetails matchDetails) { try { Match match = matchDetails?.Match; if (match != null) { var allmatches = new ObservableCollection <Match>(_viewModel.AllMatches); var allMatchesWithDetails = new ObservableCollection <MatchDetails>(_viewModel.AllMatchesWithDetails); Match findMatch = allmatches?.FirstOrDefault(x => x.MatchID == match?.MatchID); if (findMatch != null) { // UPDATE MATCH allmatches.Remove(findMatch); allmatches.Add(match); _viewModel.AllMatches = new ObservableCollection <Match>(allmatches); // REMOVE MATCH if (match.StatusID > 14) { allmatches?.Remove(findMatch); _viewModel.AllMatches = new ObservableCollection <Match>(allmatches); } MatchDetails findMatchDetails = _viewModel.AllMatchesWithDetails.FirstOrDefault(x => x?.Match?.MatchID == findMatch?.MatchID); if (findMatchDetails != null) { // UPDATE MATCH DETAILS findMatchDetails.Match = match; findMatchDetails.PlayersOfMatch = new ObservableCollection <PlayerOfMatch>(matchDetails.PlayersOfMatch); findMatchDetails.EventsOfMatch = new ObservableCollection <EventOfMatch>(matchDetails.EventsOfMatch); findMatchDetails.IsDataLoaded = true; // REMOVE MATCH DETAILS if (match.StatusID > 14) { allMatchesWithDetails.Remove(findMatchDetails); _viewModel.AllMatchesWithDetails = new ObservableCollection <MatchDetails>(allMatchesWithDetails); _viewModel.SetMatchesBySelectedDate(); } } } else { // ADD MATCH allmatches?.Add(match); _viewModel.AllMatches = new ObservableCollection <Match>(allmatches); // ADD MATCH DETAILS allMatchesWithDetails.Add(matchDetails); _viewModel.AllMatchesWithDetails = new ObservableCollection <MatchDetails>(allMatchesWithDetails); _viewModel.SetMatchesBySelectedDate(); } if (match.StatusID != findMatch.StatusID || match.HomeTeamScore != findMatch.HomeTeamScore || match.AwayTeamScore != findMatch.AwayTeamScore) { _ = _viewModel.GetStandingsAsync(); _ = _viewModel.GetCompetitionStatisticsAsync(); } _viewModel.TimeCounter.MatchesTime(_viewModel); } } catch (Exception ex) { _ = ReloadAsync(LoadDataType.FullData); Console.WriteLine($"Error: {ex.Message}"); } }