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

#import "CNLiveLoginController.h"

#import "MJExtension.h"
#import "QMUIKit.h"
#import "YYKit.h"

#import "CNLiveUserAgreementManager.h"
#import "CNLiveCategory.h"

#import "CNLiveLoginView.h"
#import "CNLiveThreeLoginView.h"
#import "CNLiveBindingTelController.h"//绑定手机号
#import "CNLiveCompleteInfoController.h"//修改昵称

@interface CNLiveLoginController()<CNLiveLoginViewDelegate, CNLiveThreeLoginViewDelegate>
@property (nonatomic, weak) CNLiveLoginView *loginView;
@property (nonatomic, weak) CNLiveThreeLoginView *threeLoginView;
@property (nonatomic, weak) YYLabel *protocol;
@property (nonatomic, strong) UIButton *close;

@end

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

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    [self createUI];
}

- (void)createUI{
    
    [self.view addSubview:self.close];

    CNLiveLoginView *loginView = [[CNLiveLoginView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/8.0, NavigationContentTop+20, SCREEN_WIDTH*3/4.0, 380)];
    loginView.delegate = self;
    [self.view addSubview:loginView];
    self.loginView = loginView;
    
    YYLabel *protocol = [[YYLabel alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-30-SafeAreaInsetsConstantForDeviceWithNotch.bottom, SCREEN_WIDTH, 30)];
    protocol.textAlignment = NSTextAlignmentCenter;
    protocol.textColor = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0];
    protocol.font = [UIFont systemFontOfSize:14.0];
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"登录即代表阅读并同意《用户协议》及《隐私政策》"];
    NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    style.alignment = NSTextAlignmentCenter;//对齐方式
    [text addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, text.length)];
    text.color = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0];
    text.font = [UIFont systemFontOfSize:14.0];
    __weak typeof(self) weakSelf = self;
    [text setTextHighlightRange:NSMakeRange(11, 4) color:[UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        [weakSelf.view endEditing:YES];
        [CNLiveUserAgreementManager jumpToAgreementH5WithType:CNLiveUserAgreementUser];
    }];
    [text setTextHighlightRange:NSMakeRange(text.length-5, 4) color:[UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        [weakSelf.view endEditing:YES];
        [CNLiveUserAgreementManager jumpToAgreementH5WithType:CNLiveUserAgreementPrivacy];
    }];
    protocol.attributedText = text;
    [self.view addSubview:protocol];
    self.protocol = protocol;
    
    CNLiveThreeLoginView *threeLoginView = [[CNLiveThreeLoginView alloc] initWithFrame:CGRectMake(loginView.left, SCREEN_HEIGHT-30-SafeAreaInsetsConstantForDeviceWithNotch.bottom-100-10, loginView.width, 100)];
    threeLoginView.delegate = self;
    [self.view addSubview:threeLoginView];
    self.threeLoginView = threeLoginView;
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];

}

#pragma mark - CNLiveLoginViewDelegate
- (void)loginSuccess:(CNLiveLoginView *)view isNewUser:(BOOL)isNewUser result:(id _Nonnull)result{
    if (isNewUser) {
        // 新用户 -> 设置昵称和头像
        CNLiveCompleteInfoController *vc = [[CNLiveCompleteInfoController alloc]init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        
    }else{
        // 老用户 -> home
//        [XWAlertView alertSucceedViewWithTextMessage:@"登录成功" view:self.view block:^{
//            // 通知
//            [XWLoginNotification postUserLoginNotification:result];
//        }];
    }
    
}

#pragma mark - CNLiveThreeLoginViewDelegate
- (void)clickedButton:(CNLiveThreeLoginView *)view type:(CNLiveThreeLoginType)type{
    // 1.请求三方平台
    
    // 2.绑定手机号
    [self jumpToBindingTelController:type];

}

- (void)jumpToBindingTelController:(CNLiveThreeLoginType)type{
    CNLiveBindingTelController *vc = [[CNLiveBindingTelController alloc]initWithType:type];
    [self.navigationController pushViewController:vc animated:YES];
    
}

/*
#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 - 响应事件
- (void)closeDidSelected:(UIButton *)btn{
    if (self.navigationController.topViewController == self) {
         [self.navigationController popViewControllerAnimated:YES];
     }else{
         [self dismissViewControllerAnimated:YES completion:nil];
     }
}

#pragma mark - 懒加载
- (UIButton *)close{
    if (!_close) {
        _close = [UIButton buttonWithType:UIButtonTypeCustom];
        _close.frame = CGRectMake(SCREEN_WIDTH-44-10, StatusBarHeight, 44, 44);
        _close.hidden = !self.isShowClose;
        UIImage *image = [UIImage cn_getImageName:@"login_close" bundleName:@"CNLiveLoginModule" targetClass:[self class]];
        [_close setImage:image forState:UIControlStateNormal];
        [_close addTarget:self action:@selector(closeDidSelected:) forControlEvents:UIControlEventTouchUpInside];
        _close.adjustsImageWhenHighlighted = NO;
    }
    return _close;
    
}

@end