SpecialFeatureViewModel.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using MediaBrowser.Model.Dto;
  2. using MediaBrowser.Model.Entities;
  3. using MediaBrowser.Model.Net;
  4. using System;
  5. using System.Windows.Media.Imaging;
  6. namespace MediaBrowser.UI.ViewModels
  7. {
  8. /// <summary>
  9. /// Class SpecialFeatureViewModel
  10. /// </summary>
  11. public class SpecialFeatureViewModel : BaseViewModel
  12. {
  13. /// <summary>
  14. /// Gets or sets the image download options.
  15. /// </summary>
  16. /// <value>The image download options.</value>
  17. public ImageOptions ImageDownloadOptions { get; set; }
  18. /// <summary>
  19. /// The _image width
  20. /// </summary>
  21. private double _imageWidth;
  22. /// <summary>
  23. /// Gets or sets the width of the image.
  24. /// </summary>
  25. /// <value>The width of the image.</value>
  26. public double ImageWidth
  27. {
  28. get { return _imageWidth; }
  29. set
  30. {
  31. _imageWidth = value;
  32. OnPropertyChanged("ImageWidth");
  33. }
  34. }
  35. /// <summary>
  36. /// The _image height
  37. /// </summary>
  38. private double _imageHeight;
  39. /// <summary>
  40. /// Gets or sets the height of the image.
  41. /// </summary>
  42. /// <value>The height of the image.</value>
  43. public double ImageHeight
  44. {
  45. get { return _imageHeight; }
  46. set
  47. {
  48. _imageHeight = value;
  49. OnPropertyChanged("ImageHeight");
  50. }
  51. }
  52. /// <summary>
  53. /// The _item
  54. /// </summary>
  55. private BaseItemDto _item;
  56. /// <summary>
  57. /// Gets or sets the item.
  58. /// </summary>
  59. /// <value>The item.</value>
  60. public BaseItemDto Item
  61. {
  62. get { return _item; }
  63. set
  64. {
  65. _item = value;
  66. OnPropertyChanged("Item");
  67. OnItemChanged();
  68. }
  69. }
  70. /// <summary>
  71. /// Gets the time string.
  72. /// </summary>
  73. /// <value>The time string.</value>
  74. public string MinutesString
  75. {
  76. get
  77. {
  78. var time = TimeSpan.FromTicks(Item.RunTimeTicks ?? 0);
  79. var minutes = Math.Round(time.TotalMinutes);
  80. if (minutes <= 1)
  81. {
  82. return "1 minute";
  83. }
  84. return string.Format("{0} minutes", minutes);
  85. }
  86. }
  87. /// <summary>
  88. /// The _image
  89. /// </summary>
  90. private BitmapImage _image;
  91. /// <summary>
  92. /// Gets the image.
  93. /// </summary>
  94. /// <value>The image.</value>
  95. public BitmapImage Image
  96. {
  97. get { return _image; }
  98. set
  99. {
  100. _image = value;
  101. OnPropertyChanged("Image");
  102. }
  103. }
  104. /// <summary>
  105. /// Called when [item changed].
  106. /// </summary>
  107. private async void OnItemChanged()
  108. {
  109. var options = ImageDownloadOptions ?? new ImageOptions { };
  110. options.ImageType = ImageType.Primary;
  111. try
  112. {
  113. Image = await App.Instance.GetRemoteBitmapAsync(App.Instance.ApiClient.GetImageUrl(Item, options));
  114. }
  115. catch (HttpException)
  116. {
  117. }
  118. }
  119. }
  120. }