LeaderboardViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. //
  2. // LeaderboardViewController.m
  3. // BuguLive
  4. //
  5. // Created by yy on 16/10/11.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "LeaderboardViewController.h"
  9. #import "LeaderboardTableViewCell.h"
  10. #import "MBProgressHUD.h"
  11. #import "UserModel.h"
  12. #import "ConsumptionViewController.h"
  13. #import "ContributionViewController.h"
  14. #import "SHomePageVC.h"
  15. #import "SSearchVC.h"
  16. #import "BogoRankHeadGifView.h"
  17. NS_ENUM(NSInteger,leaderboardScroll)
  18. {
  19. Eleadboard_Regal, //富豪榜
  20. Eleadboard_Host, //主播榜
  21. Eleadboard_Count,
  22. };
  23. @interface LeaderboardViewController ()<UIScrollViewDelegate,SegmentViewDelegate,ListDayViewControllerDelegate>
  24. {
  25. UITableView *_listTableView;
  26. int _buttonCount; //button个数
  27. UIButton *_dayBoardBtn; //日榜
  28. UIButton *_monthBoardBtn; //月榜
  29. UIButton *_totalBoardbtn; //总榜
  30. UIButton *_meritBtn; //功德榜
  31. UIButton *_contriBtn; //贡献榜
  32. UIView *_topicView;
  33. UIView *_headView;
  34. NSArray *_listItems;
  35. UIScrollView *_tScrollView;
  36. CGRect _listSegmentFrame;
  37. ConsumptionViewController *_ConsumptionViewController; //功德榜
  38. ContributionViewController *_ContributionViewController; //贡献榜
  39. NSInteger _startPage; // 起始页
  40. }
  41. @property ( nonatomic, strong) JSBadgeView *badge;
  42. @property(nonatomic, strong) UIImageView *bgImgView;
  43. @property(nonatomic, strong) UIButton *leftButton;
  44. @end
  45. @implementation LeaderboardViewController
  46. - (void)viewWillAppear:(BOOL)animated
  47. {
  48. [super viewWillAppear:animated];
  49. _headView.hidden = NO;
  50. // [self loadBtnBadageData];
  51. [self.navigationController setNavigationBarHidden:YES animated:animated];
  52. }
  53. - (void)viewDidLoad
  54. {
  55. [super viewDidLoad];
  56. [self.view addSubview:self.bgImgView];
  57. SUS_WINDOW.window_Tap_Ges.enabled = NO;
  58. SUS_WINDOW.window_Pan_Ges.enabled = NO;
  59. _startPage = 1;
  60. self.view.backgroundColor = kNavBarThemeColor;
  61. //分段视图
  62. _listItems =[NSArray arrayWithObjects:ASLocalizedString(@"富豪榜"),ASLocalizedString(@"魅力榜"), nil];
  63. self.navigationItem.title = @"";
  64. [self leftOrRightNavItem];
  65. [self createHeadView];
  66. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(iMChatHaveNotification:) name:g_notif_chatmsg object:nil];
  67. }
  68. - (void)viewWillDisappear:(BOOL)animated
  69. {
  70. _headView.hidden = YES;
  71. }
  72. #pragma mark 导航栏部分
  73. //搜索
  74. - (void)searchClick
  75. {
  76. if (self.isHiddenTabbar)
  77. {
  78. [[AppDelegate sharedAppDelegate]popViewController];
  79. }else
  80. {
  81. SSearchVC *searchVC = [[SSearchVC alloc]init];
  82. searchVC.searchType = @"0";
  83. [[AppDelegate sharedAppDelegate] pushViewController:searchVC animated:YES];
  84. }
  85. }
  86. - (void)createHeadView
  87. {
  88. _headView = [[UIView alloc]initWithFrame:CGRectMake(0, kTopHeight - 44, 180, 44)];
  89. _headView.centerX = kScreenW / 2;
  90. _headView.backgroundColor = kRedColor;
  91. [self.view addSubview:_headView];
  92. // [self.navigationController.navigationBar addSubview:_headView];
  93. _listSegmentFrame = CGRectMake(0, 0, 180, 44);
  94. _listSegmentView = [[SegmentView alloc]initWithFrame:_listSegmentFrame andItems:_listItems andSize:16 border:NO isrankingRist:YES];
  95. _listSegmentView.centerX = _headView.width / 2;
  96. _listSegmentView.backgroundColor = kClearColor;
  97. _listSegmentView.delegate = self;
  98. [_listSegmentView setSelectIndex:0];
  99. _listSegmentView.backgroundColor = kClearColor;
  100. [_headView addSubview:_listSegmentView];
  101. _headView.backgroundColor = kClearColor;
  102. _headView.centerY = self.leftButton.centerY;
  103. if (self.isHiddenTabbar)
  104. {
  105. _tScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, _headView.bottom, self.view.frame.size.width, self.view.frame.size.height-kNavigationBarHeight-kStatusBarHeight)];
  106. }else
  107. {
  108. _tScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, _headView.bottom, self.view.frame.size.width, self.view.frame.size.height-kNavigationBarHeight-kStatusBarHeight-kTabBarHeight)];
  109. }
  110. _tScrollView.backgroundColor = kClearColor;
  111. _tScrollView.contentSize = CGSizeMake(Eleadboard_Count*kScreenW, 0);
  112. _tScrollView.pagingEnabled = YES;
  113. _tScrollView.bounces = NO;
  114. _tScrollView.showsHorizontalScrollIndicator = NO;
  115. _tScrollView.delegate = self;
  116. [self.view addSubview:_tScrollView];
  117. _tScrollView.contentOffset = CGPointMake(0, 0);
  118. //富豪榜
  119. if (!_ContributionViewController)
  120. {
  121. _ContributionViewController = [[ContributionViewController alloc]init];
  122. _ContributionViewController.isHiddenTabbar = self.isHiddenTabbar;
  123. _ContributionViewController.view.frame = CGRectMake(kScreenW * Eleadboard_Regal, 0, kScreenW, _tScrollView.bounds.size.height);
  124. _ContributionViewController.ContriDayViewController.delegate = self;
  125. _ContributionViewController.ContriMonthViewController.delegate = self;
  126. _ContributionViewController.ContriTotalViewController.delegate = self;
  127. if (self.hostLiveId.length)
  128. {
  129. _ContributionViewController.ContriDayViewController.hostLiveId = self.hostLiveId;
  130. _ContributionViewController.ContriMonthViewController.hostLiveId = self.hostLiveId;
  131. _ContributionViewController.ContriTotalViewController.hostLiveId = self.hostLiveId;
  132. }
  133. _ContributionViewController.view.backgroundColor = kClearColor;
  134. }
  135. [_tScrollView addSubview:_ContributionViewController.view];
  136. //富豪榜
  137. if (!_ConsumptionViewController)
  138. {
  139. _ConsumptionViewController = [[ConsumptionViewController alloc]init];
  140. _ConsumptionViewController.isHiddenTabbar = self.isHiddenTabbar;
  141. _ConsumptionViewController.view.frame = CGRectMake(kScreenW * Eleadboard_Host, 0, kScreenW, _tScrollView.bounds.size.height);
  142. _ConsumptionViewController.listDayViewController.delegate = self;
  143. _ConsumptionViewController.listMonthViewController.delegate = self;
  144. _ConsumptionViewController.listTotalViewController.delegate = self;
  145. if (self.hostLiveId.length)
  146. {
  147. _ConsumptionViewController.listDayViewController.hostLiveId = self.hostLiveId;
  148. _ConsumptionViewController.listMonthViewController.hostLiveId = self.hostLiveId;
  149. _ConsumptionViewController.listTotalViewController.hostLiveId = self.hostLiveId;
  150. }
  151. _ConsumptionViewController.view.backgroundColor = kClearColor;
  152. }
  153. [_tScrollView addSubview:_ConsumptionViewController.view];
  154. }
  155. - (void)leftOrRightNavItem
  156. {
  157. // 左上角按钮
  158. UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
  159. leftButton.frame = CGRectMake(kRealValue(10), kStatusBarHeight, kRealValue(35), kRealValue(35));
  160. // [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 35, kNavigationBarHeight)];
  161. if (self.isHiddenTabbar)
  162. {
  163. [leftButton setImage:[UIImage imageNamed:@"back_w"] forState:UIControlStateNormal];
  164. }
  165. else
  166. {
  167. [leftButton setImage:[UIImage imageNamed:@"hm_search"] forState:UIControlStateNormal];
  168. }
  169. [leftButton addTarget:self action:@selector(searchClick) forControlEvents:UIControlEventTouchUpInside];
  170. leftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  171. self.leftButton = leftButton;
  172. [self.view addSubview:leftButton];
  173. // UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
  174. //
  175. // self.navigationItem.leftBarButtonItem = leftBarButtonItem;
  176. // 右上角按钮
  177. UIButton *rightButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 35, kNavigationBarHeight)];
  178. [rightButton setImage:[UIImage imageNamed:@"hm_private_message"] forState:UIControlStateNormal];
  179. [rightButton addTarget:self action:@selector(clickedIMChat) forControlEvents:UIControlEventTouchUpInside];
  180. rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  181. UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
  182. self.navigationItem.rightBarButtonItem = rightButtonItem;
  183. // leftButton.hidden = YES;
  184. rightButton.hidden = YES;
  185. // 设置角标
  186. [self initBadgeBtn:rightButton];
  187. // [self loadBtnBadageData];
  188. }
  189. #pragma mark --SegmentView代理方法
  190. - (void)segmentView:(SegmentView*)segmentView selectIndex:(NSInteger)index
  191. {
  192. [UIView animateWithDuration:0.2f animations:^{
  193. _tScrollView.contentOffset = CGPointMake(_tScrollView.frame.size.width*index, 0);
  194. }];
  195. }
  196. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scroll
  197. {
  198. CGPoint offset = _tScrollView.contentOffset;
  199. NSInteger page = (offset.x + _tScrollView.frame.size.width/2) / _tScrollView.frame.size.width;
  200. // self.segmentView.indicatorView.hidden = NO;
  201. [_listSegmentView setSelectIndex:page];
  202. }
  203. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  204. {
  205. CGFloat pageWidth = scrollView.frame.size.width;
  206. NSInteger tmpPage = scrollView.contentOffset.x / pageWidth;
  207. float tmpPage2 = scrollView.contentOffset.x / pageWidth;
  208. NSInteger page = tmpPage2-tmpPage>=0.5 ? tmpPage+1 : tmpPage;
  209. if (_startPage != page)
  210. {
  211. [_listSegmentView setSelectIndex:page];
  212. _startPage = page;
  213. }
  214. }
  215. - (void)pushToHomePage:(UserModel *)model
  216. {
  217. SHomePageVC *homeVC = [[SHomePageVC alloc]init];
  218. homeVC.user_id = model.user_id;
  219. // homeVC.user_nickname =model.nick_name;
  220. homeVC.type = 0;
  221. if ([model.is_noble_ranking_stealth isEqualToString:@"1"] && ![model.user_id isEqualToString:[BGIMLoginManager sharedInstance].loginParam.identifier]) {
  222. [FanweMessage alertHUD:ASLocalizedString(@"不能查看神秘人信息")];
  223. return;
  224. }
  225. [[AppDelegate sharedAppDelegate]pushViewController:homeVC animated:YES];
  226. }
  227. #pragma mark - ----------------------- 私信消息、角标 -----------------------
  228. #pragma mark IM
  229. - (void)clickedIMChat
  230. {
  231. BGConversationSegmentController *chatListVC = [[BGConversationSegmentController alloc]init];
  232. [[AppDelegate sharedAppDelegate] pushViewController:chatListVC animated:YES];
  233. }
  234. - (void)iMChatHaveNotification:(NSNotification*)notification
  235. {
  236. //all 角标数据
  237. // [self loadBtnBadageData];
  238. }
  239. /**
  240. 设置 角标
  241. @param sender 对应的控件
  242. */
  243. - (void)initBadgeBtn:(UIButton *)sender
  244. {
  245. //-好友
  246. _badge = [[JSBadgeView alloc]initWithParentView:sender alignment:JSBadgeViewAlignmentTopRight];
  247. _badge.badgePositionAdjustment = CGPointMake(0, 12);
  248. }
  249. /**
  250. 获取角标的数据: 注意:调All未读/调好友&&非好友方法 算All时,别调后者2各和来算,里面有耗时操作
  251. 使用:1.在willApperar 2.SDK监听会发通知,通知的方法/block 里调用
  252. 给控件初始化一个角标
  253. badage的 数据 获取(个人页面获取所有未读的条数)
  254. 1.在willApear里调用一次 2.SDk消息变化,接受通知,在通知方法还要调用 用于更新 角标数据
  255. */
  256. - (void)loadBtnBadageData
  257. {
  258. [SFriendObj getAllUnReadCountComplete:^(int num) {
  259. //all
  260. int scount = num;
  261. if( scount )
  262. {
  263. if(scount > 98)
  264. {
  265. _badge.badgeText = @"99+";
  266. }
  267. else
  268. {
  269. _badge.badgeText = [NSString stringWithFormat:@"%d",scount];
  270. }
  271. }
  272. else
  273. {
  274. _badge.badgeText = nil;
  275. }
  276. }];
  277. }
  278. -(UIImageView *)bgImgView{
  279. if (!_bgImgView) {
  280. _bgImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, SCREEN_HEIGHT)];
  281. _bgImgView.image = [UIImage imageNamed:@"bogo_contributeList_BGImage"];
  282. BogoRankHeadGifView *headGifView = [[BogoRankHeadGifView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 320)];
  283. headGifView.backgroundColor = kClearColor;
  284. [_bgImgView addSubview:headGifView];
  285. }
  286. return _bgImgView;
  287. }
  288. @end