AppResources.cs 7.2 KB

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