using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Net; using MediaBrowser.Plugins.DefaultTheme.Controls.Details; using MediaBrowser.Plugins.DefaultTheme.Resources; using MediaBrowser.UI; using MediaBrowser.UI.Controller; using MediaBrowser.UI.Pages; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Media.Imaging; namespace MediaBrowser.Plugins.DefaultTheme.Pages { /// /// Interaction logic for DetailPage.xaml /// public partial class DetailPage : BaseDetailPage { /// /// Initializes a new instance of the class. /// /// The item id. public DetailPage(string itemId) : base(itemId) { InitializeComponent(); BtnOverview.Click += BtnOverview_Click; BtnChapters.Click += BtnChapters_Click; BtnMediaInfo.Click += BtnDetails_Click; BtnPerformers.Click += BtnPerformers_Click; BtnTrailers.Click += BtnTrailers_Click; BtnSpecialFeatures.Click += BtnSpecialFeatures_Click; BtnGallery.Click += BtnGallery_Click; } /// /// Handles the Click event of the BtnGallery control. /// /// The source of the event. /// The instance containing the event data. void BtnGallery_Click(object sender, RoutedEventArgs e) { PrimaryImageGrid.Visibility = Visibility.Collapsed; ShowDetailControl(BtnGallery, new ItemGallery { }); } /// /// Handles the Click event of the BtnSpecialFeatures control. /// /// The source of the event. /// The instance containing the event data. void BtnSpecialFeatures_Click(object sender, RoutedEventArgs e) { PrimaryImageGrid.Visibility = Visibility.Collapsed; ShowDetailControl(BtnSpecialFeatures, new ItemSpecialFeatures { }); } /// /// Handles the Click event of the BtnTrailers control. /// /// The source of the event. /// The instance containing the event data. void BtnTrailers_Click(object sender, RoutedEventArgs e) { PrimaryImageGrid.Visibility = Visibility.Collapsed; ShowDetailControl(BtnTrailers, new ItemTrailers { }); } /// /// Handles the Click event of the BtnDetails control. /// /// The source of the event. /// The instance containing the event data. void BtnDetails_Click(object sender, RoutedEventArgs e) { PrimaryImageGrid.Visibility = Visibility.Visible; ShowDetailControl(BtnMediaInfo, new ItemMediaInfo { }); } /// /// Handles the Click event of the BtnChapters control. /// /// The source of the event. /// The instance containing the event data. void BtnChapters_Click(object sender, RoutedEventArgs e) { PrimaryImageGrid.Visibility = Visibility.Collapsed; ShowDetailControl(BtnChapters, new ItemChapters { }); } /// /// Handles the Click event of the BtnOverview control. /// /// The source of the event. /// The instance containing the event data. void BtnOverview_Click(object sender, RoutedEventArgs e) { PrimaryImageGrid.Visibility = Visibility.Visible; ShowDetailControl(BtnOverview, new ItemOverview { }); } /// /// Handles the Click event of the BtnPerformers control. /// /// The source of the event. /// The instance containing the event data. void BtnPerformers_Click(object sender, RoutedEventArgs e) { PrimaryImageGrid.Visibility = Visibility.Collapsed; ShowDetailControl(BtnPerformers, new ItemPerformers { }); } /// /// Handles the Click event of the BtnQueue control. /// /// The source of the event. /// The instance containing the event data. void BtnQueue_Click(object sender, RoutedEventArgs e) { Queue(); } /// /// Called when [loaded]. /// protected override async void OnLoaded() { base.OnLoaded(); if (Item != null) { await AppResources.Instance.SetPageTitle(Item); } } /// /// Called when [item changed]. /// protected override async void OnItemChanged() { base.OnItemChanged(); var pageTitleTask = AppResources.Instance.SetPageTitle(Item); BtnOverview_Click(null, null); RenderItem(); await pageTitleTask; } /// /// Renders the item. /// private async void RenderItem() { Task primaryImageTask = null; if (Item.HasPrimaryImage) { PrimaryImage.Visibility = Visibility.Visible; primaryImageTask = App.Instance.GetRemoteBitmapAsync(UIKernel.Instance.ApiClient.GetImageUrl(Item, new ImageOptions { ImageType = ImageType.Primary, Quality = 100 })); } else { SetDefaultImage(); } if (Item.IsType("movie") || Item.IsType("trailer")) { TxtName.Visibility = Visibility.Collapsed; } else { var name = Item.Name; if (Item.IndexNumber.HasValue) { name = Item.IndexNumber.Value + " - " + name; if (Item.ParentIndexNumber.HasValue) { name = Item.ParentIndexNumber.Value + "." + name; } } TxtName.Text = name; TxtName.Visibility = Visibility.Visible; } if (Item.Taglines != null && Item.Taglines.Count > 0) { Tagline.Visibility = Visibility.Visible; Tagline.Text = Item.Taglines[0]; } else { Tagline.Visibility = Visibility.Collapsed; } BtnGallery.Visibility = ItemGallery.GetImages(Item).Count > 0 ? Visibility.Visible : Visibility.Collapsed; BtnTrailers.Visibility = Item.HasTrailer ? Visibility.Visible : Visibility.Collapsed; BtnSpecialFeatures.Visibility = Item.SpecialFeatureCount > 0 ? Visibility.Visible : Visibility.Collapsed; BtnPerformers.Visibility = Item.People != null && Item.People.Length > 0 ? Visibility.Visible : Visibility.Collapsed; BtnChapters.Visibility = Item.Chapters != null && Item.Chapters.Count > 0 ? Visibility.Visible : Visibility.Collapsed; if (primaryImageTask != null) { try { PrimaryImage.Source = await primaryImageTask; } catch (HttpException) { SetDefaultImage(); } } } /// /// Sets the default image. /// private void SetDefaultImage() { PrimaryImage.Visibility = Visibility.Collapsed; } /// /// Handles the 1 event of the Button_Click control. /// /// The source of the event. /// The instance containing the event data. private void Button_Click_1(object sender, RoutedEventArgs e) { Play(); } /// /// Handles the 2 event of the Button_Click control. /// /// The source of the event. /// The instance containing the event data. private async void Button_Click_2(object sender, RoutedEventArgs e) { await UIKernel.Instance.PlaybackManager.StopAllPlayback(); } /// /// Shows the detail control. /// /// The button. /// The element. private void ShowDetailControl(Button button, BaseDetailsControl element) { DetailContent.Content = element; element.Item = Item; } } }