MOSearchUserVC.m 12 KB

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