BaseDetailPage.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. using MediaBrowser.Model.Dto;
  2. using MediaBrowser.Model.Net;
  3. using MediaBrowser.UI.Controller;
  4. using MediaBrowser.UI.Playback;
  5. using System.Collections.Generic;
  6. using System.Threading.Tasks;
  7. namespace MediaBrowser.UI.Pages
  8. {
  9. /// <summary>
  10. /// Provides a base class for detail pages
  11. /// </summary>
  12. public abstract class BaseDetailPage : BasePage
  13. {
  14. /// <summary>
  15. /// The _item id
  16. /// </summary>
  17. private string _itemId;
  18. /// <summary>
  19. /// Gets or sets the id of the item being displayed
  20. /// </summary>
  21. /// <value>The item id.</value>
  22. protected string ItemId
  23. {
  24. get { return _itemId; }
  25. private set
  26. {
  27. _itemId = value;
  28. OnPropertyChanged("ItemId");
  29. }
  30. }
  31. /// <summary>
  32. /// The _item
  33. /// </summary>
  34. private BaseItemDto _item;
  35. /// <summary>
  36. /// Gets or sets the item.
  37. /// </summary>
  38. /// <value>The item.</value>
  39. public BaseItemDto Item
  40. {
  41. get { return _item; }
  42. set
  43. {
  44. _item = value;
  45. OnPropertyChanged("Item");
  46. OnItemChanged();
  47. }
  48. }
  49. /// <summary>
  50. /// Gets a value indicating whether this instance can resume.
  51. /// </summary>
  52. /// <value><c>true</c> if this instance can resume; otherwise, <c>false</c>.</value>
  53. protected bool CanResume
  54. {
  55. get { return Item.CanResume; }
  56. }
  57. /// <summary>
  58. /// Gets a value indicating whether this instance can queue.
  59. /// </summary>
  60. /// <value><c>true</c> if this instance can queue; otherwise, <c>false</c>.</value>
  61. protected bool CanQueue
  62. {
  63. get { return true; }
  64. }
  65. /// <summary>
  66. /// Gets a value indicating whether this instance can play trailer.
  67. /// </summary>
  68. /// <value><c>true</c> if this instance can play trailer; otherwise, <c>false</c>.</value>
  69. protected bool CanPlayTrailer
  70. {
  71. get { return Item.HasTrailer; }
  72. }
  73. /// <summary>
  74. /// Initializes a new instance of the <see cref="BaseDetailPage" /> class.
  75. /// </summary>
  76. /// <param name="itemId">The item id.</param>
  77. protected BaseDetailPage(string itemId)
  78. : base()
  79. {
  80. ItemId = itemId;
  81. }
  82. /// <summary>
  83. /// Called when [property changed].
  84. /// </summary>
  85. /// <param name="name">The name.</param>
  86. public async override void OnPropertyChanged(string name)
  87. {
  88. base.OnPropertyChanged(name);
  89. // Reload the item when the itemId changes
  90. if (name.Equals("ItemId"))
  91. {
  92. await ReloadItem();
  93. }
  94. }
  95. /// <summary>
  96. /// Reloads the item.
  97. /// </summary>
  98. /// <returns>Task.</returns>
  99. private async Task ReloadItem()
  100. {
  101. try
  102. {
  103. Item = await App.Instance.ApiClient.GetItemAsync(ItemId, App.Instance.CurrentUser.Id);
  104. }
  105. catch (HttpException)
  106. {
  107. App.Instance.ShowDefaultErrorMessage();
  108. }
  109. }
  110. /// <summary>
  111. /// Called when [item changed].
  112. /// </summary>
  113. protected virtual void OnItemChanged()
  114. {
  115. SetBackdrops(Item);
  116. }
  117. /// <summary>
  118. /// Plays this instance.
  119. /// </summary>
  120. public async void Play()
  121. {
  122. await UIKernel.Instance.PlaybackManager.Play(new PlayOptions
  123. {
  124. Items = new List<BaseItemDto> { Item }
  125. });
  126. }
  127. /// <summary>
  128. /// Resumes this instance.
  129. /// </summary>
  130. public async void Resume()
  131. {
  132. await UIKernel.Instance.PlaybackManager.Play(new PlayOptions
  133. {
  134. Items = new List<BaseItemDto> { Item },
  135. Resume = true
  136. });
  137. }
  138. /// <summary>
  139. /// Queues this instance.
  140. /// </summary>
  141. public void Queue()
  142. {
  143. }
  144. }
  145. }