BogoYoungModeVideoViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. //
  2. // BogoYoungModeVideoViewController.m
  3. // BuguLive
  4. //
  5. // Created by 丁凯 on 2017/8/17.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "BogoYoungModeVideoViewController.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. #import "BogoYouthModePassWordViewController.h"
  18. #import <MBProgressHUD/MBProgressHUD.h>
  19. @interface BogoYoungModeVideoViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,UIScrollViewDelegate,XRWaterfallLayoutDelegate>
  20. @property ( nonatomic,strong) XRWaterfallLayout *myCollectionLayout;
  21. @property ( nonatomic,strong) NSMutableArray *dataArray;
  22. @property ( nonatomic,assign) int currentPage;
  23. @property ( nonatomic,assign) int has_next;
  24. @property (nonatomic, strong) NSMutableArray<XRImage *> *images;
  25. @property(nonatomic, strong) MBProgressHUD *hud;
  26. @property(nonatomic, strong) UIView *tipView;
  27. @end
  28. @implementation BogoYoungModeVideoViewController
  29. -(NSMutableArray<XRImage *> *)images{
  30. if (!_images) {
  31. _images = [NSMutableArray array];
  32. }
  33. return _images;
  34. }
  35. - (void)viewDidLoad
  36. {
  37. [super viewDidLoad];
  38. }
  39. - (NSMutableArray *)dataArray
  40. {
  41. if (!_dataArray)
  42. {
  43. _dataArray = [NSMutableArray arrayWithCapacity:0];
  44. }
  45. return _dataArray;
  46. }
  47. - (void)viewWillAppear:(BOOL)animated
  48. {
  49. [super viewWillAppear:animated];
  50. if (_isHaveNavBar) {
  51. [self.navigationController setNavigationBarHidden:NO animated:NO];
  52. self.navigationController.navigationBar.hidden = NO;
  53. }
  54. // [self.navigationController setNavigationBarHidden:NO animated:NO];
  55. // [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:animated];
  56. }
  57. - (void)initFWUI
  58. {
  59. [super initFWUI];
  60. // [self setupBackBtnWithBlock:nil];
  61. [self.navigationItem setHidesBackButton:YES animated:YES];
  62.  self.navigationItem.leftBarButtonItem = nil;
  63. UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  64. [backBtn setTitle:ASLocalizedString(@"退出") forState:UIControlStateNormal];
  65. [backBtn setTitleColor:[UIColor colorWithHexString:@"#9152F8"] forState:UIControlStateNormal];
  66. backBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  67. [backBtn addTarget:self action:@selector(clickBackBtn:) forControlEvents:UIControlEventTouchUpInside];
  68. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
  69. self.navigationItem.title = ASLocalizedString(@"青少年模式");
  70. // self.view.backgroundColor = kGreenColor;
  71. self.myCollectionLayout = [XRWaterfallLayout waterFallLayoutWithColumnCount:2];
  72. //或者一次性设置
  73. [self.myCollectionLayout setColumnSpacing:10 rowSpacing:10 sectionInset:UIEdgeInsetsMake(10, 10, 10, 10)];
  74. self.myCollectionLayout.delegate = self;
  75. self.videoCollectionV = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH-kTopHeight) collectionViewLayout:self.myCollectionLayout];
  76. self.videoCollectionV.contentInset = UIEdgeInsetsMake(0, 0, MG_BOTTOM_MARGIN, 0);
  77. self.videoCollectionV.delegate = self;
  78. self.videoCollectionV.dataSource = self;
  79. self.videoCollectionV.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
  80. [self.videoCollectionV registerNib:[UINib nibWithNibName:@"SmallVideoCell" bundle:nil] forCellWithReuseIdentifier:@"SmallVideoCell"];
  81. [self.view addSubview:self.videoCollectionV];
  82. [self.videoCollectionV registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"foot"];
  83. [BGMJRefreshManager refresh:self.videoCollectionV target:self headerRereshAction:@selector(refreshHeader) footerRereshAction:@selector(refreshFooter)];
  84. // [[FDHUDManager defaultManager]show:ASLocalizedString(@"您已开启青少年模式") ToView:self.view];
  85. [self.view addSubview:self.tipView];
  86. [UIView animateWithDuration:0.25 animations:^{
  87. self.tipView.alpha = 1;
  88. }];
  89. [self performSelector:@selector(hideTipView) afterDelay:3];
  90. }
  91. - (void)hideTipView{
  92. [UIView animateWithDuration:0.25 animations:^{
  93. self.tipView.alpha = 0;
  94. } completion:^(BOOL finished) {
  95. [self.tipView removeFromSuperview];
  96. }];
  97. }
  98. -(void)clickBackBtn:(UIButton *)sender{
  99. // BogoYoungModeBlindPhoneVC *vc = [[BogoYoungModeBlindPhoneVC alloc]init];
  100. // [self.navigationController pushViewController:vc animated:YES];
  101. BogoYouthModePassWordViewController *vc = [[BogoYouthModePassWordViewController alloc]initWithYounthType:BOGO_YOUNTH_TYPE_PASSWORD_CLOSE];
  102. [self.navigationController pushViewController:vc animated:YES];
  103. }
  104. - (void)returnCenterVC
  105. {
  106. [[AppDelegate sharedAppDelegate]popViewController];
  107. }
  108. - (void)refreshHeader
  109. {
  110. [self requestNetDataWithPage:1];
  111. }
  112. - (void)refreshFooter
  113. {
  114. if (_has_next == 1)
  115. {
  116. _currentPage ++;
  117. [self requestNetDataWithPage:_currentPage];
  118. }
  119. else
  120. {
  121. [self.videoCollectionV.mj_footer endRefreshingWithNoMoreData];
  122. }
  123. }
  124. - (void)requestNetDataWithPage:(int)Page
  125. {
  126. if (kIsCheckingVersion())
  127. {
  128. [self.dataArray removeAllObjects];
  129. [self.images removeAllObjects];
  130. [self.videoCollectionV reloadData];
  131. [BGMJRefreshManager endRefresh:self.videoCollectionV];
  132. return;
  133. }
  134. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  135. [parmDict setObject:@"svideo" forKey:@"ctl"];
  136. if (!self.notHaveTabbar)
  137. {
  138. [parmDict setObject:@"index" forKey:@"act"];
  139. }else
  140. {
  141. [parmDict setObject:@"video" forKey:@"act"];
  142. }
  143. [parmDict setObject:[NSNumber numberWithInt:Page] forKey:@"page"];
  144. if (self.paramDict) {
  145. [parmDict setValuesForKeysWithDictionary:self.paramDict];
  146. }
  147. FWWeakify(self)
  148. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  149. FWStrongify(self)
  150. if ([responseJson toInt:@"status"] == 1)
  151. {
  152. if (Page == 1)
  153. {
  154. [self.dataArray removeAllObjects];
  155. [self.images removeAllObjects];
  156. }
  157. _has_next = [responseJson toInt:@"has_next"];
  158. _currentPage = [responseJson toInt:@"page"];
  159. NSArray *list = responseJson[@"data"];
  160. for ( NSDictionary *dict in list)
  161. {
  162. SmallVideoListModel *model = [SmallVideoListModel mj_objectWithKeyValues:dict];
  163. XRImage *image = [XRImage new];
  164. image.imageURL = [NSURL URLWithString:model.photo_image];
  165. [self.images addObject:image];
  166. [self.dataArray addObject:model];
  167. }
  168. [self.videoCollectionV reloadData];
  169. }
  170. [BGMJRefreshManager endRefresh:self.videoCollectionV];
  171. if (!self.dataArray.count)
  172. {
  173. [self showNoContentView];
  174. }
  175. else
  176. {
  177. [self hideNoContentView];
  178. }
  179. } FailureBlock:^(NSError *error) {
  180. FWStrongify(self)
  181. [BGMJRefreshManager endRefresh:self.videoCollectionV];
  182. }];
  183. }
  184. #pragma mark collectionView delegate
  185. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  186. {
  187. return self.dataArray.count;
  188. }
  189. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  190. {
  191. SmallVideoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SmallVideoCell" forIndexPath:indexPath];
  192. SmallVideoListModel *model = self.dataArray[indexPath.row];
  193. [cell creatCellWithModel:model andRow:(int)indexPath.row];
  194. return cell;
  195. }
  196. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  197. {
  198. if (indexPath.row < self.dataArray.count)
  199. {
  200. // SmallVideoListModel *model = _dataArray[indexPath.row];
  201. // BGVideoDetailController *VideoVC = [[BGVideoDetailController alloc]init];
  202. // VideoVC.weibo_id = model.weibo_id;
  203. // [[AppDelegate sharedAppDelegate] pushViewController:VideoVC];
  204. // BogoVideoPlayViewController *vc = [[BogoVideoPlayViewController alloc]initWithModelArr:_dataArray];
  205. HMVideoPlayerViewController *vc = [[HMVideoPlayerViewController alloc]initWithVideos:_dataArray index:indexPath.item IsPushed:YES requestDict:nil];
  206. WeakSelf
  207. vc.isRefreshVideoBlock = ^(BOOL isRefresh) {
  208. [weakSelf refreshHeader];
  209. };
  210. // vc.videoView.hidden = YES;
  211. [[AppDelegate sharedAppDelegate] pushViewController:vc animated:YES];
  212. }
  213. }
  214. ////每个item之间的横间距
  215. //- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  216. //
  217. // return 10;
  218. //}
  219. ////每个item之间的纵间距
  220. // - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  221. //{
  222. // if (section == 0 || section % 3 == 0) {
  223. // return 10;
  224. // }
  225. // return 0;
  226. //}
  227. //
  228. //- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  229. //{
  230. // if (section == 1) {
  231. // return UIEdgeInsetsMake(0, 10, 0, 10);
  232. // }
  233. // return UIEdgeInsetsMake(-10, 10, 0, 10);
  234. //}
  235. //根据item的宽度与indexPath计算每一个item的高度
  236. - (CGFloat)waterfallLayout:(XRWaterfallLayout *)waterfallLayout itemHeightForWidth:(CGFloat)itemWidth atIndexPath:(NSIndexPath *)indexPath {
  237. //根据图片的原始尺寸,及显示宽度,等比例缩放来计算显示高度
  238. XRImage *image = self.images[indexPath.item];
  239. // if (indexPath.row % 2 == 0) {
  240. return (kScreenW-30)/2.0f * 1.8;
  241. // }
  242. // return (kScreenW-30)/2.0f * 1.4;
  243. }
  244. //-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  245. //
  246. // if (indexPath.row == 1) {
  247. // return CGSizeMake((kScreenW-30)/2.0f,(kScreenW-30)/2.0f * 1.5);
  248. // }
  249. //
  250. // return CGSizeMake((kScreenW-30)/2.0f,(kScreenW-30)/2.0f * 1.2);
  251. //}
  252. #pragma mark - ----------------------- scrollViewDelegate -----------------------
  253. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  254. {
  255. }
  256. - (UIView *)tipView{
  257. if (!_tipView) {
  258. _tipView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 180, 40)];
  259. _tipView.backgroundColor = [FD_BlackColor colorWithAlphaComponent:0.4];
  260. _tipView.layer.cornerRadius = 20;
  261. _tipView.clipsToBounds = YES;
  262. UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 140, 20)];
  263. titleLabel.textColor = FD_WhiteColor;
  264. titleLabel.center = _tipView.center;
  265. titleLabel.text = ASLocalizedString(@"您已开启青少年模式");
  266. titleLabel.font = [UIFont systemFontOfSize:14];
  267. titleLabel.textAlignment = NSTextAlignmentCenter;
  268. [_tipView addSubview:titleLabel];
  269. _tipView.center = self.view.center;
  270. _tipView.alpha = 0;
  271. }
  272. return _tipView;
  273. }
  274. @end