private async void UpdateLogo(ItemViewModel item) { if (item.Item.HasLogo || item.Item.ParentLogoImageTag.HasValue) { try { var bitmap = await item.GetBitmapImageAsync(new ImageOptions { ImageType = ImageType.Logo }, CancellationToken.None); ImgLogo.Source = bitmap; ImgLogo.Visibility = Visibility.Visible; return; } catch { // Logged at lower levels } } ImgLogo.Visibility = Visibility.Collapsed; }
private void OnItemChanged(ItemViewModel viewModel, BaseItemDto item) { UpdateLogo(viewModel, item); TxtGenres.Visibility = item.Genres.Count > 0 && !item.IsType("episode") && !item.IsType("season") ? Visibility.Visible : Visibility.Collapsed; TxtGenres.Text = string.Join(" / ", item.Genres.Take(3).ToArray()); }
protected override void OnInitialized(EventArgs e) { base.OnInitialized(e); DataContextChanged += ItemInfoFooter_DataContextChanged; Item = DataContext as ItemViewModel; }
private async void UpdateLogo(ItemViewModel viewModel, BaseItemDto item) { DisposeLogoCancellationToken(_logoCancellationTokenSource, true); if (string.Equals(viewModel.ViewType, ListViewTypes.List)) { UpdateLogoForListView(viewModel, item); } }
private async void UpdateLogo(ItemViewModel viewModel, BaseItemDto item) { DisposeLogoCancellationToken(_logoCancellationTokenSource, true); if (string.Equals(viewModel.ViewType, ListViewTypes.List)) { PnlTitle.Visibility = Visibility.Visible; UpdateLogoForListView(viewModel, item); return; } if (item != null && (item.HasLogo || item.ParentLogoImageTag.HasValue)) { var tokenSource = new CancellationTokenSource(); _logoCancellationTokenSource = tokenSource; try { var img = await viewModel.GetBitmapImageAsync(new ImageOptions { ImageType = ImageType.Logo }, tokenSource.Token); LogoImage.Source = img; LogoImage.Visibility = Visibility.Visible; LogoImage.HorizontalAlignment = HorizontalAlignment.Center; // If the logo is owned by the current item, don't show the title if (item.HasLogo) { PnlTitle.Visibility = Visibility.Collapsed; } } catch (OperationCanceledException) { } catch { LogoImage.Visibility = Visibility.Collapsed; PnlTitle.Visibility = Visibility.Visible; } finally { DisposeLogoCancellationToken(tokenSource, false); } } else { LogoImage.Visibility = Visibility.Collapsed; PnlTitle.Visibility = Visibility.Visible; } }
public DetailPageViewModel(ItemViewModel item, IApiClient apiClient, ISessionManager sessionManager, IImageManager imageManager, IPresentationManager presentationManager, IPlaybackManager playback, INavigationService navigation, ILogger logger, ViewType context) { _apiClient = apiClient; _sessionManager = sessionManager; _imageManager = imageManager; _presentationManager = presentationManager; _playback = playback; _navigation = navigation; _logger = logger; Context = context; ItemViewModel = item; }
public DetailPage(ItemViewModel itemViewModel, IPresentationManager presentation) { _itemViewModel = itemViewModel; _presentation = presentation; InitializeComponent(); Loaded += PanoramaDetailPage_Loaded; SetTitle(_itemViewModel.Item); DataContextChanged += PanoramaDetailPage_DataContextChanged; }
public DetailPage(ItemViewModel itemViewModel, IPresentationManager presentation) { _itemViewModel = itemViewModel; _presentation = presentation; _isFocusFunctionButtons = true; _isInitialMenuSelection = true; InitializeComponent(); Loaded += PanoramaDetailPage_Loaded; SetTitle(_itemViewModel.Item); DataContextChanged += PanoramaDetailPage_DataContextChanged; }
/// <summary> /// Gets the item page. /// </summary> /// <param name="item">The item.</param> /// <param name="context">The context.</param> /// <returns>Page.</returns> public Page GetItemPage(BaseItemDto item, ViewType context) { var itemViewModel = new ItemViewModel(_apiClient, _imageManager, _playbackManager, _presentationManager, _logger, _serverEvents) { Item = item, ImageWidth = 550, PreferredImageTypes = new[] { ImageType.Primary, ImageType.Thumb } }; return new DetailPage(itemViewModel, _presentationManager) { DataContext = new DetailPageViewModel(itemViewModel, _apiClient, _sessionManager, _imageManager, _presentationManager, _playbackManager, _navService, _logger, _serverEvents, context) }; }
void ItemInfoFooter_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { Item = DataContext as ItemViewModel; }
private async void UpdateLogoForListView(ItemViewModel viewModel, BaseItemDto item) { if (item != null && item.BackdropCount > 0) { var tokenSource = new CancellationTokenSource(); _logoCancellationTokenSource = tokenSource; try { var img = await viewModel.GetBitmapImageAsync(new ImageOptions { ImageType = ImageType.Backdrop, Height = 320 }, tokenSource.Token); tokenSource.Token.ThrowIfCancellationRequested(); LogoImage.Source = img; LogoImage.Visibility = Visibility.Visible; LogoImage.HorizontalAlignment = HorizontalAlignment.Left; } catch (OperationCanceledException) { LogoImage.Visibility = Visibility.Collapsed; } catch { LogoImage.Visibility = Visibility.Collapsed; } finally { DisposeLogoCancellationToken(tokenSource, false); } } else if (item != null && item.HasThumb) { var tokenSource = new CancellationTokenSource(); _logoCancellationTokenSource = tokenSource; try { var img = await viewModel.GetBitmapImageAsync(new ImageOptions { ImageType = ImageType.Thumb, Height = 320 }, tokenSource.Token); tokenSource.Token.ThrowIfCancellationRequested(); LogoImage.Source = img; LogoImage.Visibility = Visibility.Visible; LogoImage.HorizontalAlignment = HorizontalAlignment.Left; } catch (OperationCanceledException) { LogoImage.Visibility = Visibility.Collapsed; } catch { LogoImage.Visibility = Visibility.Collapsed; } finally { DisposeLogoCancellationToken(tokenSource, false); } } else if (item != null && item.HasPrimaryImage) { var tokenSource = new CancellationTokenSource(); _logoCancellationTokenSource = tokenSource; try { var img = await viewModel.GetBitmapImageAsync(new ImageOptions { ImageType = ImageType.Primary, Height = 320 }, tokenSource.Token); tokenSource.Token.ThrowIfCancellationRequested(); LogoImage.Source = img; LogoImage.Visibility = Visibility.Visible; LogoImage.HorizontalAlignment = HorizontalAlignment.Left; } catch (OperationCanceledException) { LogoImage.Visibility = Visibility.Collapsed; } catch { LogoImage.Visibility = Visibility.Collapsed; } finally { DisposeLogoCancellationToken(tokenSource, false); } } else { LogoImage.Visibility = Visibility.Collapsed; } }
private async void UpdateImage(ItemViewModel item) { var options = GetImageOptions(); if (string.Equals(ImageType, "EpisodeThumb")) { if (item.Item.HasPrimaryImage) { try { options.ImageType = Model.Entities.ImageType.Primary; var bitmap = await item.GetBitmapImageAsync(options, CancellationToken.None); SetImage(bitmap); return; } catch { // Logged at lower levels } } if (item.Item.ParentThumbImageTag.HasValue) { try { options.ImageType = Model.Entities.ImageType.Thumb; var bitmap = await item.GetBitmapImageAsync(options, CancellationToken.None); SetImage(bitmap); return; } catch { // Logged at lower levels } } } else if (string.Equals(ImageType, "Art")) { if (item.Item.HasArtImage || item.Item.ParentArtImageTag.HasValue) { try { options.ImageType = Model.Entities.ImageType.Art; var bitmap = await item.GetBitmapImageAsync(options, CancellationToken.None); SetImage(bitmap); return; } catch { // Logged at lower levels } } } else if (item.Item.HasPrimaryImage) { try { options.ImageType = Model.Entities.ImageType.Primary; var bitmap = await item.GetBitmapImageAsync(options, CancellationToken.None); SetImage(bitmap); return; } catch { // Logged at lower levels } } Img.Visibility = Visibility.Collapsed; }
public async Task ReloadItems(bool isInitialLoad) { if (HasIndexOptions && CurrentIndexOption == null) { return; } if (ShowLoadingAnimation) { _presentationManager.ShowLoadingAnimation(); } try { var result = await _getItemsDelegate(this); var items = result.Items; IsVirtualizationRequired = items.Length > 40; int? selectedIndex = null; if (isInitialLoad && AutoSelectFirstItem) { selectedIndex = 0; } MedianPrimaryImageAspectRatio = result.Items.MedianPrimaryImageAspectRatio(); _listItems.Clear(); var imageTypes = GetPreferredImageTypes(); var childWidth = Convert.ToInt32(ImageDisplayWidth); var imageDisplayHeight = Convert.ToInt32(GetImageDisplayHeight()); var viewModels = items.Select( i => { var vm = new ItemViewModel(i, _apiClient, _imageManager, _playbackManager, _presentationManager, _logger, _serverEvents) { DownloadPrimaryImageAtExactSize = DownloadImageAtExactSize ?? IsCloseToMedianPrimaryImageAspectRatio(i), ImageHeight = imageDisplayHeight, ImageWidth = childWidth, ViewType = ViewType, DisplayName = DisplayNameGenerator == null ? i.Name : DisplayNameGenerator(i), DownloadImagesAtExactSize = DownloadImageAtExactSize ?? true, PreferredImageTypes = imageTypes, ListType = ListType, EnableServerImageEnhancers = EnableServerImageEnhancers }; if (OnItemCreated != null) { OnItemCreated(vm); } var stretch = ImageStretch; if (!stretch.HasValue && imageTypes.Length > 0) { var exact = imageTypes[0] == ImageType.Primary ? vm.DownloadPrimaryImageAtExactSize : vm.DownloadImagesAtExactSize; stretch = exact ? Stretch.UniformToFill : Stretch.Uniform; } if (stretch.HasValue) { vm.ImageStretch = stretch.Value; } return vm; } ).ToList(); _listItems.AddRange(viewModels); ItemCount = items.Length; UpdateContainerSizes(); if (selectedIndex.HasValue) { ListCollectionView.MoveCurrentToPosition(selectedIndex.Value); } } catch (Exception ex) { _presentationManager.ShowDefaultErrorMessage(); } finally { if (ShowLoadingAnimation) { _presentationManager.HideLoadingAnimation(); } } }
private void SectionViewModel_CurrentItemChanged(BaseHomePageSectionViewModel sender, EventArgs e) { CurrentItem = sender.CurrentItem; }
private async Task ReloadItems(bool isInitialLoad) { if (HasIndexOptions && CurrentIndexOption == null) { return; } if (ShowLoadingAnimation) { _presentationManager.ShowLoadingAnimation(); } try { var result = await _getItemsDelegate(this); var items = result.Items; int?selectedIndex = null; if (isInitialLoad && AutoSelectFirstItem) { selectedIndex = 0; } MedianPrimaryImageAspectRatio = result.Items.MedianPrimaryImageAspectRatio(); _listItems.Clear(); var imageTypes = GetPreferredImageTypes(); var childWidth = Convert.ToInt32(ImageDisplayWidth); var imageDisplayHeight = Convert.ToInt32(GetImageDisplayHeight()); var viewModels = items.Select( i => { var vm = new ItemViewModel(_apiClient, _imageManager, _playbackManager, _presentationManager, _logger, _serverEvents) { DownloadPrimaryImageAtExactSize = DownloadImageAtExactSize ?? IsCloseToMedianPrimaryImageAspectRatio(i), ImageHeight = imageDisplayHeight, ImageWidth = childWidth, Item = i, ViewType = ViewType, DisplayName = DisplayNameGenerator == null ? i.Name : DisplayNameGenerator(i), DownloadImagesAtExactSize = DownloadImageAtExactSize ?? true, PreferredImageTypes = imageTypes, ListType = ListType, ShowTitle = ShowTitle }; var stretch = ImageStretch; if (!stretch.HasValue && imageTypes.Length > 0) { var exact = imageTypes[0] == ImageType.Primary ? vm.DownloadPrimaryImageAtExactSize : vm.DownloadImagesAtExactSize; stretch = exact ? Stretch.UniformToFill : Stretch.Uniform; } if (stretch.HasValue) { vm.ImageStretch = stretch.Value; } return(vm); } ).ToList(); _listItems.AddRange(viewModels); ItemCount = items.Length; UpdateContainerSizes(); if (selectedIndex.HasValue) { ListCollectionView.MoveCurrentToPosition(selectedIndex.Value); } } catch (Exception) { _presentationManager.ShowDefaultErrorMessage(); } finally { if (ShowLoadingAnimation) { _presentationManager.HideLoadingAnimation(); } } }