MovieListViewController.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // MovieListViewController.m
  3. // LenzCameraNativeModuleForRN
  4. //
  5. // Created by 王昭威 on 2023/1/23.
  6. //
  7. #import "MovieListViewController.h"
  8. #import "OperationNodeMovie.h"
  9. #import "PhotoListCellModel.h"
  10. #import "CollectionViewPlayerCell.h"
  11. #import "MoviePlayerViewController.h"
  12. #import "MovieListCellModel.h"
  13. #import "QuitMultipleModeAlertViewController.h"
  14. @interface MovieListViewController ()
  15. @property (nonatomic, weak) CollectionViewPlayerCell* currentCell;
  16. @end
  17. @implementation MovieListViewController
  18. - (void)setMovieModels:(NSArray<__kindof RecordedMovieModel *> *)movieModels{
  19. _movieModels = movieModels;
  20. NSMutableArray<__kindof PhotoListCellModel*>* cellModels = [[NSMutableArray alloc] initWithCapacity:MAX(self.movieModels.count, 1)];
  21. [self.movieModels enumerateObjectsUsingBlock:^(__kindof RecordedMovieModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  22. MovieListCellModel* model = [[MovieListCellModel alloc] init];
  23. model.movieModel = obj;
  24. [cellModels addObject: model];
  25. }];
  26. self.cellModels = cellModels;
  27. }
  28. - (void)viewWillDisappear:(BOOL)animated{
  29. [super viewWillDisappear:animated];
  30. [self.currentCell stop];
  31. }
  32. + (instancetype)movieMakeViewController{
  33. UIStoryboard* sb = [UIStoryboard storyboardWithName:[PCSTools shared].mainStoryboardName bundle:[PCSTools sdkBundle]];
  34. return [sb instantiateViewControllerWithIdentifier:@"MovieListVC"];
  35. }
  36. - (void)viewDidLoad {
  37. [super viewDidLoad];
  38. // Do any additional setup after loading the view.
  39. }
  40. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
  41. [self.currentCell stop];
  42. self.currentCell = nil;
  43. }
  44. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
  45. NSInteger currentPage = self.currentPageIndex;
  46. [[NSNotificationCenter defaultCenter]postNotificationName:@"changeNum" object:[NSString stringWithFormat:@"%ld",(long)currentPage]];
  47. // [self.photoListVC updatePageIndexLabelWithCurrentIndex:currentPage];
  48. }
  49. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  50. UICollectionViewCell* cell = [self.photoCollectionView cellForItemAtIndexPath:indexPath];
  51. if(cell != nil && [cell isKindOfClass:[CollectionViewPlayerCell class]]){
  52. CollectionViewPlayerCell* playerCell = (CollectionViewPlayerCell*)cell;
  53. if(self.currentCell == playerCell){
  54. [self.currentCell stop];
  55. self.currentCell = nil;
  56. }
  57. else{
  58. if(self.currentCell.playerController.player.currentItem != nil){
  59. [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:self.currentCell.playerController.player.currentItem];
  60. }
  61. [self.currentCell stop];
  62. self.currentCell = playerCell;
  63. AVPlayer* player = [playerCell play];
  64. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerDidEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:player.currentItem];
  65. }
  66. }
  67. }
  68. - (void)playerDidEnd: (NSNotification*)noti{
  69. [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:self.currentCell.playerController.player.currentItem];
  70. self.currentCell.playIconView.hidden = NO;
  71. self.currentCell = nil;
  72. }
  73. - (void)backButtonTouchUpInside:(id)sender{
  74. [self.currentCell stop];
  75. dispatch_async(dispatch_get_main_queue(), ^{
  76. [super backButtonTouchUpInside:sender];
  77. });
  78. }
  79. - (void)deleteButtonTouchUpInside:(id)sender{
  80. NSInteger currPageIdx = MAX(self.currentPageIndex, 0);
  81. [QuitMultipleModeAlertViewController show:self title:nil text:LOCALIZATION_STRING_KEY_DELETE_IMAGE_ALERT_TEXT leftBtnTitle:LOCALIZATION_STRING_KEY_DELETE_ALERT_BTN_TITLE_CANCEL rightBtnTitle:LOCALIZATION_STRING_KEY_DELETE_ALERT_BTN_TITLE_CONFIRM withLeftButtonCallBack:^(QuitMultipleModeAlertViewController * _Nonnull alertController) {
  82. [alertController dismissViewControllerAnimated:NO completion:^{}];
  83. } rightButtonCallBack:^(QuitMultipleModeAlertViewController * _Nonnull alertController) {
  84. if(self.cellModels.count > currPageIdx){
  85. MovieListCellModel* cellModel = self.cellModels[currPageIdx];
  86. if(cellModel.movieModel != nil){
  87. [self.delegate deleteMovie:cellModel completion:^(BOOL successful) {
  88. if(successful){
  89. dispatch_async(dispatch_get_main_queue(), ^{
  90. [self deletedCachedResourceSuccessfulAtIndex:currPageIdx];
  91. });
  92. }
  93. }];
  94. }
  95. }
  96. }];
  97. }
  98. - (void)dealloc{
  99. [[NSNotificationCenter defaultCenter] removeObserver:self];
  100. }
  101. /*
  102. #pragma mark - Navigation
  103. // In a storyboard-based application, you will often want to do a little preparation before navigation
  104. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  105. // Get the new view controller using [segue destinationViewController].
  106. // Pass the selected object to the new view controller.
  107. }
  108. */
  109. @end