MOSearchUserVC.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. //
  2. // MOSearchUserVC.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2023/12/25.
  6. //
  7. //一页的size
  8. #define kPageSize 15
  9. #import "MOSearchUserVC.h"
  10. #import "MOHistoryListCell.h"
  11. #import "MOContactSearchTxf.h"
  12. #import "MOUserHomePageVC.h"
  13. #import "MOShowLivePagesVC.h"
  14. #import "UITextField+CustomClearButton.h"
  15. @interface MOSearchUserVC ()<UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate>
  16. @property (nonatomic, strong) BigBtn *backButton;
  17. @property (nonatomic, strong) UITableView *tableView;
  18. @property (nonatomic, strong) UIImageView *searchBgImgView;
  19. @property (nonatomic, strong) UIImageView *searchIconView;
  20. @property (nonatomic, strong) UITextField *searchTextField;
  21. @property (nonatomic, strong) NSMutableArray *dataArr;
  22. /** 没有更多的数据视图 */
  23. @property (nonatomic, strong) MONoMoreDataView *noMoreDataView;
  24. @property (nonatomic, copy) NSString *next;
  25. @end
  26. @implementation MOSearchUserVC
  27. - (void)viewWillAppear:(BOOL)animated{
  28. [super viewWillAppear:animated];
  29. [self.navigationController setNavigationBarHidden:YES animated:animated];
  30. [[IQKeyboardManager sharedManager] setEnable:NO];
  31. }
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. [self setupUI];
  35. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  36. [self.searchTextField becomeFirstResponder];
  37. });
  38. }
  39. - (void)backButtonAction {
  40. [self.navigationController popViewControllerAnimated:YES];
  41. }
  42. #pragma mark - UITextFieldDelegate
  43. - (BOOL)textFieldShouldReturn:(UITextField *)textField{
  44. if(textField.text.length != 0){
  45. self.next = @"";
  46. NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
  47. NSDictionary *baseDict = @{@"search":textField.text,
  48. @"page":basePage};
  49. [self.tableView.mj_footer resetNoMoreData];
  50. [self toSearchSomeOneWithDict:baseDict];
  51. }
  52. return YES;
  53. }
  54. - (void)toSearchSomeOneWithDict:(NSDictionary *)dict{
  55. WEAKSELF
  56. [kHttpManager toSearchTheUserInfoWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  57. __strong typeof(weakSelf) self = weakSelf;
  58. [self.tableView.mj_footer endRefreshing];
  59. if(kCode_Success){
  60. // MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  61. MOLiveMemberData *baseModel = [MOLiveMemberData modelObjectWithDictionary:data[@"data"]];
  62. if(baseModel.next == nil || baseModel.next.length == 0){
  63. if(self.next == nil || self.next.length == 0){
  64. //第一页
  65. self.dataArr = [baseModel.userBase mutableCopy];
  66. }
  67. else{
  68. //最后一页
  69. [self.dataArr addObjectsFromArray:baseModel.userBase];
  70. }
  71. self.next = @"";
  72. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  73. }
  74. else{
  75. self.next = baseModel.next;
  76. [self.dataArr addObjectsFromArray:baseModel.userBase];
  77. }
  78. if(self.dataArr.count == 0){
  79. [MBProgressHUD showTipMessageInWindow:NSLocalString(@"mimo_common_search_no_user_tip")];
  80. }
  81. [self.tableView reloadData];
  82. self.tableView.mj_footer.hidden = (self.dataArr.count > 0) ? NO : YES;
  83. self.noMoreDataView.isHaveData = (self.dataArr.count > 0) ? YES : NO;
  84. }
  85. else{
  86. kShowNetError(data)
  87. }
  88. }];
  89. }
  90. #pragma mark - UITableViewDelegate,UITableViewDataSource
  91. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  92. return self.dataArr.count;
  93. }
  94. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  95. return 1;
  96. }
  97. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  98. WEAKSELF
  99. MOUserBase *model = self.dataArr[indexPath.section];
  100. MOHistoryListCell *cell = [tableView dequeueReusableCellWithIdentifier:MOHistoryListCell_ID];
  101. if (cell == nil){
  102. cell = [[MOHistoryListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MOHistoryListCell_ID];
  103. }
  104. cell.cellIndexPath = indexPath;
  105. cell.cellModel = model;
  106. // cell.searchText = self.searchTextField.text;
  107. cell.followBtnBlock = ^(MOUserBase * _Nonnull cellModel, NSIndexPath * _Nonnull cellIndexPath) {
  108. cellModel.follow = YES;
  109. for (MOUserBase *tempModel in weakSelf.dataArr) {
  110. if([tempModel.userProfile.id isEqualToString:cellModel.userProfile.id]){
  111. tempModel.follow = YES;
  112. break;
  113. }
  114. }
  115. NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:cellIndexPath.section];
  116. [weakSelf.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationNone];
  117. };
  118. cell.headBtnClickBlock = ^(MOUserBase * _Nonnull cellModel) {
  119. if(cellModel.liveRoomId.length > 0){
  120. //去直播间
  121. [weakSelf toShowTheLiveRoomWith:cellModel.liveRoomId];
  122. }
  123. else{
  124. //去主页
  125. if(cellModel.userProfile.id.length > 0){
  126. [weakSelf toShowTheUserHomePageWith:cellModel.userProfile.id];
  127. }
  128. }
  129. };
  130. return cell;
  131. }
  132. - (void)toShowTheLiveRoomWith:(NSString *)roomId{
  133. [MOShowAgoraKitManager shareManager].isFirstShow = YES;
  134. [MOShowAgoraKitManager shareManager].isCreatLive = NO;
  135. MOLiveList *model = [[MOLiveList alloc] init];
  136. model.id = roomId;
  137. MOShowLivePagesVC *vc = [[MOShowLivePagesVC alloc] init];
  138. vc.userType = MOShowLiveAudienceType;
  139. vc.roomList = @[model].mutableCopy;
  140. vc.focusIndex = 0;
  141. // UINavigationController *newNav = [[UINavigationController alloc] initWithRootViewController:vc];
  142. // newNav.modalPresentationStyle = UIModalPresentationFullScreen;
  143. // [self.navigationController presentViewController:newNav animated:YES completion:nil];
  144. vc.hidesBottomBarWhenPushed = YES;
  145. [self.navigationController pushViewController:vc animated:YES];
  146. }
  147. - (void)toShowTheUserHomePageWith:(NSString *)userId{
  148. MOUserHomePageVC *vc = [[MOUserHomePageVC alloc] init];
  149. vc.userId = userId;
  150. [self.navigationController pushViewController:vc animated:YES];
  151. }
  152. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  153. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  154. MOUserBase *model = self.dataArr[indexPath.section];
  155. //去主页
  156. if(model.userProfile.id.length > 0){
  157. [self toShowTheUserHomePageWith:model.userProfile.id];
  158. }
  159. }
  160. - (void)setupUI {
  161. self.view.backgroundColor = [MOTools colorWithHexString:@"#FFFFFF"];
  162. [self.view addSubview:self.backButton];
  163. [self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
  164. make.top.mas_equalTo(kTopSafeAreaInset + 15);
  165. make.left.mas_equalTo(16);
  166. make.size.mas_equalTo(CGSizeMake(24, 24));
  167. }];
  168. [self.view addSubview:self.searchBgImgView];
  169. [self.searchBgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  170. make.left.mas_equalTo(self.backButton.mas_right).offset(12);
  171. make.right.mas_equalTo(-16);
  172. make.centerY.equalTo(self.backButton);
  173. make.height.mas_equalTo(36);
  174. }];
  175. [self.view addSubview:self.searchIconView];
  176. [self.searchIconView mas_makeConstraints:^(MASConstraintMaker *make) {
  177. make.left.equalTo(self.searchBgImgView).offset(12);
  178. make.centerY.mas_equalTo(self.searchBgImgView);
  179. make.size.mas_equalTo(CGSizeMake(18, 18));
  180. }];
  181. [self.view addSubview:self.searchTextField];
  182. [self.searchTextField mas_makeConstraints:^(MASConstraintMaker *make) {
  183. make.left.equalTo(self.searchIconView.mas_right).offset(8);
  184. make.right.equalTo(self.searchBgImgView).offset(-10);
  185. make.top.bottom.equalTo(self.searchBgImgView);
  186. }];
  187. [self.view addSubview:self.tableView];
  188. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  189. make.top.equalTo(self.searchBgImgView.mas_bottom).offset(12);
  190. make.left.right.bottom.mas_equalTo(0);
  191. }];
  192. self.next = @"";
  193. WEAKSELF
  194. self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  195. if(weakSelf.next.length == 0){
  196. return;
  197. }
  198. NSDictionary *basePage = @{@"size":@(kPageSize),@"next":weakSelf.next};
  199. NSDictionary *baseDict = @{@"search":weakSelf.searchTextField.text,
  200. @"page":basePage};
  201. [weakSelf toSearchSomeOneWithDict:baseDict];
  202. }];
  203. self.tableView.mj_footer.hidden = YES;
  204. self.tableView.backgroundView = self.noMoreDataView;
  205. }
  206. #pragma mark - Lazy
  207. - (UITableView *)tableView{
  208. if (!_tableView) {
  209. _tableView = [[UITableView alloc] init];
  210. if (@available(iOS 11.0, *)) {
  211. _tableView.estimatedRowHeight = 0;
  212. _tableView.estimatedSectionFooterHeight = 0;
  213. _tableView.estimatedSectionHeaderHeight = 0;
  214. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  215. }
  216. //iOS15适配
  217. if (@available(iOS 15.0, *)) {
  218. self.tableView.sectionHeaderTopPadding = 0;
  219. }
  220. _tableView.backgroundColor = [UIColor clearColor];
  221. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  222. _tableView.dataSource = self;
  223. _tableView.delegate = self;
  224. _tableView.showsVerticalScrollIndicator = NO;
  225. _tableView.showsHorizontalScrollIndicator = NO;
  226. _tableView.rowHeight = 64.0;
  227. [_tableView registerClass:[MOHistoryListCell class] forCellReuseIdentifier:MOHistoryListCell_ID];
  228. _tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
  229. _tableView.backgroundView = self.noMoreDataView;
  230. }
  231. return _tableView;
  232. }
  233. - (NSMutableArray *)dataArr{
  234. if(!_dataArr){
  235. _dataArr = [NSMutableArray array];
  236. }
  237. return _dataArr;
  238. }
  239. - (MONoMoreDataView *)noMoreDataView{
  240. if(!_noMoreDataView){
  241. _noMoreDataView = [MONoMoreDataView new];
  242. _noMoreDataView.hidden = YES;
  243. }
  244. return _noMoreDataView;
  245. }
  246. - (BigBtn *)backButton {
  247. if (!_backButton) {
  248. _backButton = [[BigBtn alloc] init];
  249. [_backButton setImage:[UIImage imageNamed:@"v_2_icon_new_back_black"] forState:UIControlStateNormal];
  250. [_backButton addTarget:self action:@selector(backButtonAction) forControlEvents:UIControlEventTouchUpInside];
  251. }
  252. return _backButton;
  253. }
  254. - (UIImageView *)searchBgImgView {
  255. if (!_searchBgImgView) {
  256. _searchBgImgView = [[UIImageView alloc] initWithImage:[MOTools createImageWithColor:[MOTools colorWithHexString:@"#F3F4FA"]]];
  257. _searchBgImgView.layer.masksToBounds = YES;
  258. _searchBgImgView.layer.cornerRadius = 8;
  259. }
  260. return _searchBgImgView;
  261. }
  262. - (UIImageView *)searchIconView {
  263. if (!_searchIconView) {
  264. _searchIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_search_36"]];
  265. }
  266. return _searchIconView;
  267. }
  268. - (UITextField *)searchTextField {
  269. if (!_searchTextField) {
  270. _searchTextField = [[UITextField alloc] init];
  271. _searchTextField.returnKeyType = UIReturnKeySearch;
  272. _searchTextField.delegate = self;
  273. [_searchTextField setFont:[MOTextTools mediumFont:12]];
  274. _searchTextField.textColor = [MOTools colorWithHexString:@"#5C5E66"];
  275. NSMutableAttributedString *placeholderString = [[NSMutableAttributedString alloc] initWithString:NSLocalString(@"mimo_contact_search_hint") attributes:@{
  276. NSForegroundColorAttributeName : [MOTools colorWithHexString:@"#878A99"],
  277. NSFontAttributeName : [MOTextTools mediumFont:12]
  278. }];
  279. _searchTextField.attributedPlaceholder = placeholderString;
  280. UIImage *clearIcon = [UIImage imageNamed:@"icon_textfield_clear"];
  281. [_searchTextField enableCustomClearButtonWithImage:clearIcon];
  282. }
  283. return _searchTextField;
  284. }
  285. @end