using MediaBrowser.Model.Entities; using MediaBrowser.Model.Net; using MediaBrowser.Plugins.DefaultTheme.DisplayPreferences; using MediaBrowser.Plugins.DefaultTheme.Resources; using MediaBrowser.UI; using MediaBrowser.UI.Controls; using MediaBrowser.UI.Pages; using System; using System.Windows; namespace MediaBrowser.Plugins.DefaultTheme.Pages { /// /// Interaction logic for ListPage.xaml /// public partial class ListPage : BaseListPage { /// /// Initializes a new instance of the class. /// /// The item id. public ListPage(string itemId) : base(itemId) { InitializeComponent(); } /// /// Subclasses must provide the list box that holds the items /// /// The items list. protected override ExtendedListBox ItemsList { get { return lstItems; } } /// /// If the page is using it's own image type and not honoring the DisplayPreferences setting, it should return it here /// /// The type of the fixed image. protected override ImageType? FixedImageType { get { return ImageType.Primary; } } /// /// Called when [loaded]. /// protected override async void OnLoaded() { base.OnLoaded(); if (Folder != null) { ShowViewButton(); await AppResources.Instance.SetPageTitle(Folder); } else { HideViewButton(); } } /// /// Called when [unloaded]. /// protected override void OnUnloaded() { base.OnUnloaded(); HideViewButton(); } /// /// Called when [property changed]. /// /// The name. public override void OnPropertyChanged(string name) { base.OnPropertyChanged(name); if (name.Equals("CurrentItemIndex", StringComparison.OrdinalIgnoreCase)) { UpdateCurrentItemIndex(); } } /// /// Updates the index of the current item. /// private void UpdateCurrentItemIndex() { var index = CurrentItemIndex; currentItemIndex.Visibility = index == -1 ? Visibility.Collapsed : Visibility.Visible; currentItemIndex.Text = (CurrentItemIndex + 1).ToString(); currentItemIndexDivider.Visibility = index == -1 ? Visibility.Collapsed : Visibility.Visible; } /// /// Gets called anytime the Folder gets refreshed /// protected override async void OnFolderChanged() { base.OnFolderChanged(); var pageTitleTask = AppResources.Instance.SetPageTitle(Folder); ShowViewButton(); if (Folder.IsType("Season")) { TxtName.Visibility = Visibility.Visible; TxtName.Text = Folder.Name; } else { TxtName.Visibility = Visibility.Collapsed; } if (!string.IsNullOrEmpty(Folder.Overview) || Folder.IsType("Series") || Folder.IsType("Season")) { sidebar.Visibility = Visibility.Collapsed; //RefreshSidebar(); } else { sidebar.Visibility = Visibility.Collapsed; } await pageTitleTask; } /// /// Shows the view button. /// private void ShowViewButton() { var viewButton = AppResources.Instance.ViewButton; viewButton.Visibility = Visibility.Visible; viewButton.Click -= ViewButton_Click; viewButton.Click += ViewButton_Click; } /// /// Hides the view button. /// private void HideViewButton() { var viewButton = AppResources.Instance.ViewButton; viewButton.Visibility = Visibility.Collapsed; viewButton.Click -= ViewButton_Click; } /// /// Handles the Click event of the ViewButton control. /// /// The source of the event. /// The instance containing the event data. async void ViewButton_Click(object sender, RoutedEventArgs e) { var menu = new DisplayPreferencesMenu { FolderId = Folder.Id, MainPage = this }; menu.ShowModal(this.GetWindow()); try { await App.Instance.ApiClient.UpdateDisplayPreferencesAsync(App.Instance.CurrentUser.Id, Folder.Id, DisplayPreferences); } catch (HttpException) { App.Instance.ShowDefaultErrorMessage(); } } /// /// Refreshes the sidebar. /// private void RefreshSidebar() { //if (Folder.BackdropCount > 0) //{ // //backdropImage.Source = App.Instance.GetBitmapImage(ApiClient.GetImageUrl(Folder.Id, Model.Entities.ImageType.Backdrop, width: 560, height: 315)); // backdropImage.Visibility = Visibility.Visible; //} //else //{ // backdropImage.Source = null; // backdropImage.Visibility = Visibility.Collapsed; //} } /// /// Handles current item selection changes /// protected override void OnCurrentItemChanged() { base.OnCurrentItemChanged(); // Name /*if (CurrentItem != null) { txtName.Visibility = CurrentItem.HasLogo ? Visibility.Collapsed : Visibility.Visible; currentItemLogo.Visibility = CurrentItem.HasLogo ? Visibility.Visible : Visibility.Collapsed; if (CurrentItem.HasLogo) { var uri = ApiClient.GetImageUrl(CurrentItem.Id, ImageType.Logo, maxWidth: 400, maxHeight: 125); Dispatcher.InvokeAsync(() => currentItemLogo.Source = App.Instance.GetBitmapImage(new Uri(uri, UriKind.Absolute))); } else { var name = CurrentItem.Name; if (!CurrentItem.IsType("Season") && CurrentItem.IndexNumber.HasValue) { name = CurrentItem.IndexNumber + " - " + name; } if (CurrentItem.IsType("Movie") && CurrentItem.ProductionYear.HasValue) { name += " (" + CurrentItem.ProductionYear + ")"; } txtName.Text = name; } } else { txtName.Visibility = Visibility.Collapsed; currentItemLogo.Visibility = Visibility.Collapsed; } // PremiereDate if (CurrentItem != null && CurrentItem.PremiereDate.HasValue && !CurrentItem.IsType("Series")) { pnlPremiereDate.Visibility = Visibility.Visible; var prefix = CurrentItem.IsType("Episode") ? "Aired" : CurrentItem.IsType("Series") ? "First Aired" : "Premiered"; txtPremiereDate.Text = string.Format("{0} {1}", prefix, CurrentItem.PremiereDate.Value.ToShortDateString()); } else { pnlPremiereDate.Visibility = Visibility.Collapsed; } // Taglines if (CurrentItem != null && CurrentItem.Taglines != null && CurrentItem.Taglines.Length > 0) { txtTagLine.Visibility = Visibility.Visible; txtTagLine.Text = CurrentItem.Taglines[0]; } else { txtTagLine.Visibility = Visibility.Collapsed; } // Genres if (CurrentItem != null && CurrentItem.Genres != null && CurrentItem.Genres.Length > 0) { txtGenres.Visibility = Visibility.Visible; // Try to keep them on one line by limiting to three txtGenres.Text = string.Join(" / ", CurrentItem.Genres.Take(3)); } else { txtGenres.Visibility = Visibility.Collapsed; } // Season Number if (CurrentItem != null && CurrentItem.ParentIndexNumber.HasValue && CurrentItem.IsType("Episode")) { txtSeasonHeader.Visibility = Visibility.Visible; txtSeasonHeader.Text = string.Format("Season {0}", CurrentItem.ParentIndexNumber); } else { txtSeasonHeader.Visibility = Visibility.Collapsed; } UpdateSeriesAirTime(); UpdateMiscellaneousFields(); UpdateCommunityRating(); UpdateVideoInfo(); UpdateAudioInfo();*/ } /// /// Updates the series air time. /// private void UpdateSeriesAirTime() { /*if (CurrentItem != null && CurrentItem.SeriesInfo != null) { var series = CurrentItem.SeriesInfo; txtSeriesAirTime.Visibility = Visibility.Visible; if (series.Status.HasValue && series.Status.Value == SeriesStatus.Ended) { txtSeriesAirTime.Text = "Ended"; } else { string txt = "Airs"; if (series.AirDays.Length > 0) { if (series.AirDays.Length == 7) { txt += " Everyday"; } else { txt += " " + series.AirDays[0].ToString(); } } if (CurrentItem.Studios != null && CurrentItem.Studios.Length > 0) { txt += " on " + CurrentItem.Studios[0].Name; } if (!string.IsNullOrEmpty(series.AirTime)) { txt += " at " + series.AirTime; } txtSeriesAirTime.Text = txt; } } else { txtSeriesAirTime.Visibility = Visibility.Collapsed; }*/ } /// /// Updates the miscellaneous fields. /// private void UpdateMiscellaneousFields() { /*if (CurrentItem == null) { pnlRuntime.Visibility = Visibility.Collapsed; pnlOfficialRating.Visibility = Visibility.Collapsed; } else { var runtimeTicks = CurrentItem.RunTimeTicks ?? 0; // Runtime if (runtimeTicks > 0) { pnlRuntime.Visibility = Visibility.Visible; txtRuntime.Text = string.Format("{0} minutes", Convert.ToInt32(TimeSpan.FromTicks(runtimeTicks).TotalMinutes)); } else { pnlRuntime.Visibility = Visibility.Collapsed; } pnlOfficialRating.Visibility = string.IsNullOrEmpty(CurrentItem.OfficialRating) ? Visibility.Collapsed : Visibility.Visible; } // Show the parent panel only if one of the children is visible pnlMisc.Visibility = pnlRuntime.Visibility == Visibility.Visible || pnlOfficialRating.Visibility == Visibility.Visible ? Visibility.Visible : Visibility.Collapsed;*/ } /// /// Updates the community rating. /// private void UpdateCommunityRating() { /*// Community Rating if (CurrentItem != null && CurrentItem.CommunityRating.HasValue) { pnlRating.Visibility = Visibility.Visible; } else { pnlRating.Visibility = Visibility.Collapsed; return; } var rating = CurrentItem.CommunityRating.Value; for (var i = 0; i < 10; i++) { if (rating < i - 1) { TreeHelper.FindChild(this, "communityRatingImage" + i).SetResourceReference(Image.StyleProperty, "CommunityRatingImageEmpty"); } else if (rating < i) { TreeHelper.FindChild(this, "communityRatingImage" + i).SetResourceReference(Image.StyleProperty, "CommunityRatingImageHalf"); } else { TreeHelper.FindChild(this, "communityRatingImage" + i).SetResourceReference(Image.StyleProperty, "CommunityRatingImageFull"); } }*/ } /// /// Updates the video info. /// private void UpdateVideoInfo() { /*if (CurrentItem != null && CurrentItem.VideoInfo != null) { pnlVideoInfo.Visibility = Visibility.Visible; } else { pnlVideoInfo.Visibility = Visibility.Collapsed; return; } var videoInfo = CurrentItem.VideoInfo; if (videoInfo.VideoType == VideoType.VideoFile) { txtVideoType.Text = Path.GetExtension(CurrentItem.Path).Replace(".", string.Empty).ToLower(); } else { txtVideoType.Text = videoInfo.VideoType.ToString().ToLower(); } txtVideoResolution.Text = GetResolutionText(videoInfo); pnlVideoResolution.Visibility = string.IsNullOrEmpty(txtVideoResolution.Text) ? Visibility.Collapsed : Visibility.Visible; if (!string.IsNullOrEmpty(videoInfo.Codec)) { pnlVideoCodec.Visibility = Visibility.Visible; txtVideoCodec.Text = videoInfo.Codec.ToLower(); } else { pnlVideoCodec.Visibility = Visibility.Collapsed; } var audio = videoInfo.GetDefaultAudioStream(); if (audio == null || string.IsNullOrEmpty(audio.Codec)) { pnlAudioCodec.Visibility = Visibility.Collapsed; } else { pnlAudioCodec.Visibility = Visibility.Visible; txtAudioCodec.Text = audio.Codec.ToLower(); }*/ } /// /// Updates the audio info. /// private void UpdateAudioInfo() { /*if (CurrentItem != null && CurrentItem.AudioInfo != null) { pnlAudioInfo.Visibility = Visibility.Visible; } else { pnlAudioInfo.Visibility = Visibility.Collapsed; return; } var audioInfo = CurrentItem.AudioInfo; txtAudioType.Text = Path.GetExtension(CurrentItem.Path).Replace(".", string.Empty).ToLower(); if (audioInfo.BitRate > 0) { pnlAudioBitrate.Visibility = Visibility.Visible; txtAudioBitrate.Text = (audioInfo.BitRate / 1000).ToString() + "kbps"; } else { pnlAudioBitrate.Visibility = Visibility.Collapsed; }*/ } /*private string GetResolutionText(VideoInfo info) { var scanType = info.ScanType ?? string.Empty; if (info.Height == 1080) { if (scanType.Equals("progressive", StringComparison.OrdinalIgnoreCase)) { return "1080p"; } if (scanType.Equals("interlaced", StringComparison.OrdinalIgnoreCase)) { return "1080i"; } } if (info.Height == 720) { if (scanType.Equals("progressive", StringComparison.OrdinalIgnoreCase)) { return "720p"; } if (scanType.Equals("interlaced", StringComparison.OrdinalIgnoreCase)) { return "720i"; } } if (info.Height == 480) { if (scanType.Equals("progressive", StringComparison.OrdinalIgnoreCase)) { return "480p"; } if (scanType.Equals("interlaced", StringComparison.OrdinalIgnoreCase)) { return "480i"; } } return info.Width == 0 || info.Height == 0 ? string.Empty : info.Width + "x" + info.Height; }*/ } }