YMDynamicListCellViewModel.m 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // YMDynamicListCellViewModel.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/26.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMDynamicListCellViewModel.h"
  9. #import "YMDynamicListModel.h"
  10. @interface YMDynamicListCellViewModel()
  11. /// 动态Id
  12. @property (nonatomic, assign, readwrite) NSInteger dynamicId;
  13. /// 用户Id
  14. @property (nonatomic, assign, readwrite) NSInteger userId;
  15. /// 用户头像
  16. @property (nonatomic, strong, readwrite) NSString *userAvatar;
  17. /// 用户昵称
  18. @property (nonatomic, strong, readwrite) NSString *userNickname;
  19. /// 用户昵称颜色
  20. @property (nonatomic, strong, readwrite) UIColor *userNicknameColor;
  21. /// 用户描述
  22. @property (nonatomic, strong, readwrite) NSString *userDesc;
  23. /// 是否隐藏VIP图标
  24. @property (nonatomic, assign, readwrite) BOOL isHideVIPIcon;
  25. /// 是否隐藏心动按钮
  26. @property (nonatomic, assign, readwrite) BOOL isHideHeartbeatButton;
  27. /// 用户内容
  28. @property (nonatomic, strong, readwrite) NSString *userContent;
  29. /// 相册数据
  30. @property (nonatomic, strong, readwrite) NSArray <YMDynamicListAlbumCellViewModel*>*albumDataArray;
  31. /// 日期
  32. @property (nonatomic, strong, readwrite) NSString *date;
  33. /// 评论图片
  34. @property (nonatomic, strong, readwrite) UIImage *commentsImage;
  35. /// 评论数量
  36. @property (nonatomic, strong, readwrite) NSString *commentsNumber;
  37. /// 点赞图片
  38. @property (nonatomic, strong, readwrite) UIImage *likesImage;
  39. /// 点赞数量
  40. @property (nonatomic, strong, readwrite) NSString *likesNumber;
  41. @end
  42. @implementation YMDynamicListCellViewModel
  43. - (void)ym_initialize{
  44. [super ym_initialize];
  45. if ([self.params[ParamsModel] isKindOfClass:[YMDynamicListModel class]]) {
  46. YMDynamicListModel *model = self.params[ParamsModel];
  47. self.dynamicId = model.dynamic_id;
  48. self.userId = model.user_id;
  49. self.userAvatar = model.avatar;
  50. self.userNickname = model.nickname;
  51. if (model.vip != 1) {
  52. self.userNicknameColor = HexColorFromRGB(0x333333);
  53. } else {
  54. self.userNicknameColor = HexColorFromRGB(0x954403);
  55. }
  56. NSMutableString *desc = [NSMutableString string];
  57. if (model.age != 0) {
  58. [desc appendFormat:@"%ld岁 | ",model.age];
  59. }
  60. if (!OCStringIsEmpty(model.height)) {
  61. [desc appendFormat:@"%@ | ",model.height];
  62. }
  63. if (!OCStringIsEmpty(model.weight)) {
  64. [desc appendFormat:@"%@ | ",model.weight];
  65. }
  66. self.userDesc = [desc substringToIndex:desc.length - 2];
  67. self.isHideVIPIcon = model.vip == 1 ? NO : YES;
  68. self.isHideHeartbeatButton = self.userId != model.user_id ? YES : NO;
  69. self.userContent = model.content;
  70. self.albumDataArray = [model.images.rac_sequence map:^(YMDynamicImageModel * _Nullable value) {
  71. YMDynamicListAlbumCellViewModel *viewModel = [[YMDynamicListAlbumCellViewModel alloc]initWithParams:@{
  72. ParamsModel:value
  73. }];
  74. return viewModel;
  75. }].array;
  76. self.date = model.create_time;
  77. self.commentsImage = ImageByName(@"ym_dynamic_comments_icon");
  78. self.commentsNumber = model.comment_count == 0 ? @"评论" : model.comment_count> 99 ? @"99+" : stringFormat(@"%ld",model.comment_count);
  79. self.likesImage = ImageByName(@"ym_dynamic_likes_normal_icon");
  80. self.likesNumber = model.like_count == 0 ? @"点赞" : model.like_count> 99 ? @"99+" : stringFormat(@"%ld",model.like_count);
  81. [self.refreshUISubject sendNext:@(YMRefreshUI)];
  82. }
  83. }
  84. @end