XMLinkWallSwitchCell.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // XMLinkWallSwitchCell.m
  3. // XWorld_General
  4. //
  5. // Created by SaturdayNight on 2018/10/22.
  6. // Copyright © 2018年 xiongmaitech. All rights reserved.
  7. //
  8. #import "XMLinkWallSwitchCell.h"
  9. #import <Masonry/Masonry.h>
  10. #import "UIColor+Util.h"
  11. #import "UIView+WZLBadge.h"
  12. @interface XMLinkWallSwitchCell ()
  13. @property (nonatomic, strong) UILabel *titleLabel;
  14. @property (nonatomic, strong) UILabel *detailLabel;
  15. @property (nonatomic, strong) UIImageView *iconImageView;
  16. @end
  17. @implementation XMLinkWallSwitchCell
  18. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  19. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  20. if (self) {
  21. [self makeUI];
  22. UILongPressGestureRecognizer *longPressGR = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
  23. [self addGestureRecognizer:longPressGR];
  24. }
  25. return self;
  26. }
  27. -(void)makeUI {
  28. self.selectionStyle = UITableViewCellSelectionStyleNone;
  29. [self.contentView addSubview:self.titleLabel];
  30. [self.contentView addSubview:self.detailLabel];
  31. [self.contentView addSubview:self.iconImageView];
  32. [self.contentView addSubview:self.wallSwitchView];
  33. [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.left.equalTo(self).offset(20);
  35. make.centerY.equalTo(self);
  36. make.height.equalTo(@40);
  37. make.width.equalTo(@40);
  38. }];
  39. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.left.equalTo(self.iconImageView.mas_right);
  41. make.centerY.equalTo(self).offset(-5);
  42. make.height.equalTo(@24);
  43. make.width.equalTo(@200);
  44. }];
  45. [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.left.equalTo(self.iconImageView.mas_right);
  47. make.top.equalTo(self.titleLabel.mas_bottom);
  48. make.bottom.equalTo(self).offset(-10);
  49. make.width.equalTo(@100);
  50. }];
  51. [self.wallSwitchView mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.width.mas_equalTo(40*3*0.75+10);
  53. make.centerY.equalTo(self);
  54. make.height.mas_equalTo(40);
  55. make.right.equalTo(self).mas_offset(-20);
  56. }];
  57. }
  58. -(UILabel *)titleLabel {
  59. if (!_titleLabel) {
  60. _titleLabel = [[UILabel alloc]init];
  61. }
  62. return _titleLabel;
  63. }
  64. -(UILabel *)detailLabel {
  65. if (!_detailLabel) {
  66. _detailLabel = [[UILabel alloc]init];
  67. _detailLabel.font = [UIFont systemFontOfSize:13];
  68. _detailLabel.textColor = [UIColor lightGrayColor];
  69. }
  70. return _detailLabel;
  71. }
  72. -(UIImageView *)iconImageView {
  73. if (!_iconImageView) {
  74. _iconImageView = [[UIImageView alloc]init];
  75. }
  76. return _iconImageView;
  77. }
  78. - (XMWallSwitchView *)wallSwitchView{
  79. if (!_wallSwitchView) {
  80. _wallSwitchView = [[XMWallSwitchView alloc] init];
  81. __weak typeof(self) weakSelf = self;
  82. _wallSwitchView.WallSwitchClickedAction = ^(NSInteger index, BOOL selected) {
  83. if (weakSelf.WallSwitchClickedAction) {
  84. weakSelf.WallSwitchClickedAction(index, selected);
  85. }
  86. };
  87. }
  88. return _wallSwitchView;
  89. }
  90. -(void)longPress:(UILongPressGestureRecognizer *)sender {
  91. if (sender.state == UIGestureRecognizerStateEnded&&self.longPressAction) {
  92. self.longPressAction(self);
  93. }
  94. }
  95. - (void)configureCellWithModel:(SensorDeviceModel *)linkDev {
  96. self.titleLabel.text = [linkDev.dicListInfo objectForKey:@"DevName"];
  97. int online = linkDev.ifOnline ? 1 : 0;
  98. int unreadCount = 0;
  99. self.iconImageView.badgeBgColor = [UIColor redColor];
  100. [self.iconImageView showBadgeWithStyle:WBadgeStyleNumber value:unreadCount animationType:WBadgeAnimTypeNone];
  101. if (online) {
  102. [self.iconImageView setImage:[UIImage imageNamed:@"dev_wall_switch_on"]];
  103. } else {
  104. [self.iconImageView setImage:[UIImage imageNamed:@"dev_wall_switch"]];
  105. }
  106. // 刷新墙壁开关状态
  107. int mask = [[linkDev.dicStatusInfo objectForKey:@"DevStatus"] intValue];
  108. if ((mask & 1) == 1) {
  109. self.wallSwitchView.btnOne.selected = YES;
  110. }
  111. else{
  112. self.wallSwitchView.btnOne.selected = NO;
  113. }
  114. if ((mask & 2) == 2) {
  115. self.wallSwitchView.btnTwo.selected = YES;
  116. }
  117. else{
  118. self.wallSwitchView.btnTwo.selected = NO;
  119. }
  120. if ((mask & 4) == 4) {
  121. self.wallSwitchView.btnThree.selected = YES;
  122. }
  123. else{
  124. self.wallSwitchView.btnThree.selected = NO;
  125. }
  126. }
  127. @end