JLChen
2021-11-26 f26dfd48aa7bf4c194863cc3b3f47d38bc8a2d57
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
//  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