JXSearchImageLogVC.m 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. //
  2. // JXSearchImageLogVC.m
  3. // shiku_im
  4. //
  5. // Created by p on 2019/4/9.
  6. // Copyright © 2019年 Reese. All rights reserved.
  7. //
  8. #import "JXSearchImageLogVC.h"
  9. #import "JXSearchImageLogCell.h"
  10. #import "JXMessageObject.h"
  11. #import "ImageBrowserViewController.h"
  12. @interface JXSearchImageLogVC ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
  13. @property (nonatomic, strong) NSArray *array;
  14. @property (nonatomic, strong) UICollectionView *collectionView;
  15. @property (nonatomic, strong) JXVideoPlayer *player;
  16. @end
  17. @implementation JXSearchImageLogVC
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. // Do any additional setup after loading the view.
  21. self.heightHeader = JX_SCREEN_TOP;
  22. self.heightFooter = 0;
  23. self.isGotoBack = YES;
  24. [self createHeadAndFoot];
  25. if (self.isImage) {
  26. self.title = Localized(@"JX_Image");
  27. }else {
  28. self.title = Localized(@"JX_Video");
  29. }
  30. _array = [NSMutableArray array];
  31. if (self.isImage) {
  32. _array = [[JXMessageObject sharedInstance] fetchAllMessageListWithUser:self.user.userId withTypes:@[[NSNumber numberWithInt:kWCMessageTypeImage]]];
  33. }else {
  34. _array = [[JXMessageObject sharedInstance] fetchAllMessageListWithUser:self.user.userId withTypes:@[[NSNumber numberWithInt:kWCMessageTypeVideo]]];
  35. }
  36. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  37. _collectionView = [[JXCollectionView alloc] initWithFrame:self.tableBody.frame collectionViewLayout:layout];
  38. _collectionView.backgroundColor = THEMEBACKCOLOR;
  39. _collectionView.alwaysBounceVertical = YES;
  40. _collectionView.delegate = self;
  41. _collectionView.dataSource = self;
  42. [_collectionView registerClass:[JXSearchImageLogCell class] forCellWithReuseIdentifier:NSStringFromClass([JXSearchImageLogCell class])];
  43. [self.view addSubview:_collectionView];
  44. }
  45. #pragma mark UICollectionView delegate
  46. #pragma mark-----多少组
  47. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  48. return 1;
  49. }
  50. #pragma mark-----多少个
  51. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  52. return _array.count;
  53. }
  54. #pragma mark-----每一个的大小
  55. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  56. {
  57. // return CGSizeMake((JX_SCREEN_WIDTH - 30)/2, (JX_SCREEN_WIDTH - 30)/2 + 50);
  58. return CGSizeMake((JX_SCREEN_WIDTH - 20) /4, (JX_SCREEN_WIDTH - 20) /4);
  59. }
  60. #pragma mark-----每一个边缘留白
  61. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
  62. return UIEdgeInsetsMake(10, 10, 0, 10);
  63. }
  64. #pragma mark-----最小行间距
  65. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  66. return 0.0;
  67. }
  68. #pragma mark-----最小竖间距
  69. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  70. return 0.0;
  71. }
  72. #pragma mark-----返回每个单元格是否可以被选择
  73. - (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath{
  74. return YES;
  75. }
  76. -(void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath{
  77. NSLog(@"didUnhighlightItemAtIndexPath");
  78. JXSearchImageLogCell *cell = (JXSearchImageLogCell *)[_collectionView cellForItemAtIndexPath:indexPath];
  79. cell.backgroundColor = [UIColor whiteColor];
  80. }
  81. -(void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath{
  82. // NSLog(@"didHighlightItemAtIndexPath");
  83. JXSearchImageLogCell *cell = (JXSearchImageLogCell *)[_collectionView cellForItemAtIndexPath:indexPath];
  84. cell.backgroundColor = [UIColor groupTableViewBackgroundColor];
  85. }
  86. -(BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath{
  87. return YES;
  88. }
  89. #pragma mark-----创建单元格
  90. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  91. JXSearchImageLogCell *cell;
  92. cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([JXSearchImageLogCell class]) forIndexPath:indexPath];
  93. cell.backgroundColor = [UIColor whiteColor];
  94. JXMessageObject *msg = _array[indexPath.row];
  95. cell.msg = msg;
  96. return cell;
  97. }
  98. #pragma mark-----点击单元格
  99. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  100. JXMessageObject *msg = _array[indexPath.row];
  101. if ([msg.type integerValue] == kWCMessageTypeVideo) {
  102. [self showVideoPlayerWithMsg:msg];
  103. }else {
  104. [self onDidImageWithMsg:msg];
  105. }
  106. }
  107. // 显示全屏视频播放
  108. - (void)showVideoPlayerWithMsg:(JXMessageObject *)msg {
  109. _player= [JXVideoPlayer alloc];
  110. _player.type = JXVideoTypeChat;
  111. _player.isShowHide = YES; //播放中点击播放器便销毁播放器
  112. _player.isStartFullScreenPlay = YES; //全屏播放
  113. _player.didVideoPlayEnd = @selector(didVideoPlayEnd);
  114. _player.delegate = self;
  115. if(msg.isMySend && isFileExist(msg.fileName))
  116. _player.videoFile = msg.fileName;
  117. else
  118. _player.videoFile = msg.content;
  119. _player = [_player initWithParent:self.view];
  120. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.2f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  121. [_player switch];
  122. });
  123. }
  124. #pragma mark-------照片查看
  125. - (void)onDidImageWithMsg:(JXMessageObject *)msg{
  126. //图片路径数组
  127. NSMutableArray *imagePathArr = [[NSMutableArray alloc]init];
  128. NSMutableArray *msgArray = [NSMutableArray array];
  129. if ([msg.isReadDel boolValue] || [msg.content rangeOfString:@".gif"].location != NSNotFound) {//是阅后即焚 gif图片
  130. [msgArray addObject:msg];
  131. [imagePathArr addObject:msg.content];
  132. }else{
  133. //获取所有聊天记录
  134. NSString* s = self.user.userId;
  135. NSArray *arr = [msg fetchImageMessageListWithUser:s];
  136. NSMutableArray *allChatImageArr = [NSMutableArray array];
  137. for(NSInteger i=[arr count]-1;i>=0;i--){
  138. [allChatImageArr addObject:[arr objectAtIndex:i]];
  139. }
  140. for (int i = 0; i < [allChatImageArr count]; i++) {
  141. JXMessageObject * msgP = [allChatImageArr objectAtIndex:i];
  142. if (![msgP.isReadDel boolValue] && [msgP.content rangeOfString:@".gif"].location == NSNotFound) {//得到的消息中含有阅后即焚 或 gif图片 的剔除掉
  143. if (msgP.content) {
  144. [msgArray addObject:msgP];
  145. [imagePathArr addObject:msgP.content];
  146. }
  147. }
  148. }
  149. }
  150. //查到当前点击的图片的位置
  151. for (int i = 0; i < [msgArray count]; i++) {
  152. JXMessageObject * msgObj = [msgArray objectAtIndex:i];
  153. if ([msg.messageId isEqualToString:msgObj.messageId]) {
  154. [ImageBrowserViewController show:self delegate:self isReadDel:[msgObj.isReadDel boolValue] type:PhotoBroswerVCTypeModal contentArray:msgArray index:i imagesBlock:^NSArray *{
  155. return imagePathArr;
  156. }];
  157. }
  158. }
  159. imagePathArr = nil;
  160. }
  161. //销毁播放器
  162. - (void)didVideoPlayEnd {
  163. }
  164. /*
  165. #pragma mark - Navigation
  166. // In a storyboard-based application, you will often want to do a little preparation before navigation
  167. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  168. // Get the new view controller using [segue destinationViewController].
  169. // Pass the selected object to the new view controller.
  170. }
  171. */
  172. @end