| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- //
- // SearchResultViewController.m
- // AICity
- //
- // Created by 刘伟伟 on 2023/7/13.
- // Copyright © 2023 wei.z. All rights reserved.
- //
- #import "SearchResultViewController.h"
- #import "SearchCommonBarView.h"
- #import "ZFNormalViewController.h"
- @interface SearchResultViewController ()<UITableViewDelegate,UITableViewDataSource>
- @property(nonatomic,strong)SearchCommonBarView *barView;
- @property(nonatomic,strong)UITableView *tableView;
- @property(nonatomic,strong)UIImageView *noDataView;
- @end
- @implementation SearchResultViewController
- -(UIStatusBarStyle)preferredStatusBarStyle{
- return UIStatusBarStyleLightContent;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.fd_prefersNavigationBarHidden = true;
- self.view.backgroundColor = rgba(18, 23, 41, 1);
- [self.view addSubview:self.barView];
- [self.view addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.equalTo(self.view);
- make.top.equalTo(self.barView.mas_bottom);
- }];
-
- [self addNotDataView];
-
- [self search:self.txt];
- }
- -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
- [self.view endEditing:YES];
- }
- -(void)addNotDataView{
- UIImageView *noDataView = [UIImageView new];
- self.noDataView = noDataView;
- self.noDataView.hidden = true;
- noDataView.image = [UIImage imageNamed:@"nocollect_1"];
- [self.view addSubview:noDataView];
- [noDataView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(246, 180));
- make.centerX.equalTo(self.view);
- make.top.equalTo(self.barView.mas_bottom).offset(188);
- }];
-
- UILabel *label = [UILabel new];
- label.textColor = rgba(255, 255, 255, 0.4);
- label.text = @"暂无内容";
- label.font = [UIFont systemFontOfSize:16];
- [noDataView addSubview:label];
- [label mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(noDataView);
- make.bottom.equalTo(noDataView);
- }];
- }
- -(void)setTxt:(NSString *)txt{
- _txt=txt;
- self.barView.textField.text = txt;
- }
- -(void)setSearchResArr:(NSArray *)searchResArr{
- _searchResArr = searchResArr;
- if([searchResArr isKindOfClass:[NSNull class]]){
- self.noDataView.hidden = false;
- _searchResArr = [NSArray array];
- }else{
- self.noDataView.hidden = (searchResArr.count>0);
- }
- }
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return self.searchResArr.count;
- // return 3;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- searchResCell1 *cell = [searchResCell1 cellWithTableView:tableView];
- cell.data = self.searchResArr[indexPath.row];
- return cell;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 130+10;
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- [self.view endEditing:YES];
- NSDictionary *dic = self.searchResArr[indexPath.row];
- [self playItem:[dic[@"vid"] intValue]];
- }
- -(void)playItem:(int)vid{
- ZFNormalViewController *vc = [[ZFNormalViewController alloc] init];
- vc.vid = vid;
- [self.navigationController pushViewController:vc animated:true];
- }
- -(UITableView *)tableView{
- if(!_tableView){
- _tableView =[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.showsVerticalScrollIndicator = false;
- _tableView.showsHorizontalScrollIndicator = false;
- _tableView.backgroundColor = rgba(18, 23, 41, 1);
- // _tableView.backgroundColor = [UIColor redColor];
- if (@available(iOS 11, *)) {
- _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- _tableView.estimatedRowHeight = 0;
- _tableView.estimatedSectionFooterHeight = 0;
- _tableView.estimatedSectionHeaderHeight = 0;
-
- UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
- UIEdgeInsets safeAreaInsets = keyWindow.safeAreaInsets;
- CGFloat topSafeArea = safeAreaInsets.top;
- _tableView.contentInset = UIEdgeInsetsMake(-topSafeArea, 0, BAR_HEIGHT, 0);
- // _tableView2.contentInset = UIEdgeInsetsMake(-35, 0, 0, 0);
- }
- #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 // only Xcode 13+ needs and can compile this
- if (@available(iOS 15.0, *)) {
- _tableView.sectionHeaderTopPadding = 0;
- }
- #endif
- }
- return _tableView;
- }
- -(SearchCommonBarView *)barView{
- if(!_barView){
- CGFloat h=0;
- if(@available(iOS 13.0, *)){
- UIStatusBarManager *sc= [UIApplication sharedApplication].windows.firstObject.windowScene.statusBarManager;
- CGRect f=sc.statusBarFrame;
- h=f.size.height;
- }else{
- h=[UIApplication sharedApplication].statusBarFrame.size.height;
- }
- if(h>=40){
- h=30;
- }
- if(self.txt){
- _barView.textField.text = self.txt;
- }
- _barView =[[SearchCommonBarView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 72-20+h)];
- _barView.backgroundColor = rgba(18, 23, 41, 1);
- __weak typeof(self) weakSelf = self;
- _barView.searchAction = ^(NSString * _Nonnull tit) {
- [weakSelf search:tit];
- };
- }
- return _barView;
- }
- -(void)search:(NSString *)keyword{
- [self.view endEditing:true];
- NSArray *tarr = [[NSUserDefaults standardUserDefaults] objectForKey:@"mylocationhistory"];
-
- if(![tarr containsObject:keyword]){
- NSMutableArray *marr = [NSMutableArray array];
- [marr addObjectsFromArray:tarr];
- [marr addObject:keyword];
- [[NSUserDefaults standardUserDefaults] setObject:marr forKey:@"mylocationhistory"];
- }
- // [self.tableView reloadData];
- //搜索影片
- __weak typeof(self) weakSelf = self;
- [RequestTool post:@"search/searchMovie" params:@{@"search_key":keyword,@"page":@{@"page":@(1),@"pageSize":@(10)}} success:^(id responseObject) {
- NSLog(@"home/homePage-%@",responseObject);
- if([responseObject[@"code"] intValue] == 0){
- weakSelf.searchResArr = responseObject[@"data"][@"list"];
- [weakSelf.tableView reloadData];
- }else{
- weakSelf.searchResArr = @[];
- [weakSelf.tableView reloadData];
- }
- } failure:^(NSError *error) {}];
- }
- @end
- @interface searchResCell1()
- @end
- @implementation searchResCell1
- + (instancetype)cellWithTableView:(UITableView *)tableView{
- static NSString *identifier = @"searchResCell1";
- searchResCell1 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
- if (cell == nil) {
- cell = [[searchResCell1 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
- }
-
- return cell;
- }
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- [self creatView];
- }
- return self;
- }
- -(void)setData:(NSDictionary *)data{
- _data = data;
- UIImageView *iv = [self.contentView viewWithTag:100];
- [iv sd_setImageWithURL:[NSURL URLWithString:data[@"vertical_cover_url"]]];
-
- UILabel *nameLabel = [self.contentView viewWithTag:101];
- nameLabel.text = [NSString stringWithFormat:@"%@ %.1f",data[@"ch_name"],[data[@"score"] floatValue]];
-
- NSDate* date = [NSDate dateWithTimeIntervalSince1970:[data[@"screen_time"] doubleValue]];
- NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
- [formatter setDateFormat:@"yyyy"];
- NSString* dateString = [formatter stringFromDate:date];
-
- UILabel *detailLabel = [self.contentView viewWithTag:102];
- detailLabel.text = [NSString stringWithFormat:@"%@·%@·%@ | %d集全",dateString,[data[@"movie_type"] intValue] == 1 ? @"电视剧" :@"电影",data[@"country"],[data[@"total_episodes"] intValue]] ;
- //@"2023·电视剧·韩国 | 10集全"
-
- UILabel *roleLabel = [self.contentView viewWithTag:103];
- roleLabel.text = @"主演:";
-
-
- int vid = [data[@"vid"] intValue];
- UIButton *btn = [self.contentView viewWithTag:150];
- if([UserModel collectContainVid:vid]){
- [btn setTitle:@"已收藏" forState:UIControlStateNormal];
- [btn setImage:[UserModel imageWithColor:[UIColor clearColor]] forState:UIControlStateNormal];
- }else{
- [btn setImage:[UIImage imageNamed:@"Frame13"] forState:UIControlStateNormal];
- [btn setTitle:@"收藏" forState:UIControlStateNormal];
- }
- }
- -(void)addCollectAction{
- int vid = [self.data[@"vid"] intValue];
- UIButton *btn = [self.contentView viewWithTag:150];
- if([UserModel collectContainVid:vid]){
- }else{
- [UserModel addCollect:self.data];
- [btn setTitle:@"已收藏" forState:UIControlStateNormal];
- [btn setImage:[UserModel imageWithColor:[UIColor clearColor]] forState:UIControlStateNormal];
- }
- }
- -(void)creatView{
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.backgroundColor = [UIColor clearColor];
- UIView *bgv = [UIView new];
- bgv.backgroundColor = rgba(255, 255, 255, 0.03);
- [self.contentView addSubview:bgv];
- [bgv mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.bottom.equalTo(self.contentView);
- make.left.equalTo(self.contentView).offset(12);
- make.right.equalTo(self.contentView).offset(-12);
- }];
-
- UIImageView *iv=[UIImageView new];
- iv.tag = 100;
- iv.image = [UIImage imageNamed:@""];
- iv.backgroundColor = [UIColor grayColor];
- [self.contentView addSubview:iv];
- [iv mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.contentView);
- make.left.equalTo(self.contentView).offset(12);
- make.size.mas_equalTo(CGSizeMake(96, 130));
- }];
-
- UILabel *nameLabel = [UILabel new];
- nameLabel.font= [UIFont boldSystemFontOfSize:18];
- nameLabel.textColor = rgba(255, 212, 0, 1);
- nameLabel.text = @"你的名字 9.9";
- nameLabel.tag = 101;
- [self.contentView addSubview:nameLabel];
- [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(iv.mas_right).offset(8);
- make.top.equalTo(self.contentView).offset(5);
- }];
-
- UILabel *detailLabel = [UILabel new];
- detailLabel.font= [UIFont systemFontOfSize:12];
- detailLabel.textColor = rgba(255, 255, 255, 1);
- detailLabel.text = @"2023·电视剧·韩国 | 10集全";
- detailLabel.tag = 102;
- [self.contentView addSubview:detailLabel];
- [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(nameLabel);
- make.top.equalTo(nameLabel.mas_bottom).offset(12);
- }];
-
- UILabel *roleLabel = [UILabel new];
- roleLabel.font= [UIFont systemFontOfSize:12];
- roleLabel.textColor = rgba(255, 255, 255, 0.4);
- roleLabel.text = @"主演:李恩泉、李恩泉、李恩泉、李恩泉";
- roleLabel.tag = 103;
- [self.contentView addSubview:roleLabel];
- [roleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(nameLabel);
- make.top.equalTo(detailLabel.mas_bottom).offset(4);
- }];
-
- UIButton *leftButton =[UIButton buttonWithType:UIButtonTypeCustom];
- // [leftButton setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
- [leftButton setBackgroundColor:rgba(239, 164, 0, 1)];
- [leftButton setImage:[UIImage imageNamed:@"Frame12"] forState:UIControlStateNormal];
- [leftButton setTitle:@"播放" forState:UIControlStateNormal];
- [leftButton setTitleColor:rgba(109, 66, 0, 1) forState:UIControlStateNormal];
- leftButton.titleLabel.font = [UIFont systemFontOfSize:12];
- leftButton.adjustsImageWhenHighlighted = false;
-
- // [leftButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
- [self.contentView addSubview:leftButton];
- leftButton.userInteractionEnabled = false;
- [leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(82, 32));
- make.left.equalTo(nameLabel);
- make.bottom.equalTo(iv.mas_bottom).offset(-5);
- }];
-
- UIButton *rightButton =[UIButton buttonWithType:UIButtonTypeCustom];
- // [rightButton setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
- [rightButton setBackgroundColor:rgba(255, 255, 255, 0.05)];
- [rightButton setImage:[UIImage imageNamed:@"Frame13"] forState:UIControlStateNormal];
- [rightButton setTitle:@"收藏" forState:UIControlStateNormal];
- [rightButton setTitleColor:rgba(255, 212, 0, 1) forState:UIControlStateNormal];
- rightButton.titleLabel.font = [UIFont systemFontOfSize:12];
- rightButton.adjustsImageWhenHighlighted = false;
- [rightButton addTarget:self action:@selector(addCollectAction) forControlEvents:UIControlEventTouchUpInside];
- rightButton.tag = 150;
- [self.contentView addSubview:rightButton];
- [rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(82, 32));
- make.left.equalTo(leftButton.mas_right).offset(8);
- make.centerY.equalTo(leftButton);
- }];
-
- iv.layer.cornerRadius = 8;
- iv.layer.masksToBounds = true;
-
- leftButton.layer.cornerRadius = 8;
- leftButton.layer.masksToBounds = true;
-
- rightButton.layer.cornerRadius = 8;
- rightButton.layer.masksToBounds = true;
-
- bgv.layer.cornerRadius = 8;
- bgv.layer.masksToBounds = true;
-
- }
- -(void)setFrame:(CGRect)frame{
- frame.origin.y += 10;
- frame.size.height -= 10;
- [super setFrame:frame];
- }
- @end
|