Files
yinmeng-ios/xplan-ios/Main/Home/View/XPHomeSearchViewController.m
2021-12-02 20:33:58 +08:00

131 lines
4.2 KiB
Objective-C

//
// XPHomeSearchViewController.m
// xplan-ios
//
// Created by 冯硕 on 2021/11/29.
//
#import "XPHomeSearchViewController.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "ThemeColor.h"
#import "XPMacro.h"
///Model
#import "HomeSearchResultModel.h"
///View
#import "XPSearchListTableViewCell.h"
///P
#import "XPHomeSearchPresenter.h"
#import "XPHomeSearchProtocol.h"
///VC
#import "XPRoomViewController.h"
#import "XPMineUserInfoViewController.h"
@interface XPHomeSearchViewController ()<UITableViewDelegate, UITableViewDataSource,XPHomeSearchProtocol>
///列表
@property (nonatomic,strong) UITableView *tableView;
///数据源
@property (nonatomic,strong) NSArray *datasource;
@end
@implementation XPHomeSearchViewController
- (XPHomeSearchPresenter *)createPresenter {
return [[XPHomeSearchPresenter alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initSubViews];
[self initSubViewConstraints];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}
#pragma mark - Public Method
- (void)searchText:(NSString *)text {
NSString * type = [NSString stringWithFormat:@"%ld", self.type];
[self.presenter searchRoomList:text type:type];
}
#pragma mark - Private Method
- (void)initSubViews {
[self.view addSubview:self.tableView];
}
- (void)initSubViewConstraints {
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
}
#pragma mark - UITableViewDelegate And UITableViewDataSource
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 74;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.datasource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
XPSearchListTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPSearchListTableViewCell class])];
if (cell == nil) {
cell = [[XPSearchListTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPSearchListTableViewCell class])];
}
HomeSearchResultModel * resultModel = [self.datasource objectAtIndex:indexPath.row];
[cell configData:resultModel type:self.type];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
HomeSearchResultModel * resultModel = [self.datasource objectAtIndex:indexPath.row];
[self dismissViewControllerAnimated:YES completion:nil];
if (self.type == SearchType_Room) {
if (resultModel.valid) {
[XPRoomViewController openRoom:resultModel.uid viewController:self.presentingViewController];
} else {
XPMineUserInfoViewController * infoVC = [[XPMineUserInfoViewController alloc] init];
infoVC.uid = resultModel.uid.integerValue;
[(UINavigationController *)self.presentingViewController pushViewController:infoVC animated:YES];
}
} else {
XPMineUserInfoViewController * infoVC = [[XPMineUserInfoViewController alloc] init];
infoVC.uid = resultModel.uid.integerValue;
[(UINavigationController *)self.presentingViewController pushViewController:infoVC animated:YES];
}
}
#pragma mark - XPHomeSearchProtocol
- (void)searchRoomSuccess:(NSArray *)data {
self.datasource = data;
[self.tableView reloadData];
}
#pragma mark - <JXCategoryListContentViewDelegate>
- (UIView *)listView {
return self.view;
}
#pragma mark - Getters And Setters
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.tableHeaderView = [UIView new];
_tableView.tableFooterView = [UIView new];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.backgroundColor = [UIColor clearColor];
if (@available(iOS 11.0, *)) {
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
[_tableView registerClass:[XPSearchListTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPSearchListTableViewCell class])];
}
return _tableView;
}
@end