PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/BaconographyPortable/ViewModel/LinkedPictureViewModel.cs

https://github.com/hippiehunter/Baconography
C# | 170 lines | 153 code | 17 blank | 0 comment | 16 complexity | 04eb7dff8f5085b704dacf9c84afa7be MD5 | raw file
  1. using BaconographyPortable.Common;
  2. using BaconographyPortable.Messages;
  3. using BaconographyPortable.Services;
  4. using GalaSoft.MvvmLight;
  5. using GalaSoft.MvvmLight.Command;
  6. using GalaSoft.MvvmLight.Messaging;
  7. using Microsoft.Practices.ServiceLocation;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace BaconographyPortable.ViewModel
  14. {
  15. public class LinkedPictureViewModel : ViewModelBase
  16. {
  17. public class LinkedPicture : ViewModelBase
  18. {
  19. private object _imageSource;
  20. public object ImageSource
  21. {
  22. get
  23. {
  24. return _imageSource;
  25. }
  26. set
  27. {
  28. _imageSource = value;
  29. RaisePropertyChanged("ImageSource");
  30. }
  31. }
  32. public string Url { get; set; }
  33. public string Title { get; set; }
  34. public bool IsAlbum { get; set; }
  35. public int PositionInAlbum { get; set; }
  36. public int AlbumSize { get; set; }
  37. public bool IsGif { get; set; }
  38. public bool HasExtendableTitle
  39. {
  40. get
  41. {
  42. return Title.Length > 40 || Title.Contains("\r") || Title.Contains("\n");
  43. }
  44. }
  45. }
  46. public string LinkId { get; set; }
  47. public IEnumerable<LinkedPicture> _pictures;
  48. public IEnumerable<LinkedPicture> Pictures
  49. {
  50. get
  51. {
  52. return _pictures;
  53. }
  54. set
  55. {
  56. if (value != null)
  57. {
  58. var refiedValue = value.ToList();
  59. if (refiedValue.Count > 1)
  60. {
  61. int i = 1;
  62. foreach (var picture in refiedValue)
  63. {
  64. picture.IsAlbum = true;
  65. picture.PositionInAlbum = i++;
  66. picture.AlbumSize = refiedValue.Count;
  67. }
  68. }
  69. else
  70. {
  71. foreach (var picture in refiedValue)
  72. {
  73. picture.IsAlbum = false;
  74. picture.PositionInAlbum = 1;
  75. picture.AlbumSize = 1;
  76. }
  77. }
  78. _pictures = refiedValue;
  79. }
  80. else
  81. _pictures = null;
  82. }
  83. }
  84. public string ImageTitle
  85. {
  86. get
  87. {
  88. var firstPicture = Pictures.FirstOrDefault();
  89. if (firstPicture != null)
  90. return firstPicture.Title;
  91. else
  92. return "";
  93. }
  94. }
  95. public string LinkTitle
  96. {
  97. get;
  98. set;
  99. }
  100. public bool IsAlbum
  101. {
  102. get
  103. {
  104. return Pictures != null && Pictures.Count() > 1;
  105. }
  106. }
  107. LinkViewModel _parentLink;
  108. public LinkViewModel ParentLink
  109. {
  110. get
  111. {
  112. if (_parentLink == null)
  113. {
  114. if (string.IsNullOrWhiteSpace(LinkId))
  115. return null;
  116. _parentLink = StreamViewUtility.FindSelfFromLink(LinkId) as LinkViewModel;
  117. }
  118. return _parentLink;
  119. }
  120. }
  121. public bool HasContext
  122. {
  123. get
  124. {
  125. return ParentLink != null;
  126. }
  127. }
  128. public int CommentCount
  129. {
  130. get
  131. {
  132. if (HasContext)
  133. return ParentLink.LinkThing.Data.CommentCount;
  134. return 0;
  135. }
  136. }
  137. public VotableViewModel Votable
  138. {
  139. get
  140. {
  141. if (ParentLink != null)
  142. return ParentLink.Votable;
  143. return null;
  144. }
  145. }
  146. public RelayCommand<LinkedPictureViewModel> NavigateToComments { get { return _navigateToComments; } }
  147. static RelayCommand<LinkedPictureViewModel> _navigateToComments = new RelayCommand<LinkedPictureViewModel>(NavigateToCommentsImpl);
  148. private static void NavigateToCommentsImpl(LinkedPictureViewModel vm)
  149. {
  150. vm.ParentLink.NavigateToComments.Execute(vm.ParentLink);
  151. }
  152. }
  153. }