FavViewController.m 17 KB

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