summaryrefslogtreecommitdiff
path: root/SmartDeviceLink/SDLScreenManager.m
blob: bfd8c9b71586d0fb24744a0a3640ab050c3a4976 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
//
//  SDLScreenManager.m
//  SmartDeviceLink
//
//  Created by Joel Fischer on 3/5/18.
//  Copyright © 2018 smartdevicelink. All rights reserved.
//

#import "SDLScreenManager.h"

#import "SDLArtwork.h"
#import "SDLChoiceSetManager.h"
#import "SDLMenuManager.h"
#import "SDLSoftButtonManager.h"
#import "SDLTextAndGraphicManager.h"
#import "SDLVoiceCommandManager.h"

NS_ASSUME_NONNULL_BEGIN

@interface SDLScreenManager()

@property (strong, nonatomic) SDLTextAndGraphicManager *textAndGraphicManager;
@property (strong, nonatomic) SDLSoftButtonManager *softButtonManager;
@property (strong, nonatomic) SDLMenuManager *menuManager;
@property (strong, nonatomic) SDLVoiceCommandManager *voiceCommandMenuManager;
@property (strong, nonatomic) SDLChoiceSetManager *choiceSetManager;

@property (weak, nonatomic) id<SDLConnectionManagerType> connectionManager;
@property (weak, nonatomic) SDLFileManager *fileManager;

@end

@implementation SDLScreenManager

- (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)connectionManager fileManager:(SDLFileManager *)fileManager {
    self = [super init];
    if (!self) { return nil; }

    _connectionManager = connectionManager;
    _fileManager = fileManager;

    _textAndGraphicManager = [[SDLTextAndGraphicManager alloc] initWithConnectionManager:connectionManager fileManager:fileManager];
    _softButtonManager = [[SDLSoftButtonManager alloc] initWithConnectionManager:connectionManager fileManager:fileManager];
    _menuManager = [[SDLMenuManager alloc] initWithConnectionManager:connectionManager fileManager:fileManager];
    _voiceCommandMenuManager = [[SDLVoiceCommandManager alloc] initWithConnectionManager:connectionManager];
    _choiceSetManager = [[SDLChoiceSetManager alloc] initWithConnectionManager:connectionManager fileManager:fileManager];

    return self;
}

- (void)startWithCompletionHandler:(void (^)(NSError * _Nullable))handler {
    [self.choiceSetManager start];

    handler(nil);
}

- (void)stop {
    [self.textAndGraphicManager stop];
    [self.softButtonManager stop];
    [self.menuManager stop];
    [self.voiceCommandMenuManager stop];
    [self.choiceSetManager stop];
}

- (nullable SDLSoftButtonObject *)softButtonObjectNamed:(NSString *)name {
    return [self.softButtonManager softButtonObjectNamed:name];
}

#pragma mark - Setters

- (void)setTextField1:(nullable NSString *)textField1 {
    self.textAndGraphicManager.textField1 = textField1;
    self.softButtonManager.currentMainField1 = textField1;
}

- (void)setTextField2:(nullable NSString *)textField2 {
    self.textAndGraphicManager.textField2 = textField2;
}

- (void)setTextField3:(nullable NSString *)textField3 {
    self.textAndGraphicManager.textField3 = textField3;
}

- (void)setTextField4:(nullable NSString *)textField4 {
    self.textAndGraphicManager.textField4 = textField4;
}

- (void)setMediaTrackTextField:(nullable NSString *)mediaTrackTextField {
    self.textAndGraphicManager.mediaTrackTextField = mediaTrackTextField;
}

- (void)setPrimaryGraphic:(nullable SDLArtwork *)primaryGraphic {
    if (primaryGraphic == nil) {
        self.textAndGraphicManager.primaryGraphic = self.textAndGraphicManager.blankArtwork;
        return;
    }

    self.textAndGraphicManager.primaryGraphic = primaryGraphic;
}

- (void)setSecondaryGraphic:(nullable SDLArtwork *)secondaryGraphic {
    if (secondaryGraphic == nil) {
        self.textAndGraphicManager.secondaryGraphic = self.textAndGraphicManager.blankArtwork;
        return;
    }

    self.textAndGraphicManager.secondaryGraphic = secondaryGraphic;
}

- (void)setTextAlignment:(SDLTextAlignment)textAlignment {
    self.textAndGraphicManager.alignment = textAlignment;
}

- (void)setTextField1Type:(nullable SDLMetadataType)textField1Type {
    self.textAndGraphicManager.textField1Type = textField1Type;
}

- (void)setTextField2Type:(nullable SDLMetadataType)textField2Type {
    self.textAndGraphicManager.textField2Type = textField2Type;
}

- (void)setTextField3Type:(nullable SDLMetadataType)textField3Type {
    self.textAndGraphicManager.textField3Type = textField3Type;
}

- (void)setTextField4Type:(nullable SDLMetadataType)textField4Type {
    self.textAndGraphicManager.textField4Type = textField4Type;
}

- (void)setSoftButtonObjects:(NSArray<SDLSoftButtonObject *> *)softButtonObjects {
    self.softButtonManager.softButtonObjects = softButtonObjects;
}

- (void)setMenu:(NSArray<SDLMenuCell *> *)menu {
    self.menuManager.menuCells = menu;
}

- (void)setVoiceCommands:(NSArray<SDLVoiceCommand *> *)voiceCommands {
    self.voiceCommandMenuManager.voiceCommands = voiceCommands;
}

- (void)setKeyboardConfiguration:(nullable SDLKeyboardProperties *)keyboardConfiguration {
    self.choiceSetManager.keyboardConfiguration = keyboardConfiguration;
}

#pragma mark - Getters

- (nullable NSString *)textField1 {
    return _textAndGraphicManager.textField1;
}

- (nullable NSString *)textField2 {
    return _textAndGraphicManager.textField2;
}

- (nullable NSString *)textField3 {
    return _textAndGraphicManager.textField3;
}

- (nullable NSString *)textField4 {
    return _textAndGraphicManager.textField4;
}

- (nullable NSString *)mediaTrackTextField {
    return _textAndGraphicManager.mediaTrackTextField;
}

- (nullable SDLArtwork *)primaryGraphic {
    if ([_textAndGraphicManager.primaryGraphic.name isEqualToString:_textAndGraphicManager.blankArtwork.name]) {
        return nil;
    }

    return _textAndGraphicManager.primaryGraphic;
}

- (nullable SDLArtwork *)secondaryGraphic {
    if ([_textAndGraphicManager.secondaryGraphic.name isEqualToString:_textAndGraphicManager.blankArtwork.name]) {
        return nil;
    }

    return _textAndGraphicManager.secondaryGraphic;
}

- (SDLTextAlignment)alignment {
    return _textAndGraphicManager.alignment;
}

- (nullable SDLMetadataType)textField1Type {
    return _textAndGraphicManager.textField1Type;
}

- (nullable SDLMetadataType)textField2Type {
    return _textAndGraphicManager.textField2Type;
}

- (nullable SDLMetadataType)textField3Type {
    return _textAndGraphicManager.textField3Type;
}

- (nullable SDLMetadataType)textField4Type {
    return _textAndGraphicManager.textField4Type;
}

- (NSArray<SDLSoftButtonObject *> *)softButtonObjects {
    return _softButtonManager.softButtonObjects;
}

- (NSArray<SDLMenuCell *> *)menu {
    return _menuManager.menuCells;
}

- (NSArray<SDLVoiceCommand *> *)voiceCommands {
    return _voiceCommandMenuManager.voiceCommands;
}

- (NSSet<SDLChoiceCell *> *)preloadedChoices {
    return _choiceSetManager.preloadedChoices;
}

- (SDLKeyboardProperties *)keyboardConfiguration {
    return _choiceSetManager.keyboardConfiguration;
}

#pragma mark - Begin / End Updates

- (void)beginUpdates {
    self.softButtonManager.batchUpdates = YES;
    self.textAndGraphicManager.batchUpdates = YES;
}

- (void)endUpdates {
    [self endUpdatesWithCompletionHandler:nil];
}

- (void)endUpdatesWithCompletionHandler:(nullable SDLScreenManagerUpdateCompletionHandler)handler {
    self.softButtonManager.batchUpdates = NO;
    self.textAndGraphicManager.batchUpdates = NO;

    [self.textAndGraphicManager updateWithCompletionHandler:handler];
    [self.softButtonManager updateWithCompletionHandler:handler];
}

#pragma mark - Choice Sets

- (void)deleteChoices:(NSArray<SDLChoiceCell *> *)choices {
    [self.choiceSetManager deleteChoices:choices];
}

- (void)preloadChoices:(NSArray<SDLChoiceCell *> *)choices withCompletionHandler:(nullable SDLPreloadChoiceCompletionHandler)handler {
    [self.choiceSetManager preloadChoices:choices withCompletionHandler:handler];
}

- (void)presentChoiceSet:(SDLChoiceSet *)choiceSet mode:(SDLInteractionMode)mode {
    [self.choiceSetManager presentChoiceSet:choiceSet mode:mode withKeyboardDelegate:nil];
}

- (void)presentSearchableChoiceSet:(SDLChoiceSet *)choiceSet mode:(SDLInteractionMode)mode withKeyboardDelegate:(id<SDLKeyboardDelegate>)delegate {
    [self.choiceSetManager presentChoiceSet:choiceSet mode:mode withKeyboardDelegate:delegate];
}

- (void)presentKeyboardWithInitialText:(NSString *)initialText delegate:(id<SDLKeyboardDelegate>)delegate {
    [self.choiceSetManager presentKeyboardWithInitialText:initialText delegate:delegate];
}

@end

NS_ASSUME_NONNULL_END