WFCUCallSummaryCell.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //
  2. // InformationCell.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/9/1.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUCallSummaryCell.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import "WFCUUtilities.h"
  11. #define TEXT_TOP_PADDING 6
  12. #define TEXT_BUTTOM_PADDING 6
  13. #define TEXT_LEFT_PADDING 8
  14. #define TEXT_RIGHT_PADDING 8
  15. #define TEXT_LABEL_TOP_PADDING TEXT_TOP_PADDING + 4
  16. #define TEXT_LABEL_BUTTOM_PADDING TEXT_BUTTOM_PADDING + 4
  17. #define TEXT_LABEL_LEFT_PADDING 30
  18. #define TEXT_LABEL_RIGHT_PADDING 30
  19. #if WFCU_SUPPORT_VOIP
  20. #import <WFAVEngineKit/WFAVEngineKit.h>
  21. #endif
  22. @implementation WFCUCallSummaryCell
  23. + (CGSize)sizeForClientArea:(WFCUMessageModel *)msgModel withViewWidth:(CGFloat)width {
  24. NSString *text = [WFCUCallSummaryCell getCallText:msgModel.message.content];
  25. CGSize textSize = [WFCUUtilities getTextDrawingSize:text font:[UIFont systemFontOfSize:18] constrainedSize:CGSizeMake(width, 8000)];
  26. return CGSizeMake(textSize.width + 25, 30);
  27. }
  28. + (NSString *)getCallText:(WFCCCallStartMessageContent *)startContent {
  29. NSString *text;
  30. if (startContent.isAudioOnly) {
  31. text = WFCString(@"VoiceCall");
  32. } else {
  33. text = WFCString(@"VideoCall");
  34. }
  35. if (startContent.connectTime > 0 && startContent.endTime > 0) {
  36. long long duration = startContent.endTime - startContent.connectTime;
  37. if (duration <= 0) {
  38. return text;
  39. }
  40. duration = duration/1000; //转化成s
  41. if (duration == 0) {
  42. return text;
  43. }
  44. long long hour = duration/3600; //小时数
  45. duration = duration - hour * 3600; //去除小时
  46. long long mins = duration/60; //分钟数
  47. duration = duration - mins*60;
  48. long long second = duration;
  49. if (hour) {
  50. text = [text stringByAppendingFormat:@"%lld:", hour];
  51. }
  52. text = [text stringByAppendingFormat:@"%02lld:", mins];
  53. text = [text stringByAppendingFormat:@"%02lld", second];
  54. } else {
  55. #if WFCU_SUPPORT_VOIP
  56. switch (startContent.status) {
  57. case kWFAVCallEndReasonAcceptByOtherClient:
  58. text = @"其它端已接听";
  59. break;
  60. case kWFAVCallEndReasonBusy:
  61. case kWFAVCallEndReasonRemoteBusy:
  62. text = @"线路忙";
  63. break;
  64. case kWFAVCallEndReasonRemoteTimeout:
  65. text = @"对方未接听";
  66. break;
  67. case kWFAVCallEndReasonRemoteNetworkError:
  68. text = @"网络错误";
  69. break;
  70. default:
  71. break;
  72. }
  73. if ([WFAVEngineKit sharedEngineKit].supportMultiCall && (startContent.status == kWFAVCallEndReasonRemoteHangup)) {
  74. text = @"对方已拒绝";
  75. }
  76. #endif
  77. }
  78. return text;
  79. }
  80. - (void)setModel:(WFCUMessageModel *)model {
  81. [super setModel:model];
  82. CGFloat width = self.contentArea.bounds.size.width;
  83. self.infoLabel.text = [WFCUCallSummaryCell getCallText:model.message.content];
  84. self.infoLabel.layoutMargins = UIEdgeInsetsMake(TEXT_TOP_PADDING, TEXT_LEFT_PADDING, TEXT_BUTTOM_PADDING, TEXT_RIGHT_PADDING);
  85. CGSize textSize = [WFCUUtilities getTextDrawingSize:self.infoLabel.text font:[UIFont systemFontOfSize:18] constrainedSize:CGSizeMake(width, 8000)];
  86. if (model.message.direction == MessageDirection_Send) {
  87. self.infoLabel.frame = CGRectMake(0, 0, width - 25, 30);
  88. self.modeImageView.frame = CGRectMake(width - 25, 3, 25, 25);
  89. } else {
  90. self.infoLabel.frame = CGRectMake(0, 0, width-25, 30);
  91. self.modeImageView.frame = CGRectMake(width-25, 3, 25, 25);
  92. }
  93. if ([self.model.message.content isKindOfClass:[WFCCCallStartMessageContent class]]) {
  94. WFCCCallStartMessageContent *startContent = (WFCCCallStartMessageContent *)self.model.message.content;
  95. if (startContent.isAudioOnly) {
  96. self.modeImageView.image = [UIImage imageNamed:@"msg_audio_call"];
  97. } else {
  98. self.modeImageView.image = [UIImage imageNamed:@"msg_video_call"];
  99. }
  100. }
  101. }
  102. - (UILabel *)infoLabel {
  103. if (!_infoLabel) {
  104. _infoLabel = [[UILabel alloc] init];
  105. _infoLabel.numberOfLines = 0;
  106. _infoLabel.font = [UIFont systemFontOfSize:14];
  107. _infoLabel.textColor = [UIColor whiteColor];
  108. _infoLabel.numberOfLines = 0;
  109. _infoLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  110. _infoLabel.textAlignment = NSTextAlignmentCenter;
  111. _infoLabel.font = [UIFont systemFontOfSize:14.f];
  112. _infoLabel.layer.masksToBounds = YES;
  113. _infoLabel.layer.cornerRadius = 5.f;
  114. _infoLabel.textAlignment = NSTextAlignmentCenter;
  115. _infoLabel.textColor = [UIColor blackColor];
  116. _infoLabel.userInteractionEnabled = YES;
  117. [self.contentArea addSubview:_infoLabel];
  118. }
  119. return _infoLabel;
  120. }
  121. - (UIImageView *)modeImageView {
  122. if (!_modeImageView) {
  123. _modeImageView = [[UIImageView alloc] init];
  124. [self.contentArea addSubview:_modeImageView];
  125. }
  126. return _modeImageView;
  127. }
  128. @end