508 lines
19 KiB
Objective-C
508 lines
19 KiB
Objective-C
//
|
|
// DDSearchListVC.m
|
|
// DingDangApp
|
|
//
|
|
// Created by apple on 2023/7/6.
|
|
//
|
|
|
|
#import "DDSearchListVC.h"
|
|
#import "DDSearchHeaderView.h"
|
|
#import "DDFollowFansCell.h"
|
|
#import "DDSearchRoomCell.h"
|
|
#import "DDRoomPartyModel.h"
|
|
#import "DDFansFollowVisitModel.h"
|
|
#import "Api+DDHomeApi.h"
|
|
|
|
@interface DDSearchListVC () <UITableViewDelegate,UITableViewDataSource>
|
|
@property (nonatomic, assign) NSInteger pageNum;
|
|
/** 数据源*/
|
|
@property (nonatomic,strong) NSMutableArray *userListArr;
|
|
@property (nonatomic,strong) NSMutableArray *roomListArr;
|
|
@property (nonatomic, strong) UITableView * searchTable;
|
|
|
|
@property (nonatomic, strong) DDSearchHeaderView * userHeaderView;
|
|
@property (nonatomic, strong) DDSearchHeaderView * roomHeaderView;
|
|
/** 防止重复点击 */
|
|
@property (nonatomic,assign) BOOL isClick;
|
|
|
|
@end
|
|
|
|
@implementation DDSearchListVC
|
|
- (void)dealloc{
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
|
}
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self initBaseUI];
|
|
self.pageNum = 1;
|
|
[self initRequest];
|
|
}
|
|
-(void)initBaseUI
|
|
{
|
|
self.view.backgroundColor = DDHEXColor(0xF6F6F6);
|
|
[self.view addSubview:self.searchTable];
|
|
[self.searchTable mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.bottom.equalTo(self.view);
|
|
make.left.right.equalTo(self.view).inset(16);
|
|
}];
|
|
}
|
|
-(void)initRequest
|
|
{
|
|
WeakSelf(weakSelf)
|
|
[Api dd_getHomePageSearchComplection:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
[weakSelf endrefresh];
|
|
if(code == 200){
|
|
if (weakSelf.pageNum == 1) {
|
|
[weakSelf.userListArr removeAllObjects];
|
|
}
|
|
NSArray *list = [DDFansFollowVisitModel DD_ModelsWithArray:data.data];
|
|
[weakSelf.userListArr addObjectsFromArray:list];
|
|
[self.searchTable reloadData];
|
|
}
|
|
} key:self.searchStr type:@"2" page:@(self.pageNum).stringValue pageSize:@"20"];
|
|
|
|
return;
|
|
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
|
|
//综合 用户 聊天室
|
|
if ([self.typeStr isEqualToString:@"综合"]) {
|
|
[dic setObject:@"all" forKey:@"type"];
|
|
}else if ([self.typeStr isEqualToString:@"用户"]){
|
|
[dic setObject:@"user" forKey:@"type"];
|
|
}else if ([self.typeStr isEqualToString:@"聊天室"]){
|
|
[dic setObject:@"room" forKey:@"type"];
|
|
}
|
|
[dic setObject:self.searchStr ?: @"" forKey:@"keywords"];
|
|
[dic setObject:@(20) forKey:@"current_page"];
|
|
[dic setObject:@(self.pageNum) forKey:@"page_number"];
|
|
|
|
/// /home/search
|
|
NSString *url = [DDEncryptManager dd_aesDecryptWithText:@"9IiqdwQ2vgAWrRrCUnNGlA=="];
|
|
[NetworkRequest requestPOST:url parameters:dic block:^(BaseResponse * _Nonnull response) {
|
|
|
|
if (response.isSuccess) {
|
|
if ([ToolsObject IsNullWithObject:response.data]) {
|
|
return;
|
|
}
|
|
if ([self.typeStr isEqualToString:@"综合"]) {
|
|
|
|
[self.userListArr removeAllObjects];
|
|
[self.userListArr addObjectsFromArray:[NSArray yy_modelArrayWithClass:DDFansFollowVisitModel.class json:response.data[@"record"][@"userList"][@"list"]]];
|
|
|
|
[self.roomListArr removeAllObjects];
|
|
[self.roomListArr addObjectsFromArray:[NSArray yy_modelArrayWithClass:DDRoomPartyModel.class json:response.data[@"record"][@"roomList"][@"list"]]];
|
|
|
|
self.roomHeaderView.numLabel.text = [NSString stringWithFormat:@"%ld",[response.data[@"record"][@"roomList"][@"count"] integerValue]];
|
|
self.userHeaderView.numLabel.text = [NSString stringWithFormat:@"%ld",[response.data[@"record"][@"userList"][@"count"] integerValue]];
|
|
|
|
}else if ([self.typeStr isEqualToString:@"用户"]){
|
|
if (self.pageNum == 1) {
|
|
[self.userListArr removeAllObjects];
|
|
}
|
|
[self.userListArr addObjectsFromArray:[NSArray yy_modelArrayWithClass:DDFansFollowVisitModel.class json:response.data[@"record"][@"userList"][@"list"]]];
|
|
[self endrefresh];
|
|
|
|
if ([response.data[@"next"]integerValue] == 0) {
|
|
[self.searchTable.mj_footer endRefreshingWithNoMoreData];
|
|
}
|
|
}else if ([self.typeStr isEqualToString:@"聊天室"]){
|
|
if (self.pageNum == 1) {
|
|
[self.roomListArr removeAllObjects];
|
|
}
|
|
[self.roomListArr addObjectsFromArray:[NSArray yy_modelArrayWithClass:DDRoomPartyModel.class json:response.data[@"record"][@"roomList"][@"list"]]];
|
|
[self endrefresh];
|
|
if ([response.data[@"next"]integerValue] == 0) {
|
|
[self.searchTable.mj_footer endRefreshingWithNoMoreData];
|
|
}
|
|
}
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
[self.searchTable reloadData];
|
|
});
|
|
} else {
|
|
|
|
[self endrefresh];
|
|
}
|
|
}];
|
|
}
|
|
-(UITableView *)searchTable
|
|
{
|
|
if (!_searchTable) {
|
|
_searchTable = [[UITableView alloc] initWithFrame:CGRectZero
|
|
style:UITableViewStyleGrouped];
|
|
_searchTable.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
|
_searchTable.estimatedSectionHeaderHeight = 0;
|
|
_searchTable.estimatedSectionFooterHeight = 0;
|
|
_searchTable.dataSource = self;
|
|
_searchTable.delegate = self;
|
|
_searchTable.estimatedRowHeight = 0;
|
|
_searchTable.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
_searchTable.separatorColor = [UIColor clearColor];
|
|
_searchTable.backgroundColor = [UIColor clearColor];
|
|
[_searchTable registerClass:DDFollowFansCell.class forCellReuseIdentifier:@"DDFollowFansCell"];
|
|
[_searchTable registerClass:DDSearchRoomCell.class forCellReuseIdentifier:@"DDSearchRoomCell"];
|
|
|
|
@weakify(self)
|
|
_searchTable.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
|
@strongify(self)
|
|
self.pageNum = 1;
|
|
[self initRequest];
|
|
}];
|
|
if (![self.typeStr isEqualToString:@"综合"]) {
|
|
_searchTable.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
|
|
@strongify(self)
|
|
self.pageNum ++ ;
|
|
[self initRequest];
|
|
}];
|
|
}
|
|
|
|
}
|
|
return _searchTable;
|
|
}
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
|
{
|
|
if ([self.typeStr isEqualToString:@"综合"]) {
|
|
return 40;
|
|
}else{
|
|
return 0.1;
|
|
}
|
|
}
|
|
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
|
|
{
|
|
if ([self.typeStr isEqualToString:@"综合"]) {
|
|
if (self.userListArr.count>0 && self.roomListArr.count>0) {
|
|
if (section == 0) {
|
|
return self.userHeaderView;
|
|
}else{
|
|
return self.roomHeaderView;
|
|
}
|
|
}else{
|
|
if (self.userListArr.count>0) {
|
|
return self.userHeaderView;
|
|
}else{
|
|
return self.roomHeaderView;
|
|
}
|
|
}
|
|
}else{
|
|
return [UIView new];
|
|
}
|
|
}
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
|
|
{
|
|
return 0.1;
|
|
}
|
|
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
|
{
|
|
if ([self.typeStr isEqualToString:@"综合"]) {
|
|
if (self.userListArr.count>0 && self.roomListArr.count>0) {
|
|
return 2;
|
|
}else{
|
|
return 1;
|
|
}
|
|
}else{
|
|
return 1;
|
|
}
|
|
}
|
|
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
{
|
|
if ([self.typeStr isEqualToString:@"综合"]) {
|
|
if (self.userListArr.count>0 && self.roomListArr.count>0) {
|
|
if (section == 0) {
|
|
return self.userListArr.count;
|
|
}else{
|
|
return self.roomListArr.count;
|
|
}
|
|
}else{
|
|
if (self.userListArr.count>0) {
|
|
return self.userListArr.count;
|
|
}else{
|
|
return self.roomListArr.count;
|
|
}
|
|
}
|
|
}else{
|
|
if ([self.typeStr isEqualToString:@"用户"]) {
|
|
return self.userListArr.count;
|
|
}else{
|
|
return self.roomListArr.count;
|
|
}
|
|
}
|
|
}
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
if ([self.typeStr isEqualToString:@"综合"]) {
|
|
if (self.userListArr.count>0 && self.roomListArr.count>0) {
|
|
if (indexPath.section == 0) {
|
|
return 70;
|
|
}else{
|
|
return 120;
|
|
}
|
|
}else{
|
|
if (self.userListArr.count>0) {
|
|
return 70;
|
|
}else{
|
|
return 120;
|
|
}
|
|
}
|
|
}else if ([self.typeStr isEqualToString:@"用户"]){
|
|
return 70;
|
|
}else{
|
|
return 120;
|
|
}
|
|
}
|
|
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
if ([self.typeStr isEqualToString:@"综合"]) {
|
|
if (self.userListArr.count>0 && self.roomListArr.count>0) {
|
|
if (indexPath.section == 0) {
|
|
return [self returnCellWithType:@"userCell" withTableView:tableView index:indexPath];
|
|
}else{
|
|
return [self returnCellWithType:@"roonCell" withTableView:tableView index:indexPath];
|
|
}
|
|
}else{
|
|
if (self.userListArr.count>0) {
|
|
return [self returnCellWithType:@"userCell" withTableView:tableView index:indexPath];
|
|
}else{
|
|
return [self returnCellWithType:@"roonCell" withTableView:tableView index:indexPath];
|
|
}
|
|
}
|
|
}else if ([self.typeStr isEqualToString:@"用户"]){
|
|
return [self returnCellWithType:@"userCell" withTableView:tableView index:indexPath];
|
|
}else{
|
|
return [self returnCellWithType:@"roonCell" withTableView:tableView index:indexPath];
|
|
}
|
|
}
|
|
-(UITableViewCell *)returnCellWithType:(NSString *)type withTableView:(UITableView *)tableView index:(NSIndexPath *)indexPath
|
|
{
|
|
if ([type isEqualToString:@"userCell"]) {
|
|
static NSString *indentifiers = @"DDFollowFansCell";
|
|
DDFollowFansCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifiers];
|
|
if (!cell) {
|
|
cell = [[DDFollowFansCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifiers];
|
|
}
|
|
if (indexPath.row < self.userListArr.count) {
|
|
cell.cellIndex = indexPath;
|
|
cell.model = self.userListArr[indexPath.row];
|
|
}
|
|
@weakify(self)
|
|
cell.didFollowBlock = ^(DDFansFollowVisitModel * _Nonnull fansModel, NSIndexPath * _Nonnull index) {
|
|
@strongify(self)
|
|
if (fansModel.is_attention) {
|
|
[self requestcancelFollow:fansModel withIndexPath:index];
|
|
}else{
|
|
[self requestAddFollow:fansModel withIndexPath:index];
|
|
}
|
|
};
|
|
cell.backgroundColor = UIColor.clearColor;
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
return cell;
|
|
}else{
|
|
static NSString *indentifiers = @"DDSearchRoomCell";
|
|
DDSearchRoomCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifiers];
|
|
if (!cell) {
|
|
cell = [[DDSearchRoomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifiers];
|
|
}
|
|
if (indexPath.row < self.roomListArr.count) {
|
|
DDRoomPartyModel *model = self.roomListArr[indexPath.row];
|
|
cell.model = model;
|
|
}
|
|
cell.backgroundColor = UIColor.clearColor;
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
return cell;
|
|
}
|
|
}
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
if ([self.typeStr isEqualToString:@"综合"]) {
|
|
if (self.userListArr.count>0 && self.roomListArr.count>0) {
|
|
if (indexPath.section == 0) {
|
|
if (self.isClick) {
|
|
return ;
|
|
}
|
|
self.isClick = YES;
|
|
DDFansFollowVisitModel *model = self.userListArr[indexPath.row];
|
|
[ToolsObject pushMyInformationViewController:model.id];
|
|
@weakify(self);
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1*NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
|
@strongify(self);
|
|
self.isClick = NO;
|
|
});
|
|
}else{
|
|
if (self.isClick) {
|
|
return ;
|
|
}
|
|
self.isClick = YES;
|
|
DDRoomPartyModel *model = self.roomListArr[indexPath.row];
|
|
[[ToolsObject shareTools] jumpToRoomVC:model.room_id followUser:[RoomUserInfoModel new]];
|
|
@weakify(self);
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1*NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
|
@strongify(self);
|
|
self.isClick = NO;
|
|
});
|
|
}
|
|
}else{
|
|
if (self.userListArr.count>0) {
|
|
if (self.isClick) {
|
|
return ;
|
|
}
|
|
self.isClick = YES;
|
|
DDFansFollowVisitModel *model = self.userListArr[indexPath.row];
|
|
[ToolsObject pushMyInformationViewController:model.id];
|
|
@weakify(self);
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1*NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
|
@strongify(self);
|
|
self.isClick = NO;
|
|
});
|
|
}else{
|
|
if (self.isClick) {
|
|
return ;
|
|
}
|
|
self.isClick = YES;
|
|
DDRoomPartyModel *model = self.roomListArr[indexPath.row];
|
|
[[ToolsObject shareTools] jumpToRoomVC:model.room_id followUser:[RoomUserInfoModel new]];
|
|
@weakify(self);
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1*NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
|
@strongify(self);
|
|
self.isClick = NO;
|
|
});
|
|
}
|
|
}
|
|
}else if ([self.typeStr isEqualToString:@"用户"]){
|
|
if (self.isClick) {
|
|
return ;
|
|
}
|
|
self.isClick = YES;
|
|
DDFansFollowVisitModel *model = self.userListArr[indexPath.row];
|
|
[ToolsObject pushMyInformationViewController:model.uid];
|
|
@weakify(self);
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1*NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
|
@strongify(self);
|
|
self.isClick = NO;
|
|
});
|
|
}else{
|
|
if (self.isClick) {
|
|
return ;
|
|
}
|
|
self.isClick = YES;
|
|
DDRoomPartyModel *model = self.roomListArr[indexPath.row];
|
|
[[ToolsObject shareTools] jumpToRoomVC:model.room_id followUser:[RoomUserInfoModel new]];
|
|
@weakify(self);
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1*NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
|
@strongify(self);
|
|
self.isClick = NO;
|
|
});
|
|
}
|
|
}
|
|
#pragma mark --- 关注
|
|
/** 添加关注 */
|
|
- (void)requestAddFollow:(DDFansFollowVisitModel *)userModel withIndexPath:(NSIndexPath *)index{
|
|
|
|
if ([ToolsObject IsNullWithObject:userModel.id]) {
|
|
[ToolsObject addPopVieToText:@"未获取到该用户信息,请刷新重试"];
|
|
return;
|
|
}
|
|
[ToolsObject ShowSVProgressHUD:@""];
|
|
/** para*/
|
|
NSMutableDictionary *parameter =@{@"followed_user_id":userModel.id}.mutableCopy;
|
|
@weakify(self)
|
|
[NetworkRequest requestPOST:@"/dynamic/attention" parameters:parameter block:^(BaseResponse * _Nonnull response) {
|
|
[ToolsObject DismissSVProgressHUD];
|
|
@strongify(self);
|
|
if (response.code == 200) {
|
|
userModel.is_attention = !userModel.is_attention;
|
|
[ToolsObject addPopVieToText:@"关注成功"];
|
|
[self.userListArr replaceObjectAtIndex:index.row withObject:userModel];
|
|
[self.searchTable reloadRowsAtIndexPaths:@[index] withRowAnimation:UITableViewRowAnimationNone];
|
|
}
|
|
}];
|
|
}
|
|
/** 取消关注 */
|
|
- (void)requestcancelFollow:(DDFansFollowVisitModel *)userModel withIndexPath:(NSIndexPath *)index{
|
|
|
|
if ([ToolsObject IsNullWithObject:userModel.id]) {
|
|
[ToolsObject addPopVieToText:@"未获取到该用户信息,请刷新重试"];
|
|
return;
|
|
}
|
|
[ToolsObject ShowSVProgressHUD:@""];
|
|
/** para*/
|
|
NSMutableDictionary *parameter =@{@"followed_user_id":userModel.id}.mutableCopy;
|
|
@weakify(self)
|
|
[NetworkRequest requestPOST:@"/dynamic/cancel/attention" parameters:parameter block:^(BaseResponse * _Nonnull response) {
|
|
[ToolsObject DismissSVProgressHUD];
|
|
@strongify(self);
|
|
if (response.code == 200) {
|
|
userModel.is_attention = !userModel.is_attention;
|
|
[self.userListArr replaceObjectAtIndex:index.row withObject:userModel];
|
|
[self.searchTable reloadRowsAtIndexPaths:@[index] withRowAnimation:UITableViewRowAnimationNone];
|
|
}
|
|
}];
|
|
}
|
|
-(void)endrefresh
|
|
{
|
|
[self.searchTable.mj_header endRefreshing];
|
|
[self.searchTable.mj_footer endRefreshing];
|
|
}
|
|
-(NSMutableArray *)userListArr
|
|
{
|
|
if (!_userListArr) {
|
|
_userListArr = @[].mutableCopy;
|
|
}
|
|
return _userListArr;
|
|
}
|
|
-(NSMutableArray *)roomListArr
|
|
{
|
|
if (!_roomListArr) {
|
|
_roomListArr = @[].mutableCopy;
|
|
}
|
|
return _roomListArr;
|
|
}
|
|
-(DDSearchHeaderView *)roomHeaderView
|
|
{
|
|
if (!_roomHeaderView) {
|
|
_roomHeaderView = [[DDSearchHeaderView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 40)];
|
|
_roomHeaderView.titLabel.text = @"聊天室";
|
|
_roomHeaderView.backgroundColor = UIColor.clearColor;
|
|
@weakify(self)
|
|
[[_roomHeaderView.clickBtn rac_signalForControlEvents:(UIControlEventTouchUpInside)]subscribeNext:^(__kindof UIControl * _Nullable x) {
|
|
@strongify(self)
|
|
if (self.didScrollIndexBlock) {
|
|
if (self.userListArr.count>0 && self.roomListArr.count>0) {
|
|
self.didScrollIndexBlock(2);
|
|
}else{
|
|
self.didScrollIndexBlock(1);
|
|
}
|
|
|
|
}
|
|
}];
|
|
}
|
|
return _roomHeaderView;
|
|
}
|
|
-(DDSearchHeaderView *)userHeaderView
|
|
{
|
|
if (!_userHeaderView) {
|
|
_userHeaderView = [[DDSearchHeaderView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 40)];
|
|
_userHeaderView.titLabel.text = @"相关用户";
|
|
_userHeaderView.backgroundColor = UIColor.clearColor;
|
|
@weakify(self)
|
|
[[_userHeaderView.clickBtn rac_signalForControlEvents:(UIControlEventTouchUpInside)]subscribeNext:^(__kindof UIControl * _Nullable x) {
|
|
@strongify(self)
|
|
if (self.didScrollIndexBlock) {
|
|
self.didScrollIndexBlock(1);
|
|
}
|
|
}];
|
|
}
|
|
return _userHeaderView;
|
|
}
|
|
|
|
/*
|
|
#pragma mark - Navigation
|
|
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
|
// Get the new view controller using [segue destinationViewController].
|
|
// Pass the selected object to the new view controller.
|
|
}
|
|
*/
|
|
|
|
@end
|