// // DeviceSetView.m // LekangGuard // // Created by ecell on 2022/11/17. // #import "DeviceSetView.h" #import "LocationModeViewController.h" @interface DeviceSetView () @property (nonatomic ,weak) UIButton *titleBtn; @property (nonatomic ,weak) UISwitch *customSwitch; @property (nonatomic ,weak) UISwitch *customSwitch1; /// 定位模式 @property (nonatomic ,weak) UILabel *textLabel; @property (nonatomic ,strong) PositionModel *pmodel; @end @implementation DeviceSetView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.backgroundColor = KKClearColor; [self subHeaderView]; } return self; } - (void)subHeaderView { for (UIView *views in self.subviews) { [views removeFromSuperview]; } [self DevicePosition]; UIView *bgView = [UICommon ui_view:CGRectZero backgroundColor:KKWhiteColorColor cornerRadius:8 borderWidth:0 borderColor:KKWhiteColorColor]; [self addSubview:bgView]; [bgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self).inset(10); make.top.equalTo(self); make.bottom.equalTo(self.mas_bottom); }]; NSArray *arr = @[GJText(@"定位模式"),GJText(@"拒接陌生电话")]; if ([APIManager sharedManager].deviceModel.dial) arr = @[GJText(@"定位模式"),GJText(@"拒接陌生电话"),GJText(@"拨号盘开关")]; kWeakSelf(self) for (int i = 0; i < arr.count; i++) { UIButton *titleBtn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(13) normalColor:KKTextBlackColor normalText:arr[i] click:^(UIButton *btn) { if (btn.tag == 0) { LocationModeViewController *vc = [LocationModeViewController new]; vc.model = weakself.pmodel; [[UICommon currentVC].navigationController pushViewController:vc animated:YES]; vc.isLoSuccess = ^{ [weakself DevicePosition]; }; } }]; titleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; titleBtn.tag = i; self.titleBtn = titleBtn; [bgView addSubview:titleBtn]; [titleBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(bgView).offset(Adapted(10)); make.right.equalTo(bgView.mas_right); make.top.equalTo(self).offset(i*Adapted(55)); make.height.mas_equalTo(Adapted(55)); }]; if(i == 0) { UIImageView *rightImg = [UICommon ui_imageView:CGRectZero fileName:@"icon_enter_gray"]; [bgView addSubview:rightImg]; [rightImg mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(bgView.mas_right).inset(10); make.centerY.equalTo(titleBtn); make.size.mas_equalTo(CGSizeMake(Adapted(rightImg.image.size.width), Adapted(rightImg.image.size.height))); }]; UILabel *textLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontADA_(13) textColor:KKMainColor text:@"正常模式" Radius:0]; self.textLabel = textLabel; [bgView addSubview:textLabel]; [textLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(rightImg.mas_left).inset(10); make.centerY.equalTo(rightImg); }]; } else { UISwitch *customSwitch = [[UISwitch alloc] init]; customSwitch.tag = i; [customSwitch setOnTintColor:KKMainColor]; [customSwitch addTarget:self action:@selector(switchChange:) forControlEvents:UIControlEventValueChanged]; if (i == 1) { [customSwitch setOn:APIManager.sharedManager.deviceModel.rejectStrange]; self.customSwitch = customSwitch; } else { [customSwitch setOn:APIManager.sharedManager.deviceModel.dialSwitch]; self.customSwitch1 = customSwitch; } [bgView addSubview:customSwitch]; [customSwitch mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(bgView.mas_right).inset(10); make.centerY.equalTo(titleBtn); //make.size.mas_equalTo(CGSizeMake(Adapted(80), Adapted(40))); }]; } if (i < arr.count-1) { UILabel *line = [UILabel new]; line.backgroundColor = KKLineColor; [bgView addSubview:line]; [line mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(bgView).offset(10); make.bottom.equalTo(titleBtn.mas_bottom); make.right.equalTo(bgView.mas_right); make.height.mas_equalTo(0.5); }]; } } } /** * 按钮切换事件监听回调方法 */ - (void)switchChange:(UISwitch*)sw { if(sw.on == YES) { NSLog(@"开关切换为开"); } else if(sw.on == NO) { NSLog(@"开关切换为关"); } [self DeviceDialSwitch:sw.isOn type:sw.tag]; } #pragma mark 拨号盘开关/拒绝陌生来电 /// 拨号盘开关/拒绝陌生来电 - (void)DeviceDialSwitch:(BOOL)isOpen type:(NSInteger)type { NSInteger open = isOpen ? 1 : 0; [UICommon MessageUpload:@"加载中"]; NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; [parameters setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"]; [parameters setValue:@(open) forKey:type == 1 ? @"rejectStrange" : @"dialSwitch"]; [[[APIManager sharedManager] APPOST:type == 1 ? RejectStrangeCalls_URL : DeviceDialSwitch_URL parameters:parameters isJson:YES resultClass:nil] subscribeNext:^(id _Nullable x) { [UICommon HidenLoading]; self.isOpenState(); [UICommon MessageSuccessText:@"设置成功"]; } error:^(NSError * _Nullable error) { NSDictionary *dic = error.userInfo; [UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; if (type == 1)[self.customSwitch setOn:APIManager.sharedManager.deviceModel.rejectStrange]; else [self.customSwitch1 setOn:APIManager.sharedManager.deviceModel.dialSwitch]; }]; } #pragma mark 查询定位模式 /// 查询定位模式 - (void)DevicePosition { kWeakSelf(self) NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; [[[APIManager sharedManager] APGET:F(@"%@/%@", DevicePosition_URL,APIManager.sharedManager.deviceModel.imei) parameters:parameters resultClass:PositionModel.class] subscribeNext:^(PositionModel *model) { [UICommon HidenLoading]; if (model != nil) { NSLog(@"--->%@",APIManager.sharedManager.deviceModel); if (APIManager.sharedManager.deviceModel.positioningInterval == model.positioningOneInterva)//10 self.textLabel.text = GJText(@"正常模式"); else if (APIManager.sharedManager.deviceModel.positioningInterval == model.positioningTwoInterva)//60 self.textLabel.text = GJText(@"省电模式"); else if (APIManager.sharedManager.deviceModel.positioningInterval == model.positioningThreeInterva)//5 self.textLabel.text = GJText(@"高频模式"); weakself.pmodel = model; } } error:^(NSError * _Nullable error) { NSDictionary *dic = error.userInfo; [UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; }]; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end