JXSquareViewController.m 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  1. //
  2. // JXSquareViewController.m
  3. // shiku_im
  4. //
  5. // Created by 1 on 2018/11/7.
  6. // Copyright © 2018年 Reese. All rights reserved.
  7. //
  8. #import "JXSquareViewController.h"
  9. #import "WeiboViewControlle.h"
  10. #import "JXActionSheetVC.h"
  11. #ifdef Meeting_Version
  12. #import "JXSelectFriendsVC.h"
  13. #import "JXAVCallViewController.h"
  14. #endif
  15. #ifdef Live_Version
  16. #import "JXLiveViewController.h"
  17. #endif
  18. #import "JXScanQRViewController.h"
  19. #import "JXNearVC.h"
  20. #import "JXBlogRemind.h"
  21. #import "JXTabMenuView.h"
  22. #ifdef Meeting_Version
  23. #ifdef Live_Version
  24. #import "GKDYHomeViewController.h"
  25. #import "JXSmallVideoViewController.h"
  26. #endif
  27. #endif
  28. #import "ImageResize.h"
  29. #import "JXChatViewController.h"
  30. #import "JXCell.h"
  31. #import "JXUserInfoVC.h"
  32. /*
  33. * 如果要改变左右间隔
  34. * 减少间隔,则增加 SQUARE_HEIGHT
  35. * 增加间隔,则减少 SQUARE_HEIGHT
  36. */
  37. #define SQUARE_HEIGHT 52 //图片宽高
  38. #define INSET_IMAGE 7 // 字和图片的间距
  39. typedef NS_ENUM(NSInteger, JXSquareType) {
  40. JXSquareTypeLife, // 生活圈
  41. JXSquareTypeVideo, // 视频会议
  42. JXSquareTypeVideoLive, // 视频直播
  43. JXSquareTypeShortVideo, // 短视频
  44. JXSquareTypeQrcode, // 扫一扫
  45. JXSquareTypeNearby, // 附近的人
  46. };
  47. @interface JXSquareViewController () <JXActionSheetVCDelegate,UITableViewDelegate,UITableViewDataSource>
  48. @property (nonatomic, strong) NSArray *titleArr;
  49. @property (nonatomic, strong) NSArray *iconArr;
  50. @property (nonatomic, assign) JXSquareType type;
  51. @property (nonatomic, assign) BOOL isAudioMeeting;
  52. @property (nonatomic, strong) UILabel *weiboNewMsgNum;
  53. @property (nonatomic, strong) NSMutableArray *remindArray;
  54. @property (nonatomic, strong) UIButton *imgV;
  55. @property (nonatomic, strong) UIImageView *topImageView;
  56. @property (nonatomic, strong) NSMutableArray *subviews;
  57. @property (nonatomic, strong) UIScrollView *scrollView;
  58. @property (nonatomic, strong) UITableView *tableView;
  59. @property (nonatomic, strong) NSMutableArray *array;
  60. @property (nonatomic, assign) NSInteger page;
  61. @property(nonatomic,strong) MJRefreshFooterView *footer;
  62. @property(nonatomic,strong) MJRefreshHeaderView *header;
  63. @end
  64. @implementation JXSquareViewController
  65. - (instancetype)init {
  66. if (self = [super init]) {
  67. self.title = Localized(@"JXMainViewController_Find");
  68. _array = [NSMutableArray array];
  69. self.heightFooter = 0;
  70. self.heightHeader = JX_SCREEN_TOP;
  71. [self createHeadAndFoot];
  72. self.tableBody.backgroundColor = HEXCOLOR(0xF2F2F2);
  73. self.subviews = [[NSMutableArray alloc] init];
  74. [self setupViews];
  75. [g_notify addObserver:self selector:@selector(remindNotif:) name:kXMPPMessageWeiboRemind object:nil];
  76. }
  77. return self;
  78. }
  79. - (void)viewDidLoad {
  80. [super viewDidLoad];
  81. [self getServerData];
  82. }
  83. - (void)onQrCode {
  84. AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
  85. if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied)
  86. {
  87. [g_server showMsg:Localized(@"JX_CanNotopenCenmar")];
  88. return;
  89. }
  90. JXScanQRViewController * scanVC = [[JXScanQRViewController alloc] init];
  91. [g_navigation pushViewController:scanVC animated:YES];
  92. }
  93. - (void)getServerData {
  94. [g_server searchPublicWithKeyWorld:@"" limit:20 page:(int)_page toView:self];
  95. }
  96. -(void)dealloc{
  97. [g_notify removeObserver:self name:kXMPPMessageWeiboRemind object:nil];
  98. }
  99. - (void)viewWillAppear:(BOOL)animated {
  100. [super viewWillAppear:animated];
  101. [self showNewMsgNoti];
  102. }
  103. - (void)showNewMsgNoti {
  104. _remindArray = [[JXBlogRemind sharedInstance] doFetchUnread];
  105. NSString *newMsgNum = [NSString stringWithFormat:@"%ld",_remindArray.count];
  106. if (_remindArray.count >= 10 && _remindArray.count <= 99) {
  107. self.weiboNewMsgNum.font = SYSFONT(12);
  108. }else if (_remindArray.count > 0 && _remindArray.count < 10) {
  109. self.weiboNewMsgNum.font = SYSFONT(13);
  110. }else if(_remindArray.count > 99){
  111. self.weiboNewMsgNum.font = SYSFONT(9);
  112. }
  113. self.weiboNewMsgNum.text = newMsgNum;
  114. // [g_mainVC.tb setBadge:2 title:newMsgNum];
  115. int number = 0;
  116. if (g_App.linkArray.count == 0) {
  117. number = 2;
  118. }else if(g_App.linkArray.count == 1){
  119. number = 100;
  120. }else if(g_App.linkArray.count == 2){
  121. number = 100;
  122. }
  123. [g_mainVC.tb setBadge:number title:newMsgNum];
  124. self.weiboNewMsgNum.hidden = _remindArray.count <= 0;
  125. }
  126. - (void)setupViews {
  127. UIButton *qrCodeBtn = [[UIButton alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH-15*2-18, JX_SCREEN_TOP-15*2-18, 18+15*2, 18+15*2)];
  128. [qrCodeBtn setImage:[UIImage imageNamed:@"square_qrcode"] forState:UIControlStateNormal];
  129. [qrCodeBtn addTarget:self action:@selector(onQrCode) forControlEvents:UIControlEventTouchUpInside];
  130. [self.tableHeader addSubview:qrCodeBtn];
  131. UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 0)];
  132. baseView.backgroundColor = [UIColor whiteColor];
  133. [self.tableBody addSubview:baseView];
  134. //顶部图片
  135. _topImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 180)];
  136. [baseView addSubview:_topImageView];
  137. CGFloat fl = (_topImageView.frame.size.width/_topImageView.frame.size.height);
  138. [_topImageView sd_setImageWithURL:[NSURL URLWithString:g_config.headBackgroundImg] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  139. if (error) {
  140. image = [UIImage imageNamed:@"Default_Gray"];
  141. }
  142. _topImageView.image = [ImageResize image:image fillSize:CGSizeMake((_topImageView.frame.size.height+200)*fl, _topImageView.frame.size.height+200)];
  143. }];
  144. UIView *boldLine = [[UIView alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(_topImageView.frame)+20, 3, 20)];
  145. boldLine.backgroundColor = THEMECOLOR;
  146. [baseView addSubview:boldLine];
  147. //热门应用
  148. CGSize size = [Localized(@"JX_TopicalApplication") boundingRectWithSize:CGSizeMake(MAXFLOAT, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:SYSFONT(18)} context:nil].size;
  149. UILabel *hotLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(boldLine.frame)+10, CGRectGetMinY(boldLine.frame), size.width, 20)];
  150. hotLabel.text = Localized(@"JX_TopicalApplication");
  151. hotLabel.font = SYSFONT(17);
  152. [baseView addSubview:hotLabel];
  153. //更多应用敬请期待!
  154. UILabel *hintLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(hotLabel.frame)+10, CGRectGetMinY(boldLine.frame)+6, 160, 14)];
  155. hintLabel.text = Localized(@"JX_MoreApps");
  156. hintLabel.textColor = [UIColor grayColor];
  157. hintLabel.font = SYSFONT(12);
  158. [baseView addSubview:hintLabel];
  159. // 左右滑 菜单栏
  160. _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(hotLabel.frame)+5, JX_SCREEN_WIDTH, 0)];
  161. _scrollView.showsVerticalScrollIndicator = NO;
  162. _scrollView.showsHorizontalScrollIndicator = NO;
  163. [baseView addSubview:_scrollView];
  164. BOOL lifeCircle = YES; // 生活圈
  165. BOOL videoMeeting = YES; // 视频会议
  166. BOOL liveVideo = YES; // 视频直播
  167. BOOL shortVideo = YES; // 短视频
  168. BOOL peopleNearby = YES; // 附近的人
  169. BOOL scan = YES; // 扫一扫
  170. if (g_config.popularAPP) {
  171. lifeCircle = [[g_config.popularAPP objectForKey:@"lifeCircle"] boolValue];
  172. videoMeeting = [[g_config.popularAPP objectForKey:@"videoMeeting"] boolValue];
  173. liveVideo = [[g_config.popularAPP objectForKey:@"liveVideo"] boolValue];
  174. shortVideo = [[g_config.popularAPP objectForKey:@"shortVideo"] boolValue];
  175. peopleNearby = [[g_config.popularAPP objectForKey:@"peopleNearby"] boolValue];
  176. scan = [[g_config.popularAPP objectForKey:@"scan"] boolValue];
  177. }
  178. UIButton *button;
  179. // 图片在button中的左右间隙
  180. int leftInset = (button.frame.size.width - SQUARE_HEIGHT)/2;
  181. int btnX = 0;
  182. int btnY = 0;
  183. if (lifeCircle) {
  184. // 生活圈
  185. button = [self createButtonWithFrame:CGRectMake(0, btnY, JX_SCREEN_WIDTH/5, 0) title:Localized(@"JX_LifeCircle") icon:@"square_life" highlighted:@"square_life_highlighted" index:JXSquareTypeLife];
  186. }
  187. #ifdef Meeting_Version
  188. if (videoMeeting) {
  189. // 视频会议
  190. btnX += button.frame.size.width;
  191. button = [self createButtonWithFrame:CGRectMake(btnX, btnY, JX_SCREEN_WIDTH/5, 0) title:Localized(@"JXSettingVC_VideoMeeting") icon:@"square_video" highlighted:@"square_video_highlighted" index:JXSquareTypeVideo];
  192. }
  193. #endif
  194. #ifdef Live_Version
  195. if (liveVideo) {
  196. // 视频直播
  197. btnX += button.frame.size.width;
  198. button = [self createButtonWithFrame:CGRectMake(btnX, btnY, JX_SCREEN_WIDTH/5, 0) title:Localized(@"JX_LiveVideo") icon:@"square_videochat" highlighted:@"square_videochat_highlighted" index:JXSquareTypeVideoLive];
  199. }
  200. #endif
  201. if (shortVideo) {
  202. // 抖音模块
  203. btnX += button.frame.size.width;
  204. button = [self createButtonWithFrame:CGRectMake(btnX, btnY, JX_SCREEN_WIDTH/5, 0) title:Localized(@"JX_ShorVideo") icon:@"square_douyin" highlighted:@"square_douyin_highlighted" index:JXSquareTypeShortVideo];
  205. }
  206. if (peopleNearby) {
  207. // 附近的人
  208. btnX += button.frame.size.width;
  209. button = [self createButtonWithFrame:CGRectMake(btnX, btnY, JX_SCREEN_WIDTH/5, 0) title:Localized(@"JXNearVC_NearPer") icon:@"square_nearby" highlighted:@"square_nearby_highlighted" index:JXSquareTypeNearby];
  210. }
  211. // if (scan) {
  212. // // 扫一扫
  213. // btnX += button.frame.size.width;
  214. // button = [self createButtonWithFrame:CGRectMake(btnX, btnY, JX_SCREEN_WIDTH/5, 0) title:Localized(@"JX_Scan") icon:@"square_qrcode" index:JXSquareTypeQrcode];
  215. // }
  216. CGRect scrollFrame = _scrollView.frame;
  217. scrollFrame.size.height = button.frame.size.height;
  218. _scrollView.frame = scrollFrame;
  219. _scrollView.contentSize = CGSizeMake(btnX+button.frame.size.width, 0);
  220. CGRect frame = baseView.frame;
  221. frame.size.height = CGRectGetMaxY(_scrollView.frame)+25;
  222. baseView.frame = frame;
  223. if ([g_config.enableMpModule boolValue]) {
  224. //热门公众号 以及列表
  225. UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(baseView.frame)+8, JX_SCREEN_WIDTH, 50)];
  226. headerView.backgroundColor = [UIColor whiteColor];
  227. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 3, 20)];
  228. line.backgroundColor = THEMECOLOR;
  229. [headerView addSubview:line];
  230. UILabel *numLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(line.frame)+8, 20, 240, 20)];
  231. numLabel.text = Localized(@"JX_PopularPublicAccount");
  232. numLabel.font = SYSFONT(17);
  233. [headerView addSubview:numLabel];
  234. [self.tableBody addSubview:headerView];
  235. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(headerView.frame), JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT - JX_SCREEN_TOP - CGRectGetMaxY(headerView.frame)-JX_SCREEN_BOTTOM) style:UITableViewStylePlain];
  236. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  237. _tableView.backgroundColor = HEXCOLOR(0xF2F2F2);
  238. _tableView.scrollEnabled = NO;
  239. // _tableView.tableHeaderView = headerView;
  240. _tableView.delegate = self;
  241. _tableView.dataSource = self;
  242. [self.tableBody addSubview:_tableView];
  243. [self addHeader];
  244. [self addFooter];
  245. }
  246. }
  247. - (void)stopLoading {
  248. [_footer endRefreshing];
  249. [_header endRefreshing];
  250. }
  251. - (void)addFooter
  252. {
  253. if(_footer){
  254. // [_footer free];
  255. // return;
  256. }
  257. _footer = [MJRefreshFooterView footer];
  258. _footer.scrollView = _tableView;
  259. __weak JXSquareViewController *weakSelf = self;
  260. _footer.beginRefreshingBlock = ^(MJRefreshBaseView *refreshView) {
  261. [weakSelf scrollToPageDown];
  262. // NSLog(@"%@----开始进入刷新状态", refreshView.class);
  263. };
  264. _footer.endStateChangeBlock = ^(MJRefreshBaseView *refreshView) {
  265. // 刷新完毕就会回调这个Block
  266. // NSLog(@"%@----刷新完毕", refreshView.class);
  267. };
  268. _footer.refreshStateChangeBlock = ^(MJRefreshBaseView *refreshView, MJRefreshState state) {
  269. // 控件的刷新状态切换了就会调用这个block
  270. switch (state) {
  271. case MJRefreshStateNormal:
  272. // NSLog(@"%@----切换到:普通状态", refreshView.class);
  273. break;
  274. case MJRefreshStatePulling:
  275. // NSLog(@"%@----切换到:松开即可刷新的状态", refreshView.class);
  276. break;
  277. case MJRefreshStateRefreshing:
  278. // NSLog(@"%@----切换到:正在刷新状态", refreshView.class);
  279. break;
  280. default:
  281. break;
  282. }
  283. };
  284. }
  285. - (void)addHeader
  286. {
  287. if(_header){
  288. // [_header free];
  289. // return;
  290. }
  291. _header = [MJRefreshHeaderView header];
  292. _header.scrollView = _tableView;
  293. __weak JXSquareViewController *weakSelf = self;
  294. _header.beginRefreshingBlock = ^(MJRefreshBaseView *refreshView) {
  295. // 进入刷新状态就会回调这个Block
  296. [weakSelf scrollToPageUp];
  297. };
  298. _header.endStateChangeBlock = ^(MJRefreshBaseView *refreshView) {
  299. // 刷新完毕就会回调这个Block
  300. // NSLog(@"%@----刷新完毕", refreshView.class);
  301. };
  302. _header.refreshStateChangeBlock = ^(MJRefreshBaseView *refreshView, MJRefreshState state) {
  303. // 控件的刷新状态切换了就会调用这个block
  304. switch (state) {
  305. case MJRefreshStateNormal:
  306. // NSLog(@"%@----切换到:普通状态", refreshView.class);
  307. break;
  308. case MJRefreshStatePulling:
  309. // NSLog(@"%@----切换到:松开即可刷新的状态", refreshView.class);
  310. break;
  311. case MJRefreshStateRefreshing:
  312. // NSLog(@"%@----切换到:正在刷新状态", refreshView.class);
  313. break;
  314. default:
  315. break;
  316. }
  317. };
  318. }
  319. //顶部刷新获取数据
  320. -(void)scrollToPageUp{
  321. _page = 0;
  322. [self getServerData];
  323. }
  324. -(void)scrollToPageDown{
  325. [self getServerData];
  326. }
  327. #pragma mark - tableView dataSource
  328. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  329. return 1;
  330. }
  331. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  332. return _array.count;
  333. }
  334. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  335. if (_array.count == 1) {
  336. return 100;
  337. }
  338. return 59;
  339. }
  340. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  341. static NSString *cellIdentifier = @"JXCell";
  342. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  343. JXUserObject *user = _array[indexPath.row];
  344. if (_array.count == 1) {
  345. if ([cell isKindOfClass:[JXCell class]]) {
  346. cell = nil;
  347. }
  348. if (!cell) {
  349. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  350. UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(15, 30, 40, 40)];
  351. imgV.tag = 100;
  352. imgV.layer.cornerRadius = imgV.frame.size.width/2;
  353. imgV.layer.masksToBounds = YES;
  354. [cell.contentView addSubview:imgV];
  355. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(imgV.frame)+10, 41.5, 200, 17)];
  356. label.tag = 101;
  357. [cell.contentView addSubview:label];
  358. }
  359. UIImageView *imgV = [cell.contentView viewWithTag:100];
  360. UILabel *label = [cell.contentView viewWithTag:101];
  361. [g_server getHeadImageSmall:user.userId userName:user.userNickname imageView:imgV];
  362. label.text = user.userNickname;
  363. }else {
  364. JXCell *cell=nil;
  365. if(cell==nil){
  366. cell = [[JXCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  367. }
  368. cell.title = user.userNickname;
  369. cell.index = (int)indexPath.row;
  370. cell.userId = user.userId;
  371. [cell.lbTitle setText:cell.title];
  372. cell.isSmall = YES;
  373. [cell headImageViewImageWithUserId:nil roomId:nil];
  374. if (indexPath.row == _array.count - 1) {
  375. cell.lineView.frame = CGRectMake(cell.lineView.frame.origin.x, cell.lineView.frame.origin.y, cell.lineView.frame.size.width, 0);
  376. }else {
  377. cell.lineView.frame = CGRectMake(cell.lineView.frame.origin.x, cell.lineView.frame.origin.y, cell.lineView.frame.size.width, LINE_WH);
  378. }
  379. return cell;
  380. }
  381. return cell;
  382. }
  383. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  384. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  385. JXUserObject *user = _array[indexPath.row];
  386. [g_server getUser:user.userId toView:self];
  387. }
  388. //服务端返回数据
  389. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  390. [_wait hide];
  391. if( [aDownload.action isEqualToString:act_PublicSearch] ){
  392. [self stopLoading];
  393. if (array1.count < 20) {
  394. _footer.hidden = YES;
  395. }
  396. NSMutableArray *arr = [[NSMutableArray alloc] init];
  397. if(_page == 0){
  398. [_array removeAllObjects];
  399. for (int i = 0; i < array1.count; i++) {
  400. JXUserObject *user = [[JXUserObject alloc] init];
  401. [user getDataFromDict:array1[i]];
  402. [arr addObject:user];
  403. }
  404. [_array addObjectsFromArray:arr];
  405. }else{
  406. if([array1 count]>0){
  407. for (int i = 0; i < array1.count; i++) {
  408. JXUserObject *user = [[JXUserObject alloc] init];
  409. [user getDataFromDict:array1[i]];
  410. [arr addObject:user];
  411. }
  412. [_array addObjectsFromArray:arr];
  413. }
  414. }
  415. _page ++;
  416. [self setTableviewHeight];
  417. [_tableView reloadData];
  418. }
  419. if( [aDownload.action isEqualToString:act_UserGet] ){
  420. JXUserObject* user = [[JXUserObject alloc]init];
  421. [user getDataFromDict:dict];
  422. if([user.userType intValue] == 2 && [user.status intValue] != 2){
  423. JXUserInfoVC* userVC = [JXUserInfoVC alloc];
  424. userVC.userId = user.userId;
  425. userVC.user = user;
  426. userVC.fromAddType = 6;
  427. userVC = [userVC init];
  428. [g_navigation pushViewController:userVC animated:YES];
  429. return;
  430. }
  431. JXChatViewController *sendView=[JXChatViewController alloc];
  432. sendView.scrollLine = 0;
  433. sendView.title = user.userNickname;
  434. sendView.chatPerson = user;
  435. sendView = [sendView init];
  436. [g_navigation pushViewController:sendView animated:YES];
  437. }
  438. }
  439. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  440. [_wait hide];
  441. [self stopLoading];
  442. return hide_error;
  443. }
  444. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  445. [_wait hide];
  446. [self stopLoading];
  447. return hide_error;
  448. }
  449. -(void) didServerConnectStart:(JXConnection*)aDownload{
  450. // [_wait start];
  451. }
  452. - (void)setTableviewHeight {
  453. int height = [self tableView:_tableView heightForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
  454. CGRect frame = _tableView.frame;
  455. frame.size.height = height*_array.count;
  456. _tableView.frame = frame;
  457. self.tableBody.contentSize = CGSizeMake(0, CGRectGetMaxY(_tableView.frame)+50+8);
  458. }
  459. - (void)clickButtonWithTag:(NSInteger)btnTag {
  460. switch (btnTag) {
  461. case JXSquareTypeLife:{// 生活圈
  462. WeiboViewControlle *weiboVC = [WeiboViewControlle alloc];
  463. weiboVC.user = g_server.myself;
  464. weiboVC = [weiboVC init];
  465. [g_navigation pushViewController:weiboVC animated:YES];
  466. }
  467. break;
  468. case JXSquareTypeVideo:{// 视频会议
  469. #ifdef Meeting_Version
  470. if(g_xmpp.isLogined != 1){
  471. [g_xmpp showXmppOfflineAlert];
  472. return;
  473. }
  474. NSString *str1;
  475. NSString *str2;
  476. str1 = Localized(@"JXSettingVC_VideoMeeting");
  477. str2 = Localized(@"JX_Meeting");
  478. JXActionSheetVC *actionVC = [[JXActionSheetVC alloc] initWithImages:@[@"meeting_tel",@"meeting_video"] names:@[str2,str1]];
  479. actionVC.delegate = self;
  480. [self presentViewController:actionVC animated:NO completion:nil];
  481. #endif
  482. }
  483. break;
  484. case JXSquareTypeVideoLive:{ // 视频直播
  485. #ifdef Live_Version
  486. JXLiveViewController *vc = [[JXLiveViewController alloc] init];
  487. [g_navigation pushViewController:vc animated:YES];
  488. #endif
  489. }
  490. break;
  491. case JXSquareTypeShortVideo:{// 短视频
  492. #ifdef Meeting_Version
  493. #ifdef Live_Version
  494. JXSmallVideoViewController *vc = [[JXSmallVideoViewController alloc] init];
  495. [g_navigation pushViewController:vc animated:YES];
  496. return;
  497. // GKDYHomeViewController *vc = [[GKDYHomeViewController alloc] init];
  498. // [g_navigation pushViewController:vc animated:NO];
  499. // return;
  500. #endif
  501. #endif
  502. [JXMyTools showTipView:Localized(@"JX_It'sNotOpenYet")];
  503. }
  504. break;
  505. case JXSquareTypeQrcode:{// 扫一扫
  506. AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
  507. if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied)
  508. {
  509. [g_server showMsg:Localized(@"JX_CanNotopenCenmar")];
  510. return;
  511. }
  512. JXScanQRViewController * scanVC = [[JXScanQRViewController alloc] init];
  513. [g_navigation pushViewController:scanVC animated:YES];
  514. }
  515. break;
  516. case JXSquareTypeNearby:{// 附近的人
  517. JXNearVC * nearVc = [[JXNearVC alloc] init];
  518. [g_navigation pushViewController:nearVc animated:YES];
  519. }
  520. break;
  521. default:
  522. break;
  523. }
  524. }
  525. #ifdef Meeting_Version
  526. - (void)actionSheet:(JXActionSheetVC *)actionSheet didButtonWithIndex:(NSInteger)index {
  527. if (index == 0) {
  528. [self onGroupAudioMeeting:nil];
  529. }else if(index == 1){
  530. [self onGroupVideoMeeting:nil];
  531. }
  532. }
  533. -(void)onGroupAudioMeeting:(JXMessageObject*)msg{
  534. self.isAudioMeeting = YES;
  535. [self onInvite];
  536. }
  537. -(void)onGroupVideoMeeting:(JXMessageObject*)msg{
  538. self.isAudioMeeting = NO;
  539. [self onInvite];
  540. }
  541. -(void)onInvite{
  542. NSMutableSet* p = [[NSMutableSet alloc]init];
  543. JXSelectFriendsVC* vc = [JXSelectFriendsVC alloc];
  544. vc.isNewRoom = NO;
  545. vc.isShowMySelf = NO;
  546. vc.type = JXSelectFriendTypeSelFriends;
  547. vc.existSet = p;
  548. vc.delegate = self;
  549. vc.didSelect = @selector(meetingAddMember:);
  550. vc = [vc init];
  551. [g_navigation pushViewController:vc animated:YES];
  552. }
  553. - (void) remindNotif:(NSNotification *)notif {
  554. // JXMessageObject *msg = notif.object;
  555. // _remindArray = [[JXBlogRemind sharedInstance] doFetchUnread];
  556. // if (_remindArray.count > 0) {
  557. // NSString *newMsgNum = [NSString stringWithFormat:@"%ld",_remindArray.count];
  558. // self.weiboNewMsgNum.hidden = NO;
  559. // self.weiboNewMsgNum.text = newMsgNum;
  560. // [g_mainVC.tb setBadge:2 title:newMsgNum];
  561. // }
  562. [self showNewMsgNoti];
  563. }
  564. -(void)meetingAddMember:(JXSelectFriendsVC*)vc{
  565. int type;
  566. if (self.isAudioMeeting) {
  567. type = kWCMessageTypeAudioMeetingInvite;
  568. }else {
  569. type = kWCMessageTypeVideoMeetingInvite;
  570. }
  571. for(NSNumber* n in vc.set){
  572. JXUserObject *user;
  573. if (vc.seekTextField.text.length > 0) {
  574. user = vc.searchArray[[n intValue] % 100000-1];
  575. }else{
  576. user = [[vc.letterResultArr objectAtIndex:[n intValue] / 100000-1] objectAtIndex:[n intValue] % 100000-1];
  577. }
  578. NSString* s = [NSString stringWithFormat:@"%@",user.userId];
  579. [g_meeting sendMeetingInvite:s toUserName:user.userNickname roomJid:MY_USER_ID callId:nil type:type];
  580. }
  581. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  582. if (g_meeting.isMeeting) {
  583. return;
  584. }
  585. JXAVCallViewController *avVC = [[JXAVCallViewController alloc] init];
  586. avVC.roomNum = MY_USER_ID;
  587. avVC.isAudio = self.isAudioMeeting;
  588. avVC.isGroup = YES;
  589. avVC.toUserName = MY_USER_NAME;
  590. avVC.view.frame = [UIScreen mainScreen].bounds;
  591. [g_window addSubview:avVC.view];
  592. });
  593. }
  594. #endif
  595. - (UIButton *)createButtonWithFrame:(CGRect)frame title:(NSString *)title icon:(NSString *)iconName highlighted:(NSString *)highlighted index:(NSInteger)index {
  596. UIButton *button = [[UIButton alloc] init];
  597. button.frame = frame;
  598. button.tag = index;
  599. [button addTarget:self action:@selector(didButton:) forControlEvents:UIControlEventTouchUpInside];
  600. [button addTarget:self action:@selector(didButtonDown:) forControlEvents:UIControlEventTouchDown];
  601. [button addTarget:self action:@selector(didButtonDragInside:) forControlEvents:UIControlEventTouchDragInside];
  602. [button addTarget:self action:@selector(didButtonDragOutside:) forControlEvents:UIControlEventTouchDragOutside];
  603. [_scrollView addSubview:button];
  604. // CGFloat X = frame.origin.x;
  605. // CGFloat Y = frame.origin.y;
  606. CGFloat inset =(JX_SCREEN_WIDTH-SQUARE_HEIGHT*5)/10; // 间隔
  607. // CGFloat originY = Y > 0 ? 20+51- INSET_IMAGE : 20+51;
  608. CGFloat originY = 15;
  609. _imgV = [[UIButton alloc] init];
  610. _imgV.frame = CGRectMake(inset, originY, SQUARE_HEIGHT, SQUARE_HEIGHT);
  611. [_imgV setImage:[UIImage imageNamed:iconName] forState:UIControlStateNormal];
  612. [_imgV setImage:[UIImage imageNamed:highlighted] forState:UIControlStateHighlighted];
  613. _imgV.userInteractionEnabled = NO;
  614. _imgV.tag = index;
  615. [button addSubview:_imgV];
  616. [_subviews addObject:_imgV];
  617. _imgV.highlighted = button.highlighted;
  618. if (index == JXSquareTypeLife) {
  619. self.weiboNewMsgNum = [[UILabel alloc] initWithFrame:CGRectMake(SQUARE_HEIGHT - 18, -2, 20, 20)];
  620. self.weiboNewMsgNum.backgroundColor = HEXCOLOR(0xEF2D37);
  621. self.weiboNewMsgNum.font = SYSFONT(13);
  622. self.weiboNewMsgNum.textAlignment = NSTextAlignmentCenter;
  623. self.weiboNewMsgNum.layer.cornerRadius = self.weiboNewMsgNum.frame.size.width / 2;
  624. self.weiboNewMsgNum.layer.masksToBounds = YES;
  625. self.weiboNewMsgNum.hidden = YES;
  626. self.weiboNewMsgNum.textColor = [UIColor whiteColor];
  627. self.weiboNewMsgNum.text = @"99";
  628. [_imgV addSubview:self.weiboNewMsgNum];
  629. }
  630. CGSize size = [title boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:SYSFONT(14)} context:nil].size;
  631. UILabel *lab = [[UILabel alloc] init];
  632. lab.text = title;
  633. lab.textAlignment = NSTextAlignmentCenter;
  634. lab.textColor = HEXCOLOR(0x323232);
  635. lab.font = SYSFONT(14);
  636. lab.frame = CGRectMake(0, CGRectGetMaxY(_imgV.frame)+INSET_IMAGE, frame.size.width - 5, size.height);
  637. CGPoint center = lab.center;
  638. center.x = _imgV.center.x;
  639. lab.center = center;
  640. CGRect btnFrame = button.frame;
  641. btnFrame.size.height = originY+SQUARE_HEIGHT+size.height+INSET_IMAGE;
  642. button.frame = btnFrame;
  643. [button addSubview:lab];
  644. return button;
  645. }
  646. // 点击事件
  647. - (void)didButton:(UIButton *)button {
  648. for (UIView *sub in button.subviews) {
  649. if ([sub isKindOfClass:[UIButton class]]) {
  650. UIButton *btn = (UIButton *)sub;
  651. btn.highlighted = button.highlighted;
  652. [self clickButtonWithTag:button.tag];
  653. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  654. btn.highlighted = NO;
  655. });
  656. }
  657. }
  658. }
  659. // 按下事件
  660. - (void)didButtonDown:(UIButton *)button {
  661. for (UIView *sub in button.subviews) {
  662. if ([sub isKindOfClass:[UIButton class]]) {
  663. UIButton *btn = (UIButton *)sub;
  664. btn.highlighted = button.highlighted;
  665. }
  666. }
  667. }
  668. // 手指在control的bounds范围内拖动的的事件
  669. - (void)didButtonDragInside:(UIButton *)button {
  670. UIButton *btn;
  671. for (UIView *sub in button.subviews) {
  672. if ([sub isKindOfClass:[UIButton class]]) {
  673. btn = (UIButton *)sub;
  674. btn.highlighted = button.highlighted;
  675. }
  676. }
  677. }
  678. - (void)didButtonDragOutside:(UIButton *)button {
  679. UIButton *btn;
  680. for (UIView *sub in button.subviews) {
  681. if ([sub isKindOfClass:[UIButton class]]) {
  682. btn = (UIButton *)sub;
  683. btn.highlighted = button.highlighted;
  684. }
  685. }
  686. }
  687. @end