JXSearchUserListVC.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. //
  2. // JXSearchUserListVC.m
  3. // shiku_im
  4. //
  5. // Created by p on 2018/4/18.
  6. // Copyright © 2018年 Reese. All rights reserved.
  7. //
  8. #import "JXSearchUserListVC.h"
  9. #import "JXNearCell.h"
  10. #import "JXUserInfoVC.h"
  11. #import "JXChatViewC.h"
  12. @interface JXSearchUserListVC ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>{
  13. JXCollectionView *_collectionView;
  14. MJRefreshHeaderView *_refreshHeader;
  15. MJRefreshFooterView *_refreshFooter;
  16. }
  17. @property (nonatomic, strong) NSMutableArray *array;
  18. @property (nonatomic,assign)int page;
  19. @property (nonatomic, assign) NSInteger selectNum;
  20. @property (nonatomic, assign) int oldRowCount;
  21. @property (nonatomic, assign) NSTimeInterval lastScrollTime;
  22. @end
  23. @implementation JXSearchUserListVC
  24. - (id)init
  25. {
  26. self = [super init];
  27. if (self) {
  28. self.heightHeader = JX_SCREEN_TOP;
  29. self.heightFooter = 0;
  30. //self.view.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT);
  31. self.isFreeOnClose = YES;
  32. self.isGotoBack = YES;
  33. _array = [[NSMutableArray alloc] init];
  34. _page=0;
  35. [g_notify addObserver:self selector:@selector(refreshCallPhone:) name:kNearRefreshCallPhone object:nil];
  36. }
  37. return self;
  38. }
  39. - (void)refreshCallPhone:(NSNotification *)notif {
  40. [_collectionView reloadItemsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:self.selectNum inSection:0], nil]];
  41. }
  42. - (void)viewDidLoad {
  43. [super viewDidLoad];
  44. // Do any additional setup after loading the view.
  45. self.tableBody.backgroundColor = THEMEBACKCOLOR;
  46. [self createHeadAndFoot];
  47. [self customView];
  48. [self getServerData];
  49. }
  50. - (void) customView {
  51. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  52. _collectionView = [[JXCollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.tableBody.frame.size.height)collectionViewLayout:layout];
  53. _collectionView.frame = self.tableBody.frame;
  54. _collectionView.backgroundColor = THEMEBACKCOLOR;
  55. _collectionView.contentSize = CGSizeMake(0, self.tableBody.frame.size.height+10);
  56. _collectionView.delegate = self;
  57. _collectionView.dataSource = self;
  58. [_collectionView registerClass:[JXNearCell class] forCellWithReuseIdentifier:NSStringFromClass([JXNearCell class])];
  59. [self.view addSubview:_collectionView];
  60. _refreshHeader = [MJRefreshHeaderView header];
  61. _refreshFooter = [MJRefreshFooterView footer];
  62. [self addRefreshViewWith:_collectionView header:_refreshHeader footer:_refreshFooter];
  63. }
  64. //添加刷新控件
  65. - (void)addRefreshViewWith:(UICollectionView *)collectionView header:(MJRefreshHeaderView *)header footer:(MJRefreshFooterView *)footer{
  66. header.scrollView = collectionView;
  67. footer.scrollView = collectionView;
  68. header.beginRefreshingBlock = ^(MJRefreshBaseView *baseView){
  69. [self scrollToPageUp];
  70. _page = 0;
  71. // [self getServerData];
  72. };
  73. footer.beginRefreshingBlock = ^(MJRefreshBaseView *baseView){
  74. [self scrollToPageDown];
  75. // [self getServerData];
  76. };
  77. }
  78. //顶部刷新获取数据
  79. -(void)scrollToPageUp{
  80. _page = 0;
  81. [self getServerData];
  82. [self performSelector:@selector(stopLoading) withObject:nil afterDelay:1.0];
  83. }
  84. -(void)scrollToPageDown{
  85. _page++;
  86. [self getServerData];
  87. }
  88. - (void)stopLoading {
  89. [_refreshHeader endRefreshing];
  90. [_refreshFooter endRefreshing];
  91. }
  92. -(void)getServerData{
  93. [_wait start];
  94. if (_isUserSearch) {
  95. [g_server nearbyUser:_search nearOnly:NO lat:0 lng:0 page:_page toView:self];
  96. }else {
  97. [g_server searchPublicWithKeyWorld:_keyWorld limit:20 page:_page toView:self];
  98. }
  99. }
  100. #pragma mark UICollectionView delegate
  101. #pragma mark-----多少组
  102. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  103. return 1;
  104. }
  105. #pragma mark-----多少个
  106. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  107. return _array.count;
  108. }
  109. #pragma mark-----每一个的大小
  110. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  111. {
  112. return CGSizeMake((JX_SCREEN_WIDTH - 38)/2, (JX_SCREEN_WIDTH - 38)/2+53);
  113. }
  114. #pragma mark-----每一个边缘留白
  115. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
  116. return UIEdgeInsetsMake(10, 15, 10, 15);
  117. }
  118. #pragma mark-----最小行间距
  119. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  120. return 10.0;
  121. }
  122. #pragma mark-----最小竖间距
  123. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  124. return 8.0;
  125. }
  126. #pragma mark-----返回每个单元格是否可以被选择
  127. - (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath{
  128. return YES;
  129. }
  130. #pragma mark-----创建单元格
  131. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  132. JXNearCell *cell;
  133. cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([JXNearCell class]) forIndexPath:indexPath];
  134. cell.backgroundColor = [UIColor whiteColor];
  135. // cell.delegate = self;
  136. // cell.didTouch = @selector(onHeadImage:);
  137. // if (_array.count)
  138. // [cell doRefreshNearExpert:[_array objectAtIndex:indexPath.row]];
  139. if (_array.count) {
  140. [cell doRefreshNearExpert:[_array objectAtIndex:indexPath.row]];
  141. }
  142. // else if (_selMenu == 2) {
  143. // if (_userArray.count) {
  144. // [cell doRefreshNearExpert:[_userArray objectAtIndex:indexPath.row]];
  145. // }
  146. // }
  147. if(indexPath.row == [self collectionView:_collectionView numberOfItemsInSection:indexPath.section]-1){
  148. BOOL flag = YES;
  149. if(_oldRowCount == [self collectionView:_collectionView numberOfItemsInSection:indexPath.section])//说明翻页之后,数据没有增长,则不再自动翻页,但可手动翻页
  150. flag = NO;
  151. if([[NSDate date] timeIntervalSince1970]-_lastScrollTime<0.5)//避免刷新过快
  152. flag = NO;;
  153. if (flag) {
  154. _oldRowCount = (int)[self collectionView:_collectionView numberOfItemsInSection:indexPath.section];
  155. [self scrollToPageDown];
  156. _lastScrollTime = [[NSDate date] timeIntervalSince1970];
  157. }
  158. }
  159. return cell;
  160. }
  161. #pragma mark-----点击单元格
  162. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  163. // [self stopAllPlayer];
  164. self.selectNum = indexPath.row;
  165. NSDictionary* d;
  166. d = [_array objectAtIndex:indexPath.row];
  167. // [g_server getUser:[d objectForKey:@"userId"] toView:self];
  168. int fromAddType = 0;
  169. NSString *name = [d objectForKey:@"nickname"];
  170. if ([name rangeOfString:_keyWorld].location != NSNotFound) {
  171. fromAddType = 5;
  172. }else {
  173. fromAddType = 4;
  174. }
  175. JXUserInfoVC* vc = [JXUserInfoVC alloc];
  176. vc.userId = [d objectForKey:@"userId"];
  177. vc.fromAddType = fromAddType;
  178. vc.isSearchPush=@"10000";
  179. vc.isShowGoinBtn = YES;
  180. vc = [vc init];
  181. [g_navigation pushViewController:vc animated:YES];
  182. d = nil;
  183. }
  184. - (void)didReceiveMemoryWarning {
  185. [super didReceiveMemoryWarning];
  186. // Dispose of any resources that can be recreated.
  187. }
  188. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  189. [_wait stop];
  190. [self stopLoading];
  191. if([aDownload.action isEqualToString:act_nearbyUser] || [aDownload.action isEqualToString:act_nearNewUser]||[aDownload.action isEqualToString:act_PublicSearch]){
  192. if(_page == 0){
  193. // [_array removeAllObjects];
  194. // [_array addObjectsFromArray:array1];
  195. [_array removeAllObjects];
  196. [_array addObjectsFromArray:array1];
  197. }else{
  198. if([array1 count]>0){
  199. [_array addObjectsFromArray:array1];
  200. }
  201. }
  202. if (_array.count <= 0 && !_isUserSearch) {
  203. [g_App showAlert:Localized(@"JX_NoSuchServerNo.IsAvailable")];
  204. }
  205. [_collectionView reloadData];
  206. }else if([aDownload.action isEqualToString:act_UserGet]){
  207. JXUserObject* user = [[JXUserObject alloc]init];
  208. [user getDataFromDict:dict];
  209. JXUserInfoVC* vc = [JXUserInfoVC alloc];
  210. vc.user = user;
  211. vc.isSearchPush=@"10000";
  212. vc = [vc init];
  213. // [g_window addSubview:vc.view];
  214. [g_navigation pushViewController:vc animated:YES];
  215. // [user release];
  216. }
  217. // else if ([aDownload.action isEqualToString:act_nearNewUser]) {
  218. // if (_page == 0) {
  219. //// [_array removeAllObjects];
  220. //// [_array addObjectsFromArray:array1];
  221. // [_userArray removeAllObjects];
  222. // [_userArray addObjectsFromArray:array1];
  223. // }else{
  224. // if ([_userArray count] > 0) {
  225. // [_userArray addObjectsFromArray:array1];
  226. // }else{
  227. // [g_App showAlert:Localized(@"JX_NotMoreData")];
  228. // _isNoMoreData = YES;
  229. // _search = nil;
  230. // _search = [[searchData alloc] init];
  231. // _search.minAge = 0;
  232. // _search.maxAge = 200;
  233. // _search.sex = -1;
  234. // _page=0;
  235. // }
  236. //
  237. // }
  238. // [_collectionView reloadData];
  239. // }
  240. }
  241. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  242. [_wait stop];
  243. return show_error;
  244. }
  245. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  246. [_wait stop];
  247. return show_error;
  248. }
  249. -(void) didServerConnectStart:(JXConnection*)aDownload{
  250. [_wait start];
  251. }
  252. /*
  253. #pragma mark - Navigation
  254. // In a storyboard-based application, you will often want to do a little preparation before navigation
  255. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  256. // Get the new view controller using [segue destinationViewController].
  257. // Pass the selected object to the new view controller.
  258. }
  259. */
  260. @end