| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442 |
- //
- // PlayHistoryViewController.m
- // AICity
- //
- // Created by 刘伟伟 on 2023/7/13.
- // Copyright © 2023 wei.z. All rights reserved.
- //
- #import "PlayHistoryViewController.h"
- #import "CommonBarView.h"
- @interface PlayHistoryViewController ()<UITableViewDelegate,UITableViewDataSource>
- @property(nonatomic,strong)CommonBarView *customerbar;
- @property(nonatomic,strong)UITableView *tableView;
- @property(nonatomic,strong)UIView *bottomView;
- @property(nonatomic,assign)BOOL isEdit;
- @property(nonatomic,strong)NSArray *playHisData;
- @end
- @implementation PlayHistoryViewController
- -(UIStatusBarStyle)preferredStatusBarStyle{
- return UIStatusBarStyleLightContent;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.fd_prefersNavigationBarHidden = true;
- self.playHisData = [[NSUserDefaults standardUserDefaults] objectForKey:@"myhistoryplaylist"];
- self.view.backgroundColor = rgba(18, 23, 41, 1);
- [self.view addSubview:self.customerbar];
- [self.view addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.equalTo(self.view);
- make.top.equalTo(self.customerbar.mas_bottom);
- }];
-
- [self addBottomView];
- if(self.playHisData.count == 0){
- [self addNotDataView];
- }
- }
- -(void)addNotDataView{
- UIImageView *iv = [UIImageView new];
- iv.image = [UIImage imageNamed:@"nohis_1"];
- [self.view addSubview:iv];
- [iv mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(246, 175));
- make.centerX.equalTo(self.view);
- make.top.equalTo(self.customerbar.mas_bottom).offset(192);
- }];
-
- UILabel *label = [UILabel new];
- label.textColor = rgba(255, 255, 255, 0.4);
- label.text = @"您还没有观看历史";
- label.font = [UIFont systemFontOfSize:16];
- [self.view addSubview:label];
- [label mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(iv);
- make.bottom.equalTo(iv).offset(-6);
- }];
-
- UILabel *label2 = [UILabel new];
- label2.textColor = rgba(255, 255, 255, 0.2);
- label2.text = @"快来开始您的观影之旅吧";
- label2.font = [UIFont systemFontOfSize:12];
- [self.view addSubview:label2];
- [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(iv);
- make.top.equalTo(label.mas_bottom).offset(8);
- }];
- }
- -(void)addBottomView{
- UIView *bottomView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 48+safebottom)];
- self.bottomView = bottomView;
- self.bottomView.hidden = true;
- bottomView.backgroundColor = rgba(25, 29, 49, 1);
- [self.view addSubview:bottomView];
- [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(self.view);
- make.height.mas_equalTo(@(48+safebottom));
- make.width.mas_equalTo(@(SCREEN_WIDTH));
- }];
-
- UIButton *leftbtn =[UIButton buttonWithType:UIButtonTypeCustom];
- // [leftbtn setImage:[UIImage imageNamed:@"Frame 9423"] forState:UIControlStateNormal];
- [leftbtn setTitle:@"取消全选" forState:UIControlStateNormal];
- [leftbtn setTitleColor:rgba(255, 255, 255, 1) forState:UIControlStateNormal];
- leftbtn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
- leftbtn.adjustsImageWhenHighlighted = false;
- [bottomView addSubview:leftbtn];
- [leftbtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.equalTo(bottomView);
- make.right.equalTo(bottomView.mas_centerX);
- make.height.mas_equalTo(@48);
- }];
-
- UIView *line = [UIView new];
- line.backgroundColor = rgba(255, 255, 255, 0.2);
- [bottomView addSubview:line];
- [line mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(bottomView).offset(12);
- make.centerX.equalTo(bottomView);
- make.height.mas_equalTo(@24);
- make.width.mas_equalTo(@2);
- }];
-
- UIButton *rightbtn =[UIButton buttonWithType:UIButtonTypeCustom];
- // [leftbtn setImage:[UIImage imageNamed:@"Frame 9423"] forState:UIControlStateNormal];
- [rightbtn setTitle:@"删除" forState:UIControlStateNormal];
- [rightbtn setTitleColor:rgba(255, 212, 0, 1) forState:UIControlStateNormal];
- rightbtn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
- rightbtn.adjustsImageWhenHighlighted = false;
- [bottomView addSubview:rightbtn];
- [rightbtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.top.equalTo(bottomView);
- make.left.equalTo(bottomView.mas_centerX);
- make.height.mas_equalTo(@48);
- }];
-
-
- // 创建圆角路径
- UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:bottomView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(12, 12)];
- // 创建圆角图层
- CAShapeLayer *maskLayer = [CAShapeLayer layer];
- maskLayer.path = path.CGPath;
- bottomView.layer.mask = maskLayer;
-
- line.layer.cornerRadius = 2;
- line.layer.masksToBounds = true;
- }
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- // return self.dataArr.count;
- return self.playHisData.count;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- HistoryCell *cell = [HistoryCell cellWithTableView:tableView];
- cell.isEdit = self.isEdit;
- cell.dic = self.playHisData[self.playHisData.count - 1 - indexPath.row];
- return cell;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 80+16;
- }
- -(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;
- }
- -(void)changeSelState:(UIButton *)btn{
- if(!btn.isSelected){
- //编辑状态
- self.isEdit = true;
- self.bottomView.hidden = false;
- [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.equalTo(self.view);
- make.bottom.equalTo(self.bottomView.mas_top);
- make.top.equalTo(self.customerbar.mas_bottom);
- }];
-
- }else{
- //取消编辑
- self.isEdit = false;
- self.bottomView.hidden = true;
- [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.equalTo(self.view);
- make.top.equalTo(self.customerbar.mas_bottom);
- }];
- }
- [self.tableView reloadData];
- btn.selected = !btn.isSelected;
- }
- -(CommonBarView *)customerbar{
- if(!_customerbar){
- 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;
- }
- _customerbar =[[CommonBarView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 72-20+h)];
- _customerbar.bgView.backgroundColor = [UIColor clearColor];
- _customerbar.label.text=@"观看历史";
- _customerbar.bgView.alpha = 1;
- _customerbar.label.textColor = rgba(255, 255, 255, 1);
- // _customerbar.leftButton.hidden = true;
- // [_customerbar.leftButton setImage:[UIImage imageNamed:@"his_back"] forState:UIControlStateNormal];
- [_customerbar.rightButton setImage:[UIImage imageNamed:@"Frame 9411"] forState:UIControlStateNormal];
- [_customerbar.rightButton setTitle:@"编辑" forState:UIControlStateNormal];
- [_customerbar.rightButton setImage:[self imageWithColor:[UIColor clearColor]] forState:UIControlStateSelected];
- [_customerbar.rightButton setTitle:@"取消" forState:UIControlStateSelected];
- [_customerbar.rightButton setTitleColor:rgba(255, 255, 255, 1) forState:UIControlStateNormal];
- _customerbar.rightButton.titleLabel.font =[UIFont systemFontOfSize:14];
- _customerbar.rightButton.hidden = true;
- [_customerbar.leftButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
- [_customerbar.rightButton addTarget:self action:@selector(changeSelState:) forControlEvents:UIControlEventTouchUpInside];
- // [_customerbar.rightButton addTarget:self action:@selector(shareAction) forControlEvents:UIControlEventTouchUpInside];
- // [_customerbar.rightButton mas_remakeConstraints:^(MASConstraintMaker *make) {
- // make.centerY.equalTo(_customerbar.leftButton);
- // make.right.equalTo(_customerbar).offset(-15);
- // make.size.mas_equalTo(CGSizeMake(23, 23));
- // }];
- }
- return _customerbar;
- }
- -(void)backAction{
- [self.navigationController popViewControllerAnimated:true];
- }
- - (UIImage *)imageWithColor:(UIColor *)color
- {
- CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
- UIGraphicsBeginImageContext(rect.size);
- CGContextRef context = UIGraphicsGetCurrentContext();
-
- CGContextSetFillColorWithColor(context, [color CGColor]);
- CGContextFillRect(context, rect);
-
- UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
-
- return image;
- }
- @end
- @interface HistoryCell()
- @property(nonatomic,strong)UIButton *sel;
- @property(nonatomic,strong)UILabel *playProcessLabel;
- @end
- @implementation HistoryCell
- + (instancetype)cellWithTableView:(UITableView *)tableView{
- static NSString *identifier = @"HistoryCell";
- HistoryCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
- if (cell == nil) {
- cell = [[HistoryCell 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)setIsEdit:(BOOL)isEdit{
- _isEdit = isEdit;
- if(isEdit){
- self.sel.hidden = false;
- }else{
- self.sel.hidden = true;
- }
- }
- -(void)setDic:(NSDictionary *)dic{
- _dic = dic;
- UIView *cview = [self.contentView viewWithTag:200] ;
- UIImageView *iv=[cview viewWithTag:100];
- [iv sd_setImageWithURL:[NSURL URLWithString:dic[@"simple_info"][@"horizontal_cover_url"]]];
-
- UILabel *nameLabel=[cview viewWithTag:101];
- nameLabel.text = dic[@"simple_info"][@"ch_name"];
-
- UIButton *processBtn=[cview viewWithTag:102];
- NSString *vid = [NSString stringWithFormat:@"%d",[dic[@"simple_info"][@"vid"] intValue]];
-
- NSDictionary *dicp = [[NSUserDefaults standardUserDefaults] objectForKey:@"playProcessData"];
- if(dicp && dicp[vid]){
- [processBtn setTitle:[NSString stringWithFormat:@" 观看进度%.0f%%",[dicp[vid] floatValue]*100] forState:UIControlStateNormal];
- }else{
- [processBtn setTitle:@" 观看不足1%" forState:UIControlStateNormal];
- }
-
- self.playProcessLabel.text = [NSString stringWithFormat:@"观看到第%d集",[dic[@"episodes"] intValue]];
-
- UIView *lineProcess2 = [cview viewWithTag:103];
- [lineProcess2 mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(nameLabel);
- make.width.mas_equalTo(@((SCREEN_WIDTH-188)*[dicp[vid] floatValue]));
- make.bottom.equalTo(cview).offset(-12);
- make.height.mas_equalTo(@2);
- }];
- }
- -(void)creatView{
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.backgroundColor = [UIColor clearColor];
-
- UIView *cview = [UIView new];
- cview.backgroundColor = rgba(27, 31, 48, 1);
- cview.tag = 200;
- [self.contentView addSubview:cview];
- [cview 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];
- [cview addSubview:iv];
- iv.tag = 100;
- [iv mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.equalTo(cview);
- make.size.mas_equalTo(CGSizeMake(140, 80));
- }];
-
- UIImageView *playProcess = [UIImageView new];
- playProcess.image = [UIImage imageNamed:@"Rectangle 84"];
- [iv addSubview:playProcess];
- [playProcess mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.bottom.equalTo(iv);
- make.size.mas_equalTo(CGSizeMake(74, 20));
- }];
-
- UILabel *playProcessLabel = [UILabel new];
- self.playProcessLabel = playProcessLabel;
- playProcessLabel.font= [UIFont systemFontOfSize:10];
- playProcessLabel.textColor = rgba(255, 255, 255, 1);
- playProcessLabel.textAlignment = NSTextAlignmentCenter;
- [playProcess addSubview:playProcessLabel];
- [playProcessLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(playProcess);
- }];
-
-
-
- UIButton *sel = [UIButton new];
- self.sel = sel;
- sel.hidden = true;
- [sel setBackgroundImage:[UIImage imageNamed:@"Frame 9465"] forState:UIControlStateNormal];
- [cview addSubview:sel];
- [sel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(16, 16));
- make.right.equalTo(cview).offset(-8);
- make.top.equalTo(cview).offset(8);
- }];
-
-
- //48
- // UIView *bview =[UIView new];
- // bview.backgroundColor = rgba(27, 31, 48, 1);
- // [cview addSubview:bview];
- // [bview mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.height.mas_equalTo(@48);
- // make.left.right.bottom.equalTo(cview);
- // }];
-
- UILabel *nameLabel = [UILabel new];
- nameLabel.font= [UIFont boldSystemFontOfSize:14];
- nameLabel.textColor = rgba(255, 255, 255, 1);
- nameLabel.text = @"复仇者联盟";
- nameLabel.tag = 101;
- [cview addSubview:nameLabel];
- [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(iv.mas_right).offset(12);
- make.top.equalTo(cview).offset(12);
- }];
-
- UIButton *processBtn =[UIButton buttonWithType:UIButtonTypeCustom];
- [processBtn setImage:[UIImage imageNamed:@"Frame 9423"] forState:UIControlStateNormal];
- [processBtn setTitle:@" 观看不足1%" forState:UIControlStateNormal];
- [processBtn setTitleColor:rgba(255, 255, 255, 0.4) forState:UIControlStateNormal];
- processBtn.titleLabel.font = [UIFont systemFontOfSize:12];
- processBtn.adjustsImageWhenHighlighted = false;
- [cview addSubview:processBtn];
- processBtn.tag = 102;
- [processBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(nameLabel.mas_bottom).offset(11);
- make.left.equalTo(nameLabel);
- }];
-
- UIView *lineProcess = [UIView new];
- lineProcess.backgroundColor = rgba(255, 255, 255, 0.4);
- [cview addSubview:lineProcess];
- [lineProcess mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(nameLabel);
- make.right.equalTo(cview).offset(-12);
- make.bottom.equalTo(cview).offset(-12);
- make.height.mas_equalTo(@2);
- }];
-
- UIView *lineProcess2 = [UIView new];
- lineProcess2.backgroundColor = rgba(255, 212, 0, 1);
- [cview addSubview:lineProcess2];
- lineProcess2.tag = 103;
- [lineProcess2 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(nameLabel);
- make.width.mas_equalTo(@((SCREEN_WIDTH-188)*0.4));
- make.bottom.equalTo(cview).offset(-12);
- make.height.mas_equalTo(@2);
- }];
-
- cview.layer.cornerRadius = 8;
- cview.layer.masksToBounds = true;
- iv.layer.cornerRadius = 8;
- iv.layer.masksToBounds = true;
- lineProcess.layer.cornerRadius = 1;
- lineProcess.layer.masksToBounds = true;
- lineProcess2.layer.cornerRadius = 1;
- lineProcess2.layer.masksToBounds = true;
- }
- -(void)setFrame:(CGRect)frame{
- frame.origin.y += 16;
- frame.size.height -= 16;
- [super setFrame:frame];
- }
- @end
|