JXFaceCreateRoomVC.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. //
  2. // JXFaceCreateRoomVC.m
  3. // shiku_im
  4. //
  5. // Created by p on 2019/4/16.
  6. // Copyright © 2019年 Reese. All rights reserved.
  7. //
  8. #import "JXFaceCreateRoomVC.h"
  9. #import "HWTFCodeView.h"
  10. #import "JXChatViewController.h"
  11. #import "JXRoomPool.h"
  12. #import "JXUserObject.h"
  13. #import "JXChatViewC.h"
  14. #define HEIGHT 50
  15. @interface JXFaceCreateRoomVC ()<HWTFCodeViewDelegate>
  16. @property (nonatomic, strong) UILabel *tip;
  17. @property (nonatomic, strong) UILabel *joinTip;
  18. @property (nonatomic, strong) HWTFCodeView *codeView;
  19. @property (nonatomic, strong) UIButton *btn;
  20. @property (nonatomic, strong) UIView *lineView;
  21. @property (nonatomic, strong) UIView *usersView;
  22. @property (nonatomic, strong) NSMutableArray *array;
  23. @property (nonatomic, copy) NSString *jid;
  24. @property (nonatomic, copy) NSString *password;
  25. @property (nonatomic, strong) NSDictionary *roomDic;
  26. @end
  27. @implementation JXFaceCreateRoomVC
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. // Do any additional setup after loading the view.
  31. self.view.backgroundColor = HEXCOLOR(0x181E1F);
  32. _array = [NSMutableArray array];
  33. UIButton *closeBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP - 46, 46, 46)];
  34. [closeBtn setBackgroundImage:[[UIImage imageNamed:@"title_back_black_big"] imageWithTintColor:[UIColor whiteColor]] forState:UIControlStateNormal];
  35. [closeBtn addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
  36. [self.view addSubview:closeBtn];
  37. JXLabel* title = [[JXLabel alloc]initWithFrame:CGRectMake(60, JX_SCREEN_TOP - 32, JX_SCREEN_WIDTH-60*2, 20)];
  38. title.backgroundColor = [UIColor clearColor];
  39. title.textAlignment = NSTextAlignmentCenter;
  40. title.textColor = [UIColor whiteColor];
  41. title.text = Localized(@"JX_FaceToFaceGroup");
  42. title.font = [UIFont systemFontOfSize:18.0];
  43. title.userInteractionEnabled = YES;
  44. title.didTouch = @selector(actionTitle:);
  45. title.delegate = self;
  46. title.changeAlpha = NO;
  47. [self.view addSubview:title];
  48. _tip = [[UILabel alloc] initWithFrame:CGRectMake(50, JX_SCREEN_TOP + 50, JX_SCREEN_WIDTH - 100, 50)];
  49. _tip.textAlignment = NSTextAlignmentCenter;
  50. _tip.numberOfLines = 0;
  51. _tip.textColor = [UIColor lightGrayColor];
  52. _tip.font = [UIFont systemFontOfSize:15.0];
  53. _tip.text = Localized(@"JX_IntoSameGroup");
  54. [self.view addSubview:_tip];
  55. HWTFCodeView *code1View = [[HWTFCodeView alloc] initWithCount:4 margin:10];
  56. code1View.frame = CGRectMake((JX_SCREEN_WIDTH - 150) / 2, CGRectGetMaxY(_tip.frame) + 20, 150, 30);
  57. code1View.delegate = self;
  58. [self.view addSubview:code1View];
  59. self.codeView = code1View;
  60. _joinTip = [[UILabel alloc] initWithFrame:CGRectMake(50, CGRectGetMaxY(code1View.frame) + 10, JX_SCREEN_WIDTH - 100, 30)];
  61. _joinTip.textAlignment = NSTextAlignmentCenter;
  62. _joinTip.numberOfLines = 0;
  63. _joinTip.textColor = [UIColor lightGrayColor];
  64. _joinTip.font = [UIFont systemFontOfSize:15.0];
  65. _joinTip.text = Localized(@"JX_TheseFriendsWillAlsoJoinGroup");
  66. _joinTip.hidden = YES;
  67. [self.view addSubview:_joinTip];
  68. _lineView = [[UIView alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(_joinTip.frame) + 10, JX_SCREEN_WIDTH - 30, LINE_WH)];
  69. _lineView.backgroundColor = THE_LINE_COLOR;
  70. _lineView.hidden = YES;
  71. [self.view addSubview:_lineView];
  72. _btn = [UIFactory createCommonButton:Localized(@"JX_AccessToGroup") target:self action:@selector(onJoin)];
  73. _btn.custom_acceptEventInterval = 1.0f;
  74. _btn.frame = CGRectMake(15, self.view.frame.size.height - HEIGHT - 50-20, JX_SCREEN_WIDTH-30, 40);
  75. _btn.titleLabel.font = SYSFONT(16);
  76. _btn.layer.masksToBounds = YES;
  77. _btn.layer.cornerRadius = 7.f;
  78. _btn.hidden = YES;
  79. [self.view addSubview:_btn];
  80. [g_notify addObserver:self selector:@selector(msgRoomFaceNotif:) name:kMsgRoomFaceNotif object:nil];//收到了群控制消息
  81. }
  82. - (void)viewWillAppear:(BOOL)animated {
  83. [super viewWillAppear:animated];
  84. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  85. }
  86. - (void)viewWillDisappear:(BOOL)animated {
  87. [super viewWillDisappear:animated];
  88. if (THESIMPLESTYLE) {
  89. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  90. }
  91. }
  92. -(void)msgRoomFaceNotif:(NSNotification *)notifacation {
  93. [g_server roomLocationQueryWithIsQuery:1 password:self.password toView:self];
  94. }
  95. - (void)createUsers {
  96. CGFloat w = 50;
  97. CGFloat h = 50;
  98. int count = 5;
  99. CGFloat space = 20;
  100. CGFloat margin = (JX_SCREEN_WIDTH - (w * count) - ((count - 1) * space)) / 2;
  101. if (!_usersView){
  102. _usersView = [[UIView alloc] init];
  103. [self.view addSubview:_usersView];
  104. }
  105. [_usersView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  106. _usersView.frame = CGRectMake(margin, CGRectGetMaxY(_lineView.frame) + 10, JX_SCREEN_WIDTH - margin*2, 0);
  107. CGFloat usersH = 0;
  108. for (NSInteger i = 0; i < _array.count; i ++) {
  109. NSDictionary *dict = _array[i];
  110. CGFloat x = (i % 5) * (w + space);
  111. CGFloat y = (i / 5) * (w + 30);
  112. UIImageView *head = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
  113. head.layer.cornerRadius = w / 2;
  114. head.layer.masksToBounds = YES;
  115. [g_server getHeadImageLarge:dict[@"userId"] userName:dict[@"nickname"] imageView:head];
  116. [_usersView addSubview:head];
  117. UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(head.frame.origin.x, CGRectGetMaxY(head.frame), head.frame.size.width, 20)];
  118. name.textAlignment = NSTextAlignmentCenter;
  119. name.textColor = [UIColor lightGrayColor];
  120. name.font = [UIFont systemFontOfSize:14.0];
  121. name.text = dict[@"nickname"];
  122. [_usersView addSubview:name];
  123. usersH = CGRectGetMaxY(name.frame);
  124. }
  125. _usersView.frame = CGRectMake(_usersView.frame.origin.x, _usersView.frame.origin.y, _usersView.frame.size.width, usersH);
  126. }
  127. - (void)codeView:(HWTFCodeView *)codeView inputFnish:(NSString *)text {
  128. _codeView.userInteractionEnabled = NO;
  129. self.password = text;
  130. [g_server roomLocationQueryWithIsQuery:0 password:text toView:self];
  131. }
  132. - (void)onJoin {
  133. [g_server roomLocationJoinWithJid:self.jid toView:self];
  134. }
  135. - (void)cancelAction {
  136. [self actionQuit];
  137. }
  138. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  139. [_wait stop];
  140. if( [aDownload.action isEqualToString:act_RoomLocationQuery] ){
  141. [_array removeAllObjects];
  142. [_array addObjectsFromArray:[dict objectForKey:@"members"]];
  143. self.jid = [dict objectForKey:@"jid"];
  144. self.roomDic = dict;
  145. if (!_tip.hidden) {
  146. [UIView animateWithDuration:0.5 animations:^{
  147. _tip.frame = CGRectMake(_tip.frame.origin.x, _tip.frame.origin.y - 50, _tip.frame.size.width, _tip.frame.size.height);
  148. _codeView.frame = CGRectMake(_codeView.frame.origin.x, _codeView.frame.origin.y - 50, _codeView.frame.size.width, _codeView.frame.size.height);
  149. } completion:^(BOOL finished) {
  150. _joinTip.frame = CGRectMake(_joinTip.frame.origin.x, CGRectGetMaxY(_codeView.frame) + 10, _joinTip.frame.size.width, _joinTip.frame.size.height);
  151. _lineView.frame = CGRectMake(_lineView.frame.origin.x, CGRectGetMaxY(_joinTip.frame) + 10, _lineView.frame.size.width, _lineView.frame.size.height);
  152. _tip.hidden = YES;
  153. _joinTip.hidden = NO;
  154. _lineView.hidden = NO;
  155. _btn.hidden = NO;
  156. [self createUsers];
  157. }];
  158. }else {
  159. [self createUsers];
  160. }
  161. }
  162. if ([aDownload.action isEqualToString:act_RoomLocationJoin]) {
  163. [self insertRoom:dict];
  164. [self actionQuit];
  165. }
  166. }
  167. -(void)insertRoom:(NSDictionary *)dict{
  168. JXUserObject* user = [[JXUserObject alloc]init];
  169. user.userNickname = dict[@"name"];
  170. user.userId = dict[@"jid"];
  171. user.userDescription = @"";
  172. user.roomId = dict[@"id"];
  173. user.content = Localized(@"JX_WelcomeGroupChat");
  174. user.showRead = [NSNumber numberWithBool:[dict[@"showRead"] boolValue]];
  175. user.showMember = [NSNumber numberWithBool:[dict[@"showMember"] boolValue]];
  176. user.allowSendCard = [NSNumber numberWithBool:[dict[@"allowSendCard"] boolValue]];
  177. user.allowInviteFriend = [NSNumber numberWithBool:[dict[@"allowInviteFriend"] boolValue]];
  178. user.allowUploadFile = [NSNumber numberWithBool:[dict[@"allowUploadFile"] boolValue]];
  179. user.allowSpeakCourse = [NSNumber numberWithBool:[dict[@"allowSpeakCourse"] boolValue]];
  180. user.isNeedVerify = [NSNumber numberWithBool:[dict[@"isNeedVerify"] boolValue]];
  181. user.createUserId = dict[@"userId"];
  182. [user insertRoom];
  183. [self onNewRoom:user createName:dict[@"nickname"]];
  184. }
  185. -(void)onNewRoom:(JXUserObject *)user createName:(NSString *)createName{
  186. JXChatViewC *sendView=[JXChatViewC alloc];
  187. //JXChatViewController *sendView=[JXChatViewController alloc];
  188. sendView.title = user.userNickname;
  189. sendView.roomJid = user.userId;
  190. sendView.roomId = user.roomId;
  191. sendView.chatRoom = [[JXXMPP sharedInstance].roomPool joinRoom:user.userId title:user.userNickname lastDate:nil isNew:NO];
  192. roomData *room = [[roomData alloc] init];
  193. room.roomJid= user.userId;
  194. room.roomId = user.roomId;
  195. room.name = user.userNickname;
  196. room.desc = @"";
  197. room.userId = [g_myself.userId longLongValue];
  198. room.userNickName = createName;
  199. room.showRead = NO;
  200. room.showMember = YES;
  201. room.allowSendCard = YES;
  202. room.isNeedVerify = NO;
  203. room.allowInviteFriend = YES;
  204. room.allowUploadFile = YES;
  205. room.allowConference = YES;
  206. room.allowSpeakCourse = YES;
  207. sendView.room = room;
  208. sendView.chatPerson = user;
  209. sendView = [sendView init];
  210. // [g_App.window addSubview:sendView.view];
  211. [g_navigation pushViewController:sendView animated:YES];
  212. }
  213. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  214. [_wait stop];
  215. return show_error;
  216. }
  217. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  218. [_wait stop];
  219. return show_error;
  220. }
  221. -(void) didServerConnectStart:(JXConnection*)aDownload{
  222. [_wait start];
  223. }
  224. - (void)actionQuit {
  225. [g_server roomLocationExitWithJid:self.jid toView:self];
  226. [super actionQuit];
  227. }
  228. - (void)dealloc {
  229. [g_notify removeObserver:self];
  230. }
  231. /*
  232. #pragma mark - Navigation
  233. // In a storyboard-based application, you will often want to do a little preparation before navigation
  234. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  235. // Get the new view controller using [segue destinationViewController].
  236. // Pass the selected object to the new view controller.
  237. }
  238. */
  239. @end