You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
180 lines
7.0 KiB
180 lines
7.0 KiB
![]()
2 years ago
|
//
|
||
|
// TimingViewController.m
|
||
|
// LekangGuard
|
||
|
//
|
||
|
// Created by ecell on 2022/12/10.
|
||
|
//
|
||
|
|
||
|
#import "TimingViewController.h"
|
||
|
|
||
|
@interface TimingViewController ()
|
||
|
|
||
|
/// 定时开关
|
||
|
@property (nonatomic ,weak) UISwitch *timeSwitch;
|
||
|
|
||
|
/// 开机时间
|
||
|
@property (nonatomic ,weak) UIButton *startTime;
|
||
|
|
||
|
/// 关机时间
|
||
|
@property (nonatomic ,weak) UIButton *endTime;
|
||
|
|
||
|
@property (nonatomic ,assign) NSInteger status;
|
||
|
|
||
|
@end
|
||
|
|
||
|
@implementation TimingViewController
|
||
|
|
||
|
- (void)viewDidLoad {
|
||
|
[super viewDidLoad];
|
||
|
// Do any additional setup after loading the view.
|
||
|
self.view.backgroundColor = KKBackgroundGrey;
|
||
|
self.zx_navTitle = GJText(@"定时开关机");
|
||
|
[self zx_setRightBtnWithText:GJText(@"保存") clickedBlock:^(ZXNavItemBtn * _Nonnull btn) {
|
||
|
[self SwitchAddSetting];
|
||
|
}];
|
||
|
self.status = 0;
|
||
|
NSArray *arr = @[GJText(@"定时开关机"),GJText(@"开机时间"),GJText(@"关机时间")];
|
||
|
|
||
|
UIView *bgView = [UICommon ui_view:CGRectMake(0, iPhoneX_NavHeight, SCREEN_WIDTH, Adapted(55)*arr.count) backgroundColor:KKWhiteColorColor cornerRadius:0 borderWidth:0 borderColor:KKWhiteColorColor];
|
||
|
[self.view addSubview:bgView];
|
||
|
|
||
|
|
||
|
UILabel *headerTitle = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:FontADA_(12) textColor:KKGrey121 text:@"" Radius:0];
|
||
|
headerTitle.text = GJText(@"温馨提示:\n为了增加设备的电池续航,平台已经为你开启定时开关机功能,您可以选择关闭");
|
||
|
[self.view addSubview:headerTitle];
|
||
|
[headerTitle mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.right.equalTo(self.view).inset(15);
|
||
|
make.top.equalTo(bgView.mas_bottom).offset(Adapted(20));
|
||
|
}];
|
||
|
|
||
|
for (int i = 0; i < arr.count; i++)
|
||
|
{
|
||
|
UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontADA_(14) textColor:KKTextBlackColor text:arr[i] Radius:0];
|
||
|
[bgView addSubview:titleLabel];
|
||
|
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.equalTo(self.view).offset(15);
|
||
|
make.top.equalTo(bgView).offset(i*Adapted(55));
|
||
|
make.height.mas_equalTo(Adapted(55));
|
||
|
}];
|
||
|
|
||
|
if (i == 0)
|
||
|
{
|
||
|
UISwitch *timeSwitch = [[UISwitch alloc] init];
|
||
|
[timeSwitch setOnTintColor:KKMainColor];
|
||
|
[timeSwitch addTarget:self action:@selector(switchChange:) forControlEvents:UIControlEventValueChanged];
|
||
|
self.timeSwitch = timeSwitch;
|
||
|
[bgView addSubview:timeSwitch];
|
||
|
[timeSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.right.equalTo(bgView.mas_right).inset(20);
|
||
|
make.centerY.equalTo(titleLabel);
|
||
|
//make.size.mas_equalTo(CGSizeMake(Adapted(80), Adapted(40)));
|
||
|
}];
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
UIButton *timeBtn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(13) normalColor:KKTextBlackColor normalText:i == 1 ? @"06:00" : @"23:00" click:^(UIButton *btn) {
|
||
|
[BRDatePickerView showDatePickerWithMode:BRDatePickerModeHM title:btn.tag == 1 ? GJText(@"选择开机时间") : GJText(@"选择关机时间") selectValue:btn.tag == 1 ? self.startTime.currentTitle : self.startTime.currentTitle minDate:nil maxDate:nil isAutoSelect:NO resultBlock:^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) {
|
||
|
if (btn.tag == 1)
|
||
|
[self.startTime setTitle:selectValue forState:0];
|
||
|
else
|
||
|
[self.endTime setTitle:selectValue forState:0];
|
||
|
}];
|
||
|
}];
|
||
|
timeBtn.tag = i;
|
||
|
timeBtn.layer.borderWidth = 0.5;
|
||
|
timeBtn.layer.borderColor = KKGrey219.CGColor;
|
||
|
timeBtn.layer.cornerRadius = Adapted(16);
|
||
|
if(i == 1) self.startTime = timeBtn;
|
||
|
else self.endTime = timeBtn;
|
||
|
[bgView addSubview:timeBtn];
|
||
|
[timeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.right.equalTo(bgView.mas_right).inset(15);
|
||
|
make.centerY.equalTo(titleLabel);
|
||
|
make.size.mas_equalTo(CGSizeMake(Adapted(60), Adapted(32)));
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
if (i < arr.count-1)
|
||
|
{
|
||
|
UIImageView *line = [UIImageView new];
|
||
|
line.backgroundColor = KKLineColor;
|
||
|
[bgView addSubview:line];
|
||
|
[line mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.equalTo(bgView).offset(15);
|
||
|
make.right.equalTo(bgView.mas_right);
|
||
|
make.top.equalTo(titleLabel.mas_bottom);
|
||
|
make.height.mas_equalTo(0.5);
|
||
|
}];
|
||
|
}
|
||
|
}
|
||
|
[self SwitchQuerySetting];
|
||
|
}
|
||
|
|
||
|
- (void)switchChange:(UISwitch*)sw
|
||
|
{
|
||
|
if(sw.on == YES) {
|
||
|
NSLog(@"开关切换为开");
|
||
|
self.status = 1;
|
||
|
} else if(sw.on == NO) {
|
||
|
NSLog(@"开关切换为关");
|
||
|
self.status = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
#pragma mark 查询定时开关机
|
||
|
/// 查询定时开关机
|
||
|
- (void)SwitchQuerySetting
|
||
|
{
|
||
|
[UICommon MessageUpload:@"加载中"];
|
||
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
|
||
|
[parameters setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"];
|
||
|
[[[APIManager sharedManager] APGET:SwitchQuerySetting_URL parameters:parameters resultClass:TimeSwitchModel.class] subscribeNext:^(TimeSwitchModel *model) {
|
||
|
[UICommon HidenLoading];
|
||
|
if (model != nil)
|
||
|
{
|
||
|
[self.timeSwitch setOn:model.status];
|
||
|
[self.endTime setTitle:model.endTime forState:0];
|
||
|
[self.startTime setTitle:model.startTime forState:0];
|
||
|
}
|
||
|
|
||
|
} error:^(NSError * _Nullable error) {
|
||
|
NSDictionary *dic = error.userInfo;
|
||
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
|
||
|
#pragma mark 保存定时开关机设置
|
||
|
/// 保存定时开关机设置
|
||
|
- (void)SwitchAddSetting
|
||
|
{
|
||
|
[UICommon MessageUpload:@"加载中"];
|
||
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
|
||
|
[parameters setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"];
|
||
|
[parameters setValue:self.endTime.currentTitle forKey:@"endTime"];
|
||
|
[parameters setValue:self.startTime.currentTitle forKey:@"startTime"];
|
||
|
[parameters setValue:@(self.status) forKey:@"status"];
|
||
|
[[[APIManager sharedManager] APPOST:SwitchAddSetting_URL parameters:parameters isJson:YES resultClass:nil] subscribeNext:^(id _Nullable x) {
|
||
|
[UICommon HidenLoading];
|
||
|
[UICommon MessageSuccessText:@"设置成功"];
|
||
|
} error:^(NSError * _Nullable error) {
|
||
|
NSDictionary *dic = error.userInfo;
|
||
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/*
|
||
|
#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.
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
@end
|