123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- //
- // RDSRoomCell.m
- // Temperature
- //
- // Created by RD on 2022/10/31.
- //
- #import "RDSRoomCell.h"
- #import <SDWebImage/SDWebImage.h>
- @interface RDSRoomCell()
- @property (nonatomic, strong) UIView *containerView;
- @property (nonatomic, strong) UIImageView *iconView;
- @property (nonatomic, strong) UILabel *nameLabel;
- @property (nonatomic, strong) UILabel *statusLabel;
- @property (nonatomic, strong) UIButton *deviceBtn;
- @end
- @implementation RDSRoomCell
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- [self configSubviews];
- _style = RoomCellStyleDefault;
- }
- return self;
- }
- - (void)setModel:(YXHomeDeviceModel *)model {
- _model = model;
- self.nameLabel.text = model.name;
- [self.iconView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", TheApiHelper.baseUrlHeadImg, model.icon]] placeholderImage:[UIImage imageNamed:@"icon_placeholder_image"]];
-
- if (model.show_power.integerValue == 1) {
- self.deviceBtn.hidden = NO;
- if (model.power.integerValue == 0) {
- self.deviceBtn.selected = NO;
- }else{
- self.deviceBtn.selected = YES;
- }
- }else{
- self.deviceBtn.hidden = YES;
- }
-
- if (model.show_online.integerValue == 1) {
- if (model.is_online.integerValue == 1) {
- self.statusLabel.text = @"设备在线";
- } else {
- self.statusLabel.text = @"设备离线";
- }
- }else{
- self.statusLabel.text = [NSString stringWithFormat:@"温度%@°C | 湿度%@%%", model.temperature, model.humidity];
- }
-
- }
- -(void)setStyle:(RoomCellStyle)style
- {
- _style = style;
-
- if (style == RoomCellStyleDefault) {
- [self.containerView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.left.bottom.right.equalTo(@0);
- }];
-
- [self.iconView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.top.equalTo(@15);
- make.width.equalTo(@50);
- make.height.equalTo(@50);
- }];
-
- [self.deviceBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(@15);
- make.right.equalTo(@-15);
- make.width.equalTo(@50);
- make.height.equalTo(@26);
- }];
-
- [self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.iconView.mas_bottom).offset(5);
- make.left.equalTo(@15);
- make.right.equalTo(@-15);
- make.height.equalTo(@25);
- }];
-
- [self.statusLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.nameLabel.mas_bottom);
- make.left.equalTo(@15);
- make.right.equalTo(@-15);
- make.height.equalTo(@25);
- }];
- }else{
- [self.containerView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.left.bottom.right.equalTo(@0);
- }];
-
- [self.iconView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(@0);
- make.left.equalTo(@20);
- make.width.equalTo(@50);
- make.height.equalTo(@50);
- }];
-
- [self.deviceBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(@0);
- make.right.equalTo(@-20);
- make.width.equalTo(@50);
- make.height.equalTo(@26);
- }];
-
- [self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.iconView.mas_right).offset(12);
- make.top.equalTo(self.iconView.mas_top);
- make.right.equalTo(self.deviceBtn.mas_left).offset(-10);
- make.height.equalTo(@25);
- }];
-
- [self.statusLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.iconView.mas_right).offset(10);
- make.top.equalTo(self.nameLabel.mas_bottom);
- make.right.equalTo(self.deviceBtn.mas_left).offset(-10);
- make.height.equalTo(@25);
- }];
- }
- }
- - (void)onPowerChanged:(UIButton *)btn {
- BLOCK_SAFE_RUN(_onPowerClick, btn.isSelected);
- }
- - (void)configSubviews {
- [self.contentView addSubview:self.containerView];
- [self.containerView addSubview:self.iconView];
- [self.containerView addSubview:self.nameLabel];
- [self.containerView addSubview:self.statusLabel];
- [self.containerView addSubview:self.deviceBtn];
- }
- - (UIView *)containerView {
- if (!_containerView) {
- _containerView = [[UIView alloc] init];
- _containerView.backgroundColor = UIColor.whiteColor;
- _containerView.layer.cornerRadius = 6;
- }
- return _containerView;
- }
- - (UIImageView *)iconView {
- if (!_iconView) {
- _iconView = [[UIImageView alloc] init];
- }
- return _iconView;
- }
- - (UILabel *)nameLabel {
- if (!_nameLabel) {
- _nameLabel = [[UILabel alloc] init];
- _nameLabel.font = [UIFont pingFangSCMediumOfSize:16];
- _nameLabel.textColor = [UIColor colorWithHexString:@"#333333"];
- }
- return _nameLabel;
- }
- - (UILabel *)statusLabel {
- if (!_statusLabel) {
- _statusLabel = [[UILabel alloc] init];
- _statusLabel.font = [UIFont pingFangSCRegularOfSize:12];
- _statusLabel.textColor = [UIColor colorWithHexString:@"#999999"];
- }
- return _statusLabel;
- }
- - (UIButton *)deviceBtn {
- if (!_deviceBtn) {
- _deviceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_deviceBtn setBackgroundImage:[UIImage imageNamed:@"home_switch_off"] forState:UIControlStateNormal];
- [_deviceBtn setBackgroundImage:[UIImage imageNamed:@"home_switch_on"] forState:UIControlStateSelected];
- _deviceBtn.contentMode = UIViewContentModeScaleToFill;
- [_deviceBtn addTarget:self action:@selector(onPowerChanged:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _deviceBtn;
- }
- @end
|