| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800 |
- //
- // HMHomeViewController.m
- // BuguLive
- //
- // Created by xfg on 2017/6/29.
- // Copyright © 2017年 xfg. All rights reserved.
- //
- #import "HMHomeViewController.h"
- #import "SSearchVC.h"
- #import "UpgradeTipView.h"
- #import "SHomePageVC.h"
- #import "BGConversationSegmentController.h"
- #import "VideoViewController.h"
- #import "SocietyDetailVC.h"
- #import "SociatyListModel.h"
- #import "SocietyHomePageVC.h"
- #import "SChooseAreaView.h"
- #import "EveryDayFirstLoginPopView.h"/**<每日首次登录奖励*/
- // 动态项,便于后期拓展以及灵活组装
- static NSString const *kFocusOnStr = @"关注";
- static NSString const *kHotStr = @"热门";
- static NSString const *kNearbyStr = @"附近";
- static float const kSegmentLeftEdge = 10; // segmentedControl左边边距
- static float const kSegmentTitleFont = 15; // segmentedControl字体大小
- static NSInteger const kSelectedSegmentIndex = 1; // segmentedControl默认选中的index
- @interface HMHomeViewController ()<UIScrollViewDelegate, handleMainDelegate, PushToLiveControllerDelegate, HMHotViewControllerDelegate, SocietyHomePageVCDelegate>
- {
- JSBadgeView *_badge;
- BOOL _isFirstLoad; // 是否首次加载
- NSString *_oldSocietyListName; // 公会名称可以修改,修改前的公会名字
- NSString *_societyListName; // 公会名称
- UIButton *_addressBtn;
- }
- @property (nonatomic, strong) HMHotViewController *hotViewController; // 热门
- @property (nonatomic, strong) FocusOnViewController *focusOnViewController; // 关注
- @property (nonatomic, strong) NewestViewController *livingListViewController; // 最新
- @property (nonatomic, strong) NewestViewController *news_hotViewController; // 最新
- @property (nonatomic, strong) SocietyHomePageVC *societyHomePage; // 公会
- @property (nonatomic, strong) UIScrollView *scrollView; // ScrollView
- @property (nonatomic, strong) HMSegmentedControl *segmentedControl; // Segmented
- @property (nonatomic, strong) NSTimer *refreshHomeTimer; // 首页定时刷新
- @property (nonatomic, assign) BOOL isRefreshing; // 是否正在刷新
- @property (nonatomic, assign) NSInteger startPage; // Segmented的滑块起始页
- @property (nonatomic, assign) BOOL isClickedSegmented; // 是否点击了Segmented的滑块
- @property (nonatomic, strong) SChooseAreaView *chooseAreaView; // 地区选择
- @property (nonatomic, assign) int sexType; // 性别
- @property (nonatomic, strong) NSMutableArray *itemTitleMutableArray; // 完整的分类标题容器
- @property (nonatomic, strong) NSMutableArray<VideoClassifiedModel *> *classifiedModelMutableArray; // 服务端下发分类的模型容器
- @property (nonatomic, strong) NSMutableArray<VideoViewController *> *videoVCMutableArray; // 服务端下发分类的对应的控制器容器
- @end
- @implementation HMHomeViewController
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
-
- [self loadClassifiedVC];
-
- [self loadBtnBadageData];
-
- [self.navigationController setNavigationBarHidden:YES animated:NO];
-
- // 加载礼物列表
- [[GiftListManager sharedInstance] reloadGiftList];
-
- [self setupTimer];
- }
- - (void)viewDidAppear:(BOOL)animated
- {
- [super viewDidAppear:animated];
-
- if (!_isFirstLoad)
- {
- [self refreshOfTime];
- }
- _isFirstLoad = NO;
- }
- - (void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [self.navigationController setNavigationBarHidden:NO animated:NO];
- [self invalidateTimer];
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // self.navigationController.navigationBar.hidden = YES;
- }
- - (void)initFWUI
- {
- [super initFWUI];
-
- [BGIMMsgHandler sharedInstance];
-
- self.navigationItem.title = @"";
-
- self.BuguLive.appNavigationBarHeight = self.navigationController.navigationBar.frame.size.height;
- self.BuguLive.appTabBarHeight = self.tabBarController.tabBar.frame.size.height;
-
- _startPage = kSelectedSegmentIndex;
-
- _videoVCMutableArray = [NSMutableArray array];
- _oldSocietyListName = self.BuguLive.appModel.society_list_name;
-
- CGFloat viewWidth = CGRectGetWidth(self.view.frame);
- CGFloat viewHeight = CGRectGetHeight(self.view.frame);
-
- #if kSupportH5Shopping
- self.itemTitleMutableArray = [NSMutableArray arrayWithObjects:kFocusOnStr, kHotStr, nil];
- #else
- // 配置本地分类
- self.itemTitleMutableArray = [NSMutableArray arrayWithObjects:kFocusOnStr, kHotStr, kNearbyStr, nil];
- #endif
-
- self.segmentedControl = [[HMSegmentedControl alloc] initWithFrame:CGRectMake(60, kStatusBarHeight, viewWidth - 60 - 80 , kSegmentedHeight)];
- self.segmentedControl.sectionTitles = self.itemTitleMutableArray;
- self.segmentedControl.selectedSegmentIndex = kSelectedSegmentIndex;
- self.segmentedControl.backgroundColor = kWhiteColor;
- self.segmentedControl.titleTextAttributes = @{NSForegroundColorAttributeName : kAppGrayColor3, NSFontAttributeName : [UIFont systemFontOfSize:kSegmentTitleFont]};
- self.segmentedControl.selectedTitleTextAttributes = @{NSForegroundColorAttributeName : kAppMainColor, NSBackgroundColorAttributeName : kClearColor, NSFontAttributeName : [UIFont systemFontOfSize:kSegmentTitleFont]};
- self.segmentedControl.selectionIndicatorColor = kAppMainColor;
- self.segmentedControl.selectionIndicatorHeight = 3;
- self.segmentedControl.selectionIndicatorBoxColor = kClearColor;
- self.segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleTextWidthStripe;
- self.segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
- self.segmentedControl.segmentEdgeInset = UIEdgeInsetsMake(0, kSegmentLeftEdge, 0, kSegmentLeftEdge);
- self.segmentedControl.segmentWidthStyle = HMSegmentedControlSegmentWidthStyleDynamicFixedSuperView;
- self.segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
- FWWeakify(self)
- [self.segmentedControl setIndexChangeBlock:^(NSInteger index) {
-
- FWStrongify(self)
- [self.scrollView scrollRectToVisible:CGRectMake(viewWidth * index, 0, viewWidth, CGRectGetHeight(self.scrollView.frame)) animated:YES];
- [self loadClassifiedVC];
-
- [self refreshClassifiedVC:index];
- if (index == 1) {
- if (self.chooseAreaView) {
- [self removeChooseView];
- }
- }
-
- self.isClickedSegmented = YES;
- }];
-
- [self.view addSubview:self.segmentedControl];
- self.navigationController.navigationBar.hidden = YES;
- // [self.navigationController setNavigationBarHidden:<#(BOOL)#>]
- // [self.navigationController.navigationBar addSubview:_segmentedControl];
-
- self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, _segmentedControl.bottom, viewWidth, viewHeight - kSegmentedHeight-kTabBarHeight - 20)];
- self.scrollView.delegate = self;
- self.scrollView.backgroundColor = kClearColor;
- self.scrollView.pagingEnabled = YES;
- self.scrollView.showsHorizontalScrollIndicator = NO;
- self.scrollView.bounces = NO;
- self.scrollView.contentSize = CGSizeMake(viewWidth * [self.itemTitleMutableArray count], CGRectGetHeight(self.scrollView.frame));
- [self.scrollView scrollRectToVisible:CGRectMake(kSelectedSegmentIndex * viewWidth, 0, viewWidth, CGRectGetHeight(self.scrollView.frame)) animated:NO];
- [self.view addSubview:self.scrollView];
-
- // 关注
- if ([self.itemTitleMutableArray containsObject:kFocusOnStr])
- {
- _focusOnViewController = [[FocusOnViewController alloc]init];
- _focusOnViewController.collectionViewFrame = CGRectMake(0, 0, viewWidth, _scrollView.frame.size.height);
- _focusOnViewController.view.frame = CGRectMake(viewWidth * [self.itemTitleMutableArray indexOfObject:kFocusOnStr], 0, viewWidth, _scrollView.bounds.size.height);
- _focusOnViewController.delegate = self;
- [_scrollView addSubview:_focusOnViewController.view];
- }
-
- // 热门
- if ([self.itemTitleMutableArray containsObject:kHotStr])
- {
-
- _news_hotViewController = [[NewestViewController alloc]init];
- _news_hotViewController.types = @"1";
- _news_hotViewController.collectionViewFrame = CGRectMake(0, 0, viewWidth, _scrollView.bounds.size.height);
- _news_hotViewController.view.frame = CGRectMake(viewWidth * [self.itemTitleMutableArray indexOfObject:kHotStr], 0, viewWidth, _scrollView.bounds.size.height);
- _news_hotViewController.delegate = self;
- [_scrollView addSubview:_news_hotViewController.view];
- // _hotViewController = [[HMHotViewController alloc]init];
- // _hotViewController.tableViewFrame = CGRectMake(0, 0, viewWidth, _scrollView.bounds.size.height);
- // _hotViewController.view.frame = CGRectMake(viewWidth * [self.itemTitleMutableArray indexOfObject:kHotStr], 0, viewWidth, _scrollView.bounds.size.height);
- // _hotViewController.delegate = self;
- // _hotViewController.areaString = [NSString stringWithFormat:@"%@",kHotStr];
- // [_scrollView addSubview:_hotViewController.view];
- }
-
- // 附近
- if ([self.itemTitleMutableArray containsObject:kNearbyStr])
- {
- _livingListViewController = [[NewestViewController alloc]init];
- _livingListViewController.collectionViewFrame = CGRectMake(0, 0, viewWidth, _scrollView.bounds.size.height);
- _livingListViewController.types = @"2";
- _livingListViewController.view.frame = CGRectMake(viewWidth * [self.itemTitleMutableArray indexOfObject:kNearbyStr], 0, viewWidth, _scrollView.bounds.size.height);
- _livingListViewController.delegate = self;
- [_scrollView addSubview:_livingListViewController.view];
- }
-
- [self loadClassifiedVC];
-
- [self leftOrRightNavItem];
-
- [self.BuguLive addObserver:self forKeyPath:@"appModel.video_classified" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
-
- // 升级提示等
- UpgradeTipView *upgradeTipView = [[UpgradeTipView alloc] init];
- [upgradeTipView initRewards];
- }
- - (void)initFWData
- {
- [super initFWData];
-
- _isFirstLoad = YES;
- _isRefreshing = YES;
- //
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateTitleName:) name:@"updateTitleName" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(invalidateTimer) name:kInvalidateHomeTimer object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshHome) name:kRefreshHome object:nil];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self loadBtnBadageData];
- });
- }
- - (void)leftOrRightNavItem
- {
- #if kSupportH5Shopping
- UIButton *rightButton = [[UIButton alloc]initWithFrame:CGRectMake(6, 22, 20, 20)];
- [rightButton setImage:[UIImage imageNamed:@"hm_search"] forState:UIControlStateNormal];
- [rightButton addTarget:self action:@selector(goSearch) forControlEvents:UIControlEventTouchUpInside];
- UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
- self.navigationItem.rightBarButtonItem = leftBarButtonItem;
- #else
- // 左上角按钮
- UIButton *leftButton = [[UIButton alloc]initWithFrame:CGRectMake(20, kStatusBarHeight, 35, kNavigationBarHeight)];
- [leftButton setImage:[UIImage imageNamed:@"hm_search"] forState:UIControlStateNormal];
- [leftButton addTarget:self action:@selector(goSearch) forControlEvents:UIControlEventTouchUpInside];
- leftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
-
- // self.navigationItem.leftBarButtonItem = leftBarButtonItem;
- [self.view addSubview:leftButton];
-
- // 右上角按钮
- UIView *rightViewContrainer = [[UIView alloc] initWithFrame:CGRectMake(kScreenW - 70 - 10, kStatusBarHeight, 70, kNavigationBarHeight)];
- rightViewContrainer.backgroundColor = kClearColor;
-
- UIButton *rightButton = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetWidth(rightViewContrainer.frame)-35, 0, 35, rightViewContrainer.frame.size.height)];
- [rightButton setImage:[UIImage imageNamed:@"hm_private_message"] forState:UIControlStateNormal];
- [rightButton addTarget:self action:@selector(clickRightHeadBtn:) forControlEvents:UIControlEventTouchUpInside];
- rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
- [rightViewContrainer addSubview:rightButton];
-
- _addressBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 35, rightViewContrainer.frame.size.height)];
- [_addressBtn setImage:[UIImage imageNamed:@"hm_address"] forState:UIControlStateNormal];
- [_addressBtn addTarget:self action:@selector(clickRightHeadBtn:) forControlEvents:UIControlEventTouchUpInside];
- _addressBtn.tag = 1;
- _addressBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
- [rightViewContrainer addSubview:_addressBtn];
- [self.view addSubview:rightViewContrainer];
- [self.view addSubview:leftButton];
- // UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightViewContrainer];
- // self.navigationItem.rightBarButtonItem = rightButtonItem;
-
- // 设置角标
- [self initBadgeBtn:rightButton];
- #endif
- }
- #pragma mark 动态加载初始化接口下发的分类、公会等
- - (void)loadClassifiedVC
- {
- CGFloat viewWidth = CGRectGetWidth(self.view.frame);
-
- // 动态添加、删除公会
- if (self.BuguLive.appModel.open_society_module.intValue == 1 && ![BGUtils isBlankString:self.BuguLive.appModel.society_list_name])
- {
- _societyListName = self.BuguLive.appModel.society_list_name;
- if (![_societyListName isEqualToString:_oldSocietyListName] && [self.itemTitleMutableArray containsObject:_oldSocietyListName])//修改了公会名字并且原来有公会就替换
- {
- NSInteger index = [self.itemTitleMutableArray indexOfObject:_oldSocietyListName];
- [self.itemTitleMutableArray replaceObjectAtIndex:index withObject:_societyListName];
- _oldSocietyListName = _societyListName;
- }else if(![_societyListName isEqualToString:_oldSocietyListName] && ![self.itemTitleMutableArray containsObject:_oldSocietyListName])//修改了公会名字并且原来没有公会加上去
- {
- [self.itemTitleMutableArray addObject:_societyListName];
- _oldSocietyListName = _societyListName;
- }else
- {
- if (![self.itemTitleMutableArray containsObject:_societyListName])
- {
- [self.itemTitleMutableArray addObject:_societyListName];
- }
- }
-
- if (!self.societyHomePage.view.superview)
- {
- self.societyHomePage.view.frame = CGRectMake(viewWidth * [self.itemTitleMutableArray indexOfObject:_societyListName], 0, viewWidth, _scrollView.bounds.size.height);
- [self.scrollView addSubview:self.societyHomePage.view];
- }
- }
- else if (self.BuguLive.appModel.open_society_module.intValue == 0 && [self.itemTitleMutableArray containsObject:_societyListName])
- {
- [self.itemTitleMutableArray removeObject:_societyListName];
-
- [self.societyHomePage.view removeFromSuperview];
- }
-
- if (![self.BuguLive.appModel.video_classified isEqual:self.classifiedModelMutableArray])
- {
- [self updateClassiFiedVC];
- }
- }
- - (void)updateClassiFiedVC
- {
- CGFloat viewWidth = CGRectGetWidth(self.view.frame);
- @synchronized (self)
- {
- if (self.classifiedModelMutableArray.count > 0)
- {
- // 获取到本地暂存的服务端下发的分类的在完整的分类容器中的起点与终点,进行移除视频分类相关视图和视图控制器的操作
- VideoClassifiedModel *tmpModel = [self.classifiedModelMutableArray firstObject];
- NSInteger tmpIndex = [self.itemTitleMutableArray indexOfObject:tmpModel.title];
- VideoClassifiedModel *lastVideoModel = [self.classifiedModelMutableArray lastObject];
- NSInteger lastIndex = [self.itemTitleMutableArray indexOfObject:lastVideoModel.title];
- [self.videoVCMutableArray removeAllObjects];
- for (NSInteger i = tmpIndex; i <= lastIndex; i++)
- {
- if (self.scrollView.subviews.count > i)
- {
- [self.scrollView.subviews[i] removeFromSuperview];
- }
- }
-
- // 动态删除视频分类
- for (VideoClassifiedModel *tmpModel in self.classifiedModelMutableArray)
- {
- [self.itemTitleMutableArray removeObject:tmpModel.title];
- }
- }
-
- // 动态添加视频分类
- for (VideoClassifiedModel *model in self.BuguLive.appModel.video_classified)
- {
- [self.itemTitleMutableArray addObject:model.title];
- }
-
- self.classifiedModelMutableArray = self.BuguLive.appModel.video_classified;
-
- self.segmentedControl.sectionTitles = self.itemTitleMutableArray;
- self.scrollView.contentSize = CGSizeMake(viewWidth * [self.itemTitleMutableArray count], CGRectGetHeight(self.scrollView.frame));
-
- for (NSInteger i = 0; i < self.classifiedModelMutableArray.count; ++i)
- {
- // 服务端下发的分类的在完整的分类容器中的起点
- VideoClassifiedModel *tmpModel = [self.classifiedModelMutableArray firstObject];
- NSUInteger tmpIndex = [self.itemTitleMutableArray indexOfObject:tmpModel.title];
-
- VideoViewController *videoVC = [[VideoViewController alloc] init];
- VideoClassifiedModel * model = [self.BuguLive.appModel.video_classified objectAtIndex:i];
- videoVC.viewFrame = CGRectMake(0, 0, viewWidth, self.scrollView.bounds.size.height);
- videoVC.view.frame = CGRectMake(viewWidth * (i+tmpIndex), 0, viewWidth, self.scrollView.bounds.size.height);
- videoVC.classified_id = model.classified_id;
- [self.scrollView addSubview:videoVC.view];
-
- [self.videoVCMutableArray addObject:videoVC];
- }
- }
- }
- #pragma mark 刷新分类VC的数据
- - (void)refreshClassifiedVC:(NSInteger)page
- {
- if (self.classifiedModelMutableArray.count > 0)
- {
- // 服务端下发的分类的在完整的分类容器中的起点
- VideoClassifiedModel *tmpModel = [self.classifiedModelMutableArray firstObject];
- NSUInteger tmpIndex = [self.itemTitleMutableArray indexOfObject:tmpModel.title];
-
- // 服务端下发的分类的在完整的分类容器中的终点
- VideoClassifiedModel *tmpModel2 = [self.classifiedModelMutableArray lastObject];
- NSUInteger tmpIndex2 = [self.itemTitleMutableArray indexOfObject:tmpModel2.title];
-
- if (page >= tmpIndex && page <= tmpIndex2)
- {
- VideoViewController *videoVC = self.videoVCMutableArray[page-tmpIndex];
- [videoVC setNetworing:1];
- }
- }
-
- NSString *tmpStr = [BGUtils isBlankString:self.news_hotViewController.areaString] ? kHotStr : self.news_hotViewController.areaString;
- [self isShowAddressBtn:(page==[self.itemTitleMutableArray indexOfObject:tmpStr] ? YES : NO)];
- }
- #pragma mark - ----------------------- 事件处理 -----------------------
- - (void)isShowAddressBtn:(BOOL)isShow
- {
- if (isShow)
- {
- _addressBtn.hidden = NO;
- }
- else
- {
- _addressBtn.hidden = YES;
- }
- }
- #pragma mark 搜索
- - (void)goSearch
- {
- [self removeChooseView];
- SSearchVC *searchVC = [[SSearchVC alloc]init];
- searchVC.searchType = @"0";
- [[AppDelegate sharedAppDelegate] pushViewController:searchVC animated:YES];
- }
- #pragma mark 右上角地区、IM按钮事件
- - (void)clickRightHeadBtn:(UIButton *)btn
- {
- if (btn.tag == 1)
- {
- if (!self.chooseAreaView)
- {
- self.chooseAreaView = [[SChooseAreaView alloc]initWithFrame:CGRectMake(0, kScreenH, kScreenW, kScreenH-kStatusBarHeight-kNavigationBarHeight) andChooseType:[self.news_hotViewController.sexString intValue] andAreaStr:self.news_hotViewController.areaString];
- FWWeakify(self)
- [self.chooseAreaView setAreaBlock:^(NSString *areStr, int sexType){
- FWStrongify(self)
- if (areStr) {
- [self.itemTitleMutableArray replaceObjectAtIndex:1 withObject:areStr];
- self.segmentedControl.sectionTitles = self.itemTitleMutableArray;
- self.news_hotViewController.areaString = areStr;
- self.news_hotViewController.sexString = [NSString stringWithFormat:@"%d",sexType];
- [self.news_hotViewController loadDataFromNet:1];
- [self removeChooseView];
- }
- }];
- [[[UIApplication sharedApplication] keyWindow] addSubview:self.chooseAreaView];
-
- [UIView animateWithDuration:0.6 animations:^{
- CGRect rect = self.chooseAreaView.frame;
- rect.origin.y = kStatusBarHeight+kNavigationBarHeight;
- self.chooseAreaView.frame = rect;
- }];
- }
- else
- {
- [self removeChooseView];
- }
- }
- else
- {
- [self removeChooseView];
- BGConversationSegmentController *chatListVC = [[BGConversationSegmentController alloc]init];
- [[AppDelegate sharedAppDelegate] pushViewController:chatListVC animated:YES];
- }
- }
- - (void)removeChooseView
- {
- [UIView animateWithDuration:0.6 animations:^{
- CGRect rect = self.chooseAreaView.frame;
- rect.origin.y = kScreenH;
- self.chooseAreaView.frame = rect;
- } completion:^(BOOL finished) {
- [self.chooseAreaView removeFromSuperview];
- self.chooseAreaView = nil;
- }];
- }
- #pragma mark 通知处理事件
- - (void)updateTitleName:(NSNotification *)noti
- {
- if ([[noti.object objectForKey:@"name"] length])
- {
- [self.itemTitleMutableArray replaceObjectAtIndex:1 withObject:[noti.object objectForKey:@"name"]];
- self.segmentedControl.sectionTitles = self.itemTitleMutableArray;
- }
- }
- #pragma mark - ----------------------- 首页刷新机制 -----------------------
- - (void)refreshHome
- {
- [self setupTimer];
-
- [self refreshOfTime];
- }
- - (void)setupTimer
- {
- @synchronized (self)
- {
- if (!_refreshHomeTimer)
- {
- _refreshHomeTimer = [NSTimer scheduledTimerWithTimeInterval:kRefreshWithNewaTimeInterval target:self selector:@selector(refreshOfTime) userInfo:nil repeats:YES];
- [[NSRunLoop currentRunLoop] addTimer:_refreshHomeTimer forMode:NSRunLoopCommonModes];
- }
- }
- }
- - (void)invalidateTimer
- {
- [_refreshHomeTimer invalidate];
- _refreshHomeTimer = nil;
- }
- #pragma mark 最新和最热20秒定时刷新
- - (void)refreshOfTime
- {
- // 防止短时间内重复刷新
- if (self.isRefreshing && [[[BGTabBarController sharedInstance] selectedViewController].childViewControllers[0] isKindOfClass:[HMHomeViewController class]])
- {
- self.isRefreshing = NO;
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-
- self.isRefreshing = YES;
-
- });
- }
- else
- {
- return;
- }
-
- NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
- [dateformatter setDateFormat:@"HH:mm:ss"];
- NSLog(ASLocalizedString(@"============调起首页刷新机制时间点:%@"),[dateformatter stringFromDate:[NSDate date]]);
-
- if (_focusOnViewController)
- {
- [_focusOnViewController requestNetWorking];
- }
-
- if (_hotViewController)
- {
- [_hotViewController loadDataFromNet:1];
- }
-
- if (_livingListViewController)
- {
- [_livingListViewController loadDataWithPage:1];
- }
-
- // 当 open_society_module == 1 开启公会功能,公会名称根据字段 society_list_name 由服务器下发
- if (self.BuguLive.appModel.open_society_module.intValue == 1)
- {
- [_societyHomePage loadDataWithPage:1];
- }
- }
- #pragma mark - ----------------------- 代理 -----------------------
- #pragma mark 解决Segmented的滑块快速滑动时的延迟,同时把点击滑块的情况排除在外
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView
- {
- if (!self.isClickedSegmented)
- {
- CGFloat pageWidth = scrollView.frame.size.width;
- NSInteger tmpPage = scrollView.contentOffset.x / pageWidth;
- float tmpPage2 = scrollView.contentOffset.x / pageWidth;
- NSInteger page = tmpPage2-tmpPage>=0.5 ? tmpPage+1 : tmpPage;
-
- if (_startPage != page)
- {
- [self.segmentedControl setSelectedSegmentIndex:page animated:YES];
- _startPage = page;
- }
- }
- }
- #pragma mark 页面滚动,同时调起Segmented的滑块滑动起来等
- - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
- {
- CGFloat pageWidth = scrollView.frame.size.width;
- NSInteger page = scrollView.contentOffset.x / pageWidth;
- [self loadClassifiedVC];
-
- [self refreshClassifiedVC:page];
-
- self.isClickedSegmented = NO;
-
- [self.segmentedControl setSelectedSegmentIndex:page animated:YES];
- }
- #pragma mark 跳转HomePageController页面
- - (void)goToMainPage:(NSString *)userID
- {
- SHomePageVC *tmpController= [[SHomePageVC alloc]init];
- tmpController.user_id = userID;
- tmpController.type = 0;
- [[AppDelegate sharedAppDelegate] pushViewController:tmpController animated:YES];
- }
- - (void)goToNewestView
- {
- if ([self.itemTitleMutableArray containsObject:kHotStr])
- {
- NSUInteger tmpIndex = [self.itemTitleMutableArray indexOfObject:kHotStr];
- self.segmentedControl.selectedSegmentIndex = tmpIndex;
- [self.scrollView scrollRectToVisible:CGRectMake(kScreenW * tmpIndex, 0, kScreenW, CGRectGetHeight(self.scrollView.frame)-10) animated:NO];
- }
- }
- #pragma mark 跳转到话题页面和hotTopicViewController二级页面
- - (void)pushToNextControllerWithModel:(cuserModel *)model
- {
- if ([model.cate_id isEqualToString:@"0"])
- {
- // 暂时不能跳转
- }
- else
- {
- NewestViewController *tmpController = [[NewestViewController alloc]init];
- tmpController.topicName = model.title;
- tmpController.cate_id = model.cate_id;
- tmpController.types = @"1";
- [[AppDelegate sharedAppDelegate] pushViewController:tmpController animated:YES];
- }
- }
- #pragma mark NewestViewController跳转到直播
- -(void)pushToLiveController:(LivingModel *)model modelArr:(NSArray *)modelArr isFirstJump:(BOOL)isFirstJump
- {
- if (![BGUtils isNetConnected])
- {
- return;
- }
-
- [self.BuguLive.newestLivingMArray removeAllObjects];
- [self.BuguLive.newestLivingMArray addObject:model];
-
- if ([self checkUser:[IMAPlatform sharedInstance].host])
- {
- TCShowLiveListItem *item = [[TCShowLiveListItem alloc]init];
- item.chatRoomId = model.group_id;
- item.avRoomId = model.room_id;
- item.title = StringFromInt(model.room_id);
- item.vagueImgUrl = model.head_image;
- item.is_voice = model.is_voice;
- TCShowUser *showUser = [[TCShowUser alloc]init];
- showUser.uid = model.user_id;
- showUser.avatar = model.head_image;
- item.host = showUser;
-
- if (model.live_in == FW_LIVE_STATE_ING)
- {
- item.liveType = FW_LIVE_TYPE_AUDIENCE;
- }
- // else if (model.live_in == FW_LIVE_STATE_RELIVE)
- // {
- // item.liveType = FW_LIVE_TYPE_RELIVE;
- // }
- //2020-1-7 小直播变大
- [LiveCenterManager sharedInstance].itemModel=item;
- BOOL isSusWindow = [[LiveCenterManager sharedInstance] judgeIsSusWindow];
- [[LiveCenterManager sharedInstance] showLiveOfAudienceLiveofTCShowLiveListItem:item modelArr:modelArr isSusWindow:isSusWindow isSmallScreen:NO block:^(BOOL isFinished) {
-
- }];
-
- [self invalidateTimer];
- }
- else
- {
- [[BGHUDHelper sharedInstance] loading:@"" delay:2 execute:^{
- [[BGIMLoginManager sharedInstance] loginImSDK:YES succ:nil failed:nil];
- } completion:^{
-
- }];
- }
- }
- - (BOOL)checkUser:(id<IMHostAble>)user
- {
- if (![user conformsToProtocol:@protocol(AVUserAble)])
- {
- return NO;
- }
- return YES;
- }
- #pragma mark 跳转到天团详情页面
- - (void)pushSocietyDetail:(SociatyListModel *)listModel
- {
- SocietyDetailVC *tianTuanVC = [[SocietyDetailVC alloc] init];
- tianTuanVC.mySocietyID = [listModel.society_id intValue];
- tianTuanVC.type = [listModel.type intValue];
- [[AppDelegate sharedAppDelegate] pushViewController:tianTuanVC animated:YES];
- }
- #pragma mark - ----------------------- 私信消息、角标 -----------------------
- #pragma mark IM
- - (void)iMChatHaveNotification:(NSNotification*)notification
- {
- //all 角标数据
- [self loadBtnBadageData];
- }
- /**
- 获取角标的数据: 注意:调All未读/调好友&&非好友方法 算All时,别调后者2各和来算,里面有耗时操作
- 使用:1.在willApperar 2.SDK监听会发通知,通知的方法/block 里调用
- 给控件初始化一个角标
-
- badage的 数据 获取(个人页面获取所有未读的条数)
- 1.在willApear里调用一次 2.SDk消息变化,接受通知,在通知方法还要调用 用于更新 角标数据
-
- */
- - (void)loadBtnBadageData
- {
- [SFriendObj getAllUnReadCountComplete:^(int num) {
- //all
- int scount = num;
- if( scount )
- {
- if(scount > 98)
- {
- _badge.badgeText = @"99+";
- }
- else
- {
- _badge.badgeText = [NSString stringWithFormat:@"%d",scount];
- }
- }
- else
- {
- _badge.badgeText = nil;
- }
- }];
-
- }
- /**
- 设置 角标
-
- @param sender 对应的控件
- */
- - (void)initBadgeBtn:(UIButton *)sender
- {
- //-好友
- _badge = [[JSBadgeView alloc]initWithParentView:sender alignment:JSBadgeViewAlignmentTopRight];
- _badge.badgePositionAdjustment = CGPointMake(0, 12);
- }
- #pragma mark - ----------------------- GET -----------------------
- - (SocietyHomePageVC *)societyHomePage
- {
- if (!_societyHomePage)
- {
- _societyHomePage = [[SocietyHomePageVC alloc] init];
- _societyHomePage.societyFrame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), _scrollView.bounds.size.height);
- _societyHomePage.delegate = self;
- }
- return _societyHomePage;
- }
- - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
- {
- [self updateClassiFiedVC];
- }
- - (void)dealloc
- {
- [self.BuguLive removeObserver:self forKeyPath:@"appModel.video_classified" context:nil];
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- @end
|