private void LoadRomanticSeriesViewModel(TvView view) { var now = DateTime.Now; if (now.DayOfWeek == DayOfWeek.Friday) { ShowRomanticSeries = view.RomanceItems.Count > 0 && now.Hour >= 15; } else if (now.DayOfWeek == DayOfWeek.Saturday) { ShowRomanticSeries = view.RomanceItems.Count > 0 && (now.Hour < 3 || now.Hour >= 15); } else if (now.DayOfWeek == DayOfWeek.Sunday) { ShowRomanticSeries = view.RomanceItems.Count > 0 && now.Hour < 3; } else { ShowRomanticSeries = false; } var images = view.RomanceItems.Take(1).Select(i => ApiClient.GetImageUrl(i.Id, new ImageOptions { ImageType = i.ImageType, Tag = i.ImageTag, Width = Convert.ToInt32(TileWidth * 2), EnableImageEnhancers = false })); RomanticSeriesViewModel.AddImages(images); }
private void LoadComedySeriesViewModel(TvView view) { var now = DateTime.Now; if (now.DayOfWeek == DayOfWeek.Thursday) { ShowComedyItems = view.ComedyItems.Count > 0 && now.Hour >= 12; ComedyItemsViewModel.Name = "Comedy Night"; } else if (now.DayOfWeek == DayOfWeek.Sunday) { ShowComedyItems = view.ComedyItems.Count > 0; ComedyItemsViewModel.Name = "Sunday Funnies"; } else { ShowComedyItems = false; } var images = view.ComedyItems.Take(1).Select(i => ApiClient.GetImageUrl(i.Id, new ImageOptions { ImageType = i.ImageType, Tag = i.ImageTag, Width = Convert.ToInt32(TileWidth * 2), EnableImageEnhancers = false })); ComedyItemsViewModel.AddImages(images); }
private void LoadSpotlightViewModel(TvView view) { const ImageType imageType = ImageType.Backdrop; var tileWidth = TileWidth * 2 + TilePadding; var tileHeight = tileWidth * 9 / 16; BackdropItems = view.BackdropItems.ToArray(); var images = view.SpotlightItems.Select(i => new ImageViewerImage { Url = ApiClient.GetImageUrl(i, new ImageOptions { Height = Convert.ToInt32(tileHeight), Width = Convert.ToInt32(tileWidth), ImageType = imageType }), Caption = i.Name, Item = i }).ToList(); SpotlightViewModel.Images.AddRange(images); SpotlightViewModel.StartRotating(10000); }
private void LoadMiniSpotlightsViewModel2(TvView view) { Func <ItemListViewModel, Task <ItemsResult> > getItems = vm => { var items = view.MiniSpotlights.Skip(2).Take(3).ToArray(); return(Task.FromResult(new ItemsResult { TotalRecordCount = items.Length, Items = items })); }; MiniSpotlightsViewModel2 = new ItemListViewModel(getItems, PresentationManager, _imageManager, ApiClient, _navService, _playbackManager, _logger, _serverEvents) { ImageDisplayWidth = TileWidth, ImageDisplayHeightGenerator = v => TileHeight, DisplayNameGenerator = HomePageViewModel.GetDisplayName, EnableBackdropsForCurrentItem = false, ImageStretch = Stretch.UniformToFill, PreferredImageTypesGenerator = vm => new[] { ImageType.Backdrop }, DownloadImageAtExactSize = true }; OnPropertyChanged("MiniSpotlightsViewModel2"); }
private async void LoadViewModels() { var cancellationSource = _mainViewCancellationTokenSource = new CancellationTokenSource(); try { var view = await ApiClient.GetTvView(_sessionManager.LocalUserId, ParentId, cancellationSource.Token); _tvView = view; cancellationSource.Token.ThrowIfCancellationRequested(); LoadSpotlightViewModel(view); LoadAllShowsViewModel(view); LoadMiniSpotlightsViewModel(view); LoadNextUpViewModel(view); LoadLatestEpisodesViewModel(view); LoadResumableViewModel(view); LatestEpisodesViewModel.CurrentItemUpdated += LatestEpisodesViewModel_CurrentItemUpdated; MiniSpotlightsViewModel.CurrentItemUpdated += MiniSpotlightsViewModel_CurrentItemUpdated; NextUpViewModel.CurrentItemUpdated += NextUpViewModel_CurrentItemUpdated; ResumeViewModel.CurrentItemUpdated += ResumeViewModel_CurrentItemUpdated; } catch (Exception ex) { _logger.ErrorException("Error getting tv view", ex); PresentationManager.ShowDefaultErrorMessage(); } finally { DisposeMainViewCancellationTokenSource(false); } }
private void LoadAllShowsViewModel(TvView view) { var images = view.ShowsItems.Take(1).Select(i => ApiClient.GetImageUrl(i.Id, new ImageOptions { ImageType = i.ImageType, Tag = i.ImageTag, Height = Convert.ToInt32(TileWidth * 2), EnableImageEnhancers = false })); AllShowsViewModel.AddImages(images); }
private void LoadNextUpViewModel(TvView view) { NextUpViewModel = new ItemListViewModel(GetNextUpAsync, PresentationManager, _imageManager, ApiClient, _navService, _playbackManager, _logger) { ImageDisplayWidth = TileWidth, ImageDisplayHeightGenerator = v => TileHeight, DisplayNameGenerator = i => i.SeriesName, EnableBackdropsForCurrentItem = false, EnableServerImageEnhancers = false, OnItemCreated = vm => { vm.DisplayNameVisibility = Visibility.Visible; } }; OnPropertyChanged("NextUpViewModel"); }
private void LoadLatestEpisodesViewModel(TvView view) { LatestEpisodesViewModel = new ItemListViewModel(GetLatestEpisodes, PresentationManager, _imageManager, ApiClient, _navService, _playbackManager, _logger, _serverEvents) { ImageDisplayWidth = TileWidth, ImageDisplayHeightGenerator = v => TileHeight, DisplayNameGenerator = HomePageViewModel.GetDisplayName, EnableBackdropsForCurrentItem = false, EnableServerImageEnhancers = false, OnItemCreated = vm => { vm.DisplayNameVisibility = Visibility.Visible; } }; OnPropertyChanged("LatestEpisodesViewModel"); }
private void LoadSpotlightViewModel(TvView view) { const ImageType imageType = ImageType.Backdrop; var tileWidth = TileWidth * 2 + TileMargin; var tileHeight = tileWidth * 9 / 16; BackdropItems = view.BackdropItems.ToArray(); var images = view.SpotlightItems.Select(i => new ImageViewerImage { Url = ApiClient.GetImageUrl(i, new ImageOptions { Height = Convert.ToInt32(tileHeight), Width = Convert.ToInt32(tileWidth), ImageType = imageType }), Caption = i.Name, Item = i }).ToList(); SpotlightViewModel.Images.AddRange(images); SpotlightViewModel.StartRotating(10000); }
private void LoadMiniSpotlightsViewModel(TvView view) { Func<ItemListViewModel, Task<ItemsResult>> getItems = vm => { var items = view.MiniSpotlights.Take(3).ToArray(); return Task.FromResult(new ItemsResult { TotalRecordCount = items.Length, Items = items }); }; MiniSpotlightsViewModel = new ItemListViewModel(getItems, PresentationManager, _imageManager, ApiClient, _navService, _playbackManager, _logger) { ImageDisplayWidth = TileWidth + (TileMargin / 4) - 1, ImageDisplayHeightGenerator = v => TileHeight, DisplayNameGenerator = HomePageViewModel.GetDisplayName, EnableBackdropsForCurrentItem = false, ImageStretch = Stretch.UniformToFill, PreferredImageTypesGenerator = vm => new[] { ImageType.Backdrop }, DownloadImageAtExactSize = true, OnItemCreated = vm => { vm.DisplayNameVisibility = Visibility.Visible; } }; OnPropertyChanged("MiniSpotlightsViewModel"); }