IVTGreatHallViewController.m 5.34 KB
//
//  IVTGreatHallViewController.m
//  IVTMeLiveTwo
//
//  Created by XRG on 16/8/10.
//  Copyright © 2016年 QLQ. All rights reserved.
//

#import "IVTGreatHallViewController.h"
#import "IVTMyChatListViewController.h"
#import "IVTMeSearchViewController.h"
#import "DBManager.h"

@interface IVTGreatHallViewController ()
{
    GMCategaryScrollBar *scrb;
    UIImageView *dot;
}
@end

@implementation IVTGreatHallViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUI];
    [self setNavigationBar];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshDot) name:kPrivateMessageDidChange object:nil];
}


- (void)setNavigationBar{
    [self hiddenLeftBarBackButtonItem];
    [self setTitleText:@"大厅" textColor:UIColorFromRGBAlphaHex(0xf6f6f6, 1.0) textFont:[UIFont IVTH1Font]];
    [self setCustomNavigationBarToSearchFunc];
    [self setCustomNavigationBarToMessageFunc];
}
- (void)setTitleText:(NSString *)TitleText textColor:(UIColor *)textColor textFont:(UIFont *)textFont
{
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: textColor,NSFontAttributeName:textFont}];
    self.title = TitleText;
}

- (void)setCustomNavigationBarToSearchFunc{
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"搜索图标"] style:UIBarButtonItemStylePlain target:self action:@selector(pushToSearchVCFunc)];
    leftBarButton.tintColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem = leftBarButton;
}

- (void)setCustomNavigationBarToMessageFunc
{
    UIView *rightView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
    
    UIButton *messageButton = [UIButton buttonWithType:UIButtonTypeCustom];
    messageButton.frame = rightView.frame;
    [messageButton setImage:[UIImage imageNamed:@"进入私信"] forState:UIControlStateNormal];
    [messageButton addTarget:self action:@selector(pushToMessageVCFunc) forControlEvents:UIControlEventTouchUpInside];
    [rightView addSubview:messageButton];
    
    dot = [[UIImageView alloc]initWithFrame:CGRectMake(23, 5, 4, 4)];
    dot.backgroundColor = [UIColor whiteColor];
    dot.userInteractionEnabled = YES;
    dot.layer.cornerRadius = 2;
    dot.clipsToBounds = YES;
    [rightView addSubview:dot];
    if ([[DBManager sharedInstance] getTotalNumberOfMessageNoRead] > 0) {
        dot.hidden = NO;
    }
    else{
        dot.hidden = YES;
    }
    
    UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc]initWithCustomView:rightView];
    self.navigationItem.rightBarButtonItem = rightBarButton;
}

- (void)refreshDot{
    NSInteger total = [[DBManager sharedInstance] getTotalNumberOfMessageNoRead];
    dispatch_async(dispatch_get_main_queue(), ^{
        if (total > 0) {
            dot.hidden = NO;
        }
        else{
            dot.hidden = YES;
        }
    });
}

- (void)pushToSearchVCFunc
{
    IVTMeSearchViewController *meSearchVC = [[IVTMeSearchViewController alloc]init];
    meSearchVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:meSearchVC animated:YES];
}


- (void)pushToMessageVCFunc
{
    IVTMyChatListViewController *myChatListVC = [[IVTMyChatListViewController alloc]init];
    myChatListVC.isSmall = NO;
    myChatListVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:myChatListVC animated:YES];
}


- (void)initUI{
    NSMutableArray *ary = [NSMutableArray arrayWithArray:@[@"关注",@"热门",@"最新",@"明星"]];
    scrb = [GMCategaryScrollBar categaryScrollBar];
    scrb.scrv.contentInset = UIEdgeInsetsZero;
    scrb.scrv.scrollIndicatorInsets = UIEdgeInsetsZero;
    scrb.isReponseDelegate = YES;
    [scrb categaryBarTitle:ary withIsEqualBtn:YES];
    [self.view addSubview:scrb];
    
    NSArray *aryType = @[@"attention",@"hot",@"new",@"star"];
    // 组装VC
    NSMutableArray *maryVC = [NSMutableArray array];
    for (NSInteger i = 0; i < ary.count; i++)
    {
        if (i == 0 || i == 1) {
            
            IVTHotAndFollowLiveVC *hotVC = [[IVTHotAndFollowLiveVC alloc] init];
            [hotVC.tableV reloadData];
            hotVC.strType = aryType[i];
            [maryVC addObject:hotVC];
            [self addChildViewController:hotVC];
        }else if (i == 2){
            IVTNewLiveVC *newVC = [[IVTNewLiveVC alloc] init];
            [newVC.userLiveScrollView reloadData];
            newVC.strType = aryType[2];
            [maryVC addObject:newVC];
            [self addChildViewController:newVC];
        }else if (i ==3){
            IVTStarLiveVC *starVC = [[IVTStarLiveVC alloc] init];
            [starVC.userLiveScrollView reloadData];
            [starVC.tableV reloadData];
            
            starVC.strType = aryType[3];
            [maryVC addObject:starVC];
            [self addChildViewController:starVC];
        }
    }
    scrb.maryVC = maryVC;
    [scrb automaticScroll:1];

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end