JXCollectionViewController.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. //
  2. // JXCollectionViewController.m
  3. // AICity
  4. //
  5. // Created by TogetherWatch on 2025-10-20.
  6. //
  7. #import "JXCollectionViewController.h"
  8. #import "JXAPIService.h"
  9. #import "JXDrama.h"
  10. #import "JXEpisodeInfo.h"
  11. #import "JXInteraction.h"
  12. #import "JXShortDramaCell.h"
  13. #import "videoItemsCell.h"
  14. #import "videoItemsNavCell.h"
  15. // Cell复用标识符
  16. //static NSString * const kEpisodeCellIdentifier = @"JXEpisodeCell";
  17. @interface JXCollectionViewController () <UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
  18. #pragma mark - UI组件
  19. @property (nonatomic, strong) UIView *headerView;
  20. @property (strong, nonatomic) UIImageView *headImg;
  21. @property (nonatomic, strong) UILabel *titleLabel;
  22. @property (nonatomic, strong) UILabel *statsLabel;
  23. @property (nonatomic, strong) UIButton *closeButton;
  24. @property (nonatomic, strong) UIView *rangePickerView;
  25. @property (nonatomic, strong) UIButton *rangeButton1;
  26. @property (nonatomic, strong) UIButton *rangeButton2;
  27. @property (nonatomic, strong) UIButton *rangeButton3;
  28. @property (nonatomic, strong) UICollectionView *collectionView;
  29. @property (nonatomic, strong) UICollectionView *collectionViewNav;
  30. @property (strong, nonatomic) NSMutableArray *navArray;
  31. #pragma mark - 数据
  32. @property (nonatomic, copy) NSString *dramaId;
  33. @property (nonatomic, strong) JXDrama *drama;
  34. @property (nonatomic, strong) NSDictionary *pageData;
  35. @property (nonatomic, strong) NSArray<JXEpisodeInfo *> *episodes;
  36. @property (nonatomic, strong) NSArray<JXEpisodeInfo *> *filteredEpisodes;
  37. @property (nonatomic, assign) NSInteger selectedRange; // 0=全部, 1=1-50, 2=51-100
  38. @end
  39. @implementation JXCollectionViewController
  40. #pragma mark - 初始化
  41. - (instancetype)initWithDramaId:(NSString *)dramaId {
  42. self = [super init];
  43. if (self) {
  44. _dramaId = dramaId;
  45. _selectedRange = 0;
  46. }
  47. return self;
  48. }
  49. #pragma mark - 生命周期
  50. - (void)viewDidLoad {
  51. [super viewDidLoad];
  52. self.view.backgroundColor = [UIColor whiteColor];
  53. self.pageData = [[NSDictionary alloc] init];
  54. [self setupUI];
  55. [self loadData];
  56. }
  57. #pragma mark - UI设置
  58. - (void)setupUI {
  59. // 顶部标题栏
  60. [self setupHeader];
  61. // 集数范围选择器
  62. // [self setupRangePicker];
  63. [self setupCollectionViewnav];
  64. // 剧集列表
  65. [self setupCollectionView];
  66. }
  67. - (void)setupHeader {
  68. self.headerView = [[UIView alloc] init];
  69. self.headerView.backgroundColor = [UIColor whiteColor];
  70. [self.view addSubview:self.headerView];
  71. //图片
  72. self.headImg = [[UIImageView alloc] init];
  73. self.headImg.image = [UIImage imageNamed:@"icon 2.1"];
  74. [self.headerView addSubview:self.headImg];
  75. // 标题
  76. self.titleLabel = [[UILabel alloc] init];
  77. self.titleLabel.text = @"合集";
  78. self.titleLabel.font = [UIFont boldSystemFontOfSize:18];
  79. self.titleLabel.textColor = [UIColor blackColor];
  80. [self.headerView addSubview:self.titleLabel];
  81. // 统计信息
  82. self.statsLabel = [[UILabel alloc] init];
  83. self.statsLabel.text = @"正在加载...";
  84. self.statsLabel.font = [UIFont systemFontOfSize:14];
  85. self.statsLabel.textColor = [UIColor grayColor];
  86. [self.headerView addSubview:self.statsLabel];
  87. // 关闭按钮
  88. self.closeButton = [UIButton buttonWithType:UIButtonTypeSystem];
  89. [self.closeButton setImage:[UIImage systemImageNamed:@"xmark"] forState:UIControlStateNormal];
  90. self.closeButton.tintColor = [UIColor grayColor];
  91. [self.closeButton addTarget:self action:@selector(handleClose) forControlEvents:UIControlEventTouchUpInside];
  92. [self.headerView addSubview:self.closeButton];
  93. // 约束
  94. self.headerView.translatesAutoresizingMaskIntoConstraints = NO;
  95. self.headImg.translatesAutoresizingMaskIntoConstraints = NO;
  96. self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
  97. self.statsLabel.translatesAutoresizingMaskIntoConstraints = NO;
  98. self.closeButton.translatesAutoresizingMaskIntoConstraints = NO;
  99. [NSLayoutConstraint activateConstraints:@[
  100. [self.headerView.topAnchor constraintEqualToAnchor:self.view.topAnchor],
  101. [self.headerView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
  102. [self.headerView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
  103. [self.headerView.heightAnchor constraintEqualToConstant:80],
  104. [self.headImg.topAnchor constraintEqualToAnchor:self.headerView.topAnchor constant:14.5],
  105. [self.headImg.leadingAnchor constraintEqualToAnchor:self.headerView.leadingAnchor constant:16],
  106. [self.headImg.widthAnchor constraintEqualToConstant:17],
  107. [self.headImg.heightAnchor constraintEqualToConstant:16.5],
  108. [self.titleLabel.topAnchor constraintEqualToAnchor:self.headerView.topAnchor constant:14.5],
  109. [self.titleLabel.leadingAnchor constraintEqualToAnchor:self.headerView.leadingAnchor constant:41],
  110. [self.titleLabel.heightAnchor constraintEqualToConstant:16.5],
  111. [self.statsLabel.topAnchor constraintEqualToAnchor:self.titleLabel.bottomAnchor constant:10],
  112. [self.statsLabel.leadingAnchor constraintEqualToAnchor:self.headerView.leadingAnchor constant:16],
  113. [self.closeButton.trailingAnchor constraintEqualToAnchor:self.headerView.trailingAnchor constant:-16],
  114. [self.closeButton.centerYAnchor constraintEqualToAnchor:self.titleLabel.centerYAnchor],
  115. [self.closeButton.widthAnchor constraintEqualToConstant:30],
  116. [self.closeButton.heightAnchor constraintEqualToConstant:30]
  117. ]];
  118. }
  119. - (void)setupRangePicker {
  120. // self.rangePickerView = [[UIView alloc] init];
  121. // self.rangePickerView.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1.0];
  122. // [self.view addSubview:self.rangePickerView];
  123. // // 全部
  124. // self.rangeButton1 = [self createRangeButtonWithTitle:@"全部" tag:0];
  125. // [self.rangePickerView addSubview:self.rangeButton1];
  126. //
  127. // // 1-50
  128. // self.rangeButton2 = [self createRangeButtonWithTitle:@"1-50集" tag:1];
  129. // [self.rangePickerView addSubview:self.rangeButton2];
  130. //
  131. // // 51-100
  132. // self.rangeButton3 = [self createRangeButtonWithTitle:@"51-100集" tag:2];
  133. // [self.rangePickerView addSubview:self.rangeButton3];
  134. //
  135. // // 默认选中"全部"
  136. // [self selectRangeButton:self.rangeButton1];
  137. //
  138. // // 约束
  139. // self.rangePickerView.translatesAutoresizingMaskIntoConstraints = NO;
  140. // self.rangeButton1.translatesAutoresizingMaskIntoConstraints = NO;
  141. // self.rangeButton2.translatesAutoresizingMaskIntoConstraints = NO;
  142. // self.rangeButton3.translatesAutoresizingMaskIntoConstraints = NO;
  143. //
  144. // [NSLayoutConstraint activateConstraints:@[
  145. // [self.rangePickerView.topAnchor constraintEqualToAnchor:self.headerView.bottomAnchor],
  146. // [self.rangePickerView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
  147. // [self.rangePickerView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
  148. // [self.rangePickerView.heightAnchor constraintEqualToConstant:50],
  149. //
  150. // [self.rangeButton1.leadingAnchor constraintEqualToAnchor:self.rangePickerView.leadingAnchor constant:16],
  151. // [self.rangeButton1.centerYAnchor constraintEqualToAnchor:self.rangePickerView.centerYAnchor],
  152. // [self.rangeButton1.widthAnchor constraintEqualToConstant:80],
  153. // [self.rangeButton1.heightAnchor constraintEqualToConstant:32],
  154. //
  155. // [self.rangeButton2.leadingAnchor constraintEqualToAnchor:self.rangeButton1.trailingAnchor constant:12],
  156. // [self.rangeButton2.centerYAnchor constraintEqualToAnchor:self.rangePickerView.centerYAnchor],
  157. // [self.rangeButton2.widthAnchor constraintEqualToConstant:80],
  158. // [self.rangeButton2.heightAnchor constraintEqualToConstant:32],
  159. //
  160. // [self.rangeButton3.leadingAnchor constraintEqualToAnchor:self.rangeButton2.trailingAnchor constant:12],
  161. // [self.rangeButton3.centerYAnchor constraintEqualToAnchor:self.rangePickerView.centerYAnchor],
  162. // [self.rangeButton3.widthAnchor constraintEqualToConstant:80],
  163. // [self.rangeButton3.heightAnchor constraintEqualToConstant:32]
  164. // ]];
  165. }
  166. //- (UIButton *)createRangeButtonWithTitle:(NSString *)title tag:(NSInteger)tag {
  167. // UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
  168. // [button setTitle:title forState:UIControlStateNormal];
  169. // button.titleLabel.font = [UIFont systemFontOfSize:14];
  170. // button.layer.cornerRadius = 16;
  171. // button.layer.borderWidth = 1.0;
  172. // button.tag = tag;
  173. // [button addTarget:self action:@selector(handleRangeButtonTap:) forControlEvents:UIControlEventTouchUpInside];
  174. // return button;
  175. //}
  176. - (void)setupCollectionViewnav{
  177. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  178. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  179. layout.minimumLineSpacing = 6;
  180. layout.minimumInteritemSpacing = 6;
  181. layout.sectionInset = UIEdgeInsetsMake(0, 16, 0, 16);
  182. self.collectionViewNav = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  183. self.collectionViewNav.backgroundColor = [UIColor whiteColor];
  184. self.collectionViewNav.delegate = self;
  185. self.collectionViewNav.dataSource = self;
  186. [self.collectionViewNav registerNib:[UINib nibWithNibName:NSStringFromClass(videoItemsNavCell.class) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass(videoItemsNavCell.class)];
  187. [self.view addSubview:self.collectionViewNav];
  188. // 约束
  189. self.collectionViewNav.translatesAutoresizingMaskIntoConstraints = NO;
  190. [NSLayoutConstraint activateConstraints:@[
  191. [self.collectionViewNav.topAnchor constraintEqualToAnchor:self.headerView.bottomAnchor],
  192. [self.collectionViewNav.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
  193. [self.collectionViewNav.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
  194. [self.collectionViewNav.heightAnchor constraintEqualToConstant:31],
  195. ]];
  196. }
  197. - (void)setupCollectionView {
  198. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  199. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  200. layout.minimumLineSpacing = 0;
  201. layout.minimumInteritemSpacing = 0;
  202. layout.sectionInset = UIEdgeInsetsMake(16, 16, 16, 16);
  203. self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  204. self.collectionView.backgroundColor = [UIColor whiteColor];
  205. self.collectionView.delegate = self;
  206. self.collectionView.dataSource = self;
  207. [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass(videoItemsCell.class) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass(videoItemsCell.class)];
  208. [self.view addSubview:self.collectionView];
  209. // 约束
  210. self.collectionView.translatesAutoresizingMaskIntoConstraints = NO;
  211. [NSLayoutConstraint activateConstraints:@[
  212. [self.collectionView.topAnchor constraintEqualToAnchor:self.collectionViewNav.bottomAnchor],
  213. [self.collectionView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
  214. [self.collectionView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
  215. [self.collectionView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor]
  216. ]];
  217. }
  218. #pragma mark - 数据加载
  219. - (void)loadData {
  220. // 获取短剧详情和剧集列表
  221. [[JXAPIService sharedService] getDramaDetailWithDramaId:self.dramaId
  222. success:^(id response) {
  223. NSDictionary *dramaDict = response[@"data"];
  224. // 解析短剧信息
  225. self.drama = [[JXDrama alloc] initWithDictionary:dramaDict[@"drama"]];
  226. // 解析剧集列表
  227. NSArray *episodesArray = dramaDict[@"episodes"];
  228. NSMutableArray *episodes = [NSMutableArray array];
  229. for (NSDictionary *dict in episodesArray) {
  230. JXEpisodeInfo *episode = [[JXEpisodeInfo alloc] initWithDictionary:dict];
  231. [episodes addObject:episode];
  232. }
  233. self.episodes = episodes;
  234. // 更新UI
  235. [self updateUI];
  236. [self filterEpisodesByRange:self.selectedRange];
  237. } failure:^(NSError *error) {
  238. NSLog(@"[JXCollection] 加载失败: %@", error.localizedDescription);
  239. }];
  240. }
  241. - (void)updateUI {
  242. // self.titleLabel.text = self.drama.title;
  243. // self.statsLabel.text = [NSString stringWithFormat:@"共%ld集 · %@ 播放",
  244. // (long)self.drama.totalEpisodes,
  245. // [JXShortDramaCell formattedCountWithCount:self.drama.viewCount]];
  246. self.statsLabel.text = [NSString stringWithFormat:@"%@ 播放 · 已更新至%ld集", [JXShortDramaCell formattedCountWithCount:self.drama.viewCount], (long)self.drama.totalEpisodes];
  247. }
  248. #pragma mark - 筛选逻辑
  249. - (void)filterEpisodesByRange:(NSInteger)range {
  250. NSInteger all = self.drama.totalEpisodes;
  251. if (all == 0) {
  252. return;
  253. }
  254. for (int i = 1; i < all; i=i+20) {
  255. [self.navArray addObject: [NSString stringWithFormat:@"%d",i]];
  256. }
  257. NSString *str = self.navArray[range];
  258. NSPredicate *predicate;
  259. if (self.drama.totalEpisodes < 20) {
  260. predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"episodeNumber >= %@ AND episodeNumber <= %ld",str,self.drama.totalEpisodes]];
  261. }else{
  262. predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"episodeNumber >= %@ AND episodeNumber <= %d",str,str.intValue+20]];
  263. }
  264. self.filteredEpisodes = [self.episodes filteredArrayUsingPredicate:predicate];
  265. [self.collectionViewNav reloadData];
  266. [self.collectionView reloadData];
  267. }
  268. - (void)selectRangeButton:(UIButton *)button {
  269. // 重置所有按钮
  270. for (UIButton *btn in @[self.rangeButton1, self.rangeButton2, self.rangeButton3]) {
  271. btn.selected = NO;
  272. [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
  273. btn.backgroundColor = [UIColor whiteColor];
  274. btn.layer.borderColor = [UIColor lightGrayColor].CGColor;
  275. }
  276. // 选中当前按钮
  277. button.selected = YES;
  278. [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  279. button.backgroundColor = [UIColor systemBlueColor];
  280. button.layer.borderColor = [UIColor systemBlueColor].CGColor;
  281. }
  282. #pragma mark - UICollectionViewDataSource
  283. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  284. if (collectionView == self.collectionViewNav) {
  285. return self.navArray.count;
  286. }
  287. return self.filteredEpisodes.count;
  288. }
  289. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  290. if (collectionView == self.collectionViewNav) {
  291. videoItemsNavCell *cell1 = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass(videoItemsNavCell.class) forIndexPath:indexPath];
  292. cell1.layer.cornerRadius = 5;
  293. if (self.selectedRange == indexPath.row) {
  294. cell1.backgroundColor = [UIColor colorWithRed:255/255.0 green:240/255.0 blue:234/255.0 alpha:1];
  295. cell1.labelT.textColor = [UIColor colorWithRed:255/255.0 green:112/255.0 blue:48/255.0 alpha:1];
  296. }else{
  297. cell1.backgroundColor = [UIColor colorWithRed:247/255.0 green:247/255.0 blue:247/255.0 alpha:1];
  298. cell1.labelT.textColor = [UIColor colorWithRed:140/255.0 green:140/255.0 blue:140/255.0 alpha:1];
  299. }
  300. NSString *str = self.navArray[indexPath.row];
  301. if (indexPath.row == self.navArray.count -1) {
  302. cell1.labelT.text = [NSString stringWithFormat:@"%@-%ld",str,self.drama.totalEpisodes];
  303. }else{
  304. cell1.labelT.text = [NSString stringWithFormat:@"%@-%d",str,str.intValue+19];
  305. }
  306. return cell1;
  307. }
  308. videoItemsCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass(videoItemsCell.class) forIndexPath:indexPath];
  309. JXEpisodeInfo *episode = self.filteredEpisodes[indexPath.item];
  310. cell.viewVIP.hidden = !episode.isPaid;
  311. cell.btnVIP.hidden = !episode.isPaid;
  312. cell.labelT.text = episode.title;
  313. cell.labelView.text = [NSString stringWithFormat:@"%lld",episode.likeCount];
  314. [cell.imgH sd_setImageWithURL:[NSURL URLWithString:episode.thumbnailUrl]];
  315. cell.labelTime.text = [self getMMSSFromSS:episode.duration];
  316. cell.vipClicked = ^{
  317. //去会员
  318. [MBProgressHUD showMessage:@"维护中..."];
  319. };
  320. cell.playClicked = ^{
  321. if ([self.delegate respondsToSelector:@selector(collectionViewControllerDidSelectEpisode:)]) {
  322. [self.delegate collectionViewControllerDidSelectEpisode:[NSString stringWithFormat:@"%ld",episode.episodeNumber]];
  323. }
  324. [self dismissViewControllerAnimated:YES completion:nil];
  325. };
  326. // JXEpisodeInfo *episode = self.filteredEpisodes[indexPath.item];
  327. // 临时简单展示(后续可创建自定义Cell)
  328. // cell.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1.0];
  329. // cell.layer.cornerRadius = 8;
  330. // 清除旧标签
  331. // for (UIView *subview in cell.contentView.subviews) {
  332. // [subview removeFromSuperview];
  333. // }
  334. //
  335. // // 第X集标签
  336. // UILabel *label = [[UILabel alloc] init];
  337. // label.text = [NSString stringWithFormat:@"第%ld集", (long)episode.episodeNumber];
  338. // label.font = [UIFont boldSystemFontOfSize:14];
  339. // label.textColor = [UIColor blackColor];
  340. // label.textAlignment = NSTextAlignmentCenter;
  341. // [cell.contentView addSubview:label];
  342. //
  343. // // VIP标识
  344. // if (episode.isPaid) {
  345. // UILabel *vipLabel = [[UILabel alloc] init];
  346. // vipLabel.text = @"VIP";
  347. // vipLabel.font = [UIFont boldSystemFontOfSize:10];
  348. // vipLabel.textColor = [UIColor systemOrangeColor];
  349. // vipLabel.textAlignment = NSTextAlignmentCenter;
  350. // [cell.contentView addSubview:vipLabel];
  351. //
  352. // vipLabel.translatesAutoresizingMaskIntoConstraints = NO;
  353. // [NSLayoutConstraint activateConstraints:@[
  354. // [vipLabel.topAnchor constraintEqualToAnchor:cell.contentView.topAnchor constant:4],
  355. // [vipLabel.trailingAnchor constraintEqualToAnchor:cell.contentView.trailingAnchor constant:-4]
  356. // ]];
  357. // }
  358. //
  359. // // 约束
  360. // label.translatesAutoresizingMaskIntoConstraints = NO;
  361. // [NSLayoutConstraint activateConstraints:@[
  362. // [label.centerXAnchor constraintEqualToAnchor:cell.contentView.centerXAnchor],
  363. // [label.centerYAnchor constraintEqualToAnchor:cell.contentView.centerYAnchor]
  364. // ]];
  365. return cell;
  366. }
  367. -(NSString *)getMMSSFromSS:(float)total{
  368. int fen = (int)(total / 60 ) % 60;
  369. int miao = (int)total % 60;
  370. int shi = (int)(total / 3600);
  371. NSString *format_time = [NSString stringWithFormat:@"%@%@%@",shi>0 ?[NSString stringWithFormat:@"%02d:",shi]:@"",[NSString stringWithFormat:@"%02d:",fen],[NSString stringWithFormat:@"%02d",miao]];
  372. return format_time;
  373. }
  374. #pragma mark - UICollectionViewDelegateFlowLayout
  375. - (CGSize)collectionView:(UICollectionView *)collectionView
  376. layout:(UICollectionViewLayout *)collectionViewLayout
  377. sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  378. if (collectionView == self.collectionViewNav) {
  379. return CGSizeMake(60, 31);
  380. }
  381. CGFloat width = collectionView.bounds.size.width; // 3列
  382. return CGSizeMake(width, 93);
  383. }
  384. #pragma mark - UICollectionViewDelegate
  385. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  386. if (collectionView == self.collectionViewNav) {
  387. self.selectedRange = indexPath.row;
  388. NSString *str = self.navArray[indexPath.row];
  389. NSPredicate *predicate;
  390. if (indexPath.row == self.navArray.count -1) {
  391. predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"episodeNumber >= %@ AND episodeNumber <= %ld",str,self.drama.totalEpisodes]];
  392. }else{
  393. predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"episodeNumber >= %@ AND episodeNumber <= %d",str,str.intValue+20]];
  394. }
  395. self.filteredEpisodes = [self.episodes filteredArrayUsingPredicate:predicate];
  396. [self.collectionViewNav reloadData];
  397. [self.collectionView reloadData];
  398. return ;
  399. }
  400. // if (self.filteredEpisodes.count > 0 && (self.filteredEpisodes.count >= indexPath.item)) {
  401. // JXEpisodeInfo *episode = self.filteredEpisodes[indexPath.item];
  402. //
  403. // NSLog(@"[JXCollection] 选择剧集: %ld", (long)episode.episodeNumber);
  404. //
  405. // if ([self.delegate respondsToSelector:@selector(collectionViewControllerDidSelectEpisode:)]) {
  406. // [self.delegate collectionViewControllerDidSelectEpisode:episode.episodeId];
  407. // }
  408. //
  409. // [self dismissViewControllerAnimated:YES completion:nil];
  410. // }else{
  411. // //测试一下
  412. //
  413. // if ([self.delegate respondsToSelector:@selector(collectionViewControllerDidSelectEpisode:)]) {
  414. // [self.delegate collectionViewControllerDidSelectEpisode:@"1"];
  415. // }
  416. //
  417. // [self dismissViewControllerAnimated:YES completion:nil];
  418. // }
  419. }
  420. - (NSMutableArray *)navArray{
  421. if (!_navArray) {
  422. _navArray = [NSMutableArray array];
  423. }
  424. return _navArray;
  425. }
  426. - (NSDictionary *)pageData{
  427. if (!_pageData) {
  428. _pageData = [NSDictionary dictionary];
  429. }
  430. return _pageData;
  431. }
  432. #pragma mark - 关闭
  433. - (void)handleClose {
  434. [self dismissViewControllerAnimated:YES completion:nil];
  435. }
  436. @end