320 lines
10 KiB
Objective-C
320 lines
10 KiB
Objective-C
//
|
|
// XPRoomSearchContaierViewController.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2021/12/2.
|
|
//
|
|
|
|
#import "XPRoomSearchContainerViewController.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <JXCategoryView/JXCategoryView.h>
|
|
#import <JXCategoryView/JXCategoryListContainerView.h>
|
|
///Tool
|
|
#import "XPMacro.h"
|
|
#import "ThemeColor.h"
|
|
#import "XPHomeSearchNavView.h"
|
|
#import "TTPopup.h"
|
|
///View
|
|
#import "XPHomeSearchViewController.h"
|
|
#import "XPRoomSearchRecordViewController.h"
|
|
#import "XPHomeSearchRelateView.h"
|
|
#import "XPRoomViewController.h"
|
|
#import "XPHomeSearchAwardView.h"
|
|
///P
|
|
#import "XPHomeSearchPresenter.h"
|
|
#import "XPHomeSearchProtocol.h"
|
|
///Model
|
|
#import "HomeSearchHijackBaseModel.h"
|
|
|
|
UIKIT_EXTERN NSString *kFromSearchToHomeViewKey;
|
|
UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
|
|
|
|
@interface XPRoomSearchContainerViewController ()<JXCategoryViewDelegate, JXCategoryListContainerViewDelegate, XPHomeSearchNavViewDelegate,UITextFieldDelegate, XPRoomSearchRecordViewControllerDelegate, XPHomeSearchProtocol, XPHomeSearchRelateViewDelegate>
|
|
///分页标题
|
|
@property (nonatomic, strong) NSArray<NSString *> *titles;
|
|
///分页控件
|
|
@property (nonatomic, strong) JXCategoryTitleView *titleView;
|
|
///分页lineView
|
|
@property (nonatomic, strong) JXCategoryListContainerView *contentView;
|
|
///搜索
|
|
@property (nonatomic,strong) XPHomeSearchNavView *searchView;
|
|
///房间
|
|
@property (nonatomic,strong) XPHomeSearchViewController *roomVC;
|
|
///用户
|
|
@property (nonatomic,strong) XPHomeSearchViewController *userVC;
|
|
///进房、搜索记录
|
|
@property (nonatomic, strong) XPRoomSearchRecordViewController *recordVc;
|
|
///相关房间
|
|
@property (nonatomic, strong) XPHomeSearchRelateView *relateView;
|
|
|
|
@end
|
|
|
|
@implementation XPRoomSearchContainerViewController
|
|
|
|
|
|
- (XPHomeSearchPresenter *)createPresenter {
|
|
return [[XPHomeSearchPresenter alloc] init];
|
|
}
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
self.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[self.view addSubview:self.searchView];
|
|
[self.view addSubview:self.titleView];
|
|
[self.view addSubview:self.contentView];
|
|
[self.view addSubview:self.recordVc.view];
|
|
[self addChildViewController:self.recordVc];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.searchView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.top.mas_equalTo(self.view);
|
|
make.height.mas_equalTo(kNavigationHeight);
|
|
}];
|
|
|
|
[self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.mas_equalTo(self.view);
|
|
make.top.mas_equalTo(self.searchView.mas_bottom).offset(10);
|
|
make.height.mas_equalTo(50);
|
|
}];
|
|
|
|
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.titleView.mas_bottom).offset(10);
|
|
make.left.right.bottom.mas_equalTo(self.view);
|
|
}];
|
|
[self.recordVc.view mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.mas_equalTo(self.view);
|
|
make.top.mas_equalTo(self.searchView.mas_bottom);
|
|
make.bottom.mas_equalTo(self.view);
|
|
}];
|
|
}
|
|
|
|
- (void)searchVCLoadData:(NSString *)text {
|
|
self.recordVc.view.hidden = YES;
|
|
[self.roomVC searchText:text];
|
|
[self.userVC searchText:text];
|
|
}
|
|
|
|
#pragma mark - JXCategoryViewDelegate
|
|
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
|
|
return self.titles.count;
|
|
}
|
|
|
|
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
|
|
if (index == 0) {
|
|
return self.roomVC;
|
|
}
|
|
return self.userVC;
|
|
}
|
|
|
|
#pragma mark - UITextFieldDelegate
|
|
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
|
|
if (textField.text.length > 0) {
|
|
[textField resignFirstResponder];
|
|
[self.presenter getSearchHijack:textField.text];
|
|
[self.recordVc storeSearchRecord:textField.text];
|
|
} else {
|
|
[self showErrorToast:@"请输入需要搜索的内容"];
|
|
}
|
|
return YES;
|
|
}
|
|
|
|
#pragma mark -XPHomeSearchNavViewDelegate
|
|
- (void)xPHomeSearchNavView:(XPHomeSearchNavView *)view didClickSearch:(UIButton *)sender {
|
|
if (view.searchTextField.text.length > 0) {
|
|
[view.searchTextField resignFirstResponder];
|
|
[self.presenter getSearchHijack:view.searchTextField.text];
|
|
[self.recordVc storeSearchRecord:view.searchTextField.text];
|
|
} else {
|
|
[self showErrorToast:@"请输入需要搜索的内容"];
|
|
}
|
|
}
|
|
|
|
- (void)xPHomeSearchNavView:(XPHomeSearchNavView *)view didClickBack:(UIButton *)sender {
|
|
[view.searchTextField resignFirstResponder];
|
|
BOOL result = [[NSUserDefaults standardUserDefaults] boolForKey:kFromSearchToHomeViewKey];
|
|
if (!result) {
|
|
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kFromSearchToHomeViewKey];
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:kTabShowAnchorCardKey object:nil];
|
|
}
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
|
}
|
|
|
|
///搜索框没有文字
|
|
- (void)xPHomeSearchNavViewClearTextField:(XPHomeSearchNavView *)view {
|
|
self.recordVc.view.hidden = NO;
|
|
[self.recordVc updateSearchRecord];
|
|
[self.relateView removeFromSuperview];
|
|
}
|
|
|
|
#pragma mark - XPRoomSearchRecordViewControllerDelegate
|
|
- (void)xPRoomSearchRecordViewControllerSearchWithWord:(NSString *)word {
|
|
if (word.length > 0) {
|
|
self.searchView.searchTextField.text = word;
|
|
[self.presenter getSearchHijack:word];
|
|
[self.recordVc storeSearchRecord:word];
|
|
} else {
|
|
[self showErrorToast:@"请输入需要搜索的内容"];
|
|
}
|
|
}
|
|
|
|
///大家都在搜
|
|
- (void)xPRoomSearchRecordViewControllerEveryoneSearch:(NSString *)word sid:(nonnull NSString *)sid {
|
|
self.searchView.searchTextField.text = word;
|
|
[self.recordVc storeSearchRecord:word];
|
|
[self.presenter getEveryOneSearchRoomList:sid];
|
|
}
|
|
|
|
#pragma mark - XPHomeSearchProtocol
|
|
- (void)everyoneSearchListSuccess:(NSArray *)list {
|
|
if (list.count) {//有值,显示列表
|
|
[self.view addSubview:self.relateView];
|
|
[self.relateView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.bottom.mas_equalTo(0);
|
|
make.top.mas_equalTo(self.searchView.mas_bottom);
|
|
}];
|
|
self.relateView.relateArray = list;
|
|
} else {//无数据,显示推荐房间
|
|
[self.presenter getHomeRecommendRoomList];
|
|
}
|
|
}
|
|
|
|
- (void)searchRoomGetRecommendSuccess:(NSArray *)data {
|
|
if (data.count) {//有值,显示列表
|
|
[self.view addSubview:self.relateView];
|
|
[self.relateView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.bottom.mas_equalTo(0);
|
|
make.top.mas_equalTo(self.searchView.mas_bottom);
|
|
}];
|
|
self.relateView.recommendArray = data;
|
|
}
|
|
}
|
|
|
|
- (void)searchRoomGetRecommendFail {
|
|
|
|
}
|
|
|
|
///获取搜索劫持成功
|
|
- (void)searchHijackSuccess:(HomeSearchHijackBaseModel *)data key:(nonnull NSString *)key {
|
|
if (data.roomUid.length) {
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
|
[XPRoomViewController openRoom:data.roomUid viewController:self.presentingViewController];
|
|
} else if (data.awardVo) {
|
|
XPHomeSearchAwardView *view = [[XPHomeSearchAwardView alloc] init];
|
|
view.data = data.awardVo;
|
|
[TTPopup popupView:view style:TTPopupStyleAlert];
|
|
} else {
|
|
[self searchVCLoadData:key];
|
|
}
|
|
}
|
|
|
|
///获取搜索劫持失败
|
|
- (void)searchHijackFail:(NSString *)key {
|
|
[self searchVCLoadData:key];
|
|
}
|
|
|
|
#pragma mark - XPHomeSearchRelateViewDelegate
|
|
///进入房间
|
|
- (void)xPHomeSearchRelateViewEnterRoom:(NSString *)roomUid {
|
|
BOOL result = [[NSUserDefaults standardUserDefaults] boolForKey:kFromSearchToHomeViewKey];
|
|
if (!result) {
|
|
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kFromSearchToHomeViewKey];
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:kTabShowAnchorCardKey object:@{@"delayShow" : @(YES)}];
|
|
}
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
|
[XPRoomViewController openRoom:roomUid viewController:self.presentingViewController];
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (JXCategoryTitleView *)titleView {
|
|
if (!_titleView) {
|
|
_titleView = [[JXCategoryTitleView alloc] init];
|
|
_titleView.delegate = self;
|
|
_titleView.titles = self.titles;
|
|
_titleView.titleColor = [ThemeColor secondTextColor];
|
|
_titleView.titleSelectedColor = [ThemeColor mainTextColor];
|
|
_titleView.titleFont = [UIFont fontWithName:@"PingFang-SC-Medium" size:16];
|
|
_titleView.titleSelectedFont = [UIFont fontWithName:@"PingFang-SC-Medium" size:16];
|
|
_titleView.titleLabelAnchorPointStyle = JXCategoryTitleLabelAnchorPointStyleCenter;
|
|
_titleView.contentScrollViewClickTransitionAnimationEnabled = NO;
|
|
_titleView.defaultSelectedIndex = 0;
|
|
_titleView.listContainer = self.contentView;
|
|
|
|
JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
|
|
lineView.indicatorColor = [ThemeColor appMainColor];
|
|
lineView.indicatorWidth = 8.f;
|
|
lineView.indicatorHeight = 4.f;
|
|
lineView.indicatorCornerRadius = 2.f;
|
|
_titleView.indicators = @[lineView];
|
|
}
|
|
return _titleView;
|
|
}
|
|
|
|
- (JXCategoryListContainerView *)contentView {
|
|
if (!_contentView) {
|
|
_contentView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
|
|
_contentView.defaultSelectedIndex = 0;
|
|
}
|
|
return _contentView;
|
|
}
|
|
|
|
- (NSArray<NSString *> *)titles {
|
|
return @[@"房间", @"用户"];
|
|
}
|
|
|
|
- (XPHomeSearchNavView *)searchView {
|
|
if (!_searchView) {
|
|
_searchView = [[XPHomeSearchNavView alloc] init];
|
|
_searchView.delegate = self;
|
|
_searchView.searchTextField.delegate = self;
|
|
}
|
|
return _searchView;
|
|
}
|
|
|
|
- (XPHomeSearchViewController *)roomVC {
|
|
if (!_roomVC) {
|
|
_roomVC = [[XPHomeSearchViewController alloc] init];
|
|
_roomVC.type = SearchType_Room;
|
|
}
|
|
return _roomVC;
|
|
}
|
|
|
|
- (XPHomeSearchViewController *)userVC {
|
|
if (!_userVC) {
|
|
_userVC = [[XPHomeSearchViewController alloc] init];
|
|
_userVC.type = SearchType_Users;
|
|
}
|
|
return _userVC;
|
|
}
|
|
|
|
- (XPRoomSearchRecordViewController *)recordVc {
|
|
if (!_recordVc) {
|
|
_recordVc = [[XPRoomSearchRecordViewController alloc] init];
|
|
_recordVc.delegate = self;
|
|
}
|
|
return _recordVc;
|
|
}
|
|
|
|
- (XPHomeSearchRelateView *)relateView {
|
|
if (!_relateView) {
|
|
_relateView = [[XPHomeSearchRelateView alloc] init];
|
|
_relateView.delegate = self;
|
|
}
|
|
return _relateView;
|
|
}
|
|
|
|
@end
|