//
|
// HDLSiriSceneListCell.m
|
// HdlSmartIoT
|
//
|
// Created by 陈嘉乐 on 2021/11/17.
|
//
|
|
#import "HDLSiriSceneListCell.h"
|
#import "HDLSceneSiri.h"
|
|
@interface HDLSiriSceneListCell ()<INUIAddVoiceShortcutButtonDelegate>
|
|
|
@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 clearColor];
|
self.contentView.backgroundColor = [UIColor clearColor];
|
[self.contentView addSubview:self.bgView];
|
[self.bgView addSubview:self.titleLabel];
|
if (@available(iOS 12.0, *)) {
|
[self.bgView addSubview:self.shortcutButton];
|
}
|
}
|
|
-(UIView*)bgView{
|
if(!_bgView){
|
_bgView = [[UIView alloc]initWithFrame:CGRectMake(20, 6, APP_SCREEN_WIDTH - 40, 60)];
|
_bgView.backgroundColor = UIColor.whiteColor;
|
_bgView.layer.cornerRadius = 12;
|
_bgView.layer.masksToBounds = YES;// 隐藏边界
|
}
|
return _bgView;
|
}
|
|
-(UILabel*)titleLabel{
|
if(!_titleLabel){
|
_titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(6, 10, APP_SCREEN_WIDTH - 40 - 206, 40)];
|
_titleLabel.textColor = COLOR_TEXT;
|
_titleLabel.font = Get_FontMediumWithSize(16);
|
_titleLabel.textAlignment = NSTextAlignmentLeft;
|
_titleLabel.numberOfLines = 2;
|
}
|
return _titleLabel;
|
}
|
|
- (INUIAddVoiceShortcutButton*)shortcutButton{
|
if(!_shortcutButton){
|
_shortcutButton = [[INUIAddVoiceShortcutButton alloc] initWithStyle:INUIAddVoiceShortcutButtonStyleWhite];
|
// _shortcutButton.shortcut = [[INShortcut alloc] initWithIntent:self.intent];
|
_shortcutButton.translatesAutoresizingMaskIntoConstraints = YES;
|
_shortcutButton.frame = CGRectMake(APP_SCREEN_WIDTH - 40 - 150, 6, 150, 48);
|
[_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:(HDLSiriSceneModel *)model intent:(HDLRunSceneIntent*)intent API_AVAILABLE(ios(12.0)){
|
_model = model;
|
//判空
|
if (_model == nil) return;
|
//处理model数据
|
self.titleLabel.text = model.name;
|
if(intent == nil){
|
_shortcutButton.shortcut = [self getINShortcut];
|
}else{
|
_shortcutButton.shortcut = [[INShortcut alloc] initWithIntent:intent];
|
}
|
}
|
|
- (INShortcut *) getINShortcut API_AVAILABLE(ios(12.0)){
|
NSString *title = _model.name;
|
HDLRunSceneIntent *intent = [[HDLRunSceneIntent alloc] init];
|
intent.sceneId = _model.userSceneId;
|
intent.suggestedInvocationPhrase = title; //在Siri语音设置时显示的建议设置唤起文字
|
intent.sceneName = title;
|
INShortcut *shortCut = [[INShortcut alloc] initWithIntent:intent];
|
return shortCut;
|
}
|
|
@end
|