YHTimeLineListController.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. //
  2. // YHQAListController.m
  3. // github: https://github.com/samuelandkevin
  4. //
  5. // Created by samuelandkevin on 16/8/29.
  6. // Copyright © 2016年 HKP. All rights reserved.
  7. //
  8. #import "YHTimeLineListController.h"
  9. #import "CellForWorkGroup.h"
  10. #import "CellForWorkGroupRepost.h"
  11. #import "YHRefreshTableView.h"
  12. #import "YHWorkGroup.h"
  13. #import "YHUserInfoManager.h"
  14. //#import "YHUtils.h"
  15. #import "YHSharePresentView.h"
  16. #import "UITableViewCell+HYBMasonryAutoCellHeight.h"
  17. //#import "XWPublishController.h"
  18. #import "DetailsLineViewController.h"
  19. #import <CLPlayer/CLPlayerView.h>
  20. #import "YHPlayerViewController.h"
  21. #import "ReleaseDynamicVC.h"
  22. #import "BGTopicTimeLineListController.h"
  23. #import "MGNewDTNearByViewController.h"//附近的人
  24. @interface YHTimeLineListController ()<UITableViewDelegate,UITableViewDataSource,CellForWorkGroupDelegate,CellForWorkGroupRepostDelegate,BzoneLogicDelegate>{
  25. int _currentRequestPage; //当前请求页面
  26. BOOL _reCalculate;
  27. }
  28. //@property (nonatomic,strong) UITableView *tableView;
  29. @property (nonatomic, strong) UIButton *rightBtn;
  30. @property (nonatomic,strong) NSMutableArray *dataArray;
  31. @property (nonatomic,strong) NSMutableDictionary *heightDict;
  32. @property (nonatomic, strong) BzoneLogic *logic;
  33. @property (nonatomic, strong) CellForWorkGroup *c_cell;
  34. @property (nonatomic, strong) CLPlayerView *playerView;
  35. @property(nonatomic, assign) CGFloat scrollOffset;
  36. @property(nonatomic, strong) UIView *tableHeadView;
  37. @end
  38. @implementation YHTimeLineListController
  39. -(instancetype)initWithIndexAct:(MGDTHOMETYPE)act withUID:(NSString *)toUid{
  40. YHTimeLineListController *vc = [YHTimeLineListController new];
  41. vc.homeType = act;
  42. vc.toUid = toUid;
  43. return vc;
  44. }
  45. - (void)viewDidLoad{
  46. [super viewDidLoad];
  47. [self initUI];
  48. self.logic = [BzoneLogic new];
  49. self.logic.page = 1;
  50. _logic.delegagte = self;
  51. _logic.to_uid = self.toUid;
  52. _logic.isGZ = YES;
  53. // [self requestDataLoadNew:YES];
  54. //设置UserId
  55. [YHUserInfoManager sharedInstance].userInfo.uid = @"1";
  56. }
  57. - (void)initUI{
  58. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH - kTabBarHeight - 64 - 49) style:UITableViewStylePlain];
  59. self.tableView.tag = 1107;
  60. if (isIPhoneX()) {
  61. self.tableView.height = kScreenH - 49 - 64 - 20;
  62. }
  63. if (@available(iOS 15.0, *)) {
  64. _tableView.sectionHeaderTopPadding = 0;
  65. }
  66. NSLog(@"%f",kTabBarHeight);
  67. NSLog(@"%f",kNavigationBarHeight);
  68. self.tableView.delegate = self;
  69. self.tableView.dataSource = self;
  70. self.tableView.backgroundColor = RGBCOLOR(244, 244, 244);
  71. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  72. [self.view addSubview:self.tableView];
  73. // [self.tableView setEnableLoadNew:YES];
  74. // [self.tableView setEnableLoadMore:YES];
  75. self.view.backgroundColor = UIColor.clearColor;
  76. [self.tableView registerClass:[CellForWorkGroup class] forCellReuseIdentifier:NSStringFromClass([CellForWorkGroup class])];
  77. [self.tableView registerClass:[CellForWorkGroupRepost class] forCellReuseIdentifier:NSStringFromClass([CellForWorkGroupRepost class])];
  78. self.rightBtn = [[UIButton alloc] init];
  79. self.rightBtn.frame = CGRectMake(kScreenW - 50 - 15, kScreenH - kNavigationBarHeight - kTabBarHeight - 50 - 25, 50, 50);
  80. // search.imageEdgeInsets = UIEdgeInsetsMake(6, 6, 6, 6);
  81. [self.rightBtn setImage:[UIImage imageNamed:@"mg_dy_publish"] forState:UIControlStateNormal];
  82. [self.rightBtn addTarget:self action:@selector(handleSearchEvent) forControlEvents:UIControlEventTouchUpInside];
  83. [BGMJRefreshManager refresh:self.tableView target:self headerRereshAction:@selector(refreshHeader) footerRereshAction:@selector(refreshFooter)];
  84. [self.view addSubview:self.rightBtn];
  85. }
  86. -(void)refreshHeader{
  87. [self resetHeadView];
  88. [self requestDataLoadNew:YES];
  89. }
  90. -(void)refreshFooter{
  91. [self requestDataLoadNew:NO];
  92. }
  93. - (void)viewWillAppear:(BOOL)animated {
  94. [super viewWillAppear:animated];
  95. [self requestDataLoadNew:YES];
  96. // [self.logic loadListDataWithAct:self.homeType];
  97. }
  98. - (void)viewWillDisappear:(BOOL)animated {
  99. [super viewWillDisappear:animated];
  100. [_playerView destroyPlayer];
  101. _c_cell =nil;
  102. }
  103. -(void)reloadDynamicData{
  104. BzoneLogic *logic = [BzoneLogic new];
  105. logic.delegagte = self;
  106. [logic loadListDataWithAct:self.homeType];
  107. }
  108. //发布动态
  109. - (void)handleSearchEvent
  110. {
  111. // XWPublishController *pushVC = [XWPublishController new];
  112. ReleaseDynamicVC *pushVC = [ReleaseDynamicVC new];
  113. __weak __typeof(self)weakSelf = self;
  114. pushVC.postFinishBlock = ^(BOOL isFinish) {
  115. if (isFinish) {
  116. if (weakSelf.timeLineDelegate && [weakSelf.timeLineDelegate respondsToSelector:@selector(reloadDynamicData)]) {
  117. [weakSelf.timeLineDelegate reloadDynamicData];
  118. }
  119. // [weakSelf.logic loadListDataWithAct:self.homeType];
  120. }
  121. };
  122. [[AppDelegate sharedAppDelegate]presentViewController:pushVC animated:YES completion:nil];
  123. // [self presentViewController:pushVC animated:YES completion:nil];
  124. }
  125. #pragma mark - Lazy Load
  126. - (NSMutableArray *)dataArray{
  127. if (!_dataArray) {
  128. _dataArray = [NSMutableArray array];
  129. }
  130. return _dataArray;
  131. }
  132. - (NSMutableDictionary *)heightDict{
  133. if (!_heightDict) {
  134. _heightDict = [NSMutableDictionary new];
  135. }
  136. return _heightDict;
  137. }
  138. #pragma mark - UITableViewDataSource
  139. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  140. return self.dataArray.count;
  141. }
  142. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  143. return self.tableHeadView;
  144. }
  145. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  146. return _homeType == MGDTHOMETYPE_NEARBY ? kRealValue(80) :0;
  147. }
  148. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  149. if (self.dataArray.count < 1) {
  150. return [UITableViewCell new];
  151. }
  152. MGGroupUserInfo *model = self.dataArray[indexPath.row];
  153. //原创cell
  154. CellForWorkGroup *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([CellForWorkGroup class])];
  155. if (!cell) {
  156. cell = [[CellForWorkGroup alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([CellForWorkGroup class])];
  157. }
  158. cell.homeType = self.homeType;
  159. cell.indexPath = indexPath;
  160. cell.model = model;
  161. cell.delegate = self;
  162. return cell;
  163. }
  164. #pragma mark - UITableViewDelegate
  165. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  166. if (indexPath.row < self.dataArray.count) {
  167. CGFloat height = 0.0;
  168. //原创cell
  169. Class currentClass = [CellForWorkGroup class];
  170. MGGroupUserInfo *model = self.dataArray[indexPath.row];
  171. //取缓存高度
  172. NSDictionary *dict = self.heightDict[model.id];
  173. if (dict) {
  174. if (model.isOpening) {
  175. height = [dict[@"open"] floatValue];
  176. }else{
  177. height = [dict[@"normal"] floatValue];
  178. }
  179. if (height) {
  180. return height;
  181. }
  182. }
  183. height = [CellForWorkGroup hyb_heightForTableView:tableView config:^(UITableViewCell *sourceCell) {
  184. CellForWorkGroup *cell = (CellForWorkGroup *)sourceCell;
  185. cell.model = model;
  186. }];
  187. if (model.cover_url && ![model.cover_url isEqualToString:@""])
  188. {
  189. // height += 74;
  190. }
  191. // }
  192. //缓存高度
  193. if (model.id) {
  194. NSMutableDictionary *aDict = [NSMutableDictionary new];
  195. if (model.isOpening) {
  196. [aDict setObject:@(height) forKey:@"open"];
  197. }else{
  198. [aDict setObject:@(height) forKey:@"normal"];
  199. }
  200. [self.heightDict setObject:aDict forKey:model.id];
  201. }
  202. return height;
  203. }
  204. else{
  205. return 44.0f;
  206. }
  207. }
  208. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  209. self.hidesBottomBarWhenPushed = YES;
  210. if (self.dataArray.count > 0) {
  211. MGGroupUserInfo *model = self.dataArray[indexPath.row];
  212. DetailsLineViewController *datails = [DetailsLineViewController new];
  213. datails.title = ASLocalizedString(@"动态详情");
  214. datails.model = model;
  215. datails.refreshData = ^{
  216. [self refreshHeader];
  217. };
  218. [[AppDelegate sharedAppDelegate] pushViewController:datails animated:YES];
  219. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  220. [AppDelegate sharedAppDelegate].topViewController.hidesBottomBarWhenPushed = YES;
  221. }
  222. }
  223. -(void)tableView:(UITableView *)tableView willDisplayCell:(CellForWorkGroup *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
  224. if (self.dataArray.count < 1) {
  225. return;
  226. }
  227. MGGroupUserInfo *model = self.dataArray[indexPath.row];
  228. if (model.cover_url && ![model.cover_url isEqualToString:@""] && indexPath.row == 0){
  229. //原创cell
  230. [self onTouchActionVideo:cell withFullScreen:NO];
  231. }
  232. }
  233. - (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  234. {
  235. }
  236. -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
  237. if (self.dataArray.count > 0) {
  238. NSArray *cellArr = self.tableView.visibleCells;
  239. CellForWorkGroup *cell;
  240. if (self.scrollOffset - scrollView.contentOffset.y > 0) {
  241. cell = cellArr.firstObject;
  242. }else{
  243. cell = cellArr.lastObject;
  244. }
  245. if (cellArr.count == 3) {//当可见视图有三个cell时,展示中间那个。
  246. cell = [cellArr objectAtIndex:1];
  247. }
  248. self.scrollOffset = scrollView.contentOffset.y;
  249. if (self.scrollOffset == 0) cell = cellArr.firstObject;//下拉刷新时展示第一个
  250. if (_c_cell != cell) {
  251. _c_cell = cell;
  252. [self onTouchActionVideo:cell withFullScreen:NO];
  253. }
  254. }
  255. // MGGroupUserInfo *model = self.dataArray[indexPath.row];
  256. if (self.vDelegate && [self.vDelegate respondsToSelector:@selector(didDynamicCollectionViewScrollView:)]) {
  257. [self.vDelegate didDynamicCollectionViewScrollView:scrollView];
  258. return;
  259. }
  260. CGFloat sectionHeaderHeight = self.tableHeadView.height + kTopHeight;
  261. if(scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
  262. scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
  263. } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
  264. scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
  265. }
  266. if(self.timeLineDelegate && [self.timeLineDelegate respondsToSelector:@selector(protocolTimeLineDidScrollView:offset:)])
  267. {
  268. [self.timeLineDelegate protocolTimeLineDidScrollView:scrollView offset:scrollView.contentOffset.y];
  269. }
  270. }
  271. #pragma mark - 网络请求
  272. - (void)requestDataLoadNew:(BOOL)loadNew{
  273. YHRefreshType refreshType;
  274. if (loadNew) {
  275. _currentRequestPage = 1;
  276. refreshType = YHRefreshType_LoadNew;
  277. }
  278. else{
  279. _currentRequestPage ++;
  280. refreshType = YHRefreshType_LoadMore;
  281. }
  282. if (loadNew) {
  283. [self.dataArray removeAllObjects];
  284. [self.heightDict removeAllObjects];
  285. }
  286. _logic.page = _currentRequestPage;
  287. int totalCount = 10;
  288. NSUInteger lastDynamicID = 0;
  289. if (!loadNew && self.dataArray.count) {
  290. MGGroupUserInfo *model = self.dataArray.lastObject;
  291. lastDynamicID = [model.id integerValue];
  292. }
  293. [_logic loadListDataWithAct:self.homeType];
  294. // [BGMJRefreshManager endRefresh:self.tableView];
  295. // [self.tableView reloadData];
  296. }
  297. -(void)requestZoneListDataCompleted
  298. {
  299. [self.tableView.mj_footer endRefreshing];
  300. [self.tableView.mj_header endRefreshing];
  301. self.dataArray = _logic.dataArray;
  302. if(_logic.noHasMore == YES)
  303. {
  304. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  305. }
  306. if (self.dataArray.count < 1)
  307. {
  308. [self showNoContentView];
  309. self.noContentView.top = kRealValue(120);
  310. }else
  311. {
  312. [self hideNoContentView];
  313. }
  314. if (kIsCheckingVersion())
  315. {
  316. [self.dataArray removeAllObjects];
  317. }
  318. [self.tableView reloadData];
  319. // [BGMJRefreshManager endRefresh:self.tableView];
  320. }
  321. #pragma mark - 模拟产生数据源
  322. - (void)randomModel:(MGGroupUserInfo *)model totalCount:(int)totalCount{
  323. model.type = arc4random()%totalCount %2? DynType_Forward:DynType_Original;//动态类型
  324. if (model.type == DynType_Forward) {
  325. model.forwardModel = [MGGroupUserInfo new];
  326. [self creatOriModel:model.forwardModel totalCount:totalCount];
  327. }
  328. [self creatOriModel:model totalCount:totalCount];
  329. }
  330. - (void)creatOriModel:(MGGroupUserInfo *)model totalCount:(int)totalCount{
  331. }
  332. #pragma mark - YHRefreshTableViewDelegate
  333. - (void)refreshTableViewLoadNew:(YHRefreshTableView*)view{
  334. // [self requestDataLoadNew:YES];
  335. }
  336. - (void)refreshTableViewLoadmore:(YHRefreshTableView*)view{
  337. // [self requestDataLoadNew:NO];
  338. }
  339. #pragma mark - CellForWorkGroupDelegate
  340. - (void)onAvatarInCell:(CellForWorkGroup *)cell{
  341. SHomePageVC *tmpController= [[SHomePageVC alloc]init];
  342. tmpController.user_id = cell.model.uid;
  343. tmpController.type = 0;
  344. [[AppDelegate sharedAppDelegate]pushViewController:tmpController animated:YES];
  345. }
  346. - (void)onMoreInCell:(CellForWorkGroup *)cell{
  347. if (cell.indexPath.row < [self.dataArray count]) {
  348. YHWorkGroup *model = self.dataArray[cell.indexPath.row];
  349. model.isOpening = !model.isOpening;
  350. [self.tableView reloadRowsAtIndexPaths:@[cell.indexPath] withRowAnimation:UITableViewRowAnimationFade];
  351. }
  352. }
  353. - (void)onCommentInCell:(CellForWorkGroup *)cell{
  354. MGGroupUserInfo *model = self.dataArray[cell.indexPath.row];
  355. // self.hidesBottomBarWhenPushed = YES;
  356. DetailsLineViewController *datails = [DetailsLineViewController new];
  357. datails.hidesBottomBarWhenPushed = YES;
  358. datails.title = ASLocalizedString(@"动态详情");
  359. datails.model = model;
  360. datails.refreshData = ^{
  361. [self refreshHeader];
  362. };
  363. [self.navigationController pushViewController:datails animated:YES];
  364. self.hidesBottomBarWhenPushed = NO;
  365. }
  366. - (void)onLikeInCell:(CellForWorkGroup *)cell{
  367. __weak __typeof(self)weakSelf = self;
  368. MGGroupUserInfo *model = self.dataArray[cell.indexPath.row];
  369. BOOL isLike = ![model.is_like isEqualToString:@"1"];
  370. [self.logic addDolikeID:cell.model.id isLike:isLike Success:^(id _Nonnull selfPtr, BOOL isFinished) {
  371. if (cell.indexPath.row < [self.dataArray count]) {
  372. MGGroupUserInfo *model = weakSelf.dataArray[cell.indexPath.row];
  373. // BOOL isLike = [model.is_like isEqualToString:@"1"];
  374. NSInteger praise = [model.praise integerValue];
  375. if (isFinished) {//此处取反
  376. praise += 1;
  377. model.is_like = @"1";
  378. }else{
  379. praise -= 1;
  380. model.is_like = @"0";
  381. }
  382. //
  383. model.praise = [NSString stringWithFormat:@"%ld",praise];
  384. cell.model = model;
  385. [weakSelf.dataArray replaceObjectAtIndex:cell.indexPath.row withObject:model];
  386. // [cell.liksBtn setImage:[UIImage imageNamed:[model.is_like isEqualToString:@"1"] ? @"mg_dy_likes_select" : @"mg_dy_like"] forState:UIControlStateNormal];
  387. // [cell.liksBtn setTitleColor:[UIColor colorWithHexString:[model.is_like isEqualToString:@"1"] ? @"#FF268E" : @"#999999"] forState:UIControlStateNormal];
  388. // [weakSelf.tableView reloadRowsAtIndexPaths:@[cell.indexPath] withRowAnimation:UITableViewRowAnimationNone];
  389. }
  390. }];
  391. }
  392. - (void)onShareInCell:(CellForWorkGroup *)cell{
  393. if (cell.indexPath.row < [self.dataArray count]){
  394. [self _shareWithCell:cell];
  395. }
  396. }
  397. - (void)onDeleteInCell:(CellForWorkGroup *)cell{
  398. if (cell.indexPath.row < [self.dataArray count]) {
  399. [self _deleteDynAtIndexPath:cell.indexPath dynamicId:cell.model.id cell:cell];
  400. }
  401. }
  402. - (void)onTopicInCell:(CellForWorkGroup *)cell{
  403. if (cell.indexPath.row < [self.dataArray count]) {
  404. BGTopicTimeLineListController *pushVC = [BGTopicTimeLineListController new];
  405. MGDynamicTopicModel *topic = [MGDynamicTopicModel new];
  406. topic.t_id = cell.model.theme_id;
  407. topic.name = cell.model.theme;
  408. pushVC.topic = topic;
  409. [[AppDelegate sharedAppDelegate]pushViewController:pushVC animated:YES];
  410. }
  411. }
  412. - (void)onFollowInCell:(CellForWorkGroup *)cell{
  413. if (cell.indexPath.row < [self.dataArray count]) {
  414. FWWeakify(self)
  415. [self.logic addFollowUID:cell.model.uid Success:^(NSDictionary * _Nonnull dic) {
  416. NSInteger _has_focus = [dic toInt:@"has_focus"];
  417. if (_has_focus == 1) {
  418. // [FanweMessage alertHUD:@""]
  419. // [FanweMessage alert:ASLocalizedString(@"关注成功")];
  420. }
  421. //刷新数据
  422. FWStrongify(self)
  423. _currentRequestPage = 1;
  424. self.logic.page = _currentRequestPage;
  425. [self.logic loadListDataWithAct:self.homeType];
  426. }];
  427. }
  428. }
  429. - (void)onTouchActionVideo:(CellForWorkGroup *)cell withFullScreen:(BOOL)fullScreen
  430. {
  431. if (fullScreen) {
  432. YHPlayerViewController *vc = [[YHPlayerViewController alloc]initWithPlayerURL:cell.model.video];
  433. [[AppDelegate sharedAppDelegate] pushViewController:vc animated:YES];
  434. return;
  435. }
  436. _c_cell =cell;
  437. [_playerView destroyPlayer];
  438. _playerView =nil;
  439. _playerView = [[CLPlayerView alloc] initWithFrame:CGRectMake(0, 0, cell.ClVideoview.width, cell.ClVideoview.height)];
  440. _playerView.backgroundColor = kClearColor;
  441. _playerView.layer.cornerRadius = 4;
  442. _playerView.layer.masksToBounds = YES;
  443. _playerView.maskView.playButton.hidden = YES;
  444. // CLPlayerViewConfigure *config = [CLPlayerViewConfigure defaultConfigure];
  445. // config.mute = YES;
  446. _playerView.configure.mute = YES;
  447. _playerView.configure.repeatPlay = YES;
  448. _playerView.isFullScreen = fullScreen;
  449. _playerView.configure.mute = !fullScreen;
  450. _playerView.configure.isLandscape = YES;
  451. _playerView.configure.videoFillMode = VideoFillModeResizeAspectFill;
  452. [_playerView updateWithConfigure:^(CLPlayerViewConfigure *configure) {
  453. if (fullScreen) {
  454. _playerView.frame = CGRectMake(0, 0, kScreenW, kScreenH);
  455. [self.tabBarController.view addSubview:_playerView];
  456. UITapGestureRecognizer *tapPlayerView = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapPlayerView:)];
  457. [_playerView.maskView addGestureRecognizer:tapPlayerView];
  458. }else{
  459. [cell.ClVideoview addSubview:_playerView];
  460. UITapGestureRecognizer *tapPlayerView = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapBigScreen:)];
  461. [_playerView.maskView addGestureRecognizer:tapPlayerView];
  462. }
  463. _playerView.url =[NSURL URLWithString:cell.model.video];
  464. //播放
  465. [_playerView playVideo];
  466. }];
  467. //返回按钮点击事件回调
  468. [_playerView backButton:^(UIButton *button) {
  469. NSLog(ASLocalizedString(@"返回按钮被点击"));
  470. }];
  471. //播放完成回调
  472. [_playerView endPlay:^{
  473. // //销毁播放器
  474. // [_playerView destroyPlayer];
  475. // _playerView = nil;
  476. // NSLog(ASLocalizedString(@"播放完成"));
  477. }];
  478. }
  479. -(void)tapPlayerView:(UITapGestureRecognizer *)sender{
  480. [self onTouchActionVideo:_c_cell withFullScreen:NO];
  481. }
  482. -(void)tapBigScreen:(UITapGestureRecognizer *)sender{
  483. [self onTouchActionVideo:_c_cell withFullScreen:YES];
  484. }
  485. #pragma mark - CellForWorkGroupRepostDelegate
  486. - (void)onAvatarInRepostCell:(CellForWorkGroupRepost *)cell{
  487. }
  488. - (void)onTapRepostViewInCell:(CellForWorkGroupRepost *)cell{
  489. }
  490. - (void)onCommentInRepostCell:(CellForWorkGroupRepost *)cell{
  491. }
  492. //附近--点击去看看
  493. -(void)cliclSeeBtn:(UIButton *)sender{
  494. if (kIsCheckingVersion())
  495. {
  496. return;
  497. }
  498. MGNewDTNearByViewController *pushVC = [[MGNewDTNearByViewController alloc]initWithType:MGNEWDTTYPE_NEAR_PEOPLE];
  499. [[AppDelegate sharedAppDelegate]pushViewController:pushVC animated:YES];
  500. }
  501. - (void)onLikeInRepostCell:(CellForWorkGroupRepost *)cell{
  502. if (cell.indexPath.row < [self.dataArray count]) {
  503. YHWorkGroup *model = self.dataArray[cell.indexPath.row];
  504. BOOL isLike = !model.isLike;
  505. //更新本地数据源
  506. model.isLike = isLike;
  507. if (isLike) {
  508. model.likeCount += 1;
  509. }else{
  510. model.likeCount -= 1;
  511. }
  512. [self.tableView reloadRowsAtIndexPaths:@[cell.indexPath] withRowAnimation:UITableViewRowAnimationNone];
  513. }
  514. }
  515. - (void)onShareInRepostCell:(CellForWorkGroupRepost *)cell{
  516. // if (cell.indexPath.row < [self.dataArray count]){
  517. // [self _shareWithCell:cell];
  518. // }
  519. }
  520. - (void)onDeleteInRepostCell:(CellForWorkGroup *)cell{
  521. if (cell.indexPath.row < [self.dataArray count]) {
  522. [self _deleteDynAtIndexPath:cell.indexPath dynamicId:cell.model.id cell:cell];
  523. }
  524. }
  525. - (void)onMoreInRespostCell:(CellForWorkGroupRepost *)cell{
  526. if (cell.indexPath.row < [self.dataArray count]) {
  527. YHWorkGroup *model = self.dataArray[cell.indexPath.row];
  528. model.isOpening = !model.isOpening;
  529. [self.tableView reloadRowsAtIndexPaths:@[cell.indexPath] withRowAnimation:UITableViewRowAnimationFade];
  530. }
  531. }
  532. #pragma mark - private
  533. - (void)_deleteDynAtIndexPath:(NSIndexPath *)indexPath dynamicId:(NSString *)dynamicId cell:(CellForWorkGroup *)cell{
  534. __weak __typeof(self)weakSelf = self;
  535. // [FanweMessage alert:ASLocalizedString(@"提示")message:ASLocalizedString(@"确定删除该动态?")destructiveAction:^{
  536. [weakSelf.logic delZone:dynamicId Success:^{
  537. [weakSelf.logic loadListDataWithAct:self.homeType];
  538. [FanweMessage alertHUD:ASLocalizedString(@"删除成功")];
  539. }];
  540. // } cancelAction:^{
  541. //
  542. // }];
  543. }
  544. - (void)_shareWithCell:(CellForWorkGroup *)cell{
  545. __weak __typeof(self)weakSelf = self;
  546. [_logic dynamicForwardWithDynamic_id:cell.model.id Success:^{
  547. cell.model.bottomViewSelect = YES;
  548. cell.bottomView.hidden = YES;
  549. [[BGHUDHelper sharedInstance]tipMessage:ASLocalizedString(@"转发成功")];
  550. [weakSelf.logic loadListDataWithAct:self.homeType];
  551. }];
  552. }
  553. #pragma mark - UIScrollViewDelegate
  554. -(UIView *)tableHeadView{
  555. if (!_tableHeadView) {
  556. _tableHeadView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kRealValue(80))];
  557. _tableHeadView.backgroundColor = kWhiteColor;
  558. UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(kRealValue(10), 0, kScreenW - kRealValue(10 * 2), kRealValue(80))];
  559. imgView.image = [UIImage imageNamed:@"dy_newby_people_bgimg"];
  560. imgView.userInteractionEnabled = YES;
  561. UILabel *titleL = [[UILabel alloc]initWithFrame:CGRectMake(kRealValue(28), kRealValue(12), kRealValue(100), kRealValue(20))];
  562. titleL.text = ASLocalizedString(@"附近的人");
  563. titleL.font = [UIFont systemFontOfSize:15];
  564. titleL.textColor = kBlackColor;
  565. UIButton *toSeeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  566. toSeeBtn.frame = CGRectMake(kRealValue(25), titleL.bottom + kRealValue(5), kRealValue(64), kRealValue(29));
  567. [toSeeBtn setBackgroundImage:[UIImage imageNamed:@"dy_newby_people_tosee"] forState:UIControlStateNormal];
  568. [toSeeBtn setTitle:ASLocalizedString(@"去看看")forState:UIControlStateNormal];
  569. [toSeeBtn addTarget:self action:@selector(cliclSeeBtn:) forControlEvents:UIControlEventTouchUpInside];
  570. toSeeBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  571. [imgView addSubview:titleL];
  572. [imgView addSubview:toSeeBtn];
  573. [_tableHeadView addSubview:imgView];
  574. for (int i = 0; i < 3; i ++ ) {
  575. UIImageView *headImgView = [[UIImageView alloc]initWithFrame:CGRectMake(kRealValue(240) + kRealValue(30) * i, 0, kRealValue(40), kRealValue(40))];
  576. headImgView.tag = 100 + i;
  577. headImgView.centerY = imgView.height / 2;
  578. headImgView.layer.masksToBounds = YES;
  579. headImgView.layer.cornerRadius = kRealValue(40 / 2);
  580. headImgView.backgroundColor = kClearColor;
  581. [_tableHeadView addSubview:headImgView];
  582. }
  583. }
  584. return _tableHeadView;
  585. }
  586. -(void)resetHeadView{
  587. //附近的人
  588. if (self.homeType == MGDTHOMETYPE_NEARBY) {
  589. if (kIsCheckingVersion())
  590. {
  591. return;
  592. }
  593. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  594. [parmDict setObject:@"dynamic" forKey:@"ctl"];
  595. [parmDict setObject:@"fujin_user" forKey:@"act"];
  596. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  597. if ([[responseJson valueForKey:@"status"] integerValue] == 1) {
  598. NSArray *arr = responseJson[@"data"];
  599. [self resetTableHeadViewWithArr:arr];
  600. }else{
  601. }
  602. } FailureBlock:^(NSError *error) {
  603. }];
  604. }
  605. }
  606. -(void)resetTableHeadViewWithArr:(NSArray *)arr{
  607. if (arr.count > 0)
  608. {
  609. for ( int i = 0; i < arr.count; i++) {
  610. NSDictionary *dic = arr[i];
  611. MGNewDTNearlistModel *model = [MGNewDTNearlistModel modelWithDictionary:dic];
  612. UIImageView *imgView = [_tableHeadView viewWithTag:100 + i];
  613. [imgView sd_setImageWithURL:[NSURL URLWithString:model.head_image] placeholderImage:nil];
  614. }
  615. }
  616. }
  617. @end