JXVerifyDetailVC.m 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. //
  2. // JXVerifyDetailVC.m
  3. // shiku_im
  4. //
  5. // Created by p on 2018/5/29.
  6. // Copyright © 2018年 Reese. All rights reserved.
  7. //
  8. #import "JXVerifyDetailVC.h"
  9. #define HEIGHT 50
  10. @interface JXVerifyDetailVC ()
  11. @property (nonatomic, strong) UIButton *confirmBtn;
  12. @property (nonatomic, strong) NSArray *userIds;
  13. @property (nonatomic, strong) NSArray *userNames;
  14. @end
  15. @implementation JXVerifyDetailVC
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. // Do any additional setup after loading the view.
  19. self.heightHeader = JX_SCREEN_TOP;
  20. self.heightFooter = 0;
  21. self.isGotoBack = YES;
  22. self.title = Localized(@"JX_InvitingDetails");
  23. [self createHeadAndFoot];
  24. [self customView];
  25. }
  26. - (void)customView {
  27. SBJsonParser * resultParser = [[SBJsonParser alloc] init] ;
  28. NSDictionary *resultObject = [resultParser objectWithString:self.msg.objectId];
  29. JXImageView *imageView = [[JXImageView alloc] initWithFrame:CGRectMake(0, 50, 80, 80)];
  30. imageView.center = CGPointMake(JX_SCREEN_WIDTH / 2, imageView.center.y);
  31. imageView.layer.cornerRadius = imageView.frame.size.width / 2;
  32. imageView.layer.masksToBounds = YES;
  33. [self.tableBody addSubview:imageView];
  34. [g_server getHeadImageLarge:self.msg.fromUserId userName:self.msg.fromUserName imageView:imageView];
  35. UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(imageView.frame) + 10, JX_SCREEN_WIDTH, 20)];
  36. name.text = self.msg.fromUserName;
  37. name.textAlignment = NSTextAlignmentCenter;
  38. name.textColor = [UIColor lightGrayColor];
  39. name.font = [UIFont systemFontOfSize:15.0];
  40. [self.tableBody addSubview:name];
  41. NSString *userIds = [resultObject objectForKey:@"userIds"];
  42. NSArray *array = [userIds componentsSeparatedByString:@","];
  43. UILabel *tip = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(name.frame) + 10, JX_SCREEN_WIDTH, 20)];
  44. tip.text = [NSString stringWithFormat:Localized(@"JX_InviteFriendsJoinGroupChat"),array.count];
  45. tip.textAlignment = NSTextAlignmentCenter;
  46. tip.textColor = [UIColor lightGrayColor];
  47. tip.font = [UIFont systemFontOfSize:15.0];
  48. [self.tableBody addSubview:tip];
  49. if ([self.msg.fromUserId isEqualToString:[array firstObject]] && array.count == 1) {
  50. tip.text = [NSString stringWithFormat:@"%@申请加入群组",self.msg.fromUserName];
  51. }
  52. UILabel *detail = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(tip.frame) + 10, JX_SCREEN_WIDTH, 20)];
  53. detail.text = [resultObject objectForKey:@"reason"];
  54. detail.textAlignment = NSTextAlignmentCenter;
  55. detail.textColor = [UIColor lightGrayColor];
  56. detail.font = [UIFont systemFontOfSize:15.0];
  57. [self.tableBody addSubview:detail];
  58. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(detail.frame) + 20, JX_SCREEN_WIDTH - 40, 1)];
  59. line.backgroundColor = [UIColor grayColor];
  60. [self.tableBody addSubview:line];
  61. UIView *view = [self createImages];
  62. view.frame = CGRectMake(0, CGRectGetMaxY(line.frame) + 20, JX_SCREEN_WIDTH, view.frame.size.height);
  63. _confirmBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(view.frame) + 20, WIDTH, 50)];
  64. _confirmBtn.center = CGPointMake(JX_SCREEN_WIDTH / 2, _confirmBtn.center.y);
  65. if ([self.msg.fileName isEqualToString:@"1"]) {
  66. self.confirmBtn.enabled = NO;
  67. self.confirmBtn.backgroundColor = [UIColor grayColor];
  68. }else {
  69. _confirmBtn.enabled = YES;
  70. _confirmBtn.backgroundColor = THEMECOLOR;
  71. }
  72. [_confirmBtn setTitle:Localized(@"JX_ConfirmationInvitations") forState:UIControlStateNormal];
  73. [_confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  74. [_confirmBtn addTarget:self action:@selector(confirmBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  75. [self.tableBody addSubview:_confirmBtn];
  76. [self.tableBody setContentSize:CGSizeMake(0, CGRectGetMaxY(_confirmBtn.frame) + 20)];
  77. }
  78. - (UIView *) createImages {
  79. SBJsonParser * resultParser = [[SBJsonParser alloc] init] ;
  80. NSDictionary *resultObject = [resultParser objectWithString:self.msg.objectId];
  81. NSString *userIdStr = [resultObject objectForKey:@"userIds"];
  82. NSString *userNameStr = [resultObject objectForKey:@"userNames"];
  83. self.userIds = [userIdStr componentsSeparatedByString:@","];
  84. self.userNames = [userNameStr componentsSeparatedByString:@","];
  85. UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 0)];
  86. [self.tableBody addSubview:contentView];
  87. //动态分配行数,且居中
  88. int screenWidth = JX_SCREEN_WIDTH;
  89. //+52让间隙变大,更美观
  90. // float widthInset = (screenWidth%52 +52)/(screenWidth/52.0);
  91. int num = screenWidth / 52;
  92. while ((screenWidth - num * 52) < 15 * (num + 1)) {
  93. num = num - 1;
  94. }
  95. float widthInset = (screenWidth - num * 52) / 6;
  96. float x = widthInset;
  97. int y = 10;
  98. for (NSInteger i = 0; i < self.userIds.count; i ++) {
  99. NSString *userId = self.userIds[i];
  100. NSString *userName = self.userNames[i];
  101. JXImageView* headImageView = [[JXImageView alloc] init];
  102. [g_server getHeadImageLarge:userId userName:userName imageView:headImageView];
  103. [contentView addSubview:headImageView];
  104. if(headImageView){
  105. if(x +52 >= screenWidth){
  106. y += 77;
  107. x = widthInset;
  108. }
  109. headImageView.frame = CGRectMake(x, y, 52, 52);
  110. headImageView.layer.cornerRadius = headImageView.frame.size.width / 2;
  111. headImageView.layer.masksToBounds = YES;
  112. x = x+52+widthInset;
  113. JXLabel* b = [[JXLabel alloc]initWithFrame:CGRectMake( headImageView.frame.origin.x, headImageView.frame.origin.y+headImageView.frame.size.height + 5, 52, 10)];
  114. b.text = userName;
  115. b.font = g_factory.font9;
  116. b.textAlignment = NSTextAlignmentCenter;
  117. [contentView addSubview:b];
  118. }
  119. }
  120. contentView.frame = CGRectMake(contentView.frame.origin.x, contentView.frame.origin.y, contentView.frame.size.width, y + 77);
  121. return contentView;
  122. }
  123. - (void)confirmBtnAction:(UIButton *)btn {
  124. if ((self.userIds.count + self.room.curCount) > self.room.maxCount) {
  125. [JXMyTools showTipView:@"群成员已达上限"];
  126. return;
  127. }
  128. [g_server addRoomMember:self.room.roomId userArray:self.userIds toView:self];//用接口即可
  129. }
  130. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  131. [_wait stop];
  132. if( [aDownload.action isEqualToString:act_roomMemberSet] ){
  133. for (int i=0;i<[_userIds count];i++) {
  134. NSString *userId=[_userIds objectAtIndex:i];
  135. memberData* p = [[memberData alloc] init];
  136. p.userId = [userId intValue];
  137. p.userNickName = [_userNames objectAtIndex:i];
  138. [self.room.members addObject:p];
  139. }
  140. self.msg.fileName = @"1";
  141. self.msg.content = [self.msg.content stringByReplacingOccurrencesOfString:Localized(@"JX_ToConfirm") withString:Localized(@"JX_VerifyConfirmed")];
  142. [self.msg updateNeedVerifyFileName];
  143. [self.msg update];
  144. self.confirmBtn.enabled = NO;
  145. self.confirmBtn.backgroundColor = [UIColor grayColor];
  146. for(NSInteger i=[self.chatVC.array count]-1;i>=0;i--){
  147. JXMessageObject *p=[self.chatVC.array objectAtIndex:i];
  148. if([p.messageId isEqualToString:self.msg.messageId]){//如果找到被撤回的那条消息
  149. [self.chatVC.tableView reloadRow:(int)i section:0];
  150. break;
  151. }
  152. p =nil;
  153. }
  154. [g_navigation popToViewController:[JXChatViewController class] animated:YES];
  155. }
  156. }
  157. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  158. [_wait stop];
  159. return show_error;
  160. }
  161. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  162. [_wait stop];
  163. return show_error;
  164. }
  165. -(void) didServerConnectStart:(JXConnection*)aDownload{
  166. [_wait start];
  167. }
  168. - (void)didReceiveMemoryWarning {
  169. [super didReceiveMemoryWarning];
  170. // Dispose of any resources that can be recreated.
  171. }
  172. /*
  173. #pragma mark - Navigation
  174. // In a storyboard-based application, you will often want to do a little preparation before navigation
  175. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  176. // Get the new view controller using [segue destinationViewController].
  177. // Pass the selected object to the new view controller.
  178. }
  179. */
  180. @end