AppResources.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. using System.Threading.Tasks;
  2. using MediaBrowser.Model.Dto;
  3. using MediaBrowser.Model.Net;
  4. using MediaBrowser.UI;
  5. using MediaBrowser.UI.Controller;
  6. using MediaBrowser.UI.Controls;
  7. using MediaBrowser.UI.Playback;
  8. using MediaBrowser.UI.Playback.InternalPlayer;
  9. using System.ComponentModel.Composition;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. namespace MediaBrowser.Plugins.DefaultTheme.Resources
  13. {
  14. /// <summary>
  15. /// Class AppResources
  16. /// </summary>
  17. [Export(typeof(ResourceDictionary))]
  18. public partial class AppResources : ResourceDictionary
  19. {
  20. /// <summary>
  21. /// Gets the instance.
  22. /// </summary>
  23. /// <value>The instance.</value>
  24. public static AppResources Instance { get; private set; }
  25. /// <summary>
  26. /// Initializes a new instance of the <see cref="AppResources" /> class.
  27. /// </summary>
  28. public AppResources()
  29. {
  30. InitializeComponent();
  31. Instance = this;
  32. UIKernel.Instance.PlaybackManager.PlaybackStarted += PlaybackManager_PlaybackStarted;
  33. UIKernel.Instance.PlaybackManager.PlaybackCompleted += PlaybackManager_PlaybackCompleted;
  34. }
  35. /// <summary>
  36. /// Handles the Click event of the NowPlayingButton control.
  37. /// </summary>
  38. /// <param name="sender">The source of the event.</param>
  39. /// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param>
  40. void NowPlaying_Click(object sender, RoutedEventArgs e)
  41. {
  42. App.Instance.NavigateToInternalPlayerPage();
  43. }
  44. /// <summary>
  45. /// Handles the PlaybackCompleted event of the PlaybackManager control.
  46. /// </summary>
  47. /// <param name="sender">The source of the event.</param>
  48. /// <param name="e">The <see cref="PlaybackStopEventArgs" /> instance containing the event data.</param>
  49. /// <exception cref="System.NotImplementedException"></exception>
  50. void PlaybackManager_PlaybackCompleted(object sender, PlaybackStopEventArgs e)
  51. {
  52. App.Instance.ApplicationWindow.Dispatcher.Invoke(() => NowPlayingButton.Visibility = Visibility.Collapsed);
  53. }
  54. /// <summary>
  55. /// Handles the PlaybackStarted event of the PlaybackManager control.
  56. /// </summary>
  57. /// <param name="sender">The source of the event.</param>
  58. /// <param name="e">The <see cref="PlaybackEventArgs" /> instance containing the event data.</param>
  59. void PlaybackManager_PlaybackStarted(object sender, PlaybackEventArgs e)
  60. {
  61. if (e.Player is BaseInternalMediaPlayer)
  62. {
  63. App.Instance.ApplicationWindow.Dispatcher.Invoke(() => NowPlayingButton.Visibility = Visibility.Visible);
  64. }
  65. }
  66. /// <summary>
  67. /// Weathers the button click.
  68. /// </summary>
  69. /// <param name="sender">The sender.</param>
  70. /// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param>
  71. void WeatherButtonClick(object sender, RoutedEventArgs e)
  72. {
  73. App.Instance.DisplayWeather();
  74. }
  75. /// <summary>
  76. /// Settingses the button click.
  77. /// </summary>
  78. /// <param name="sender">The sender.</param>
  79. /// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param>
  80. void SettingsButtonClick(object sender, RoutedEventArgs e)
  81. {
  82. App.Instance.NavigateToSettingsPage();
  83. }
  84. /// <summary>
  85. /// This is a common element that appears on every page.
  86. /// </summary>
  87. /// <value>The view button.</value>
  88. public Button ViewButton
  89. {
  90. get
  91. {
  92. return TreeHelper.FindChild<Button>(App.Instance.ApplicationWindow, "ViewButton");
  93. }
  94. }
  95. /// <summary>
  96. /// Gets the now playing button.
  97. /// </summary>
  98. /// <value>The now playing button.</value>
  99. private Button NowPlayingButton
  100. {
  101. get
  102. {
  103. return TreeHelper.FindChild<Button>(App.Instance.ApplicationWindow, "NowPlayingButton");
  104. }
  105. }
  106. /// <summary>
  107. /// This is a common element that appears on every page.
  108. /// </summary>
  109. /// <value>The page title panel.</value>
  110. public StackPanel PageTitlePanel
  111. {
  112. get
  113. {
  114. return TreeHelper.FindChild<StackPanel>(App.Instance.ApplicationWindow, "PageTitlePanel");
  115. }
  116. }
  117. /// <summary>
  118. /// Gets the content of the header.
  119. /// </summary>
  120. /// <value>The content of the header.</value>
  121. public StackPanel HeaderContent
  122. {
  123. get
  124. {
  125. return TreeHelper.FindChild<StackPanel>(App.Instance.ApplicationWindow, "HeaderContent");
  126. }
  127. }
  128. /// <summary>
  129. /// Sets the default page title.
  130. /// </summary>
  131. public void SetDefaultPageTitle()
  132. {
  133. var img = new Image { };
  134. img.SetResourceReference(Image.StyleProperty, "MBLogoImageWhite");
  135. SetPageTitle(img);
  136. }
  137. /// <summary>
  138. /// Clears the page title.
  139. /// </summary>
  140. public void ClearPageTitle()
  141. {
  142. PageTitlePanel.Children.Clear();
  143. }
  144. /// <summary>
  145. /// Sets the page title.
  146. /// </summary>
  147. /// <param name="item">The item.</param>
  148. public async Task SetPageTitle(BaseItemDto item)
  149. {
  150. if (item.HasLogo || !string.IsNullOrEmpty(item.ParentLogoItemId))
  151. {
  152. var url = App.Instance.ApiClient.GetLogoImageUrl(item, new ImageOptions
  153. {
  154. Quality = 100
  155. });
  156. try
  157. {
  158. var image = await App.Instance.GetRemoteImageAsync(url);
  159. image.SetResourceReference(Image.StyleProperty, "ItemLogo");
  160. SetPageTitle(image);
  161. }
  162. catch (HttpException)
  163. {
  164. SetPageTitleText(item);
  165. }
  166. }
  167. else
  168. {
  169. SetPageTitleText(item);
  170. }
  171. }
  172. /// <summary>
  173. /// Sets the page title text.
  174. /// </summary>
  175. /// <param name="item">The item.</param>
  176. private void SetPageTitleText(BaseItemDto item)
  177. {
  178. SetPageTitle(item.SeriesName ?? item.Album ?? item.Name);
  179. }
  180. /// <summary>
  181. /// Sets the page title.
  182. /// </summary>
  183. /// <param name="title">The title.</param>
  184. public void SetPageTitle(string title)
  185. {
  186. var textblock = new TextBlock { Text = title, Margin = new Thickness(0, 10, 0, 0) };
  187. textblock.SetResourceReference(TextBlock.StyleProperty, "Heading2TextBlockStyle");
  188. SetPageTitle(textblock);
  189. }
  190. /// <summary>
  191. /// Sets the page title.
  192. /// </summary>
  193. /// <param name="element">The element.</param>
  194. public void SetPageTitle(UIElement element)
  195. {
  196. var panel = PageTitlePanel;
  197. panel.Children.Clear();
  198. panel.Children.Add(element);
  199. }
  200. }
  201. }