BogoSearchVideoSubViewController.m 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. //
  2. // MSmallVideoVC.m
  3. // BuguLive
  4. //
  5. // Created by 丁凯 on 2017/8/17.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "BogoSearchVideoSubViewController.h"
  9. #import "SSearchVC.h"
  10. #import "SmallVideoCell.h"
  11. #import "SmallVideoListModel.h"
  12. #import "BGVideoDetailController.h"
  13. #import "HMVideoPlayerViewController.h"
  14. #import "BogoVideoPlayViewController.h"
  15. #import "XRWaterfallLayout.h"
  16. #import "XRImage.h"
  17. @interface BogoSearchVideoSubViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,UIScrollViewDelegate,XRWaterfallLayoutDelegate>
  18. @property ( nonatomic,strong) XRWaterfallLayout *myCollectionLayout;
  19. @property ( nonatomic,strong) NSMutableArray *dataArray;
  20. @property ( nonatomic,assign) int currentPage;
  21. @property ( nonatomic,assign) int has_next;
  22. @property (nonatomic, strong) NSMutableArray<XRImage *> *images;
  23. @property(nonatomic, assign) NSInteger page;
  24. @end
  25. @implementation BogoSearchVideoSubViewController
  26. - (instancetype)init{
  27. if (self = [super init]) {
  28. self.keyword = @"";
  29. }
  30. return self;
  31. }
  32. -(NSMutableArray<XRImage *> *)images{
  33. if (!_images) {
  34. _images = [NSMutableArray array];
  35. }
  36. return _images;
  37. }
  38. - (void)viewDidLoad
  39. {
  40. [super viewDidLoad];
  41. }
  42. - (NSMutableArray *)dataArray
  43. {
  44. if (!_dataArray)
  45. {
  46. _dataArray = [NSMutableArray arrayWithCapacity:0];
  47. }
  48. return _dataArray;
  49. }
  50. - (void)viewWillAppear:(BOOL)animated
  51. {
  52. [super viewWillAppear:animated];
  53. if (_isHaveNavBar) {
  54. [self.navigationController setNavigationBarHidden:NO animated:NO];
  55. self.navigationController.navigationBar.hidden = NO;
  56. }
  57. // [self.navigationController setNavigationBarHidden:NO animated:NO];
  58. // [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:animated];
  59. }
  60. - (void)initFWUI
  61. {
  62. [super initFWUI];
  63. [self setupBackBtnWithBlock:nil];
  64. self.title = ASLocalizedString(@"小视频");
  65. // self.view.backgroundColor = kGreenColor;
  66. self.myCollectionLayout = [XRWaterfallLayout waterFallLayoutWithColumnCount:2];
  67. //或者一次性设置
  68. [self.myCollectionLayout setColumnSpacing:10 rowSpacing:10 sectionInset:UIEdgeInsetsMake(0, 0, FD_Bottom_SafeArea_Height, 0)];
  69. self.myCollectionLayout.delegate = self;
  70. // self.myCollectionLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  71. // self.myCollectionLayout.minimumInteritemSpacing = 5;
  72. // self.myCollectionLayout.itemSize = );
  73. self.videoCollectionV = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH-FD_Top_Height - 40) collectionViewLayout:self.myCollectionLayout];
  74. self.videoCollectionV.delegate = self;
  75. self.videoCollectionV.dataSource = self;
  76. self.videoCollectionV.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
  77. [self.videoCollectionV registerNib:[UINib nibWithNibName:@"SmallVideoCell" bundle:nil] forCellWithReuseIdentifier:@"SmallVideoCell"];
  78. [self.view addSubview:self.videoCollectionV];
  79. [self.videoCollectionV registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"foot"];
  80. [BGMJRefreshManager refresh:self.videoCollectionV target:self headerRereshAction:@selector(refreshHeader) footerRereshAction:@selector(refreshFooter)];
  81. }
  82. - (void)setKeyword:(NSString *)keyword{
  83. _keyword = keyword;
  84. [self refreshHeader];
  85. }
  86. - (void)returnCenterVC
  87. {
  88. [[AppDelegate sharedAppDelegate]popViewController];
  89. }
  90. - (void)refreshHeader
  91. {
  92. [self requestNetDataWithPage:1];
  93. }
  94. - (void)refreshFooter
  95. {
  96. if (_has_next == 1)
  97. {
  98. _currentPage ++;
  99. [self requestNetDataWithPage:_currentPage];
  100. }
  101. else
  102. {
  103. [self.videoCollectionV.mj_footer endRefreshingWithNoMoreData];
  104. }
  105. }
  106. - (void)requestNetDataWithPage:(int)Page
  107. {
  108. if (kIsCheckingVersion())
  109. {
  110. [self.dataArray removeAllObjects];
  111. [self.images removeAllObjects];
  112. [self.videoCollectionV reloadData];
  113. [BGMJRefreshManager endRefresh:self.videoCollectionV];
  114. return;
  115. }
  116. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  117. // /mapi/index.php?ctl=index&act=search_all&keyword=夏&type=0
  118. [parmDict setObject:@"index" forKey:@"ctl"];
  119. if (!self.notHaveTabbar)
  120. {
  121. [parmDict setObject:@"search_all" forKey:@"act"];
  122. }else
  123. {
  124. [parmDict setObject:@"search_all" forKey:@"act"];
  125. }
  126. [parmDict setObject:self.keyword forKey:@"keyword"];
  127. [parmDict setObject:@"2" forKey:@"type"];
  128. [parmDict setObject:[NSNumber numberWithInt:Page] forKey:@"page"];
  129. if (self.paramDict) {
  130. [parmDict setValuesForKeysWithDictionary:self.paramDict];
  131. }
  132. FWWeakify(self)
  133. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  134. FWStrongify(self)
  135. if ([responseJson toInt:@"status"] == 1)
  136. {
  137. if (Page == 1)
  138. {
  139. [self.dataArray removeAllObjects];
  140. [self.images removeAllObjects];
  141. }
  142. _has_next = [responseJson toInt:@"has_next"];
  143. _currentPage = [responseJson toInt:@"page"];
  144. NSArray *list = responseJson[@"weibo"];
  145. for ( NSDictionary *dict in list)
  146. {
  147. SmallVideoListModel *model = [SmallVideoListModel mj_objectWithKeyValues:dict];
  148. XRImage *image = [XRImage new];
  149. image.imageURL = [NSURL URLWithString:model.photo_image];
  150. [self.images addObject:image];
  151. [self.dataArray addObject:model];
  152. }
  153. [self.videoCollectionV reloadData];
  154. }
  155. [BGMJRefreshManager endRefresh:self.videoCollectionV];
  156. if (!self.dataArray.count)
  157. {
  158. [self showNoContentView];
  159. }
  160. else
  161. {
  162. [self hideNoContentView];
  163. }
  164. } FailureBlock:^(NSError *error) {
  165. FWStrongify(self)
  166. [BGMJRefreshManager endRefresh:self.videoCollectionV];
  167. }];
  168. }
  169. #pragma mark collectionView delegate
  170. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  171. {
  172. return self.dataArray.count;
  173. }
  174. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  175. {
  176. SmallVideoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SmallVideoCell" forIndexPath:indexPath];
  177. SmallVideoListModel *model = self.dataArray[indexPath.row];
  178. [cell creatCellWithModel:model andRow:(int)indexPath.row];
  179. return cell;
  180. }
  181. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  182. {
  183. if (indexPath.row < self.dataArray.count)
  184. {
  185. // SmallVideoListModel *model = _dataArray[indexPath.row];
  186. // BGVideoDetailController *VideoVC = [[BGVideoDetailController alloc]init];
  187. // VideoVC.weibo_id = model.weibo_id;
  188. // [[AppDelegate sharedAppDelegate] pushViewController:VideoVC];
  189. // BogoVideoPlayViewController *vc = [[BogoVideoPlayViewController alloc]initWithModelArr:_dataArray];
  190. HMVideoPlayerViewController *vc = [[HMVideoPlayerViewController alloc]initWithVideos:_dataArray index:indexPath.item IsPushed:YES requestDict:nil];
  191. WeakSelf
  192. vc.isRefreshVideoBlock = ^(BOOL isRefresh) {
  193. [weakSelf refreshHeader];
  194. };
  195. [[AppDelegate sharedAppDelegate] pushViewController:vc animated:YES];
  196. }
  197. }
  198. ////每个item之间的横间距
  199. //- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  200. //
  201. // return 10;
  202. //}
  203. ////每个item之间的纵间距
  204. // - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  205. //{
  206. // if (section == 0 || section % 3 == 0) {
  207. // return 10;
  208. // }
  209. // return 0;
  210. //}
  211. //
  212. //- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  213. //{
  214. // if (section == 1) {
  215. // return UIEdgeInsetsMake(0, 10, 0, 10);
  216. // }
  217. // return UIEdgeInsetsMake(-10, 10, 0, 10);
  218. //}
  219. //根据item的宽度与indexPath计算每一个item的高度
  220. - (CGFloat)waterfallLayout:(XRWaterfallLayout *)waterfallLayout itemHeightForWidth:(CGFloat)itemWidth atIndexPath:(NSIndexPath *)indexPath {
  221. //根据图片的原始尺寸,及显示宽度,等比例缩放来计算显示高度
  222. XRImage *image = self.images[indexPath.item];
  223. if (indexPath.row % 2 == 0) {
  224. return (kScreenW-30)/2.0f * 1.8;
  225. }
  226. return (kScreenW-30)/2.0f * 1.4;
  227. // image.imageH / image.imageW * itemWidth;
  228. }
  229. //-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  230. //
  231. // if (indexPath.row == 1) {
  232. // return CGSizeMake((kScreenW-30)/2.0f,(kScreenW-30)/2.0f * 1.5);
  233. // }
  234. //
  235. // return CGSizeMake((kScreenW-30)/2.0f,(kScreenW-30)/2.0f * 1.2);
  236. //}
  237. #pragma mark - ----------------------- scrollViewDelegate -----------------------
  238. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  239. {
  240. }
  241. @end