PlayHistoryViewController.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. //
  2. // PlayHistoryViewController.m
  3. // AICity
  4. //
  5. // Created by 刘伟伟 on 2023/7/13.
  6. // Copyright © 2023 wei.z. All rights reserved.
  7. //
  8. #import "PlayHistoryViewController.h"
  9. #import "CommonBarView.h"
  10. @interface PlayHistoryViewController ()<UITableViewDelegate,UITableViewDataSource>
  11. @property(nonatomic,strong)CommonBarView *customerbar;
  12. @property(nonatomic,strong)UITableView *tableView;
  13. @property(nonatomic,strong)UIView *bottomView;
  14. @property(nonatomic,assign)BOOL isEdit;
  15. @property(nonatomic,strong)NSArray *playHisData;
  16. @end
  17. @implementation PlayHistoryViewController
  18. -(UIStatusBarStyle)preferredStatusBarStyle{
  19. return UIStatusBarStyleLightContent;
  20. }
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. // Do any additional setup after loading the view.
  24. self.fd_prefersNavigationBarHidden = true;
  25. self.playHisData = [[NSUserDefaults standardUserDefaults] objectForKey:@"myhistoryplaylist"];
  26. self.view.backgroundColor = rgba(18, 23, 41, 1);
  27. [self.view addSubview:self.customerbar];
  28. [self.view addSubview:self.tableView];
  29. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.left.right.bottom.equalTo(self.view);
  31. make.top.equalTo(self.customerbar.mas_bottom);
  32. }];
  33. [self addBottomView];
  34. if(self.playHisData.count == 0){
  35. [self addNotDataView];
  36. }
  37. }
  38. -(void)addNotDataView{
  39. UIImageView *iv = [UIImageView new];
  40. iv.image = [UIImage imageNamed:@"nohis_1"];
  41. [self.view addSubview:iv];
  42. [iv mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.size.mas_equalTo(CGSizeMake(246, 175));
  44. make.centerX.equalTo(self.view);
  45. make.top.equalTo(self.customerbar.mas_bottom).offset(192);
  46. }];
  47. UILabel *label = [UILabel new];
  48. label.textColor = rgba(255, 255, 255, 0.4);
  49. label.text = @"您还没有观看历史";
  50. label.font = [UIFont systemFontOfSize:16];
  51. [self.view addSubview:label];
  52. [label mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.centerX.equalTo(iv);
  54. make.bottom.equalTo(iv).offset(-6);
  55. }];
  56. UILabel *label2 = [UILabel new];
  57. label2.textColor = rgba(255, 255, 255, 0.2);
  58. label2.text = @"快来开始您的观影之旅吧";
  59. label2.font = [UIFont systemFontOfSize:12];
  60. [self.view addSubview:label2];
  61. [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
  62. make.centerX.equalTo(iv);
  63. make.top.equalTo(label.mas_bottom).offset(8);
  64. }];
  65. }
  66. -(void)addBottomView{
  67. UIView *bottomView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 48+safebottom)];
  68. self.bottomView = bottomView;
  69. self.bottomView.hidden = true;
  70. bottomView.backgroundColor = rgba(25, 29, 49, 1);
  71. [self.view addSubview:bottomView];
  72. [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.bottom.equalTo(self.view);
  74. make.height.mas_equalTo(@(48+safebottom));
  75. make.width.mas_equalTo(@(SCREEN_WIDTH));
  76. }];
  77. UIButton *leftbtn =[UIButton buttonWithType:UIButtonTypeCustom];
  78. // [leftbtn setImage:[UIImage imageNamed:@"Frame 9423"] forState:UIControlStateNormal];
  79. [leftbtn setTitle:@"取消全选" forState:UIControlStateNormal];
  80. [leftbtn setTitleColor:rgba(255, 255, 255, 1) forState:UIControlStateNormal];
  81. leftbtn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
  82. leftbtn.adjustsImageWhenHighlighted = false;
  83. [bottomView addSubview:leftbtn];
  84. [leftbtn mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.left.top.equalTo(bottomView);
  86. make.right.equalTo(bottomView.mas_centerX);
  87. make.height.mas_equalTo(@48);
  88. }];
  89. UIView *line = [UIView new];
  90. line.backgroundColor = rgba(255, 255, 255, 0.2);
  91. [bottomView addSubview:line];
  92. [line mas_makeConstraints:^(MASConstraintMaker *make) {
  93. make.top.equalTo(bottomView).offset(12);
  94. make.centerX.equalTo(bottomView);
  95. make.height.mas_equalTo(@24);
  96. make.width.mas_equalTo(@2);
  97. }];
  98. UIButton *rightbtn =[UIButton buttonWithType:UIButtonTypeCustom];
  99. // [leftbtn setImage:[UIImage imageNamed:@"Frame 9423"] forState:UIControlStateNormal];
  100. [rightbtn setTitle:@"删除" forState:UIControlStateNormal];
  101. [rightbtn setTitleColor:rgba(255, 212, 0, 1) forState:UIControlStateNormal];
  102. rightbtn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
  103. rightbtn.adjustsImageWhenHighlighted = false;
  104. [bottomView addSubview:rightbtn];
  105. [rightbtn mas_makeConstraints:^(MASConstraintMaker *make) {
  106. make.right.top.equalTo(bottomView);
  107. make.left.equalTo(bottomView.mas_centerX);
  108. make.height.mas_equalTo(@48);
  109. }];
  110. // 创建圆角路径
  111. UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:bottomView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(12, 12)];
  112. // 创建圆角图层
  113. CAShapeLayer *maskLayer = [CAShapeLayer layer];
  114. maskLayer.path = path.CGPath;
  115. bottomView.layer.mask = maskLayer;
  116. line.layer.cornerRadius = 2;
  117. line.layer.masksToBounds = true;
  118. }
  119. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  120. // return self.dataArr.count;
  121. return self.playHisData.count;
  122. }
  123. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  124. HistoryCell *cell = [HistoryCell cellWithTableView:tableView];
  125. cell.isEdit = self.isEdit;
  126. cell.dic = self.playHisData[self.playHisData.count - 1 - indexPath.row];
  127. return cell;
  128. }
  129. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  130. return 80+16;
  131. }
  132. -(UITableView *)tableView{
  133. if(!_tableView){
  134. _tableView =[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
  135. _tableView.delegate = self;
  136. _tableView.dataSource = self;
  137. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  138. _tableView.showsVerticalScrollIndicator = false;
  139. _tableView.showsHorizontalScrollIndicator = false;
  140. _tableView.backgroundColor = rgba(18, 23, 41, 1);
  141. // _tableView.backgroundColor = [UIColor redColor];
  142. if (@available(iOS 11, *)) {
  143. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  144. _tableView.estimatedRowHeight = 0;
  145. _tableView.estimatedSectionFooterHeight = 0;
  146. _tableView.estimatedSectionHeaderHeight = 0;
  147. UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
  148. UIEdgeInsets safeAreaInsets = keyWindow.safeAreaInsets;
  149. CGFloat topSafeArea = safeAreaInsets.top;
  150. _tableView.contentInset = UIEdgeInsetsMake(-topSafeArea, 0, BAR_HEIGHT, 0);
  151. // _tableView2.contentInset = UIEdgeInsetsMake(-35, 0, 0, 0);
  152. }
  153. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 // only Xcode 13+ needs and can compile this
  154. if (@available(iOS 15.0, *)) {
  155. _tableView.sectionHeaderTopPadding = 0;
  156. }
  157. #endif
  158. }
  159. return _tableView;
  160. }
  161. -(void)changeSelState:(UIButton *)btn{
  162. if(!btn.isSelected){
  163. //编辑状态
  164. self.isEdit = true;
  165. self.bottomView.hidden = false;
  166. [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  167. make.left.right.equalTo(self.view);
  168. make.bottom.equalTo(self.bottomView.mas_top);
  169. make.top.equalTo(self.customerbar.mas_bottom);
  170. }];
  171. }else{
  172. //取消编辑
  173. self.isEdit = false;
  174. self.bottomView.hidden = true;
  175. [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  176. make.left.right.bottom.equalTo(self.view);
  177. make.top.equalTo(self.customerbar.mas_bottom);
  178. }];
  179. }
  180. [self.tableView reloadData];
  181. btn.selected = !btn.isSelected;
  182. }
  183. -(CommonBarView *)customerbar{
  184. if(!_customerbar){
  185. CGFloat h=0;
  186. if(@available(iOS 13.0, *)){
  187. UIStatusBarManager *sc= [UIApplication sharedApplication].windows.firstObject.windowScene.statusBarManager;
  188. CGRect f=sc.statusBarFrame;
  189. h=f.size.height;
  190. }else{
  191. h=[UIApplication sharedApplication].statusBarFrame.size.height;
  192. }
  193. if(h>=40){
  194. h=30;
  195. }
  196. _customerbar =[[CommonBarView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 72-20+h)];
  197. _customerbar.bgView.backgroundColor = [UIColor clearColor];
  198. _customerbar.label.text=@"观看历史";
  199. _customerbar.bgView.alpha = 1;
  200. _customerbar.label.textColor = rgba(255, 255, 255, 1);
  201. // _customerbar.leftButton.hidden = true;
  202. // [_customerbar.leftButton setImage:[UIImage imageNamed:@"his_back"] forState:UIControlStateNormal];
  203. [_customerbar.rightButton setImage:[UIImage imageNamed:@"Frame 9411"] forState:UIControlStateNormal];
  204. [_customerbar.rightButton setTitle:@"编辑" forState:UIControlStateNormal];
  205. [_customerbar.rightButton setImage:[self imageWithColor:[UIColor clearColor]] forState:UIControlStateSelected];
  206. [_customerbar.rightButton setTitle:@"取消" forState:UIControlStateSelected];
  207. [_customerbar.rightButton setTitleColor:rgba(255, 255, 255, 1) forState:UIControlStateNormal];
  208. _customerbar.rightButton.titleLabel.font =[UIFont systemFontOfSize:14];
  209. _customerbar.rightButton.hidden = true;
  210. [_customerbar.leftButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  211. [_customerbar.rightButton addTarget:self action:@selector(changeSelState:) forControlEvents:UIControlEventTouchUpInside];
  212. // [_customerbar.rightButton addTarget:self action:@selector(shareAction) forControlEvents:UIControlEventTouchUpInside];
  213. // [_customerbar.rightButton mas_remakeConstraints:^(MASConstraintMaker *make) {
  214. // make.centerY.equalTo(_customerbar.leftButton);
  215. // make.right.equalTo(_customerbar).offset(-15);
  216. // make.size.mas_equalTo(CGSizeMake(23, 23));
  217. // }];
  218. }
  219. return _customerbar;
  220. }
  221. -(void)backAction{
  222. [self.navigationController popViewControllerAnimated:true];
  223. }
  224. - (UIImage *)imageWithColor:(UIColor *)color
  225. {
  226. CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
  227. UIGraphicsBeginImageContext(rect.size);
  228. CGContextRef context = UIGraphicsGetCurrentContext();
  229. CGContextSetFillColorWithColor(context, [color CGColor]);
  230. CGContextFillRect(context, rect);
  231. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  232. UIGraphicsEndImageContext();
  233. return image;
  234. }
  235. @end
  236. @interface HistoryCell()
  237. @property(nonatomic,strong)UIButton *sel;
  238. @property(nonatomic,strong)UILabel *playProcessLabel;
  239. @end
  240. @implementation HistoryCell
  241. + (instancetype)cellWithTableView:(UITableView *)tableView{
  242. static NSString *identifier = @"HistoryCell";
  243. HistoryCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  244. if (cell == nil) {
  245. cell = [[HistoryCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  246. }
  247. return cell;
  248. }
  249. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  250. {
  251. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  252. if (self) {
  253. [self creatView];
  254. }
  255. return self;
  256. }
  257. -(void)setIsEdit:(BOOL)isEdit{
  258. _isEdit = isEdit;
  259. if(isEdit){
  260. self.sel.hidden = false;
  261. }else{
  262. self.sel.hidden = true;
  263. }
  264. }
  265. -(void)setDic:(NSDictionary *)dic{
  266. _dic = dic;
  267. UIView *cview = [self.contentView viewWithTag:200] ;
  268. UIImageView *iv=[cview viewWithTag:100];
  269. [iv sd_setImageWithURL:[NSURL URLWithString:dic[@"simple_info"][@"horizontal_cover_url"]]];
  270. UILabel *nameLabel=[cview viewWithTag:101];
  271. nameLabel.text = dic[@"simple_info"][@"ch_name"];
  272. UIButton *processBtn=[cview viewWithTag:102];
  273. NSString *vid = [NSString stringWithFormat:@"%d",[dic[@"simple_info"][@"vid"] intValue]];
  274. NSDictionary *dicp = [[NSUserDefaults standardUserDefaults] objectForKey:@"playProcessData"];
  275. if(dicp && dicp[vid]){
  276. [processBtn setTitle:[NSString stringWithFormat:@" 观看进度%.0f%%",[dicp[vid] floatValue]*100] forState:UIControlStateNormal];
  277. }else{
  278. [processBtn setTitle:@" 观看不足1%" forState:UIControlStateNormal];
  279. }
  280. self.playProcessLabel.text = [NSString stringWithFormat:@"观看到第%d集",[dic[@"episodes"] intValue]];
  281. UIView *lineProcess2 = [cview viewWithTag:103];
  282. [lineProcess2 mas_remakeConstraints:^(MASConstraintMaker *make) {
  283. make.left.equalTo(nameLabel);
  284. make.width.mas_equalTo(@((SCREEN_WIDTH-188)*[dicp[vid] floatValue]));
  285. make.bottom.equalTo(cview).offset(-12);
  286. make.height.mas_equalTo(@2);
  287. }];
  288. }
  289. -(void)creatView{
  290. self.selectionStyle = UITableViewCellSelectionStyleNone;
  291. self.backgroundColor = [UIColor clearColor];
  292. UIView *cview = [UIView new];
  293. cview.backgroundColor = rgba(27, 31, 48, 1);
  294. cview.tag = 200;
  295. [self.contentView addSubview:cview];
  296. [cview mas_makeConstraints:^(MASConstraintMaker *make) {
  297. make.top.bottom.equalTo(self.contentView);
  298. make.left.equalTo(self.contentView).offset(12);
  299. make.right.equalTo(self.contentView).offset(-12);
  300. }];
  301. UIImageView *iv = [UIImageView new];
  302. [cview addSubview:iv];
  303. iv.tag = 100;
  304. [iv mas_makeConstraints:^(MASConstraintMaker *make) {
  305. make.top.left.equalTo(cview);
  306. make.size.mas_equalTo(CGSizeMake(140, 80));
  307. }];
  308. UIImageView *playProcess = [UIImageView new];
  309. playProcess.image = [UIImage imageNamed:@"Rectangle 84"];
  310. [iv addSubview:playProcess];
  311. [playProcess mas_makeConstraints:^(MASConstraintMaker *make) {
  312. make.right.bottom.equalTo(iv);
  313. make.size.mas_equalTo(CGSizeMake(74, 20));
  314. }];
  315. UILabel *playProcessLabel = [UILabel new];
  316. self.playProcessLabel = playProcessLabel;
  317. playProcessLabel.font= [UIFont systemFontOfSize:10];
  318. playProcessLabel.textColor = rgba(255, 255, 255, 1);
  319. playProcessLabel.textAlignment = NSTextAlignmentCenter;
  320. [playProcess addSubview:playProcessLabel];
  321. [playProcessLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  322. make.edges.equalTo(playProcess);
  323. }];
  324. UIButton *sel = [UIButton new];
  325. self.sel = sel;
  326. sel.hidden = true;
  327. [sel setBackgroundImage:[UIImage imageNamed:@"Frame 9465"] forState:UIControlStateNormal];
  328. [cview addSubview:sel];
  329. [sel mas_makeConstraints:^(MASConstraintMaker *make) {
  330. make.size.mas_equalTo(CGSizeMake(16, 16));
  331. make.right.equalTo(cview).offset(-8);
  332. make.top.equalTo(cview).offset(8);
  333. }];
  334. //48
  335. // UIView *bview =[UIView new];
  336. // bview.backgroundColor = rgba(27, 31, 48, 1);
  337. // [cview addSubview:bview];
  338. // [bview mas_makeConstraints:^(MASConstraintMaker *make) {
  339. // make.height.mas_equalTo(@48);
  340. // make.left.right.bottom.equalTo(cview);
  341. // }];
  342. UILabel *nameLabel = [UILabel new];
  343. nameLabel.font= [UIFont boldSystemFontOfSize:14];
  344. nameLabel.textColor = rgba(255, 255, 255, 1);
  345. nameLabel.text = @"复仇者联盟";
  346. nameLabel.tag = 101;
  347. [cview addSubview:nameLabel];
  348. [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  349. make.left.equalTo(iv.mas_right).offset(12);
  350. make.top.equalTo(cview).offset(12);
  351. }];
  352. UIButton *processBtn =[UIButton buttonWithType:UIButtonTypeCustom];
  353. [processBtn setImage:[UIImage imageNamed:@"Frame 9423"] forState:UIControlStateNormal];
  354. [processBtn setTitle:@" 观看不足1%" forState:UIControlStateNormal];
  355. [processBtn setTitleColor:rgba(255, 255, 255, 0.4) forState:UIControlStateNormal];
  356. processBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  357. processBtn.adjustsImageWhenHighlighted = false;
  358. [cview addSubview:processBtn];
  359. processBtn.tag = 102;
  360. [processBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  361. make.top.equalTo(nameLabel.mas_bottom).offset(11);
  362. make.left.equalTo(nameLabel);
  363. }];
  364. UIView *lineProcess = [UIView new];
  365. lineProcess.backgroundColor = rgba(255, 255, 255, 0.4);
  366. [cview addSubview:lineProcess];
  367. [lineProcess mas_makeConstraints:^(MASConstraintMaker *make) {
  368. make.left.equalTo(nameLabel);
  369. make.right.equalTo(cview).offset(-12);
  370. make.bottom.equalTo(cview).offset(-12);
  371. make.height.mas_equalTo(@2);
  372. }];
  373. UIView *lineProcess2 = [UIView new];
  374. lineProcess2.backgroundColor = rgba(255, 212, 0, 1);
  375. [cview addSubview:lineProcess2];
  376. lineProcess2.tag = 103;
  377. [lineProcess2 mas_makeConstraints:^(MASConstraintMaker *make) {
  378. make.left.equalTo(nameLabel);
  379. make.width.mas_equalTo(@((SCREEN_WIDTH-188)*0.4));
  380. make.bottom.equalTo(cview).offset(-12);
  381. make.height.mas_equalTo(@2);
  382. }];
  383. cview.layer.cornerRadius = 8;
  384. cview.layer.masksToBounds = true;
  385. iv.layer.cornerRadius = 8;
  386. iv.layer.masksToBounds = true;
  387. lineProcess.layer.cornerRadius = 1;
  388. lineProcess.layer.masksToBounds = true;
  389. lineProcess2.layer.cornerRadius = 1;
  390. lineProcess2.layer.masksToBounds = true;
  391. }
  392. -(void)setFrame:(CGRect)frame{
  393. frame.origin.y += 16;
  394. frame.size.height -= 16;
  395. [super setFrame:frame];
  396. }
  397. @end