2
0

WFCUCallSummaryCell.m 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. #import "WFCUImage.h"
  12. #define TEXT_TOP_PADDING 6
  13. #define TEXT_BUTTOM_PADDING 6
  14. #define TEXT_LEFT_PADDING 8
  15. #define TEXT_RIGHT_PADDING 8
  16. #define TEXT_LABEL_TOP_PADDING TEXT_TOP_PADDING + 4
  17. #define TEXT_LABEL_BUTTOM_PADDING TEXT_BUTTOM_PADDING + 4
  18. #define TEXT_LABEL_LEFT_PADDING 30
  19. #define TEXT_LABEL_RIGHT_PADDING 30
  20. #if WFCU_SUPPORT_VOIP
  21. #import <WFAVEngineKit/WFAVEngineKit.h>
  22. #endif
  23. @implementation WFCUCallSummaryCell
  24. + (CGSize)sizeForClientArea:(WFCUMessageModel *)msgModel withViewWidth:(CGFloat)width {
  25. NSString *text = [WFCUCallSummaryCell getCallText:msgModel.message.content];
  26. CGSize textSize = [WFCUUtilities getTextDrawingSize:text font:[UIFont systemFontOfSize:18] constrainedSize:CGSizeMake(width, 8000)];
  27. return CGSizeMake(textSize.width + 25, 30);
  28. }
  29. + (NSString *)getCallText:(WFCCCallStartMessageContent *)startContent {
  30. NSString *text;
  31. if (startContent.isAudioOnly) {
  32. text = WFCString(@"VoiceCall");
  33. } else {
  34. text = WFCString(@"VideoCall");
  35. }
  36. #if WFCU_SUPPORT_VOIP
  37. if(startContent.status == kWFAVCallEndReasonInterrupted) {
  38. text = @"通话中断";
  39. } else if(startContent.status == kWFAVCallEndReasonRemoteInterrupted) {
  40. text = @"对方通话中断";
  41. }
  42. if (startContent.connectTime > 0 && startContent.endTime > 0) {
  43. long long duration = startContent.endTime - startContent.connectTime;
  44. if (duration <= 0) {
  45. return text;
  46. }
  47. duration = duration/1000; //转化成s
  48. if (duration == 0) {
  49. return text;
  50. }
  51. long long hour = duration/3600; //小时数
  52. duration = duration - hour * 3600; //去除小时
  53. long long mins = duration/60; //分钟数
  54. duration = duration - mins*60;
  55. long long second = duration;
  56. if (hour) {
  57. text = [text stringByAppendingFormat:@"%lld:", hour];
  58. }
  59. text = [text stringByAppendingFormat:@"%02lld:", mins];
  60. text = [text stringByAppendingFormat:@"%02lld", second];
  61. } else {
  62. switch (startContent.status) {
  63. case kWFAVCallEndReasonBusy:
  64. text = @"线路忙";
  65. break;
  66. case kWFAVCallEndReasonSignalError:
  67. text = @"网络错误";
  68. break;
  69. case kWFAVCallEndReasonHangup:
  70. text = @"已取消";
  71. break;
  72. case kWFAVCallEndReasonMediaError:
  73. text = @"网络错误";
  74. break;
  75. case kWFAVCallEndReasonRemoteHangup:
  76. text = @"对方已取消";
  77. break;
  78. case kWFAVCallEndReasonOpenCameraFailure:
  79. text = @"网络错误";
  80. break;
  81. case kWFAVCallEndReasonTimeout:
  82. text = @"未接听";
  83. break;
  84. case kWFAVCallEndReasonAcceptByOtherClient:
  85. text = @"其它端已接听";
  86. break;
  87. case kWFAVCallEndReasonAllLeft:
  88. text = @"通话已结束";
  89. break;
  90. case kWFAVCallEndReasonRemoteBusy:
  91. text = @"对方线路忙";
  92. break;
  93. case kWFAVCallEndReasonRemoteTimeout:
  94. text = @"对方未接听";
  95. break;
  96. case kWFAVCallEndReasonRemoteNetworkError:
  97. text = @"对方网络错误";
  98. break;
  99. case kWFAVCallEndReasonRoomDestroyed:
  100. text = @"通话已结束";
  101. break;
  102. case kWFAVCallEndReasonRoomNotExist:
  103. text = @"通话已结束";
  104. break;
  105. case kWFAVCallEndReasonRoomParticipantsFull:
  106. text = @"已达到最大参与人数";
  107. break;
  108. case kWFAVCallEndReasonInterrupted:
  109. text = @"通话中断";
  110. break;
  111. case kWFAVCallEndReasonRemoteInterrupted:
  112. text = @"对方通话中断";
  113. break;
  114. default:
  115. break;
  116. }
  117. }
  118. #endif
  119. return text;
  120. }
  121. - (void)setModel:(WFCUMessageModel *)model {
  122. [super setModel:model];
  123. CGFloat width = self.contentArea.bounds.size.width;
  124. self.infoLabel.text = [WFCUCallSummaryCell getCallText:model.message.content];
  125. self.infoLabel.layoutMargins = UIEdgeInsetsMake(TEXT_TOP_PADDING, TEXT_LEFT_PADDING, TEXT_BUTTOM_PADDING, TEXT_RIGHT_PADDING);
  126. if (model.message.direction == MessageDirection_Send) {
  127. self.infoLabel.frame = CGRectMake(0, 0, width - 25, 30);
  128. self.modeImageView.frame = CGRectMake(width - 25, 3, 25, 25);
  129. } else {
  130. self.infoLabel.frame = CGRectMake(0, 0, width-25, 30);
  131. self.modeImageView.frame = CGRectMake(width-25, 3, 25, 25);
  132. }
  133. if ([self.model.message.content isKindOfClass:[WFCCCallStartMessageContent class]]) {
  134. WFCCCallStartMessageContent *startContent = (WFCCCallStartMessageContent *)self.model.message.content;
  135. if (startContent.isAudioOnly) {
  136. self.modeImageView.image = [WFCUImage imageNamed:@"msg_audio_call"];
  137. } else {
  138. self.modeImageView.image = [WFCUImage imageNamed:@"msg_video_call"];
  139. }
  140. }
  141. }
  142. - (UILabel *)infoLabel {
  143. if (!_infoLabel) {
  144. _infoLabel = [[UILabel alloc] init];
  145. _infoLabel.numberOfLines = 0;
  146. _infoLabel.font = [UIFont systemFontOfSize:14];
  147. _infoLabel.numberOfLines = 0;
  148. _infoLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  149. _infoLabel.textAlignment = NSTextAlignmentCenter;
  150. _infoLabel.font = [UIFont systemFontOfSize:14.f];
  151. _infoLabel.layer.masksToBounds = YES;
  152. _infoLabel.layer.cornerRadius = 5.f;
  153. _infoLabel.textAlignment = NSTextAlignmentCenter;
  154. _infoLabel.userInteractionEnabled = YES;
  155. [self.contentArea addSubview:_infoLabel];
  156. }
  157. return _infoLabel;
  158. }
  159. - (UIImageView *)modeImageView {
  160. if (!_modeImageView) {
  161. _modeImageView = [[UIImageView alloc] init];
  162. [self.contentArea addSubview:_modeImageView];
  163. }
  164. return _modeImageView;
  165. }
  166. @end