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.
249 lines
8.8 KiB
249 lines
8.8 KiB
// |
|
// DeviceMsgHeaderView.m |
|
// LekangGuard |
|
// |
|
// Created by ecell on 2023/8/24. |
|
// |
|
|
|
#import "DeviceMsgHeaderView.h" |
|
#import "EditDeviceViewController.h" |
|
|
|
@interface DeviceMsgHeaderView () |
|
|
|
/// 设备头像 |
|
@property (nonatomic ,weak) UIImageView *iconImg; |
|
|
|
/// 设备名称 |
|
@property (nonatomic ,weak) UILabel *nameLabel; |
|
|
|
/// 年级班级 |
|
@property (nonatomic ,weak) UILabel *bnLabel; |
|
|
|
/// 设备电量图片 |
|
@property (nonatomic ,weak) UIImageView *batteryImg; |
|
|
|
/// 设备电量 |
|
@property (nonatomic ,weak) UILabel *batteryLabel; |
|
|
|
|
|
/// 运营商 |
|
@property (nonatomic ,weak) UIImageView *operatorImg; |
|
|
|
@property (nonatomic ,weak) UILabel *line; |
|
|
|
/// 是否在线图标 |
|
@property (nonatomic ,weak) UIImageView *signalImg; |
|
|
|
@property (nonatomic ,weak) UILabel *titleLabel; |
|
|
|
@property (nonatomic ,weak) UILabel *IdLabel; |
|
|
|
@end |
|
|
|
@implementation DeviceMsgHeaderView |
|
|
|
- (instancetype)initWithFrame:(CGRect)frame |
|
{ |
|
self = [super initWithFrame:frame]; |
|
if (self) |
|
{ |
|
self.backgroundColor = KKClearColor; |
|
[self subHeaderView]; |
|
} |
|
return self; |
|
} |
|
|
|
- (void)subHeaderView |
|
{ |
|
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); |
|
}]; |
|
|
|
/// 设备头像 |
|
UIImageView *iconImg = [UIImageView new]; |
|
iconImg.layer.cornerRadius = 25; |
|
iconImg.layer.masksToBounds = YES; |
|
self.iconImg = iconImg; |
|
[bgView addSubview:iconImg]; |
|
[iconImg mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(bgView.mas_left).offset(15); |
|
make.top.equalTo(bgView.mas_top).offset(16); |
|
make.size.mas_equalTo(CGSizeMake(50, 50)); |
|
}]; |
|
|
|
UIButton *btn = [UICommon ui_buttonSimple:CGRectZero font:Font_(0) normalColor:KKClearColor normalText:@"" click:^(id x) { |
|
EditDeviceViewController *vc = [[EditDeviceViewController alloc] init]; |
|
[[UICommon currentVC].navigationController pushViewController:vc animated:YES]; |
|
}]; |
|
[bgView addSubview:btn]; |
|
[btn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.right.equalTo(bgView); |
|
make.top.equalTo(bgView); |
|
make.bottom.equalTo(iconImg.mas_bottom); |
|
}]; |
|
|
|
|
|
/// 班级年级 |
|
UILabel *bnLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(14) textColor:KKTextBlackColor text:@"" Radius:0]; |
|
self.bnLabel = bnLabel; |
|
[bgView addSubview:bnLabel]; |
|
[bnLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(iconImg.mas_right).offset(20); |
|
make.centerY.equalTo(iconImg); |
|
}]; |
|
|
|
/// 设备名称 |
|
UILabel *nameLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontBold_(16) textColor:KKTextBlackColor text:@"" Radius:0]; |
|
self.nameLabel = nameLabel; |
|
[bgView addSubview:nameLabel]; |
|
[nameLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(iconImg.mas_right).offset(20); |
|
// make.top.equalTo(iconImg.mas_top).offset(3); |
|
make.bottom.equalTo(bnLabel.mas_top).inset(5); |
|
}]; |
|
|
|
|
|
UILabel *IdLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(12) textColor:KKGrey133 text:@"" Radius:0]; |
|
self.IdLabel = IdLabel; |
|
[bgView addSubview:IdLabel]; |
|
[IdLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(nameLabel); |
|
make.top.equalTo(bnLabel.mas_bottom).offset(5); |
|
}]; |
|
|
|
|
|
/// 右箭头图片 |
|
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(18); |
|
make.centerY.equalTo(iconImg.mas_centerY); |
|
make.size.mas_equalTo(CGSizeMake(8, 15)); |
|
}]; |
|
|
|
UILabel *ttLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(12) textColor:KKGrey133 text:@"编辑资料" Radius:0]; |
|
[bgView addSubview:ttLabel]; |
|
[ttLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.right.equalTo(rightImg.mas_left).inset(10); |
|
make.centerY.equalTo(rightImg.mas_centerY); |
|
}]; |
|
|
|
NSArray *titleArr = @[@"当前电量",@"未连接",]; |
|
CGFloat ww = (SCREEN_WIDTH-30)/titleArr.count; |
|
|
|
for (int i = 1; i < titleArr.count; i++) |
|
{ |
|
UILabel *line = [UILabel new]; |
|
line.backgroundColor = KKLineColor; |
|
self.line = line; |
|
[self addSubview:line]; |
|
[line mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(self.mas_left).offset(i*ww); |
|
make.top.equalTo(iconImg.mas_bottom).offset(25); |
|
//make.bottom.equalTo(bgView.mas_bottom).inset(26); |
|
make.size.mas_equalTo(CGSizeMake(1, 45)); |
|
}]; |
|
} |
|
|
|
for (int i = 0; i < titleArr.count; i++) |
|
{ |
|
UILabel *label = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(10) textColor:KKGrey133 text:titleArr[i] Radius:0]; |
|
if (i == 0) self.batteryLabel = label; |
|
if (i == 1) self.titleLabel = label; |
|
[self addSubview:label]; |
|
[label mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(self.mas_left).offset(i*ww); |
|
make.top.equalTo(self.line.mas_centerY).offset(5); |
|
make.width.mas_equalTo(ww); |
|
}]; |
|
|
|
/// 当前电量 |
|
UIImageView *signalImg = [UICommon ui_imageView:CGRectZero fileName:@""]; |
|
[self addSubview:signalImg]; |
|
|
|
if (i == 0) |
|
{ |
|
self.batteryImg = signalImg; |
|
[signalImg mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.centerX.equalTo(label.mas_centerX); |
|
make.bottom.equalTo(self.line.mas_centerY).inset(5); |
|
make.size.mas_equalTo(CGSizeMake(25, 10)); |
|
}]; |
|
} |
|
else if (i == 1) |
|
{ |
|
self.signalImg = signalImg; |
|
[signalImg mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.centerX.equalTo(label.mas_centerX); |
|
make.centerY.equalTo(self.batteryImg); |
|
make.size.mas_equalTo(CGSizeMake(15, 15)); |
|
}]; |
|
} |
|
else if (i == 2) |
|
{ |
|
[signalImg mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.centerX.equalTo(label.mas_centerX); |
|
make.centerY.equalTo(self.batteryImg); |
|
make.size.mas_equalTo(CGSizeMake(15, 15)); |
|
}]; |
|
} |
|
} |
|
} |
|
|
|
- (void)setModel |
|
{ |
|
UIImage *defaImage; |
|
self.nameLabel.text = APIManager.sharedManager.deviceModel.name; |
|
self.bnLabel.text = F(@"%@%@",APIManager.sharedManager.deviceModel.gradeName,APIManager.sharedManager.deviceModel.className); |
|
self.IdLabel.text = [NSString stringWithFormat:@"IMEI:%@",APIManager.sharedManager.deviceModel.imei]; |
|
if (APIManager.sharedManager.deviceModel.image.length <= 0) |
|
[self.iconImg setImage:ImageName_(APIManager.sharedManager.deviceModel.sex == 0 ? @"icon_head_girl" : @"icon_head_boy")]; |
|
else |
|
[self.iconImg sd_setImageWithURL:[NSURL URLWithString:APIManager.sharedManager.deviceModel.image] placeholderImage:ImageName_(@"icon_head_boy")]; |
|
self.signalImg.image = APIManager.sharedManager.laloModel.onlineStatus ? ImageName_(@"icon_device_connected") : ImageName_(@"icon_device_unconnected"); |
|
self.titleLabel.text = APIManager.sharedManager.laloModel.onlineStatus ? @"已连接" : @"未连接"; |
|
NSInteger battery = APIManager.sharedManager.laloModel.battery; |
|
NSString *imageName = @""; |
|
if(battery == 0) |
|
imageName = @"battery_0"; |
|
else if (battery < 10) |
|
imageName = @"battery_low"; |
|
else if (battery < 20) |
|
imageName = @"battery_1"; |
|
else if (battery < 30) |
|
imageName = @"battery_2"; |
|
else if (battery < 40) |
|
imageName = @"battery_3"; |
|
else if (battery < 50) |
|
imageName = @"battery_4"; |
|
else if (battery < 60) |
|
imageName = @"battery_4"; |
|
else if (battery < 70) |
|
imageName = @"battery_6"; |
|
else if (battery < 80) |
|
imageName = @"battery_7"; |
|
else if (battery < 90) |
|
imageName = @"battery_8"; |
|
else if (battery < 100) |
|
imageName = @"battery_9"; |
|
else |
|
imageName = @"battery_10"; |
|
|
|
self.batteryImg.image = ImageName_(imageName); |
|
self.batteryLabel.text = [NSString stringWithFormat:@"当前电量:%ld%%",battery]; |
|
} |
|
|
|
|
|
/* |
|
// Only override drawRect: if you perform custom drawing. |
|
// An empty implementation adversely affects performance during animation. |
|
- (void)drawRect:(CGRect)rect { |
|
// Drawing code |
|
} |
|
*/ |
|
|
|
@end
|
|
|