aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Plugins.DefaultTheme/Controls/Details/ItemChapters.xaml.cs
blob: 196b92b6993e4d650db4e3bf6b12601d9c3f6c4c (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
using MediaBrowser.Model.DTO;
using MediaBrowser.UI.Controller;
using MediaBrowser.UI.Controls;
using MediaBrowser.UI.Playback;
using MediaBrowser.UI.ViewModels;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace MediaBrowser.Plugins.DefaultTheme.Controls.Details
{
    /// <summary>
    /// Interaction logic for ItemChapters.xaml
    /// </summary>
    public partial class ItemChapters : BaseDetailsControl
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ItemChapters" /> class.
        /// </summary>
        public ItemChapters()
        {
            InitializeComponent();

            lstItems.ItemInvoked += lstItems_ItemInvoked;
        }

        /// <summary>
        /// LSTs the items_ item invoked.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        void lstItems_ItemInvoked(object sender, ItemEventArgs<object> e)
        {
            var chapterViewModel = (ChapterInfoDtoViewModel) e.Argument;

            UIKernel.Instance.PlaybackManager.Play(new PlayOptions
            {
                Items = new List<DtoBaseItem> { Item },
                StartPositionTicks = chapterViewModel.Chapter.StartPositionTicks
            });
        }

        /// <summary>
        /// Called when [item changed].
        /// </summary>
        protected override void OnItemChanged()
        {
            const double height = 297;

            var width = ChapterInfoDtoViewModel.GetChapterImageWidth(Item, height, 528);

            var chapters = Item.Chapters ?? new List<ChapterInfoDto> { };

            lstItems.ItemsSource = new ObservableCollection<ChapterInfoDtoViewModel>(chapters.Select(i => new ChapterInfoDtoViewModel
            {
                Item = Item,
                Chapter = i,
                ImageWidth = width,
                ImageHeight = height,
                ImageDownloadOptions = new ImageOptions
                {
                    MaxHeight = 400
                }
            }));
        }
    }
}