using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Net; using MediaBrowser.UI; using MediaBrowser.UI.Controller; using MediaBrowser.UI.Controls; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Media.Imaging; namespace MediaBrowser.Plugins.DefaultTheme.Controls.Details { /// /// Interaction logic for ItemGallery.xaml /// public partial class ItemGallery : BaseDetailsControl { /// /// Initializes a new instance of the class. /// public ItemGallery() : base() { InitializeComponent(); lstItems.ItemInvoked += lstItems_ItemInvoked; } /// /// LSTs the items_ item invoked. /// /// The sender. /// The e. void lstItems_ItemInvoked(object sender, ItemEventArgs e) { var img = (BitmapImage)e.Argument; var index = Images.IndexOf(img); //App.Instance.OpenImageViewer(new Uri(ImageUrls[index]), Item.Name); } /// /// The _images /// private List _images; /// /// Gets or sets the images. /// /// The images. public List Images { get { return _images; } set { _images = value; lstItems.ItemsSource = value; OnPropertyChanged("Images"); } } /// /// Gets or sets the image urls. /// /// The image urls. private List ImageUrls { get; set; } /// /// Called when [item changed]. /// protected override async void OnItemChanged() { ImageUrls = GetImages(Item); var tasks = ImageUrls.Select(GetImage); var results = await Task.WhenAll(tasks); Images = results.Where(i => i != null).ToList(); } /// /// Gets the image. /// /// The URL. /// Task{BitmapImage}. private async Task GetImage(string url) { try { return await App.Instance.GetRemoteBitmapAsync(url); } catch (HttpException) { return null; } } /// /// Gets the images. /// /// The item. /// List{System.String}. internal static List GetImages(BaseItemDto item) { var images = new List { }; if (item.BackdropCount > 0) { for (var i = 0; i < item.BackdropCount; i++) { images.Add(UIKernel.Instance.ApiClient.GetImageUrl(item, new ImageOptions { ImageType = ImageType.Backdrop, ImageIndex = i })); } } if (item.HasThumb) { images.Add(UIKernel.Instance.ApiClient.GetImageUrl(item, new ImageOptions { ImageType = ImageType.Thumb })); } if (item.HasArtImage) { images.Add(UIKernel.Instance.ApiClient.GetImageUrl(item, new ImageOptions { ImageType = ImageType.Art })); } if (item.HasDiscImage) { images.Add(UIKernel.Instance.ApiClient.GetImageUrl(item, new ImageOptions { ImageType = ImageType.Disc })); } if (item.HasMenuImage) { images.Add(UIKernel.Instance.ApiClient.GetImageUrl(item, new ImageOptions { ImageType = ImageType.Menu })); } if (item.HasBoxImage) { images.Add(UIKernel.Instance.ApiClient.GetImageUrl(item, new ImageOptions { ImageType = ImageType.Box })); } return images; } } }