From 767cdc1f6f6a63ce997fc9476911e2c361f9d402 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Wed, 20 Feb 2013 20:33:05 -0500 Subject: Pushing missing changes --- .../ViewModels/ChapterInfoDtoViewModel.cs | 182 +++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 MediaBrowser.UI/ViewModels/ChapterInfoDtoViewModel.cs (limited to 'MediaBrowser.UI/ViewModels/ChapterInfoDtoViewModel.cs') diff --git a/MediaBrowser.UI/ViewModels/ChapterInfoDtoViewModel.cs b/MediaBrowser.UI/ViewModels/ChapterInfoDtoViewModel.cs new file mode 100644 index 000000000..53ab787c4 --- /dev/null +++ b/MediaBrowser.UI/ViewModels/ChapterInfoDtoViewModel.cs @@ -0,0 +1,182 @@ +using MediaBrowser.Model.DTO; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Net; +using System; +using System.Linq; +using System.Windows.Media.Imaging; + +namespace MediaBrowser.UI.ViewModels +{ + /// + /// Class ChapterInfoDtoViewModel + /// + public class ChapterInfoDtoViewModel : BaseViewModel + { + /// + /// Gets or sets the image download options. + /// + /// The image download options. + public ImageOptions ImageDownloadOptions { get; set; } + + /// + /// The _image width + /// + private double _imageWidth; + /// + /// Gets or sets the width of the image. + /// + /// The width of the image. + public double ImageWidth + { + get { return _imageWidth; } + + set + { + _imageWidth = value; + OnPropertyChanged("ImageWidth"); + } + } + + /// + /// The _image height + /// + private double _imageHeight; + /// + /// Gets or sets the height of the image. + /// + /// The height of the image. + public double ImageHeight + { + get { return _imageHeight; } + + set + { + _imageHeight = value; + OnPropertyChanged("ImageHeight"); + } + } + + /// + /// The _item + /// + private ChapterInfoDto _chapter; + /// + /// Gets or sets the item. + /// + /// The item. + public ChapterInfoDto Chapter + { + get { return _chapter; } + + set + { + _chapter = value; + OnPropertyChanged("Chapter"); + OnPropertyChanged("TimeString"); + OnChapterChanged(); + } + } + + /// + /// The _item + /// + private DtoBaseItem _item; + /// + /// Gets or sets the item. + /// + /// The item. + public DtoBaseItem Item + { + get { return _item; } + + set + { + _item = value; + OnPropertyChanged("Item"); + } + } + + /// + /// Gets the time string. + /// + /// The time string. + public string TimeString + { + get + { + var time = TimeSpan.FromTicks(Chapter.StartPositionTicks); + + return time.ToString(time.TotalHours < 1 ? "m':'ss" : "h':'mm':'ss"); + } + } + + /// + /// The _image + /// + private BitmapImage _image; + /// + /// Gets the image. + /// + /// The image. + public BitmapImage Image + { + get { return _image; } + set + { + _image = value; + OnPropertyChanged("Image"); + } + } + + /// + /// Called when [item changed]. + /// + private async void OnChapterChanged() + { + var options = ImageDownloadOptions ?? new ImageOptions { }; + + options.ImageType = ImageType.ChapterImage; + options.ImageIndex = Item.Chapters.IndexOf(Chapter); + + try + { + Image = await App.Instance.GetRemoteBitmapAsync(App.Instance.ApiClient.GetImageUrl(Item, options)); + } + catch (HttpException) + { + } + } + + /// + /// Gets the height of the chapter image. + /// + /// The item. + /// The height. + /// The default width. + /// System.Double. + public static double GetChapterImageWidth(DtoBaseItem item, double height, double defaultWidth) + { + var width = defaultWidth; + + if (item.MediaStreams != null) + { + var videoStream = item.MediaStreams.FirstOrDefault(s => s.Type == MediaStreamType.Video); + + if (videoStream != null) + { + double streamHeight = videoStream.Height ?? 0; + double streamWidth = videoStream.Width ?? 0; + + if (streamHeight > 0 && streamWidth > 0) + { + var aspectRatio = streamWidth / streamHeight; + + width = height * aspectRatio; + } + } + } + + return width; + } + } +} -- cgit v1.2.3