YMDynamicDetailCommentCellViewModel.m 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // YMDynamicDetailCommentCellViewModel.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/21.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMDynamicDetailCommentCellViewModel.h"
  9. #import "YMDynamicCommentModel.h"
  10. @interface YMDynamicDetailCommentCellViewModel ()
  11. /// 动态Id
  12. @property (nonatomic, assign, readwrite) NSInteger commentId;
  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) NSString *dynamicCommentDate;
  21. /// 动态消息内容
  22. @property (nonatomic, strong, readwrite) NSAttributedString *dynamicCommentContent;
  23. @end
  24. @implementation YMDynamicDetailCommentCellViewModel
  25. - (void)ym_initialize{
  26. [super ym_initialize];
  27. if ([self.params[ParamsModel] isKindOfClass:[YMDynamicCommentModel class]]) {
  28. YMDynamicCommentModel *model = self.params[ParamsModel];
  29. self.commentId = model.comment_id;
  30. self.userId = model.user_id;
  31. self.userAvatar = model.avatar;
  32. self.userNickname = model.nickname;
  33. self.dynamicCommentDate = model.create_time;
  34. NSString *content = @"";
  35. switch (model.is_type) {
  36. case 1:
  37. {
  38. if (model.comment_user_id != 0) {
  39. content = stringFormat(@"回复%@:%@",model.comment_nickname,model.content);
  40. }else{
  41. content = model.content;
  42. }
  43. }
  44. break;
  45. case 2:
  46. {
  47. content = stringFormat(@"%@回复了你:%@",model.nickname,model.content);
  48. }
  49. break;
  50. case 3:
  51. {
  52. content = stringFormat(@"%@评论了你:%@",model.nickname,model.content);
  53. }
  54. break;
  55. default:
  56. break;
  57. }
  58. NSMutableAttributedString *dynamicCommentContentAttributed = [[NSMutableAttributedString alloc]initWithString:content];
  59. dynamicCommentContentAttributed.yy_font = LCFont(13);
  60. dynamicCommentContentAttributed.yy_color = HexColorFromRGB(0x333333);
  61. dynamicCommentContentAttributed.yy_alignment = NSTextAlignmentLeft;
  62. dynamicCommentContentAttributed.yy_lineSpacing = 5;
  63. [dynamicCommentContentAttributed yy_setColor:HexColorFromRGB(0x7c69fe) range:[content rangeOfString:model.nickname]];
  64. self.dynamicCommentContent = dynamicCommentContentAttributed;
  65. }
  66. }
  67. @end