CNLiveSettingViewController.m 6.82 KB
//
//  CNLiveSettingViewController.m
//  CNLiveScioLive
//
//  Created by CNLive-zxw on 2018/9/20.
//  Copyright © 2018年 CNLive. All rights reserved.
//

#import "CNLiveSettingViewController.h"
#import "CNLiveSettingTableViewCell.h"
#import "CNLiveAboutUsViewController.h"
#import "CNLiveArticleFontViewController.h"

@interface CNLiveSettingViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *fontArray;
@property (nonatomic, assign) NSInteger selectFont;

@end
@implementation CNLiveSettingViewController
static NSString *settingTableViewCell = @"CNLiveSettingTableViewCell";
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    _selectFont = [[NSUserDefaults standardUserDefaults] integerForKey:@"FontSize"];
    [self.tableView reloadData];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setUpNavigationBar];
    [self.view addSubview:self.tableView];

}
#pragma mark - UI
- (void)setUpNavigationBar{
    
    self.navigationController.navigationBar.barTintColor = Color_Blue;
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];

    //左
    UIButton *headerButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 44)];
    headerButton.layer.cornerRadius = 2.0;
    headerButton.layer.masksToBounds = true;
    [headerButton setImage:[UIImage imageNamed:@"cnlive_white_back"] forState:UIControlStateNormal];
    [headerButton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:headerButton];

    self.navigationItem.title = self.navTitle;

}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 45;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.00000001f;
    
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(section == 0){
        return 2;
        
    }else if (section == 1){
        return 1;
        
    }
    return 0;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    //    NSArray *name = @[@[@"清空缓存", @"文章字体大小"],@[@"关于我们"]];
    NSArray *name = @[@[CustomStr(@"ClearCache"), CustomStr(@"ArticleFontSize")],@[CustomStr(@"AboutUs")]];

    CNLiveSettingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:settingTableViewCell];
    if (!cell) {
        cell = [[CNLiveSettingTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:settingTableViewCell];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    cell.name = name[indexPath.section][indexPath.row];
    if(indexPath.section == 0 && indexPath.row == 0){
        cell.details = [NSString stringWithFormat:@"%.2f M",(CGFloat)[[SDImageCache sharedImageCache] getSize]/(1024*1024)];
    }
    if(indexPath.section == 0 && indexPath.row == 1){
        cell.details = self.fontArray[_selectFont];
    }
    return cell;
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, MainScreenWidth, 10)];
    headerView.backgroundColor = HEXCOLOR(0xebebeb);
    return headerView;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, MainScreenWidth, 0.00000001f)];
    footerView.backgroundColor = HEXCOLOR(0xebebeb);
    return footerView;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //登录
    if(indexPath.section == 0){
        if(indexPath.row == 0){
            [SVProgressHUD showWithStatus:CustomStr(@"CleanUp") maskType:SVProgressHUDMaskTypeClear];
            [[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
                [SVProgressHUD dismiss];
                [AlertViewTool showHUDAddedToView:self.view text:CustomStr(@"CleanCompleted")];
                [self.tableView reloadData];
            }];
        }else{
            //字体大小
            CNLiveArticleFontViewController *vc = [CNLiveArticleFontViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }
        
        
    }else if (indexPath.section == 1){
        if(indexPath.row == 0){
            //新版本检测
            CNLiveAboutUsViewController *vc = [CNLiveAboutUsViewController new];
            vc.names = CustomStr(@"AboutUs");
            [self.navigationController pushViewController:vc animated:YES];
        }else{
            //关于我们
            CNLiveAboutUsViewController *vc = [CNLiveAboutUsViewController new];
            vc.names = CustomStr(@"AboutUs");
            [self.navigationController pushViewController:vc animated:YES];
        }
        
    }
    return;
}
- (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.
}
*/
#pragma mark - Lazy Laoding
- (UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, MainScreenHeight - NavBarHeight) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        _tableView.backgroundColor = HEXCOLOR(0xebebeb);
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        [_tableView registerClass:[CNLiveSettingTableViewCell class] forCellReuseIdentifier:settingTableViewCell];
        
    }
    return _tableView;
}
- (NSArray *)fontArray{
    if(!_fontArray){
        _fontArray = [[NSArray alloc] initWithObjects:CustomStr(@"Small"), CustomStr(@"Medium"), CustomStr(@"Big"), nil];
    }
    return _fontArray;
}
@end