BGVideoDetailController.m 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  1. //
  2. // BGVideoDetailController.m
  3. // BuguLive
  4. //
  5. // Created by fanwe2014 on 2017/3/23.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "BGVideoDetailController.h"
  9. #import "BGShareView.h"
  10. #import "BGVideoMirrorCell.h"
  11. #import "CommentModel.h"
  12. #import "PersonCenterModel.h"
  13. #import "PersonCenterListModel.h"
  14. #import "BGReportController.h"
  15. #import "BGReplyCell.h"
  16. #import "BGPlayVideoController.h"
  17. #import "SHomePageVC.h"
  18. NS_ENUM(NSInteger, FWMyVideoDetailTabIndexs)
  19. {
  20. FWPCDetailOneSection, //第一段
  21. FWPCDetailTwoSection, //第二段
  22. FWPCDetailThreeSection, //第三段
  23. EPCTab_Count,
  24. };
  25. @interface BGVideoDetailController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,shareDeleGate,commentDeleGate,ZanandVideoDelegate,UIActionSheetDelegate>
  26. {
  27. int _currentPage; //当前页数
  28. int _has_next; //是否还有下一页1代表有
  29. UIImageView *_headImgView; //播放图像
  30. UIImageView *_playImgView; //播放控件
  31. UIView *_buttomView; //输入键盘底部的view
  32. UITextField *_textField; //评论
  33. UIButton *_commentBtn; //评论bt
  34. BOOL _isShowKeyBoard; //是否显示键盘
  35. NSString *_comment_id; //被评论的评论ID
  36. BGShareView *_myShareView; //分享view
  37. PersonCenterModel *_detailModel; //数据模型
  38. int _rowCount; //第三段哪一组
  39. NSMutableDictionary *_shareDict; //分享的信息
  40. }
  41. @end
  42. @implementation BGVideoDetailController
  43. - (void)viewDidLoad
  44. {
  45. [super viewDidLoad];
  46. self.automaticallyAdjustsScrollViewInsets = NO;// 默认是YES
  47. _shareDict = [[NSMutableDictionary alloc]init];
  48. self.navigationItem.title = ASLocalizedString(@"小视频详情");
  49. self.dataArray = [[NSMutableArray alloc]init];
  50. self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(moreChoose) image:@"fw_vdetail_more" highImage:@"fw_vdetail_more"];
  51. self.view.backgroundColor = kWhiteColor;
  52. [self creatMianView];
  53. [self keyboardMonitor];//通知
  54. FWWeakify(self)
  55. [self setupBackBtnWithBlock:^{
  56. FWStrongify(self)
  57. [self tap];
  58. [self.navigationController popViewControllerAnimated:YES];
  59. }];
  60. }
  61. #pragma mark 键盘监听
  62. - (void)keyboardMonitor
  63. {
  64. //键盘显示时发出通知
  65. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  66. //键盘隐藏时发出
  67. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  68. }
  69. - (void)keyboardWillShow:(NSNotification *)notification
  70. {
  71. _isShowKeyBoard = YES;
  72. // 键盘弹出需要的时间
  73. CGFloat animationDuration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
  74. // 取出键盘高度
  75. CGRect keyboardF = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  76. CGRect currentFrame = self.view.frame;
  77. currentFrame.origin.y = currentFrame.origin.y - keyboardF.size.height - 115;
  78. _tableView.frame = currentFrame;
  79. // 执行动画
  80. [UIView animateWithDuration:animationDuration animations:^{
  81. _buttomView.y = kScreenH - keyboardF.size.height - 50 - kTopHeight;
  82. }];
  83. }
  84. - (void)keyboardWillHide:(NSNotification *)notification
  85. {
  86. // 键盘弹出需要的时间
  87. CGFloat animationDuration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
  88. CGRect currentFrame = self.view.frame;
  89. currentFrame.origin.y = 0 ;
  90. currentFrame.size.height = kScreenH- 64-50;
  91. _tableView.frame = currentFrame;
  92. [UIView animateWithDuration:animationDuration animations:^{
  93. [_commentBtn setTitle:ASLocalizedString(@"发表评论")forState:UIControlStateNormal];
  94. _buttomView.y = kScreenH - kTopHeight - 50 - 10;
  95. }];
  96. }
  97. - (void)inputViewDown
  98. {
  99. _textField.placeholder = ASLocalizedString(@"请输入您的评论");
  100. _comment_id = @"";
  101. _isShowKeyBoard = NO;
  102. [_textField resignFirstResponder];
  103. }
  104. - (void)creatMianView
  105. {
  106. _myShareView = [[BGShareView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 60) Delegate:self];
  107. _shareArray = _myShareView.shareArray;
  108. self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH-kStatusBarHeight-kNavigationBarHeight-50)];
  109. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  110. self.tableView.delegate = self;
  111. self.tableView.dataSource = self;
  112. [self.view addSubview:self.tableView];
  113. [_tableView registerClass:[BGReplyCell class] forCellReuseIdentifier:@"BGReplyCell"];
  114. _buttomView = [[UIView alloc]initWithFrame:CGRectMake(0, kScreenH - 50 - kTopHeight - 10, kScreenW, 50)];
  115. _buttomView.backgroundColor = kWhiteColor;
  116. [self.view addSubview:_buttomView];
  117. //搜索框
  118. _textField = [[UITextField alloc]initWithFrame:CGRectMake(10, 5, kScreenW -130, 40)];
  119. _textField.userInteractionEnabled = YES;
  120. _textField.layer.cornerRadius = 3;
  121. _textField.leftViewMode = UITextFieldViewModeAlways;
  122. _textField.backgroundColor = kBackGroundColor;
  123. _textField.textColor = RGB(153, 153, 153);
  124. _textField.textAlignment = NSTextAlignmentLeft;
  125. _textField.font = [UIFont systemFontOfSize:12];
  126. _textField.delegate = self;
  127. _textField.placeholder = ASLocalizedString(@"请输入您的评论");
  128. [_buttomView addSubview:_textField];
  129. UILabel * leftView = [[UILabel alloc] initWithFrame:CGRectMake(0,0,10,40)];
  130. leftView.backgroundColor = [UIColor clearColor];
  131. _textField.leftView = leftView;
  132. _textField.leftViewMode = UITextFieldViewModeAlways;
  133. _textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
  134. _commentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  135. _commentBtn.frame = CGRectMake(kScreenW-110, 5, 100, 40);
  136. _commentBtn.layer.cornerRadius = 3;
  137. _commentBtn.backgroundColor = kAppMainColor;
  138. [_commentBtn setTitle:ASLocalizedString(@"发表评论")forState:UIControlStateNormal];
  139. [_commentBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
  140. [_commentBtn addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
  141. _commentBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  142. [_buttomView addSubview:_commentBtn];
  143. [BGMJRefreshManager refresh:_tableView target:self headerRereshAction:@selector(headerReresh) footerRereshAction:@selector(refresherOfNew)];
  144. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
  145. [_tableView addGestureRecognizer:tap];
  146. _headImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, (kScreenW*42)/75)];
  147. _headImgView.backgroundColor = kAppGrayColor1;
  148. _headImgView.image = kDefaultPreloadVideoHeadImg;
  149. _headImgView.contentMode = UIViewContentModeScaleAspectFit;
  150. _headImgView.userInteractionEnabled = YES;
  151. UITapGestureRecognizer *playTaps = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(playTap)];
  152. [_headImgView addGestureRecognizer:playTaps];
  153. _playImgView = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenW/2-19, (kScreenW*42)/150 -19, 39, 39)];
  154. _playImgView.userInteractionEnabled = YES;
  155. _playImgView.image = [UIImage imageNamed:@"fw_personCenter_play"];
  156. UITapGestureRecognizer *playTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(playTap)];
  157. [_playImgView addGestureRecognizer:playTap];
  158. [_headImgView addSubview:_playImgView];
  159. _tableView.tableHeaderView = _headImgView;
  160. }
  161. - (void)showKeyBoard
  162. {
  163. [_textField becomeFirstResponder];
  164. }
  165. - (void)tap
  166. {
  167. _isShowKeyBoard = NO;
  168. [self inputViewDown];
  169. }
  170. - (void)playTap
  171. {
  172. [self addPlayNumWithWeiBoId:_detailModel.info.weibo_id];
  173. BGPlayVideoController *playVC = [BGPlayVideoController new];
  174. playVC.playUrl =_detailModel.info.video_url;
  175. [[AppDelegate sharedAppDelegate] pushViewController:playVC animated:YES];
  176. }
  177. #pragma mark 播放视频加1
  178. - (void)addPlayNumWithWeiBoId:(NSString *)weiBoId
  179. {
  180. NSMutableDictionary *MDict = [NSMutableDictionary new];
  181. [MDict setObject:@"weibo" forKey:@"ctl"];
  182. [MDict setObject:@"add_video_count" forKey:@"act"];
  183. [MDict setObject:@"xr" forKey:@"itype"];
  184. if (weiBoId.length)
  185. {
  186. [MDict setObject:weiBoId forKey:@"weibo_id"];
  187. }
  188. FWWeakify(self)
  189. [self.httpsManager POSTWithParameters:MDict SuccessBlock:^(NSDictionary *responseJson)
  190. {
  191. FWStrongify(self)
  192. if ([responseJson toInt:@"status"]== 1)
  193. {
  194. _detailModel.info.video_count = [responseJson toString:@"video_count"];
  195. NSMutableDictionary *postDict = [[NSMutableDictionary alloc]init];
  196. [postDict setObject:@"video" forKey:@"type"];
  197. [postDict setObject:[NSString stringWithFormat:@"%d",[responseJson toInt:@"video_count"]] forKey:@"count"];
  198. [postDict setObject:[NSString stringWithFormat:@"%d",self.lastView] forKey:@"reloadView"];
  199. [[NSNotificationCenter defaultCenter] postNotificationName:@"changeTableViewStatus" object:postDict];
  200. }
  201. NSIndexPath *te = [NSIndexPath indexPathForRow:0 inSection:FWPCDetailOneSection];//刷新某段某行
  202. [_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:te,nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  203. [[BGHUDHelper sharedInstance] tipMessage:[responseJson toString:@"error"]];
  204. } FailureBlock:^(NSError *error)
  205. {
  206. NSLog(@"error==%@",error);
  207. }];
  208. }
  209. - (void)moreChoose
  210. {
  211. if (_detailModel.is_admin)//是自己
  212. {
  213. UIActionSheet *headImgSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
  214. [headImgSheet addButtonWithTitle:ASLocalizedString(@"删除动态")];
  215. [headImgSheet addButtonWithTitle:ASLocalizedString(@"取消")];
  216. headImgSheet.tag = 3;
  217. headImgSheet.cancelButtonIndex = headImgSheet.numberOfButtons-1;
  218. headImgSheet.delegate = self;
  219. [headImgSheet showInView:[UIApplication sharedApplication].keyWindow];
  220. }else
  221. {
  222. UIActionSheet *headImgSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
  223. [headImgSheet addButtonWithTitle:ASLocalizedString(@"举报该动态")];
  224. [headImgSheet addButtonWithTitle:ASLocalizedString(@"举报该用户")];
  225. [headImgSheet addButtonWithTitle:ASLocalizedString(@"取消")];
  226. headImgSheet.tag = 1;
  227. headImgSheet.cancelButtonIndex = headImgSheet.numberOfButtons-1;
  228. headImgSheet.delegate = self;
  229. [headImgSheet showInView:[UIApplication sharedApplication].keyWindow];
  230. }
  231. }
  232. #pragma mark 头部刷新
  233. - (void)headerReresh
  234. {
  235. [self loadNetDataWithPage:1];
  236. }
  237. - (void)refresherOfNew
  238. {
  239. if (_has_next == 1)
  240. {
  241. _currentPage ++;
  242. [self loadNetDataWithPage:_currentPage];
  243. }
  244. else
  245. {
  246. [BGMJRefreshManager endRefresh:self.tableView];
  247. }
  248. }
  249. #pragma mark 加载数据
  250. -(void)loadNetDataWithPage:(int)page
  251. {
  252. NSMutableDictionary *MDict = [NSMutableDictionary new];
  253. [MDict setObject:@"weibo" forKey:@"ctl"];
  254. [MDict setObject:@"index" forKey:@"act"];
  255. [MDict setObject:@"xr" forKey:@"itype"];
  256. if (self.weibo_id.length)
  257. {
  258. [MDict setObject:self.weibo_id forKey:@"weibo_id"];
  259. }
  260. FWWeakify(self)
  261. [self.httpsManager POSTWithParameters:MDict SuccessBlock:^(NSDictionary *responseJson)
  262. {
  263. FWStrongify(self)
  264. _has_next = [responseJson toInt:@"has_next"];
  265. _currentPage = [responseJson toInt:@"page"];
  266. if (_currentPage == 1)
  267. {
  268. [_dataArray removeAllObjects];
  269. }
  270. if ([responseJson toInt:@"status"]== 1)
  271. {
  272. NSDictionary *shareD = [responseJson objectForKey:@"invite_info"];
  273. if (shareD && [shareD isKindOfClass:[NSDictionary class]]) {
  274. if ([shareD count])
  275. {
  276. if ([[shareD objectForKey:@"clickUrl"] length])
  277. {
  278. [_shareDict setObject:[shareD objectForKey:@"clickUrl"] forKey:@"share_url"];
  279. }else
  280. {
  281. [_shareDict setObject:@"" forKey:@"share_url"];
  282. }
  283. if ([[shareD objectForKey:@"content"] length])
  284. {
  285. [_shareDict setObject:[shareD objectForKey:@"content"] forKey:@"share_content"];
  286. }else
  287. {
  288. [_shareDict setObject:@"" forKey:@"share_content"];
  289. }
  290. if ([[shareD objectForKey:@"imageUrl"] length])
  291. {
  292. [_shareDict setObject:[shareD objectForKey:@"imageUrl"] forKey:@"share_imageUrl"];
  293. }else
  294. {
  295. [_shareDict setObject:@"" forKey:@"share_imageUrl"];
  296. }
  297. if ([[shareD objectForKey:@"title"] length])
  298. {
  299. [_shareDict setObject:[shareD objectForKey:@"title"] forKey:@"share_title"];
  300. }else
  301. {
  302. [_shareDict setObject:@"" forKey:@"share_title"];
  303. }
  304. }
  305. }
  306. _detailModel = [PersonCenterModel mj_objectWithKeyValues:responseJson];
  307. //动态
  308. NSArray *comment_listArray = [responseJson objectForKey:@"comment_list"];
  309. if (comment_listArray && [comment_listArray isKindOfClass:[NSArray class]])
  310. {
  311. if (comment_listArray.count)
  312. {
  313. for (NSDictionary *dict in comment_listArray)
  314. {
  315. CommentModel *CModel = [CommentModel mj_objectWithKeyValues:dict];
  316. [self.dataArray addObject:CModel];
  317. }
  318. }
  319. }
  320. [_headImgView sd_setImageWithURL:[NSURL URLWithString:[[responseJson objectForKey:@"info"] objectForKey:@"photo_image"]] placeholderImage:kDefaultPreloadVideoHeadImg];
  321. [self.tableView reloadData];
  322. }else
  323. {
  324. [[BGHUDHelper sharedInstance] tipMessage:[responseJson toString:@"error"]];
  325. }
  326. [BGMJRefreshManager endRefresh:self.tableView];
  327. } FailureBlock:^(NSError *error)
  328. {
  329. FWStrongify(self)
  330. [BGMJRefreshManager endRefresh:self.tableView];
  331. NSLog(@"error==%@",error);
  332. }];
  333. }
  334. #pragma mark ----tabelView代理方法
  335. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  336. {
  337. return EPCTab_Count;
  338. }
  339. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  340. {
  341. if (section == FWPCDetailOneSection)
  342. {
  343. if (_detailModel.info!= nil)
  344. {
  345. return 1;
  346. }else
  347. {
  348. return 0;
  349. }
  350. }else if (section == FWPCDetailTwoSection)
  351. {
  352. if (_shareArray.count)
  353. {
  354. return 1;
  355. }else
  356. {
  357. return 0;
  358. }
  359. }else
  360. {
  361. return _dataArray.count;
  362. }
  363. }
  364. #pragma mark ----设置cell的高度
  365. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  366. {
  367. if (indexPath.section == FWPCDetailOneSection)
  368. {
  369. static NSString *CellIdentifier0 = @"CellIdentifier0";
  370. BGVideoMirrorCell *cell = (BGVideoMirrorCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier0];
  371. if (cell == nil) {
  372. cell = [[BGVideoMirrorCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0];
  373. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  374. }
  375. NSLog(@"height==%f",[cell creatCellWithModel:_detailModel.info andRow:(int)indexPath.section isVideo:YES])
  376. return [cell creatCellWithModel:_detailModel.info andRow:(int)indexPath.section isVideo:YES];
  377. }else if (indexPath.section == FWPCDetailTwoSection)
  378. {
  379. if (_shareArray.count)
  380. {
  381. return 60;
  382. }else
  383. {
  384. return 0;
  385. }
  386. }else //判断是否需要返回头像的高度
  387. {
  388. static NSString *CellIdentifier1 = @"CellIdentifier1";
  389. BGReplyCell *cell = (BGReplyCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
  390. if (cell == nil) {
  391. cell = [[BGReplyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1];
  392. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  393. }
  394. return [cell creatCellWithModel:_dataArray[indexPath.row] andRow:(int)indexPath.row];
  395. }
  396. }
  397. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  398. {
  399. if (indexPath.section == FWPCDetailOneSection)
  400. {
  401. static NSString *CellIdentifier2 = @"CellIdentifier2";
  402. BGVideoMirrorCell *cell = (BGVideoMirrorCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
  403. if (cell == nil) {
  404. cell = [[BGVideoMirrorCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2];
  405. cell.ZVDelegate =self;
  406. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  407. }
  408. [cell creatCellWithModel:_detailModel.info andRow:(int)indexPath.section isVideo:YES];
  409. return cell;
  410. }else if (indexPath.section == FWPCDetailTwoSection)
  411. {
  412. static NSString *CellIdentifier3 = @"CellIdentifier3";
  413. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier3];
  414. if (!cell)
  415. {
  416. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier3];
  417. cell.accessoryType = UITableViewCellAccessoryNone;
  418. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  419. cell.backgroundColor = kBackGroundColor;
  420. }
  421. [cell.contentView addSubview:_myShareView];
  422. return cell;
  423. }else
  424. {
  425. BGReplyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BGReplyCell" forIndexPath:indexPath];
  426. cell.CDelegate = self;
  427. [cell creatCellWithModel:_dataArray[indexPath.row] andRow:(int)indexPath.row];
  428. return cell;
  429. }
  430. }
  431. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  432. {
  433. if (section == FWPCDetailThreeSection)
  434. {
  435. if (_dataArray.count)
  436. {
  437. return 10;
  438. }else
  439. {
  440. return 0;
  441. }
  442. }else
  443. {
  444. return 0;
  445. }
  446. }
  447. #pragma mark cell的回调
  448. - (void)zanOrVideoClickWithTag:(int)tag
  449. {
  450. if (tag == 0)//点赞
  451. {
  452. [self zanreLoadRowWithTag:tag];
  453. }else if (tag == 2)//点击头像
  454. {
  455. SHomePageVC *myVC = [[SHomePageVC alloc]init];
  456. myVC.user_id = _detailModel.info.user_id;
  457. myVC.type = 0;
  458. [[AppDelegate sharedAppDelegate] pushViewController:myVC animated:YES];
  459. }
  460. }
  461. #pragma mark 点赞
  462. - (void)zanreLoadRowWithTag:(int)tag
  463. {
  464. NSMutableDictionary *MDict = [NSMutableDictionary new];
  465. [MDict setObject:@"user" forKey:@"ctl"];
  466. [MDict setObject:@"publish_comment" forKey:@"act"];
  467. if (_weibo_id.length)
  468. {
  469. [MDict setObject:_weibo_id forKey:@"weibo_id"];
  470. }
  471. [MDict setObject:@"xr" forKey:@"itype"];
  472. [MDict setObject:@"2" forKey:@"type"];
  473. FWWeakify(self)
  474. [self.httpsManager POSTWithParameters:MDict SuccessBlock:^(NSDictionary *responseJson)
  475. {
  476. FWStrongify(self)
  477. if ([responseJson toInt:@"status"]== 1)
  478. {
  479. _detailModel.info.digg_count = [responseJson toString:@"digg_count"];
  480. _detailModel.info.has_digg = [responseJson toInt:@"has_digg"];
  481. NSMutableDictionary *postDict = [[NSMutableDictionary alloc]init];
  482. [postDict setObject:@"dianZan" forKey:@"type"];
  483. [postDict setObject:[NSString stringWithFormat:@"%@",_detailModel.info.digg_count] forKey:@"count"];
  484. [postDict setObject:[NSString stringWithFormat:@"%d",_detailModel.info.has_digg] forKey:@"has_digg"];
  485. [postDict setObject:[NSString stringWithFormat:@"%d",self.lastView] forKey:@"reloadView"];
  486. [[NSNotificationCenter defaultCenter] postNotificationName:@"changeTableViewStatus" object:postDict];
  487. }
  488. NSIndexPath *te = [NSIndexPath indexPathForRow:0 inSection:FWPCDetailOneSection];//刷新某段某行
  489. [[BGHUDHelper sharedInstance] tipMessage:[responseJson toString:@"error"]];
  490. [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:te,nil] withRowAnimation:UITableViewRowAnimationAutomatic];
  491. } FailureBlock:^(NSError *error)
  492. {
  493. NSLog(@"error==%@",error);
  494. }];
  495. }
  496. #pragma mark 置顶
  497. - (void)setTopWithTag
  498. {
  499. NSMutableDictionary *MDict = [NSMutableDictionary new];
  500. [MDict setObject:@"user" forKey:@"ctl"];
  501. [MDict setObject:@"set_top" forKey:@"act"];
  502. if (self.weibo_id)
  503. {
  504. [MDict setObject:self.weibo_id forKey:@"weibo_id"];
  505. }
  506. [MDict setObject:@"xr" forKey:@"itype"];
  507. FWWeakify(self)
  508. [self.httpsManager POSTWithParameters:MDict SuccessBlock:^(NSDictionary *responseJson)
  509. {
  510. FWStrongify(self)
  511. if ([responseJson toInt:@"status"]== 1)
  512. {
  513. [self loadNetDataWithPage:1];
  514. }
  515. [[BGHUDHelper sharedInstance] tipMessage:[responseJson toString:@"error"]];
  516. } FailureBlock:^(NSError *error)
  517. {
  518. NSLog(@"error==%@",error);
  519. }];
  520. }
  521. #pragma mark 拉黑
  522. - (void)defriendAction
  523. {
  524. NSMutableDictionary *MDict = [NSMutableDictionary new];
  525. [MDict setObject:@"user" forKey:@"ctl"];
  526. [MDict setObject:@"set_black" forKey:@"act"];
  527. if (_detailModel.info.user_id)
  528. {
  529. [MDict setObject:_detailModel.info.user_id forKey:@"to_user_id"];
  530. }
  531. [MDict setObject:@"xr" forKey:@"itype"];
  532. FWWeakify(self)
  533. [self.httpsManager POSTWithParameters:MDict SuccessBlock:^(NSDictionary *responseJson)
  534. {
  535. FWStrongify(self)
  536. if ([responseJson toInt:@"status"]== 1)
  537. {
  538. if (![_detailModel.info.user_id isEqualToString:[[IMAPlatform sharedInstance].host imUserId]])
  539. {
  540. [self.navigationController popViewControllerAnimated:YES];
  541. [[BGHUDHelper sharedInstance] tipMessage:[responseJson toString:@"error"]];
  542. }else
  543. {
  544. [self loadNetDataWithPage:1];
  545. }
  546. }
  547. [[BGHUDHelper sharedInstance] tipMessage:[responseJson toString:@"error"]];
  548. } FailureBlock:^(NSError *error)
  549. {
  550. NSLog(@"error==%@",error);
  551. }];
  552. }
  553. #pragma mark 进入举报页面
  554. - (void)goToReportControllerWithTag:(int)tag
  555. {
  556. BGReportController *reportVC = [[BGReportController alloc]init];
  557. reportVC.weibo_id = _detailModel.info.weibo_id;
  558. reportVC.to_user_id = _detailModel.info.user_id;
  559. if (tag == 1)//动态
  560. {
  561. reportVC.reportType = 1;
  562. }else if (tag == 2)
  563. {
  564. reportVC.reportType = 2;
  565. }
  566. [[AppDelegate sharedAppDelegate] pushViewController:reportVC animated:YES];
  567. }
  568. #pragma mark 删除某条动态
  569. - (void)deleteDynamicWithString:(NSString *)string
  570. {
  571. NSMutableDictionary *MDict = [NSMutableDictionary new];
  572. [MDict setObject:@"user" forKey:@"ctl"];
  573. [MDict setObject:@"del_weibo" forKey:@"act"];
  574. if (self.weibo_id)
  575. {
  576. [MDict setObject:self.weibo_id forKey:@"weibo_id"];
  577. }
  578. [MDict setObject:@"xr" forKey:@"itype"];
  579. FWWeakify(self)
  580. [self.httpsManager POSTWithParameters:MDict SuccessBlock:^(NSDictionary *responseJson)
  581. {
  582. FWStrongify(self);
  583. if ([responseJson toInt:@"status"]== 1)
  584. {
  585. NSMutableDictionary *postDict = [[NSMutableDictionary alloc]init];
  586. [postDict setObject:@"delete" forKey:@"type"];
  587. [postDict setObject:[NSString stringWithFormat:@"%d",self.lastView] forKey:@"reloadView"];
  588. [[NSNotificationCenter defaultCenter] postNotificationName:@"changeTableViewStatus" object:postDict];
  589. [self.navigationController popViewControllerAnimated:YES];
  590. }
  591. [[BGHUDHelper sharedInstance] tipMessage:[responseJson toString:@"error"]];
  592. } FailureBlock:^(NSError *error)
  593. {
  594. NSLog(@"error==%@",error);
  595. }];
  596. }
  597. #pragma mark ===================== 第二段的点击事件 ===============================
  598. - (void)clickShareImgViewWithTag:(int)tag
  599. {
  600. //0新浪 1朋友圈 2微信 3qq 4qq空间
  601. NSString *shareStr;
  602. if(tag == 0) shareStr = @"sina";
  603. if(tag == 1) shareStr = @"weixin_circle";
  604. if(tag == 2) shareStr = @"weixin";
  605. if(tag == 3) shareStr = @"qq";
  606. if(tag == 4) shareStr = @"qzone";
  607. //0新浪 1朋友圈 2微信 3qq 4qq空间
  608. UMSocialPlatformType socialPlatformType; //分享的类型
  609. if(tag == 0) socialPlatformType = UMSocialPlatformType_Sina;
  610. if(tag == 1) socialPlatformType = UMSocialPlatformType_WechatTimeLine;
  611. if(tag == 2) socialPlatformType = UMSocialPlatformType_WechatSession;
  612. if(tag == 3) socialPlatformType = UMSocialPlatformType_QQ;
  613. if(tag == 4) socialPlatformType = UMSocialPlatformType_Qzone;
  614. ShareModel *SModel = [ShareModel mj_objectWithKeyValues:_shareDict];
  615. [[BGUMengShareManager sharedInstance] shareTo:self platformType:socialPlatformType shareModel:SModel succ:nil failed:nil];
  616. }
  617. #pragma mark ===================== 第三段的点击事件 ===============================
  618. #pragma mark 点击名字的回调
  619. - (void)clickNameStringWithTag:(int)tag
  620. {
  621. CommentModel *CModel = _dataArray[tag];
  622. SHomePageVC *myVC = [[SHomePageVC alloc]init];
  623. myVC.user_id = CModel.user_id;
  624. myVC.type = 0;
  625. [[AppDelegate sharedAppDelegate] pushViewController:myVC animated:YES];
  626. }
  627. #pragma mark 点击动态的回调
  628. - (void)commentNewsWithTag:(int)tag
  629. {
  630. _rowCount = tag;
  631. CommentModel *CModel = _dataArray[tag];
  632. if (_detailModel.user_id >0)
  633. {
  634. if (_detailModel.is_admin)
  635. {
  636. if ([CModel.user_id intValue] == _detailModel.user_id)//如果是自己的评论,且是自己的回复就只有删除取消
  637. {
  638. UIActionSheet *headImgSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
  639. [headImgSheet addButtonWithTitle:ASLocalizedString(@"删除")];
  640. [headImgSheet addButtonWithTitle:ASLocalizedString(@"取消")];
  641. [headImgSheet setTintColor:kAppGrayColor1];
  642. headImgSheet.tag = 0;
  643. headImgSheet.cancelButtonIndex = headImgSheet.numberOfButtons-1;
  644. headImgSheet.delegate = self;
  645. [headImgSheet showInView:[UIApplication sharedApplication].keyWindow];
  646. }else//如果是自己的评论,但是是别人的评论就有删除回复取消
  647. {
  648. UIActionSheet *headImgSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
  649. [headImgSheet addButtonWithTitle:ASLocalizedString(@"回复")];
  650. [headImgSheet addButtonWithTitle:ASLocalizedString(@"取消")];
  651. [headImgSheet setTintColor:kAppGrayColor1];
  652. headImgSheet.tag = 2;
  653. headImgSheet.cancelButtonIndex = headImgSheet.numberOfButtons-1;
  654. headImgSheet.delegate = self;
  655. [headImgSheet showInView:[UIApplication sharedApplication].keyWindow];
  656. }
  657. }else
  658. {
  659. if ([CModel.user_id intValue] == _detailModel.user_id)//不是自己的评论,是回复别人的评论,只有删除
  660. {
  661. UIActionSheet *headImgSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
  662. [headImgSheet addButtonWithTitle:ASLocalizedString(@"删除")];
  663. [headImgSheet addButtonWithTitle:ASLocalizedString(@"取消")];
  664. [headImgSheet setTintColor:kAppGrayColor1];
  665. headImgSheet.tag = 0;
  666. headImgSheet.cancelButtonIndex = headImgSheet.numberOfButtons-1;
  667. headImgSheet.delegate = self;
  668. [headImgSheet showInView:[UIApplication sharedApplication].keyWindow];
  669. }else//不是自己的评论,是别人的评论,只能回复别人的评论
  670. {
  671. _isShowKeyBoard =! _isShowKeyBoard;
  672. if (_isShowKeyBoard == YES)
  673. {
  674. [_commentBtn setTitle:ASLocalizedString(@"回复")forState:UIControlStateNormal];
  675. [_textField becomeFirstResponder];
  676. _textField.placeholder = [NSString stringWithFormat:ASLocalizedString(@"回复:%@"),CModel.nick_name];
  677. _comment_id = CModel.comment_id;
  678. }else
  679. {
  680. _textField.placeholder = ASLocalizedString(@"请输入您的评论");
  681. _comment_id = @"";
  682. [self tap];
  683. }
  684. }
  685. }
  686. }
  687. }
  688. #pragma mark 删除某条评论
  689. - (void)deleteCommentWithTag:(int)count
  690. {
  691. CommentModel *CModel = _dataArray[_rowCount];
  692. NSMutableDictionary *MDict = [NSMutableDictionary new];
  693. [MDict setObject:@"user" forKey:@"ctl"];
  694. [MDict setObject:@"del_comment" forKey:@"act"];
  695. if (CModel.comment_id.length)
  696. {
  697. [MDict setObject:CModel.comment_id forKey:@"comment_id"];
  698. }
  699. [MDict setObject:@"xr" forKey:@"itype"];
  700. FWWeakify(self)
  701. [self.httpsManager POSTWithParameters:MDict SuccessBlock:^(NSDictionary *responseJson)
  702. {
  703. FWStrongify(self)
  704. if ([responseJson toInt:@"status"]== 1)
  705. {
  706. [_dataArray removeObjectAtIndex:_rowCount];
  707. _detailModel.info.comment_count = [NSString stringWithFormat:@"%d",(int)_dataArray.count];
  708. [_tableView reloadData];
  709. NSMutableDictionary *postDict = [[NSMutableDictionary alloc]init];
  710. [postDict setObject:@"comment" forKey:@"type"];
  711. [postDict setObject:[NSString stringWithFormat:@"%d",(int)_dataArray.count] forKey:@"count"];
  712. [postDict setObject:[NSString stringWithFormat:@"%d",self.lastView] forKey:@"reloadView"];
  713. [[NSNotificationCenter defaultCenter] postNotificationName:@"changeTableViewStatus" object:postDict];
  714. }
  715. [[BGHUDHelper sharedInstance] tipMessage:[responseJson toString:@"error"]];
  716. } FailureBlock:^(NSError *error)
  717. {
  718. NSLog(@"error==%@",error);
  719. }];
  720. }
  721. #pragma mark 发表评论
  722. - (void)buttonClick
  723. {
  724. if (_textField.text.length < 1)
  725. {
  726. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"请输入评论的内容")];
  727. return;
  728. }
  729. NSMutableDictionary *MDict = [NSMutableDictionary new];
  730. [MDict setObject:@"user" forKey:@"ctl"];
  731. [MDict setObject:@"publish_comment" forKey:@"act"];
  732. [MDict setObject:@"1" forKey:@"type"];
  733. if (self.weibo_id.length)
  734. {
  735. [MDict setObject:self.weibo_id forKey:@"weibo_id"];
  736. }
  737. if (_comment_id.length)
  738. {
  739. [MDict setObject:_comment_id forKey:@"to_comment_id"];
  740. }
  741. [MDict setObject:@"xr" forKey:@"itype"];
  742. [MDict setObject:_textField.text forKey:@"content"];
  743. [self inputViewDown];
  744. FWWeakify(self)
  745. [self.httpsManager POSTWithParameters:MDict SuccessBlock:^(NSDictionary *responseJson)
  746. {
  747. FWStrongify(self)
  748. if ([responseJson toInt:@"status"]== 1)
  749. {
  750. _textField.text = @"";
  751. NSDictionary *commentDict = [responseJson objectForKey:@"comment"];
  752. if (commentDict && [commentDict isKindOfClass:[NSDictionary class]])
  753. {
  754. CommentModel *CModel = [CommentModel mj_objectWithKeyValues:commentDict];
  755. [_dataArray insertObject:CModel atIndex:0];
  756. }
  757. _detailModel.info.comment_count =[NSString stringWithFormat:@"%d",(int)_dataArray.count] ;
  758. [_tableView reloadData];
  759. NSMutableDictionary *postDict = [[NSMutableDictionary alloc]init];
  760. [postDict setObject:@"comment" forKey:@"type"];
  761. [postDict setObject:[NSString stringWithFormat:@"%d",(int)_dataArray.count] forKey:@"count"];
  762. [postDict setObject:[NSString stringWithFormat:@"%d",self.lastView] forKey:@"reloadView"];
  763. [[NSNotificationCenter defaultCenter] postNotificationName:@"changeTableViewStatus" object:postDict];
  764. }
  765. [[BGHUDHelper sharedInstance] tipMessage:[responseJson toString:@"error"]];
  766. } FailureBlock:^(NSError *error)
  767. {
  768. NSLog(@"error==%@",error);
  769. }];
  770. }
  771. #pragma mark UIActionSheet的回调事件
  772. - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger) buttonIndex
  773. {
  774. if (actionSheet.tag == 0)//如果是自己的评论,且是自己的回复就只有删除取消
  775. {
  776. if (buttonIndex == 0)
  777. {
  778. [self deleteCommentWithTag:_rowCount];
  779. }else if (buttonIndex == 1)
  780. {
  781. }
  782. }else if(actionSheet.tag == 1)
  783. {
  784. if (buttonIndex == 0)
  785. {
  786. [self goToReportControllerWithTag:1];
  787. }else if (buttonIndex == 1)
  788. {
  789. [self goToReportControllerWithTag:2];
  790. }
  791. }else if(actionSheet.tag == 2)
  792. {
  793. if (buttonIndex == 0)
  794. {
  795. _isShowKeyBoard =! _isShowKeyBoard;
  796. if (_isShowKeyBoard == YES)
  797. {
  798. [_commentBtn setTitle:ASLocalizedString(@"回复")forState:UIControlStateNormal];
  799. [_textField becomeFirstResponder];
  800. CommentModel *CModel =_dataArray[_rowCount];
  801. _textField.placeholder = [NSString stringWithFormat:@"%@",CModel.nick_name];
  802. _comment_id = CModel.comment_id;
  803. }else
  804. {
  805. _textField.placeholder = ASLocalizedString(@"请输入您的评论");
  806. _comment_id = @"";
  807. [self tap];
  808. }
  809. }
  810. }else if(actionSheet.tag == 3)//自己对自己的更多去操作
  811. {
  812. if (buttonIndex == 0)
  813. {
  814. [self deleteDynamicWithString:self.weibo_id];
  815. }
  816. }
  817. }
  818. //去掉UItableview headerview黏性 ,table滑动到最上端时,header view消失掉。
  819. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  820. if (scrollView == _tableView)
  821. {
  822. CGFloat sectionHeaderHeight = 10;
  823. if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
  824. scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
  825. } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
  826. scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
  827. }
  828. }
  829. }
  830. @end