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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace MediaBrowser.ServerApplication.Controls
{
/// <summary>
/// Interaction logic for ItemUpdateNotification.xaml
/// </summary>
public partial class ItemUpdateNotification : UserControl
{
/// <summary>
/// The logger
/// </summary>
private readonly ILogger Logger;
/// <summary>
/// Gets the children changed event args.
/// </summary>
/// <value>The children changed event args.</value>
private BaseItem Item
{
get { return DataContext as BaseItem; }
}
/// <summary>
/// Initializes a new instance of the <see cref="ItemUpdateNotification" /> class.
/// </summary>
public ItemUpdateNotification(ILogger logger)
{
if (logger == null)
{
throw new ArgumentNullException("logger");
}
Logger = logger;
InitializeComponent();
Loaded += ItemUpdateNotification_Loaded;
}
/// <summary>
/// Handles the Loaded event of the ItemUpdateNotification 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 ItemUpdateNotification_Loaded(object sender, RoutedEventArgs e)
{
DisplayItem(Item);
}
/// <summary>
/// Gets the display name.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="includeParentName">if set to <c>true</c> [include parent name].</param>
/// <returns>System.String.</returns>
internal static string GetDisplayName(BaseItem item, bool includeParentName)
{
var name = item.Name;
if (item.ProductionYear.HasValue && !(item is Episode))
{
name += string.Format(" ({0})", item.ProductionYear);
}
var episode = item as Episode;
if (episode != null)
{
var indexNumbers = new List<int>();
if (episode.Season.IndexNumber.HasValue)
{
indexNumbers.Add(episode.Season.IndexNumber.Value);
}
if (episode.IndexNumber.HasValue)
{
indexNumbers.Add(episode.IndexNumber.Value);
}
var indexNumber = string.Join(".", indexNumbers.ToArray());
name = string.Format("{0} - {1}", indexNumber, name);
if (includeParentName)
{
name = episode.Series.Name + " - " + name;
}
}
if (includeParentName)
{
var season = item as Season;
if (season != null)
{
name = season.Series.Name + " - " + name;
}
}
return name;
}
/// <summary>
/// Displays the parent title.
/// </summary>
/// <param name="item">The item.</param>
private void DisplayParentTitle(BaseItem item)
{
if (!(item is Episode || item is Season))
{
txtParentName.Visibility = Visibility.Collapsed;
imgParentLogo.Visibility = Visibility.Collapsed;
return;
}
var series = item is Episode ? (item as Episode).Series : (item as Season).Series;
var logo = series.GetImage(ImageType.Logo);
if (string.IsNullOrEmpty(logo))
{
imgParentLogo.Visibility = Visibility.Collapsed;
txtParentName.Visibility = Visibility.Visible;
}
else
{
imgParentLogo.Visibility = Visibility.Visible;
txtParentName.Visibility = Visibility.Collapsed;
imgParentLogo.Source = App.Instance.GetBitmapImage(logo);
}
txtParentName.Text = series.Name;
}
/// <summary>
/// Displays the title.
/// </summary>
/// <param name="item">The item.</param>
private void DisplayTitle(BaseItem item)
{
txtName.Text = GetDisplayName(item, false);
}
/// <summary>
/// Displays the item.
/// </summary>
/// <param name="item">The item.</param>
private void DisplayItem(BaseItem item)
{
DisplayParentTitle(item);
DisplayTitle(item);
DisplayRating(item);
var path = MultiItemUpdateNotification.GetImagePath(item);
if (string.IsNullOrEmpty(path))
{
img.Visibility = Visibility.Collapsed;
}
else
{
img.Visibility = Visibility.Visible;
try
{
img.Source = App.Instance.GetBitmapImage(path);
}
catch (FileNotFoundException)
{
Logger.Error("Image file not found {0}", path);
}
}
if (string.IsNullOrEmpty(item.Overview))
{
txtOverview.Visibility = Visibility.Collapsed;
}
else
{
txtOverview.Visibility = Visibility.Visible;
txtOverview.Text = item.Overview;
}
if (item.Taglines == null || item.Taglines.Count == 0)
{
txtTagline.Visibility = Visibility.Collapsed;
}
else
{
txtTagline.Visibility = Visibility.Visible;
txtTagline.Text = item.Taglines[0];
}
if (!item.PremiereDate.HasValue)
{
txtPremeireDate.Visibility = Visibility.Collapsed;
}
else
{
txtPremeireDate.Visibility = Visibility.Visible;
txtPremeireDate.Text = "Premiered " + item.PremiereDate.Value.ToLocalTime().ToShortDateString();
}
}
/// <summary>
/// Displays the rating.
/// </summary>
/// <param name="item">The item.</param>
private void DisplayRating(BaseItem item)
{
if (!item.CommunityRating.HasValue)
{
pnlRating.Visibility = Visibility.Collapsed;
return;
}
pnlRating.Children.Clear();
pnlRating.Visibility = Visibility.Visible;
var rating = item.CommunityRating.Value;
for (var i = 0; i < 10; i++)
{
Image image;
if (rating < i - 1)
{
image = App.Instance.GetImage(new Uri("../Resources/Images/starEmpty.png", UriKind.Relative));
}
else if (rating < i)
{
image = App.Instance.GetImage(new Uri("../Resources/Images/starHalf.png", UriKind.Relative));
}
else
{
image = App.Instance.GetImage(new Uri("../Resources/Images/starFull.png", UriKind.Relative));
}
RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.Fant);
image.Stretch = Stretch.Uniform;
image.Height = 16;
pnlRating.Children.Add(image);
}
}
}
}
|