CNLiveAboutUsController.m 12 KB
//
//  CNLiveAboutUsController.m
//  CNLiveSettingModule
//
//  Created by 153993236@qq.com on 11/12/2019.
//  Copyright (c) 2019 153993236@qq.com. All rights reserved.
//

#import "CNLiveAboutUsController.h"
#import "MJExtension.h"
#import "QMUIKit.h"

#import "CNLiveServices.h"
#import "CNLiveUserAgreementManager.h"
#import "CNLiveEnvironment.h"
#import "CNLiveCategory.h"

#import "CNLiveSettingModel.h"
#import "CNLiveSettingCell.h"
#import "CNLiveSettingNavigationBar.h"

@interface CNLiveAboutUsController ()
<UITableViewDelegate, UITableViewDataSource, CNLiveSettingNavigationBarDelegate>
@property (nonatomic, strong) CNLiveSettingNavigationBar *navigationBar;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIView *headerView;
@property (nonatomic, strong) UIView *footerView;
@property (nonatomic, strong) NSMutableArray *data;

@end

@implementation CNLiveAboutUsController
static const NSInteger timeValue = 1.5;

#pragma mark - 加载数据
- (void)loadData {
    NSArray *data = @[
                      @{
                          @"style":@"1",
                          @"title":@"给软件评分",
                          @"height":@"51",
                          @"lineHeight":@"1"
                          },
                      @{
                          @"style":@"1",
                          @"title":@"应用简介",
                          @"height":@"60",
                          @"lineHeight":@"10"
                          },
                      @{
                          @"style":@"1",
                          @"title":@"隐私政策协议",
                          @"height":@"51",
                          @"lineHeight":@"1"
                          },
                      @{
                          @"style":@"1",
                          @"title":@"软件许可及服务协议",
                          @"height":@"51",
                          @"lineHeight":@"1"
                          },
                      @{
                          @"style":@"1",
                          @"title":@"版权信息",
                          @"height":@"51",
                          @"lineHeight":@"1"
                          },
                      @{
                          @"style":@"1",
                          @"title":@"资质信息",
                          @"height":@"51",
                          @"lineHeight":@"1"
                          },
                      @{
                          @"style":@"2",
                          @"title":@"当前版本",
                          @"content":@"0.0.1",
                          @"height":@"51",
                          @"lineHeight":@"1"
                          },
                      @{
                          @"style":@"1",
                          @"title":@"联系我们",
                          @"height":@"51",
                          @"lineHeight":@"1"
                          },
                      @{
                          @"style":@"1",
                          @"title":@"投诉",
                          @"height":@"51",
                          @"lineHeight":@"1"
                          }
                      
                      ];
    for(NSDictionary *dic in data){
        [self.data addObject:[CNLiveSettingModel mj_objectWithKeyValues:dic]];
    }
    [self.tableView reloadData];
    
}

#pragma mark - 生命周期
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    if (@available(iOS 11, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }

    [self createSubViews];
    [self loadData];
    
}

- (void)dealloc {
    
    
}

- (void)createSubViews {
    [self.view addSubview:self.navigationBar];
    [self.view addSubview:self.tableView];

}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CNLiveSettingModel *model = self.data[indexPath.row];
    return model.height;
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.data.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CNLiveSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:kCNLiveSettingCell];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    CNLiveSettingModel *model = self.data[indexPath.row];
    cell.model = model;
    cell.lineColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1.0];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 0){ // 给软件评分
        NSString *app = [NSString stringWithFormat:@"https://itunes.apple.com/app/apple-store/id%@?ct=web&mt=8",@"1337575478"];
        if (@available(iOS 10.0, *)) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:app] options:@{} completionHandler:nil];
        } else {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:app]];
        }

    }
    else if(indexPath.row == 1){ // 应用简介
        [CNLiveUserAgreementManager jumpToAgreementH5WithType:CNLiveUserAgreementIntroduction];

    }
    else if(indexPath.row == 2){ // 隐私政策协议
        [CNLiveUserAgreementManager jumpToAgreementH5WithType:CNLiveUserAgreementPrivacy];

    }
    else if(indexPath.row == 3){ // 软件许可及服务协议
        [CNLiveUserAgreementManager jumpToAgreementH5WithType:CNLiveUserAgreementPermission];
    }
    else if(indexPath.row == 4){ // 版权信息
        [CNLiveUserAgreementManager jumpToAgreementH5WithType:CNLiveUserAgreementCopyright];
    
    }
    else if(indexPath.row == 5){ // 资质信息
        [CNLiveUserAgreementManager jumpToAgreementH5WithType:CNLiveUserAgreementEnterpriseQualification];
    }
    else if(indexPath.row == 6){ // 当前版本
    
    }
    else if(indexPath.row == 7){ // 联系我们
        QMUIAlertAction *sure = [QMUIAlertAction actionWithTitle:@"确定" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
            NSMutableString *tel = [[NSMutableString alloc] initWithFormat:@"telprompt://%@",@"010-88824192"];
            if (@available(iOS 10.0, *)) {
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tel] options:@{} completionHandler:nil];
            } else {
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tel]];
            }

        }];
        QMUIAlertAction *cancel = [QMUIAlertAction actionWithTitle:@"取消" style:QMUIAlertActionStyleCancel handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
        }];
               
        QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"联系我们" message:@"您确定要拨打010-88824192吗?" preferredStyle:QMUIAlertControllerStyleAlert];
        [alertController addAction:sure];
        [alertController addAction:cancel];
        
        NSMutableDictionary *titleAttributs = [[NSMutableDictionary alloc] initWithDictionary:alertController.alertTitleAttributes];
               
        titleAttributs[NSForegroundColorAttributeName] = [UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0];
        
        NSMutableDictionary *cancelAttributs = [[NSMutableDictionary alloc] initWithDictionary:alertController.alertTitleAttributes];
        cancelAttributs[NSForegroundColorAttributeName] = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];

        sure.buttonAttributes = titleAttributs;
        cancel.buttonAttributes = cancelAttributs;

        [alertController showWithAnimated:YES];
        
    }else if (indexPath.row == 8){ // 投诉

        
    }
    
}

#pragma mark - 懒加载
- (NSMutableArray *)data {
    if (!_data) {
        _data = [NSMutableArray array];
    }
    return _data;
}

- (CNLiveSettingNavigationBar *)navigationBar {
    if (!_navigationBar) {
        _navigationBar = [[CNLiveSettingNavigationBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationContentTop)];
        _navigationBar.backgroundColor = [UIColor whiteColor];
        _navigationBar.delegate = self;
        _navigationBar.title.text = [NSString stringWithFormat:@"关于%@",DisplayName];
        _navigationBar.right = nil;
    }
    return _navigationBar;
}

- (UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavigationContentTop, SCREEN_WIDTH, SCREEN_HEIGHT-NavigationContentTop) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1.0];
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        [_tableView registerClass:[CNLiveSettingCell class] forCellReuseIdentifier:kCNLiveSettingCell];
        _tableView.tableHeaderView = self.headerView;
        _tableView.tableFooterView = self.footerView;

    }
    return _tableView;
}

- (UIView *)headerView {
    if (!_headerView) {
        _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 150)];
        _headerView.clipsToBounds = YES;
        _headerView.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1.0];
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-70)/2.0, 30, 70, 140)];
        UIImage *image = [self getImageWithImageName:@"about_us_icon" bundleName:@"CNLiveSettingModule" targetClass:[CNLiveSettingNavigationBar class]];
        imageView.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        imageView.clipsToBounds = YES;
        [_headerView addSubview:imageView];
        
    }
    return _headerView;
}

- (UIView *)footerView {
    if (!_footerView) {
        _footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100)];
        _footerView.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1.0];
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 25, SCREEN_WIDTH, 25)];
        title.textColor = [UIColor colorWithRed:40/255.0 green:40/255.0 blue:40/255.0 alpha:1.0];
        title.font = [UIFont systemFontOfSize:12.0f];
        title.text = @"版权信息";
        title.textAlignment = NSTextAlignmentCenter;
        [_footerView addSubview:title];
        UILabel *subTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, SCREEN_WIDTH, 25)];
        subTitle.textColor = [UIColor colorWithRed:40/255.0 green:40/255.0 blue:40/255.0 alpha:1.0];
        subTitle.font = [UIFont systemFontOfSize:12.0f];
        subTitle.text = @"北京中投视讯文化传媒股份有限公司版权所有";
        subTitle.textAlignment = NSTextAlignmentCenter;
        [_footerView addSubview:subTitle];
    }
    return _footerView;
}

#pragma mark - 响应方法
- (void)goBack {
    if (self.presentingViewController != nil) {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    else {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

#pragma mark - CNLiveSettingNavigationBarDelegate
- (void)navigationBar:(CNLiveSettingNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{
    if ([actionEvents isEqualToString:@"1"]) {
        [self goBack];
    }else if ([actionEvents isEqualToString:@"2"]){
        
    }
}

@end