YMDynamicDetailInfoCellViewModel.m 3.6 KB

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