Commit aba9dbf003fdf4a9ce88911477e2d0e68289bef1

Authored by zhangxiaowen
1 parent e37a570a

no message

CNLiveSettingModule/Classes/Cancellation/CNLiveCancellationController.h 0 → 100644
  1 +//
  2 +// CNLiveCancellationController.h
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/3/21.
  6 +// Copyright © 2019年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +// 注销账号
  10 +
  11 +NS_ASSUME_NONNULL_BEGIN
  12 +
  13 +@interface CNLiveCancellationController : UIViewController
  14 +
  15 +@end
  16 +
  17 +NS_ASSUME_NONNULL_END
... ...
CNLiveSettingModule/Classes/Cancellation/CNLiveCancellationController.m 0 → 100644
  1 +//
  2 +// CNLiveCancellationController.m
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/3/21.
  6 +// Copyright © 2019年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLiveCancellationController.h"
  10 +#import <WebKit/WebKit.h>
  11 +#import <Masonry/Masonry.h>
  12 +#import "QMUIKit.h"
  13 +
  14 +#import "CNLiveNetworking.h"
  15 +#import "CNLiveEnvironment.h"
  16 +#import "CNUserInfoManager.h"
  17 +
  18 +#import "CNLiveSettingNavigationBar.h"
  19 +#import "CNLiveCancellationView.h"
  20 +
  21 +//#import "CNIntegralRulesViewController.h"
  22 +//#import "CNMineHomeController.h"
  23 +#import "CNLiveUserAgreementManager.h"
  24 +
  25 +@interface CNLiveCancellationController ()<WKNavigationDelegate,WKUIDelegate,CNLiveCancellationViewDelegate,CNLiveSettingNavigationBarDelegate>
  26 +@property (nonatomic, strong) CNLiveSettingNavigationBar *navigationBar;
  27 +@property (nonatomic, weak) WKWebView *webView;
  28 +@property (nonatomic, weak) CNLiveCancellationView *cancellationView;
  29 +
  30 +@end
  31 +
  32 +@implementation CNLiveCancellationController
  33 +static const NSInteger timeValue = 1.5;
  34 +
  35 +#pragma mark - Data
  36 +- (void)setData {
  37 + [[CNLiveUserAgreementManager manager] getAgreementH5WithType:CNLiveUserAgreementReviewApply success:^(NSString * _Nonnull h5, NSString * _Nonnull title, BOOL isShow) {
  38 + [QMUITips showLoadingInView:self.view];
  39 + [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:h5]]];
  40 +
  41 + } failure:^(NSError * _Nonnull error) {
  42 + [self loadHTMLString];
  43 +
  44 + }];
  45 +}
  46 +
  47 +#pragma mark - 生命周期
  48 +- (void)viewWillAppear:(BOOL)animated{
  49 + [super viewWillAppear:animated];
  50 + self.navigationController.navigationBarHidden = YES;
  51 +}
  52 +
  53 +- (void)viewDidLoad {
  54 + [super viewDidLoad];
  55 + // Do any additional setup after loading the view.
  56 + self.view.backgroundColor = [UIColor whiteColor];
  57 + self.edgesForExtendedLayout = UIRectEdgeNone;//双击webview不上移
  58 +
  59 + [self createUI];
  60 + [self layoutUI];
  61 + [self setData];
  62 +
  63 +}
  64 +- (void)dealloc{
  65 +
  66 +}
  67 +#pragma mark - UI
  68 +- (void)createUI {
  69 + [self.view addSubview:self.navigationBar];
  70 +
  71 + WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc]init];
  72 + config.preferences = [WKPreferences new];
  73 + config.preferences.javaScriptEnabled = YES;
  74 + config.preferences.javaScriptCanOpenWindowsAutomatically = NO;
  75 + config.userContentController = [[WKUserContentController alloc]init];
  76 +
  77 + //下方代码,禁止缩放
  78 + WKUserContentController *userController = [WKUserContentController new];
  79 + NSString *js = @"var script = document.createElement('meta');"
  80 + "script.name = 'viewport';"
  81 + "script.content=\"width=device-width, initial-scale=1.0,maximum-scale=1.0, minimum-scale=1.0, user-scalable=no\";"
  82 + "document.getElementsByTagName('div')[0].appendChild(script);";
  83 + WKUserScript *script = [[WKUserScript alloc] initWithSource:js injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:NO];
  84 +
  85 + NSMutableString *javascript = [NSMutableString string];
  86 + [javascript appendString:@"document.documentElement.style.webkitTouchCallout='none';"];//禁止长按
  87 + [javascript appendString:@"document.documentElement.style.webkitUserSelect='none';"];//禁止选择
  88 + WKUserScript *noneSelectScript = [[WKUserScript alloc] initWithSource:javascript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
  89 + [userController addUserScript:script];
  90 + [userController addUserScript:noneSelectScript];
  91 + config.userContentController = userController;
  92 +
  93 + WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:config];
  94 + webView.navigationDelegate = self;
  95 + webView.UIDelegate = self;
  96 + webView.scrollView.bounces = NO;
  97 + webView.scrollView.showsVerticalScrollIndicator = NO;
  98 + webView.scrollView.showsHorizontalScrollIndicator = NO;
  99 + [self.view addSubview:webView];
  100 + _webView = webView;
  101 +
  102 + CNLiveCancellationView *cancellationView = [[CNLiveCancellationView alloc]init];
  103 + cancellationView.delegate = self;
  104 + [self.view addSubview:cancellationView];
  105 + _cancellationView = cancellationView;
  106 +
  107 +}
  108 +- (void)layoutUI{
  109 + [_cancellationView mas_makeConstraints:^(MASConstraintMaker *make) {
  110 + make.left.equalTo(self.view.mas_left).with.offset(0);
  111 + make.right.equalTo(self.view.mas_right).with.offset(-0);
  112 + make.bottom.equalTo(self.view.mas_bottom).with.offset(-SafeAreaInsetsConstantForDeviceWithNotch.bottom);
  113 + make.height.offset(120);
  114 + }];
  115 + [_webView mas_makeConstraints:^(MASConstraintMaker *make) {
  116 + make.top.equalTo(self.view.mas_top).with.offset(NavigationContentTop);
  117 + make.left.equalTo(self.view.mas_left).with.offset(0);
  118 + make.right.equalTo(self.view.mas_right).with.offset(-0);
  119 + make.bottom.equalTo(_cancellationView.mas_top).with.offset(-0);
  120 +
  121 + }];
  122 +
  123 +}
  124 +#pragma mark - WKNavigationDelegate
  125 +// 页面加载完成之后调用
  126 +- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
  127 + [QMUITips hideAllTipsInView:self.view];
  128 +
  129 +}
  130 +// 页面加载失败时调用
  131 +- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation{
  132 + [self loadHTMLString];
  133 + [QMUITips hideAllTipsInView:self.view];
  134 +
  135 +}
  136 +
  137 +#pragma mark - CNLiveCancellationViewDelegate
  138 +- (void)clickedProtocol:(CNLiveCancellationView *)view{
  139 + [CNLiveUserAgreementManager jumpToAgreementH5WithType:CNLiveUserAgreementCancellation];
  140 +}
  141 +
  142 +- (void)clickedCancellationButton:(CNLiveCancellationView *)view{
  143 + __weak typeof(self) weakSelf = self;
  144 + QMUIAlertAction *sure = [QMUIAlertAction actionWithTitle:@"是" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
  145 + __strong typeof(weakSelf) strongSelf = weakSelf;
  146 + if(!strongSelf) return ;
  147 + [strongSelf sendCancellationRequest];
  148 +
  149 + }];
  150 + QMUIAlertAction *cancel = [QMUIAlertAction actionWithTitle:@"否" style:QMUIAlertActionStyleCancel handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
  151 + __strong typeof(weakSelf) strongSelf = weakSelf;
  152 + if(!strongSelf) return ;
  153 + self.navigationBar.right.userInteractionEnabled = YES;
  154 +
  155 + }];
  156 +
  157 + QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"您确定要注销此账户吗,工作人员将在5个工作日内完成审核" message:@"" preferredStyle:QMUIAlertControllerStyleAlert];
  158 + [alertController addAction:sure];
  159 + [alertController addAction:cancel];
  160 +
  161 + NSMutableDictionary *titleAttributs = [[NSMutableDictionary alloc] initWithDictionary:alertController.alertTitleAttributes];
  162 +
  163 + titleAttributs[NSForegroundColorAttributeName] = [UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0];
  164 +
  165 + NSMutableDictionary *cancelAttributs = [[NSMutableDictionary alloc] initWithDictionary:alertController.alertTitleAttributes];
  166 + cancelAttributs[NSForegroundColorAttributeName] = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
  167 +
  168 + sure.buttonAttributes = titleAttributs;
  169 + cancel.buttonAttributes = cancelAttributs;
  170 +
  171 + [alertController showWithAnimated:YES];
  172 +
  173 +}
  174 +
  175 +#pragma mark - Private Methods
  176 +- (void)loadHTMLString{
  177 + NSString *htmlContent = [NSString stringWithFormat:@"<div style=\"padding:0 5px;\"><p style=\"font-size:1.0625em;\"><strong>%@</strong></p><hr style=\"background-color:#EEEEEE;height:1px;border:none;\"/><p style=\"font-size:1em;\">%@</p><hr style=\"background-color:#EEEEEE;height:1px;border:none;\"/><p style=\"font-size:1em;\">%@</p><hr style=\"background-color:#EEEEEE;height:1px;border:none;\"/><p style=\"font-size:1em;\">%@</p><hr style=\"background-color:#EEEEEE;height:1px;border:none;\"/><p style=\"font-size:1em;\">%@</p></div>",@"我们对你注销网家家账号的决定深表遗憾。如果你仍执意注销账号,你的账号需同时满足以下条件:",@"1.账号处于安全状态: 最近1个月内无绑定手机/修改手机号、无找回密码/修改密码等操作,账号为正常使用中且在1年内无任何账号被限制的记录。",@"2.账号财产已结清,没有未完成和/或存在争议的服务: 账号中没有资产、欠款、未结清的资金和虚拟权益;本账号及通过本账号接入的第三方中没有未完成和/或存在争议的服务。",@"3.账号权限解除: 账号已解除与其他产品、网站授权登录或绑定关系。",@"4.账号无任何纠纷,包括投诉举报或被投诉举报。"];
  178 + [_webView loadHTMLString:htmlContent baseURL:nil];
  179 +
  180 +}
  181 +//请求注销接口
  182 +- (void)sendCancellationRequest{
  183 + NSDictionary *params = @{@"loginSid":CNUserShareModel.uid};
  184 + [CNLiveNetworking setAllowRequestDefaultArgument:YES];
  185 + [CNLiveNetworking setupShowDataResult:NO];
  186 +
  187 + [QMUITips showLoadingInView:self.view];
  188 +
  189 + [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNCancellationUrl Param:params CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
  190 + [QMUITips hideAllTipsInView:self.view];
  191 + if ([responseObject isKindOfClass:[NSDictionary class]] && [responseObject[@"errorCode"] isEqualToString:@"0"]) {
  192 + //我知道了
  193 + [self showIKnow];
  194 +
  195 + }else if([responseObject[@"errorCode"] isEqualToString:@"455"]){
  196 + [QMUITips showError:@"账号已经在注销中,请等待" inView:self.view hideAfterDelay:timeValue];
  197 + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  198 + [self.navigationController popViewControllerAnimated:YES];
  199 +
  200 + });
  201 +
  202 + }else{
  203 + [QMUITips showError:@"注销失败" inView:self.view hideAfterDelay:timeValue];
  204 +
  205 + }
  206 +
  207 + }];
  208 +
  209 +}
  210 +
  211 +//我知道了
  212 +- (void)showIKnow{
  213 + __weak typeof(self) weakSelf = self;
  214 + QMUIAlertAction *sure = [QMUIAlertAction actionWithTitle:@"我知道了" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
  215 + __strong typeof(weakSelf) strongSelf = weakSelf;
  216 + if(!strongSelf) return ;
  217 + [strongSelf.navigationController popViewControllerAnimated:YES];
  218 +
  219 + }];
  220 +
  221 + QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"您的注销申请已提交,我们将在5个工作日内完成审核" message:@"" preferredStyle:QMUIAlertControllerStyleAlert];
  222 + [alertController addAction:sure];
  223 +
  224 + NSMutableDictionary *titleAttributs = [[NSMutableDictionary alloc] initWithDictionary:alertController.alertTitleAttributes];
  225 +
  226 + titleAttributs[NSForegroundColorAttributeName] = [UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0];
  227 +
  228 + NSMutableDictionary *cancelAttributs = [[NSMutableDictionary alloc] initWithDictionary:alertController.alertTitleAttributes];
  229 + cancelAttributs[NSForegroundColorAttributeName] = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
  230 + sure.buttonAttributes = titleAttributs;
  231 + [alertController showWithAnimated:YES];
  232 +
  233 +}
  234 +
  235 +/*
  236 +#pragma mark - Navigation
  237 +
  238 +// In a storyboard-based application, you will often want to do a little preparation before navigation
  239 +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  240 + // Get the new view controller using [segue destinationViewController].
  241 + // Pass the selected object to the new view controller.
  242 +}
  243 +*/
  244 +
  245 +#pragma mark - 懒加载
  246 +- (CNLiveSettingNavigationBar *)navigationBar {
  247 + if (!_navigationBar) {
  248 + _navigationBar = [[CNLiveSettingNavigationBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationContentTop)];
  249 + _navigationBar.backgroundColor = [UIColor whiteColor];
  250 + _navigationBar.delegate = self;
  251 + _navigationBar.title.text = @"审核申请";
  252 + _navigationBar.right = nil;
  253 + }
  254 + return _navigationBar;
  255 +}
  256 +
  257 +#pragma mark - CNLiveSettingNavigationBarDelegate
  258 +- (void)navigationBar:(CNLiveSettingNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{
  259 + if ([actionEvents isEqualToString:@"1"]) {
  260 + [self goBack];
  261 + }else if ([actionEvents isEqualToString:@"2"]){
  262 +
  263 + }
  264 +}
  265 +#pragma mark - 响应方法
  266 +- (void)goBack {
  267 + if (self.presentingViewController != nil) {
  268 + [self dismissViewControllerAnimated:YES completion:nil];
  269 + }
  270 + else {
  271 + [self.navigationController popViewControllerAnimated:YES];
  272 + }
  273 +}
  274 +
  275 +@end
... ...
CNLiveSettingModule/Classes/Cancellation/CNLiveCancellationView.h 0 → 100644
  1 +//
  2 +// CNLiveCancellationView.h
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/3/21.
  6 +// Copyright © 2019年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +NS_ASSUME_NONNULL_BEGIN
  12 +@class CNLiveCancellationView;
  13 +@protocol CNLiveCancellationViewDelegate <NSObject>
  14 +- (void)clickedCancellationButton:(CNLiveCancellationView *)view;
  15 +- (void)clickedProtocol:(CNLiveCancellationView *)view;
  16 +
  17 +@end
  18 +@interface CNLiveCancellationView : UIView
  19 +@property (nonatomic, weak) id<CNLiveCancellationViewDelegate> delegate;
  20 +
  21 +@end
  22 +
  23 +NS_ASSUME_NONNULL_END
... ...
CNLiveSettingModule/Classes/Cancellation/CNLiveCancellationView.m 0 → 100644
  1 +//
  2 +// CNLiveCancellationView.m
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/3/21.
  6 +// Copyright © 2019年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLiveCancellationView.h"
  10 +#import "YYKit.h"
  11 +#import <Masonry/Masonry.h>
  12 +
  13 +@interface CNLiveCancellationView()<UITextViewDelegate>
  14 +@property (nonatomic, strong) UIButton *agreeBtn;
  15 +@property (nonatomic, strong) YYLabel *protocol;
  16 +@property (nonatomic, strong) UIButton *cancellationBtn;
  17 +
  18 +@end
  19 +
  20 +@implementation CNLiveCancellationView
  21 +static const NSInteger margin = 15;
  22 +#pragma mark - Init
  23 +- (instancetype)initWithFrame:(CGRect)frame {
  24 + self = [super initWithFrame:frame];
  25 + if (self) {
  26 + self.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1.0];
  27 + [self setup];
  28 + }
  29 + return self;
  30 +}
  31 +- (void)dealloc{
  32 +
  33 +}
  34 +
  35 +#pragma mark - UI
  36 +- (void)setup {
  37 + [self addSubview:self.agreeBtn];
  38 + [self addSubview:self.protocol];
  39 + [self addSubview:self.cancellationBtn];
  40 +
  41 +}
  42 +- (void)layoutSubviews{
  43 + [super layoutSubviews];
  44 + [_agreeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  45 + make.left.equalTo(self.mas_left).with.offset(0);
  46 + make.top.equalTo(self.mas_top).with.offset(margin);
  47 + make.width.height.offset(30);
  48 +
  49 + }];
  50 + [_protocol mas_makeConstraints:^(MASConstraintMaker *make) {
  51 + make.left.equalTo(self->_agreeBtn.mas_right).with.offset(8);
  52 + make.right.equalTo(self.mas_right).with.offset(-margin);
  53 + make.top.equalTo(self->_agreeBtn.mas_top).with.offset(0);
  54 + make.height.offset(30);
  55 +
  56 + }];
  57 + [_cancellationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  58 + make.left.equalTo(self.mas_left).with.offset(margin);
  59 + make.right.equalTo(self.mas_right).with.offset(-margin);
  60 + make.bottom.equalTo(self.mas_bottom).with.offset(-margin);
  61 + make.height.offset(40);
  62 +
  63 + }];
  64 +
  65 +}
  66 +
  67 +#pragma mark - Data
  68 +/*
  69 + // Only override drawRect: if you perform custom drawing.
  70 + // An empty implementation adversely affects performance during animation.
  71 + - (void)drawRect:(CGRect)rect {
  72 + // Drawing code
  73 + }
  74 + */
  75 +#pragma mark - Action
  76 +- (void)clickedAgreeButton:(UIButton *)btn{
  77 + btn.selected = !btn.selected;
  78 + if(btn.selected){
  79 + _cancellationBtn.backgroundColor = [UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0];
  80 +
  81 + }else{
  82 + _cancellationBtn.backgroundColor = [UIColor colorWithRed:146/255.0 green:227/255.0 blue:154/255.0 alpha:1.0];
  83 + }
  84 +}
  85 +- (void)cancellationDidClicked:(UIButton *)btn{
  86 + if (self.delegate && [self.delegate respondsToSelector:@selector(clickedCancellationButton:)] && _agreeBtn.selected) {
  87 + [self.delegate clickedCancellationButton:self];
  88 +
  89 + }
  90 +}
  91 +
  92 +#pragma mark - UITextViewDelegate
  93 +- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
  94 + if ([[URL scheme] isEqualToString:@"cancellation"]) {
  95 + if (self.delegate && [self.delegate respondsToSelector:@selector(clickedProtocol:)]) {
  96 + [self.delegate clickedProtocol:self];
  97 +
  98 + }
  99 + return NO;
  100 + }
  101 + return YES;
  102 +}
  103 +
  104 +#pragma mark - Lazy loading
  105 +- (UIButton *)agreeBtn{
  106 + if (!_agreeBtn) {
  107 + _agreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  108 + UIImage *xw_image1 = [self xw_getImageName:@"cancellation_agree" bundleName:@"CNLiveSettingModule" targetClass:[CNLiveCancellationView class]];
  109 +
  110 + UIImage *xw_image2 = [self xw_getImageName:@"cancellation_agree_sel" bundleName:@"CNLiveSettingModule" targetClass:[CNLiveCancellationView class]];
  111 +
  112 + [_agreeBtn setImage:xw_image1 forState:UIControlStateNormal];
  113 + [_agreeBtn setImage:xw_image2 forState:UIControlStateSelected];
  114 + [_agreeBtn addTarget:self action:@selector(clickedAgreeButton:) forControlEvents:UIControlEventTouchUpInside];
  115 + _agreeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;//居左显示
  116 +
  117 + }
  118 + return _agreeBtn;
  119 +}
  120 +
  121 +- (YYLabel *)protocol{
  122 + if (!_protocol) {
  123 + _protocol = [[YYLabel alloc] init];
  124 + NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"我已阅读并同意《注销协议》"];
  125 + text.font = [UIFont fontWithName:@"PingFangSC-Regular" size:16];
  126 + text.color = [UIColor colorWithRed:40/255.0 green:40/255.0 blue:40/255.0 alpha:1.0];
  127 +
  128 + __weak typeof(self) weakSelf = self;
  129 + [text setTextHighlightRange:NSMakeRange(7, 6) color:[UIColor colorWithRed:146/255.0 green:227/255.0 blue:154/255.0 alpha:1.0] backgroundColor:[UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1.0] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
  130 + if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(clickedProtocol:)]) {
  131 + [weakSelf.delegate clickedProtocol:weakSelf];
  132 +
  133 + }
  134 +
  135 + }];
  136 +
  137 + _protocol.attributedText = text;
  138 +
  139 + }
  140 + return _protocol;
  141 +}
  142 +
  143 +- (UIButton *)cancellationBtn{
  144 + if (!_cancellationBtn) {
  145 + _cancellationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  146 + [_cancellationBtn setTitle:@"确认注销" forState:UIControlStateNormal];
  147 + _cancellationBtn.backgroundColor = [UIColor colorWithRed:146/255.0 green:227/255.0 blue:154/255.0 alpha:1.0];
  148 + _cancellationBtn.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:17];
  149 + _cancellationBtn.layer.cornerRadius = 20;
  150 + _cancellationBtn.layer.masksToBounds = YES;
  151 + [_cancellationBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  152 + [_cancellationBtn addTarget:self action:@selector(cancellationDidClicked:) forControlEvents:UIControlEventTouchUpInside];
  153 + }
  154 + return _cancellationBtn;
  155 +}
  156 +
  157 +/**
  158 + * 创建图片
  159 + *
  160 + * @param imageName 图片名字
  161 + * @param bundleName 图片所在的bundle名字
  162 + * @param targetClass 类和bundle的同级目录
  163 + * @return 返回UIImage
  164 + */
  165 +- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{
  166 + NSBundle *bundle = [NSBundle bundleForClass:targetClass];
  167 + NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"];
  168 + NSBundle *targetBundle = [NSBundle bundleWithURL:url];
  169 + UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil];
  170 + return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
  171 +
  172 +}
  173 +
  174 +@end
  175 +
... ...
CNLiveSettingModule/Classes/Privacy/CNLiveNotSeeCollectionViewCell.h 0 → 100644
  1 +//
  2 +// CNLiveNotSeeCollectionViewCell.h
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/4/22.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +NS_ASSUME_NONNULL_BEGIN
  12 +#define kCNLiveNotSeeCollectionViewCell @"CNLiveNotSeeCollectionViewCell"
  13 +@class CNLiveNotSeeModel;
  14 +@class CNLiveNotSeeCollectionViewCell;
  15 +
  16 +@protocol CNLiveNotSeeCollectionViewCellDelegate <NSObject>
  17 +- (void)clickedDelButton:(CNLiveNotSeeCollectionViewCell *)cell;
  18 +- (void)longPressCell:(CNLiveNotSeeCollectionViewCell *)cell;
  19 +
  20 +@end
  21 +@interface CNLiveNotSeeCollectionViewCell : UICollectionViewCell
  22 +@property (nonatomic, strong) CNLiveNotSeeModel *model;
  23 +@property (nonatomic, weak) id<CNLiveNotSeeCollectionViewCellDelegate> delegate;
  24 +
  25 +@end
  26 +
  27 +NS_ASSUME_NONNULL_END
... ...
CNLiveSettingModule/Classes/Privacy/CNLiveNotSeeCollectionViewCell.m 0 → 100644
  1 +//
  2 +// CNLiveNotSeeCollectionViewCell.m
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/4/22.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLiveNotSeeCollectionViewCell.h"
  10 +#import <SDWebImage/SDWebImage.h>
  11 +#import "QMUIKit.h"
  12 +#import <Masonry/Masonry.h>
  13 +
  14 +#import "CNLiveNotSeeModel.h"
  15 +
  16 +@interface CNLiveNotSeeCollectionViewCell()
  17 +@property (nonatomic, strong) UIButton *delButton;
  18 +@property (nonatomic, strong) UIImageView *avatarImage;
  19 +@property (nonatomic, strong) UILabel *nameLabel;
  20 +
  21 +@end
  22 +
  23 +@implementation CNLiveNotSeeCollectionViewCell
  24 +- (instancetype)initWithFrame:(CGRect)frame {
  25 + self = [super initWithFrame:frame];
  26 + if (self) {
  27 + self.backgroundColor = [UIColor whiteColor];
  28 + [self configSubviews];
  29 + [self xw_layoutSubviews];
  30 +
  31 + }
  32 + return self;
  33 +}
  34 +#pragma mark - Data
  35 +- (void)setModel:(CNLiveNotSeeModel *)model {
  36 + _model = model;
  37 + if(model.type == CNLiveNotSeeModelTypeAdd){
  38 + _avatarImage.layer.masksToBounds = NO;
  39 + _avatarImage.layer.cornerRadius = 0;
  40 + UIImage *xw_image = [self xw_getImageName:@"privacy_plus" bundleName:@"CNLiveSettingModule" targetClass:[CNLiveNotSeeCollectionViewCell class]];
  41 + [_avatarImage sd_setImageWithURL:[NSURL URLWithString:@""] placeholderImage:xw_image];
  42 + _nameLabel.text = @"";
  43 +
  44 + }else if (model.type == CNLiveNotSeeModelTypeMinus){
  45 + _avatarImage.layer.masksToBounds = NO;
  46 + _avatarImage.layer.cornerRadius = 0;
  47 + UIImage *xw_image = [self xw_getImageName:@"privacy_less" bundleName:@"CNLiveSettingModule" targetClass:[CNLiveNotSeeCollectionViewCell class]];
  48 + [_avatarImage sd_setImageWithURL:[NSURL URLWithString:@""] placeholderImage:xw_image];
  49 + _nameLabel.text = @"";
  50 +
  51 + }else{
  52 + _avatarImage.layer.masksToBounds = YES;
  53 + _avatarImage.layer.cornerRadius = 5;
  54 + [_avatarImage sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:[UIImage imageNamed:@""]];
  55 + _nameLabel.text = model.nickName;
  56 +
  57 + }
  58 + if(model.type == CNLiveNotSeeModelTypeDefault && [model.isEdit isEqualToString:@"1"]){
  59 + [_delButton setHidden:NO];
  60 +
  61 + }else{
  62 + [_delButton setHidden:YES];
  63 +
  64 + }
  65 +}
  66 +- (void)configSubviews {
  67 + [self.contentView addSubview:self.avatarImage];
  68 + [self.contentView addSubview:self.nameLabel];
  69 + [self.contentView addSubview:self.delButton];
  70 + UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
  71 + longPress.minimumPressDuration = 1;
  72 + [self.contentView addGestureRecognizer:longPress];
  73 +
  74 +}
  75 +
  76 +#pragma mark - Layout
  77 +- (void)xw_layoutSubviews {
  78 + [self.avatarImage mas_makeConstraints:^(MASConstraintMaker *make) {
  79 + make.top.mas_equalTo(self.contentView).offset(15);
  80 + make.centerX.mas_equalTo(self.contentView);
  81 + make.size.mas_equalTo(CGSizeMake(50, 50));
  82 + }];
  83 +
  84 + [self.delButton mas_makeConstraints:^(MASConstraintMaker *make) {
  85 + make.top.mas_equalTo(self.contentView).offset(2.5);;
  86 + make.right.mas_equalTo(self.avatarImage.mas_left).offset(12.5);
  87 + make.size.mas_equalTo(CGSizeMake(25, 25));
  88 + }];
  89 +
  90 + [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  91 + make.centerX.mas_equalTo(self.contentView);
  92 + make.bottom.mas_equalTo(self.contentView).offset(-15);
  93 + make.left.and.right.mas_lessThanOrEqualTo(self.contentView);
  94 + }];
  95 +
  96 +}
  97 +#pragma mark - Getter
  98 +- (UIButton *)delButton{
  99 + if (!_delButton) {
  100 + _delButton = [UIButton buttonWithType:UIButtonTypeCustom];
  101 + [_delButton setImage:[UIImage imageNamed:@"privacy_edit_minus"] forState:UIControlStateNormal];
  102 + [_delButton addTarget:self action:@selector(clickedDelButton:) forControlEvents:UIControlEventTouchUpInside];
  103 + [_delButton setHidden:YES];
  104 +
  105 + }
  106 + return _delButton;
  107 +}
  108 +
  109 +- (UIImageView *)avatarImage{
  110 + if (!_avatarImage) {
  111 + _avatarImage = [[UIImageView alloc]init];
  112 + _avatarImage.userInteractionEnabled = YES;
  113 + }
  114 + return _avatarImage;
  115 +}
  116 +
  117 +- (UILabel *)nameLabel {
  118 + if (!_nameLabel) {
  119 + _nameLabel = [[UILabel alloc] init];
  120 + [_nameLabel setFont:UIFontMake(14.0)];
  121 + [_nameLabel setTextAlignment:NSTextAlignmentCenter];
  122 + _nameLabel.textColor = [UIColor blackColor];
  123 + }
  124 + return _nameLabel;
  125 +}
  126 +
  127 +#pragma mark - Action Methods
  128 +- (void)clickedDelButton:(UIButton *)btn{
  129 + if (self.delegate && [self.delegate respondsToSelector:@selector(clickedDelButton:)]) {
  130 + [self.delegate clickedDelButton:self];
  131 + }
  132 +}
  133 +
  134 +// 长按手势事件
  135 +- (void)longPress:(UILongPressGestureRecognizer *)sender{
  136 + if(_model.type == CNLiveNotSeeModelTypeAdd||_model.type == CNLiveNotSeeModelTypeMinus){
  137 + return;
  138 + }
  139 + //进行判断,在什么时候触发事件
  140 + if (sender.state == UIGestureRecognizerStateBegan) {
  141 + NSLog(@"长按状态");
  142 + if (self.delegate && [self.delegate respondsToSelector:@selector(longPressCell:)]) {
  143 + [self.delegate longPressCell:self];
  144 + }
  145 +
  146 + }
  147 +}
  148 +
  149 +/**
  150 + * 创建图片
  151 + *
  152 + * @param imageName 图片名字
  153 + * @param bundleName 图片所在的bundle名字
  154 + * @param targetClass 类和bundle的同级目录
  155 + * @return 返回UIImage
  156 + */
  157 +- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{
  158 + NSBundle *bundle = [NSBundle bundleForClass:targetClass];
  159 + NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"];
  160 + NSBundle *targetBundle = [NSBundle bundleWithURL:url];
  161 + UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil];
  162 + return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
  163 +
  164 +}
  165 +
  166 +@end
... ...
CNLiveSettingModule/Classes/Privacy/CNLiveNotSeeController.h 0 → 100644
  1 +//
  2 +// CNLiveNotSeeController.h
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/4/22.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +// 不看他/不让他看
  9 +
  10 +NS_ASSUME_NONNULL_BEGIN
  11 +typedef NS_ENUM(NSUInteger, CNNotSeeType) {
  12 + CNTypeNoLetHimSee,
  13 + CNTypeNoSeeHim
  14 +};
  15 +@interface CNLiveNotSeeController : UIViewController
  16 +@property (nonatomic, copy) NSString *name;
  17 +@property (nonatomic, assign) CNNotSeeType type;
  18 +
  19 +@end
  20 +
  21 +NS_ASSUME_NONNULL_END
... ...
CNLiveSettingModule/Classes/Privacy/CNLiveNotSeeController.m 0 → 100644
  1 +//
  2 +// CNLiveNotSeeController.m
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/4/22.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLiveNotSeeController.h"
  10 +
  11 +#import "QMUIKit.h"
  12 +#import "MJExtension.h"
  13 +#import <Masonry/Masonry.h>
  14 +
  15 +#import "CNLiveNetworking.h"
  16 +#import "CNLiveEnvironment.h"
  17 +#import "CNUserInfoManager.h"
  18 +
  19 +#import "CNLiveNotSeeCollectionViewCell.h"
  20 +#import "CNLiveNotSeeModel.h"
  21 +
  22 +@interface CNLiveNotSeeController ()<UICollectionViewDelegate, UICollectionViewDataSource, CNLiveNotSeeCollectionViewCellDelegate>{
  23 + BOOL _isEdit;
  24 +}
  25 +@property (nonatomic, strong) UIButton *rightBtn;
  26 +@property (nonatomic, strong) UIButton *leftBtn;
  27 +@property (weak, nonatomic) UICollectionView *collectionView;
  28 +@property (nonatomic, strong) NSMutableArray *beforeData;//判断完成按钮是否可以点击 一直不改变
  29 +@property (nonatomic, strong) NSMutableArray *afterData;//随时改变的
  30 +
  31 +@property (nonatomic, strong) CNLiveNotSeeModel *addModel;
  32 +@property (nonatomic, strong) CNLiveNotSeeModel *minusModel;
  33 +
  34 +@end
  35 +
  36 +@implementation CNLiveNotSeeController
  37 +static const NSInteger CellHeight = 100;
  38 +static const NSInteger CellWidth = 70;
  39 +static const NSInteger margin = 10;
  40 +
  41 +static const NSInteger SectionHeight = 50;
  42 +
  43 +#pragma mark - Data
  44 +- (void)getData{
  45 + NSDictionary *params = @{@"sid":CNUserShareModel.uid};
  46 + [CNLiveNetworking setAllowRequestDefaultArgument:YES];
  47 + [QMUITips showLoadingInView:self.view];
  48 + NSString *url = _type == CNTypeNoLetHimSee?CNPrivacyNoLetHimSeeListUrl:CNPrivacyNoSeeHimListUrl;
  49 + [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:url Param:params CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
  50 + [QMUITips hideAllTipsInView:self.view];
  51 + if (error) {
  52 + if (self.beforeData.count == 0) {
  53 + if (error.code == -1001 || error.code == -1009) {
  54 +// [self showEmptyViewWithImage:[UIImage imageNamed:@"dd_wlcw"] text:@"无法连接网络" detailText:@"别紧张,试试看刷新页面~" buttonTitle:@" 重试 " buttonAction:@selector(getData)];
  55 +// [self setCNAPIErrorEmptyView];
  56 + return;
  57 +
  58 + }
  59 + }
  60 + }
  61 + if ([responseObject isKindOfClass:[NSDictionary class]] && [responseObject[@"errorCode"] isEqualToString:@"0"]) {
  62 + if(responseObject[@"data"] && [responseObject[@"data"] isKindOfClass:[NSDictionary class]]){
  63 + NSString *key = _type == CNTypeNoLetHimSee?@"doNotletFsids":@"noLookfriends";
  64 + NSArray *arr = [CNLiveNotSeeModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][key]];
  65 + [self.beforeData addObjectsFromArray:arr];
  66 + [self.afterData addObjectsFromArray:arr];
  67 +
  68 + //加号
  69 + [self.beforeData addObject:self.addModel];
  70 + [self.afterData addObject:self.addModel];
  71 +
  72 + if(self.afterData.count > 1){
  73 + //减号
  74 + [self.beforeData addObject:self.minusModel];
  75 + [self.afterData addObject:self.minusModel];
  76 +
  77 + }
  78 +
  79 + }
  80 + }else{
  81 + //加号
  82 + [self.beforeData addObject:self.addModel];
  83 + [self.afterData addObject:self.addModel];
  84 + }
  85 + self.title = self.afterData.count > 2?[NSString stringWithFormat:@"%@(%ld)",self.name,self.afterData.count-2]:self.name;
  86 + [self.collectionView reloadData];
  87 +
  88 + }];
  89 +
  90 +}
  91 +- (void)viewDidLoad {
  92 + [super viewDidLoad];
  93 + // Do any additional setup after loading the view.
  94 + self.view.backgroundColor = [UIColor colorWithRed:244.0f/255.0f green:244.0f/255.0f blue:244.0f/255.0f alpha:1.0f];
  95 + _isEdit = NO;
  96 + [self getData];
  97 + [self setupUI];
  98 +}
  99 +- (void)dealloc{
  100 +
  101 +}
  102 +#pragma mark - UI
  103 +- (void)setupUI{
  104 + UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:self.leftBtn];
  105 + self.navigationItem.leftBarButtonItem = leftItem;
  106 +
  107 + UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:self.rightBtn];
  108 + self.navigationItem.rightBarButtonItem = rightItem;
  109 +
  110 + UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  111 + [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
  112 +
  113 + //设置CollectionView的属性
  114 + UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
  115 + collectionView.delegate = self;
  116 + collectionView.dataSource = self;
  117 + collectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
  118 + collectionView.backgroundColor = [UIColor whiteColor];
  119 +
  120 + collectionView.showsVerticalScrollIndicator = NO;
  121 + collectionView.showsHorizontalScrollIndicator = NO;
  122 + [collectionView registerClass:[CNLiveNotSeeCollectionViewCell class] forCellWithReuseIdentifier:kCNLiveNotSeeCollectionViewCell];
  123 + [collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"UICollectionElementKindSectionHeader"];
  124 + flowLayout.headerReferenceSize = CGSizeMake(SCREEN_WIDTH, 0.0000001);
  125 +
  126 + [collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"UICollectionElementKindSectionFooter"];
  127 + flowLayout.footerReferenceSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT);
  128 +
  129 + [self.view addSubview:collectionView];
  130 + _collectionView = collectionView;
  131 +
  132 +}
  133 +
  134 +- (void)viewDidLayoutSubviews {
  135 + [super viewDidLayoutSubviews];
  136 + [_collectionView mas_remakeConstraints:^(MASConstraintMaker *make) {
  137 + make.left.right.equalTo(self.view);
  138 + make.top.equalTo(self.view).offset(NavigationBarHeight);
  139 + make.height.mas_equalTo([self calculateHeight]);
  140 +
  141 + }];
  142 +}
  143 +#pragma mark - CollectionView Delegate
  144 +- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  145 + return 1;
  146 +
  147 +}
  148 +- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  149 + return self.afterData.count;
  150 +
  151 +}
  152 +- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  153 + CNLiveNotSeeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCNLiveNotSeeCollectionViewCell forIndexPath:indexPath];
  154 + cell.model = self.afterData[indexPath.row];
  155 + cell.delegate = self;
  156 + return cell;
  157 +
  158 +}
  159 +- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  160 + return CGSizeMake(CellWidth, CellHeight);
  161 +
  162 +}
  163 +//列间距
  164 +- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  165 + NSInteger count = (SCREEN_WIDTH-2*margin)/CellWidth;
  166 + return ((SCREEN_WIDTH-2*margin)-CellWidth*count)/(count - 1);
  167 +
  168 +}
  169 +//行间距
  170 +- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  171 + return 0;
  172 +
  173 +}
  174 +//组头/组尾
  175 +- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  176 +
  177 + // 如果当前想要的是头部视图
  178 + // UICollectionElementKindSectionHeader是一个const修饰的字符串常量,所以可以直接使用==比较
  179 + if (kind == UICollectionElementKindSectionHeader) {
  180 + UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"UICollectionElementKindSectionHeader" forIndexPath:indexPath];
  181 + headerView.backgroundColor = [UIColor clearColor];
  182 + return headerView;
  183 + }
  184 + else { // 返回每一组的尾部视图
  185 + UICollectionReusableView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"UICollectionElementKindSectionFooter" forIndexPath:indexPath];
  186 + footerView.backgroundColor = [UIColor colorWithRed:244.0f/255.0f green:244.0f/255.0f blue:244.0f/255.0f alpha:1.0f];
  187 + UILabel *text = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, SCREEN_WIDTH-40, SectionHeight)];
  188 + text.text = _type == CNTypeNoLetHimSee?@"把通讯录的某个朋友放到这里,生活圈可见范围发照片他(她)将无法看到。":@"把通讯录的某个朋友放到这里,该朋友更新的照片将不会在你的生活圈中出现。";
  189 +
  190 + text.font = UIFontMake(12.0);
  191 +// text.textColor = CNLiveColorWithHexString(@"999999");
  192 + text.lineBreakMode = NSLineBreakByCharWrapping;
  193 + text.numberOfLines = 0;
  194 + text.textAlignment = NSTextAlignmentCenter;
  195 + [footerView addSubview:text];
  196 + return footerView;
  197 + }
  198 +
  199 +
  200 +}
  201 +
  202 +- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  203 + if(indexPath.row == self.afterData.count - 2 || self.afterData.count == 1){//加号按钮
  204 +// CNSelectContactViewController *vc = [[CNSelectContactViewController alloc] init];
  205 +// vc.delegate = self;
  206 +// vc.existedModel = self.afterData;
  207 +// [[AppDelegate sharedAppDelegate] presentViewController:vc animated:YES completion:nil];
  208 +
  209 + }else if(indexPath.row == self.afterData.count - 1){//减号按钮
  210 + [self changeEditState];
  211 +
  212 + }else{
  213 + CNLiveNotSeeModel *model = self.afterData[indexPath.row];
  214 +// IMAUser *user = [[IMAPlatform sharedInstance].contactMgr getUserByUserId:model.userId];
  215 +// CNUserInfoViewController *vc = [[CNUserInfoViewController alloc]init];
  216 +// vc.user = user;
  217 +// [[AppDelegate sharedAppDelegate] pushViewController:vc];
  218 +
  219 + }
  220 +
  221 +}
  222 +- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  223 + if(_isEdit){//取消编辑状态
  224 + [self changeEditState];
  225 + }
  226 +
  227 +}
  228 +#pragma mark - CNLiveNotSeeCollectionViewCellDelegate
  229 +- (void)longPressCell:(CNLiveNotSeeCollectionViewCell *)cell{
  230 + [self changeEditState];
  231 +
  232 +}
  233 +
  234 +- (void)clickedDelButton:(CNLiveNotSeeCollectionViewCell *)cell{
  235 + if([self.afterData containsObject:cell.model]){
  236 + [self.afterData removeObject:cell.model];
  237 +
  238 + if(self.afterData.count == 2&&[self.afterData containsObject:self.minusModel]){
  239 + // 删除减号按钮
  240 + [self.afterData removeObject:self.minusModel];
  241 + [self.beforeData removeObject:self.minusModel];
  242 +
  243 + }
  244 +
  245 + self.title = self.afterData.count > 2?[NSString stringWithFormat:@"%@(%ld)",self.name,self.afterData.count-2]:self.name;
  246 + //判断完成按钮是否可以点击
  247 + _rightBtn.userInteractionEnabled = ![self array:self.beforeData isEqualTo:self.afterData];
  248 + _rightBtn.selected = _rightBtn.userInteractionEnabled;
  249 +
  250 +// _collectionView.height = [self calculateHeight];
  251 + [self.collectionView reloadData];
  252 +
  253 + }
  254 +}
  255 +#pragma mark - CNSelectContactDelegate
  256 +//选择联系人完成代理,返回
  257 +//- (void)selectContactCompleted:(NSMutableArray *)selectedFriends{
  258 +// for (IMAUser *user in selectedFriends) {
  259 +// NSLog(@"nickName = %@",user.nickName);
  260 +// CNLiveNotSeeModel *model = [[CNLiveNotSeeModel alloc]init];
  261 +// model.userId = user.userId;
  262 +// model.nickName = user.nickName;
  263 +// model.image = user.icon;
  264 +// model.isEdit = _isEdit?@"1":@"0";
  265 +// model.type = CNLiveNotSeeModelTypeDefault;
  266 +// //大于2说明存在+-按钮
  267 +// if(self.afterData.count > 2){
  268 +// [self.afterData insertObject:model atIndex:self.afterData.count-2];
  269 +//
  270 +// }else{
  271 +// [self.afterData insertObject:model atIndex:0];
  272 +//
  273 +// }
  274 +//
  275 +// }
  276 +//
  277 +// //等于2说明只存在+按钮
  278 +// if(self.afterData.count == 2){
  279 +// if([self array:@[self.addModel,self.minusModel] isEqualTo:self.afterData]){
  280 +// // 删除减号按钮
  281 +// if(![self.afterData containsObject:self.minusModel]){
  282 +// [self.afterData addObject:self.minusModel];
  283 +// [self.beforeData addObject:self.minusModel];
  284 +// }
  285 +//
  286 +// }else{
  287 +// //减号
  288 +// if([self.afterData containsObject:self.minusModel]){
  289 +// [self.afterData removeObject:self.minusModel];
  290 +// [self.beforeData removeObject:self.minusModel];
  291 +// }
  292 +// }
  293 +//
  294 +// }else{
  295 +// //减号
  296 +// if(![self.afterData containsObject:self.minusModel]){
  297 +// [self.afterData addObject:self.minusModel];
  298 +// [self.beforeData addObject:self.minusModel];
  299 +// }
  300 +// }
  301 +// self.title = self.afterData.count > 2?[NSString stringWithFormat:@"%@(%ld)",self.name,self.afterData.count-2]:self.name;
  302 +// //判断完成按钮是否可以点击
  303 +// _rightBtn.userInteractionEnabled = ![self array:self.beforeData isEqualTo:self.afterData];
  304 +// _rightBtn.selected =_rightBtn.userInteractionEnabled;
  305 +//
  306 +// _collectionView.height = [self calculateHeight];
  307 +// [self.collectionView reloadData];
  308 +//
  309 +//}
  310 +
  311 +#pragma mark - Private Methods
  312 +//数组相等
  313 +- (BOOL)array:(NSArray *)array1 isEqualTo:(NSArray *)array2 {
  314 + if (array1 == array2) {
  315 + return YES;
  316 + }
  317 + if (array1.count != array2.count) {
  318 + return NO;
  319 + }
  320 + NSMutableArray *arr1 = [NSMutableArray arrayWithArray:array1];
  321 + NSMutableArray *arr2 = [NSMutableArray arrayWithArray:array2];
  322 +
  323 + if([arr1 containsObject:self.addModel]){
  324 + [arr1 removeObject:self.addModel];
  325 + }
  326 + if([arr2 containsObject:self.addModel]){
  327 + [arr2 removeObject:self.addModel];
  328 + }
  329 + if([arr1 containsObject:self.minusModel]){
  330 + [arr1 removeObject:self.minusModel];
  331 + }
  332 + if([arr2 containsObject:self.minusModel]){
  333 + [arr2 removeObject:self.minusModel];
  334 + }
  335 +
  336 + BOOL isEqual = YES;
  337 + for(int i = 0; i < arr1.count; i++){
  338 + CNLiveNotSeeModel *model1 = arr1[i];
  339 +
  340 + for(int j = 0; j < arr2.count; j++){
  341 + CNLiveNotSeeModel *model2 = arr2[j];
  342 + if([model1.userId isEqualToString:model2.userId]){
  343 + break;
  344 + }
  345 + if(j == arr2.count-1){
  346 + isEqual = NO;
  347 + }
  348 + }
  349 + }
  350 + return isEqual;
  351 +
  352 +}
  353 +- (CGFloat)calculateHeight{
  354 + NSInteger count = (SCREEN_WIDTH-2*margin)/CellWidth;
  355 + NSInteger row = ceilf(self.afterData.count*1.0/count);
  356 + CGFloat height = (row*(CellHeight)+SectionHeight) > (SCREEN_HEIGHT-NavigationBarHeight) ? (SCREEN_HEIGHT-NavigationBarHeight):(row*(CellHeight)+SectionHeight);
  357 + return height;
  358 +}
  359 +//改变编辑状态
  360 +- (void)changeEditState{
  361 + _isEdit = !_isEdit;
  362 + for (int i = 0; i < self.afterData.count; i++){
  363 + CNLiveNotSeeModel *model = self.afterData[i];
  364 + model.isEdit = model.type == CNLiveNotSeeModelTypeDefault&&_isEdit? @"1":@"0";
  365 +
  366 + }
  367 + [self.collectionView reloadData];
  368 +}
  369 +
  370 +// 增加
  371 +- (void)sendAddDataBlock:(void(^)(NSString *))block{
  372 + NSMutableArray *IDs = [NSMutableArray array];
  373 + for (CNLiveNotSeeModel *model in self.afterData) {
  374 + model.userId&&![model.userId isEqualToString:@"addModel"]&&![model.userId isEqualToString:@"minusModel"]?[IDs addObject:model.userId]:@"";
  375 + }
  376 + NSString *str = [NSString stringWithFormat:@"[%@]",[IDs componentsJoinedByString:@","]];
  377 + NSDictionary *params = @{@"sid":CNUserShareModel.uid,@"friendIds":str,@"appId":AppId};
  378 + [CNLiveNetworking setAllowRequestDefaultArgument:YES];
  379 + [QMUITips showLoadingInView:self.view];
  380 +
  381 + NSString *url = _type == CNTypeNoLetHimSee?CNPrivacyNoLetHimSeeAddUrl:CNPrivacyNoSeeHimAddUrl;
  382 + [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:url Param:params CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
  383 + [QMUITips hideAllTipsInView:self.view];
  384 + if ([responseObject isKindOfClass:[NSDictionary class]] && [responseObject[@"errorCode"] isEqualToString:@"0"]) {
  385 + [QMUITips showSucceed:@"已修改完毕" inView:self.view hideAfterDelay:1.5];
  386 + block?block(@"1"):@"";
  387 +
  388 + }else{
  389 + [QMUITips showError:@"修改失败" inView:self.view hideAfterDelay:1.5];
  390 + block?block(@"0"):@"";
  391 +
  392 + }
  393 +
  394 + }];
  395 +
  396 +}
  397 +
  398 +#pragma mark - Action Methods
  399 +// 点击完成按钮事件-发送请求
  400 +- (void)clickedCompleteButton:(UIButton *)btn{
  401 + btn.userInteractionEnabled = NO;
  402 + [self sendAddDataBlock:^(NSString *isSuccess) {
  403 + if([isSuccess isEqualToString:@"1"]){
  404 + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  405 + [self.navigationController popViewControllerAnimated:YES];
  406 + });
  407 + }
  408 + btn.userInteractionEnabled = YES;
  409 +
  410 + }];
  411 +
  412 +}
  413 +
  414 +// 点击取消按钮事件
  415 +- (void)clickedCloseButton:(UIButton *)btn {
  416 + if([self array:self.beforeData isEqualTo:self.afterData]){
  417 + [self.navigationController popViewControllerAnimated:YES];
  418 + return;
  419 +
  420 + }
  421 + UIAlertController *actionAlert1 = [UIAlertController alertControllerWithTitle:@"确认放弃修改吗?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  422 + UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:NULL];
  423 + UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  424 + [self.navigationController popViewControllerAnimated:YES];
  425 + }];
  426 +// [action1 setValue:CNLiveColorWithHexString(@"23D41E") forKey:@"_titleTextColor"];
  427 +// [action2 setValue:CNLiveColorWithHexString(@"23D41E") forKey:@"_titleTextColor"];
  428 + [actionAlert1 addAction:action1];
  429 + [actionAlert1 addAction:action2];
  430 + [self presentViewController:actionAlert1 animated:YES completion:nil];
  431 +
  432 +}
  433 +/*
  434 + #pragma mark - Navigation
  435 +
  436 + // In a storyboard-based application, you will often want to do a little preparation before navigation
  437 + - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  438 + // Get the new view controller using [segue destinationViewController].
  439 + // Pass the selected object to the new view controller.
  440 + }
  441 + */
  442 +#pragma mark - Lazy Laoding
  443 +- (NSMutableArray *)beforeData{
  444 + if (!_beforeData) {
  445 + _beforeData = [[NSMutableArray alloc] init];
  446 + }
  447 + return _beforeData;
  448 +}
  449 +
  450 +- (NSMutableArray *)afterData{
  451 + if (!_afterData) {
  452 + _afterData = [[NSMutableArray alloc] init];
  453 + }
  454 + return _afterData;
  455 +}
  456 +
  457 +- (UIButton *)rightBtn {
  458 + if (!_rightBtn) {
  459 + _rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  460 + _rightBtn.frame = CGRectMake(0, 0, 60, 30);
  461 + [_rightBtn setTitle:@"完成" forState:UIControlStateNormal];
  462 + _rightBtn.titleLabel.font = UIFontMake(14.0);
  463 + [_rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  464 +// [_rightBtn setBackgroundImage:[UIImage imageWithColor:CNLiveColorWithHexString(@"23D41E")] forState:UIControlStateSelected];
  465 +// [_rightBtn setBackgroundImage:[UIImage imageWithColor:CNLiveColorWithHexString(@"9BF4A4")] forState:UIControlStateNormal];
  466 + [_rightBtn addTarget:self action:@selector(clickedCompleteButton:) forControlEvents:UIControlEventTouchUpInside];
  467 + _rightBtn.layer.masksToBounds = YES;
  468 + _rightBtn.layer.cornerRadius = 15;
  469 + _rightBtn.userInteractionEnabled = NO;
  470 + _rightBtn.selected = NO;
  471 +
  472 + }
  473 + return _rightBtn;
  474 +}
  475 +
  476 +- (UIButton *)leftBtn {
  477 + if (!_leftBtn) {
  478 + _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  479 + [_leftBtn setTitle:@"取消" forState:UIControlStateNormal];
  480 + _leftBtn.frame = CGRectMake(0, 0, 60, 30);
  481 + _leftBtn.titleLabel.font = UIFontMake(15.0);
  482 + [_leftBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  483 + [_leftBtn addTarget:self action:@selector(clickedCloseButton:) forControlEvents:UIControlEventTouchUpInside];
  484 + _leftBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  485 + }
  486 + return _leftBtn;
  487 +}
  488 +- (CNLiveNotSeeModel *)addModel{
  489 + if (!_addModel) {
  490 + //加号
  491 + _addModel = [[CNLiveNotSeeModel alloc]init];
  492 + _addModel.userId = @"addModel";
  493 + _addModel.nickName = @"addModel";
  494 + _addModel.type = CNLiveNotSeeModelTypeAdd;
  495 + }
  496 + return _addModel;
  497 +}
  498 +- (CNLiveNotSeeModel *)minusModel{
  499 + if (!_minusModel) {
  500 + //减号
  501 + _minusModel = [[CNLiveNotSeeModel alloc]init];
  502 + _minusModel.userId = @"minusModel";
  503 + _minusModel.nickName = @"minusModel";
  504 + _minusModel.type = CNLiveNotSeeModelTypeMinus;
  505 + }
  506 + return _minusModel;
  507 +}
  508 +- (UIImage *)navigationBarBackgroundImage {
  509 +// return [UIImage imageWithColor:CNLiveColorWithHexString(@"F4F4F4")];
  510 + return nil;
  511 +}
  512 +
  513 +@end
... ...
CNLiveSettingModule/Classes/Privacy/CNLiveNotSeeModel.h 0 → 100644
  1 +//
  2 +// CNLiveNotSeeModel.h
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/4/22.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +
  11 +NS_ASSUME_NONNULL_BEGIN
  12 +typedef NS_ENUM(NSUInteger, CNLiveNotSeeModelType) {
  13 + CNLiveNotSeeModelTypeDefault,
  14 + CNLiveNotSeeModelTypeAdd,
  15 + CNLiveNotSeeModelTypeMinus,
  16 +};
  17 +@interface CNLiveNotSeeModel : NSObject
  18 +@property (nonatomic, copy) NSString *image;
  19 +@property (nonatomic, copy) NSString *nickName;
  20 +@property (nonatomic, copy) NSString *userId;
  21 +
  22 +
  23 +@property (nonatomic, assign) CNLiveNotSeeModelType type;
  24 +@property (nonatomic, copy) NSString *isEdit;
  25 +
  26 +@end
  27 +
  28 +NS_ASSUME_NONNULL_END
... ...
CNLiveSettingModule/Classes/Privacy/CNLiveNotSeeModel.m 0 → 100644
  1 +//
  2 +// CNLiveNotSeeModel.m
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/4/22.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLiveNotSeeModel.h"
  10 +
  11 +@implementation CNLiveNotSeeModel
  12 +
  13 +@end
... ...
CNLiveSettingModule/Classes/Privacy/CNLivePrivacyContactTableViewCell.h 0 → 100644
  1 +//
  2 +// CNLivePrivacyContactTableViewCell.h
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/4/24.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +NS_ASSUME_NONNULL_BEGIN
  12 +@class IMAUser;
  13 +
  14 +@protocol CNLivePrivacyContactCellDelegate <NSObject>
  15 +- (void)onPickAction:(IMAUser *)user;
  16 +
  17 +@end
  18 +
  19 +@interface CNLivePrivacyContactTableViewCell : UITableViewCell
  20 +@property (nonatomic, strong) UIButton *selectBtn;
  21 +@property (nonatomic, strong) IMAUser *user;
  22 +@property (nonatomic, assign) id<CNLivePrivacyContactCellDelegate> delegate;
  23 +
  24 ++ (instancetype)cellWithTableView:(UITableView *)tableView;
  25 +- (void)onPick;
  26 +
  27 +@end
  28 +
  29 +
  30 +
  31 +@interface CNLivePrivacyGroupCell : UITableViewCell
  32 ++ (instancetype)cellWithTableView:(UITableView *)tableView;
  33 +
  34 +@end
  35 +
  36 +NS_ASSUME_NONNULL_END
... ...
CNLiveSettingModule/Classes/Privacy/CNLivePrivacyContactTableViewCell.m 0 → 100644
  1 +//
  2 +// CNLivePrivacyContactTableViewCell.m
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/4/24.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLivePrivacyContactTableViewCell.h"
  10 +#import <Masonry/Masonry.h>
  11 +#import "QMUIKit.h"
  12 +
  13 +@interface CNLivePrivacyContactTableViewCell ()
  14 +@property (nonatomic, strong) UIImageView *iconImage;
  15 +@property (nonatomic, strong) UILabel *nickLabel;
  16 +
  17 +@end
  18 +
  19 +@implementation CNLivePrivacyContactTableViewCell
  20 +#pragma mark - Init
  21 ++ (instancetype)cellWithTableView:(UITableView *)tableView {
  22 + static NSString *indentify = @"CNLivePrivacyContactTableViewCell";
  23 + CNLivePrivacyContactTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentify];
  24 + if (!cell) {
  25 + cell = [[CNLivePrivacyContactTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentify];
  26 + }
  27 + return cell;
  28 +
  29 +}
  30 +
  31 +- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  32 + self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  33 + if (self) {
  34 + self.backgroundColor = [UIColor whiteColor];
  35 + [self.contentView addSubview:self.selectBtn];
  36 + [self.contentView addSubview:self.iconImage];
  37 + [self.contentView addSubview:self.nickLabel];
  38 + [self xw_layoutSubviews];
  39 +
  40 + }
  41 + return self;
  42 +}
  43 +
  44 +#pragma mark - Data
  45 +//- (void)setUser:(IMAUser *)user {
  46 +// _user = user;
  47 +// _selectBtn.selected = user.isSelected;
  48 +//
  49 +// [_iconImage sd_setImageWithURL:[NSURL URLWithString:user.icon] placeholderImage:kDefaultUserIcon];
  50 +// _nickLabel.text = [user showTitle];
  51 +//
  52 +// if (!_selectBtn.enabled) {
  53 +// [_selectBtn setBackgroundImage:[UIImage imageNamed:@"privacy_edit_no"] forState:UIControlStateNormal];
  54 +// }
  55 +// else{
  56 +// [_selectBtn setBackgroundImage:[UIImage imageNamed:@"privacy_sel_no"] forState:UIControlStateNormal];
  57 +//
  58 +// }
  59 +//
  60 +//}
  61 +
  62 +#pragma mark - Action
  63 +- (void)onPick {
  64 + [self onPicked:_selectBtn];
  65 +}
  66 +
  67 +- (void)onPicked:(UIButton *)btn {
  68 +// btn.selected = !btn.selected;
  69 +// _user.isSelected = btn.selected;
  70 +//
  71 +// if (self.delegate && [self.delegate respondsToSelector:@selector(onPickAction:)]) {
  72 +// [self.delegate onPickAction:_user];
  73 +// }
  74 +
  75 +}
  76 +
  77 +#pragma mark - Layout
  78 +- (void)xw_layoutSubviews {
  79 + [self.selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  80 + make.left.mas_equalTo(self.contentView).mas_offset(20);
  81 + make.centerY.mas_equalTo(self.contentView);
  82 + make.size.mas_equalTo(CGSizeMake(20, 20));
  83 + }];
  84 +
  85 + [self.iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
  86 + make.left.mas_equalTo(self.selectBtn.mas_right).mas_offset(20);
  87 + make.centerY.mas_equalTo(self.contentView);
  88 + make.size.mas_equalTo(CGSizeMake(40, 40));
  89 + }];
  90 +
  91 + [self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  92 + make.left.mas_equalTo(self.iconImage.mas_right).mas_offset(10);
  93 + make.right.mas_equalTo(self.contentView.mas_right).mas_offset(-10);
  94 + make.centerY.mas_equalTo(self.selectBtn.mas_centerY);
  95 + }];
  96 +
  97 +}
  98 +
  99 +#pragma mark - Getter
  100 +- (UIButton *)selectBtn {
  101 + if (!_selectBtn) {
  102 + _selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  103 + [_selectBtn setBackgroundImage:[UIImage imageNamed:@"privacy_sel_no"] forState:UIControlStateNormal];
  104 + [_selectBtn setBackgroundImage:[UIImage imageNamed:@"privacy_sel_yes"] forState:UIControlStateSelected];
  105 + [_selectBtn addTarget:self action:@selector(onPicked:) forControlEvents:UIControlEventTouchUpInside];
  106 + }
  107 + return _selectBtn;
  108 +}
  109 +
  110 +- (UIImageView *)iconImage {
  111 + if (!_iconImage) {
  112 + _iconImage = [[UIImageView alloc] init];
  113 + }
  114 + return _iconImage;
  115 +}
  116 +
  117 +- (UILabel *)nickLabel {
  118 + if (!_nickLabel) {
  119 + _nickLabel = [[UILabel alloc] init];
  120 + _nickLabel.textColor = [UIColor blackColor];
  121 + _nickLabel.font = UIFontMake(17.0);
  122 + }
  123 + return _nickLabel;
  124 +}
  125 +
  126 +- (void)awakeFromNib {
  127 + [super awakeFromNib];
  128 + // Initialization code
  129 +}
  130 +
  131 +- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  132 + [super setSelected:selected animated:animated];
  133 + // Configure the view for the selected state
  134 +}
  135 +
  136 +@end
  137 +
  138 +@interface CNLivePrivacyGroupCell ()
  139 +@property (nonatomic, strong) UILabel *titleLabel;
  140 +@property (nonatomic, strong) UIImageView *moreImage;
  141 +
  142 +@end
  143 +
  144 +@implementation CNLivePrivacyGroupCell
  145 ++ (instancetype)cellWithTableView:(UITableView *)tableView {
  146 +
  147 + static NSString *indentify = @"CNLivePrivacyGroupCell";
  148 +
  149 + CNLivePrivacyGroupCell *cell = [tableView dequeueReusableCellWithIdentifier:indentify];
  150 + if (!cell) {
  151 + cell = [[CNLivePrivacyGroupCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentify];
  152 + }
  153 + return cell;
  154 +
  155 +}
  156 +
  157 +- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  158 + self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  159 + if (self) {
  160 + self.backgroundColor = [UIColor whiteColor];
  161 + [self.contentView addSubview:self.titleLabel];
  162 + [self.contentView addSubview:self.moreImage];
  163 + [self xw_layoutSubviews];
  164 + }
  165 + return self;
  166 +}
  167 +
  168 +- (void)xw_layoutSubviews {
  169 + [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  170 + make.left.mas_equalTo(self.contentView).mas_offset(20);
  171 + make.right.mas_equalTo(self.contentView.mas_right).mas_offset(-30);
  172 + make.top.mas_equalTo(self.contentView).mas_offset(20);
  173 + }];
  174 +
  175 + [self.moreImage mas_makeConstraints:^(MASConstraintMaker *make) {
  176 + make.size.mas_equalTo(CGSizeMake(7, 14));
  177 + make.right.mas_equalTo(self.contentView.mas_right).mas_offset(-10);
  178 + make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
  179 + }];
  180 +
  181 +}
  182 +
  183 +#pragma mark - Getter
  184 +- (UILabel *)titleLabel {
  185 + if (!_titleLabel) {
  186 + _titleLabel = [[UILabel alloc] init];
  187 + _titleLabel.text = @"选择一个群";
  188 + _titleLabel.textColor = [UIColor blackColor];
  189 + _titleLabel.font = UIFontMake(17.0);
  190 + }
  191 + return _titleLabel;
  192 +}
  193 +
  194 +- (UIImageView *)moreImage {
  195 + if (!_moreImage) {
  196 + UIImage *xw_image = [self xw_getImageName:@"mine_info_front" bundleName:@"CNLiveSettingModule" targetClass:[CNLivePrivacyContactTableViewCell class]];
  197 + _moreImage = [[UIImageView alloc] initWithImage:xw_image];
  198 + }
  199 + return _moreImage;
  200 +}
  201 +
  202 +/**
  203 + * 创建图片
  204 + *
  205 + * @param imageName 图片名字
  206 + * @param bundleName 图片所在的bundle名字
  207 + * @param targetClass 类和bundle的同级目录
  208 + * @return 返回UIImage
  209 + */
  210 +- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{
  211 + NSBundle *bundle = [NSBundle bundleForClass:targetClass];
  212 + NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"];
  213 + NSBundle *targetBundle = [NSBundle bundleWithURL:url];
  214 + UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil];
  215 + return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
  216 +}
  217 +
  218 +@end
... ...
CNLiveSettingModule/Classes/Privacy/CNLivePrivacyController.h 0 → 100644
  1 +//
  2 +// CNLivePrivacyController.h
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/4/22.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +// 隐私
  10 +
  11 +NS_ASSUME_NONNULL_BEGIN
  12 +
  13 +@interface CNLivePrivacyController : UIViewController
  14 +
  15 +@end
  16 +
  17 +NS_ASSUME_NONNULL_END
... ...
CNLiveSettingModule/Classes/Privacy/CNLivePrivacyController.m 0 → 100644
  1 +//
  2 +// CNLivePrivacyController.m
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/4/22.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLivePrivacyController.h"
  10 +
  11 +#import "QMUIKit.h"
  12 +#import "MJExtension.h"
  13 +#import <Masonry/Masonry.h>
  14 +
  15 +#import "CNLiveNetworking.h"
  16 +#import "CNLiveEnvironment.h"
  17 +#import "CNUserInfoManager.h"
  18 +
  19 +#import "CNLiveSettingNavigationBar.h"
  20 +#import "CNLivePrivacyTableViewCell.h"
  21 +#import "CNLivePrivacyHeaderView.h"
  22 +#import "CNLivePrivacyModel.h"
  23 +#import "CNLiveNotSeeController.h"//不让看/不看
  24 +//#import "CNLiveBlackListController.h"//通讯录黑名单
  25 +
  26 +@interface CNLivePrivacyController ()<UITableViewDelegate,UITableViewDataSource,CNLiveSettingNavigationBarDelegate>
  27 +@property (nonatomic, strong) CNLiveSettingNavigationBar *navigationBar;
  28 +@property (nonatomic, strong) UITableView *tableView;
  29 +@property (nonatomic, strong) NSMutableArray <CNLivePrivacyModel*>*data;
  30 +@property (nonatomic, strong) CNLivePrivacyModel *model;
  31 +
  32 +@end
  33 +
  34 +@implementation CNLivePrivacyController
  35 +#pragma mark - Data
  36 +- (void)loadData:(NSString *)status {
  37 + NSArray *array = @[
  38 + @{
  39 + @"title":@"不让他(她)看",
  40 + @"rowHeight":@50,
  41 + @"lineHeight":@0,
  42 + @"cellType":@0
  43 + },
  44 + @{
  45 + @"title":@"不看他(她)",
  46 + @"rowHeight":@51,
  47 + @"lineHeight":@1,
  48 + @"cellType":@0
  49 + },
  50 + @{
  51 + @"title":@"允许陌生人查看生活圈",
  52 + @"rowHeight":@51,
  53 + @"lineHeight":@1,
  54 + @"cellType":@1,
  55 + @"status":status
  56 + }
  57 +
  58 + ];
  59 + NSDictionary *dic = @{
  60 + @"title":@"通讯录黑名单",
  61 + @"rowHeight":@50,
  62 + @"lineHeight":@0,
  63 + @"cellType":@0
  64 + };
  65 + self.data = [CNLivePrivacyModel mj_objectArrayWithKeyValuesArray:array];
  66 + self.model = [CNLivePrivacyModel mj_objectWithKeyValues:dic];
  67 + [self.tableView reloadData];
  68 +
  69 +}
  70 +
  71 +//允许陌生人查看生活圈
  72 +- (void)getData {
  73 + NSDictionary *params = @{@"appId":AppId,
  74 + @"sid":CNUserShareModel.uid};
  75 + [CNLiveNetworking setAllowRequestDefaultArgument:YES];
  76 + [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNIsAllowFindStrangerSwitchUrl Param:params CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
  77 + if ([responseObject isKindOfClass:[NSDictionary class]] && [responseObject[@"errorCode"] isEqualToString:@"0"]) {
  78 + if(responseObject[@"data"] && [responseObject[@"data"] isKindOfClass:[NSDictionary class]]){
  79 + NSMutableArray <CNLivePrivacyModel *>*arr = [CNLivePrivacyModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"findStrangerSwitch"]];
  80 + CNLivePrivacyModel *model = [arr firstObject];
  81 + [[NSUserDefaults standardUserDefaults] setValue:model.status forKey:@"findStrangerSwitch"];
  82 + for (CNLivePrivacyModel *model in self.data) {
  83 + if([model.title isEqualToString:@"允许陌生人查看生活圈"]){
  84 + model.status = model.status;
  85 + }
  86 + }
  87 + }
  88 + }
  89 + [self.tableView reloadData];
  90 +
  91 + }];
  92 +
  93 +}
  94 +
  95 +- (void)viewWillAppear:(BOOL)animated {
  96 + [super viewWillAppear:animated];
  97 + [self.tableView reloadData];
  98 +
  99 +}
  100 +- (void)viewDidLoad {
  101 + [super viewDidLoad];
  102 + // Do any additional setup after loading the view.
  103 + self.title = @"隐私";
  104 + self.view.backgroundColor = [UIColor whiteColor];
  105 + [self getData];
  106 + NSString *status = [[NSUserDefaults standardUserDefaults] valueForKey:@"findStrangerSwitch"];
  107 + [self loadData:status?status:@"access"];
  108 + [self createUI];
  109 +
  110 +}
  111 +//网络监听
  112 +- (void)cn_noNetworking {
  113 + [self.tableView reloadData];
  114 +
  115 +}
  116 +
  117 +- (void)cn_wifiOrWWANNetworking {
  118 + [self.tableView reloadData];
  119 +}
  120 +#pragma mark - UI
  121 +- (void)createUI {
  122 + [self.view addSubview:self.navigationBar];
  123 + [self.view addSubview:self.tableView];
  124 +
  125 +}
  126 +
  127 +#pragma mark - UITableViewDataSource
  128 +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  129 + return 2;
  130 +}
  131 +
  132 +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  133 + return section == 0?1:self.data.count;
  134 +
  135 +}
  136 +
  137 +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  138 + CNLivePrivacyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCNLivePrivacyTableViewCell forIndexPath:indexPath];
  139 + cell.model = indexPath.section == 0?self.model:self.data[indexPath.row];
  140 + cell.selectionStyle = UITableViewCellSelectionStyleNone;
  141 + return cell;
  142 +
  143 +}
  144 +
  145 +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  146 + return self.data[indexPath.row].rowHeight;
  147 +
  148 +}
  149 +- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  150 + return section == 0?10:30;
  151 +}
  152 +- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  153 + return 0.000001f;
  154 +
  155 +}
  156 +- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  157 + CNLivePrivacyHeaderView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:kCNLivePrivacyHeaderView];
  158 + view.text = section == 0?@"":@"生活圈和视频动态";
  159 + return view;
  160 +}
  161 +
  162 +#pragma mark - UITableViewDelegate
  163 +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  164 + if(indexPath.section == 0){
  165 + //通讯录黑名单
  166 +// CNBlackListViewController *vc = [[CNBlackListViewController alloc] init];
  167 +// [[AppDelegate sharedAppDelegate] pushViewController:vc withBackTitle:@" "];
  168 +
  169 + }else if(indexPath.section == 1){
  170 + switch (indexPath.row) {
  171 + case 0: //不让他(她)看
  172 + {
  173 + CNLivePrivacyModel *model = self.data[indexPath.row];
  174 + CNLiveNotSeeController *vc = [[CNLiveNotSeeController alloc] init];
  175 + vc.name = model.title;
  176 + vc.type = CNTypeNoLetHimSee;
  177 + [self.navigationController pushViewController:vc animated:YES];
  178 +
  179 + }
  180 + break;
  181 + case 1: //不看他(她)
  182 + {
  183 + CNLivePrivacyModel *model = self.data[indexPath.row];
  184 + CNLiveNotSeeController *vc = [[CNLiveNotSeeController alloc] init];
  185 + vc.name = model.title;
  186 + vc.type = CNTypeNoSeeHim;
  187 + [self.navigationController pushViewController:vc animated:YES];
  188 +
  189 + }
  190 + break;
  191 + case 2: //允许陌生人查看生活圈
  192 + {
  193 +
  194 + }
  195 + break;
  196 +
  197 + default:
  198 + break;
  199 + }
  200 + }
  201 +
  202 +}
  203 +
  204 +#pragma mark - CNLiveSettingNavigationBarDelegate
  205 +- (void)navigationBar:(CNLiveSettingNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{
  206 + if ([actionEvents isEqualToString:@"1"]) {
  207 + [self goBack];
  208 + }else if ([actionEvents isEqualToString:@"2"]){
  209 +
  210 + }
  211 +}
  212 +
  213 +#pragma mark - Action
  214 +- (void)goBack {
  215 + if (self.presentingViewController != nil) {
  216 + [self dismissViewControllerAnimated:YES completion:nil];
  217 + }
  218 + else {
  219 + [self.navigationController popViewControllerAnimated:YES];
  220 + }
  221 +}
  222 +
  223 +#pragma mark - Lazy loading
  224 +- (CNLiveSettingNavigationBar *)navigationBar {
  225 + if (!_navigationBar) {
  226 + _navigationBar = [[CNLiveSettingNavigationBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationContentTop)];
  227 + _navigationBar.backgroundColor = [UIColor whiteColor];
  228 + _navigationBar.delegate = self;
  229 + _navigationBar.title.text = @"隐私";
  230 + _navigationBar.right = nil;
  231 + }
  232 + return _navigationBar;
  233 +}
  234 +- (UITableView *)tableView {
  235 + if (!_tableView) {
  236 + _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavigationContentTop, SCREEN_WIDTH, SCREEN_HEIGHT-NavigationContentTop) style:UITableViewStyleGrouped];
  237 + _tableView.backgroundColor = UIColorMake(242, 242, 242);
  238 + _tableView.delegate = self;
  239 + _tableView.dataSource = self;
  240 + _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  241 + _tableView.showsVerticalScrollIndicator = NO;
  242 + _tableView.showsHorizontalScrollIndicator = NO;
  243 + [_tableView registerClass:[CNLivePrivacyTableViewCell class] forCellReuseIdentifier:kCNLivePrivacyTableViewCell];
  244 + [_tableView registerClass:[CNLivePrivacyHeaderView class] forHeaderFooterViewReuseIdentifier:kCNLivePrivacyHeaderView];
  245 + }
  246 + return _tableView;
  247 +
  248 +}
  249 +
  250 +- (NSMutableArray *)data{
  251 + if (!_data) {
  252 + _data = [[NSMutableArray alloc] init];
  253 + }
  254 + return _data;
  255 +}
  256 +
  257 +@end
... ...
CNLiveSettingModule/Classes/Privacy/CNLivePrivacyHeaderView.h 0 → 100644
  1 +//
  2 +// CNPrivacyHeaderView.h
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/4/23.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +NS_ASSUME_NONNULL_BEGIN
  12 +#define kCNLivePrivacyHeaderView @"CNLivePrivacyHeaderView"
  13 +
  14 +@interface CNLivePrivacyHeaderView : UITableViewHeaderFooterView
  15 +@property (nonatomic, copy) NSString *text;
  16 +
  17 +@end
  18 +
  19 +NS_ASSUME_NONNULL_END
... ...
CNLiveSettingModule/Classes/Privacy/CNLivePrivacyHeaderView.m 0 → 100644
  1 +//
  2 +// CNLivePrivacyHeaderView.m
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/4/23.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLivePrivacyHeaderView.h"
  10 +#import <Masonry/Masonry.h>
  11 +#import "QMUIKit.h"
  12 +
  13 +@interface CNLivePrivacyHeaderView()
  14 +@property (nonatomic, strong) UILabel *titleLabel;
  15 +
  16 +@end
  17 +@implementation CNLivePrivacyHeaderView
  18 +- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier {
  19 + if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
  20 + self.backgroundColor = [UIColor grayColor];
  21 + [self createUI];
  22 + }
  23 + return self;
  24 +}
  25 +
  26 +#pragma mark - UI
  27 +- (void)createUI{
  28 + [self.contentView addSubview:self.titleLabel];
  29 + [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  30 + make.left.mas_equalTo(self.contentView).mas_offset(10);
  31 + make.right.mas_equalTo(self.contentView).mas_offset(-10);
  32 + make.bottom.mas_equalTo(self.contentView).mas_offset(-5);
  33 +
  34 + }];
  35 +}
  36 +
  37 +#pragma mark - Setter
  38 +- (void)setText:(NSString *)text{
  39 + _text = text;
  40 + self.titleLabel.text = text;
  41 +}
  42 +
  43 +#pragma mark - Getter
  44 +- (UILabel *) titleLabel {
  45 + if (_titleLabel == nil) {
  46 + _titleLabel = [[UILabel alloc] init];
  47 + [_titleLabel setTextColor:[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0]];
  48 + [_titleLabel setFont:UIFontMake(13)];
  49 + [_titleLabel setNumberOfLines:0];
  50 + }
  51 + return _titleLabel;
  52 +}
  53 +
  54 +/*
  55 +// Only override drawRect: if you perform custom drawing.
  56 +// An empty implementation adversely affects performance during animation.
  57 +- (void)drawRect:(CGRect)rect {
  58 + // Drawing code
  59 +}
  60 +*/
  61 +
  62 +@end
... ...
CNLiveSettingModule/Classes/Privacy/CNLivePrivacyModel.h 0 → 100644
  1 +//
  2 +// CNPrivacyModel.h
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/4/23.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +NS_ASSUME_NONNULL_BEGIN
  12 +typedef enum {
  13 + CNLivePrivacyCellTypeList = 0,//隐私列表
  14 + CNLivePrivacyCellTypeSee = 1,//是否允许陌生人查看生活圈
  15 +
  16 +} CNLivePrivacyCellType;
  17 +
  18 +@interface CNLivePrivacyModel : NSObject
  19 +@property (nonatomic, copy) NSString *title;
  20 +@property (nonatomic, copy) NSString *status;
  21 +@property (nonatomic, assign) float lineHeight;
  22 +@property (nonatomic, assign) float rowHeight;
  23 +@property (nonatomic, assign) CNLivePrivacyCellType cellType;
  24 +
  25 +@end
  26 +
  27 +NS_ASSUME_NONNULL_END
... ...
CNLiveSettingModule/Classes/Privacy/CNLivePrivacyModel.m 0 → 100644
  1 +//
  2 +// CNLivePrivacyModel.m
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/4/23.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLivePrivacyModel.h"
  10 +
  11 +@implementation CNLivePrivacyModel
  12 +
  13 +@end
... ...
CNLiveSettingModule/Classes/Privacy/CNLivePrivacyTableViewCell.h 0 → 100644
  1 +//
  2 +// CNPrivacyTableViewCell.h
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/4/23.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +NS_ASSUME_NONNULL_BEGIN
  12 +#define kCNLivePrivacyTableViewCell @"CNLivePrivacyTableViewCell"
  13 +@class CNLivePrivacyModel;
  14 +
  15 +@interface CNLivePrivacyTableViewCell : UITableViewCell
  16 +@property (nonatomic, strong) CNLivePrivacyModel *model;
  17 +
  18 +@end
  19 +
  20 +NS_ASSUME_NONNULL_END
... ...
CNLiveSettingModule/Classes/Privacy/CNLivePrivacyTableViewCell.m 0 → 100644
  1 +//
  2 +// CNLivePrivacyTableViewCell.m
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by CNLive-zxw on 2019/4/23.
  6 +// Copyright © 2019 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLivePrivacyTableViewCell.h"
  10 +#import <SDWebImage/SDWebImage.h>
  11 +#import "QMUIKit.h"
  12 +#import <Masonry/Masonry.h>
  13 +
  14 +#import "CNLiveNetworking.h"
  15 +#import "CNLiveEnvironment.h"
  16 +#import "CNUserInfoManager.h"
  17 +
  18 +#import "CNLivePrivacyModel.h"
  19 +
  20 +@interface CNLivePrivacyTableViewCell ()
  21 +@property (nonatomic, strong) UILabel *titleLabel;
  22 +@property (nonatomic, strong) UISwitch *notifiSwitch;
  23 +@property (nonatomic, strong) UIImageView *arrowImage;
  24 +
  25 +@end
  26 +
  27 +@implementation CNLivePrivacyTableViewCell
  28 +static const NSInteger margin = 12;
  29 +
  30 +#pragma mark - Init
  31 +- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  32 + if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  33 + [self initSubView];
  34 + }
  35 + return self;
  36 +}
  37 +
  38 +#pragma mark - UI
  39 +- (void)initSubView {
  40 + [self.contentView addSubview:self.titleLabel];
  41 + [self.contentView addSubview:self.arrowImage];
  42 + [self.contentView addSubview:self.notifiSwitch];
  43 +
  44 +}
  45 +
  46 +- (void)layoutSubviews {
  47 + [super layoutSubviews];
  48 + [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  49 + make.centerY.mas_equalTo(self.contentView);
  50 + make.left.equalTo(self.contentView).offset(margin);
  51 + }];
  52 + [self.arrowImage mas_makeConstraints:^(MASConstraintMaker *make) {
  53 + make.centerY.mas_equalTo(self.contentView);
  54 + make.right.equalTo(self.contentView).offset(-margin);
  55 + }];
  56 + [self.notifiSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
  57 + make.centerY.mas_equalTo(self.contentView);
  58 + make.right.equalTo(self.contentView).offset(-margin);
  59 + make.width.mas_equalTo(47);
  60 + make.height.mas_equalTo(29);
  61 + }];
  62 +}
  63 +
  64 +- (void)setFrame:(CGRect)frame {
  65 + frame.origin.y += _model.lineHeight;
  66 + frame.size.height -= _model.lineHeight;
  67 + [super setFrame:frame];
  68 +}
  69 +
  70 +#pragma mark - Data
  71 +- (void)setModel:(CNLivePrivacyModel *)model {
  72 + _model = model;
  73 + _titleLabel.text = model.title;
  74 + if (model.cellType == CNLivePrivacyCellTypeList) { //0 隐私的列表
  75 + _arrowImage.hidden = NO;
  76 + _notifiSwitch.hidden = YES;
  77 +
  78 + }
  79 + if (model.cellType == CNLivePrivacyCellTypeSee) { //1 是否允许陌生人看生活圈
  80 + _arrowImage.hidden = YES;
  81 + _notifiSwitch.hidden = NO;
  82 +
  83 +// _notifiSwitch.enabled = [[KSYReachability reachabilityForInternetConnection] currentReachabilityStatus];//交互性
  84 + [_notifiSwitch setOn:[model.status isEqualToString:@"access"]];
  85 +
  86 + }
  87 +
  88 +}
  89 +
  90 +#pragma mark - Action
  91 +- (void)switchAction:(UISwitch *)sender {
  92 + if (_model.cellType == CNLivePrivacyCellTypeSee) { //1 是否允许陌生人看生活圈
  93 + sender.userInteractionEnabled = NO;
  94 + if (![[[NSUserDefaults standardUserDefaults] objectForKey:@"CNLiveConnectSuccNotification"] boolValue]) {
  95 + [sender setOn:[_model.status isEqualToString:@"access"]];
  96 + sender.userInteractionEnabled = YES;
  97 + return;
  98 + };
  99 + __weak typeof(self) weakSelf = self;
  100 + NSDictionary *params = @{@"appId":AppId,
  101 + @"type":[_model.status isEqualToString:@"access"]?@"reject":@"access",
  102 + @"sid":CNUserShareModel.uid};
  103 + [CNLiveNetworking setAllowRequestDefaultArgument:YES];
  104 + [CNLiveNetworking requestNetworkWithMethod:CNLiveRequestMethodPOST URLString:CNSwitchAllowStrangerUrl Param:params CacheType:CNLiveNetworkCacheTypeNetworkOnly CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
  105 + if ([responseObject isKindOfClass:[NSDictionary class]] && [responseObject[@"errorCode"] isEqualToString:@"0"]) {
  106 + weakSelf.model.status = [weakSelf.model.status isEqualToString:@"access"]?@"reject":@"access";
  107 + [[NSUserDefaults standardUserDefaults] setValue:weakSelf.model.status forKey:@"findStrangerSwitch"];
  108 +
  109 + }else{
  110 + [sender setOn:[weakSelf.model.status isEqualToString:@"access"]];
  111 +
  112 + }
  113 + sender.userInteractionEnabled = YES;
  114 +
  115 + }];
  116 + }
  117 +
  118 +}
  119 +
  120 +- (void)awakeFromNib {
  121 + [super awakeFromNib];
  122 + // Initialization code
  123 +}
  124 +
  125 +- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  126 + [super setSelected:selected animated:animated];
  127 + // Configure the view for the selected state
  128 +}
  129 +
  130 +#pragma mark - Lazy Loading
  131 +- (UILabel *)titleLabel {
  132 + if (!_titleLabel) {
  133 + _titleLabel = [[UILabel alloc] init];
  134 + _titleLabel.textColor = UIColorMake(40, 40, 40);
  135 + _titleLabel.font = [UIFont systemFontOfSize:16];
  136 + }
  137 + return _titleLabel;
  138 +}
  139 +
  140 +- (UIImageView *)arrowImage {
  141 + if (!_arrowImage) {
  142 + _arrowImage = [[UIImageView alloc] init];
  143 + UIImage *xw_image = [self xw_getImageName:@"mine_info_front" bundleName:@"CNLiveSettingModule" targetClass:[CNLivePrivacyTableViewCell class]];
  144 + _arrowImage.image = xw_image;
  145 + }
  146 + return _arrowImage;
  147 +}
  148 +
  149 +- (UISwitch *)notifiSwitch {
  150 + if (!_notifiSwitch) {
  151 + _notifiSwitch = [[UISwitch alloc] init];
  152 + [_notifiSwitch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
  153 + }
  154 + return _notifiSwitch;
  155 +}
  156 +
  157 +/**
  158 + * 创建图片
  159 + *
  160 + * @param imageName 图片名字
  161 + * @param bundleName 图片所在的bundle名字
  162 + * @param targetClass 类和bundle的同级目录
  163 + * @return 返回UIImage
  164 + */
  165 +- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{
  166 + NSBundle *bundle = [NSBundle bundleForClass:targetClass];
  167 + NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"];
  168 + NSBundle *targetBundle = [NSBundle bundleWithURL:url];
  169 + UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil];
  170 + return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
  171 +
  172 +}
  173 +
  174 +@end
... ...