blob: add03489ce64f47f436583230fb2eab1ccf9be3f (
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
|
//
// SDLSoftButtonTransitionOperation.m
// SmartDeviceLink
//
// Created by Joel Fischer on 4/25/19.
// Copyright © 2019 smartdevicelink. All rights reserved.
//
#import "SDLSoftButtonTransitionOperation.h"
#import "SDLConnectionManagerType.h"
#import "SDLFileManager.h"
#import "SDLLogMacros.h"
#import "SDLSoftButtonCapabilities.h"
#import "SDLShow.h"
#import "SDLSoftButton.h"
#import "SDLSoftButtonObject.h"
NS_ASSUME_NONNULL_BEGIN
@interface SDLSoftButtonTransitionOperation ()
@property (strong, nonatomic) SDLSoftButtonCapabilities *softButtonCapabilities;
@property (strong, nonatomic) NSArray<SDLSoftButtonObject *> *softButtons;
@property (weak, nonatomic) id<SDLConnectionManagerType> connectionManager;
@property (copy, nonatomic, nullable) NSError *internalError;
@end
@implementation SDLSoftButtonTransitionOperation
- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager capabilities:(SDLSoftButtonCapabilities *)capabilities softButtons:(NSArray<SDLSoftButtonObject *> *)softButtons mainField1:(NSString *)mainField1 {
self = [super init];
if (!self) { return nil; }
_connectionManager = connectionManager;
_softButtonCapabilities = capabilities;
_softButtons = softButtons;
_mainField1 = mainField1;
return self;
}
- (void)start {
[super start];
if (self.isCancelled) { return; }
[self sdl_sendNewSoftButtons];
}
- (void)sdl_sendNewSoftButtons {
SDLShow *newShow = [[SDLShow alloc] init];
newShow.mainField1 = self.mainField1;
newShow.softButtons = [self sdl_currentStateSoftButtonsForObjects:self.softButtons];
[self.connectionManager sendConnectionRequest:newShow withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) {
if (error != nil) {
SDLLogW(@"Failed to transition soft button to new state. Error: %@, Response: %@", error, response);
self.internalError = error;
}
[self finishOperation];
}];
}
- (NSArray<SDLSoftButton *> *)sdl_currentStateSoftButtonsForObjects:(NSArray<SDLSoftButtonObject *> *)objects {
NSMutableArray<SDLSoftButton *> *softButtons = [NSMutableArray arrayWithCapacity:objects.count];
for (SDLSoftButtonObject *button in objects) {
[softButtons addObject:button.currentStateSoftButton];
}
return [softButtons copy];
}
#pragma mark - Property Overrides
- (nullable NSString *)name {
return @"com.sdl.softbuttonmanager.transition";
}
- (NSOperationQueuePriority)queuePriority {
return NSOperationQueuePriorityNormal;
}
- (nullable NSError *)error {
return self.internalError;
}
@end
NS_ASSUME_NONNULL_END
|