summaryrefslogtreecommitdiff
path: root/SmartDeviceLink/SDLSoftButton.m
blob: 6d1082c48859fecef26138ef5581d57c7706d0f1 (plain)
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
//  SDLSoftButton.m
//

#import "SDLSoftButton.h"

#import "NSMutableDictionary+Store.h"
#import "SDLImage.h"
#import "SDLRPCParameterNames.h"

NS_ASSUME_NONNULL_BEGIN

@implementation SDLSoftButton

- (instancetype)initWithHandler:(nullable SDLRPCButtonNotificationHandler)handler {
    self = [self init];
    if (!self) {
        return nil;
    }

    _handler = handler;

    return self;
}

- (instancetype)initWithType:(SDLSoftButtonType)type text:(nullable NSString *)text image:(nullable SDLImage *)image highlighted:(BOOL)highlighted buttonId:(UInt16)buttonId systemAction:(nullable SDLSystemAction)systemAction handler:(nullable SDLRPCButtonNotificationHandler)handler {
    self = [self initWithHandler:handler];
    if (!self) {
        return nil;
    }

    self.type = type;
    self.text = text;
    self.image = image;
    self.isHighlighted = @(highlighted);
    self.softButtonID = @(buttonId);
    self.systemAction = systemAction;
    self.handler = handler;

    return self;
}

- (void)setType:(SDLSoftButtonType)type {
    [self.store sdl_setObject:type forName:SDLRPCParameterNameType];
}

- (SDLSoftButtonType)type {
    NSError *error = nil;
    return [self.store sdl_enumForName:SDLRPCParameterNameType error:&error];
}

- (void)setText:(nullable NSString *)text {
    [self.store sdl_setObject:text forName:SDLRPCParameterNameText];
}

- (nullable NSString *)text {
    return [self.store sdl_objectForName:SDLRPCParameterNameText ofClass:NSString.class error:nil];
}

- (void)setImage:(nullable SDLImage *)image {
    [self.store sdl_setObject:image forName:SDLRPCParameterNameImage];
}

- (nullable SDLImage *)image {
    return [self.store sdl_objectForName:SDLRPCParameterNameImage ofClass:SDLImage.class error:nil];
}

- (void)setIsHighlighted:(nullable NSNumber<SDLBool> *)isHighlighted {
    [self.store sdl_setObject:isHighlighted forName:SDLRPCParameterNameIsHighlighted];
}

- (nullable NSNumber<SDLBool> *)isHighlighted {
    return [self.store sdl_objectForName:SDLRPCParameterNameIsHighlighted ofClass:NSNumber.class error:nil];
}

- (void)setSoftButtonID:(NSNumber<SDLInt> *)softButtonID {
    [self.store sdl_setObject:softButtonID forName:SDLRPCParameterNameSoftButtonId];
}

- (NSNumber<SDLInt> *)softButtonID {
    NSError *error = nil;
    return [self.store sdl_objectForName:SDLRPCParameterNameSoftButtonId ofClass:NSNumber.class error:&error];
}

- (void)setSystemAction:(nullable SDLSystemAction)systemAction {
    [self.store sdl_setObject:systemAction forName:SDLRPCParameterNameSystemAction];
}

- (nullable SDLSystemAction)systemAction {
    return [self.store sdl_enumForName:SDLRPCParameterNameSystemAction error:nil];
}

-(id)copyWithZone:(nullable NSZone *)zone {
    SDLSoftButton *newButton = [super copyWithZone:zone];
    newButton->_handler = self.handler;

    return newButton;
}

@end

NS_ASSUME_NONNULL_END