25
25
#pragma clang diagnostic push
26
26
#pragma clang diagnostic ignored "-Wpartial-availability"
27
27
28
- @interface VLCCarPlaySceneDelegate () <CPTemplateApplicationSceneDelegate, CPMediaLibraryObserverDelegate>
28
+ @interface VLCCarPlaySceneDelegate () <CPTemplateApplicationSceneDelegate, CPMediaLibraryObserverDelegate, CPListTemplateDelegate >
29
29
{
30
30
CPInterfaceController *_interfaceController;
31
31
CarPlayMediaLibraryObserver *_mediaLibraryObserver;
32
32
VLCNowPlayingTemplateObserver *_nowPlayingTemplateObserver;
33
33
VLCCarPlayArtistsController *_artistsController;
34
34
VLCCarPlayPlaylistsController *_playlistsController;
35
+ CPListTemplate *_playQueueTemplate;
36
+ CPListSection *_section;
37
+ VLCPlaybackService *_playbackService;
35
38
}
36
39
37
40
@end
@@ -51,6 +54,11 @@ - (void)templateApplicationScene:(CPTemplateApplicationScene *)templateApplicati
51
54
_nowPlayingTemplateObserver = [VLCNowPlayingTemplateObserver new ];
52
55
[[CPNowPlayingTemplate sharedTemplate ] addObserver: _nowPlayingTemplateObserver];
53
56
[_nowPlayingTemplateObserver configureNowPlayingTemplate ];
57
+
58
+ _playbackService = [VLCPlaybackService sharedInstance ];
59
+ [[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (displayPlayQueueTemplate ) name: VLCDisplayPlayQueueCarPlay object: nil ];
60
+ [[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (resetPlayQueueTemplate ) name: VLCPlaybackServicePlaybackDidStop object: nil ];
61
+ [[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (resetPlayQueueTemplate ) name: VLCPlaybackServiceShuffleModeUpdated object: nil ];
54
62
}
55
63
56
64
- (void )templateApplicationScene : (CPTemplateApplicationScene *)templateApplicationScene
@@ -61,6 +69,9 @@ - (void)templateApplicationScene:(CPTemplateApplicationScene *)templateApplicati
61
69
_mediaLibraryObserver = nil ;
62
70
[[CPNowPlayingTemplate sharedTemplate ] removeObserver: _nowPlayingTemplateObserver];
63
71
_nowPlayingTemplateObserver = nil ;
72
+ _playQueueTemplate = nil ;
73
+ _section = nil ;
74
+ _playbackService = nil ;
64
75
}
65
76
66
77
- (CPTabBarTemplate *)generateRootTemplate
@@ -87,6 +98,54 @@ - (void)templatesNeedUpdate
87
98
[_interfaceController setRootTemplate: [self generateRootTemplate ] animated: YES ];
88
99
}
89
100
101
+ - (CPListSection *)createListSection
102
+ {
103
+ VLCMediaList *mediaList = _playbackService.isShuffleMode ? _playbackService.shuffledList : _playbackService.mediaList ;
104
+ NSInteger mediaListCount = mediaList.count ;
105
+ NSMutableArray <CPListItem *> *items = [NSMutableArray new ];
106
+
107
+ for (NSInteger index = 0 ; index < mediaListCount; index++) {
108
+ VLCMLMedia *media = [VLCMLMedia mediaForPlayingMedia: [mediaList mediaAtIndex: index]];
109
+ CPListItem *listItem = [[CPListItem alloc ] initWithText: media.title detailText: media.artist.name];
110
+
111
+ [items addObject: listItem];
112
+ }
113
+
114
+ return [[CPListSection alloc ] initWithItems: items];
115
+ }
116
+
117
+ - (void )listTemplate : (CPListTemplate *)listTemplate didSelectListItem : (CPListItem *)item completionHandler : (void (^)(void ))completionHandler
118
+ {
119
+ VLCMediaList *mediaList = _playbackService.isShuffleMode ? _playbackService.shuffledList : _playbackService.mediaList ;
120
+ NSIndexPath *index = [listTemplate indexPathForItem: item];
121
+ if (index.row >= mediaList.count ) {
122
+ return ;
123
+ }
124
+
125
+ [_playbackService playItemAtIndex: index.row];
126
+
127
+ dispatch_async (dispatch_get_main_queue (), ^{
128
+ [self ->_interfaceController popTemplateAnimated: YES ];
129
+ });
130
+ }
131
+
132
+ - (void )displayPlayQueueTemplate
133
+ {
134
+ if (!_playQueueTemplate) {
135
+ _section = [self createListSection ];
136
+ _playQueueTemplate = [[CPListTemplate alloc ] initWithTitle: NSLocalizedString(@" QUEUE_LABEL" , " " ) sections: @[_section]];
137
+ _playQueueTemplate.delegate = self;
138
+ }
139
+
140
+ [_interfaceController pushTemplate: _playQueueTemplate animated: YES ];
141
+ }
142
+
143
+ - (void )resetPlayQueueTemplate
144
+ {
145
+ _playQueueTemplate = nil ;
146
+ _section = nil ;
147
+ }
148
+
90
149
@end
91
150
92
151
#pragma clang diagnostic pop
0 commit comments