public void Refresh() { IsLoading = true; _tvshowtimeApiService.GetWatchlist(0, 0) .Subscribe(async(watchlistResponse) => { await DispatcherHelper.ExecuteOnUIThreadAsync(() => { _watchedOrUnwatchedEpisode = false; _followedOrUnfollowedShow = false; LastLoadingDate = DateTime.Now; Episodes.Clear(); foreach (var episode in watchlistResponse.Episodes) { Episodes.Add(episode); } IsLoading = false; }); }, async(error) => { await DispatcherHelper.ExecuteOnUIThreadAsync(() => { IsLoading = false; }); _toastNotificationService.ShowErrorNotification("An error happened. Please retry later."); }); }
private void RefreshByEpisodeId(long episodeId) { IsLoading = true; _tvshowtimeApiService.GetEpisode(new EpisodeRequestByEpisodeId { EpisodeId = episodeId }) .Subscribe(async(episodeResponse) => { await DispatcherHelper.ExecuteOnUIThreadAsync(() => { LastLoadingDate = DateTime.Now; Episode = episodeResponse.Episode; RaisePropertyChanged(nameof(Episode)); IsLoading = false; }); }, async(error) => { await DispatcherHelper.ExecuteOnUIThreadAsync(() => { IsLoading = false; }); _toastNotificationService.ShowErrorNotification("An error happened. Please retry later."); }); }
private void LoadAgendaPage(int page) { IsLoading = true; _tvshowtimeApiService.GetAgenda(page, 10, true) .Subscribe(async(agendaResponse) => { await DispatcherHelper.ExecuteOnUIThreadAsync(() => { foreach (var episode in agendaResponse.Episodes) { // Do not add an episode without air date if (!episode.AirDate.HasValue) { continue; } // Do not add the same episode twice if (IsAlreadyAdded(episode)) { continue; } // Add episode to the corresponding group var group = Groups.FirstOrDefault(g => g.Date == episode.AirDate); // Create a new group if necessary if (group == null) { group = new AgendaGroup { Date = episode.AirDate.Value }; int index = Groups.Count(g => g.Date < episode.AirDate.Value); Groups.Insert(index, group); } group.Episodes.Add(episode); } IsLoading = false; }); }, async(error) => { await DispatcherHelper.ExecuteOnUIThreadAsync(() => { IsLoading = false; }); _toastNotificationService.ShowErrorNotification("An error happened. Please retry later."); }); }
private void RefreshByShowId(long showId, int selectedSeason = 1) { IsLoading = true; _tvshowtimeApiService.GetShow(showId, string.Empty, true) .Subscribe(async(showResponse) => { await DispatcherHelper.ExecuteOnUIThreadAsync(() => { LastLoadingDate = DateTime.Now; Seasons.Clear(); Show = showResponse.Show; RaisePropertyChanged(nameof(Show)); foreach (var episode in Show.Episodes) { var seasonGroup = Seasons.FirstOrDefault(s => s.SeasonNumber == episode.Season); if (seasonGroup == null) { seasonGroup = new ShowSeasonGroup { SeasonNumber = episode.Season }; Seasons.Add(seasonGroup); } seasonGroup.Episodes.Add(episode); } RaisePropertyChanged(nameof(MinSeasonNumber)); RaisePropertyChanged(nameof(MaxSeasonNumber)); SelectedSeason = Seasons.FirstOrDefault(s => s.SeasonNumber == selectedSeason); IsLoading = false; }); }, async(error) => { await DispatcherHelper.ExecuteOnUIThreadAsync(() => { IsLoading = false; }); _toastNotificationService.ShowErrorNotification("An error happened. Please retry later."); }); }
private void LoadCollection() { IsLoading = true; _tvshowtimeApiService.GetLibrary(_currentPage, _pageSize) .Subscribe(async(libraryResponse) => { await DispatcherHelper.ExecuteOnUIThreadAsync(() => { foreach (var show in libraryResponse.Shows) { // Do not add the same show twice if (_allGroup.Shows.Any(s => s.Id == show.Id)) { continue; } _allGroup.Shows.Add(show); if (show.Archived.HasValue && show.Archived.Value) { _archivedGroup.Shows.Add(show); continue; } if (show.Status == "Continuing") { _continuingGroup.Shows.Add(show); } if (show.Status == "Ended") { _endedGroup.Shows.Add(show); } if (show.LastAired != null) { if (show.LastSeen != null && show.LastSeen.Season == show.LastAired.Season && show.LastSeen.Number == show.LastAired.Number) { _upToDateGroup.Shows.Add(show); } else { _lateGroup.Shows.Add(show); } } } if (libraryResponse.Shows.Count >= _pageSize) { _currentPage++; LoadCollection(); } else { IsLoading = false; } }); }, async(error) => { await DispatcherHelper.ExecuteOnUIThreadAsync(() => { IsLoading = false; }); _toastNotificationService.ShowErrorNotification("An error happened. Please retry later."); }); }
private void LoadUpcomingEpisodes() { IsLoading = true; _tvshowtimeApiService.GetAgenda(_currentPage, _pageSize) .Subscribe(async(agendaResponse) => { await DispatcherHelper.ExecuteOnUIThreadAsync(() => { foreach (var episode in agendaResponse.Episodes) { // Do not add the same show twice if (Episodes.Any(e => e.Id == episode.Id)) { continue; } // Do not add episode if already aired if (episode.AirDate < DateTime.Now) { continue; } string diffTime = string.Empty; var timeSpanDiff = episode.AirDate.Value.Subtract(DateTime.Now.ToUniversalTime()); if (episode.AirTime.HasValue) { timeSpanDiff = timeSpanDiff .Add(TimeSpan.FromHours(episode.AirTime.Value.DateTime.Hour)); timeSpanDiff = timeSpanDiff .Add(TimeSpan.FromMinutes(episode.AirTime.Value.DateTime.Minute)); } if (timeSpanDiff.Days >= 7) { diffTime += $"{timeSpanDiff.Days} days"; } else { if (timeSpanDiff.Days >= 1) { diffTime += $"{timeSpanDiff.Days} day"; if (timeSpanDiff.Days > 1) { diffTime += "s"; } } if (timeSpanDiff.Hours >= 1) { if (!string.IsNullOrWhiteSpace(diffTime)) { diffTime += Environment.NewLine; } diffTime += $"{timeSpanDiff.Hours} hour"; if (timeSpanDiff.Hours > 1) { diffTime += "s"; } } if (timeSpanDiff.Minutes >= 1) { if (!string.IsNullOrWhiteSpace(diffTime)) { diffTime += Environment.NewLine; } diffTime += $"{timeSpanDiff.Minutes} min."; } } Episodes.Add(new UpcomingEpisodeViewModel { Id = episode.Id, Season = episode.Season, Number = episode.Number, Show = episode.Show, DiffTime = diffTime.Trim(), Original = episode }); } if (agendaResponse.Episodes.Count >= _pageSize) { _currentPage++; LoadUpcomingEpisodes(); } else { IsLoading = false; } }); }, async(error) => { await DispatcherHelper.ExecuteOnUIThreadAsync(() => { IsLoading = false; }); _toastNotificationService.ShowErrorNotification("An error happened. Please retry later."); }); }