JXInteraction.m 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // JXInteraction.m
  3. // AICity
  4. //
  5. // Created by TogetherWatch on 2025-10-13.
  6. //
  7. #import "JXInteraction.h"
  8. #import "JXCountFormatter.h"
  9. @implementation JXInteraction
  10. - (instancetype)initWithDictionary:(NSDictionary *)dict {
  11. self = [super init];
  12. if (self) {
  13. _jxDramaId = dict[@"jx_drama_id"];
  14. _jxEpisodeId = dict[@"jx_episode_id"];
  15. _likeCount = [dict[@"like_count"] longLongValue];
  16. _commentCount = [dict[@"comment_count"] longLongValue];
  17. _shareCount = [dict[@"share_count"] longLongValue];
  18. _favoriteCount = [dict[@"favorite_count"] longLongValue];
  19. _followCount = [dict[@"follow_count"] longLongValue];
  20. _viewCount = [dict[@"view_count"] longLongValue];
  21. // 解析日期
  22. NSString *dateStr = dict[@"last_updated"];
  23. if (dateStr) {
  24. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  25. formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssZ";
  26. _lastUpdated = [formatter dateFromString:dateStr];
  27. }
  28. }
  29. return self;
  30. }
  31. - (NSDictionary *)toDictionary {
  32. return @{
  33. @"jx_drama_id": self.jxDramaId ?: @"",
  34. @"jx_episode_id": self.jxEpisodeId ?: @"",
  35. @"like_count": @(self.likeCount),
  36. @"comment_count": @(self.commentCount),
  37. @"share_count": @(self.shareCount),
  38. @"favorite_count": @(self.favoriteCount),
  39. @"follow_count": @(self.followCount),
  40. @"view_count": @(self.viewCount)
  41. };
  42. }
  43. #pragma mark - UI格式化方法
  44. - (NSString *)formattedLikeCount {
  45. return [JXCountFormatter formatLikeCount:self.likeCount];
  46. }
  47. - (NSString *)formattedCommentCount {
  48. return [JXCountFormatter formatCommentCount:self.commentCount];
  49. }
  50. - (NSString *)formattedShareCount {
  51. return [JXCountFormatter formatShareCount:self.shareCount];
  52. }
  53. - (NSString *)formattedFavoriteCount {
  54. return [JXCountFormatter formatFavoriteCount:self.favoriteCount];
  55. }
  56. - (NSString *)formattedViewCount {
  57. return [JXCountFormatter formatPlayCount:self.viewCount];
  58. }
  59. /**
  60. * 兼容旧代码的格式化方法(已废弃,建议使用JXCountFormatter)
  61. */
  62. - (NSString *)formatCount:(long long)count {
  63. return [JXCountFormatter formatCount:count];
  64. }
  65. @end