topicDetailsVC.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // topicDetailsVC.m
  3. // YBVideo
  4. //
  5. // Created by IOS1 on 2019/7/4.
  6. // Copyright © 2019 cat. All rights reserved.
  7. //
  8. #import "topicDetailsVC.h"
  9. #import "topicVideoCell.h"
  10. #import "YBGetVideoObj.h"
  11. @interface topicDetailsVC ()<UICollectionViewDelegate,UICollectionViewDataSource>{
  12. int page;
  13. NSMutableArray *infoArray;
  14. }
  15. @property (nonatomic,strong) UICollectionView *topicCollectView;
  16. @end
  17. @implementation topicDetailsVC
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.view.backgroundColor = Normal_Color;
  21. infoArray = [NSMutableArray array];
  22. page = 1;
  23. [self requestData];
  24. }
  25. - (void)creatUI:(NSDictionary *)dic andNums:(NSString *)num{
  26. UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 64+statusbarHeight, _window_width, 130)];
  27. headerView.backgroundColor = Normal_Color;
  28. [self.view addSubview:headerView];
  29. UIImageView *iconImgV = [[UIImageView alloc]initWithFrame:CGRectMake(20, 20, 90, 90)];
  30. iconImgV.layer.cornerRadius = 10;
  31. iconImgV.layer.masksToBounds = YES;
  32. [iconImgV sd_setImageWithURL:[NSURL URLWithString:minstr([dic valueForKey:@"thumb"])]];
  33. [headerView addSubview:iconImgV];
  34. UIImageView *jingIngV = [[UIImageView alloc]initWithFrame:CGRectMake(iconImgV.right+15, iconImgV.top+1, 16, 16)];
  35. jingIngV.image = [UIImage imageNamed:@"video_topic"];
  36. [headerView addSubview:jingIngV];
  37. UILabel *nameL = [[UILabel alloc]initWithFrame:CGRectMake(jingIngV.right+5, iconImgV.top, headerView.width-(jingIngV.right+5)-15, 18)];
  38. nameL.text = minstr([dic valueForKey:@"name"]);
  39. nameL.textColor = [UIColor whiteColor];
  40. [headerView addSubview:nameL];
  41. UILabel *contentL = [[UILabel alloc]init];
  42. contentL.numberOfLines = 3;
  43. contentL.textColor = RGB_COLOR(@"#969696", 1);
  44. contentL.font = [UIFont systemFontOfSize:13];
  45. contentL.text = minstr([dic valueForKey:@"des"]);
  46. [headerView addSubview:contentL];
  47. [contentL mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.left.equalTo(jingIngV);
  49. make.centerY.equalTo(iconImgV);
  50. make.right.equalTo(headerView).offset(-15);
  51. }];
  52. UILabel *numL = [[UILabel alloc]initWithFrame:CGRectMake(jingIngV.left, iconImgV.bottom-13, nameL.width, 13)];
  53. numL.textColor = RGB_COLOR(@"#969696", 1);
  54. numL.font = [UIFont systemFontOfSize:10];
  55. numL.text = [NSString stringWithFormat:YZMsg(@"共%@个视频"),num];
  56. if ([lagType isEqual:EN]) {
  57. numL.text = [NSString stringWithFormat:@"Videos:%@",num];
  58. }
  59. [headerView addSubview:numL];
  60. [self.view addSubview:self.topicCollectView];
  61. }
  62. - (UICollectionView *)topicCollectView{
  63. if (!_topicCollectView) {
  64. UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
  65. flow.scrollDirection = UICollectionViewScrollDirectionVertical;
  66. flow.itemSize = CGSizeMake((_window_width-2)/3, (_window_width-2)/3 * 1.33);
  67. flow.minimumLineSpacing = 1;
  68. flow.minimumInteritemSpacing = 1;
  69. _topicCollectView = [[UICollectionView alloc]initWithFrame:CGRectMake(0,64+statusbarHeight+130, _window_width, _window_height-(64+statusbarHeight+130)) collectionViewLayout:flow];
  70. [_topicCollectView registerNib:[UINib nibWithNibName:@"topicVideoCell" bundle:nil] forCellWithReuseIdentifier:@"topicVideoCELL"];
  71. _topicCollectView.delegate =self;
  72. _topicCollectView.dataSource = self;
  73. _topicCollectView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  74. page ++;
  75. [self requestData];
  76. }];
  77. _topicCollectView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  78. page = 1;
  79. [self requestData];
  80. }];
  81. }
  82. return _topicCollectView;
  83. }
  84. - (void)requestData{
  85. [YBNetworking postWithUrl:@"Label.GetLabel" Dic:@{@"uid":[Config getOwnID],@"labelid":_labelID,@"p":@(page)} Suc:^(int code, id info, NSString *msg) {
  86. [_topicCollectView.mj_header endRefreshing];
  87. [_topicCollectView.mj_footer endRefreshing];
  88. if (code == 0) {
  89. NSDictionary *infoDic = [info firstObject];
  90. NSDictionary *uiDic = [infoDic valueForKey:@"label"];
  91. [self creatUI:uiDic andNums:minstr([infoDic valueForKey:@"count"])];
  92. NSArray *list = [infoDic valueForKey:@"list"];
  93. if (page == 1) {
  94. [infoArray removeAllObjects];
  95. }
  96. [infoArray addObjectsFromArray:list];
  97. }
  98. [_topicCollectView reloadData];
  99. } Fail:^(id fail) {
  100. [_topicCollectView.mj_header endRefreshing];
  101. [_topicCollectView.mj_footer endRefreshing];
  102. }];
  103. }
  104. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  105. return infoArray.count;
  106. }
  107. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  108. topicVideoCell *cell = (topicVideoCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"topicVideoCELL" forIndexPath:indexPath];
  109. NSDictionary *subdic = infoArray[indexPath.row];
  110. cell.model = [[NearbyVideoModel alloc] initWithDic:subdic];
  111. return cell;
  112. }
  113. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  114. NSString *vidoeID = minstr([infoArray[indexPath.row] valueForKey:@"id"]);
  115. [YBGetVideoObj lookManeger].fromWhere = @"topicDetailsVC";
  116. [YBGetVideoObj lookManeger].videoID = vidoeID;
  117. [YBGetVideoObj lookManeger].playIndex = (int)indexPath.row;
  118. [YBGetVideoObj lookManeger].videoList = [infoArray mutableCopy];
  119. [YBGetVideoObj lookManeger].paging = page;
  120. NSString *baseUrl = [NSString stringWithFormat:@"Label.GetLabel&labelid=%@",_labelID];
  121. [YBGetVideoObj lookManeger].baseUrl = baseUrl;
  122. [[YBGetVideoObj lookManeger]goLookVC];
  123. }
  124. /*
  125. #pragma mark - Navigation
  126. // In a storyboard-based application, you will often want to do a little preparation before navigation
  127. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  128. // Get the new view controller using [segue destinationViewController].
  129. // Pass the selected object to the new view controller.
  130. }
  131. */
  132. @end