// // HDLSiriSceneListCell.m // HdlSmartIoT // // Created by 陈嘉乐 on 2021/11/17. // #import "HDLSiriSceneListCell.h" #import "HDLSceneSiri.h" @interface HDLSiriSceneListCell () @end @implementation HDLSiriSceneListCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { self.selectionStyle = UITableViewCellSelectionStyleNone; //添加自己需要个子视图控件 [self addAllChildView]; } return self; } /// - (void)addAllChildView{ self.backgroundColor = [UIColor whiteColor]; self.contentView.backgroundColor = [UIColor whiteColor]; // [self.contentView addSubview:self.bgView]; [self.contentView addSubview:self.titleLabel]; if (@available(iOS 12.0, *)) { [self.contentView addSubview:self.shortcutButton]; } [self.contentView addSubview:self.lineView]; } //-(UIView*)bgView{ // if(!_bgView){ // _bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, APP_SCREEN_WIDTH, 50)]; // _bgView.backgroundColor = UIColor.whiteColor; //// _bgView.layer.cornerRadius = 12; //// _bgView.layer.masksToBounds = YES;// 隐藏边界 // } // return _bgView; //} -(UIView*)lineView{ if(!_lineView){ _lineView = [[UIView alloc]initWithFrame:CGRectMake(16, 49, APP_SCREEN_WIDTH - 32, 1)]; _lineView.backgroundColor = HEXCOLORA(0xECEDEE , 1.0); } return _lineView; } -(UILabel*)titleLabel{ if(!_titleLabel){ _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(16, 0, APP_SCREEN_WIDTH - 32 - 180, 50)]; _titleLabel.textColor = COLOR_TEXT; _titleLabel.font = Get_FontMediumWithSize(14); _titleLabel.textAlignment = NSTextAlignmentLeft; _titleLabel.numberOfLines = 2; } return _titleLabel; } - (INUIAddVoiceShortcutButton*)shortcutButton{ if(!_shortcutButton){ _shortcutButton = [[INUIAddVoiceShortcutButton alloc] initWithStyle:INUIAddVoiceShortcutButtonStyleWhite]; // _shortcutButton.backgroundColor = UIColor.redColor; // _shortcutButton.shortcut = [[INShortcut alloc] initWithIntent:self.intent]; _shortcutButton.translatesAutoresizingMaskIntoConstraints = YES; _shortcutButton.frame = CGRectMake(APP_SCREEN_WIDTH - 160, 2, 160, 46); [_shortcutButton setEnabled:NO]; // _shortcutButton.delegate = self; } return _shortcutButton; } //- (void)setModel:(HDLSceneModel *)model { // _model = model; // //判空 // if (_model == nil) return; // //处理model数据 // self.titleLabel.text = model.name; //} -(void)initModel:(HDLSiriControlModel *)model intent:(HDLRunSceneIntent*)intent API_AVAILABLE(ios(12.0)){ _model = model; //判空 if (_model == nil) return; //处理model数据 self.titleLabel.text = model.controlName; if(intent == nil){ _shortcutButton.shortcut = [self getINShortcut:_model]; }else{ _shortcutButton.shortcut = [[INShortcut alloc] initWithIntent:intent]; } } - (INShortcut *) getINShortcut:(HDLSiriControlModel*)sceneModel API_AVAILABLE(ios(12.0)){ NSString *title = sceneModel.controlName; HDLRunSceneIntent *intent = [[HDLRunSceneIntent alloc] init]; intent.suggestedInvocationPhrase = title; //在Siri语音设置时显示的建议设置唤起文字 intent.controlId = sceneModel.controlId; intent.controlName = title; intent.homeId = self.homeId; intent.actionName = sceneModel.actionName; intent.controlType = sceneModel.controlType; intent.controlJSONStr = sceneModel.controlJSONStr; INShortcut *shortCut = [[INShortcut alloc] initWithIntent:intent]; return shortCut; } @end