SHomePageVC_old.m 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. //
  2. // SHomePageVC.m
  3. // BuguLive
  4. //
  5. // Created by 丁凯 on 2017/7/4.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "SHomePageVC_old.h"
  9. #import "MainPageView.h"
  10. #import "HPContributionCell.h"
  11. #import "MJRefresh.h"
  12. #import "MainLiveTableViewCell.h"
  13. #import "FollowerViewController.h"
  14. #import "GetHeadImgViewController.h"
  15. #import "SSaveHeadViewVC.h"
  16. #import "MPCHeadView.h"
  17. #import "SHomeSVideoV.h"
  18. #import "SHomeLiveV.h"
  19. #import "SHomeInfoV.h"
  20. #import "BGVideoDetailController.h"
  21. #import "SHomeNavView.h"
  22. #import "SHomeDynamicView.h"
  23. #import "YHTimeLineListController.h"
  24. #import "MGSaveHeadImgViewController.h"
  25. #import "HMVideoPlayerViewController.h"
  26. #import "BogoShopKit.h"
  27. @interface SHomePageVC_old ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate,privateLetterDelegate,videoDeleGate,LiveDeleGate,MGTimeLineDidScrollViewDelegate>
  28. @property ( nonatomic, strong) MainPageView *bottomView; //底部的view
  29. @property ( nonatomic, strong) UIView *homeOrLiveView; //主页 直播 小视频的view
  30. @property ( nonatomic, strong) UIImageView *HLineView1; //横线1
  31. @property ( nonatomic, strong) UIView *VLineView; //竖线1
  32. @property ( nonatomic, strong) UIView *newestOrHotView; //最新 最热的view
  33. @property ( nonatomic, strong) NSMutableArray *imageArray; //贡献右边显示的头像
  34. @property ( nonatomic, strong) NSArray *countArray; //主页信息的个数
  35. @property ( nonatomic, strong) MPCHeadView *myTableHeadView; //myTableview的headView
  36. @property ( nonatomic, strong) UITableView *myTableView; //tableView
  37. @property ( nonatomic, strong) NSDictionary *liveDict; //进入直播的信息
  38. @property (nonatomic, strong) NSArray *nameArray;
  39. @property ( nonatomic, strong) UserModel *userModel; //用户信息的模型
  40. @property ( nonatomic, assign) BOOL isCouldLiveData; //是否可以加载
  41. @property ( nonatomic, assign) int currentPage; //当前页
  42. @property ( nonatomic, assign) int has_next; //是否还有下一页
  43. @property ( nonatomic, assign) BOOL canClickItem; //防止重复点击
  44. @property ( nonatomic, strong) UIScrollView *myScrollView; //滚动的ScrollView
  45. @property ( nonatomic, strong) SHomeInfoV *homeInfoV; //主页的view
  46. @property ( nonatomic, strong) SHomeLiveV *homeLiveV; //直播的view
  47. @property ( nonatomic, strong) SHomeSVideoV *smallVideoV; //小视频的view
  48. //@property ( nonatomic, strong) SHomeDynamicView *smallDynamicV;
  49. @property(nonatomic, strong) YHTimeLineListController *smallDynamicV;
  50. @property ( nonatomic, assign) NSInteger startPage; //起始页
  51. @property(nonatomic, strong) SHomeNavView *navView;
  52. @property(nonatomic, assign) BOOL isAttention;
  53. @end
  54. @implementation SHomePageVC_old{
  55. CGFloat _scrollOffsetHeight;
  56. }
  57. -(NSArray *)nameArray{
  58. if (!_nameArray) {
  59. _nameArray = @[ASLocalizedString(@"资料"),ASLocalizedString(@"动态"),ASLocalizedString(@"小视频")];
  60. }
  61. return _nameArray;
  62. }
  63. -(SHomeNavView *)navView{
  64. if (!_navView) {
  65. _navView = [[SHomeNavView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kTopHeight)];
  66. _navView.backgroundColor = kClearColor;
  67. [self.view bringSubviewToFront:_navView];
  68. __weak __typeof(self)weakSelf = self;
  69. _navView.clickBtnBlock = ^(NSInteger index) {
  70. if (index == 10) {
  71. [weakSelf leftAction];
  72. }else if (index == 11){
  73. // [weakSelf pushToVCWithIndex:101];
  74. FDActionSheet *actionSheet = [[FDActionSheet alloc] initWithTitle:@"" message:@""];
  75. [actionSheet addAction:[FDAction actionWithTitle:self.userModel.has_black.integerValue == 1 ?ASLocalizedString( @"解除拉黑") :ASLocalizedString( @"加入黑名单") type:FDActionTypeDefault CallBack:^{
  76. NSMutableDictionary *dictM = [[NSMutableDictionary alloc]init];
  77. [dictM setObject:@"user" forKey:@"ctl"];
  78. [dictM setObject:@"set_black" forKey:@"act"];
  79. [dictM setObject:[NSString stringWithFormat:@"%@",self->_user_id] forKey:@"to_user_id"];
  80. [self.httpsManager POSTWithParameters:dictM SuccessBlock:^(NSDictionary *responseJson)
  81. {
  82. NSMutableDictionary *mDict = [[NSMutableDictionary alloc]init];
  83. if ([responseJson toInt:@"status"] == 1)
  84. {
  85. self.userModel.has_black = [responseJson toString:@"has_black"];
  86. if (self.userModel.has_black.integerValue == 1)//未拉黑
  87. {
  88. [mDict setObject:@"0" forKey:@"isShowFollow"];
  89. }else if (self.userModel.has_black.integerValue == 0)//已拉黑
  90. {
  91. [mDict setObject:@"1" forKey:@"isShowFollow"];
  92. }
  93. if (self.user_id.length)
  94. {
  95. [mDict setObject:self.user_id forKey:@"userId"];
  96. }
  97. [[NSNotificationCenter defaultCenter]postNotificationName:@"liveIsShowFollow" object:mDict];
  98. }
  99. } FailureBlock:^(NSError *error)
  100. {
  101. }];
  102. }]];
  103. [actionSheet addAction:[FDAction actionWithTitle:ASLocalizedString(@"取消") type:FDActionTypeCancel CallBack:nil]];
  104. [actionSheet show:[UIApplication sharedApplication].keyWindow];
  105. }
  106. };
  107. }
  108. return _navView;
  109. }
  110. - (void)leftAction
  111. {
  112. // BOOL isFocus = self.myTableHeadView.concertBtn.
  113. if (self.clickHomePageBlock) {
  114. self.clickHomePageBlock(self.isAttention);
  115. }
  116. if (self.navigationController.viewControllers.count >1)
  117. {
  118. [self.navigationController popViewControllerAnimated:YES];
  119. }else
  120. {
  121. [self.navigationController dismissViewControllerAnimated:YES completion:nil];
  122. }
  123. }
  124. - (void)viewDidLoad
  125. {
  126. [super viewDidLoad];
  127. // 是否显示关注
  128. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(isShowFollow:) name:@"liveIsShowFollow" object:nil];
  129. self.view.backgroundColor = kWhiteColor;
  130. }
  131. - (void)viewWillAppear:(BOOL)animated
  132. {
  133. [super viewWillAppear:animated];
  134. // [[UIApplication sharedApplication] setStatusBarHidden:NO];
  135. [self.navigationController setNavigationBarHidden:YES animated:YES];
  136. // [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  137. [self.smallVideoV refreshHeader];
  138. }
  139. - (void)viewWillDisappear:(BOOL)animated
  140. {
  141. [super viewWillDisappear:animated];
  142. [self.navigationController setNavigationBarHidden:NO animated:YES];
  143. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
  144. }
  145. - (void)initFWUI
  146. {
  147. [super initFWUI];
  148. self.startPage = 0;
  149. self.currentPage = 1;
  150. self.canClickItem = YES;
  151. [self.view addSubview:self.bottomView];
  152. [self.view addSubview:self.myTableView];
  153. [self.view addSubview:self.navView];
  154. if (![self.user_id isEqualToString:[IMAPlatform sharedInstance].host.imUserId])
  155. {
  156. self.bottomView.hidden = NO;
  157. self.navView.rightBtn.hidden = NO;
  158. // [self.view addSubview:self.bottomView];
  159. }else
  160. {
  161. self.myTableHeadView.concertBtn.hidden = YES;
  162. self.navView.rightBtn.hidden = YES;
  163. self.bottomView.hidden = YES;
  164. CGRect rect = self.myTableView.frame;
  165. rect.size.height = kScreenH;
  166. self.myTableView.frame = rect;
  167. }
  168. }
  169. #pragma mark 是否显示关注通知的实现
  170. - (void)isShowFollow:(NSNotification *)notification
  171. {
  172. NSDictionary *interuptionDict = notification.object;
  173. if ([interuptionDict toString:@"userId"])
  174. {
  175. if ([[interuptionDict objectForKey:@"isShowFollow"] isEqualToString:@"1"]) {
  176. }else{
  177. // [self.myTableHeadView.concertBtn setTitle:ASLocalizedString(@"关注")forState:UIControlStateNormal];
  178. [self.myTableHeadView.concertBtn setBackgroundImage:[UIImage imageNamed:@"bogo_home_person_Concert_normal"] forState:UIControlStateNormal];
  179. self.isAttention = NO;
  180. // setImage:[UIImage imageNamed:@"bogo_home_person_Concert_normal"] forState:UIControlStateNormal];
  181. // bogo_home_person_Concert_select
  182. // [self.myTableHeadView.concertBtn setBackgroundImage:[UIImage imageNamed:@"mg_new_list_concert"] forState:UIControlStateNormal];
  183. // [self.myTableHeadView.concertBtn setBackgroundColor:kWhiteColor];
  184. self.myTableHeadView.concertBtn.layer.cornerRadius = 5;
  185. }
  186. }
  187. }
  188. - (void)initFWData
  189. {
  190. [super initFWData];
  191. [self loadHomeNetWithPage:1];
  192. [self showMyHud];
  193. }
  194. #pragma mark 数据加载
  195. //主页数据请求
  196. - (void)loadHomeNetWithPage:(int)page
  197. {
  198. NSMutableDictionary *parmDict = [[NSMutableDictionary alloc]init];
  199. [parmDict setObject:@"user" forKey:@"ctl"];
  200. if (self.user_id)
  201. {
  202. [parmDict setObject:self.user_id forKey:@"to_user_id"];
  203. }
  204. [parmDict setObject:@"user_home" forKey:@"act"];
  205. FWWeakify(self)
  206. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  207. FWStrongify(self)
  208. [self hideMyHud];
  209. if ([responseJson toInt:@"status"] == 1)
  210. {
  211. if ([responseJson objectForKey:@"user"] && [[responseJson objectForKey:@"user"] count])
  212. {
  213. self.user_headimg = [[responseJson objectForKey:@"user"] toString:@"head_image"];
  214. self.user_nickname = [[responseJson objectForKey:@"user"] toString:@"nick_name"];
  215. // [self changeAlaphViewUI];
  216. }
  217. //印票贡献前3名的图标
  218. NSArray *cuser_listArray = [responseJson objectForKey:@"cuser_list"];
  219. if (cuser_listArray)
  220. {
  221. if (cuser_listArray.count > 0 )
  222. {
  223. for (NSDictionary *dict in cuser_listArray)
  224. {
  225. SenderModel *model = [SenderModel new];
  226. model.head_image = [dict objectForKey:@"head_image"];
  227. [self.imageArray addObject:model.head_image];
  228. }
  229. }
  230. }
  231. //获取字典的个数
  232. // NSArray *itemArr = [NSArray modelArrayWithClass:<#(nonnull Class)#> json:<#(nonnull id)#>]
  233. NSArray *array = [[responseJson objectForKey:@"user"] objectForKey:@"new_item"];
  234. self.countArray = array;
  235. self.bottomView.has_focus = [responseJson toInt:@"has_focus"];
  236. self.bottomView.has_black = [responseJson toInt:@"has_black"];
  237. [self.bottomView changeState];
  238. // self.userModel = [UserModel mj_objectWithKeyValues:[responseJson objectForKey:@"user"]];
  239. UserModel *infomodel = [UserModel mj_objectWithKeyValues:[responseJson objectForKey:@"user"]];
  240. self.userModel = [UserModel mj_objectWithKeyValues:responseJson];
  241. self.userModel.shop_status = infomodel.shop_status;
  242. [self.myTableHeadView setViewWithModel:self.userModel withUserId:self.user_id];
  243. self.isAttention = [self.userModel.has_focus isEqualToString:@"1"];
  244. self.liveDict = responseJson[@"video"];
  245. [self.myTableHeadView setUIWithDict:self.liveDict];
  246. UserModel *model2 = [UserModel mj_objectWithKeyValues:self.liveDict];
  247. if (model2.live_in == FW_LIVE_STATE_ING)
  248. {
  249. // [self.navView.rightBtn setTitle:ASLocalizedString(@"直播中")forState:UIControlStateNormal];
  250. }
  251. // else if (model2.live_in == FW_LIVE_STATE_RELIVE)
  252. // {
  253. //// [self.navView.rightBtn setTitle:ASLocalizedString(@"回播中")forState:UIControlStateNormal];
  254. // }
  255. [self.homeInfoV setViewWithArray:self.countArray andMDict:self.userModel.user.item];
  256. if (self.liveDict) {
  257. UserModel *model2 = [UserModel mj_objectWithKeyValues:self.userModel.user.item];
  258. // if (model2.live_in == FW_LIVE_STATE_ING)
  259. // {
  260. // [self.navView.rightBtn setTitle:ASLocalizedString(@"直播中")forState:UIControlStateNormal];
  261. // }
  262. // else if (model2.live_in == FW_LIVE_STATE_RELIVE)
  263. // {
  264. // [self.navView.rightBtn setTitle:ASLocalizedString(@"回播中")forState:UIControlStateNormal];
  265. // }
  266. self.navView.rightBtn.hidden = [[IMAPlatform sharedInstance].host.imUserId isEqualToString:self.user_id];
  267. }else{
  268. }
  269. [self.myTableView reloadData];
  270. }
  271. [BGMJRefreshManager endRefresh:self.myTableView];
  272. } FailureBlock:^(NSError *error) {
  273. FWStrongify(self)
  274. [self hideMyHud];
  275. [BGMJRefreshManager endRefresh:self.myTableView];
  276. }];
  277. }
  278. #pragma mark 主页和直播的点击事件
  279. - (void)HLBtnClick:(UIButton *)btn
  280. {
  281. [self updateUIWithTag:(int)btn.tag];
  282. }
  283. - (void)updateUIWithTag:(int)tag
  284. {
  285. for (UIButton *newBtn in self.homeOrLiveView.subviews)
  286. {
  287. if ([newBtn isKindOfClass:[UIButton class]])
  288. {
  289. if (newBtn.tag ==tag)
  290. {
  291. [newBtn setTitleColor:kAppGrayColor1 forState:0];
  292. [UIView animateWithDuration:0.5 animations:^{
  293. self.HLineView1.centerX = newBtn.centerX;
  294. // CGRect rect = self.HLineView1.frame;
  295. // rect.origin.x = kScreenW/6 -25 + kScreenW*tag/3;
  296. // self.HLineView1.frame = rect;
  297. }];
  298. }else
  299. {
  300. [newBtn setTitleColor:kAppGrayColor3 forState:0];
  301. }
  302. }
  303. }
  304. [self.myTableView setContentOffset:CGPointMake(0,0)];
  305. [_myScrollView scrollRectToVisible:CGRectMake(tag * kScreenW, 0, kScreenW, CGRectGetHeight(_myScrollView.frame)) animated:YES];
  306. }
  307. #pragma mark -UITableViewDelegate&UITableViewDataSource
  308. //返回行数
  309. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  310. {
  311. return 1;
  312. }
  313. //返回cell高度
  314. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  315. {
  316. if (indexPath.section == HPZeroSection)
  317. {
  318. return kRealValue(50);
  319. }else if (indexPath.section == HPFirstSection)
  320. {
  321. return 0.01;
  322. // 10*kAppRowHScale;
  323. }else
  324. {
  325. return kScreenW;
  326. }
  327. }
  328. //返回段数
  329. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  330. {
  331. return HPTab_Count;
  332. }
  333. //返回单元格
  334. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  335. {
  336. int newNection = (int)indexPath.section;
  337. if (newNection == HPZeroSection)
  338. {
  339. HPContributionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HPContributionCell" forIndexPath:indexPath];
  340. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  341. [cell setCellWithArray:self.imageArray];
  342. return cell;
  343. }else if (newNection == 1)
  344. {
  345. static NSString *CellIdentifier0 = @"CellIdentifier0";
  346. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier0];
  347. if (!cell)
  348. {
  349. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0];
  350. cell.accessoryType = UITableViewCellAccessoryNone;
  351. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  352. cell.backgroundColor = kBackGroundColor;
  353. }
  354. return cell;
  355. }else
  356. {
  357. static NSString *CellIdentifier1 = @"CellIdentifier1";
  358. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
  359. if (!cell)
  360. {
  361. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1];
  362. cell.accessoryType = UITableViewCellAccessoryNone;
  363. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  364. cell.backgroundColor = kBackGroundColor;
  365. [cell.contentView addSubview:self.myScrollView];
  366. }
  367. return cell;
  368. }
  369. }
  370. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  371. {
  372. if (section == HPSecondSection)
  373. {
  374. return 45*kAppRowHScale;
  375. }else
  376. {
  377. return 0;
  378. }
  379. }
  380. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  381. {
  382. if (section == HPSecondSection)
  383. {
  384. return self.homeOrLiveView;
  385. }else
  386. {
  387. return nil;
  388. }
  389. }
  390. #pragma mark -- 进入正在直播的直播间
  391. -(void)joinRoom:(UserModel *)model
  392. {
  393. if (self.canClickItem)// 防止重复点击
  394. {
  395. self.canClickItem = NO;
  396. [self performSelector:@selector(changeClickState) withObject:nil afterDelay:2];
  397. }else{
  398. return;
  399. }
  400. if (![BGUtils isNetConnected])
  401. {
  402. return;
  403. }
  404. NSDictionary *dic = model.mj_keyValues;
  405. // 直播管理中心 开启观众直播
  406. // 开启直播(先API拿直播后台类型) 非悬浮 非小屏幕
  407. BOOL isSusWindow = [[LiveCenterManager sharedInstance] judgeIsSusWindow];
  408. BOOL isSmallScreen = [[LiveCenterManager sharedInstance] judgeIsSmallSusWindow];
  409. [[LiveCenterManager sharedInstance] showLiveOfAudienceLiveofPramaDic:dic.mutableCopy isSusWindow:isSusWindow isSmallScreen:isSmallScreen block:^(BOOL finished) {
  410. }];
  411. }
  412. - (void)changeClickState
  413. {
  414. self.canClickItem = YES;
  415. }
  416. #pragma mark 私信
  417. - (void)sentPersonLetter:(NSString*)taguserid
  418. {
  419. SFriendObj* chattag = [[SFriendObj alloc]initWithUserId:[self.user_id intValue]];
  420. chattag.mNick_name = self.user_nickname;
  421. chattag.mHead_image = self.user_headimg;
  422. BGConversationServiceController* chatvc = [BGConversationServiceController makeChatVCWith:chattag];
  423. //ykk
  424. //加判断 避免循环push
  425. //如果上个界面是 聊天信息VC
  426. for(UIViewController *last_C in self.navigationController.viewControllers)
  427. {
  428. if([last_C isKindOfClass:[BGConversationServiceController class]])
  429. {
  430. [self.navigationController popViewControllerAnimated:YES];
  431. return;
  432. }
  433. }
  434. [self.navigationController pushViewController:chatvc animated:YES];
  435. }
  436. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  437. {
  438. if (indexPath.section == HPZeroSection)
  439. {
  440. ContributionListViewController *contributionVC = [[ContributionListViewController alloc]init];
  441. contributionVC.user_id = self.user_id;
  442. contributionVC.type = @"1";
  443. [self.navigationController pushViewController:contributionVC animated:NO];
  444. }
  445. }
  446. - (void)comeBackTap
  447. {
  448. [[AppDelegate sharedAppDelegate]popViewController];
  449. }
  450. #pragma mark ===============================================getter方法===================================================
  451. #pragma mark 主页和直播
  452. - (UIView *)homeOrLiveView
  453. {
  454. if (!_homeOrLiveView)
  455. {
  456. _homeOrLiveView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 45*kAppRowHScale)];
  457. _homeOrLiveView.backgroundColor = kWhiteColor;
  458. CGFloat btnWidth = kScreenW / _nameArray.count - kRealValue(10);
  459. for (int i = 0; i < _nameArray.count; i ++)
  460. {
  461. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  462. button.frame = CGRectMake(btnWidth*i ,10,btnWidth, 40);
  463. [button setTitle:_nameArray[i] forState:0];
  464. button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
  465. if (self.type == i)
  466. {
  467. [button setTitleColor:kAppGrayColor1 forState:UIControlStateNormal];
  468. button.titleLabel.font = [UIFont boldSystemFontOfSize:14];
  469. }else
  470. {
  471. [button setTitleColor:kAppGrayColor3 forState:UIControlStateNormal];
  472. button.titleLabel.font = [UIFont systemFontOfSize:14];
  473. }
  474. button.tag = i;
  475. [button addTarget:self action:@selector(HLBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  476. [_homeOrLiveView addSubview:button];
  477. // if (i < nameArray.count -1)
  478. // {
  479. // UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(kScreenW*(i+1)/3 - 1, (45-15)*kAppRowHScale/2, 1,15*kAppRowHScale)];
  480. // lineView.backgroundColor = kAppSpaceColor4;
  481. // [_homeOrLiveView addSubview:lineView];
  482. // }
  483. }
  484. self.HLineView1 = [[UIImageView alloc]init];
  485. self.HLineView1.frame = CGRectMake(kScreenW/6 -25 +kScreenW*(self.type)/3, 45*kAppRowHScale - 10, 20, 3);
  486. [self.HLineView1 setImage:[UIImage imageNamed:@"mg_text_bottomView"]];
  487. self.HLineView1.centerX = btnWidth / 2;
  488. [_homeOrLiveView addSubview:self.HLineView1];
  489. UIView *view = [[UIView alloc]initWithFrame:CGRectMake( kRealValue(10),0, kScreenW - kRealValue(10 * 2),1)];
  490. view.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
  491. [_homeOrLiveView addSubview:view];
  492. }
  493. return _homeOrLiveView;
  494. }
  495. - (UITableView *)myTableView
  496. {
  497. if (!_myTableView)
  498. {
  499. _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0,-22 - MG_BOTTOM_MARGIN, kScreenW, kScreenH-50)];
  500. _myTableView.backgroundColor = kBackGroundColor;
  501. _myTableView.dataSource = self;
  502. _myTableView.delegate = self;
  503. self.myTableHeadView = [[MPCHeadView alloc]initWithFrame:CGRectMake(0,0 , kScreenW,kRealValue(387)) andHeadType:2];
  504. // self.myTableHeadView.clearView.backgroundColor = kWhiteColor;
  505. FWWeakify(self)
  506. [self.myTableHeadView setHeadViewBlock:^(int btnIndex){
  507. FWStrongify(self)
  508. [self pushToVCWithIndex:btnIndex];
  509. }];
  510. [self.myTableHeadView setHeadViewAttentionBlock:^(BOOL isAttention) {
  511. FWStrongify(self)
  512. self.isAttention = isAttention;
  513. self.bottomView.has_black = isAttention ? 0 : 1;
  514. if (isAttention) [self.bottomView changeState];
  515. }];
  516. self.myTableHeadView.headViewBgImageBlock = ^(UIImage *image) {
  517. FWStrongify(self)
  518. MGSaveHeadImgViewController *vc = [[MGSaveHeadImgViewController alloc]initWithHeadImageWithImage:image];
  519. [self.navigationController pushViewController:vc animated:YES];
  520. };
  521. _myTableView.tableHeaderView = self.myTableHeadView;
  522. _myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  523. [_myTableView registerNib:[UINib nibWithNibName:@"HPContributionCell" bundle:nil] forCellReuseIdentifier:@"HPContributionCell"];
  524. }
  525. return _myTableView;
  526. }
  527. - (void)pushToVCWithIndex:(int)btnTag
  528. {
  529. switch (btnTag) {
  530. case 100:
  531. {
  532. if ([self.navigationController topViewController] == self)
  533. { //如果有导航控制器,并且顶部就是自己,那么应该返回
  534. if (self.navigationController.viewControllers.count == 1)
  535. { //如果只有一个
  536. if (self.presentingViewController)
  537. { //如果有就dismiss
  538. [self dismissViewControllerAnimated:YES
  539. completion:^{
  540. }];
  541. return;
  542. }
  543. }
  544. else
  545. {
  546. [self.navigationController popViewControllerAnimated:NO];
  547. }
  548. }
  549. else //其他情况,就再判断是否有 presentingViewController
  550. {
  551. if (self.presentingViewController)
  552. { //如果有就dismiss
  553. [self dismissViewControllerAnimated:YES
  554. completion:^{
  555. }];
  556. return;
  557. }
  558. }
  559. }
  560. break;
  561. case 101:
  562. {
  563. if ([self.BuguLive.liveState.roomId intValue]>0)
  564. {
  565. [FanweMessage alertHUD:ASLocalizedString(@"当前有视频正在播放")];
  566. }
  567. else
  568. {
  569. UserModel *liveModel = [UserModel mj_objectWithKeyValues:self.liveDict];
  570. [self joinRoom:liveModel];
  571. }
  572. }
  573. break;
  574. case 102:
  575. {
  576. SSaveHeadViewVC *headVC = [[SSaveHeadViewVC alloc]init];
  577. headVC.url = [NSURL URLWithString:self.userModel.user.head_image];
  578. [[AppDelegate sharedAppDelegate]pushViewController:headVC animated:YES];
  579. }
  580. break;
  581. case 103:
  582. {
  583. //送出 没有,个人中心才有
  584. }
  585. break;
  586. case 104:
  587. {
  588. //送出 没有,没有点击事件
  589. BogoOtherShopDetailViewController *shopVC = [[BogoOtherShopDetailViewController alloc]initWithNibName:@"BogoOtherShopDetailViewController" bundle:kShopKitBundle];
  590. shopVC.user_id = self.user_id;
  591. [self.navigationController pushViewController:shopVC animated:YES];
  592. }
  593. break;
  594. case 105:
  595. {
  596. FollowerViewController *followVC = [[FollowerViewController alloc]init];
  597. followVC.user_id = self.user_id;
  598. followVC.type = @"1";
  599. [self.navigationController pushViewController:followVC animated:NO];
  600. // [[AppDelegate sharedAppDelegate] pushViewController:followVC animated:YES];
  601. }
  602. break;
  603. case 106:
  604. {
  605. FollowerViewController *followVC = [[FollowerViewController alloc]init];
  606. followVC.user_id = self.user_id;
  607. followVC.type = @"2";
  608. [self.navigationController pushViewController:followVC animated:NO];
  609. // [[AppDelegate sharedAppDelegate] pushViewController:followVC animated:YES];
  610. }
  611. break;
  612. default:
  613. break;
  614. }
  615. }
  616. -(void)didVideoCollectionViewScrollView:(UIScrollView *)scrollView{
  617. CGFloat offset = scrollView.contentOffset.y;
  618. NSLog(@"%f",offset);
  619. // CGFloat scrollHeight = self.navView.height + _homeOrLiveView.height + _bottomView.height;
  620. CGFloat homeOrLiveTop = self.myTableHeadView.height + self.homeOrLiveView.height - 45*kAppRowHScale - self.navView.height;
  621. if (offset > homeOrLiveTop) {
  622. [self.myTableView setContentOffset:CGPointMake(0, homeOrLiveTop)];
  623. return;
  624. }
  625. [self.myTableView setContentOffset:CGPointMake(0, offset < 0 ? 0 : offset)];
  626. // [self.myScrollView setContentOffset:CGPointMake(kScreenW * 2, offset < 0 ? 0 : offset)];
  627. // self.myScrollView.height = self.smallVideoV.height = self.smallVideoV.videoCollectionV.height = kScreenH - homeOrLiveTop + 44 - MG_BOTTOM_MARGIN * 3;
  628. // self.myTableView.height = self.myScrollView.height = self.smallVideoV.height = self.smallVideoV.videoCollectionV.height = self.smallVideoV.videoCollectionV.height = kScreenH - kTopHeight - MG_BOTTOM_MARGIN - self.bottomView.height;
  629. NSLog(@"offsetoffsetoffset%f",offset);
  630. NSLog(@"%f",kScreenH - kTopHeight - MG_BOTTOM_MARGIN - self.bottomView.height);
  631. // kScreenH - homeOrLiveTop - self.bottomView.height - MG_BOTTOM_MARGIN + 45*kAppRowHScale ;
  632. [self didDynamicCollectionViewScrollView:scrollView];
  633. }
  634. -(void)didDynamicCollectionViewScrollView:(UIScrollView *)scrollView{
  635. CGFloat offset = scrollView.contentOffset.y;
  636. CGFloat homeOrLiveTop = self.myTableHeadView.height + self.homeOrLiveView.height - 45*kAppRowHScale - self.navView.height - 50 - kStatusBarHeight;
  637. if (offset > homeOrLiveTop) {
  638. [self.myTableView setContentOffset:CGPointMake(0, homeOrLiveTop)];
  639. return;
  640. }
  641. [self.myTableView setContentOffset:CGPointMake(0, offset < 0 ? 0 : offset)];
  642. self.myScrollView.height = self.smallDynamicV.view.height = self.smallDynamicV.tableView.height = kScreenH - homeOrLiveTop - self.bottomView.height - MG_BOTTOM_MARGIN ;
  643. // self.smallVideoV.height = self.smallVideoV.videoCollectionV.height = kScreenH - homeOrLiveTop + 44;
  644. [self scrollViewDidScroll:scrollView];
  645. }
  646. -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
  647. if (scrollView.contentOffset.y > kScreenH * 0.1) {
  648. self.navView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4];
  649. }else if (scrollView.contentOffset.y < 0 || scrollView.contentOffset.y == 0){
  650. self.navView.backgroundColor = kClearColor;
  651. }
  652. NSLog(@"contentOffsetcontentOffsetY:%f",scrollView.contentOffset.y);
  653. }
  654. - (UIView *)bottomView
  655. {
  656. if (!_bottomView)
  657. {
  658. _bottomView = [[[NSBundle mainBundle]loadNibNamed:@"MainPageView" owner:self options:nil] objectAtIndex:0];
  659. _bottomView.delegate = self;
  660. _bottomView.user_id = self.user_id;
  661. _bottomView.frame = CGRectMake(0,kScreenH - 60 - MG_BOTTOM_MARGIN,kScreenW,60);
  662. _bottomView.backgroundColor = kClearColor;
  663. }
  664. return _bottomView;
  665. }
  666. - (NSMutableArray *)imageArray
  667. {
  668. if (!_imageArray)
  669. {
  670. _imageArray = [[NSMutableArray alloc]init];
  671. }
  672. return _imageArray;
  673. }
  674. - (UIScrollView *)myScrollView
  675. {
  676. if (!_myScrollView)
  677. {
  678. _myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreenW,kScreenW)];
  679. _myScrollView.delegate = self;
  680. _myScrollView.backgroundColor = kBackGroundColor;
  681. _myScrollView.pagingEnabled = YES;
  682. _myScrollView.scrollEnabled = NO;
  683. _myScrollView.contentSize = CGSizeMake(kScreenW * self.nameArray.count, CGRectGetHeight(_myScrollView.frame));
  684. self.homeInfoV = [[SHomeInfoV alloc]initWithFrame:CGRectMake(0, 0, kScreenW, _myScrollView.height - 60 + MG_BOTTOM_MARGIN) ];
  685. [_myScrollView addSubview:self.homeInfoV];
  686. // self.homeLiveV = [[SHomeLiveV alloc]initWithFrame:CGRectMake(kScreenW, 0, kScreenW, _myScrollView.height - 60 + MG_BOTTOM_MARGIN) andUserId:self.user_id];
  687. // self.homeLiveV.LDelegate = self;
  688. // [_myScrollView addSubview:self.homeLiveV];
  689. self.smallDynamicV = [[YHTimeLineListController alloc]initWithIndexAct:MGDTHOMETYPE_MY withUID:self.user_id];
  690. self.smallDynamicV.vDelegate = self;
  691. [self addChild:self.smallDynamicV];
  692. self.smallDynamicV.view.frame = CGRectMake(kScreenW, -kStatusBarHeight, kScreenW, _myScrollView.height + kStatusBarHeight);
  693. self.smallDynamicV.tableView.frame = CGRectMake(0, 0, kScreenW, _myScrollView.height);
  694. [_myScrollView addSubview:self.smallDynamicV.view];
  695. self.smallVideoV = [[SHomeSVideoV alloc]initWithFrame:CGRectMake(kScreenW * 2, 0, kScreenW, _myScrollView.height) andUserId:self.user_id];
  696. self.smallVideoV.VDelegate = self;
  697. [_myScrollView addSubview:self.smallVideoV];
  698. }
  699. return _myScrollView;
  700. }
  701. - (void)goToLiveRoomWithModel:(UserModel *)model andView:(SHomeLiveV *)homeLiveView
  702. {
  703. [self joinRoom:model];
  704. }
  705. - (void)pushToVideoDetailWithWeiboId:(NSString *)weiboId andView:(SHomeSVideoV *)homeSVideoV
  706. {
  707. BGVideoDetailController *VideoVC = [[BGVideoDetailController alloc]init];
  708. VideoVC.weibo_id = weiboId;
  709. // [[AppDelegate sharedAppDelegate] pushViewController:VideoVC animated:YES];
  710. [self.navigationController pushViewController:VideoVC animated:NO];
  711. }
  712. -(void)pushToVideoDetailWithArr:(NSArray *)videos index:(NSInteger)index IsPushed:(BOOL)isPushed requestDict:(NSDictionary *)dict{
  713. HMVideoPlayerViewController *vc = [[HMVideoPlayerViewController alloc]initWithVideos:videos index:index IsPushed:YES requestDict:nil];
  714. vc.isRefreshVideoBlock = ^(BOOL isRefresh) {
  715. // [self refreshHeader];
  716. };
  717. [self.navigationController pushViewController:vc animated:YES];
  718. }
  719. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  720. {
  721. if (scrollView == _myScrollView)
  722. {
  723. CGFloat pageWidth = scrollView.frame.size.width;
  724. NSInteger tmpPage = scrollView.contentOffset.x / pageWidth;
  725. float tmpPage2 = scrollView.contentOffset.x / pageWidth;
  726. NSInteger page = tmpPage2-tmpPage>=0.5 ? tmpPage+1 : tmpPage;
  727. if (_startPage != page)
  728. {
  729. [self updateUIWithTag:(int)page];
  730. _startPage = page;
  731. }
  732. }
  733. }
  734. @end