ListPage.xaml.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. using MediaBrowser.Model.Entities;
  2. using MediaBrowser.Model.Net;
  3. using MediaBrowser.Plugins.DefaultTheme.DisplayPreferences;
  4. using MediaBrowser.Plugins.DefaultTheme.Resources;
  5. using MediaBrowser.UI;
  6. using MediaBrowser.UI.Controls;
  7. using MediaBrowser.UI.Pages;
  8. using System;
  9. using System.Windows;
  10. namespace MediaBrowser.Plugins.DefaultTheme.Pages
  11. {
  12. /// <summary>
  13. /// Interaction logic for ListPage.xaml
  14. /// </summary>
  15. public partial class ListPage : BaseListPage
  16. {
  17. /// <summary>
  18. /// Initializes a new instance of the <see cref="ListPage" /> class.
  19. /// </summary>
  20. /// <param name="itemId">The item id.</param>
  21. public ListPage(string itemId)
  22. : base(itemId)
  23. {
  24. InitializeComponent();
  25. }
  26. /// <summary>
  27. /// Subclasses must provide the list box that holds the items
  28. /// </summary>
  29. /// <value>The items list.</value>
  30. protected override ExtendedListBox ItemsList
  31. {
  32. get
  33. {
  34. return lstItems;
  35. }
  36. }
  37. /// <summary>
  38. /// If the page is using it's own image type and not honoring the DisplayPreferences setting, it should return it here
  39. /// </summary>
  40. /// <value>The type of the fixed image.</value>
  41. protected override ImageType? FixedImageType
  42. {
  43. get { return ImageType.Primary; }
  44. }
  45. /// <summary>
  46. /// Called when [loaded].
  47. /// </summary>
  48. protected override async void OnLoaded()
  49. {
  50. base.OnLoaded();
  51. if (Folder != null)
  52. {
  53. ShowViewButton();
  54. await AppResources.Instance.SetPageTitle(Folder);
  55. }
  56. else
  57. {
  58. HideViewButton();
  59. }
  60. }
  61. /// <summary>
  62. /// Called when [unloaded].
  63. /// </summary>
  64. protected override void OnUnloaded()
  65. {
  66. base.OnUnloaded();
  67. HideViewButton();
  68. }
  69. /// <summary>
  70. /// Called when [property changed].
  71. /// </summary>
  72. /// <param name="name">The name.</param>
  73. public override void OnPropertyChanged(string name)
  74. {
  75. base.OnPropertyChanged(name);
  76. if (name.Equals("CurrentItemIndex", StringComparison.OrdinalIgnoreCase))
  77. {
  78. UpdateCurrentItemIndex();
  79. }
  80. }
  81. /// <summary>
  82. /// Updates the index of the current item.
  83. /// </summary>
  84. private void UpdateCurrentItemIndex()
  85. {
  86. var index = CurrentItemIndex;
  87. currentItemIndex.Visibility = index == -1 ? Visibility.Collapsed : Visibility.Visible;
  88. currentItemIndex.Text = (CurrentItemIndex + 1).ToString();
  89. currentItemIndexDivider.Visibility = index == -1 ? Visibility.Collapsed : Visibility.Visible;
  90. }
  91. /// <summary>
  92. /// Gets called anytime the Folder gets refreshed
  93. /// </summary>
  94. protected override async void OnFolderChanged()
  95. {
  96. base.OnFolderChanged();
  97. var pageTitleTask = AppResources.Instance.SetPageTitle(Folder);
  98. ShowViewButton();
  99. if (Folder.IsType("Season"))
  100. {
  101. TxtName.Visibility = Visibility.Visible;
  102. TxtName.Text = Folder.Name;
  103. }
  104. else
  105. {
  106. TxtName.Visibility = Visibility.Collapsed;
  107. }
  108. if (!string.IsNullOrEmpty(Folder.Overview) || Folder.IsType("Series") || Folder.IsType("Season"))
  109. {
  110. sidebar.Visibility = Visibility.Collapsed;
  111. //RefreshSidebar();
  112. }
  113. else
  114. {
  115. sidebar.Visibility = Visibility.Collapsed;
  116. }
  117. await pageTitleTask;
  118. }
  119. /// <summary>
  120. /// Shows the view button.
  121. /// </summary>
  122. private void ShowViewButton()
  123. {
  124. var viewButton = AppResources.Instance.ViewButton;
  125. viewButton.Visibility = Visibility.Visible;
  126. viewButton.Click -= ViewButton_Click;
  127. viewButton.Click += ViewButton_Click;
  128. }
  129. /// <summary>
  130. /// Hides the view button.
  131. /// </summary>
  132. private void HideViewButton()
  133. {
  134. var viewButton = AppResources.Instance.ViewButton;
  135. viewButton.Visibility = Visibility.Collapsed;
  136. viewButton.Click -= ViewButton_Click;
  137. }
  138. /// <summary>
  139. /// Handles the Click event of the ViewButton control.
  140. /// </summary>
  141. /// <param name="sender">The source of the event.</param>
  142. /// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param>
  143. async void ViewButton_Click(object sender, RoutedEventArgs e)
  144. {
  145. var menu = new DisplayPreferencesMenu
  146. {
  147. FolderId = Folder.Id,
  148. MainPage = this
  149. };
  150. menu.ShowModal(this.GetWindow());
  151. try
  152. {
  153. await App.Instance.ApiClient.UpdateDisplayPreferencesAsync(App.Instance.CurrentUser.Id, Folder.Id, DisplayPreferences);
  154. }
  155. catch (HttpException)
  156. {
  157. App.Instance.ShowDefaultErrorMessage();
  158. }
  159. }
  160. /// <summary>
  161. /// Refreshes the sidebar.
  162. /// </summary>
  163. private void RefreshSidebar()
  164. {
  165. //if (Folder.BackdropCount > 0)
  166. //{
  167. // //backdropImage.Source = App.Instance.GetBitmapImage(ApiClient.GetImageUrl(Folder.Id, Model.Entities.ImageType.Backdrop, width: 560, height: 315));
  168. // backdropImage.Visibility = Visibility.Visible;
  169. //}
  170. //else
  171. //{
  172. // backdropImage.Source = null;
  173. // backdropImage.Visibility = Visibility.Collapsed;
  174. //}
  175. }
  176. /// <summary>
  177. /// Handles current item selection changes
  178. /// </summary>
  179. protected override void OnCurrentItemChanged()
  180. {
  181. base.OnCurrentItemChanged();
  182. // Name
  183. /*if (CurrentItem != null)
  184. {
  185. txtName.Visibility = CurrentItem.HasLogo ? Visibility.Collapsed : Visibility.Visible;
  186. currentItemLogo.Visibility = CurrentItem.HasLogo ? Visibility.Visible : Visibility.Collapsed;
  187. if (CurrentItem.HasLogo)
  188. {
  189. var uri = ApiClient.GetImageUrl(CurrentItem.Id, ImageType.Logo, maxWidth: 400, maxHeight: 125);
  190. Dispatcher.InvokeAsync(() => currentItemLogo.Source = App.Instance.GetBitmapImage(new Uri(uri, UriKind.Absolute)));
  191. }
  192. else
  193. {
  194. var name = CurrentItem.Name;
  195. if (!CurrentItem.IsType("Season") && CurrentItem.IndexNumber.HasValue)
  196. {
  197. name = CurrentItem.IndexNumber + " - " + name;
  198. }
  199. if (CurrentItem.IsType("Movie") && CurrentItem.ProductionYear.HasValue)
  200. {
  201. name += " (" + CurrentItem.ProductionYear + ")";
  202. }
  203. txtName.Text = name;
  204. }
  205. }
  206. else
  207. {
  208. txtName.Visibility = Visibility.Collapsed;
  209. currentItemLogo.Visibility = Visibility.Collapsed;
  210. }
  211. // PremiereDate
  212. if (CurrentItem != null && CurrentItem.PremiereDate.HasValue && !CurrentItem.IsType("Series"))
  213. {
  214. pnlPremiereDate.Visibility = Visibility.Visible;
  215. var prefix = CurrentItem.IsType("Episode") ? "Aired" : CurrentItem.IsType("Series") ? "First Aired" : "Premiered";
  216. txtPremiereDate.Text = string.Format("{0} {1}", prefix, CurrentItem.PremiereDate.Value.ToShortDateString());
  217. }
  218. else
  219. {
  220. pnlPremiereDate.Visibility = Visibility.Collapsed;
  221. }
  222. // Taglines
  223. if (CurrentItem != null && CurrentItem.Taglines != null && CurrentItem.Taglines.Length > 0)
  224. {
  225. txtTagLine.Visibility = Visibility.Visible;
  226. txtTagLine.Text = CurrentItem.Taglines[0];
  227. }
  228. else
  229. {
  230. txtTagLine.Visibility = Visibility.Collapsed;
  231. }
  232. // Genres
  233. if (CurrentItem != null && CurrentItem.Genres != null && CurrentItem.Genres.Length > 0)
  234. {
  235. txtGenres.Visibility = Visibility.Visible;
  236. // Try to keep them on one line by limiting to three
  237. txtGenres.Text = string.Join(" / ", CurrentItem.Genres.Take(3));
  238. }
  239. else
  240. {
  241. txtGenres.Visibility = Visibility.Collapsed;
  242. }
  243. // Season Number
  244. if (CurrentItem != null && CurrentItem.ParentIndexNumber.HasValue && CurrentItem.IsType("Episode"))
  245. {
  246. txtSeasonHeader.Visibility = Visibility.Visible;
  247. txtSeasonHeader.Text = string.Format("Season {0}", CurrentItem.ParentIndexNumber);
  248. }
  249. else
  250. {
  251. txtSeasonHeader.Visibility = Visibility.Collapsed;
  252. }
  253. UpdateSeriesAirTime();
  254. UpdateMiscellaneousFields();
  255. UpdateCommunityRating();
  256. UpdateVideoInfo();
  257. UpdateAudioInfo();*/
  258. }
  259. /// <summary>
  260. /// Updates the series air time.
  261. /// </summary>
  262. private void UpdateSeriesAirTime()
  263. {
  264. /*if (CurrentItem != null && CurrentItem.SeriesInfo != null)
  265. {
  266. var series = CurrentItem.SeriesInfo;
  267. txtSeriesAirTime.Visibility = Visibility.Visible;
  268. if (series.Status.HasValue && series.Status.Value == SeriesStatus.Ended)
  269. {
  270. txtSeriesAirTime.Text = "Ended";
  271. }
  272. else
  273. {
  274. string txt = "Airs";
  275. if (series.AirDays.Length > 0)
  276. {
  277. if (series.AirDays.Length == 7)
  278. {
  279. txt += " Everyday";
  280. }
  281. else
  282. {
  283. txt += " " + series.AirDays[0].ToString();
  284. }
  285. }
  286. if (CurrentItem.Studios != null && CurrentItem.Studios.Length > 0)
  287. {
  288. txt += " on " + CurrentItem.Studios[0].Name;
  289. }
  290. if (!string.IsNullOrEmpty(series.AirTime))
  291. {
  292. txt += " at " + series.AirTime;
  293. }
  294. txtSeriesAirTime.Text = txt;
  295. }
  296. }
  297. else
  298. {
  299. txtSeriesAirTime.Visibility = Visibility.Collapsed;
  300. }*/
  301. }
  302. /// <summary>
  303. /// Updates the miscellaneous fields.
  304. /// </summary>
  305. private void UpdateMiscellaneousFields()
  306. {
  307. /*if (CurrentItem == null)
  308. {
  309. pnlRuntime.Visibility = Visibility.Collapsed;
  310. pnlOfficialRating.Visibility = Visibility.Collapsed;
  311. }
  312. else
  313. {
  314. var runtimeTicks = CurrentItem.RunTimeTicks ?? 0;
  315. // Runtime
  316. if (runtimeTicks > 0)
  317. {
  318. pnlRuntime.Visibility = Visibility.Visible;
  319. txtRuntime.Text = string.Format("{0} minutes", Convert.ToInt32(TimeSpan.FromTicks(runtimeTicks).TotalMinutes));
  320. }
  321. else
  322. {
  323. pnlRuntime.Visibility = Visibility.Collapsed;
  324. }
  325. pnlOfficialRating.Visibility = string.IsNullOrEmpty(CurrentItem.OfficialRating) ? Visibility.Collapsed : Visibility.Visible;
  326. }
  327. // Show the parent panel only if one of the children is visible
  328. pnlMisc.Visibility = pnlRuntime.Visibility == Visibility.Visible ||
  329. pnlOfficialRating.Visibility == Visibility.Visible
  330. ? Visibility.Visible
  331. : Visibility.Collapsed;*/
  332. }
  333. /// <summary>
  334. /// Updates the community rating.
  335. /// </summary>
  336. private void UpdateCommunityRating()
  337. {
  338. /*// Community Rating
  339. if (CurrentItem != null && CurrentItem.CommunityRating.HasValue)
  340. {
  341. pnlRating.Visibility = Visibility.Visible;
  342. }
  343. else
  344. {
  345. pnlRating.Visibility = Visibility.Collapsed;
  346. return;
  347. }
  348. var rating = CurrentItem.CommunityRating.Value;
  349. for (var i = 0; i < 10; i++)
  350. {
  351. if (rating < i - 1)
  352. {
  353. TreeHelper.FindChild<Image>(this, "communityRatingImage" + i).SetResourceReference(Image.StyleProperty, "CommunityRatingImageEmpty");
  354. }
  355. else if (rating < i)
  356. {
  357. TreeHelper.FindChild<Image>(this, "communityRatingImage" + i).SetResourceReference(Image.StyleProperty, "CommunityRatingImageHalf");
  358. }
  359. else
  360. {
  361. TreeHelper.FindChild<Image>(this, "communityRatingImage" + i).SetResourceReference(Image.StyleProperty, "CommunityRatingImageFull");
  362. }
  363. }*/
  364. }
  365. /// <summary>
  366. /// Updates the video info.
  367. /// </summary>
  368. private void UpdateVideoInfo()
  369. {
  370. /*if (CurrentItem != null && CurrentItem.VideoInfo != null)
  371. {
  372. pnlVideoInfo.Visibility = Visibility.Visible;
  373. }
  374. else
  375. {
  376. pnlVideoInfo.Visibility = Visibility.Collapsed;
  377. return;
  378. }
  379. var videoInfo = CurrentItem.VideoInfo;
  380. if (videoInfo.VideoType == VideoType.VideoFile)
  381. {
  382. txtVideoType.Text = Path.GetExtension(CurrentItem.Path).Replace(".", string.Empty).ToLower();
  383. }
  384. else
  385. {
  386. txtVideoType.Text = videoInfo.VideoType.ToString().ToLower();
  387. }
  388. txtVideoResolution.Text = GetResolutionText(videoInfo);
  389. pnlVideoResolution.Visibility = string.IsNullOrEmpty(txtVideoResolution.Text) ? Visibility.Collapsed : Visibility.Visible;
  390. if (!string.IsNullOrEmpty(videoInfo.Codec))
  391. {
  392. pnlVideoCodec.Visibility = Visibility.Visible;
  393. txtVideoCodec.Text = videoInfo.Codec.ToLower();
  394. }
  395. else
  396. {
  397. pnlVideoCodec.Visibility = Visibility.Collapsed;
  398. }
  399. var audio = videoInfo.GetDefaultAudioStream();
  400. if (audio == null || string.IsNullOrEmpty(audio.Codec))
  401. {
  402. pnlAudioCodec.Visibility = Visibility.Collapsed;
  403. }
  404. else
  405. {
  406. pnlAudioCodec.Visibility = Visibility.Visible;
  407. txtAudioCodec.Text = audio.Codec.ToLower();
  408. }*/
  409. }
  410. /// <summary>
  411. /// Updates the audio info.
  412. /// </summary>
  413. private void UpdateAudioInfo()
  414. {
  415. /*if (CurrentItem != null && CurrentItem.AudioInfo != null)
  416. {
  417. pnlAudioInfo.Visibility = Visibility.Visible;
  418. }
  419. else
  420. {
  421. pnlAudioInfo.Visibility = Visibility.Collapsed;
  422. return;
  423. }
  424. var audioInfo = CurrentItem.AudioInfo;
  425. txtAudioType.Text = Path.GetExtension(CurrentItem.Path).Replace(".", string.Empty).ToLower();
  426. if (audioInfo.BitRate > 0)
  427. {
  428. pnlAudioBitrate.Visibility = Visibility.Visible;
  429. txtAudioBitrate.Text = (audioInfo.BitRate / 1000).ToString() + "kbps";
  430. }
  431. else
  432. {
  433. pnlAudioBitrate.Visibility = Visibility.Collapsed;
  434. }*/
  435. }
  436. /*private string GetResolutionText(VideoInfo info)
  437. {
  438. var scanType = info.ScanType ?? string.Empty;
  439. if (info.Height == 1080)
  440. {
  441. if (scanType.Equals("progressive", StringComparison.OrdinalIgnoreCase))
  442. {
  443. return "1080p";
  444. }
  445. if (scanType.Equals("interlaced", StringComparison.OrdinalIgnoreCase))
  446. {
  447. return "1080i";
  448. }
  449. }
  450. if (info.Height == 720)
  451. {
  452. if (scanType.Equals("progressive", StringComparison.OrdinalIgnoreCase))
  453. {
  454. return "720p";
  455. }
  456. if (scanType.Equals("interlaced", StringComparison.OrdinalIgnoreCase))
  457. {
  458. return "720i";
  459. }
  460. }
  461. if (info.Height == 480)
  462. {
  463. if (scanType.Equals("progressive", StringComparison.OrdinalIgnoreCase))
  464. {
  465. return "480p";
  466. }
  467. if (scanType.Equals("interlaced", StringComparison.OrdinalIgnoreCase))
  468. {
  469. return "480i";
  470. }
  471. }
  472. return info.Width == 0 || info.Height == 0 ? string.Empty : info.Width + "x" + info.Height;
  473. }*/
  474. }
  475. }