aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Plugins.DefaultTheme/Resources/AppResources.cs
blob: 3ca6e8df2b8edde709d26fc836e6a5b6fec6a8ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Net;
using MediaBrowser.UI;
using MediaBrowser.UI.Controller;
using MediaBrowser.UI.Controls;
using MediaBrowser.UI.Playback;
using MediaBrowser.UI.Playback.InternalPlayer;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace MediaBrowser.Plugins.DefaultTheme.Resources
{
    /// <summary>
    /// Class AppResources
    /// </summary>
    public partial class AppResources : ResourceDictionary
    {
        /// <summary>
        /// Gets the instance.
        /// </summary>
        /// <value>The instance.</value>
        public static AppResources Instance { get; private set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="AppResources" /> class.
        /// </summary>
        public AppResources()
        {
            InitializeComponent();

            Instance = this;

            UIKernel.Instance.PlaybackManager.PlaybackStarted += PlaybackManager_PlaybackStarted;
            UIKernel.Instance.PlaybackManager.PlaybackCompleted += PlaybackManager_PlaybackCompleted;
        }

        /// <summary>
        /// Handles the Click event of the NowPlayingButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param>
        void NowPlaying_Click(object sender, RoutedEventArgs e)
        {
            App.Instance.NavigateToInternalPlayerPage();
        }

        /// <summary>
        /// Handles the PlaybackCompleted event of the PlaybackManager control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="PlaybackStopEventArgs" /> instance containing the event data.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        void PlaybackManager_PlaybackCompleted(object sender, PlaybackStopEventArgs e)
        {
            App.Instance.ApplicationWindow.Dispatcher.Invoke(() => NowPlayingButton.Visibility = Visibility.Collapsed);
        }

        /// <summary>
        /// Handles the PlaybackStarted event of the PlaybackManager control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="PlaybackEventArgs" /> instance containing the event data.</param>
        void PlaybackManager_PlaybackStarted(object sender, PlaybackEventArgs e)
        {
            if (e.Player is BaseInternalMediaPlayer)
            {
                App.Instance.ApplicationWindow.Dispatcher.Invoke(() => NowPlayingButton.Visibility = Visibility.Visible);
            }
        }

        /// <summary>
        /// Weathers the button click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param>
        void WeatherButtonClick(object sender, RoutedEventArgs e)
        {
            App.Instance.DisplayWeather();
        }

        /// <summary>
        /// Settingses the button click.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param>
        void SettingsButtonClick(object sender, RoutedEventArgs e)
        {
            App.Instance.NavigateToSettingsPage();
        }

        /// <summary>
        /// This is a common element that appears on every page.
        /// </summary>
        /// <value>The view button.</value>
        public Button ViewButton
        {
            get
            {
                return TreeHelper.FindChild<Button>(App.Instance.ApplicationWindow, "ViewButton");
            }
        }

        /// <summary>
        /// Gets the now playing button.
        /// </summary>
        /// <value>The now playing button.</value>
        private Button NowPlayingButton
        {
            get
            {
                return TreeHelper.FindChild<Button>(App.Instance.ApplicationWindow, "NowPlayingButton");
            }
        }

        /// <summary>
        /// This is a common element that appears on every page.
        /// </summary>
        /// <value>The page title panel.</value>
        public StackPanel PageTitlePanel
        {
            get
            {
                return TreeHelper.FindChild<StackPanel>(App.Instance.ApplicationWindow, "PageTitlePanel");
            }
        }

        /// <summary>
        /// Gets the content of the header.
        /// </summary>
        /// <value>The content of the header.</value>
        public StackPanel HeaderContent
        {
            get
            {
                return TreeHelper.FindChild<StackPanel>(App.Instance.ApplicationWindow, "HeaderContent");
            }
        }
        
        /// <summary>
        /// Sets the default page title.
        /// </summary>
        public void SetDefaultPageTitle()
        {
            var img = new Image { };
            img.SetResourceReference(Image.StyleProperty, "MBLogoImageWhite");

            SetPageTitle(img);
        }

        /// <summary>
        /// Clears the page title.
        /// </summary>
        public void ClearPageTitle()
        {
            PageTitlePanel.Children.Clear();
        }

        /// <summary>
        /// Sets the page title.
        /// </summary>
        /// <param name="item">The item.</param>
        public async Task SetPageTitle(BaseItemDto item)
        {
            if (item.HasLogo || !string.IsNullOrEmpty(item.ParentLogoItemId))
            {
                var url = App.Instance.ApiClient.GetLogoImageUrl(item, new ImageOptions
                    {
                        Quality = 100
                    });

                try
                {
                    var image = await App.Instance.GetRemoteImageAsync(url);

                    image.SetResourceReference(Image.StyleProperty, "ItemLogo");
                    SetPageTitle(image);
                }
                catch (HttpException)
                {
                    SetPageTitleText(item);
                }
            }
            else
            {
                SetPageTitleText(item);
            }
        }

        /// <summary>
        /// Sets the page title text.
        /// </summary>
        /// <param name="item">The item.</param>
        private void SetPageTitleText(BaseItemDto item)
        {
            SetPageTitle(item.SeriesName ?? item.Album ?? item.Name);
        }

        /// <summary>
        /// Sets the page title.
        /// </summary>
        /// <param name="title">The title.</param>
        public void SetPageTitle(string title)
        {
            var textblock = new TextBlock { Text = title, Margin = new Thickness(0, 10, 0, 0) };
            textblock.SetResourceReference(TextBlock.StyleProperty, "Heading2TextBlockStyle");

            SetPageTitle(textblock);
        }

        /// <summary>
        /// Sets the page title.
        /// </summary>
        /// <param name="element">The element.</param>
        public void SetPageTitle(UIElement element)
        {
            var panel = PageTitlePanel;

            panel.Children.Clear();
            panel.Children.Add(element);
        }
    }
}