PostViewModel.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using HanumanInstitute.MvvmDialogs;
  2. using System.Collections.ObjectModel;
  3. using VeloeAvaloniaKemonoPartyApp.Models;
  4. namespace VeloeAvaloniaKemonoPartyApp.ViewModels
  5. {
  6. public class PostViewModel : ViewModelBase
  7. {
  8. private readonly Post _post;
  9. private readonly IDialogService _dialogService;
  10. public PostViewModel(IDialogService dialogService, Post post)
  11. {
  12. _post = post;
  13. _dialogService = dialogService;
  14. Images.Clear();
  15. foreach (var attachment in _post.Attachments)
  16. {
  17. if (attachment is null) continue;
  18. if (attachment.Path.EndsWith(".jpg") || attachment.Path.EndsWith(".png") || attachment.Path.EndsWith(".jpeg"))
  19. {
  20. Images.Add(new PostImageViewModel(_dialogService,attachment));
  21. }
  22. }
  23. }
  24. public ObservableCollection<PostImageViewModel> Images { get; } = new();
  25. public bool IsImagesEmpty => Images.Count == 0;
  26. public string Content => _post.Content;
  27. public string Title => _post.Title;
  28. public string Date => _post.Published;
  29. }
  30. }